Skip to content

Commit

Permalink
Merged functionality of SendCarCAN into Telemetry and removed SendCar…
Browse files Browse the repository at this point in the history
…CAN remnants
  • Loading branch information
NathanielDelgado committed Jul 8, 2023
1 parent 69bb125 commit 771a916
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 191 deletions.
4 changes: 0 additions & 4 deletions Apps/Inc/Tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ void Task_UpdateDisplay(void* p_arg);

void Task_ReadTritium(void* p_arg);

void Task_SendCarCAN(void* p_arg);

void Task_Telemetry(void* p_arg);

void Task_DebugDump(void *p_arg);
Expand All @@ -79,7 +77,6 @@ extern OS_TCB SendTritium_TCB;
extern OS_TCB ReadCarCAN_TCB;
extern OS_TCB UpdateDisplay_TCB;
extern OS_TCB ReadTritium_TCB;
extern OS_TCB SendCarCAN_TCB;
extern OS_TCB Telemetry_TCB;
extern OS_TCB DebugDump_TCB;
extern OS_TCB CommandLine_TCB;
Expand All @@ -94,7 +91,6 @@ extern CPU_STK SendTritium_Stk[TASK_SEND_TRITIUM_STACK_SIZE];
extern CPU_STK ReadCarCAN_Stk[TASK_READ_CAR_CAN_STACK_SIZE];
extern CPU_STK UpdateDisplay_Stk[TASK_UPDATE_DISPLAY_STACK_SIZE];
extern CPU_STK ReadTritium_Stk[TASK_READ_TRITIUM_STACK_SIZE];
extern CPU_STK SendCarCAN_Stk[TASK_SEND_CAR_CAN_STACK_SIZE];
extern CPU_STK Telemetry_Stk[TASK_TELEMETRY_STACK_SIZE];
extern CPU_STK DebugDump_Stk[TASK_DEBUG_DUMP_STACK_SIZE];
extern CPU_STK CommandLine_Stk[TASK_COMMAND_LINE_STACK_SIZE];
Expand Down
2 changes: 1 addition & 1 deletion Apps/Src/ReadTritium.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Objective 1:
- if error
- assertOSError
- determine information important to telementry
- SendCarCAN
- Telemetry
- determine information important for storage
- acquire mutex on Storage Array
- Store information in Storage Array (based on index)
Expand Down
35 changes: 0 additions & 35 deletions Apps/Src/SendCarCAN.c

This file was deleted.

2 changes: 0 additions & 2 deletions Apps/Src/Tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ OS_TCB SendTritium_TCB;
OS_TCB ReadCarCAN_TCB;
OS_TCB UpdateDisplay_TCB;
OS_TCB ReadTritium_TCB;
OS_TCB SendCarCAN_TCB;
OS_TCB Telemetry_TCB;
OS_TCB DebugDump_TCB;
OS_TCB CommandLine_TCB;
Expand All @@ -34,7 +33,6 @@ CPU_STK SendTritium_Stk[TASK_SEND_TRITIUM_STACK_SIZE];
CPU_STK ReadCarCAN_Stk[TASK_READ_CAR_CAN_STACK_SIZE];
CPU_STK UpdateDisplay_Stk[TASK_UPDATE_DISPLAY_STACK_SIZE];
CPU_STK ReadTritium_Stk[TASK_READ_TRITIUM_STACK_SIZE];
CPU_STK SendCarCAN_Stk[TASK_SEND_CAR_CAN_STACK_SIZE];
CPU_STK Telemetry_Stk[TASK_TELEMETRY_STACK_SIZE];
CPU_STK DebugDump_Stk[TASK_DEBUG_DUMP_STACK_SIZE];
CPU_STK CommandLine_Stk[TASK_COMMAND_LINE_STACK_SIZE];
Expand Down
10 changes: 8 additions & 2 deletions Apps/Src/Telemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
// Make sure updated to the CarData_t and carMSGID are reflected in the CAN Bus IDs excel sheet

/**
* @brief Sends pedal, switch, light, and contactor information to be read by telemetry
* @brief Sends pedal, switch, light, and contactor information, as well as the
* feedback from the motor controller to be read by telemetry
*
* @param p_arg
*/
Expand All @@ -21,10 +22,15 @@ void Task_Telemetry(void *p_arg){
carMsg.data[i] = 0;
}
OS_ERR err;

CANDATA_t motorMsg;
Minion_Error_t Merr;

while (1) {

// Send motor msg
CAN_Queue_Pend(&motorMsg);
CANbus_Send(motorMsg, true, CARCAN);

// Get pedal information
carMsg.data[0] = Pedals_Read(ACCELERATOR);
carMsg.data[1] = Pedals_Read(BRAKE);
Expand Down
18 changes: 0 additions & 18 deletions Apps/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,24 +175,6 @@ void Task_Init(void *p_arg){
);
assertOSError(OS_MAIN_LOC, err);

// Initialize SendCarCAN
OSTaskCreate(
(OS_TCB*)&SendCarCAN_TCB,
(CPU_CHAR*)"SendCarCAN",
(OS_TASK_PTR)Task_SendCarCAN,
(void*)NULL,
(OS_PRIO)TASK_SEND_CAR_CAN_PRIO,
(CPU_STK*)SendCarCAN_Stk,
(CPU_STK_SIZE)WATERMARK_STACK_LIMIT,
(CPU_STK_SIZE)TASK_SEND_CAR_CAN_STACK_SIZE,
(OS_MSG_QTY)0,
(OS_TICK)0,
(void*)NULL,
(OS_OPT)(OS_OPT_TASK_STK_CLR),
(OS_ERR*)&err
);
assertOSError(OS_MAIN_LOC, err);


Minion_Error_t merr;
while(1){
Expand Down
4 changes: 2 additions & 2 deletions Docs/source/Apps/ExtraFiles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ Some files in the Apps folder don't contain any task code, but instead contain h
CAN Queue
=========

Multiple tasks need to send messages over the car CAN bus. Sending is rather slow, so a queue is employed to absorbed the bursty nature of sending CAN messages. This way, multiple tasks can just post can messages to the queue, and another task (SendCarCAN) takes care to consume and send them to the CAN bus.
Multiple tasks need to send messages over the car CAN bus. Sending is rather slow, so a queue is employed to absorbed the bursty nature of sending CAN messages. This way, multiple tasks can just post can messages to the queue, and another task (Telemetry) takes care to consume and send them to the CAN bus.

The public interface of the file includes:

``void CAN_Queue_Init(void)`` — Initialize the queue and its associated mutex.

``ErrorStatus CAN_Queue_Post(CANDATA_t message)`` — Used by tasks that want to post CAN messages. The messages are held in a FIFO queue.

``ErrorStatus CAN_Queue_Pend(CANDATA_t *message)`` — Used by SendCarCAN to consume the queue. This function blocks the caller until the queue contains at least one message, at which point it will return message and remove it from the queue.
``ErrorStatus CAN_Queue_Pend(CANDATA_t *message)`` — Used by Telemetry to consume the queue. This function blocks the caller until the queue contains at least one message, at which point it will return message and remove it from the queue.

================
Pedal to Percent
Expand Down
2 changes: 1 addition & 1 deletion Docs/source/Apps/ReadTritium.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Read Tritium Task
*****************

In its current iteration, the Read Tritium task forwards all incoming messages from motor CAN to car CAN. It does this using :ref:`can-queue`: The task posts messages to the queue, which are then read out by the SendCarCAN task.
In its current iteration, the Read Tritium task forwards all incoming messages from motor CAN to car CAN. It does this using :ref:`can-queue`: The task posts messages to the queue, which are then read out by the Telemetry task.
1 change: 0 additions & 1 deletion Docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Keep the docs clear and readible. Reach out to more experienced team members wit
Apps/Main
Apps/ReadCarCAN
Apps/ReadTritium
Apps/SendCarCAN
Apps/UpdateDisplay
Apps/SendTritium
Apps/ExtraFiles
Expand Down
18 changes: 0 additions & 18 deletions Tests/Test_DebugDump.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,24 +175,6 @@ void Task_Init(void *p_arg){
);
assertOSError(OS_MAIN_LOC, err);

// Initialize SendCarCAN
OSTaskCreate(
(OS_TCB*)&SendCarCAN_TCB,
(CPU_CHAR*)"SendCarCAN",
(OS_TASK_PTR)Task_SendCarCAN,
(void*)NULL,
(OS_PRIO)TASK_SEND_CAR_CAN_PRIO,
(CPU_STK*)SendCarCAN_Stk,
(CPU_STK_SIZE)WATERMARK_STACK_LIMIT,
(CPU_STK_SIZE)TASK_SEND_CAR_CAN_STACK_SIZE,
(OS_MSG_QTY)0,
(OS_TICK)0,
(void*)NULL,
(OS_OPT)(OS_OPT_TASK_STK_CLR),
(OS_ERR*)&err
);
assertOSError(OS_MAIN_LOC, err);

// Initialize DebugDump
OSTaskCreate(
(OS_TCB*)&DebugDump_TCB,
Expand Down
17 changes: 0 additions & 17 deletions Tests/Test_ReadandSendCarCAN.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,6 @@ int main(void) {
(OS_ERR*)&err
);

//spawn can send task
OSTaskCreate(
(OS_TCB*)&SendCarCAN_TCB,
(CPU_CHAR*)"SendCarCan",
(OS_TASK_PTR)Task_SendCarCAN,
(void*)NULL,
(OS_PRIO)3,
(CPU_STK*)SendCarCAN_Stk,
(CPU_STK_SIZE)DEFAULT_STACK_SIZE/10,
(CPU_STK_SIZE)DEFAULT_STACK_SIZE,
(OS_MSG_QTY)0,
(OS_TICK)NULL,
(void*)NULL,
(OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_STK_CHK),
(OS_ERR*)&err
);

// Task not created
if (err != OS_ERR_NONE) {
printf("Task error code %d\n", err);
Expand Down
89 changes: 0 additions & 89 deletions Tests/Test_SendCarCAN.c

This file was deleted.

18 changes: 17 additions & 1 deletion Tests/Test_Telemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void Task1(void *arg)
{
CPU_Init();

CANbus_Init(CARCAN);
CANbus_Init(CARCAN, NULL, 0);
CAN_Queue_Init();
// BSP_UART_Init(UART_2);
Pedals_Init();
Expand Down Expand Up @@ -50,6 +50,16 @@ void Task1(void *arg)
State contactorState = OFF;

CANDATA_t msg;
msg.ID = MOTOR_STATUS;
msg.idx = 0;
msg.data[0] = 0x12;
msg.data[1] = 0x34;
msg.data[2] = 0x56;
msg.data[3] = 0x78;
msg.data[4] = 0x9A;
msg.data[5] = 0xBC;
msg.data[6] = 0xDE;
msg.data[7] = 0xF0;

while (1){
// Switches can be modified through hardware
Expand All @@ -63,6 +73,12 @@ void Task1(void *arg)
Contactors_Set(MOTOR_CONTACTOR, contactorState, true);
Contactors_Set(ARRAY_CONTACTOR, contactorState, true);

(msg.ID)++;
if(msg.ID > 0x24F){
msg.ID = MOTOR_STATUS;
}
CAN_Queue_Post(msg);

CANbus_Read(&msg, CAN_BLOCKING, CARCAN);

OSTimeDlyHMSM(0, 0, 0, 500, OS_OPT_TIME_HMSM_STRICT, &err);
Expand Down

0 comments on commit 771a916

Please sign in to comment.