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

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

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

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

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

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

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

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

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

50
	printf("=> Initializing tasks ...\n");
Rahix's avatar
Rahix committed
51
52
53

	/* Serial */
	if (xTaskCreate(
Rahix's avatar
Rahix committed
54
55
56
57
58
59
		    vSerialTask,
		    (const char *)"Serial",
		    configMINIMAL_STACK_SIZE,
		    NULL,
		    tskIDLE_PRIORITY + 1,
		    NULL) != pdPASS) {
Rahix's avatar
Rahix committed
60
61
62
63
		printf("Failed to create serial-comms task!\n");
		abort();
	}

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

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

88
	printf("=> Initializing dispatcher ...\n");
Rahix's avatar
Rahix committed
89
90
	api_dispatcher_init();

91
	printf("=> Starting core1 payload ...\n");
Rahix's avatar
Rahix committed
92
	core1_start();
Rahix's avatar
Rahix committed
93

94
	printf("=> Starting FreeRTOS ...\n");
Rahix's avatar
Rahix committed
95
	vTaskStartScheduler();
Rahix's avatar
Rahix committed
96
	printf("ERROR: FreeRTOS did not start due to unknown error!\n");
Rahix's avatar
Rahix committed
97
}