main.c 3.12 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
16
	watchdog_init();

17
	LOG_INFO("startup", "Epicardium startup ...");
Rahix's avatar
Rahix committed
18
	LOG_INFO("startup", "Version " CARD10_VERSION);
19

20
	LOG_DEBUG("startup", "Initializing hardware ...");
21
22
	hardware_early_init();

23
24
25
26
	/*
	 * Version Splash
	 */
	const char *version_buf = CARD10_VERSION;
27
28
29
30
	const int off           = (160 - (int)strlen(version_buf) * 14) / 2;
	epic_disp_clear(0x9dc0);
	epic_disp_print(10, 20, "Epicardium", 0x6c20, 0x9dc0);
	epic_disp_print(off > 0 ? off : 0, 40, version_buf, 0x6c20, 0x9dc0);
ch3's avatar
ch3 committed
31
32
	epic_disp_update();
	mxc_delay(2000000);
33

34
	LOG_DEBUG("startup", "Initializing tasks ...");
Rahix's avatar
Rahix committed
35
36
37

	/* Serial */
	if (xTaskCreate(
Rahix's avatar
Rahix committed
38
39
		    vSerialTask,
		    (const char *)"Serial",
40
		    configMINIMAL_STACK_SIZE * 2,
Rahix's avatar
Rahix committed
41
		    NULL,
42
		    tskIDLE_PRIORITY + 3,
Rahix's avatar
Rahix committed
43
		    NULL) != pdPASS) {
44
		LOG_CRIT("startup", "Failed to create %s task!", "Serial");
Rahix's avatar
Rahix committed
45
46
47
		abort();
	}

48
49
50
51
52
53
	/* PMIC */
	if (xTaskCreate(
		    vPmicTask,
		    (const char *)"PMIC",
		    configMINIMAL_STACK_SIZE,
		    NULL,
Rahix's avatar
Rahix committed
54
		    tskIDLE_PRIORITY + 4,
55
		    NULL) != pdPASS) {
56
		LOG_CRIT("startup", "Failed to create %s task!", "PMIC");
57
58
59
		abort();
	}

60
61
62
63
64
65
66
67
	/* BHI160 */
	if (xTaskCreate(
		    vBhi160Task,
		    (const char *)"BHI160 Driver",
		    configMINIMAL_STACK_SIZE * 2,
		    NULL,
		    tskIDLE_PRIORITY + 1,
		    NULL) != pdPASS) {
koalo's avatar
koalo committed
68
		LOG_CRIT("startup", "Failed to create %s task!", "BHI160");
69
70
71
		abort();
	}

schneider's avatar
schneider committed
72
73
74
75
76
77
78
79
80
81
82
	/* MAX30001 */
	if (xTaskCreate(
		    vMAX30001Task,
		    (const char *)"MAX30001 Driver",
		    configMINIMAL_STACK_SIZE * 2,
		    NULL,
		    tskIDLE_PRIORITY + 1,
		    NULL) != pdPASS) {
		LOG_CRIT("startup", "Failed to create %s task!", "MAX30001");
		abort();
	}
83
	/* API */
Rahix's avatar
Rahix committed
84
	if (xTaskCreate(
Rahix's avatar
Rahix committed
85
86
		    vApiDispatcher,
		    (const char *)"API Dispatcher",
swym's avatar
swym committed
87
		    configMINIMAL_STACK_SIZE * 16,
Rahix's avatar
Rahix committed
88
89
90
		    NULL,
		    tskIDLE_PRIORITY + 2,
		    &dispatcher_task_id) != pdPASS) {
q3k's avatar
q3k committed
91
92
93
94
95
		LOG_CRIT(
			"startup",
			"Failed to create %s task!",
			"API Dispatcher"
		);
Rahix's avatar
Rahix committed
96
97
98
		abort();
	}

schneider's avatar
schneider committed
99
	/* BLE */
100
	if (ble_shall_start()) {
koalo's avatar
koalo committed
101
102
103
104
105
106
107
108
109
110
		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();
		}
111
112
	}

113
114
115
116
117
118
119
120
121
122
123
124
	/* 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
125
126
127
128
129
130
	/* Lifecycle */
	if (xTaskCreate(
		    vLifecycleTask,
		    (const char *)"Lifecycle",
		    configMINIMAL_STACK_SIZE * 4,
		    NULL,
131
		    tskIDLE_PRIORITY + 3,
Rahix's avatar
Rahix committed
132
133
134
		    NULL) != pdPASS) {
		LOG_CRIT("startup", "Failed to create %s task!", "Lifecycle");
		abort();
q3k's avatar
q3k committed
135
136
	}

137
138
139
140
141
	/*
	 * Initialize serial driver data structures.
	 */
	serial_init();

142
	LOG_DEBUG("startup", "Starting FreeRTOS ...");
Rahix's avatar
Rahix committed
143
	vTaskStartScheduler();
144
145
146

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