altos/test: Adjust CRC error rate after FEC fix
[fw/altos] / src / stm / 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; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #include <ao.h>
20 #include "stm32l.h"
21 #include <string.h>
22 #include <ao_boot.h>
23
24 extern void main(void);
25
26 /* Interrupt functions */
27
28 void stm_halt_isr(void)
29 {
30         ao_panic(AO_PANIC_CRASH);
31 }
32
33 void stm_ignore_isr(void)
34 {
35 }
36
37 uint32_t
38 stm_flash_size(void) {
39         uint16_t        dev_id = stm_dev_id();
40         uint16_t        kbytes = 0;
41
42         switch (dev_id) {
43         case 0x416:     /* cat 1 */
44                 kbytes = stm_flash_size_medium.f_size;
45                 break;
46         case 0x429:     /* cat 2 */
47                 kbytes = stm_flash_size_medium.f_size & 0xff;
48                 break;
49         case 0x427:     /* cat 3 */
50                 kbytes = stm_flash_size_large.f_size;
51                 break;
52         case 0x436:     /* cat 4 */
53                 switch (stm_flash_size_large.f_size) {
54                 case 0:
55                         kbytes = 256;
56                         break;
57                 case 1:
58                         kbytes = 384;
59                         break;
60                 }
61                 break;
62         case 0x437:     /* cat 5 */
63                 kbytes = stm_flash_size_large.f_size;
64                 break;
65         }
66         return (uint32_t) kbytes * 1024;
67 }
68
69 #define STRINGIFY(x) #x
70
71 #define isr(name) \
72         void __attribute__ ((weak)) stm_ ## name ## _isr(void); \
73         _Pragma(STRINGIFY(weak stm_ ## name ## _isr = stm_ignore_isr))
74
75 #define isr_halt(name) \
76         void __attribute__ ((weak)) stm_ ## name ## _isr(void); \
77         _Pragma(STRINGIFY(weak stm_ ## name ## _isr = stm_halt_isr))
78
79 isr(nmi)
80 isr_halt(hardfault)
81 isr_halt(memmanage)
82 isr_halt(busfault)
83 isr_halt(usagefault)
84 isr(svc)
85 isr(debugmon)
86 isr(pendsv)
87 isr(systick)
88 isr(wwdg)
89 isr(pvd)
90 isr(tamper_stamp)
91 isr(rtc_wkup)
92 isr(flash)
93 isr(rcc)
94 isr(exti0)
95 isr(exti1)
96 isr(exti2)
97 isr(exti3)
98 isr(exti4)
99 isr(dma1_channel1)
100 isr(dma1_channel2)
101 isr(dma1_channel3)
102 isr(dma1_channel4)
103 isr(dma1_channel5)
104 isr(dma1_channel6)
105 isr(dma1_channel7)
106 isr(adc1)
107 isr(usb_hp)
108 isr(usb_lp)
109 isr(dac)
110 isr(comp)
111 isr(exti9_5)
112 isr(lcd)
113 isr(tim9)
114 isr(tim10)
115 isr(tim11)
116 isr(tim2)
117 isr(tim3)
118 isr(tim4)
119 isr(i2c1_ev)
120 isr(i2c1_er)
121 isr(i2c2_ev)
122 isr(i2c2_er)
123 isr(spi1)
124 isr(spi2)
125 isr(usart1)
126 isr(usart2)
127 isr(usart3)
128 isr(exti15_10)
129 isr(rtc_alarm)
130 isr(usb_fs_wkup)
131 isr(tim6)
132 isr(tim7)
133
134 #define i(addr,name)    [(addr)/4] = stm_ ## name ## _isr
135
136 extern char __stack[];
137 void _start(void) __attribute__((__noreturn__));
138 void main(void) __attribute__((__noreturn__));
139 void ao_setup(void) __attribute__((constructor));
140
141 /* This must be exactly 256 bytes long so that the configuration data
142  * gets loaded at the right place
143  */
144
145 __attribute__ ((section(".init")))
146 const void * const __interrupt_vector[64] = {
147         [0] = &__stack,
148         [1] = _start,
149         i(0x08, nmi),
150         i(0x0c, hardfault),
151         i(0x10, memmanage),
152         i(0x14, busfault),
153         i(0x18, usagefault),
154         i(0x2c, svc),
155         i(0x30, debugmon),
156         i(0x38, pendsv),
157         i(0x3c, systick),
158         i(0x40, wwdg),
159         i(0x44, pvd),
160         i(0x48, tamper_stamp),
161         i(0x4c, rtc_wkup),
162         i(0x50, flash),
163         i(0x54, rcc),
164         i(0x58, exti0),
165         i(0x5c, exti1),
166         i(0x60, exti2),
167         i(0x64, exti3),
168         i(0x68, exti4),
169         i(0x6c, dma1_channel1),
170         i(0x70, dma1_channel2),
171         i(0x74, dma1_channel3),
172         i(0x78, dma1_channel4),
173         i(0x7c, dma1_channel5),
174         i(0x80, dma1_channel6),
175         i(0x84, dma1_channel7),
176         i(0x88, adc1),
177         i(0x8c, usb_hp),
178         i(0x90, usb_lp),
179         i(0x94, dac),
180         i(0x98, comp),
181         i(0x9c, exti9_5),
182         i(0xa0, lcd),
183         i(0xa4, tim9),
184         i(0xa8, tim10),
185         i(0xac, tim11),
186         i(0xb0, tim2),
187         i(0xb4, tim3),
188         i(0xb8, tim4),
189         i(0xbc, i2c1_ev),
190         i(0xc0, i2c1_er),
191         i(0xc4, i2c2_ev),
192         i(0xc8, i2c2_er),
193         i(0xcc, spi1),
194         i(0xd0, spi2),
195         i(0xd4, usart1),
196         i(0xd8, usart2),
197         i(0xdc, usart3),
198         i(0xe0, exti15_10),
199         i(0xe4, rtc_alarm),
200         i(0xe8, usb_fs_wkup),
201         i(0xec, tim6),
202         i(0xf0, tim7),
203 };
204
205 void __attribute__((constructor)) ao_setup(void) {
206 #ifdef AO_BOOT_CHAIN
207         if (ao_boot_check_chain()) {
208 #ifdef AO_BOOT_PIN
209                 if (ao_boot_check_pin())
210 #endif
211                 {
212                         ao_boot_chain(AO_BOOT_APPLICATION_BASE);
213                 }
214         }
215 #endif
216         /* Set interrupt vector table offset */
217         stm_nvic.vto = (uint32_t) &__interrupt_vector;
218 }