-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.c
More file actions
100 lines (82 loc) · 2.24 KB
/
main.c
File metadata and controls
100 lines (82 loc) · 2.24 KB
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
/**
* @brief Example usage of Timer peripheral.
*
* EFR32 Application Note on Timers
* https://www.silabs.com/documents/public/application-notes/AN0014.pdf
*
* EFR32MG12 Wireless Gecko Reference Manual (Timer p672)
* https://www.silabs.com/documents/public/reference-manuals/efr32xg12-rm.pdf
*
* Timer API documentation
* https://docs.silabs.com/mcu/latest/efr32mg12/group-TIMER
*
* ARM RTOS API
* https://arm-software.github.io/CMSIS_5/RTOS2/html/group__CMSIS__RTOS.html
*
* Copyright Thinnect Inc. 2019
* Copyright ProLab TTÜ 2022
* @license MIT
* @author Johannes Ehala
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <inttypes.h>
#include "retargetserial.h"
#include "cmsis_os2.h"
#include "platform.h"
#include "SignatureArea.h"
#include "DeviceSignature.h"
#include "loggers_ext.h"
#include "logger_fwrite.h"
#include "timer_handler.h"
#include "loglevels.h"
#define __MODUUL__ "main"
#define __LOG_LEVEL__ (LOG_LEVEL_main & BASE_LOG_LEVEL)
#include "log.h"
// Include the information header binary
#include "incbin.h"
INCBIN(Header, "header.bin");
// Heartbeat thread, initialize Timer and print heartbeat messages.
void hp_loop ()
{
#define ESWGPIO_HB_DELAY 10 // Heartbeat message delay, seconds
// TODO Initialize Timer.
for (;;)
{
osDelay(ESWGPIO_HB_DELAY*osKernelGetTickFreq());
info1("Heartbeat");
}
}
int logger_fwrite_boot (const char *ptr, int len)
{
fwrite(ptr, len, 1, stdout);
fflush(stdout);
return len;
}
int main ()
{
PLATFORM_Init();
// Configure log message output
RETARGET_SerialInit();
log_init(BASE_LOG_LEVEL, &logger_fwrite_boot, NULL);
info1("ESW-Timer "VERSION_STR" (%d.%d.%d)", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
// Initialize OS kernel.
osKernelInitialize();
// Create a thread.
const osThreadAttr_t hp_thread_attr = { .name = "hp" };
osThreadNew(hp_loop, NULL, &hp_thread_attr);
if (osKernelReady == osKernelGetState())
{
// Switch to a thread-safe logger
logger_fwrite_init();
log_init(BASE_LOG_LEVEL, &logger_fwrite, NULL);
// Start the kernel
osKernelStart();
}
else
{
err1("!osKernelReady");
}
for(;;);
}