-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCubeTask.cpp
More file actions
85 lines (71 loc) · 2.25 KB
/
CubeTask.cpp
File metadata and controls
85 lines (71 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* CubeTask.cpp
*
* Created on: Oct 18, 2023
* Author: Chris
*/
#include "CubeTask.hpp"
#include "UARTDriver.hpp"
/**
* @brief Initializes Cube task with the RTOS scheduler
*/
void CubeTask::InitTask()
{
// Make sure the task is not already initialized
CUBE_ASSERT(rtTaskHandle == nullptr, "Cannot initialize UART task twice");
// Start the task
BaseType_t rtValue =
xTaskCreate((TaskFunction_t)CubeTask::RunTask,
(const char*)"CUBETask",
(uint16_t)UART_TASK_STACK_DEPTH_WORDS,
(void*)this,
(UBaseType_t)UART_TASK_RTOS_PRIORITY,
(TaskHandle_t*)&rtTaskHandle);
//Ensure creation succeded
CUBE_ASSERT(rtValue == pdPASS, "CUBETask::InitTask() - xTaskCreate() failed");
}
/**
* @brief Instance Run loop for the Cube Task, runs on scheduler start as long as the task is initialized.
* @param pvParams RTOS Passed void parameters, contains a pointer to the object instance, should not be used
*/
void CubeTask::Run(void * pvParams)
{
//UART Task loop
while(1) {
Command cm;
//Wait forever for a command
qEvtQueue->ReceiveWait(cm);
//Process the command
HandleCommand(cm);
}
}
/**
* @brief HandleCommand handles any command passed to the Cube task primary event queue. Responsible for
* handling all commands, even if unsupported. (Unexpected commands must still be reset)
* @param cm Reference to the command object to handle
*/
void CubeTask::HandleCommand(Command& cm)
{
//Switch for the GLOBAL_COMMAND
switch (cm.GetCommand()) {
case DATA_COMMAND: {
//Switch for task specific command within DATA_COMMAND
switch (cm.GetTaskCommand()) {
case CUBE_TASK_COMMAND_SEND_DEBUG:
#ifndef DISABLE_DEBUG
DEFAULT_DEBUG_UART_DRIVER->Transmit(cm.GetDataPointer(), cm.GetDataSize());
#endif
break;
default:
CUBE_PRINT("CUBETask - Received Unsupported DATA_COMMAND {%d}\n", cm.GetTaskCommand());
break;
}
break;
}
default:
CUBE_PRINT("CUBETask - Received Unsupported Command {%d}\n", cm.GetCommand());
break;
}
//No matter what we happens, we must reset allocated data
cm.Reset();
}