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

Rahix's avatar
Rahix committed
5
6
#include "FreeRTOS.h"
#include "task.h"
Rahix's avatar
Rahix committed
7

8
9
#include <stdlib.h>

10
TaskHandle_t dispatcher_task_id;
11

schneider's avatar
schneider committed
12
void vBleTask(void *pvParameters);
Rahix's avatar
Rahix committed
13

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

19
	LOG_INFO("startup", "Initializing hardware ...");
20
21
	hardware_early_init();

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

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

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

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

schneider's avatar
schneider committed
64
	/* BLE */
65
	if (xTaskCreate(
schneider's avatar
schneider committed
66
67
68
69
70
71
72
		    vBleTask,
		    (const char *)"BLE",
		    configMINIMAL_STACK_SIZE * 10,
		    NULL,
		    tskIDLE_PRIORITY + 1,
		    NULL) != pdPASS) {
		LOG_CRIT("startup", "Failed to create %s task!", "BLE");
73
74
75
		abort();
	}

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
}