main.c 1.72 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

Rahix's avatar
Rahix committed
14
15
#include "FreeRTOS.h"
#include "task.h"
Rahix's avatar
Rahix committed
16

17
TaskHandle_t dispatcher_task_id;
Rahix's avatar
Rahix committed
18
19
20
21
22

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

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

38
39
40
	/* TODO: Move this to its own function */
	SCB->SCR |= SCB_SCR_SEVONPEND_Msk;

Rahix's avatar
Rahix committed
41
	cdcacm_init();
42

43
	printf("=> Initializing tasks ...\n");
Rahix's avatar
Rahix committed
44
45
46

	/* Serial */
	if (xTaskCreate(
Rahix's avatar
Rahix committed
47
48
49
50
51
52
		    vSerialTask,
		    (const char *)"Serial",
		    configMINIMAL_STACK_SIZE,
		    NULL,
		    tskIDLE_PRIORITY + 1,
		    NULL) != pdPASS) {
Rahix's avatar
Rahix committed
53
54
55
56
		printf("Failed to create serial-comms task!\n");
		abort();
	}

57
58
59
60
61
62
63
64
65
66
67
68
69
	/* 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
70
	if (xTaskCreate(
Rahix's avatar
Rahix committed
71
72
73
74
75
76
		    vApiDispatcher,
		    (const char *)"API Dispatcher",
		    configMINIMAL_STACK_SIZE,
		    NULL,
		    tskIDLE_PRIORITY + 2,
		    &dispatcher_task_id) != pdPASS) {
Rahix's avatar
Rahix committed
77
78
79
80
		printf("Failed to create api dispatcher task!\n");
		abort();
	}

81
	printf("=> Initializing dispatcher ...\n");
Rahix's avatar
Rahix committed
82
83
	api_dispatcher_init();

84
	printf("=> Starting core1 payload ...\n");
Rahix's avatar
Rahix committed
85
	core1_start();
Rahix's avatar
Rahix committed
86

87
	printf("=> Starting FreeRTOS ...\n");
Rahix's avatar
Rahix committed
88
	vTaskStartScheduler();
Rahix's avatar
Rahix committed
89
	printf("ERROR: FreeRTOS did not start due to unknown error!\n");
Rahix's avatar
Rahix committed
90
}