Skip to content

Commit

Permalink
Reverse logic because thats how the current ignition works
Browse files Browse the repository at this point in the history
  • Loading branch information
diyarajon committed Oct 7, 2023
1 parent ac190ac commit 1773632
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 41 deletions.
4 changes: 3 additions & 1 deletion Apps/Inc/ReadCarCAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion Apps/Src/ReadCarCAN.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -407,6 +410,7 @@ void Task_ReadCarCAN(void *p_arg){
break;
}
}

}
}

Expand Down
40 changes: 20 additions & 20 deletions Tests/Test_MinionDriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
14 changes: 14 additions & 0 deletions Tests/Test_Minions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdio.h>
#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++){}
}
}
52 changes: 33 additions & 19 deletions Tests/Test_ReadCarCANrewrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
// }
}
}
Expand All @@ -115,36 +117,35 @@ 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){
printf("\n\r=========== Enable Msg Sent ===========");
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);
}
}
}
Expand All @@ -159,6 +160,7 @@ static void turnContactorOn(uint8_t isIgnitionOn){
}
}


// static void turnBothContactorsOn(){
// turnContactorOn(1);
// turnContactorOn(2);
Expand Down Expand Up @@ -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, &timestamp, &err);
// while (err != OS_ERR_NONE)
// {
// }
// infoDump();

// turnContactorOn(2);
// turnIgnitionOFF();
// sendMotorControllerEnableMsg(0);
// OSMutexPend(&infoMutex, 0, OS_OPT_PEND_BLOCKING, &timestamp, &err);
// while (err != OS_ERR_NONE)
// {
// }
// infoDump();

turnContactorOn(2);
turnIgnitionOFF();
sendEnableMsg(0);
turnIgnitionOFF();
sendEnableMsg(0);
infoDump();
infoDump();

turnIgnitionToArrayON();
sendDisableMsg();
Expand Down Expand Up @@ -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;

}

}
}

Expand Down

0 comments on commit 1773632

Please sign in to comment.