main.c 2.5 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"
8
#include "mxc_delay.h"
Rahix's avatar
Rahix committed
9

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

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

18
	LOG_DEBUG("startup", "Initializing hardware ...");
19
20
	hardware_early_init();

21
22
23
24
25
26
27
	char *commit_buf  = "Commit: " CARD10_GITHASH;
	char *version_buf = "Version: " CARD10_VERSION;
	commit_buf[16] = '\0';
	epic_disp_print (5,  5, "card10 firmware", 0x0000, 0xffff);
	epic_disp_print (25, 5, version_buf,       0x0000, 0xffff);
	epic_disp_print (45, 5, commit_buf,        0x0000, 0xffff);
	mxc_delay(5000000);
28

29
	LOG_DEBUG("startup", "Initializing tasks ...");
Rahix's avatar
Rahix committed
30
31
32

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

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

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

schneider's avatar
schneider committed
71
	/* BLE */
72
	if (ble_shall_start()) {
koalo's avatar
koalo committed
73
74
75
76
77
78
79
80
81
82
		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();
		}
83
84
	}

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

109
	LOG_DEBUG("startup", "Starting FreeRTOS ...");
Rahix's avatar
Rahix committed
110
	vTaskStartScheduler();
111
112
113

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