forked from autosportlabs/RaceCapture-Pro_firmware
/
main.c
146 lines (122 loc) · 3.81 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
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
/*
* RaceCapture Pro main
NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
The processor MUST be in supervisor mode when vTaskStartScheduler is
called. The demo applications included in the FreeRTOS.org download switch
to supervisor mode prior to main being called. If you are not using one of
these demo application projects then ensure Supervisor mode is used.
*/
// Standard includes
#include "FreeRTOS.h"
#include "task.h"
#include "capabilities.h"
#include "constants.h"
#include "LED.h"
#include "cpu.h"
#include "watchdog.h"
#include "loggerHardware.h"
#include "messaging.h"
#include "luaScript.h"
//tasks
#include "loggerTaskEx.h"
#include "fileWriter.h"
#include "connectivityTask.h"
#include "luaTask.h"
#include "OBD2_task.h"
#include "gpsTask.h"
#include "gpioTasks.h"
#include "usb_comm.h"
#include <app_info.h>
#define FATAL_ERROR_SCHEDULER 1
#define FATAL_ERROR_HARDWARE 2
#define FLASH_PAUSE_DELAY 5000000
#define FLASH_DELAY 1000000
__attribute__((aligned (4)))
static const struct app_info_block info_block = {
.magic_number = APP_INFO_MAGIC_NUMBER,
.info_crc = 0xDEADBEEF,
};
static void fatalError(int type)
{
int count;
switch (type) {
case FATAL_ERROR_HARDWARE:
count = 1;
break;
case FATAL_ERROR_SCHEDULER:
count = 2;
break;
default:
count = 3;
break;
}
while(1) {
for (int c = 0; c < count; c++) {
LED_enable(1);
LED_enable(2);
for (int i=0; i<FLASH_DELAY; i++) {}
LED_disable(1);
LED_disable(2);
for (int i=0; i < FLASH_DELAY; i++) {}
}
for (int i=0; i < FLASH_PAUSE_DELAY; i++) {}
}
}
#define OBD2_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
#define GPS_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
#define CONNECTIVITY_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
#define LOGGER_TASK_PRIORITY ( tskIDLE_PRIORITY + 6 )
#define FILE_WRITER_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
#define LUA_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
#define USB_COMM_TASK_PRIORITY ( tskIDLE_PRIORITY + 6 )
#define GPIO_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
void vApplicationStackOverflowHook(xTaskHandle pxTask, signed char *pcTaskName)
{
(void)pxTask;
(void)pcTaskName;
}
void setupTask(void *params)
{
(void)params;
initialize_tracks();
initialize_logger_config();
initialize_script();
InitLoggerHardware();
initMessaging();
startGPIOTasks ( GPIO_TASK_PRIORITY );
startUSBCommTask ( USB_COMM_TASK_PRIORITY );
startLuaTask ( LUA_TASK_PRIORITY );
startFileWriterTask ( FILE_WRITER_TASK_PRIORITY );
startConnectivityTask ( CONNECTIVITY_TASK_PRIORITY );
startGPSTask ( GPS_TASK_PRIORITY );
startOBD2Task ( OBD2_TASK_PRIORITY);
startLoggerTaskEx ( LOGGER_TASK_PRIORITY );
/* Removes this setup task from the scheduler */
vTaskDelete(NULL);
}
int main( void )
{
ALWAYS_KEEP(info_block);
cpu_init();
watchdog_init(WATCHDOG_TIMEOUT_MS);
/* Start the scheduler.
NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
The processor MUST be in supervisor mode when vTaskStartScheduler is
called. The demo applications included in the FreeRTOS.org download switch
to supervisor mode prior to main being called. If you are not using one of
these demo application projects then ensure Supervisor mode is used here.
*/
if (TASK_TASK_INIT) {
xTaskCreate(setupTask,
(signed portCHAR*)"Hardware Init",
configMINIMAL_STACK_SIZE + 500,
NULL,
tskIDLE_PRIORITY + 4,
NULL);
} else {
setupTask(NULL);
}
vTaskStartScheduler();
fatalError(FATAL_ERROR_SCHEDULER);
return 0;
}