altos/test: Adjust CRC error rate after FEC fix
[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; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 /*
20  * ao_spi.c
21  */
22
23 #define ao_spi_get_mask(reg,mask,bus,speed) do {        \
24                 (reg) &= (uint8_t) ~(mask);             \
25         } while (0)
26
27 #define ao_spi_put_mask(reg,mask,bus) do {      \
28                 (reg) |= (mask);                \
29         } while (0)
30
31 #define ao_spi_get_bit(reg,bit,bus,speed) ao_spi_get_mask(reg,(1<<(bit)),bus,speed)
32
33 #define ao_spi_put_bit(reg,bit,bus) ao_spi_put_mask(reg,(1<<(bit)),bus)
34
35 #define ao_gpio_token_paster(x,y)               x ## y
36 #define ao_gpio_token_evaluator(x,y)    ao_gpio_token_paster(x,y)
37
38 #define ao_gpio_set(port, bit, v) do {  \
39                 if (v)                          \
40                         PORTB |= (1 << bit);    \
41                 else                            \
42                         PORTB &= ~(1 << bit);   \
43         } while (0)
44
45 #define ao_gpio_get(port, bit)  ((PORTB >> (bit)) & 1)
46
47 /*
48  * The SPI mutex must be held to call either of these
49  * functions -- this mutex covers the entire SPI operation,
50  * from chip select low to chip select high
51  */
52
53 #define ao_enable_output(port, bit, v) do {                     \
54                 ao_gpio_set(port, bit, v);                              \
55                 ao_gpio_token_evaluator(DDR,port) |= (1 << bit);        \
56         } while (0)
57
58
59 void
60 ao_spi_send_bus(void *block, uint16_t len);
61
62 void
63 ao_spi_recv_bus(void *block, uint16_t len);
64
65 #define ao_spi_send(block, len, bus) ao_spi_send_bus(block, len)
66 #define ao_spi_recv(block, len, bus) ao_spi_recv_bus(block, len)
67
68 #define AO_SPI_DUPLEX   0
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(void *wchan);
116
117 void
118 ao_wakeup(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
126 void
127 ao_led_toggle(uint8_t colors);