altos: Initial STMF04x support
[fw/altos] / src / stmf0 / ao_interrupt.c
1 /*
2  * Copyright © 2012 Keith Packard <keithp@keithp.com>
3  *
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.
7  *
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.
12  *
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.
16  */
17
18 #include <ao.h>
19 #include "stm32f0.h"
20 #include <string.h>
21 #include <ao_boot.h>
22
23 extern void main(void);
24 extern char __stack__;
25 extern char __text_start__, __text_end__;
26 extern char __data_start__, __data_end__;
27 extern char __bss_start__, __bss_end__;
28
29 /* Interrupt functions */
30
31 void stm_halt_isr(void)
32 {
33         ao_panic(AO_PANIC_CRASH);
34 }
35
36 void stm_ignore_isr(void)
37 {
38 }
39
40 const void *stm_interrupt_vector[];
41
42 uint32_t
43 stm_flash_size(void) {
44         uint16_t        dev_id = stm_dev_id();
45         uint16_t        kbytes = 0;
46
47         switch (dev_id) {
48         case 0x445:
49                 kbytes = 32;    /* assume 32kB until we figure this out */
50                 break;
51         }
52         return (uint32_t) kbytes * 1024;
53 }
54
55 void start(void)
56 {
57 #if 0
58 #ifdef AO_BOOT_CHAIN
59         if (ao_boot_check_chain()) {
60 #ifdef AO_BOOT_PIN
61                 ao_boot_check_pin();
62 #endif
63         }
64 #endif
65 #endif
66         memcpy(&__data_start__, &__text_end__, &__data_end__ - &__data_start__);
67         memset(&__bss_start__, '\0', &__bss_end__ - &__bss_start__);
68         main();
69 }
70
71 #define STRINGIFY(x) #x
72
73 #define isr(name) \
74         void __attribute__ ((weak)) stm_ ## name ## _isr(void); \
75         _Pragma(STRINGIFY(weak stm_ ## name ## _isr = stm_ignore_isr))
76
77 #define isr_halt(name) \
78         void __attribute__ ((weak)) stm_ ## name ## _isr(void); \
79         _Pragma(STRINGIFY(weak stm_ ## name ## _isr = stm_halt_isr))
80
81 isr(nmi)
82 isr_halt(hardfault)
83 isr_halt(memmanage)
84 isr_halt(busfault)
85 isr_halt(usagefault)
86 isr(svc)
87 isr(debugmon)
88 isr(pendsv)
89 isr(systick)
90 isr(wwdg)
91 isr(pvd)
92 isr(rtc)
93 isr(flash)
94 isr(rcc_crs)
95 isr(exti0_1)
96 isr(exti2_3)
97 isr(exti4_15)
98 isr(tsc)
99 isr(dma_ch1)
100 isr(dma_ch2_3_dma2_ch1_2)
101 isr(dma_ch4_5_6_7_dma2_ch3_4_5)
102 isr(adc_comp)
103 isr(tim1_brk_up_trg_com)
104 isr(tim1_cc)
105 isr(tim2)
106 isr(tim3)
107 isr(tim6_dac)
108 isr(tim7)
109 isr(tim14)
110 isr(tim15)
111 isr(tim16)
112 isr(tim17)
113 isr(i2c1)
114 isr(i2c2)
115 isr(spi1)
116 isr(spi2)
117 isr(usart1)
118 isr(usart2)
119 isr(usart3_4_5_6_7_8)
120 isr(cec_can)
121 isr(usb)
122
123 #define i(addr,name)    [(addr)/4] = stm_ ## name ## _isr
124
125 __attribute__ ((section(".interrupt")))
126 const void *stm_interrupt_vector[] = {
127         [0] = &__stack__,
128         [1] = start,
129         i(0x08, nmi),
130         i(0x0c, hardfault),
131         i(0x2c, svc),
132         i(0x30, debugmon),
133         i(0x38, pendsv),
134         i(0x3c, systick),
135         i(0x40, wwdg),          /* IRQ0 */
136         i(0x44, pvd),
137         i(0x48, rtc),
138         i(0x4c, flash),
139         i(0x50, rcc_crs),
140         i(0x54, exti0_1),
141         i(0x58, exti2_3),
142         i(0x5c, exti4_15),
143         i(0x60, tsc),
144         i(0x64, dma_ch1),
145         i(0x68, dma_ch2_3_dma2_ch1_2),
146         i(0x6c, dma_ch4_5_6_7_dma2_ch3_4_5),
147         i(0x70, adc_comp),
148         i(0x74, tim1_brk_up_trg_com),
149         i(0x78, tim1_cc),
150         i(0x7c, tim2),
151         i(0x80, tim3),
152         i(0x84, tim6_dac),
153         i(0x88, tim7),
154         i(0x8c, tim14),
155         i(0x90, tim15),
156         i(0x94, tim16),
157         i(0x98, tim17),
158         i(0x9c, i2c1),
159         i(0xa0, i2c2),
160         i(0xa4, spi1),
161         i(0xa8, spi2),
162         i(0xac, usart1),
163         i(0xb0, usart2),
164         i(0xb4, usart3_4_5_6_7_8),
165         i(0xb8, cec_can),
166         i(0xbc, usb),
167 };