main.c 2.72 KB
Newer Older
1
#include "modules/modules.h"
2
#include "modules/log.h"
koalo's avatar
koalo committed
3
#include "modules/filesystem.h"
Rahix's avatar
Rahix committed
4
#include "card10-version.h"
schneider's avatar
schneider committed
5

Rahix's avatar
Rahix committed
6
7
#include "FreeRTOS.h"
#include "task.h"
8
#include "mxc_delay.h"
Rahix's avatar
Rahix committed
9

10
#include <stdlib.h>
koalo's avatar
koalo committed
11
#include <string.h>
12

Rahix's avatar
Rahix committed
13
14
int main(void)
{
15
	LOG_INFO("startup", "Epicardium startup ...");
Rahix's avatar
Rahix committed
16
	LOG_INFO("startup", "Version " CARD10_VERSION);
17

18
	LOG_DEBUG("startup", "Initializing hardware ...");
19
20
	hardware_early_init();

21
	char *version_buf = CARD10_VERSION;
ch3's avatar
ch3 committed
22
23
	epic_disp_print(0, 5, "epicardium:", 0xffff, 0x0000);
	epic_disp_print(0, 24, version_buf, 0xffff, 0x0000);
ch3's avatar
ch3 committed
24
25
	epic_disp_update();
	mxc_delay(2000000);
26

27
	LOG_DEBUG("startup", "Initializing tasks ...");
Rahix's avatar
Rahix committed
28
29
30

	/* Serial */
	if (xTaskCreate(
Rahix's avatar
Rahix committed
31
32
		    vSerialTask,
		    (const char *)"Serial",
33
		    configMINIMAL_STACK_SIZE * 2,
Rahix's avatar
Rahix committed
34
35
36
		    NULL,
		    tskIDLE_PRIORITY + 1,
		    NULL) != pdPASS) {
37
		LOG_CRIT("startup", "Failed to create %s task!", "Serial");
Rahix's avatar
Rahix committed
38
39
40
		abort();
	}

41
42
43
44
45
46
	/* PMIC */
	if (xTaskCreate(
		    vPmicTask,
		    (const char *)"PMIC",
		    configMINIMAL_STACK_SIZE,
		    NULL,
Rahix's avatar
Rahix committed
47
		    tskIDLE_PRIORITY + 4,
48
		    NULL) != pdPASS) {
49
		LOG_CRIT("startup", "Failed to create %s task!", "PMIC");
50
51
52
		abort();
	}

53
54
55
56
57
58
59
60
	/* BHI160 */
	if (xTaskCreate(
		    vBhi160Task,
		    (const char *)"BHI160 Driver",
		    configMINIMAL_STACK_SIZE * 2,
		    NULL,
		    tskIDLE_PRIORITY + 1,
		    NULL) != pdPASS) {
koalo's avatar
koalo committed
61
		LOG_CRIT("startup", "Failed to create %s task!", "BHI160");
62
63
64
		abort();
	}

65
	/* API */
Rahix's avatar
Rahix committed
66
	if (xTaskCreate(
Rahix's avatar
Rahix committed
67
68
		    vApiDispatcher,
		    (const char *)"API Dispatcher",
swym's avatar
swym committed
69
		    configMINIMAL_STACK_SIZE * 16,
Rahix's avatar
Rahix committed
70
71
72
		    NULL,
		    tskIDLE_PRIORITY + 2,
		    &dispatcher_task_id) != pdPASS) {
q3k's avatar
q3k committed
73
74
75
76
77
		LOG_CRIT(
			"startup",
			"Failed to create %s task!",
			"API Dispatcher"
		);
Rahix's avatar
Rahix committed
78
79
80
		abort();
	}

schneider's avatar
schneider committed
81
	/* BLE */
82
	if (ble_shall_start()) {
koalo's avatar
koalo committed
83
84
85
86
87
88
89
90
91
92
		if (xTaskCreate(
			    vBleTask,
			    (const char *)"BLE",
			    configMINIMAL_STACK_SIZE * 10,
			    NULL,
			    tskIDLE_PRIORITY + 1,
			    NULL) != pdPASS) {
			LOG_CRIT("startup", "Failed to create %s task!", "BLE");
			abort();
		}
93
94
	}

95
96
97
98
99
100
101
102
103
104
105
106
	/* LEDs */
	if (xTaskCreate(
		    vLedTask,
		    (const char *)"LED",
		    configMINIMAL_STACK_SIZE,
		    NULL,
		    tskIDLE_PRIORITY + 1,
		    NULL) != pdPASS) {
		LOG_CRIT("startup", "Failed to create %s task!", "LED");
		abort();
	}

Rahix's avatar
Rahix committed
107
108
109
110
111
112
	/* Lifecycle */
	if (xTaskCreate(
		    vLifecycleTask,
		    (const char *)"Lifecycle",
		    configMINIMAL_STACK_SIZE * 4,
		    NULL,
113
		    tskIDLE_PRIORITY + 3,
Rahix's avatar
Rahix committed
114
115
116
		    NULL) != pdPASS) {
		LOG_CRIT("startup", "Failed to create %s task!", "Lifecycle");
		abort();
q3k's avatar
q3k committed
117
118
	}

119
	/* Watchdog petting */
Rahix's avatar
Rahix committed
120
121
122
123
#if 0
	/*
	 * Disabled for this release.
	 */
124
	watchdog_clearer_init();
Rahix's avatar
Rahix committed
125
#endif
126

127
	LOG_DEBUG("startup", "Starting FreeRTOS ...");
Rahix's avatar
Rahix committed
128
	vTaskStartScheduler();
129
130
131

	LOG_CRIT("startup", "FreeRTOS did not start due to unknown error!");
	abort();
Rahix's avatar
Rahix committed
132
}