-
Notifications
You must be signed in to change notification settings - Fork 35
/
main.c
140 lines (122 loc) · 3.93 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
/*
* Race Capture Firmware
*
* Copyright (C) 2015 Autosport Labs
*
* This file is part of the Race Capture firmware suite
*
* This is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details. You should
* have received a copy of the GNU General Public License along with
* this code. If not, see <http://www.gnu.org/licenses/>.
*
*
* 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.
*/
#include "FreeRTOS.h"
#include "CAN_task.h"
#include "capabilities.h"
#include "connectivityTask.h"
#include "constants.h"
#include "cpu.h"
#include "fileWriter.h"
#include "gpioTasks.h"
#include "gpsTask.h"
#include "led.h"
#include "loggerHardware.h"
#include "loggerTaskEx.h"
#include "luaScript.h"
#include "luaTask.h"
#include "messaging.h"
#include "panic.h"
#include "printk.h"
#include "task.h"
#include "usb_comm.h"
#include "wifi.h"
#include "watchdog.h"
#include "versionInfo.h"
#include "virtual_channel.h"
#include <app_info.h>
#include <stdbool.h>
__attribute__((aligned (4)))
static const struct app_info_block info_block = {
.magic_number = APP_INFO_MAGIC_NUMBER,
.info_crc = 0xDEADBEEF,
};
/*
* Define task priorities here. Ensure that these values are
* all below `configMAX_PRIORITIES - 1` in the FreeRTOSConfig.h.
* See http://www.freertos.org/RTOS-task-priority.html for more
* info on how to best set these. 0 is lowest priority.
*/
#define TASK_PRIORITY(v) (tskIDLE_PRIORITY + v)
#define RCP_LOGGING_PRIORITY TASK_PRIORITY(4)
#define RCP_INPUT_PRIORITY TASK_PRIORITY(3)
#define RCP_OUTPUT_PRIORITY TASK_PRIORITY(2)
#define RCP_LUA_PRIORITY TASK_PRIORITY(1)
void setupTask(void *param)
{
#if VIRTUAL_CHANNEL_SUPPORT == 1
init_virtual_channels();
#endif
initialize_tracks();
initialize_logger_config();
InitLoggerHardware();
initMessaging();
startGPSTask(RCP_INPUT_PRIORITY);
#if USB_SERIAL_SUPPORT
startUSBCommTask(RCP_INPUT_PRIORITY);
#endif
start_CAN_task(RCP_INPUT_PRIORITY);
startConnectivityTask(RCP_OUTPUT_PRIORITY);
startLoggerTaskEx(RCP_LOGGING_PRIORITY);
#if GPIO_CHANNELS > 0
startGPIOTasks(RCP_INPUT_PRIORITY);
#endif
#if SDCARD_SUPPORT
startFileWriterTask(RCP_OUTPUT_PRIORITY);
#endif
#if LUA_SUPPORT
lua_task_init(RCP_LUA_PRIORITY);
#endif
#if WIFI_SUPPORT
wifi_init_task(RCP_OUTPUT_PRIORITY, RCP_INPUT_PRIORITY);
#endif
/* Removes this setup task from the scheduler */
pr_info("[main] Setup Task complete!\r\n");
vTaskDelete(NULL);
}
int main( void )
{
ALWAYS_KEEP(info_block);
cpu_init();
pr_info("*** ");
pr_info(FRIENDLY_DEVICE_NAME);
pr_info(" ");
pr_info(version_full());
pr_info(" ***\r\n");
/* Defined as part of our compilation process */
if (true == ASL_WATCHDOG)
watchdog_init(WATCHDOG_TIMEOUT_MS);
const signed portCHAR task_name[] = "Hardware Init";
xTaskCreate(setupTask, task_name, HARDWARE_INIT_STACK_SIZE,
NULL, RCP_LUA_PRIORITY, NULL);
vTaskStartScheduler();
/* SHOULD NEVER GET HERE */
panic(PANIC_CAUSE_SCHEDULER);
return 1;
}