2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 extern __xdata uint8_t ao_spi_mutex;
24 #define AO_SPI_SPEED_FAST 17
25 #define AO_SPI_SPEED_200kHz 13
27 #define ao_spi_set_speed(speed) (U0GCR = (UxGCR_CPOL_NEGATIVE | \
28 UxGCR_CPHA_FIRST_EDGE | \
30 ((speed) << UxGCR_BAUD_E_SHIFT)))
32 #define ao_spi_get_slave(bus) do { \
33 ao_mutex_get(&ao_spi_mutex); \
34 ao_spi_set_speed(AO_SPI_SPEED_FAST); \
37 #define ao_spi_put_slave(bus) do { \
38 ao_mutex_put(&ao_spi_mutex); \
41 #define ao_spi_get_mask(reg,mask,bus,speed) do { \
42 ao_mutex_get(&ao_spi_mutex); \
43 ao_spi_set_speed(speed); \
47 #define ao_spi_put_mask(reg,mask,bus) do { \
49 ao_mutex_put(&ao_spi_mutex); \
53 #define ao_spi_get_bit(reg,bit,pin,bus,speed) do { \
54 ao_mutex_get(&ao_spi_mutex); \
55 ao_spi_set_speed(speed); \
59 #define ao_spi_put_bit(reg,bit,pin,bus) do { \
61 ao_mutex_put(&ao_spi_mutex); \
66 * The SPI mutex must be held to call either of these
67 * functions -- this mutex covers the entire SPI operation,
68 * from chip select low to chip select high
72 ao_spi_send_bus(void __xdata *block, uint16_t len) __reentrant;
75 ao_spi_recv_bus(void __xdata *block, uint16_t len) __reentrant;
77 #define ao_spi_send(block, len, bus) ao_spi_send_bus(block, len)
78 #define ao_spi_recv(block, len, bus) ao_spi_recv_bus(block, len)
82 ao_spi_send_wait(void);
85 ao_spi_recv_wait(void);
91 #define ao_spi_init_cs(port, mask) do { \
92 SPI_CS_PORT |= mask; \
94 SPI_CS_SEL &= ~mask; \
97 #define cc1111_enable_output(port,dir,sel,pin,bit,v) do { \
100 sel &= ~(1 << bit); \
103 #define disable_unreachable _Pragma("disable_warning 126")
105 #define token_paster(x,y) x ## y
106 #define token_evaluator(x,y) token_paster(x,y)
107 #define ao_enable_output(port,bit,pin,v) cc1111_enable_output(port,token_evaluator(port,DIR), token_evaluator(port,SEL), pin, bit, v)
108 #define ao_gpio_set(port, bit, pin, v) ((pin) = (v))