-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
116 lines (97 loc) · 3.44 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
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
#include <stdint.h>
#include <stdbool.h>
#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "bsp.h"
#include "segmentlcd.h"
#include "bsp_trace.h"
#include "SST39SF040.h"
#include "main.h"
#include "inttypes.h"
volatile uint32_t msTicks; /* counts 1ms timeTicks */
int _write(int file, const char *ptr, int len)
{
int x;
for (x = 0; x < len; x++)
ITM_SendChar (*ptr++);
return (len);
}
void SWO_SetupForPrint(void) {
/* Enable GPIO clock. */
CMU ->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;
/* Enable Serial wire output pin */
GPIO ->ROUTE |= GPIO_ROUTE_SWOPEN;
#if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_LEOPARD_FAMILY) || defined(_EFM32_WONDER_FAMILY) || defined(_EFM32_GECKO_FAMILY)
/* Set location 0 */
GPIO ->ROUTE = (GPIO ->ROUTE & ~(_GPIO_ROUTE_SWLOCATION_MASK)) | GPIO_ROUTE_SWLOCATION_LOC0;
/* Enable output on pin - GPIO Port F, Pin 2 */
GPIO ->P[5].MODEL &= ~(_GPIO_P_MODEL_MODE2_MASK);
GPIO ->P[5].MODEL |= GPIO_P_MODEL_MODE2_PUSHPULL;
#else
/* Set location 1 */
GPIO->ROUTE = (GPIO->ROUTE & ~(_GPIO_ROUTE_SWLOCATION_MASK)) |GPIO_ROUTE_SWLOCATION_LOC1;
/* Enable output on pin */
GPIO->P[2].MODEH &= ~(_GPIO_P_MODEH_MODE15_MASK);
GPIO->P[2].MODEH |= GPIO_P_MODEH_MODE15_PUSHPULL;
#endif
/* Enable debug clock AUXHFRCO */
CMU ->OSCENCMD = CMU_OSCENCMD_AUXHFRCOEN;
/* Wait until clock is ready */
while (!(CMU ->STATUS & CMU_STATUS_AUXHFRCORDY)) ;
/* Enable trace in core debug */
CoreDebug ->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
ITM ->LAR = 0xC5ACCE55;
ITM ->TER = 0x0;
ITM ->TCR = 0x0;
TPI ->SPPR = 2;
TPI ->ACPR = 0xf;
ITM ->TPR = 0x0;
DWT ->CTRL = 0x400003FE;
ITM ->TCR = 0x0001000D;
TPI ->FFCR = 0x00000100;
ITM ->TER = 0x1;
}
/**************************************************************************//**
* @brief SysTick_Handler
* Interrupt Service Routine for system tick counter
* @note
* No wrap around protection
*****************************************************************************/
void SysTick_Handler(void)
{
msTicks++; /* increment counter necessary in Delay()*/
}
/**************************************************************************//**
* @brief Delays number of msTick Systicks (typically 1 ms)
* @param dlyTicks Number of ticks to delay
*****************************************************************************/
void Delay(uint32_t dlyTicks)
{
uint32_t curTicks;
curTicks = msTicks;
while ((msTicks - curTicks) < dlyTicks) ;
}
/**************************************************************************//**
* @brief Main function
*****************************************************************************/
int main(void)
{
/* Chip errata */
CHIP_Init();
/* Configures the SWO to output both printf-information, PC-samples and interrupt trace. */
SWO_SetupForPrint();
/* Enable two leds to show we're alive */
BSP_LedsInit();
BSP_LedSet(0);
BSP_LedSet(1);
/* Setup SysTick Timer for 1 msec interrupts */
if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ;
/* Enable LCD without voltage boost */
SegmentLCD_Init(false);
/* Setup DAC and initialize pins */
flash_setup();
set_flash_voltage(5);
/* Code goes here*/
return 0;
}