Merge branch 'lpc'
[fw/altos] / src / lpc / ao_interrupt.c
1 /*
2  * Copyright © 2013 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 <string.h>
20
21 extern void main(void);
22 extern char __stack__;
23 extern char __text_start__, __text_end__;
24 extern char __data_start__, __data_end__;
25 extern char __bss_start__, __bss_end__;
26
27 /* Interrupt functions */
28
29 void lpc_halt_isr(void)
30 {
31         ao_panic(AO_PANIC_CRASH);
32 }
33
34 void lpc_ignore_isr(void)
35 {
36 }
37
38 int x;
39
40 void start(void) {
41         x = 0;
42         memcpy(&__data_start__, &__text_end__, &__data_end__ - &__data_start__);
43         memset(&__bss_start__, '\0', &__bss_end__ - &__bss_start__);
44         main();
45 }
46
47 #define STRINGIFY(x) #x
48
49 #define isr(name) \
50         void __attribute__ ((weak)) lpc_ ## name ## _isr(void); \
51         _Pragma(STRINGIFY(weak lpc_ ## name ## _isr = lpc_ignore_isr))
52
53 #define isr_halt(name) \
54         void __attribute__ ((weak)) lpc_ ## name ## _isr(void); \
55         _Pragma(STRINGIFY(weak lpc_ ## name ## _isr = lpc_halt_isr))
56
57 isr(nmi)
58 isr_halt(hardfault)
59 isr_halt(memmanage)
60 isr_halt(busfault)
61 isr_halt(usagefault)
62 isr(svc)
63 isr(debugmon)
64 isr(pendsv)
65 isr(systick)
66
67 isr(pin_int0)   /* IRQ0 */
68 isr(pin_int1)
69 isr(pin_int2)
70 isr(pin_int3)
71 isr(pin_int4)   /* IRQ4 */
72 isr(pin_int5)
73 isr(pin_int6)
74 isr(pin_int7)
75
76 isr(gint0)      /* IRQ8 */
77 isr(gint1)
78 isr(ssp1)
79 isr(i2c)
80
81 isr(ct16b0)     /* IRQ16 */
82 isr(ct16b1)
83 isr(ct32b0)
84 isr(ct32b1)
85 isr(ssp0)       /* IRQ20 */
86 isr(usart)
87 isr(usb_irq)
88 isr(usb_fiq)
89
90 isr(adc)        /* IRQ24 */
91 isr(wwdt)
92 isr(bod)
93 isr(flash)
94
95 isr(usb_wakeup)
96
97 #define i(addr,name)    [(addr)/4] = lpc_ ## name ## _isr
98 #define c(addr,value)   [(addr)/4] = (value)
99
100 __attribute__ ((section(".interrupt")))
101 const void *lpc_interrupt_vector[] = {
102         [0] = &__stack__,
103         [1] = start,
104         i(0x08, nmi),
105         i(0x0c, hardfault),
106         c(0x10, 0),
107         c(0x14, 0),
108         c(0x18, 0),
109         c(0x1c, 0),
110         c(0x20, 0),
111         c(0x24, 0),
112         c(0x28, 0),
113         i(0x2c, svc),
114         i(0x30, hardfault),
115         i(0x34, hardfault),
116         i(0x38, pendsv),
117         i(0x3c, systick),
118
119         i(0x40, pin_int0),      /* IRQ0 */
120         i(0x44, pin_int1),
121         i(0x48, pin_int2),
122         i(0x4c, pin_int3),
123         i(0x50, pin_int4),      /* IRQ4 */
124         i(0x54, pin_int5),
125         i(0x58, pin_int6),
126         i(0x5c, pin_int7),
127
128         i(0x60, gint0),         /* IRQ8 */
129         i(0x64, gint1),
130         i(0x68, hardfault),
131         i(0x6c, hardfault),
132         i(0x70, hardfault),     /* IRQ12 */
133         i(0x74, hardfault),
134         i(0x78, ssp1),
135         i(0x7c, i2c),
136
137         i(0x80, ct16b0),        /* IRQ16 */
138         i(0x84, ct16b1),
139         i(0x88, ct32b0),
140         i(0x8c, ct32b1),
141         i(0x90, ssp0),          /* IRQ20 */
142         i(0x94, usart),
143         i(0x98, usb_irq),
144         i(0x9c, usb_fiq),
145
146         i(0xa0, adc),           /* IRQ24 */
147         i(0xa4, wwdt),
148         i(0xa8, bod),
149         i(0xac, flash),
150
151         i(0xb0, hardfault),     /* IRQ28 */
152         i(0xb4, hardfault),
153         i(0xb8, usb_wakeup),
154         i(0xbc, hardfault),     
155 };