main.c 2.14 KB
Newer Older
Rahix's avatar
Rahix committed
1
#include <stdio.h>
Rahix's avatar
Rahix committed
2
3
#include <stdlib.h>

4
#include "max32665.h"
Rahix's avatar
Rahix committed
5
#include "uart.h"
6
#include "cdcacm.h"
Rahix's avatar
Rahix committed
7
8

#include "card10.h"
9
#include "pmic.h"
Rahix's avatar
Rahix committed
10
#include "leds.h"
Rahix's avatar
Rahix committed
11
#include "api/dispatcher.h"
12
#include "modules/modules.h"
13
#include "modules/log.h"
14
#include "modules/stream.h"
Rahix's avatar
Rahix committed
15

schneider's avatar
schneider committed
16
17
18
#include <Heart.h>
#include "GUI_Paint.h"

Rahix's avatar
Rahix committed
19
20
#include "FreeRTOS.h"
#include "task.h"
Rahix's avatar
Rahix committed
21

22
TaskHandle_t dispatcher_task_id;
Rahix's avatar
Rahix committed
23
24
25
26
27

/*
 * API dispatcher task.  This task will sleep until an API call is issued and
 * then wake up to dispatch it.
 */
Rahix's avatar
Rahix committed
28
void vApiDispatcher(void *pvParameters)
Rahix's avatar
Rahix committed
29
{
30
	LOG_DEBUG("dispatcher", "Ready.");
Rahix's avatar
Rahix committed
31
	while (1) {
Rahix's avatar
Rahix committed
32
33
34
35
		if (api_dispatcher_poll()) {
			api_dispatcher_exec();
		}
		ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
Rahix's avatar
Rahix committed
36
	}
Rahix's avatar
Rahix committed
37
}
Rahix's avatar
Rahix committed
38
39
40

int main(void)
{
41
42
	LOG_INFO("startup", "Epicardium startup ...");

Rahix's avatar
Rahix committed
43
44
	card10_init();
	card10_diag();
Rahix's avatar
Rahix committed
45

schneider's avatar
schneider committed
46
47
48
	Paint_DrawImage(Heart, 0, 0, 160, 80);
	LCD_Update();

49
50
51
	/* TODO: Move this to its own function */
	SCB->SCR |= SCB_SCR_SEVONPEND_Msk;

52
53
54
55
	if (cdcacm_init() < 0) {
		LOG_ERR("startup", "USB-Serial unavailable");
	}

swym's avatar
swym committed
56
	fatfs_init();
57
	stream_init();
58

59
	LOG_INFO("startup", "Initializing tasks ...");
Rahix's avatar
Rahix committed
60
61
62

	/* Serial */
	if (xTaskCreate(
Rahix's avatar
Rahix committed
63
64
65
66
67
68
		    vSerialTask,
		    (const char *)"Serial",
		    configMINIMAL_STACK_SIZE,
		    NULL,
		    tskIDLE_PRIORITY + 1,
		    NULL) != pdPASS) {
69
		LOG_CRIT("startup", "Failed to create %s task!", "Serial");
Rahix's avatar
Rahix committed
70
71
72
		abort();
	}

73
74
75
76
77
78
79
80
	/* PMIC */
	if (xTaskCreate(
		    vPmicTask,
		    (const char *)"PMIC",
		    configMINIMAL_STACK_SIZE,
		    NULL,
		    tskIDLE_PRIORITY + 1,
		    NULL) != pdPASS) {
81
		LOG_CRIT("startup", "Failed to create %s task!", "PMIC");
82
83
84
85
		abort();
	}

	/* API */
Rahix's avatar
Rahix committed
86
	if (xTaskCreate(
Rahix's avatar
Rahix committed
87
88
		    vApiDispatcher,
		    (const char *)"API Dispatcher",
swym's avatar
swym committed
89
		    configMINIMAL_STACK_SIZE * 16,
Rahix's avatar
Rahix committed
90
91
92
		    NULL,
		    tskIDLE_PRIORITY + 2,
		    &dispatcher_task_id) != pdPASS) {
93
		LOG_CRIT("startup", "Failed to create %s task!", "API Dispatcher");
Rahix's avatar
Rahix committed
94
95
96
		abort();
	}

97
	LOG_INFO("startup", "Initializing dispatcher ...");
Rahix's avatar
Rahix committed
98
99
	api_dispatcher_init();

100
	LOG_INFO("startup", "Starting core1 payload ...");
Rahix's avatar
Rahix committed
101
	core1_start();
Rahix's avatar
Rahix committed
102

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

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