main.c 1.96 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"
Rahix's avatar
Rahix committed
14

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

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

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

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

int main(void)
{
	card10_init();
	card10_diag();
Rahix's avatar
Rahix committed
41

schneider's avatar
schneider committed
42
43
44
	Paint_DrawImage(Heart, 0, 0, 160, 80);
	LCD_Update();

45
46
47
	/* TODO: Move this to its own function */
	SCB->SCR |= SCB_SCR_SEVONPEND_Msk;

Rahix's avatar
Rahix committed
48
	cdcacm_init();
swym's avatar
swym committed
49
	fatfs_init();
50

51
	LOG_DEBUG("startup", "Initializing tasks ...");
Rahix's avatar
Rahix committed
52
53
54

	/* Serial */
	if (xTaskCreate(
Rahix's avatar
Rahix committed
55
56
57
58
59
60
		    vSerialTask,
		    (const char *)"Serial",
		    configMINIMAL_STACK_SIZE,
		    NULL,
		    tskIDLE_PRIORITY + 1,
		    NULL) != pdPASS) {
61
		LOG_CRIT("startup", "Failed to create %s task!", "Serial");
Rahix's avatar
Rahix committed
62
63
64
		abort();
	}

65
66
67
68
69
70
71
72
	/* PMIC */
	if (xTaskCreate(
		    vPmicTask,
		    (const char *)"PMIC",
		    configMINIMAL_STACK_SIZE,
		    NULL,
		    tskIDLE_PRIORITY + 1,
		    NULL) != pdPASS) {
73
		LOG_CRIT("startup", "Failed to create %s task!", "PMIC");
74
75
76
77
		abort();
	}

	/* API */
Rahix's avatar
Rahix committed
78
	if (xTaskCreate(
Rahix's avatar
Rahix committed
79
80
		    vApiDispatcher,
		    (const char *)"API Dispatcher",
swym's avatar
swym committed
81
		    configMINIMAL_STACK_SIZE * 16,
Rahix's avatar
Rahix committed
82
83
84
		    NULL,
		    tskIDLE_PRIORITY + 2,
		    &dispatcher_task_id) != pdPASS) {
85
		LOG_CRIT("startup", "Failed to create %s task!", "API Dispatcher");
Rahix's avatar
Rahix committed
86
87
88
		abort();
	}

89
	LOG_INFO("startup", "Initializing dispatcher ...");
Rahix's avatar
Rahix committed
90
91
	api_dispatcher_init();

92
	LOG_INFO("startup", "Starting core1 payload ...");
Rahix's avatar
Rahix committed
93
	core1_start();
Rahix's avatar
Rahix committed
94

95
	LOG_INFO("startup", "Starting FreeRTOS ...");
Rahix's avatar
Rahix committed
96
	vTaskStartScheduler();
97
98
99

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