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

7
8
9
10
#include "gfx.h"
#include "display.h"
#include "version-splash.h"

Rahix's avatar
Rahix committed
11
12
#include "FreeRTOS.h"
#include "task.h"
13
#include "mxc_delay.h"
Rahix's avatar
Rahix committed
14

15
#include <stdlib.h>
koalo's avatar
koalo committed
16
#include <string.h>
17

Rahix's avatar
Rahix committed
18
19
int main(void)
{
20
21
	watchdog_init();

22
	LOG_INFO("startup", "Epicardium startup ...");
Rahix's avatar
Rahix committed
23
	LOG_INFO("startup", "Version " CARD10_VERSION);
24

25
	LOG_DEBUG("startup", "Initializing hardware ...");
26
27
	hardware_early_init();

swym's avatar
swym committed
28
29
	load_config();

30
31
32
33
	/*
	 * Version Splash
	 */
	const char *version_buf = CARD10_VERSION;
34
	mxc_delay(500000);
35
	epic_disp_clear(0x0000);
36
	if (strcmp(CARD10_VERSION, "v1.11") == 0) {
37
38
39
40
41
42
43
44
45
		gfx_copy_region(
			&display_screen,
			0,
			0,
			160,
			80,
			GFX_RAW,
			sizeof(version_splash),
			version_splash
46
47
48
49
50
51
52
53
		);
	} else {
		const int off = (160 - (int)strlen(version_buf) * 14) / 2;
		epic_disp_print(10, 20, "Epicardium", 0xfe20, 0x0000);
		epic_disp_print(
			off > 0 ? off : 0, 40, version_buf, 0xfe20, 0x0000
		);
	}
ch3's avatar
ch3 committed
54
55
	epic_disp_update();
	mxc_delay(2000000);
56

57
	LOG_DEBUG("startup", "Initializing tasks ...");
Rahix's avatar
Rahix committed
58
59
60

	/* Serial */
	if (xTaskCreate(
Rahix's avatar
Rahix committed
61
62
		    vSerialTask,
		    (const char *)"Serial",
63
		    configMINIMAL_STACK_SIZE * 2,
Rahix's avatar
Rahix committed
64
		    NULL,
65
		    tskIDLE_PRIORITY + 3,
Rahix's avatar
Rahix committed
66
		    NULL) != pdPASS) {
67
		LOG_CRIT("startup", "Failed to create %s task!", "Serial");
Rahix's avatar
Rahix committed
68
69
70
		abort();
	}

71
72
73
74
75
76
	/* PMIC */
	if (xTaskCreate(
		    vPmicTask,
		    (const char *)"PMIC",
		    configMINIMAL_STACK_SIZE,
		    NULL,
Rahix's avatar
Rahix committed
77
		    tskIDLE_PRIORITY + 4,
78
		    NULL) != pdPASS) {
79
		LOG_CRIT("startup", "Failed to create %s task!", "PMIC");
80
81
82
		abort();
	}

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

schneider's avatar
schneider committed
95
96
97
98
99
100
101
102
103
104
105
	/* 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();
	}
106
	/* API */
Rahix's avatar
Rahix committed
107
	if (xTaskCreate(
Rahix's avatar
Rahix committed
108
109
		    vApiDispatcher,
		    (const char *)"API Dispatcher",
swym's avatar
swym committed
110
		    configMINIMAL_STACK_SIZE * 16,
Rahix's avatar
Rahix committed
111
112
113
		    NULL,
		    tskIDLE_PRIORITY + 2,
		    &dispatcher_task_id) != pdPASS) {
q3k's avatar
q3k committed
114
115
116
117
118
		LOG_CRIT(
			"startup",
			"Failed to create %s task!",
			"API Dispatcher"
		);
Rahix's avatar
Rahix committed
119
120
121
		abort();
	}

schneider's avatar
schneider committed
122
	/* BLE */
123
	if (ble_shall_start()) {
koalo's avatar
koalo committed
124
125
126
127
128
		if (xTaskCreate(
			    vBleTask,
			    (const char *)"BLE",
			    configMINIMAL_STACK_SIZE * 10,
			    NULL,
129
			    tskIDLE_PRIORITY + 3,
koalo's avatar
koalo committed
130
131
132
133
			    NULL) != pdPASS) {
			LOG_CRIT("startup", "Failed to create %s task!", "BLE");
			abort();
		}
134
135
	}

136
137
138
139
140
141
142
143
144
145
146
147
	/* 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
148
149
150
151
152
153
	/* Lifecycle */
	if (xTaskCreate(
		    vLifecycleTask,
		    (const char *)"Lifecycle",
		    configMINIMAL_STACK_SIZE * 4,
		    NULL,
154
		    tskIDLE_PRIORITY + 3,
Rahix's avatar
Rahix committed
155
156
157
		    NULL) != pdPASS) {
		LOG_CRIT("startup", "Failed to create %s task!", "Lifecycle");
		abort();
q3k's avatar
q3k committed
158
159
	}

160
161
162
163
164
	/*
	 * Initialize serial driver data structures.
	 */
	serial_init();

165
	LOG_DEBUG("startup", "Starting FreeRTOS ...");
Rahix's avatar
Rahix committed
166
	vTaskStartScheduler();
167
168
169

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