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 CORTEX_M3_AIRCR ((uint32_t *) 0xe000ed0c)
47 #define ao_arch_reboot() (*((uint32_t *) 0xe000ed0c) = 0x05fa0004)
49 #define ao_arch_nop() asm("nop")
51 #define ao_arch_interrupt(n) /* nothing */
55 #define putchar(c) ao_putchar(c)
56 #define getchar ao_getchar
58 extern void putchar(char c);
59 extern char getchar(void);
60 extern void ao_avr_stdio_init(void);
62 extern const uint16_t ao_serial_number;
64 #define ARM_PUSH32(stack, val) (*(--(stack)) = (val))
66 #define ao_arch_task_members\
67 uint32_t *sp; /* saved stack pointer */
69 #define cli() asm("cpsid i")
70 #define sei() asm("cpsie i")
72 #define ao_arch_init_stack(task, start) do { \
73 uint32_t *sp = (uint32_t *) (task->stack + AO_STACK_SIZE); \
74 uint32_t a = (uint32_t) start; \
80 /* PRIMASK with interrupts enabled */ \
83 /* Return address (goes into LR) */ \
86 /* Clear register values r0-r12 */ \
94 #define ao_arch_save_regs() do { \
99 asm("mrs %0,apsr" : "=&r" (apsr)); \
100 asm("push {%0}" : : "r" (apsr)); \
103 asm("mrs %0,primask" : "=&r" (primask)); \
104 asm("push {%0}" : : "r" (primask)); \
106 /* Save general registers */ \
107 asm("push {r0-r12,lr}\n"); \
110 #define ao_arch_save_stack() do { \
112 asm("mov %0,sp" : "=&r" (sp) ); \
113 ao_cur_task->sp = (sp); \
114 if ((uint8_t *) sp < ao_cur_task->stack) \
115 ao_panic (AO_PANIC_STACK); \
118 #define ao_arch_isr_stack() /* nothing */
120 #define ao_arch_cpu_idle() do { \
124 #define ao_arch_restore_stack() do { \
128 sp = (uint32_t) ao_cur_task->sp; \
130 /* Switch stacks */ \
131 asm("mov sp, %0" : : "r" (sp) ); \
133 /* Restore general registers */ \
134 asm("pop {r0-r12,lr}\n"); \
136 /* Restore PRIMASK */ \
137 asm("pop {%0}" : "=&r" (primask) ); \
138 asm("msr primask,%0" : : "r" (primask) ); \
141 asm("pop {%0}" : "=&r" (apsr) ); \
142 asm("msr apsr,%0" : : "r" (apsr) ); \
144 /* Return to calling function */ \
148 #define ao_arch_critical(b) do { cli(); do { b } while (0); sei(); } while (0)
151 * For now, we're running at a weird frequency
155 #define AO_PLLSRC AO_HSE
157 #define AO_PLLSRC STM_HSI_FREQ
160 #define AO_PLLVCO (AO_PLLSRC * AO_PLLMUL)
161 #define AO_SYSCLK (AO_PLLVCO / AO_PLLDIV)
162 #define AO_HCLK (AO_SYSCLK / AO_AHB_PRESCALER)
163 #define AO_PCLK1 (AO_HCLK / AO_APB1_PRESCALER)
164 #define AO_PCLK2 (AO_HCLK / AO_APB2_PRESCALER)
166 #if AO_APB1_PRESCALER == 1
167 #define AO_TIM23467_CLK AO_PCLK1
169 #define AO_TIM23467_CLK (2 * AO_PCLK1)
172 #if AO_APB2_PRESCALER == 1
173 #define AO_TIM91011_CLK AO_PCLK2
175 #define AO_TIM91011_CLK (2 * AO_PCLK2)
178 void ao_lcd_stm_init(void);
180 void ao_lcd_font_init(void);
182 void ao_lcd_font_string(char *s);
185 ao_serial1_getchar(void);
188 ao_serial1_putchar(char c);
191 ao_serial1_pollchar(void);
194 ao_serial1_set_speed(uint8_t speed);
197 ao_serial2_getchar(void);
200 ao_serial2_putchar(char c);
203 ao_serial2_pollchar(void);
206 ao_serial2_set_speed(uint8_t speed);
209 ao_serial3_getchar(void);
212 ao_serial3_putchar(char c);
215 ao_serial3_pollchar(void);
218 ao_serial3_set_speed(uint8_t speed);
220 extern uint32_t ao_radio_cal;
225 #endif /* _AO_ARCH_H_ */