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.
23 #include <avr/interrupt.h>
24 #include <avr/sleep.h>
31 #define F_CPU 16000000UL // 16 MHz
33 #define F_CPU 8000000UL // 8 MHz
37 * AVR definitions and code fragments for AltOS
40 #define AO_STACK_SIZE 116
42 /* Various definitions to make GCC look more like SDCC */
44 #define ao_arch_naked_declare __attribute__((naked))
45 #define ao_arch_naked_define
52 #define __interrupt(n)
55 #define ao_arch_reboot() /* XXX */
57 #define ao_arch_nop() asm("nop")
59 #define ao_arch_interrupt(n) /* nothing */
63 #define putchar(c) ao_putchar(c)
64 #define getchar ao_getchar
66 extern void putchar(char c);
67 extern char getchar(void);
68 extern void ao_avr_stdio_init(void);
70 #define AO_ROMCONFIG_VERSION 2
72 #define AO_ROMCONFIG_SYMBOL(a) const
74 extern AO_ROMCONFIG_SYMBOL(0) uint16_t ao_serial_number;
76 #define AVR_PUSH8(stack, val) (*((stack)--) = (val))
78 extern uint8_t ao_cpu_sleep_disable;
80 #define ao_arch_task_globals uint8_t ao_cpu_sleep_disable;
82 #define ao_arch_task_members\
83 uint8_t *sp; /* saved stack pointer */
85 #define ao_arch_init_stack(task, start) do { \
86 uint8_t *sp = task->stack + AO_STACK_SIZE - 1; \
87 uint16_t a = (uint16_t) start; \
90 /* Return address */ \
92 AVR_PUSH8(sp, (a >> 8)); \
94 /* Clear register values */ \
99 /* SREG with interrupts enabled */ \
100 AVR_PUSH8(sp, 0x80); \
104 #define ao_arch_save_regs() do { \
105 asm("push r31" "\n\t" "push r30"); \
106 asm("push r29" "\n\t" "push r28" "\n\t" "push r27" "\n\t" "push r26" "\n\t" "push r25"); \
107 asm("push r24" "\n\t" "push r23" "\n\t" "push r22" "\n\t" "push r21" "\n\t" "push r20"); \
108 asm("push r19" "\n\t" "push r18" "\n\t" "push r17" "\n\t" "push r16" "\n\t" "push r15"); \
109 asm("push r14" "\n\t" "push r13" "\n\t" "push r12" "\n\t" "push r11" "\n\t" "push r10"); \
110 asm("push r9" "\n\t" "push r8" "\n\t" "push r7" "\n\t" "push r6" "\n\t" "push r5"); \
111 asm("push r4" "\n\t" "push r3" "\n\t" "push r2" "\n\t" "push r1" "\n\t" "push r0"); \
112 asm("in r0, __SREG__" "\n\t" "push r0"); \
116 #define ao_arch_save_stack() do { \
117 uint8_t sp_l, sp_h; \
118 asm("in %0,__SP_L__" : "=&r" (sp_l) ); \
119 asm("in %0,__SP_H__" : "=&r" (sp_h) ); \
120 ao_cur_task->sp = (uint8_t *) ((uint16_t) sp_l | ((uint16_t) sp_h << 8)); \
123 #define ao_arch_isr_stack() /* nothing */
125 #define ao_arch_cpu_idle() do { \
126 if (!ao_cpu_sleep_disable) \
130 #define ao_arch_restore_stack() do { \
131 uint8_t sp_l, sp_h; \
132 sp_l = (uint16_t) ao_cur_task->sp; \
133 sp_h = ((uint16_t) ao_cur_task->sp) >> 8; \
135 asm("out __SP_H__,%0" : : "r" (sp_h) ); \
136 asm("out __SP_L__,%0" : : "r" (sp_l) ); \
137 asm("pop r0" "\n\t" \
138 "out __SREG__, r0"); \
139 asm("pop r0" "\n\t" "pop r1" "\n\t" "pop r2" "\n\t" "pop r3" "\n\t" "pop r4"); \
140 asm("pop r5" "\n\t" "pop r6" "\n\t" "pop r7" "\n\t" "pop r8" "\n\t" "pop r9"); \
141 asm("pop r10" "\n\t" "pop r11" "\n\t" "pop r12" "\n\t" "pop r13" "\n\t" "pop r14"); \
142 asm("pop r15" "\n\t" "pop r16" "\n\t" "pop r17" "\n\t" "pop r18" "\n\t" "pop r19"); \
143 asm("pop r20" "\n\t" "pop r21" "\n\t" "pop r22" "\n\t" "pop r23" "\n\t" "pop r24"); \
144 asm("pop r25" "\n\t" "pop r26" "\n\t" "pop r27" "\n\t" "pop r28" "\n\t" "pop r29"); \
145 asm("pop r30" "\n\t" "pop r31"); \
149 #define ao_arch_critical(b) do { cli(); do { b } while (0); sei(); } while (0)
151 #define AO_TELESCIENCE_NUM_ADC 12
153 #endif /* _AO_ARCH_H_ */