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_get_mask(reg,mask,bus) do { \
25 ao_mutex_get(&ao_spi_mutex); \
29 #define ao_spi_put_mask(reg,mask,bus) do { \
31 ao_mutex_put(&ao_spi_mutex); \
34 #define ao_spi_get_bit(reg,bit,pin,bus) do { \
35 ao_mutex_get(&ao_spi_mutex); \
39 #define ao_spi_put_bit(reg,bit,pin,bus) do { \
41 ao_mutex_put(&ao_spi_mutex); \
46 * The SPI mutex must be held to call either of these
47 * functions -- this mutex covers the entire SPI operation,
48 * from chip select low to chip select high
52 ao_spi_send_bus(void __xdata *block, uint16_t len) __reentrant;
55 ao_spi_recv_bus(void __xdata *block, uint16_t len) __reentrant;
57 #define ao_spi_send(block, len, bus) ao_spi_send_bus(block, len)
58 #define ao_spi_recv(block, len, bus) ao_spi_recv_bus(block, len)
63 #define ao_spi_init_cs(port, mask) do { \
64 SPI_CS_PORT |= mask; \
66 SPI_CS_SEL &= ~mask; \
69 #define cc1111_enable_output(port,dir,sel,mask,v) do { \
70 port = port & ~(mask) | v; \
75 #define disable_unreachable _Pragma("disable_warning 126")
77 #define token_paster(x,y) x ## y
78 #define token_evaluator(x,y) token_paster(x,y)
79 #define ao_enable_output(port,pin,v) cc1111_enable_output(port,token_evaluator(port,DIR), token_evaluator(port,SEL), 1 << pin, 1 << v)