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; \
76 /* PRIMASK with interrupts enabled */ \
79 /* Return address (goes into LR) */ \
82 /* Clear register values r0-r12 */ \
90 #define ao_arch_save_regs() do { \
95 asm("mrs %0,apsr" : "=&r" (apsr)); \
96 asm("push {%0}" : : "r" (apsr)); \
99 asm("mrs %0,primask" : "=&r" (primask)); \
100 asm("push {%0}" : : "r" (primask)); \
102 /* Save general registers */ \
103 asm("push {r0-r12,lr}\n"); \
106 #define ao_arch_save_stack() do { \
108 asm("mov %0,sp" : "=&r" (sp) ); \
109 ao_cur_task->sp = (sp); \
110 if ((uint8_t *) sp < ao_cur_task->stack) \
111 ao_panic (AO_PANIC_STACK); \
114 #define ao_arch_isr_stack() /* nothing */
116 #define ao_arch_cpu_idle() do { \
120 #define ao_arch_restore_stack() do { \
124 sp = (uint32_t) ao_cur_task->sp; \
126 /* Switch stacks */ \
127 asm("mov sp, %0" : : "r" (sp) ); \
129 /* Restore general registers */ \
130 asm("pop {r0-r12,lr}\n"); \
132 /* Restore PRIMASK */ \
133 asm("pop {%0}" : "=&r" (primask) ); \
134 asm("msr primask,%0" : : "r" (primask) ); \
137 asm("pop {%0}" : "=&r" (apsr) ); \
138 asm("msr apsr,%0" : : "r" (apsr) ); \
140 /* Return to calling function */ \
144 #define ao_arch_critical(b) do { cli(); do { b } while (0); sei(); } while (0)
146 #define AO_ARM_NUM_ADC 12
149 uint16_t tick; /* tick when the sample was read */
150 uint16_t adc[AO_ARM_NUM_ADC]; /* samples */
154 * For now, we're running at a weird frequency
156 #define STM_APB1 (16000000 * 6 / 4)
158 void ao_lcd_stm_init(void);
160 void ao_lcd_font_init(void);
162 void ao_lcd_font_string(char *s);
164 #endif /* _AO_ARCH_H_ */