diff --git a/Apps/Inc/UpdateDisplay.h b/Apps/Inc/UpdateDisplay.h index 1a98fc8d..6afb41b1 100644 --- a/Apps/Inc/UpdateDisplay.h +++ b/Apps/Inc/UpdateDisplay.h @@ -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 \ No newline at end of file diff --git a/Apps/Src/Tasks.c b/Apps/Src/Tasks.c index c837b0ad..50d53f1c 100644 --- a/Apps/Src/Tasks.c +++ b/Apps/Src/Tasks.c @@ -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 } diff --git a/Apps/Src/UpdateDisplay.c b/Apps/Src/UpdateDisplay.c index 45512180..d89aecb9 100644 --- a/Apps/Src/UpdateDisplay.c +++ b/Apps/Src/UpdateDisplay.c @@ -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); @@ -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 */ @@ -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 } diff --git a/Tests/Test_FaultThread_Exceptions.c b/Tests/Test_FaultThread_Exceptions.c index 2ae451a7..0fd2cff5 100644 --- a/Tests/Test_FaultThread_Exceptions.c +++ b/Tests/Test_FaultThread_Exceptions.c @@ -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), @@ -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; @@ -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 ==========="); @@ -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); @@ -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); @@ -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", @@ -433,8 +445,6 @@ void createUpdateDisplay(void) { (OS_ERR *)&err ); checkOSError(err); - Display_Init(); - UpdateDisplay_Init(); printf("\n\rCreated and initialized Display and UpdateDisplay"); } @@ -497,6 +507,7 @@ int main(void) { checkOSError(err); + TaskSwHook_Init(); // Create the task manager thread OSTaskCreate(