main.c 3.74 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
#include "gfx.h"
#include "display.h"
9
#include "leds.h"
10
11
#include "version-splash.h"

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

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

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

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

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

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

31
32
33
34
	/*
	 * Version Splash
	 */
	const char *version_buf = CARD10_VERSION;
35
36
37
38
39
40
41
42
43
44
45
46
47

	//LED feedback in case of dead display
	epic_leds_set(11, 0, 0, 1);
	epic_leds_set(12, 0, 0, 1);
	epic_leds_set(13, 0, 0, 1);
	epic_leds_set(14, 0, 0, 1);
	for (int i = 0; i < 3; i++) {
		epic_leds_set_rocket(i, 31);
		mxc_delay(166666);
		epic_leds_set_rocket(i, 0);
	}
	epic_leds_clear_all(0, 0, 0);

48
	epic_disp_clear(0x0000);
49

50
	if (strcmp(CARD10_VERSION, "v1.14") == 0) {
51
52
53
54
55
56
57
58
59
		gfx_copy_region(
			&display_screen,
			0,
			0,
			160,
			80,
			GFX_RAW,
			sizeof(version_splash),
			version_splash
60
61
62
63
64
65
66
67
		);
	} 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
68
69
	epic_disp_update();
	mxc_delay(2000000);
70

71
	LOG_DEBUG("startup", "Initializing tasks ...");
Rahix's avatar
Rahix committed
72
73
74

	/* Serial */
	if (xTaskCreate(
Rahix's avatar
Rahix committed
75
76
		    vSerialTask,
		    (const char *)"Serial",
77
		    configMINIMAL_STACK_SIZE * 2,
Rahix's avatar
Rahix committed
78
		    NULL,
79
		    tskIDLE_PRIORITY + 3,
Rahix's avatar
Rahix committed
80
		    NULL) != pdPASS) {
81
		panic("Failed to create %s task!", "Serial");
Rahix's avatar
Rahix committed
82
83
	}

84
85
86
87
88
89
	/* PMIC */
	if (xTaskCreate(
		    vPmicTask,
		    (const char *)"PMIC",
		    configMINIMAL_STACK_SIZE,
		    NULL,
Rahix's avatar
Rahix committed
90
		    tskIDLE_PRIORITY + 4,
91
		    NULL) != pdPASS) {
92
		panic("Failed to create %s task!", "PMIC");
93
94
	}

95
96
97
98
99
100
101
102
	/* BHI160 */
	if (xTaskCreate(
		    vBhi160Task,
		    (const char *)"BHI160 Driver",
		    configMINIMAL_STACK_SIZE * 2,
		    NULL,
		    tskIDLE_PRIORITY + 1,
		    NULL) != pdPASS) {
103
		panic("Failed to create %s task!", "BHI160");
104
105
	}

schneider's avatar
schneider committed
106
107
108
109
110
111
112
113
	/* MAX30001 */
	if (xTaskCreate(
		    vMAX30001Task,
		    (const char *)"MAX30001 Driver",
		    configMINIMAL_STACK_SIZE * 2,
		    NULL,
		    tskIDLE_PRIORITY + 1,
		    NULL) != pdPASS) {
114
		panic("Failed to create %s task!", "MAX30001");
schneider's avatar
schneider committed
115
	}
116
117
118
119
120
121
122
123
124
125
	/* MAX86150 */
	if (xTaskCreate(
		    vMAX86150Task,
		    (const char *)"MAX86150 Driver",
		    configMINIMAL_STACK_SIZE * 2,
		    NULL,
		    tskIDLE_PRIORITY + 1,
		    NULL) != pdPASS) {
		panic("Failed to create %s task!", "MAX86150");
	}
126
	/* API */
Rahix's avatar
Rahix committed
127
	if (xTaskCreate(
Rahix's avatar
Rahix committed
128
129
		    vApiDispatcher,
		    (const char *)"API Dispatcher",
swym's avatar
swym committed
130
		    configMINIMAL_STACK_SIZE * 16,
Rahix's avatar
Rahix committed
131
132
133
		    NULL,
		    tskIDLE_PRIORITY + 2,
		    &dispatcher_task_id) != pdPASS) {
134
		panic("Failed to create %s task!", "API Dispatcher");
Rahix's avatar
Rahix committed
135
136
	}

schneider's avatar
schneider committed
137
	/* BLE */
138
	if (ble_shall_start()) {
koalo's avatar
koalo committed
139
140
141
142
143
		if (xTaskCreate(
			    vBleTask,
			    (const char *)"BLE",
			    configMINIMAL_STACK_SIZE * 10,
			    NULL,
144
			    tskIDLE_PRIORITY + 3,
koalo's avatar
koalo committed
145
			    NULL) != pdPASS) {
146
			panic("Failed to create %s task!", "BLE");
koalo's avatar
koalo committed
147
		}
148
149
	}

150
151
152
153
154
155
156
157
	/* LEDs */
	if (xTaskCreate(
		    vLedTask,
		    (const char *)"LED",
		    configMINIMAL_STACK_SIZE,
		    NULL,
		    tskIDLE_PRIORITY + 1,
		    NULL) != pdPASS) {
158
		panic("Failed to create %s task!", "LED");
159
160
	}

Rahix's avatar
Rahix committed
161
162
163
164
165
166
	/* Lifecycle */
	if (xTaskCreate(
		    vLifecycleTask,
		    (const char *)"Lifecycle",
		    configMINIMAL_STACK_SIZE * 4,
		    NULL,
167
		    tskIDLE_PRIORITY + 3,
Rahix's avatar
Rahix committed
168
		    NULL) != pdPASS) {
169
		panic("Failed to create %s task!", "Lifecycle");
q3k's avatar
q3k committed
170
171
	}

172
173
174
175
176
	/*
	 * Initialize serial driver data structures.
	 */
	serial_init();

177
	LOG_DEBUG("startup", "Starting FreeRTOS ...");
Rahix's avatar
Rahix committed
178
	vTaskStartScheduler();
179

180
	panic("FreeRTOS did not start due to unknown error!");
Rahix's avatar
Rahix committed
181
}