Loading...
Searching...
No Matches
AustralisCore.c
1/***********************************************************************************
2 * @file AustralisCore.c *
3 * @author Matt Ricci *
4 * @brief Main application entry point and system initialization. *
5 ***********************************************************************************/
6
7#include "AustralisCore.h"
8#include "stm32f439xx.h"
9
10// -- STD Lib -----------------------------------------------
11
12#include "stdio.h"
13
14// -- FreeRTOS ----------------------------------------------
15
16#include "FreeRTOS.h"
17#include "event_groups.h"
18#include "groups.h"
19#include "message_buffer.h"
20#include "semphr.h"
21#include "stream_buffer.h"
22
23// -- Australis Core ----------------------------------------
24
25#include "flashwrite.h"
26#include "hdataacquisition.h"
27#include "ldataacquisition.h"
28#include "state.h"
29#include "stateupdate.h"
30#include "tasklist.h"
31
32// ------------------------------------------------------------
33
34static void configure_interrupts();
35
36// RTOS event groups
37EventGroupHandle_t xTaskEnableGroup; // 0: FLASH, 1: HIGHRES, 2: LOWRES, 3: LORA, 7: IDLE
38EventGroupHandle_t xSystemStatusGroup; // 0-2: Flight state, 3: Payload, 4: Aerobrakes
39EventGroupHandle_t xMsgReadyGroup; // 0: LORA, 1: USB
40
41// RTOS message buffers
42MessageBufferHandle_t xUsbTxBuff;
43StreamBufferHandle_t xUsbRxBuff;
44StreamBufferHandle_t xGpsRxBuff;
45
46SemaphoreHandle_t xUsbMutex;
47
48#define AVG_BUFF_SIZE 15
49#define MEM_BUFF_SIZE 20992
50#define USB_TX_SIZE 25
51#define USB_RX_SIZE 25
52
53/* =============================================================================== */
58
59void Australis_startCore(void) {
60
61 // Start the scheduler
62 vTaskStartScheduler();
63}
64
65/* =============================================================================== */
79
80void Australis_init() {
81
82 #if coreUSE_TRACE == 1
83 xTraceEnable(TRC_START);
84 #endif
85
86 // TODO: Replace usage of event groups for xTaskEnableGroup and xMsgReadyGroup
87 // with direct-to-task notifications, for better efficiency and clarity as
88 // these flags aren't shared across multiple tasks.
89
90 // Initialise event groups for task synchronization and message signaling
91 xTaskEnableGroup = xEventGroupCreate(); // 0: FLASH, 1: HIGHRES, 2: LOWRES, 3: LORA, 7: IDLE
92 xSystemStatusGroup = xEventGroupCreate();
93 xMsgReadyGroup = xEventGroupCreate();
94 xEventGroupSetBits(xMsgReadyGroup, GROUP_MESSAGE_READY_LORA);
95
96// Initialise USB buffers and mutex
97// ALLOW FORMATTING
98#ifdef USB_TX_SIZE
99 xUsbTxBuff = xMessageBufferCreate(USB_TX_SIZE);
100 xUsbRxBuff = xStreamBufferCreate(USB_RX_SIZE, 1);
101#endif
102
103 xUsbMutex = xSemaphoreCreateMutex();
104
105 // Initialise core state
106 State_init();
107
108 /**********************************************************************************
109 * TASK INIT *
110 **********************************************************************************/
111
112 #if (coreTASK_ENABLE == 1)
113 xTaskCreate(vHDataAcquisition, "HDataAcq", 512, NULL, configMAX_PRIORITIES - 2, TaskList_new());
114 xTaskCreate(vLDataAcquisition, "LDataAcq", 512, NULL, configMAX_PRIORITIES - 3, TaskList_new());
115 xTaskCreate(vStateUpdate, "StateUpdate", 512, NULL, configMAX_PRIORITIES - 4, TaskList_new());
116 xTaskCreate(vFlashBuffer, "FlashData", 512, NULL, configMAX_PRIORITIES - 1, TaskList_new());
117 //xTaskCreate(vIdle, "Idle", 256, NULL, tskIDLE_PRIORITY, TaskList_new());
118 #endif
119}
void State_init()
Definition state.c:45
TaskHandle_t * TaskList_new()
Retrieve a pointer to the first empty task handle in list.
Definition tasklist.c:42