-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.c
87 lines (64 loc) · 1.88 KB
/
main.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
/** ***************************************************************************
* @file main.c
* @brief Simple Flash Demo for EFM32GG_STK3700
* @version 1.0
******************************************************************************/
#include <stdint.h>
#include <stdio.h>
/*
* Including this file, it is possible to define which processor using command line
* E.g. -DEFM32GG995F1024
* The alternative is to include the processor specific file directly
* #include "efm32gg995f1024.h"
*/
#include "em_device.h"
#include "clock_efm32gg_ext.h"
#include "led.h"
//void UART0_TX_IRQHandler(void);
#define ENTER_ATOMIC() __disable_irq()
#define EXIT_ATOMIC() __enable_irq()
/*************************************************************************//**
* @brief Sys Tick Handler
*/
const int TickDivisor = 1000; // milliseconds
volatile uint64_t tick = 0;
void SysTick_Handler (void) {
static int counter = 0;
tick++;
if( counter == 0 ) {
counter = TickDivisor;
// Process every second
LED_Toggle(LED1);
}
counter--;
}
void Delay(int delay) {
uint64_t l = tick+delay;
while(tick<l) {}
}
/**************************************************************************//**
* @brief Main function
*
* @note Using external crystal oscillator
* HFCLK = HFXO
* HFCORECLK = HFCLK
* HFPERCLK = HFCLK
*/
int main(void) {
char line[100];
int tryn = 0;
/* Configure LEDs */
LED_Init(LED1|LED2);
// Set clock source to external crystal: 48 MHz
(void) SystemCoreClockSet(CLOCK_HFXO,1,1);
/* Turn on LEDs */
LED_Write(0,LED1|LED2);
/* Configure SysTick */
SysTick_Config(SystemCoreClock/TickDivisor);
__enable_irq();
printf("Hello\n");
while (1) {
putchar('+');
Delay(100);
}
}