forked from cmaglie/ArduinoCore-samd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard_startup.c
165 lines (139 loc) · 4.04 KB
/
board_startup.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
Copyright (c) 2015 Arduino LLC. All right reserved.
Copyright (c) 2015 Atmel Corporation/Thibaut VIARD. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <sam.h>
#include "board_driver_led.h"
struct ConstVectors
{
/* Stack pointer */
void* pvStack;
/* Cortex-M handlers */
void* pfnReset_Handler;
void* pfnNMI_Handler;
void* pfnHardFault_Handler;
void* pfnReservedM12;
void* pfnReservedM11;
void* pfnReservedM10;
void* pfnReservedM9;
void* pfnReservedM8;
void* pfnReservedM7;
void* pfnReservedM6;
void* pfnSVC_Handler;
void* pfnReservedM4;
void* pfnReservedM3;
void* pfnPendSV_Handler;
void* pfnSysTick_Handler;
};
/* Symbols exported from linker script */
extern uint32_t __etext ;
extern uint32_t __data_start__ ;
extern uint32_t __data_end__ ;
extern uint32_t __bss_start__ ;
extern uint32_t __bss_end__ ;
extern uint32_t __StackTop;
extern int main(void);
extern void __libc_init_array(void);
/* Exception Table */
__attribute__ ((section(".isr_vector")))
const struct ConstVectors exception_table =
{
/* Configure Initial Stack Pointer, using linker-generated symbols */
.pvStack = (void*) (&__StackTop),
.pfnReset_Handler = (void*) Reset_Handler,
.pfnNMI_Handler = (void*) NMI_Handler,
.pfnHardFault_Handler = (void*) HardFault_Handler,
.pfnReservedM12 = (void*) (0UL), /* Reserved */
.pfnReservedM11 = (void*) (0UL), /* Reserved */
.pfnReservedM10 = (void*) (0UL), /* Reserved */
.pfnReservedM9 = (void*) (0UL), /* Reserved */
.pfnReservedM8 = (void*) (0UL), /* Reserved */
.pfnReservedM7 = (void*) (0UL), /* Reserved */
.pfnReservedM6 = (void*) (0UL), /* Reserved */
.pfnSVC_Handler = (void*) SVC_Handler,
.pfnReservedM4 = (void*) (0UL), /* Reserved */
.pfnReservedM3 = (void*) (0UL), /* Reserved */
.pfnPendSV_Handler = (void*) PendSV_Handler,
.pfnSysTick_Handler = (void*) SysTick_Handler,
};
/**
* \brief This is the code that gets called on processor reset.
* Initializes the device and call the main() routine.
*/
void Reset_Handler( void )
{
uint32_t *pSrc, *pDest;
/* Initialize the initialized data section */
pSrc = &__etext;
pDest = &__data_start__;
if ( (&__data_start__ != &__data_end__) && (pSrc != pDest) )
{
for (; pDest < &__data_end__ ; pDest++, pSrc++ )
{
*pDest = *pSrc ;
}
}
/* Clear the zero section */
if ( &__bss_start__ != &__bss_end__ )
{
for ( pDest = &__bss_start__ ; pDest < &__bss_end__ ; pDest++ )
{
*pDest = 0ul ;
}
}
// board_init(); // will be done in main() after app check
/* Initialize the C library */
// __libc_init_array();
main();
while (1);
}
void NMI_Handler(void)
{
__BKPT(14);
while (1);
}
void HardFault_Handler(void)
{
__BKPT(13);
while (1);
}
void SVC_Handler(void)
{
__BKPT(5);
while (1);
}
void PendSV_Handler(void)
{
__BKPT(2);
while (1);
}
volatile uint8_t keepValue = 0;
volatile uint8_t targetValue = 20;
volatile int8_t direction = 1;
void SysTick_Handler(void)
{
if (keepValue == 0) {
targetValue += direction;
LED_toggle();
}
keepValue ++;
if (targetValue > 240 || targetValue < 10) {
direction = -direction;
targetValue += direction;
}
if (keepValue == targetValue) {
LED_toggle();
}
//TC5->COUNT16.INTFLAG.bit.MC0 = 1; // Clear interrupt
}