2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
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.
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.
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.
22 #include <avr/interrupt.h>
29 #define F_CPU 16000000UL // 16 MHz
31 #define F_CPU 8000000UL // 8 MHz
35 * AVR definitions and code fragments for AltOS
38 #define AO_STACK_SIZE 128
40 /* Various definitions to make GCC look more like SDCC */
42 #define ao_arch_naked_declare __attribute__((naked))
43 #define ao_arch_naked_define
50 #define __interrupt(n)
52 #define ao_arch_reboot() /* XXX */
54 #define ao_arch_nop() asm("nop")
56 #define ao_arch_interrupt(n) /* nothing */
60 #define putchar(c) ao_putchar(c)
61 #define getchar ao_getchar
63 extern void putchar(char c);
64 extern char getchar(void);
66 extern int ao_serial_number;
68 #define ao_arch_init_stack(task, start) do { \
69 uint8_t *sp = task->stack + AO_STACK_SIZE - 1; \
70 uint16_t a = (uint16_t) start; \
73 /* Return address */ \
75 PUSH8(sp, (a >> 8)); \
77 /* Clear register values */ \
82 /* SREG with interrupts enabled */ \
87 #define ao_arch_save_context() do { \
88 asm("push r31" "\n\t" "push r30"); \
89 asm("push r29" "\n\t" "push r28" "\n\t" "push r27" "\n\t" "push r26" "\n\t" "push r25"); \
90 asm("push r24" "\n\t" "push r23" "\n\t" "push r22" "\n\t" "push r21" "\n\t" "push r20"); \
91 asm("push r19" "\n\t" "push r18" "\n\t" "push r17" "\n\t" "push r16" "\n\t" "push r15"); \
92 asm("push r14" "\n\t" "push r13" "\n\t" "push r12" "\n\t" "push r11" "\n\t" "push r10"); \
93 asm("push r9" "\n\t" "push r8" "\n\t" "push r7" "\n\t" "push r6" "\n\t" "push r5"); \
94 asm("push r4" "\n\t" "push r3" "\n\t" "push r2" "\n\t" "push r1" "\n\t" "push r0"); \
95 asm("in r0, __SREG__" "\n\t" "push r0"); \
99 #endif /* _AO_ARCH_H_ */