Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
[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 #define AO_PORT_TYPE    uint8_t
35
36 /* Various definitions to make GCC look more like SDCC */
37
38 #define ao_arch_naked_declare   __attribute__((naked))
39 #define ao_arch_naked_define
40 #define __pdata
41 #define __data
42 #define __xdata
43 #define __code const
44 #define __reentrant
45 #define __critical
46 #define __interrupt(n)
47 #define __at(n)
48
49 #define ao_arch_reboot()        /* XXX */
50
51 #define ao_arch_nop()           asm("nop")
52
53 #define ao_arch_interrupt(n)    /* nothing */
54
55 #undef putchar
56 #undef getchar
57 #define putchar(c)      ao_putchar(c)
58 #define getchar         ao_getchar
59
60 #define ao_arch_wait_interrupt() do {           \
61                 sleep_enable();                 \
62                 sei();                          \
63                 sleep_cpu();                    \
64                 sleep_disable();                \
65         } while (0)
66
67 #define ao_arch_critical(b) do { cli(); do { b } while (0); sei(); } while (0)
68
69 #define ao_arch_block_interrupts()      cli()
70 #define ao_arch_release_interrupts()    sei()
71
72 #define ao_mutex_get(m)
73 #define ao_mutex_put(m)
74
75 void
76 ao_delay_until(uint16_t target);
77
78 /* We can't hit 100 Hz, but we can hit 125 */
79 #define AO_HERTZ        125
80
81 void
82 ao_eeprom_read(uint16_t addr, void *buf, uint16_t len);
83
84 void
85 ao_eeprom_write(uint16_t addr, void *buf, uint16_t len);
86
87 #endif /* _AO_ARCH_H_ */