altos: Add attiny architecture files
[fw/altos] / src / attiny / ao_arch_funcs.h
1 /*
2  * Copyright © 2012 Keith Packard <keithp@keithp.com>
3  *
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.
7  *
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.
12  *
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.
16  */
17
18 /*
19  * ao_spi.c
20  */
21
22 #define ao_spi_get_mask(reg,mask,bus,speed) do {        \
23                 (reg) &= ~(mask);               \
24         } while (0)
25
26 #define ao_spi_put_mask(reg,mask,bus) do {      \
27                 (reg) |= (mask);                \
28         } while (0)
29
30 #define ao_spi_get_bit(reg,bit,pin,bus,speed) do {      \
31                 (pin) = 0;                      \
32         } while (0)
33
34 #define ao_spi_put_bit(reg,bit,pin,bus) do {    \
35                 (pin) = 1;                      \
36         } while (0)
37
38
39 #define ao_gpio_token_paster(x,y)               x ## y
40 #define ao_gpio_token_evaluator(x,y)    ao_gpio_token_paster(x,y)
41
42 #define ao_gpio_set(port, bit, pin, v) do {     \
43                 if (v)                          \
44                         PORTB |= (1 << bit);    \
45                 else                            \
46                         PORTB &= ~(1 << bit);   \
47         } while (0)
48
49 /*
50  * The SPI mutex must be held to call either of these
51  * functions -- this mutex covers the entire SPI operation,
52  * from chip select low to chip select high
53  */
54
55 #define ao_enable_output(port, bit, pin, v) do {                        \
56                 ao_gpio_set(port, bit, pin, v);                         \
57                 ao_gpio_token_evaluator(DDR,port) |= (1 << bit);        \
58         } while (0)
59
60
61 void
62 ao_spi_send_bus(void __xdata *block, uint16_t len) __reentrant;
63
64 void
65 ao_spi_recv_bus(void __xdata *block, uint16_t len) __reentrant;
66
67 #define ao_spi_send(block, len, bus) ao_spi_send_bus(block, len)
68 #define ao_spi_recv(block, len, bus) ao_spi_recv_bus(block, len)
69
70 void
71 ao_spi_init(void);
72
73 #define ao_spi_get(bus, speed)
74 #define ao_spi_put(bus)
75
76 #define ao_spi_init_cs(port, mask) do {         \
77                 PORTB |= (mask);                \
78                 DDRB |= (mask);         \
79         } while (0)
80
81 /* I2C */
82
83 void
84 ao_i2c_get(uint8_t i2c_index);
85
86 uint8_t
87 ao_i2c_start_bus(uint8_t address);
88
89 #define ao_i2c_start(i,a)       ao_i2c_start_bus(a)
90
91 void
92 ao_i2c_put(uint8_t i2c_index);
93
94 uint8_t
95 ao_i2c_send_bus(void *block, uint16_t len, uint8_t stop);
96
97 #define ao_i2c_send(b,l,i,s) ao_i2c_send_bus(b,l.s)
98
99 uint8_t
100 ao_i2c_send_fixed_bus(uint8_t value, uint16_t len, uint8_t stop);
101
102 #define ao_i2c_send_fixed(v,l,i,s) ao_i2c_send_fixed_bus(v,l.s)
103
104 uint8_t
105 ao_i2c_recv_bus(void *block, uint16_t len, uint8_t stop);
106
107 #define ao_i2c_recv(b,l,i,s) ao_i2c_recv_bus(b,l.s)
108
109 void
110 ao_i2c_init(void);
111
112 /* notask.c */
113
114 uint8_t
115 ao_sleep(__xdata void *wchan);
116
117 void
118 ao_wakeup(__xdata void *wchan);
119
120 extern alt_t    ao_max_height;
121
122 extern void ao_report_altitude(void);
123
124 void ao_delay_us(uint16_t us);
125