Skip to content

Commit d9df908

Browse files
committed
Fixed cortex-M hooks for RTOS
Fixes #4
1 parent a546da2 commit d9df908

File tree

4 files changed

+181
-177
lines changed

4 files changed

+181
-177
lines changed

cores/arduino/Tone.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ volatile bool toneIsActive = false;
3434
#define TONE_TC_IRQn TC5_IRQn
3535
#define TONE_TC_TOP 0xFFFF
3636
#define TONE_TC_CHANNEL 0
37+
void TC5_Handler (void) __attribute__ ((weak, alias("Tone_Handler")));
3738

3839
static inline void resetTC (Tc* TCx)
3940
{
@@ -183,8 +184,6 @@ void Tone_Handler (void)
183184
}
184185
}
185186

186-
void TC5_Handler (void) __attribute__ ((weak, alias("Tone_Handler")));
187-
188187
#ifdef __cplusplus
189188
}
190189
#endif

cores/arduino/cortex_handlers.c

+178
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/*
2+
Copyright (c) 2015 Arduino LLC. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#include "sam.h"
20+
#include "variant.h"
21+
22+
/* RTOS Hooks */
23+
extern void svcHook(void);
24+
extern void pendSVHook(void);
25+
extern int sysTickHook(void);
26+
27+
/* Default empty handler */
28+
29+
void Dummy_Handler(void)
30+
{
31+
#if defined DEBUG
32+
__BKPT(3);
33+
#endif
34+
for (;;) { }
35+
}
36+
37+
/* Cortex-M0+ core handlers */
38+
void HardFault_Handler(void) __attribute__ ((weak, alias("Dummy_Handler")));
39+
void Reest_Handler (void);
40+
void NMI_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
41+
void SVC_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
42+
void PendSV_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
43+
void SysTick_Handler (void);
44+
45+
/* Peripherals handlers */
46+
void PM_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
47+
void SYSCTRL_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
48+
void WDT_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
49+
void RTC_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
50+
void EIC_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
51+
void NVMCTRL_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
52+
void DMAC_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
53+
void USB_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
54+
void EVSYS_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
55+
void SERCOM0_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
56+
void SERCOM1_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
57+
void SERCOM2_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
58+
void SERCOM3_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
59+
void SERCOM4_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
60+
void SERCOM5_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
61+
void TCC0_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
62+
void TCC1_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
63+
void TCC2_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
64+
void TC3_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
65+
void TC4_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
66+
void TC5_Handler (void) __attribute__ ((weak)); // Used in Tone.cpp
67+
void TC6_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
68+
void TC7_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
69+
void ADC_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
70+
void AC_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
71+
void DAC_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
72+
void PTC_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
73+
void I2S_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
74+
75+
/* Initialize segments */
76+
extern uint32_t __etext;
77+
extern uint32_t __data_start__;
78+
extern uint32_t __data_end__;
79+
extern uint32_t __bss_start__;
80+
extern uint32_t __bss_end__;
81+
extern uint32_t __StackTop;
82+
83+
/* Exception Table */
84+
__attribute__ ((section(".isr_vector"))) const DeviceVectors exception_table =
85+
{
86+
/* Configure Initial Stack Pointer, using linker-generated symbols */
87+
(void*) (&__StackTop),
88+
89+
(void*) Reset_Handler,
90+
(void*) NMI_Handler,
91+
(void*) HardFault_Handler,
92+
(void*) (0UL), /* Reserved */
93+
(void*) (0UL), /* Reserved */
94+
(void*) (0UL), /* Reserved */
95+
(void*) (0UL), /* Reserved */
96+
(void*) (0UL), /* Reserved */
97+
(void*) (0UL), /* Reserved */
98+
(void*) (0UL), /* Reserved */
99+
(void*) SVC_Handler,
100+
(void*) (0UL), /* Reserved */
101+
(void*) (0UL), /* Reserved */
102+
(void*) PendSV_Handler,
103+
(void*) SysTick_Handler,
104+
105+
/* Configurable interrupts */
106+
(void*) PM_Handler, /* 0 Power Manager */
107+
(void*) SYSCTRL_Handler, /* 1 System Control */
108+
(void*) WDT_Handler, /* 2 Watchdog Timer */
109+
(void*) RTC_Handler, /* 3 Real-Time Counter */
110+
(void*) EIC_Handler, /* 4 External Interrupt Controller */
111+
(void*) NVMCTRL_Handler, /* 5 Non-Volatile Memory Controller */
112+
(void*) DMAC_Handler, /* 6 Direct Memory Access Controller */
113+
(void*) USB_Handler, /* 7 Universal Serial Bus */
114+
(void*) EVSYS_Handler, /* 8 Event System Interface */
115+
(void*) SERCOM0_Handler, /* 9 Serial Communication Interface 0 */
116+
(void*) SERCOM1_Handler, /* 10 Serial Communication Interface 1 */
117+
(void*) SERCOM2_Handler, /* 11 Serial Communication Interface 2 */
118+
(void*) SERCOM3_Handler, /* 12 Serial Communication Interface 3 */
119+
(void*) SERCOM4_Handler, /* 13 Serial Communication Interface 4 */
120+
(void*) SERCOM5_Handler, /* 14 Serial Communication Interface 5 */
121+
(void*) TCC0_Handler, /* 15 Timer Counter Control 0 */
122+
(void*) TCC1_Handler, /* 16 Timer Counter Control 1 */
123+
(void*) TCC2_Handler, /* 17 Timer Counter Control 2 */
124+
(void*) TC3_Handler, /* 18 Basic Timer Counter 0 */
125+
(void*) TC4_Handler, /* 19 Basic Timer Counter 1 */
126+
(void*) TC5_Handler, /* 20 Basic Timer Counter 2 */
127+
(void*) TC6_Handler, /* 21 Basic Timer Counter 3 */
128+
(void*) TC7_Handler, /* 22 Basic Timer Counter 4 */
129+
(void*) ADC_Handler, /* 23 Analog Digital Converter */
130+
(void*) AC_Handler, /* 24 Analog Comparators */
131+
(void*) DAC_Handler, /* 25 Digital Analog Converter */
132+
(void*) PTC_Handler, /* 26 Peripheral Touch Controller */
133+
(void*) I2S_Handler /* 27 Inter-IC Sound Interface */
134+
};
135+
136+
extern int main(void);
137+
extern void __libc_init_array(void);
138+
139+
/* This is called on processor reset to initialize the device and call main() */
140+
void Reset_Handler(void)
141+
{
142+
uint32_t *pSrc, *pDest;
143+
144+
/* Initialize the initialized data section */
145+
pSrc = &__etext;
146+
pDest = &__data_start__;
147+
148+
if ((&__data_start__ != &__data_end__) && (pSrc != pDest)) {
149+
for (; pDest < &__data_end__; pDest++, pSrc++)
150+
*pDest = *pSrc;
151+
}
152+
153+
/* Clear the zero section */
154+
if ((&__data_start__ != &__data_end__) && (pSrc != pDest)) {
155+
for (pDest = &__bss_start__; pDest < &__bss_end__; pDest++)
156+
*pDest = 0;
157+
}
158+
159+
/* Initialize the C library */
160+
__libc_init_array();
161+
162+
SystemInit();
163+
164+
main();
165+
166+
while (1)
167+
;
168+
}
169+
170+
/* Default Arduino systick handler */
171+
extern void SysTick_DefaultHandler(void);
172+
173+
void SysTick_Handler(void)
174+
{
175+
if (sysTickHook())
176+
return;
177+
SysTick_DefaultHandler();
178+
}

cores/arduino/delay.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ void delay( uint32_t ms )
7878

7979
#include "Reset.h" // for tickReset()
8080

81-
void SysTick_Handler( void )
81+
void SysTick_DefaultHandler(void)
8282
{
8383
// Increment tick count each ms
84-
_ulTickCount++ ;
84+
_ulTickCount++;
8585
tickReset();
8686
}
8787

cores/arduino/startup.c

-173
Original file line numberDiff line numberDiff line change
@@ -19,123 +19,6 @@
1919
#include "sam.h"
2020
#include "variant.h"
2121

22-
/* Initialize segments */
23-
extern uint32_t __etext ;
24-
extern uint32_t __data_start__ ;
25-
extern uint32_t __data_end__ ;
26-
extern uint32_t __bss_start__ ;
27-
extern uint32_t __bss_end__ ;
28-
extern uint32_t __StackTop;
29-
30-
extern int main( void ) ;
31-
extern void __libc_init_array(void);
32-
33-
/* Default empty handler */
34-
void Dummy_Handler(void);
35-
36-
/* Cortex-M0+ core handlers */
37-
#if defined DEBUG
38-
void HardFault_Handler( void )
39-
{
40-
__BKPT( 3 ) ;
41-
42-
while ( 1 )
43-
{
44-
}
45-
}
46-
#else
47-
void HardFault_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
48-
#endif //DEBUG
49-
50-
void NMI_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
51-
void SVC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
52-
void PendSV_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
53-
void SysTick_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
54-
55-
/* Peripherals handlers */
56-
void PM_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
57-
void SYSCTRL_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
58-
void WDT_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
59-
void RTC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
60-
void EIC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
61-
void NVMCTRL_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
62-
void DMAC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
63-
void USB_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
64-
void EVSYS_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
65-
void SERCOM0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
66-
void SERCOM1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
67-
void SERCOM2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
68-
void SERCOM3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
69-
void SERCOM4_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
70-
void SERCOM5_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
71-
void TCC0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
72-
void TCC1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
73-
void TCC2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
74-
void TC3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
75-
void TC4_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
76-
void TC5_Handler ( void ) __attribute__ ((weak));
77-
void TC6_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
78-
void TC7_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
79-
void ADC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
80-
void AC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
81-
void DAC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
82-
void PTC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
83-
void I2S_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
84-
85-
/* Exception Table */
86-
__attribute__ ((section(".isr_vector")))
87-
const DeviceVectors exception_table=
88-
{
89-
/* Configure Initial Stack Pointer, using linker-generated symbols */
90-
(void*) (&__StackTop),
91-
92-
(void*) Reset_Handler,
93-
(void*) NMI_Handler,
94-
(void*) HardFault_Handler,
95-
(void*) (0UL), /* Reserved */
96-
(void*) (0UL), /* Reserved */
97-
(void*) (0UL), /* Reserved */
98-
(void*) (0UL), /* Reserved */
99-
(void*) (0UL), /* Reserved */
100-
(void*) (0UL), /* Reserved */
101-
(void*) (0UL), /* Reserved */
102-
(void*) SVC_Handler,
103-
(void*) (0UL), /* Reserved */
104-
(void*) (0UL), /* Reserved */
105-
(void*) PendSV_Handler,
106-
(void*) SysTick_Handler,
107-
108-
/* Configurable interrupts */
109-
(void*) PM_Handler, /* 0 Power Manager */
110-
(void*) SYSCTRL_Handler, /* 1 System Control */
111-
(void*) WDT_Handler, /* 2 Watchdog Timer */
112-
(void*) RTC_Handler, /* 3 Real-Time Counter */
113-
(void*) EIC_Handler, /* 4 External Interrupt Controller */
114-
(void*) NVMCTRL_Handler, /* 5 Non-Volatile Memory Controller */
115-
(void*) DMAC_Handler, /* 6 Direct Memory Access Controller */
116-
(void*) USB_Handler, /* 7 Universal Serial Bus */
117-
(void*) EVSYS_Handler, /* 8 Event System Interface */
118-
(void*) SERCOM0_Handler, /* 9 Serial Communication Interface 0 */
119-
(void*) SERCOM1_Handler, /* 10 Serial Communication Interface 1 */
120-
(void*) SERCOM2_Handler, /* 11 Serial Communication Interface 2 */
121-
(void*) SERCOM3_Handler, /* 12 Serial Communication Interface 3 */
122-
(void*) SERCOM4_Handler, /* 13 Serial Communication Interface 4 */
123-
(void*) SERCOM5_Handler, /* 14 Serial Communication Interface 5 */
124-
(void*) TCC0_Handler, /* 15 Timer Counter Control 0 */
125-
(void*) TCC1_Handler, /* 16 Timer Counter Control 1 */
126-
(void*) TCC2_Handler, /* 17 Timer Counter Control 2 */
127-
(void*) TC3_Handler, /* 18 Basic Timer Counter 0 */
128-
(void*) TC4_Handler, /* 19 Basic Timer Counter 1 */
129-
(void*) TC5_Handler, /* 20 Basic Timer Counter 2 */
130-
(void*) TC6_Handler, /* 21 Basic Timer Counter 3 */
131-
(void*) TC7_Handler, /* 22 Basic Timer Counter 4 */
132-
(void*) ADC_Handler, /* 23 Analog Digital Converter */
133-
(void*) AC_Handler, /* 24 Analog Comparators */
134-
(void*) DAC_Handler, /* 25 Digital Analog Converter */
135-
(void*) PTC_Handler, /* 26 Peripheral Touch Controller */
136-
(void*) I2S_Handler /* 27 Inter-IC Sound Interface */
137-
} ;
138-
13922
/**
14023
* \brief SystemInit() configures the needed clocks and according Flash Read Wait States.
14124
* At reset:
@@ -340,59 +223,3 @@ void SystemInit( void )
340223
ADC->CALIB.reg = ADC_CALIB_BIAS_CAL(bias) | ADC_CALIB_LINEARITY_CAL(linearity);
341224
}
342225

343-
/**
344-
* \brief This is the code that gets called on processor reset.
345-
* To initialize the device, and call the main() routine.
346-
*/
347-
void Reset_Handler( void )
348-
{
349-
uint32_t *pSrc, *pDest;
350-
351-
/* Initialize the initialized data section */
352-
pSrc = &__etext;
353-
pDest = &__data_start__;
354-
355-
if ( (&__data_start__ != &__data_end__) && (pSrc != pDest) )
356-
{
357-
for (; pDest < &__data_end__ ; pDest++, pSrc++ )
358-
{
359-
*pDest = *pSrc ;
360-
}
361-
}
362-
363-
/* Clear the zero section */
364-
if ( (&__data_start__ != &__data_end__) && (pSrc != pDest) )
365-
{
366-
for ( pDest = &__bss_start__ ; pDest < &__bss_end__ ; pDest++ )
367-
{
368-
*pDest = 0 ;
369-
}
370-
}
371-
372-
/* Initialize the C library */
373-
__libc_init_array();
374-
375-
SystemInit() ;
376-
377-
/* Branch to main function */
378-
main() ;
379-
380-
/* Infinite loop */
381-
while ( 1 )
382-
{
383-
}
384-
}
385-
386-
/**
387-
* \brief Default interrupt handler for unused IRQs.
388-
*/
389-
void Dummy_Handler( void )
390-
{
391-
#if defined DEBUG
392-
__BKPT( 3 ) ;
393-
#endif // DEBUG
394-
395-
while ( 1 )
396-
{
397-
}
398-
}

0 commit comments

Comments
 (0)