main.c 1.91 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"
Rahix's avatar
Rahix committed
8

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

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

17
	LOG_INFO("startup", "Initializing hardware ...");
18
19
	hardware_early_init();

20
	LOG_INFO("startup", "Initializing tasks ...");
Rahix's avatar
Rahix committed
21
22
23

	/* Serial */
	if (xTaskCreate(
Rahix's avatar
Rahix committed
24
25
26
27
28
29
		    vSerialTask,
		    (const char *)"Serial",
		    configMINIMAL_STACK_SIZE,
		    NULL,
		    tskIDLE_PRIORITY + 1,
		    NULL) != pdPASS) {
30
		LOG_CRIT("startup", "Failed to create %s task!", "Serial");
Rahix's avatar
Rahix committed
31
32
33
		abort();
	}

34
35
36
37
38
39
	/* PMIC */
	if (xTaskCreate(
		    vPmicTask,
		    (const char *)"PMIC",
		    configMINIMAL_STACK_SIZE,
		    NULL,
Rahix's avatar
Rahix committed
40
		    tskIDLE_PRIORITY + 4,
41
		    NULL) != pdPASS) {
42
		LOG_CRIT("startup", "Failed to create %s task!", "PMIC");
43
44
45
46
		abort();
	}

	/* API */
Rahix's avatar
Rahix committed
47
	if (xTaskCreate(
Rahix's avatar
Rahix committed
48
49
		    vApiDispatcher,
		    (const char *)"API Dispatcher",
swym's avatar
swym committed
50
		    configMINIMAL_STACK_SIZE * 16,
Rahix's avatar
Rahix committed
51
52
53
		    NULL,
		    tskIDLE_PRIORITY + 2,
		    &dispatcher_task_id) != pdPASS) {
q3k's avatar
q3k committed
54
55
56
57
58
		LOG_CRIT(
			"startup",
			"Failed to create %s task!",
			"API Dispatcher"
		);
Rahix's avatar
Rahix committed
59
60
61
		abort();
	}

schneider's avatar
schneider committed
62
	/* BLE */
63
	if (ble_shall_start()) {
koalo's avatar
koalo committed
64
65
66
67
68
69
70
71
72
73
		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();
		}
74
75
	}

Rahix's avatar
Rahix committed
76
77
78
79
80
81
82
83
84
85
	/* Lifecycle */
	if (xTaskCreate(
		    vLifecycleTask,
		    (const char *)"Lifecycle",
		    configMINIMAL_STACK_SIZE * 4,
		    NULL,
		    tskIDLE_PRIORITY + 1,
		    NULL) != pdPASS) {
		LOG_CRIT("startup", "Failed to create %s task!", "Lifecycle");
		abort();
q3k's avatar
q3k committed
86
87
	}

88
	LOG_INFO("startup", "Starting FreeRTOS ...");
Rahix's avatar
Rahix committed
89
	vTaskStartScheduler();
90
91
92

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