main.c 2.2 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"
15
#include "api/interrupt-sender.h"
Rahix's avatar
Rahix committed
16

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

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

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

/*
 * 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
29
void vApiDispatcher(void *pvParameters)
Rahix's avatar
Rahix committed
30
{
31
	LOG_DEBUG("dispatcher", "Ready.");
Rahix's avatar
Rahix committed
32
	while (1) {
Rahix's avatar
Rahix committed
33
34
35
36
		if (api_dispatcher_poll()) {
			api_dispatcher_exec();
		}
		ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
Rahix's avatar
Rahix committed
37
	}
Rahix's avatar
Rahix committed
38
}
Rahix's avatar
Rahix committed
39
40
41

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

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

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

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

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

swym's avatar
swym committed
57
	fatfs_init();
58
	api_interrupt_init();
59
	stream_init();
60

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

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

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

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

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

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

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

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