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 #define AO_LED_TYPE uint16_t
32 /* Various definitions to make GCC look more like SDCC */
34 #define ao_arch_naked_declare __attribute__((naked))
35 #define ao_arch_naked_define
42 #define __interrupt(n)
45 #define ao_arch_reboot() /* XXX */
47 #define ao_arch_nop() asm("nop")
49 #define ao_arch_interrupt(n) /* nothing */
53 #define putchar(c) ao_putchar(c)
54 #define getchar ao_getchar
56 extern void putchar(char c);
57 extern char getchar(void);
58 extern void ao_avr_stdio_init(void);
60 extern const uint16_t ao_serial_number;
62 #define ARM_PUSH32(stack, val) (*(--(stack)) = (val))
64 #define ao_arch_task_members\
65 uint32_t *sp; /* saved stack pointer */
67 #define cli() asm("cpsid i")
68 #define sei() asm("cpsie i")
70 #define ao_arch_init_stack(task, start) do { \
71 uint32_t *sp = (uint32_t *) (task->stack + AO_STACK_SIZE); \
72 uint32_t a = (uint32_t) start; \
78 /* PRIMASK with interrupts enabled */ \
81 /* Return address (goes into LR) */ \
84 /* Clear register values r0-r12 */ \
92 #define ao_arch_save_regs() do { \
97 asm("mrs %0,apsr" : "=&r" (apsr)); \
98 asm("push {%0}" : : "r" (apsr)); \
101 asm("mrs %0,primask" : "=&r" (primask)); \
102 asm("push {%0}" : : "r" (primask)); \
104 /* Save general registers */ \
105 asm("push {r0-r12,lr}\n"); \
108 #define ao_arch_save_stack() do { \
110 asm("mov %0,sp" : "=&r" (sp) ); \
111 ao_cur_task->sp = (sp); \
112 if ((uint8_t *) sp < ao_cur_task->stack) \
113 ao_panic (AO_PANIC_STACK); \
116 #define ao_arch_isr_stack() /* nothing */
118 #define ao_arch_cpu_idle() do { \
122 #define ao_arch_restore_stack() do { \
126 sp = (uint32_t) ao_cur_task->sp; \
128 /* Switch stacks */ \
129 asm("mov sp, %0" : : "r" (sp) ); \
131 /* Restore general registers */ \
132 asm("pop {r0-r12,lr}\n"); \
134 /* Restore PRIMASK */ \
135 asm("pop {%0}" : "=&r" (primask) ); \
136 asm("msr primask,%0" : : "r" (primask) ); \
139 asm("pop {%0}" : "=&r" (apsr) ); \
140 asm("msr apsr,%0" : : "r" (apsr) ); \
142 /* Return to calling function */ \
146 #define ao_arch_critical(b) do { cli(); do { b } while (0); sei(); } while (0)
148 #define AO_ARM_NUM_ADC 12
151 uint16_t tick; /* tick when the sample was read */
152 uint16_t adc[AO_ARM_NUM_ADC]; /* samples */
156 * For now, we're running at a weird frequency
158 #define STM_APB1 (16000000 * 6 / 4)
160 void ao_lcd_stm_init(void);
162 void ao_lcd_font_init(void);
164 void ao_lcd_font_string(char *s);
166 #define USE_SERIAL_STDIN (USE_SERIAL_1_STDIN + USE_SERIAL_2_STDIN + USE_SERIAL_3_STDIN)
169 ao_serial1_getchar(void);
172 ao_serial1_putchar(char c);
175 ao_serial1_pollchar(void);
178 ao_serial1_set_speed(uint8_t speed);
181 ao_serial2_getchar(void);
184 ao_serial2_putchar(char c);
187 ao_serial2_pollchar(void);
190 ao_serial2_set_speed(uint8_t speed);
193 ao_serial3_getchar(void);
196 ao_serial3_putchar(char c);
199 ao_serial3_pollchar(void);
202 ao_serial3_set_speed(uint8_t speed);
204 extern uint32_t ao_radio_cal;
206 #endif /* _AO_ARCH_H_ */