summaryrefslogtreecommitdiff
path: root/src/attiny/ao_arch_funcs.h
blob: 76dc7820a0d2460d583b74696a28d993bd1e8079 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Copyright © 2012 Keith Packard <keithp@keithp.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 */

/*
 * ao_spi.c
 */

#define ao_spi_get_mask(reg,mask,bus,speed) do {	\
		(reg) &= ~(mask);			\
	} while (0)

#define ao_spi_put_mask(reg,mask,bus) do {	\
		(reg) |= (mask);		\
	} while (0)

#define ao_spi_get_bit(reg,bit,pin,bus,speed) ao_spi_get_mask(reg,(1<<(bit)),bus,speed)

#define ao_spi_put_bit(reg,bit,pin,bus) ao_spi_put_mask(reg,(1<<(bit)),bus)

#define ao_gpio_token_paster(x,y)		x ## y
#define ao_gpio_token_evaluator(x,y)	ao_gpio_token_paster(x,y)

#define ao_gpio_set(port, bit, pin, v) do {	\
		if (v)				\
			PORTB |= (1 << bit);	\
		else				\
			PORTB &= ~(1 << bit);	\
	} while (0)

/*
 * The SPI mutex must be held to call either of these
 * functions -- this mutex covers the entire SPI operation,
 * from chip select low to chip select high
 */

#define ao_enable_output(port, bit, pin, v) do {			\
		ao_gpio_set(port, bit, pin, v);				\
		ao_gpio_token_evaluator(DDR,port) |= (1 << bit);	\
	} while (0)


void
ao_spi_send_bus(void __xdata *block, uint16_t len) __reentrant;

void
ao_spi_recv_bus(void __xdata *block, uint16_t len) __reentrant;

#define ao_spi_send(block, len, bus) ao_spi_send_bus(block, len)
#define ao_spi_recv(block, len, bus) ao_spi_recv_bus(block, len)

void
ao_spi_init(void);

#define ao_spi_get(bus, speed)
#define ao_spi_put(bus)

#define ao_spi_init_cs(port, mask) do {		\
		PORTB |= (mask);		\
		DDRB |= (mask);		\
	} while (0)

/* I2C */

void
ao_i2c_get(uint8_t i2c_index);

uint8_t
ao_i2c_start_bus(uint8_t address);

#define ao_i2c_start(i,a)	ao_i2c_start_bus(a)

void
ao_i2c_put(uint8_t i2c_index);

uint8_t
ao_i2c_send_bus(void *block, uint16_t len, uint8_t stop);

#define ao_i2c_send(b,l,i,s) ao_i2c_send_bus(b,l.s)

uint8_t
ao_i2c_send_fixed_bus(uint8_t value, uint16_t len, uint8_t stop);

#define ao_i2c_send_fixed(v,l,i,s) ao_i2c_send_fixed_bus(v,l.s)

uint8_t
ao_i2c_recv_bus(void *block, uint16_t len, uint8_t stop);

#define ao_i2c_recv(b,l,i,s) ao_i2c_recv_bus(b,l.s)

void
ao_i2c_init(void);

/* notask.c */

uint8_t
ao_sleep(__xdata void *wchan);

void
ao_wakeup(__xdata void *wchan);

extern alt_t	ao_max_height;

extern void ao_report_altitude(void);

void ao_delay_us(uint16_t us);