main.c 2.33 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_DEBUG("startup", "Initializing hardware ...");
18
19
	hardware_early_init();

20
21
22
23
	epic_disp_print (5, 5, "card10 firmware", 0x0000, 0xffff);
	epic_disp_print (5, 5, "Tag: v1.1", 0x0000, 0xffff);
	epic_disp_print (5, 5, "Commit: f54e3c0", 0x0000, 0xffff);

24
	LOG_DEBUG("startup", "Initializing tasks ...");
Rahix's avatar
Rahix committed
25
26
27

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

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

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

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

80
81
82
83
84
85
86
87
88
89
90
91
	/* 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
92
93
94
95
96
97
	/* Lifecycle */
	if (xTaskCreate(
		    vLifecycleTask,
		    (const char *)"Lifecycle",
		    configMINIMAL_STACK_SIZE * 4,
		    NULL,
98
		    tskIDLE_PRIORITY + 3,
Rahix's avatar
Rahix committed
99
100
101
		    NULL) != pdPASS) {
		LOG_CRIT("startup", "Failed to create %s task!", "Lifecycle");
		abort();
q3k's avatar
q3k committed
102
103
	}

104
	LOG_DEBUG("startup", "Starting FreeRTOS ...");
Rahix's avatar
Rahix committed
105
	vTaskStartScheduler();
106
107
108

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