From 1773632e481092529476a37679c1c95259ec2518 Mon Sep 17 00:00:00 2001 From: Diya Rajon Date: Sat, 7 Oct 2023 20:33:03 +0000 Subject: [PATCH] Reverse logic because thats how the current ignition works --- Apps/Inc/ReadCarCAN.h | 4 ++- Apps/Src/ReadCarCAN.c | 6 +++- Tests/Test_MinionDriver.c | 40 +++++++++++++------------- Tests/Test_Minions.c | 14 +++++++++ Tests/Test_ReadCarCANrewrite.c | 52 +++++++++++++++++++++------------- 5 files changed, 75 insertions(+), 41 deletions(-) create mode 100644 Tests/Test_Minions.c diff --git a/Apps/Inc/ReadCarCAN.h b/Apps/Inc/ReadCarCAN.h index df49dcb00..852b963be 100644 --- a/Apps/Inc/ReadCarCAN.h +++ b/Apps/Inc/ReadCarCAN.h @@ -30,6 +30,9 @@ typedef enum{ */ bool ChargeEnable_Get(void); +extern OS_SEM infoMutex; //Mutex to lock GPIO writes to input pins + + /** * @brief Returns the value of charge message saturation * @return Value between -15 to 15 @@ -45,7 +48,6 @@ int8_t PlusMinusMsgSaturation_Get(void); */ bool ArrayIgnitionStatus_Get(void); - /** * @brief Returns the value of charge message saturation * @return Whether array ignition is ON/OFF diff --git a/Apps/Src/ReadCarCAN.c b/Apps/Src/ReadCarCAN.c index d7f466164..7de1ad6d8 100644 --- a/Apps/Src/ReadCarCAN.c +++ b/Apps/Src/ReadCarCAN.c @@ -12,6 +12,8 @@ #define ARRAY_SATURATION_THRESHOLD (((SAT_BUF_LENGTH + 1) * SAT_BUF_LENGTH) / 4) #define MOTOR_SATURATION_THRESHOLD (((SAT_BUF_LENGTH + 1) * SAT_BUF_LENGTH) / 4) +OS_SEM infoMutex; + // Timer delay constants #define CAN_WATCH_TMR_DLY_MS 500u #define CAN_WATCH_TMR_DLY_TMR_TS ((CAN_WATCH_TMR_DLY_MS * OS_CFG_TMR_TASK_RATE_HZ) / (1000u)) //1000 for ms -> s conversion @@ -127,7 +129,7 @@ static void setMotorControllerBypassPrechargeComplete(void *p_tmr, void *p_arg){ * @brief Turns array and motor controller precharge bypass contactor ON/OFF based on ignition and precharge status * @param None */ -static void updatePrechargeContactors(void){ + void updatePrechargeContactors(void){ Minion_Error_t Merr; arrayIgnitionStatus = Minion_Read_Pin(IGN_1, &Merr); @@ -342,6 +344,7 @@ void Task_ReadCarCAN(void *p_arg){ assertOSError(OS_READ_CAN_LOC, err); while(1){ + OSSemPost(&infoMutex,OS_OPT_POST_NONE,&err); updatePrechargeContactors(); // Sets array and motor controller bypass ignition (IGN_1, IGN_2) contactor ON/OFF @@ -407,6 +410,7 @@ void Task_ReadCarCAN(void *p_arg){ break; } } + } } diff --git a/Tests/Test_MinionDriver.c b/Tests/Test_MinionDriver.c index 4bb3477a4..508ada2c0 100644 --- a/Tests/Test_MinionDriver.c +++ b/Tests/Test_MinionDriver.c @@ -25,34 +25,34 @@ void Task1(void *arg) OSTimeDlyHMSM(0, 0, 3, 0, OS_OPT_TIME_HMSM_STRICT, &e); // tests the reading and writing - // while (1){ - // char str[128]; - // bool regen = Minion_Read_Input(REGEN_SW); - // bool forward = Minion_Read_Input(FOR_SW); - // bool reverse = Minion_Read_Input(REV_SW); - // bool enable = Minion_Read_Input(CRUZ_EN); - // bool set = Minion_Read_Input(CRUZ_ST); - // bool ign1 = Minion_Read_Input(IGN_1); - // bool ign2 = Minion_Read_Input(IGN_2); + while (1){ + char str[128]; + bool regen = Minion_Read_Pin(REGEN_SW); + bool forward = Minion_Read_Pin(FOR_SW); + bool reverse = Minion_Read_Pin(REV_SW); + bool enable = Minion_Read_Pin(CRUZ_EN); + bool set = Minion_Read_Pin(CRUZ_ST); + bool ign1 = Minion_Read_Pin(IGN_1); + bool ign2 = Minion_Read_Pin(IGN_2); - // int size = sprintf(str, "regen = %d, forward = %d, reverse = %d, enable = %d, set = %d IGN1 = %d, IGN2 = %d \r", regen, forward,reverse,enable,set,ign1,ign2); - // BSP_UART_Write(UART_2, str, size); + int size = sprintf(str, "regen = %d, forward = %d, reverse = %d, enable = %d, set = %d IGN1 = %d, IGN2 = %d \r", regen, forward,reverse,enable,set,ign1,ign2); + BSP_UART_Write(UART_2, str, size); - // lightState=!lightState; - // Minion_Write_Output(BRAKELIGHT, lightState); + lightState=!lightState; + Minion_Write_Output(BRAKELIGHT, lightState); - // OSTimeDlyHMSM(0, 0, 0, 500, OS_OPT_TIME_HMSM_STRICT, &e); - // } + OSTimeDlyHMSM(0, 0, 0, 500, OS_OPT_TIME_HMSM_STRICT, &e); + } //tests the edge cases - bool output = Minion_Write_Output(REV_SW, lightState, &mErr); - bool input = Minion_Read_Input(BRAKELIGHT, &mErr); + // bool output = Minion_Write_Output(REV_SW, lightState, &mErr); + // bool input = Minion_Read_Pin(BRAKELIGHT, &mErr); - printf("This should print 0: %d", input); - printf("This should print 0: %d", output); + // printf("This should print 0: %d", input); + // printf("This should print 0: %d", output); - lightState = !lightState; + // lightState = !lightState; for(int i = 0; i < 999999; i++){}//should be half a second }; diff --git a/Tests/Test_Minions.c b/Tests/Test_Minions.c new file mode 100644 index 000000000..9304765fe --- /dev/null +++ b/Tests/Test_Minions.c @@ -0,0 +1,14 @@ +#include +#include "Minions.h" +int main(void){ + Minion_Init(); + BSP_UART_Init(UART_2); + Minion_Error_t e; + + while(1){ + printf("IGN_1: %d\n\r", Minion_Read_Pin(IGN_1, &e)); + printf("IGN_2: %d\n\r", Minion_Read_Pin(IGN_2, &e)); + + for(int i =0; i < 999999; i++){} + } +} \ No newline at end of file diff --git a/Tests/Test_ReadCarCANrewrite.c b/Tests/Test_ReadCarCANrewrite.c index fc278f22f..9a740ba66 100644 --- a/Tests/Test_ReadCarCANrewrite.c +++ b/Tests/Test_ReadCarCANrewrite.c @@ -35,7 +35,9 @@ enum { // Test menu enum }; /*** Constants ***/ -#define TEST_OPTION TEST_RENODE // Decide what to test based on test menu enum +#define TEST_OPTION TEST_HARDWARE_CHARGE_ENABLE // Decide what to test based on test menu enum + + static OS_TCB Task1_TCB; static CPU_STK Task1_Stk[DEFAULT_STACK_SIZE]; @@ -105,7 +107,7 @@ static void sendArrayEnableMsg(uint8_t isIgnitionOn){ } }else{ // for(int i = 0; i < 1; i++){ - CANbus_Send(charge_enable_msg, CAN_BLOCKING, CARCAN); // Charge Enable messages + CANbus_Send(charge_enable_msg, CAN_BLOCKING, CARCAN); // } } } @@ -115,19 +117,18 @@ static void sendMotorControllerEnableMsg(uint8_t isIgnitionOn){ printf("\n\r=========== Motor Controller Enable Msg Sent ==========="); if(isIgnitionOn == 2){ while(Contactors_Get(MOTOR_CONTROLLER_BYPASS_PRECHARGE_CONTACTOR) != true){ - CANbus_Send(all_clear_enable_msg, CAN_BLOCKING, CARCAN); // Charge Enable messages + CANbus_Send(all_clear_enable_msg, CAN_BLOCKING, CARCAN); } }else{ for(int i = 0; i < 1; i++){ - CANbus_Send(all_clear_enable_msg, CAN_BLOCKING, CARCAN); // Charge Enable messages + CANbus_Send(all_clear_enable_msg, CAN_BLOCKING, CARCAN); } } } static void sendDisableMsg(){ - printf("\n\r=========== Motor Controller Disable Msg Sent ==========="); - CANbus_Send(disable_msg, CAN_BLOCKING, CARCAN); // Charge Enable messages + CANbus_Send(disable_msg, CAN_BLOCKING, CARCAN); } static void sendEnableMsg(int isIgnitionOn){ @@ -135,16 +136,16 @@ static void sendEnableMsg(int isIgnitionOn){ if(isIgnitionOn == 2){ while(!Contactors_Get(MOTOR_CONTROLLER_BYPASS_PRECHARGE_CONTACTOR)){ CANbus_Send(enable_msg, CAN_BLOCKING, CARCAN); - } // Charge Enable messages + } if (isIgnitionOn == 1){ while(!Contactors_Get((ARRAY_BYPASS_PRECHARGE_CONTACTOR))){ CANbus_Send(enable_msg, CAN_BLOCKING, CARCAN); - } // Charge Enable messages + } } for(int i = 0; i < 1; i++){ - CANbus_Send(enable_msg, CAN_BLOCKING, CARCAN); // Charge Enable messages + CANbus_Send(enable_msg, CAN_BLOCKING, CARCAN); } } } @@ -159,6 +160,7 @@ static void turnContactorOn(uint8_t isIgnitionOn){ } } + // static void turnBothContactorsOn(){ // turnContactorOn(1); // turnContactorOn(2); @@ -193,33 +195,42 @@ void Task1(){ ); assertOSError(OS_MAIN_LOC, err); + OSSemCreate(&infoMutex, "mutex waits for info",1, &err); + assertOSError(OS_MAIN_LOC, err); - while(1){ + switch (TEST_OPTION) { case TEST_RENODE: + turnContactorOn(2); turnIgnitionOFF(); sendDisableMsg(); - infoDump(); + infoDump(); // turnContactorOn(1); // turnIgnitionOFF(); // sendArrayEnableMsg(0); + // OSMutexPend(&infoMutex, 0, OS_OPT_PEND_BLOCKING, ×tamp, &err); + // while (err != OS_ERR_NONE) + // { + // } // infoDump(); // turnContactorOn(2); // turnIgnitionOFF(); // sendMotorControllerEnableMsg(0); + // OSMutexPend(&infoMutex, 0, OS_OPT_PEND_BLOCKING, ×tamp, &err); + // while (err != OS_ERR_NONE) + // { + // } // infoDump(); turnContactorOn(2); turnIgnitionOFF(); sendEnableMsg(0); - turnIgnitionOFF(); - sendEnableMsg(0); - infoDump(); + infoDump(); turnIgnitionToArrayON(); sendDisableMsg(); @@ -288,19 +299,22 @@ void Task1(){ case TEST_HARDWARE_CHARGE_ENABLE: while(1){ - CANbus_Send(charge_enable_msg, CAN_BLOCKING, CARCAN); // Charge enable messages + CANbus_Send(enable_msg, CAN_BLOCKING, CARCAN); // Charge enable messages infoDump(); - } + for(int i =0; i < 999999; i++){} + } break; case TEST_HARDWARE_CHARGE_DISABLE: while(1){ - CANbus_Send(disable_msg, CAN_BLOCKING, CARCAN); // Charge disable messages - infoDump(); + Minion_Error_t Merr; + CANbus_Send(disable_msg, CAN_BLOCKING, CARCAN); // Charge enable messages + printf("\r\n%d", Minion_Read_Pin(IGN_1, &Merr)); + printf("\r\n%d", Minion_Read_Pin(IGN_2, &Merr)); } break; + } - } }