1 /*
2  * This file is part of the MicroPython project, http://micropython.org/
3  *
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2017 Glenn Ruben Bakke
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  */
26 
27 #include <stdint.h>
28 
29 extern uint32_t _estack;
30 extern uint32_t _sidata;
31 extern uint32_t _sdata;
32 extern uint32_t _edata;
33 extern uint32_t _sbss;
34 extern uint32_t _ebss;
35 
36 typedef void (*func)(void);
37 
38 extern void  _start(void) __attribute__((noreturn));
39 extern void SystemInit(void);
40 
Default_Handler(void)41 void Default_Handler(void) {
42     while (1);
43 }
44 
Reset_Handler(void)45 void Reset_Handler(void) {
46     uint32_t * p_src  = &_sidata;
47     uint32_t * p_dest = &_sdata;
48 
49     while (p_dest < &_edata) {
50       *p_dest++ = *p_src++;
51     }
52 
53     uint32_t * p_bss     = &_sbss;
54     uint32_t * p_bss_end = &_ebss;
55     while (p_bss < p_bss_end) {
56         *p_bss++ = 0ul;
57     }
58 
59     SystemInit();
60     _start();
61 }
62 
63 void NMI_Handler                 (void) __attribute__ ((weak, alias("Default_Handler")));
64 void HardFault_Handler           (void) __attribute__ ((weak, alias("Default_Handler")));
65 void MemoryManagement_Handler    (void) __attribute__ ((weak, alias("Default_Handler")));
66 void BusFault_Handler            (void) __attribute__ ((weak, alias("Default_Handler")));
67 void UsageFault_Handler          (void) __attribute__ ((weak, alias("Default_Handler")));
68 void SVC_Handler                 (void) __attribute__ ((weak, alias("Default_Handler")));
69 void DebugMon_Handler            (void) __attribute__ ((weak, alias("Default_Handler")));
70 void PendSV_Handler              (void) __attribute__ ((weak, alias("Default_Handler")));
71 void SysTick_Handler             (void) __attribute__ ((weak, alias("Default_Handler")));
72 
73 void POWER_CLOCK_IRQHandler      (void) __attribute__ ((weak, alias("Default_Handler")));
74 void RADIO_IRQHandler            (void) __attribute__ ((weak, alias("Default_Handler")));
75 void UARTE0_UART0_IRQHandler     (void) __attribute__ ((weak, alias("Default_Handler")));
76 void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
77 void SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
78 void NFCT_IRQHandler             (void) __attribute__ ((weak, alias("Default_Handler")));
79 void GPIOTE_IRQHandler           (void) __attribute__ ((weak, alias("Default_Handler")));
80 void SAADC_IRQHandler            (void) __attribute__ ((weak, alias("Default_Handler")));
81 void TIMER0_IRQHandler           (void) __attribute__ ((weak, alias("Default_Handler")));
82 void TIMER1_IRQHandler           (void) __attribute__ ((weak, alias("Default_Handler")));
83 void TIMER2_IRQHandler           (void) __attribute__ ((weak, alias("Default_Handler")));
84 void RTC0_IRQHandler             (void) __attribute__ ((weak, alias("Default_Handler")));
85 void TEMP_IRQHandler             (void) __attribute__ ((weak, alias("Default_Handler")));
86 void RNG_IRQHandler              (void) __attribute__ ((weak, alias("Default_Handler")));
87 void ECB_IRQHandler              (void) __attribute__ ((weak, alias("Default_Handler")));
88 void CCM_AAR_IRQHandler          (void) __attribute__ ((weak, alias("Default_Handler")));
89 void WDT_IRQHandler              (void) __attribute__ ((weak, alias("Default_Handler")));
90 void RTC1_IRQHandler             (void) __attribute__ ((weak, alias("Default_Handler")));
91 void QDEC_IRQHandler             (void) __attribute__ ((weak, alias("Default_Handler")));
92 void COMP_LPCOMP_IRQHandler      (void) __attribute__ ((weak, alias("Default_Handler")));
93 void SWI0_EGU0_IRQHandler        (void) __attribute__ ((weak, alias("Default_Handler")));
94 void SWI1_EGU1_IRQHandler        (void) __attribute__ ((weak, alias("Default_Handler")));
95 void SWI2_EGU2_IRQHandler        (void) __attribute__ ((weak, alias("Default_Handler")));
96 void SWI3_EGU3_IRQHandler        (void) __attribute__ ((weak, alias("Default_Handler")));
97 void SWI4_EGU4_IRQHandler        (void) __attribute__ ((weak, alias("Default_Handler")));
98 void SWI5_EGU5_IRQHandler        (void) __attribute__ ((weak, alias("Default_Handler")));
99 void TIMER3_IRQHandler           (void) __attribute__ ((weak, alias("Default_Handler")));
100 void TIMER4_IRQHandler           (void) __attribute__ ((weak, alias("Default_Handler")));
101 void PWM0_IRQHandler             (void) __attribute__ ((weak, alias("Default_Handler")));
102 void PDM_IRQHandler              (void) __attribute__ ((weak, alias("Default_Handler")));
103 void MWU_IRQHandler              (void) __attribute__ ((weak, alias("Default_Handler")));
104 void PWM1_IRQHandler             (void) __attribute__ ((weak, alias("Default_Handler")));
105 void PWM2_IRQHandler             (void) __attribute__ ((weak, alias("Default_Handler")));
106 void SPIM2_SPIS2_SPI2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
107 void RTC2_IRQHandler             (void) __attribute__ ((weak, alias("Default_Handler")));
108 void I2S_IRQHandler              (void) __attribute__ ((weak, alias("Default_Handler")));
109 void FPU_IRQHandler              (void) __attribute__ ((weak, alias("Default_Handler")));
110 void USBD_IRQHandler             (void) __attribute__ ((weak, alias("Default_Handler")));
111 void UARTE1_IRQHandler           (void) __attribute__ ((weak, alias("Default_Handler")));
112 void QSPI_IRQHandler             (void) __attribute__ ((weak, alias("Default_Handler")));
113 void CRYPTOCELL_IRQHandler       (void) __attribute__ ((weak, alias("Default_Handler")));
114 void SPIM3_IRQHandler            (void) __attribute__ ((weak, alias("Default_Handler")));
115 void PWM3_IRQHandler             (void) __attribute__ ((weak, alias("Default_Handler")));
116 
117 const func __Vectors[] __attribute__ ((section(".isr_vector"),used)) = {
118     (func)&_estack,
119     Reset_Handler,
120     NMI_Handler,
121     HardFault_Handler,
122     MemoryManagement_Handler,
123     BusFault_Handler,
124     UsageFault_Handler,
125     0,
126     0,
127     0,
128     0,
129     SVC_Handler,
130     DebugMon_Handler,
131     0,
132     PendSV_Handler,
133     SysTick_Handler,
134 
135     /* External Interrupts */
136     POWER_CLOCK_IRQHandler,
137     RADIO_IRQHandler,
138     UARTE0_UART0_IRQHandler,
139     SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler,
140     SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler,
141     NFCT_IRQHandler,
142     GPIOTE_IRQHandler,
143     SAADC_IRQHandler,
144     TIMER0_IRQHandler,
145     TIMER1_IRQHandler,
146     TIMER2_IRQHandler,
147     RTC0_IRQHandler,
148     TEMP_IRQHandler,
149     RNG_IRQHandler,
150     ECB_IRQHandler,
151     CCM_AAR_IRQHandler,
152     WDT_IRQHandler,
153     RTC1_IRQHandler,
154     QDEC_IRQHandler,
155     COMP_LPCOMP_IRQHandler,
156     SWI0_EGU0_IRQHandler,
157     SWI1_EGU1_IRQHandler,
158     SWI2_EGU2_IRQHandler,
159     SWI3_EGU3_IRQHandler,
160     SWI4_EGU4_IRQHandler,
161     SWI5_EGU5_IRQHandler,
162     TIMER3_IRQHandler,
163     TIMER4_IRQHandler,
164     PWM0_IRQHandler,
165     PDM_IRQHandler,
166     0,
167     0,
168     MWU_IRQHandler,
169     PWM1_IRQHandler,
170     PWM2_IRQHandler,
171     SPIM2_SPIS2_SPI2_IRQHandler,
172     RTC2_IRQHandler,
173     I2S_IRQHandler,
174     FPU_IRQHandler,
175     USBD_IRQHandler,
176     UARTE1_IRQHandler,
177     QSPI_IRQHandler,
178     CRYPTOCELL_IRQHandler,
179     0,
180     0,
181     PWM3_IRQHandler,
182     0,
183     SPIM3_IRQHandler,
184 };
185