Skip to content

Commit c1f9134

Browse files
sandeepmistrycmaglie
authored andcommitted
Move SysTick_Handler to main.c and create LED_pulse function
1 parent aed3a34 commit c1f9134

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

bootloaders/zero/board_driver_led.c

+20
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,24 @@
1919

2020
#include "board_driver_led.h"
2121

22+
volatile uint8_t ledKeepValue = 0;
23+
volatile uint8_t ledTargetValue = 20;
24+
volatile int8_t ledDirection = 1;
2225

26+
inline void LED_pulse()
27+
{
28+
if (ledKeepValue == 0) {
29+
ledTargetValue += ledDirection;
30+
LED_toggle();
31+
}
32+
ledKeepValue ++;
33+
34+
if (ledTargetValue > 240 || ledTargetValue < 10) {
35+
ledDirection = -ledDirection;
36+
ledTargetValue += ledDirection;
37+
}
38+
39+
if (ledKeepValue == ledTargetValue) {
40+
LED_toggle();
41+
}
42+
}

bootloaders/zero/board_driver_led.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ inline void LED_init(void) { PORT->Group[BOARD_LED_PORT].DIRSET.reg = (1<<BOARD_
2727
inline void LED_on(void) { PORT->Group[BOARD_LED_PORT].OUTSET.reg = (1<<BOARD_LED_PIN); }
2828
inline void LED_off(void) { PORT->Group[BOARD_LED_PORT].OUTCLR.reg = (1<<BOARD_LED_PIN); }
2929
inline void LED_toggle(void) { PORT->Group[BOARD_LED_PORT].OUTTGL.reg = (1<<BOARD_LED_PIN); }
30+
void LED_pulse();
3031

3132
inline void LEDRX_init(void) { PORT->Group[BOARD_LEDRX_PORT].DIRSET.reg = (1<<BOARD_LEDRX_PIN); }
3233
inline void LEDRX_on(void) { PORT->Group[BOARD_LEDRX_PORT].OUTCLR.reg = (1<<BOARD_LEDRX_PIN); }
@@ -38,6 +39,4 @@ inline void LEDTX_on(void) { PORT->Group[BOARD_LEDTX_PORT].OUTCLR.reg = (1<<BOAR
3839
inline void LEDTX_off(void) { PORT->Group[BOARD_LEDTX_PORT].OUTSET.reg = (1<<BOARD_LEDTX_PIN); }
3940
inline void LEDTX_toggle(void) { PORT->Group[BOARD_LEDTX_PORT].OUTTGL.reg = (1<<BOARD_LEDTX_PIN); }
4041

41-
inline void LED_configure(uint32_t sampleRate) { SysTick_Config(sampleRate); }
42-
4342
#endif // _BOARD_DRIVER_LED_

bootloaders/zero/board_startup.c

-24
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919

2020
#include <sam.h>
21-
#include "board_driver_led.h"
2221

2322
struct ConstVectors
2423
{
@@ -140,26 +139,3 @@ void PendSV_Handler(void)
140139
__BKPT(2);
141140
while (1);
142141
}
143-
144-
volatile uint8_t keepValue = 0;
145-
volatile uint8_t targetValue = 20;
146-
volatile int8_t direction = 1;
147-
148-
void SysTick_Handler(void)
149-
{
150-
if (keepValue == 0) {
151-
targetValue += direction;
152-
LED_toggle();
153-
}
154-
keepValue ++;
155-
156-
if (targetValue > 240 || targetValue < 10) {
157-
direction = -direction;
158-
targetValue += direction;
159-
}
160-
161-
if (keepValue == targetValue) {
162-
LED_toggle();
163-
}
164-
//TC5->COUNT16.INTFLAG.bit.MC0 = 1; // Clear interrupt
165-
}

bootloaders/zero/main.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,14 @@ int main(void)
181181

182182
/* Initialize LEDs */
183183
LED_init();
184-
LED_configure(1000);
185184
LEDRX_init();
186185
LEDRX_off();
187186
LEDTX_init();
188187
LEDTX_off();
189188

189+
/* Start the sys tick (1 ms) */
190+
SysTick_Config(1000);
191+
190192
/* Wait for a complete enum on usb or a '#' char on serial line */
191193
while (1)
192194
{
@@ -222,3 +224,8 @@ int main(void)
222224
#endif
223225
}
224226
}
227+
228+
void SysTick_Handler(void)
229+
{
230+
LED_pulse();
231+
}

0 commit comments

Comments
 (0)