c34206e6cc8aef6c0550484e61320df69c61de77
[fw/altos] / src / attiny / ao_arch.h
1 /*
2  * Copyright © 2011 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 #ifndef _AO_ARCH_H_
19 #define _AO_ARCH_H_
20
21 #include <stdio.h>
22 #include <avr/io.h>
23 #include <avr/interrupt.h>
24 #include <avr/sleep.h>
25
26 #define F_CPU  8000000UL        // 8 MHz
27
28 /*
29  * AVR definitions and code fragments for AltOS
30  */
31
32 #define AO_STACK_SIZE   116
33
34 /* Various definitions to make GCC look more like SDCC */
35
36 #define ao_arch_naked_declare   __attribute__((naked))
37 #define ao_arch_naked_define
38 #define __pdata
39 #define __data
40 #define __xdata
41 #define __code const
42 #define __reentrant
43 #define __critical
44 #define __interrupt(n)
45 #define __at(n)
46
47 #define ao_arch_reboot()        /* XXX */
48
49 #define ao_arch_nop()           asm("nop")
50
51 #define ao_arch_interrupt(n)    /* nothing */
52
53 #undef putchar
54 #undef getchar
55 #define putchar(c)      ao_putchar(c)
56 #define getchar         ao_getchar
57
58 #define ao_arch_cpu_idle() do {                 \
59                 sleep_enable();                 \
60                 sei();                          \
61                 sleep_cpu();                    \
62                 sleep_disable();                \
63         } while (0)
64
65 #define ao_arch_critical(b) do { cli(); do { b } while (0); sei(); } while (0)
66
67 #define ao_mutex_get(m)
68 #define ao_mutex_put(m)
69
70 void
71 ao_delay_until(uint16_t target);
72
73 /* We can't hit 100 Hz, but we can hit 125 */
74 #define AO_HERTZ        125
75
76 void
77 ao_eeprom_read(uint16_t addr, void *buf, uint16_t len);
78
79 void
80 ao_eeprom_write(uint16_t addr, void *buf, uint16_t len);
81
82 #endif /* _AO_ARCH_H_ */