Skip to content

Commit

Permalink
Fixes during hardware testing to a) stop the display error from being…
Browse files Browse the repository at this point in the history
… overwritten by initializing display and update display earlier in the test and b) prevent the UpdateDisplay task from running into FIFO_POP errors by setting the message queue semaphore to zero when resetting the queue. This was also added to assertTaskError to ensure the error doesn't get overwritten, but this really shouldn't happen so we may want to take it out.
  • Loading branch information
KnockbackNemo committed Oct 1, 2023
1 parent 7a03bb2 commit 6effcc8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
7 changes: 7 additions & 0 deletions Apps/Inc/UpdateDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,11 @@ UpdateDisplayError_t UpdateDisplay_SetRegenState(TriState_t state);
*/
UpdateDisplayError_t UpdateDisplay_SetCruiseState(TriState_t state);

/**
* @brief Clears the display message queue and sets the message counter semaphore value to 0
* @param none
* @returns none
*/
void UpdateDisplay_ClearQueue(void);

#endif
1 change: 1 addition & 0 deletions Apps/Src/Tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ void assertTaskError(os_error_loc_t errorLoc, error_code_t errorCode, callback_t
EmergencyContactorOpen(); // Apart from while loop because killing the motor is more important
Display_Error(errorLoc, errorCode); // Needs to happen before callback so that tasks can change the screen
// (ex: readCarCAN and evac screen for BPS trip)
UpdateDisplay_ClearQueue(); // Clear message queue to ensure no other commands overwrite the error screen
}


Expand Down
17 changes: 15 additions & 2 deletions Apps/Src/UpdateDisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ static UpdateDisplayError_t UpdateDisplay_SetComponent(Component_t comp, uint32_
};

ret = UpdateDisplay_PutNext(setCmd);
return UpdateDisplay_PutNext(setCmd);
return ret;
}
else{
assertUpdateDisplayError(UPDATEDISPLAY_ERR_PARSE_COMP);
Expand Down Expand Up @@ -363,6 +363,19 @@ UpdateDisplayError_t UpdateDisplay_SetCruiseState(TriState_t state){
return ret;
}

/**
* @brief Clears the display message queue and sets the message counter semaphore value to 0
*/
void UpdateDisplay_ClearQueue(){
OS_ERR err;
OSSemSet(&DisplayQ_Sem4, 0, &err); // Set the message queue semaphore value to 0
if (err != OS_ERR_TASK_WAITING) {
assertOSError(OS_DISPLAY_LOC, err); // Don't fault if UpdateDisplay is waiting
}
disp_fifo_renew(&msg_queue); // Clear the message queue

}

/**
* @brief Loops through the display queue and sends all messages
*/
Expand All @@ -383,7 +396,7 @@ void Task_UpdateDisplay(void *p_arg) {
* used if we haven't reached the restart limit and encounter an error
*/
static void handler_UpdateDisplay_Restart() {
disp_fifo_renew(&msg_queue); // Clear the message queue
UpdateDisplay_ClearQueue(); // Clear the message queue
Display_Reset(); // Try resetting to fix the display error
}

Expand Down
23 changes: 17 additions & 6 deletions Tests/Test_FaultThread_Exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ enum { // Test menu enum
};

/*** Constants ***/
#define TEST_OPTION TEST_UPDATEDISPLAY // Decide what to test based on test menu enum
#define READTRITIUM_OPTION T_HARDWARE_OVER_CURRENT_ERR // The enum for the tritium error we want to test (reference error enum)
#define TEST_OPTION TEST_READTRITIUM // Decide what to test based on test menu enum
#define READTRITIUM_OPTION T_DC_BUS_OVERVOLT_ERR // The enum for the tritium error we want to test (reference error enum)

/* READTRITIUM_OPTION menu:
T_HARDWARE_OVER_CURRENT_ERR = (1<<0),
Expand Down Expand Up @@ -159,6 +159,8 @@ void Task_ManagerTask(void* arg) {
CANbus_Init(MOTORCAN, NULL, 0);
CANbus_Init(CARCAN, NULL, 0);
Contactors_Init();
Display_Init();
UpdateDisplay_Init();
CANDATA_t canError;


Expand Down Expand Up @@ -196,6 +198,7 @@ void Task_ManagerTask(void* arg) {
case TEST_READTRITIUM:
// Test exceptions in ReadTritium by sending the fault chosen in READTRITIUM_OPTION
// Successful we enter a nonrecoverable fault and the fail message is not printed
// And the correct error info is shown on the display
// Also if the motor is reset three times before the fault for a hall error
printf("\n\n\r=========== Testing ReadTritium ===========");

Expand All @@ -212,10 +215,16 @@ void Task_ManagerTask(void* arg) {
canError.ID = MOTOR_STATUS;

createReadTritium();
//OSTimeDlyHMSM(0, 0, 10, 0, OS_OPT_TIME_HMSM_STRICT, &err); // Wait for the display to initialize
// for (int i = 0x07; i < 0x09; i++){
// printf("\n\rSending %x", i);
// Display_Error(OS_DISPLAY_LOC, i);
// OSTimeDlyHMSM(0, 0, 0, 104, OS_OPT_TIME_HMSM_STRICT, &err); // Wait for the display to initialize
//}
//OSTimeDlyHMSM(0, 0, 0, 10, OS_OPT_TIME_HMSM_STRICT, &err); // Wait for the display to initialize
printf("\n\n\rNow sending: %d", tritiumError); // Sending 0 means no Tritium error
CANbus_Send(canError, CAN_BLOCKING, MOTORCAN);
OSTimeDlyHMSM(0, 0, 1, 0, OS_OPT_TIME_HMSM_STRICT, &err); // Wait for ReadTritium to finish
printf("\n\rTesting Tritium error %d", READTRITIUM_OPTION);
if (tritiumError == T_HALL_SENSOR_ERR) { // Send the message extra times to allow for motor restart
for (int i = 0; i < 3; i++) { // Faults if greater than restart threshold (3)
CANbus_Send(canError, CAN_BLOCKING, MOTORCAN);
Expand Down Expand Up @@ -334,6 +343,9 @@ void Task_ManagerTask(void* arg) {
// Expected output
// The display should reset, and then the test will hit an infinite while loop.
createUpdateDisplay();

OSTimeDlyHMSM(0, 0, 10, 0, OS_OPT_TIME_HMSM_STRICT, &err); // Wait for the display to initialize
printf("\n\rSending display messages to fill queue");

for (int i = 0; i < 10; i++) {
UpdateDisplay_SetCruiseState(1 + i);
Expand All @@ -358,7 +370,7 @@ void Task_ManagerTask(void* arg) {
// Initializes ReadTritium
void createReadTritium(void) {
OS_ERR err;

OSTaskCreate(
(OS_TCB*)&ReadTritium_TCB,
(CPU_CHAR*)"ReadTritium",
Expand Down Expand Up @@ -433,8 +445,6 @@ void createUpdateDisplay(void) {
(OS_ERR *)&err
);
checkOSError(err);
Display_Init();
UpdateDisplay_Init();
printf("\n\rCreated and initialized Display and UpdateDisplay");

}
Expand Down Expand Up @@ -497,6 +507,7 @@ int main(void) {

checkOSError(err);

TaskSwHook_Init();

// Create the task manager thread
OSTaskCreate(
Expand Down

0 comments on commit 6effcc8

Please sign in to comment.