2 * Copyright © 2012 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.
25 * STM32L definitions and code fragments for AltOS
28 #define AO_STACK_SIZE 1024
30 /* Various definitions to make GCC look more like SDCC */
32 #define ao_arch_naked_declare __attribute__((naked))
33 #define ao_arch_naked_define
40 #define __interrupt(n)
43 #define ao_arch_reboot() /* XXX */
45 #define ao_arch_nop() asm("nop")
47 #define ao_arch_interrupt(n) /* nothing */
51 #define putchar(c) ao_putchar(c)
52 #define getchar ao_getchar
54 extern void putchar(char c);
55 extern char getchar(void);
56 extern void ao_avr_stdio_init(void);
58 extern const uint16_t ao_serial_number;
60 #define ARM_PUSH32(stack, val) (*(--(stack)) = (val))
62 #define ao_arch_task_members\
63 uint32_t *sp; /* saved stack pointer */
65 #define cli() asm("cpsid i")
66 #define sei() asm("cpsie i")
68 #define ao_arch_init_stack(task, start) do { \
69 uint32_t *sp = (uint32_t *) (task->stack + AO_STACK_SIZE); \
70 uint32_t a = (uint32_t) start; \
73 /* Return address (goes into LR) */ \
76 /* Clear register values */ \
86 #define ao_arch_save_regs() do { \
87 asm("push {r0-r12,lr}\n"); \
89 asm("mrs r0,apsr" "\n\t" "push {r0}"); \
93 #define ao_arch_save_stack() do { \
95 asm("mov %0,sp" : "=&r" (sp) ); \
96 ao_cur_task->sp = (uint32_t *) (sp); \
97 if ((uint8_t *) ao_cur_task->sp < ao_cur_task->stack) \
98 ao_panic (AO_PANIC_STACK); \
101 #define ao_arch_isr_stack() /* nothing */
103 #define ao_arch_cpu_idle() do { \
107 #define ao_arch_restore_stack() do { \
109 sp = (uint32_t) ao_cur_task->sp; \
111 asm("mov sp, %0" : : "r" (sp) ); \
112 asm("pop {r0}" "\n\t" "msr apsr,r0"); \
113 asm("pop {r0-r12,lr}\n"); \
117 #define ao_arch_critical(b) do { cli(); do { b } while (0); sei(); } while (0)
119 #define AO_ARM_NUM_ADC 12
122 uint16_t tick; /* tick when the sample was read */
123 uint16_t adc[AO_ARM_NUM_ADC]; /* samples */
127 * For now, we're running at a weird frequency
129 #define STM_APB1 (16000000 * 6 / 4)
131 #endif /* _AO_ARCH_H_ */