From 9a35ef37cefc2aedbbc250b137b25081315cdf91 Mon Sep 17 00:00:00 2001 From: MichaelMohn Date: Sat, 16 Mar 2024 15:12:37 -0600 Subject: [PATCH 01/25] UART_2 Read and Write Working --- Tests/Test_BSP_UART.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Tests/Test_BSP_UART.c b/Tests/Test_BSP_UART.c index 2e9e2fcdd..5a5e89216 100644 --- a/Tests/Test_BSP_UART.c +++ b/Tests/Test_BSP_UART.c @@ -1,10 +1,7 @@ /** * Test file for library to interact with UART * - * Run this test in conjunction with the simulator - * GUI. As this generates randomized values, the display - * will update the values accordingly to show that the - * display is reading the UART properly + * */ #include "common.h" @@ -13,13 +10,24 @@ #define TX_SIZE 128 +void TEST_UART_2_Read_Write(){ + BSP_UART_Init(UART_2); + const char* testStr = "Enter your favorite number:\n\r"; + BSP_UART_Write(UART_2, (char*) testStr , strlen(testStr)); + + char input[128]; + BSP_UART_Read(UART_2, input); + + BSP_UART_Write(UART_2, "\n", 1); + BSP_UART_Write(UART_2, input, 4); +} + int main(void) { - // BSP_UART_Init(UART_2); - BSP_UART_Init(UART_3); - const char* testStr = "\xff\xff\xffpage 2\xff\xff\xff"; - BSP_UART_Write(UART_3, (char*) testStr , strlen(testStr)); - while (1) {volatile int x=0; x++;} + TEST_UART_2_Read_Write(); + + + while(1); // char out[2][TX_SIZE]; // BSP_UART_Read(UART_2, out[UART_2]); // BSP_UART_Read(UART_3, out[UART_3]); From 13f81d1bf5d261d23629e5b4c786759012e24178 Mon Sep 17 00:00:00 2001 From: MichaelMohn Date: Sat, 16 Mar 2024 15:57:17 -0600 Subject: [PATCH 02/25] Printf and Scanf working --- BSP/STM32F413/Src/retarget.c | 4 ++-- Tests/Test_BSP_UART.c | 37 +++++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/BSP/STM32F413/Src/retarget.c b/BSP/STM32F413/Src/retarget.c index 305ffb46b..6506bd0a6 100644 --- a/BSP/STM32F413/Src/retarget.c +++ b/BSP/STM32F413/Src/retarget.c @@ -16,9 +16,9 @@ int _write(int fd, char *buffer, unsigned int len) { int _read(int const fd, char *buffer, unsigned const len) { if(buffer != NULL) { - + BSP_UART_Read(UART_2, buffer); } - return 1; + return len; } int _close(int file) diff --git a/Tests/Test_BSP_UART.c b/Tests/Test_BSP_UART.c index 5a5e89216..36cd24eab 100644 --- a/Tests/Test_BSP_UART.c +++ b/Tests/Test_BSP_UART.c @@ -10,33 +10,40 @@ #define TX_SIZE 128 +/** + * Read a line using UART + * Print the first 4 chars using UART + */ void TEST_UART_2_Read_Write(){ - BSP_UART_Init(UART_2); const char* testStr = "Enter your favorite number:\n\r"; BSP_UART_Write(UART_2, (char*) testStr , strlen(testStr)); + //128 is the minimum buffer size for BSP_UART_Read char input[128]; BSP_UART_Read(UART_2, input); - BSP_UART_Write(UART_2, "\n", 1); + //Print the first 4 characters of the input + BSP_UART_Write(UART_2, "\n\r", 2); BSP_UART_Write(UART_2, input, 4); } +/** + * Read a number using UART through scanf + * Print that number using UART printf +*/ +void Test_UART_2_Printf_Scanf(){ + int num; + printf("Enter a Number and I'll add one to it!\n\r"); + scanf("%d", &num); + printf("\n\r%d", num + 1); +} + int main(void) { + BSP_UART_Init(UART_2); - TEST_UART_2_Read_Write(); - + //Test_UART_2_Read_Write(); + //Test_UART_2_Printf_Scanf(); while(1); - // char out[2][TX_SIZE]; - // BSP_UART_Read(UART_2, out[UART_2]); - // BSP_UART_Read(UART_3, out[UART_3]); - // out[UART_2][strlen(out[UART_2])-1] = 0; // remove the newline, so we can print both in one line for now - // out[UART_3][strlen(out[UART_3])-1] = 0; - // printf("UART 2: %s\tUART 3: %s\r", out[UART_2], out[UART_3]); - // /* - // * If a long message is sent before a short message, the messages will overlap - // * on the display. This is not an issue with UART_2, but just a consequence of - // * how these tests must be structured and outputted. - // */ + } From fe1e5ead4ef005da37cd1bafcf6a1ac693779d2a Mon Sep 17 00:00:00 2001 From: MichaelMohn Date: Sat, 16 Mar 2024 16:50:05 -0600 Subject: [PATCH 03/25] UART_3 Working --- Tests/Test_BSP_UART.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Tests/Test_BSP_UART.c b/Tests/Test_BSP_UART.c index 36cd24eab..69179552a 100644 --- a/Tests/Test_BSP_UART.c +++ b/Tests/Test_BSP_UART.c @@ -38,12 +38,20 @@ void Test_UART_2_Printf_Scanf(){ printf("\n\r%d", num + 1); } +void Test_UART_3_Write(){ + const uint32_t test = 0xdeadbeef; + BSP_UART_Write(UART_3, (char*) &test , 4); +} + int main(void) { BSP_UART_Init(UART_2); //Test_UART_2_Read_Write(); //Test_UART_2_Printf_Scanf(); + BSP_UART_Init(UART_3); + Test_UART_3_Write(); + while(1); } From fc75c7675eb00e6b7aa6556c72c3b43c6c7ea3ca Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Thu, 21 Mar 2024 21:00:28 -0500 Subject: [PATCH 04/25] working BSP_ADC test with actual potentiometer --- Tests/Test_BSP_ADC.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/Tests/Test_BSP_ADC.c b/Tests/Test_BSP_ADC.c index a2515fb1d..c84ddfe1e 100644 --- a/Tests/Test_BSP_ADC.c +++ b/Tests/Test_BSP_ADC.c @@ -1,13 +1,8 @@ /** - * Test file for library to interact with hardware connected to ADC - * - * Run this test in conjunction with the simulator - * GUI. As you move the accelerator and brake on the GUI, the respective - * pressed/slided percentage will change from '0' to '100' on the terminal and display - * to show that sliding the pedals is read by the BSP - * - * Uncomment the "individual tests for each function" to determine the output of individual functions - * of the ADC module + * Test file for ADC + * Two channels: accelerator and brake + * Simply turn on the board and connect serial (UART2) as well as the potentiometer or + * analog device to the ADC pins, to inspect the values */ #include "common.h" @@ -19,17 +14,6 @@ int main() { BSP_ADC_Init(); BSP_UART_Init(UART_2); - - /* INDIVIDUAL TESTS FOR EACH FUNCTION - printf("TESTS\n"); - - printf("TESTING VALUE AND MILLIVOLTAGE\n"); - printf("ADC at channel of Accelerator is %d\n", BSP_ADC_Get_Value(Accelerator)); - printf("ADC at channel of Brake is %d\n", BSP_ADC_Get_Value(Brake)); - - printf("ADC at channel of Accelerator in mV is %d\n", BSP_ADC_Get_Millivoltage(Accelerator)); - printf("ADC at channel of Brake in mV is %d\n", BSP_ADC_Get_Millivoltage(Brake)); - */ while(1) { printf("Accelerator: %5.1d\tBrake: %5.1d\r", From b65e69273940d8c4463d37f8b16cfa967cd44a6b Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Thu, 21 Mar 2024 21:01:29 -0500 Subject: [PATCH 05/25] remove test bsp --- Tests/Test_BSP.c | 226 ----------------------------------------------- 1 file changed, 226 deletions(-) delete mode 100644 Tests/Test_BSP.c diff --git a/Tests/Test_BSP.c b/Tests/Test_BSP.c deleted file mode 100644 index eb9366dca..000000000 --- a/Tests/Test_BSP.c +++ /dev/null @@ -1,226 +0,0 @@ -/** - * Test file that unifies all individual test files of the BSP module - * - * Run this test in conjunction with the simulator - * GUI. - * - */ - -#include "common.h" -#include "config.h" -#include - -#include "BSP_ADC.h" -#include - -#define TX_SIZE 128 -#define LEN 4 -/** - * Moves the cursor n lines - */ -static void moveCursorUp(int n) { - if (n < 1) n = 1; - if (n > 99) n = 99; - printf("%c[%d;%dH", 0x1B, 1, 1); -} - -int main() { - - BSP_ADC_Init(Accelerator_ADC); - BSP_ADC_Init(Brake_ADC); - - BSP_CAN_Init(CAN_1); - //BSP_CAN_Init(CAN_2); - - BSP_Contactors_Init(MOTOR); - BSP_Contactors_Init(ARRAY); - - BSP_UART_Init(UART_3); - BSP_UART_Init(UART_2); - - BSP_Switches_Init(); - - uint8_t txData[LEN] = {0x00, 0x12, 0x42, 0x5A}; - - uint8_t txData2[LEN] = {0}; - uint8_t rxData[LEN] = {0}; - uint8_t rxData2[LEN] = {0}; - - int id2 = 0x321; - - bool negativeAcc = false; - - int threshold = 1000 * 10; - int writevsread = threshold; - - while(1) { - printf("%c[%d;%dH", 0x1B, 1, 1); - printf("-----PLEASE RUN THIS TEST FILE IN CONJUCTION WITH THE GUI-----\n"); - //BSP_ADC TEST ----------------------------------------------------------- - printf("-------------------------ADC TEST-----------------------------\n"); - printf("--------------------------------------------------------------\n"); - printf("As you move the pedals in the GUI their voltage values should change\n"); - printf("Accelerator: %5.1d mV\tBrake: %5.1d mV\n", - BSP_ADC_Get_Millivoltage(Accelerator_ADC), BSP_ADC_Get_Millivoltage(Brake_ADC)); - - //BSP_CAN TEST ----------------------------------------------------------- - //NOTE: The can test file can test both CAN1 ot CAN2 and - // it has them in separate functions - printf("-------------------------CANs TEST----------------------------\n"); - printf("--------------------------------------------------------------\n"); - printf("CAN bus 1 sends an ID and Message, which can be seen in the GUI\n"); - // CAN 1 TEST - BASICALLY JUST COPIED IT FROM BSP_CAN.c - if(txData[3] > 0x70){ - negativeAcc = true; - }else if(txData[3] < 0x40){ - negativeAcc = false; - } - - if(!negativeAcc){ - txData[3] = txData[3]+1; - }else{ - txData[3] = txData[3]-1; - } - - uint32_t id; - BSP_CAN_Write(CAN_1, 0x221, txData, LEN); - - uint8_t len = BSP_CAN_Read(CAN_1, &id, rxData); - - // printf("ID: 0x%x\nData: ", id); - // for (uint8_t i = 0; i < len; i++) { - // printf("0x%x ", rxData[i]); - // } - // printf("\n"); - - // CAN 2 test by random values - - if(writevsread == threshold){ - writevsread = 0; - id2 = rand() % 0xFFF; - for(int i = 0; i < LEN; i++){ - txData2[i] = rand() % 0xFF; - } - } else { - writevsread++; - } - - - uint8_t can2len = BSP_CAN_Read(CAN_2, &id2, rxData2); - printf("Values read from CAN_2\n"); - printf("ID: 0x%x length: %d\n", id2, can2len); - for(int i = 0; i < can2len; i++){ - printf("0x%x ", rxData2[i]); - fflush(stdout); - } - printf("\n"); - - //BSP_SWITCHES TEST ------------------------------------------------------ - printf("---------------------- SWITCHES TEST--------------------------\n"); - printf("--------------------------------------------------------------\n"); - printf("Press switches on the GUI, their state will be displayed:\n"); - printf("LT\tRT HDLT FWD_REV HZD CRS_SET CRS_EN REGEN IGN_1 IGN_2\n"); - printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", - BSP_Switches_Read(LT), - BSP_Switches_Read(RT), - BSP_Switches_Read(HDLT), - BSP_Switches_Read(FWD_REV), - BSP_Switches_Read(HZD), - BSP_Switches_Read(CRS_SET), - BSP_Switches_Read(CRS_EN), - BSP_Switches_Read(REGEN), - BSP_Switches_Read(IGN_1), - BSP_Switches_Read(IGN_2)); - - //BSP_UART TEST ---------------------------------------------------------- - //printf("--------------------------------------------------------------\n"); - printf("-------------------------UART TEST----------------------------\n"); - printf("--------------------------------------------------------------\n"); - printf("The UARTs are showing random values, UART 1 communicates with\n"); - printf("the gecko display while UART2 with the user direclty \n"); - - uint8_t byte1 = rand() % 256; - uint8_t byte2 = rand() % 256; - uint8_t byte3 = rand() % 256; - uint8_t byte4 = rand() % 256; - uint8_t byte5 = rand() % 256; - char str[TX_SIZE]; - sprintf(str, "%x%x%x%x%x", byte1, byte2, byte3, byte4, byte5); - - float speed1 = (rand() % 500) / 10.0; - int cruiseEn1 = rand() % 2; - int cruiseSet1 = rand() % 2; - int regenEn1 = rand() % 2; - int CANerr1 = rand() % 10; - char str1[TX_SIZE]; - sprintf(str1, "%f, %d, %d, %d, %d", speed1, cruiseEn1, cruiseSet1, regenEn1, CANerr1); - - BSP_UART_Write(UART_2, str , TX_SIZE); - BSP_UART_Write(UART_3, str1, TX_SIZE); - - char out[2][TX_SIZE]; - BSP_UART_Read(UART_3, out[UART_3]); - BSP_UART_Read(UART_2, out[UART_2]); - out[UART_3][strlen(out[UART_3])-1] = 0; // remove the newline, so we can print both in one line for now - out[UART_2][strlen(out[UART_2])-1] = 0; - - printf(" SPEED CRS_EN CRS_SET REGEN CAN_ERROR\n"); - printf("UART 1: %s\n", out[UART_3]); - printf("UART 2: %s\n", out[UART_2]); - - //BSP_Contactors ----------------------------------------------------- - //NOTE: The contactors test file requires input from the user in the original test - printf("----------------------CONTACTORS TEST-------------------------\n"); - printf("--------------------------------------------------------------\n"); - printf("Contactors are constantly updated randomly, changes also visible in GUI\n"); - int motorOrArray = rand() % 2; - int onOrOff = rand() % 2; - if (motorOrArray == 1){ - if (onOrOff == 1){ - BSP_Contactors_Set(MOTOR, ON); - } - else { - BSP_Contactors_Set(MOTOR, OFF); - } - }else{ - if (onOrOff == 1){ - BSP_Contactors_Set(ARRAY, ON); - } - else { - BSP_Contactors_Set(ARRAY, OFF); - } - } - printf("MOTOR CONTACTOR STATE: %d\n", BSP_Contactors_Get(MOTOR)); - printf("ARRAY CONTACTOR STATE: %d\n", BSP_Contactors_Get(ARRAY)); - - //BSP_Precharge ----------------------------------------------------- - //NOTE: The precharge test file requires input from the user in the original test - printf("----------------------Precharge TEST--------------------------\n"); - printf("--------------------------------------------------------------\n"); - int precCase = rand() % 4; - - switch (precCase) - { - case 0: - BSP_Precharge_Write(MOTOR_PRECHARGE, OFF); - printf("MOTOR PRECHARGE STATE SET TO: OFF\n"); - break; - case 1: - BSP_Precharge_Write(MOTOR_PRECHARGE, ON); - printf("MOTOR PRECHARGE STATE SET TO: ON \n"); - break; - case 2: - BSP_Precharge_Write(ARRAY_PRECHARGE_BYPASS_CONTACTOR, OFF); - printf("ARRAY PRECHARGE STATE SET TO: OFF\n"); - break; - case 3: - BSP_Precharge_Write(ARRAY_PRECHARGE_BYPASS_CONTACTOR, ON); - printf("ARRAY PRECHARGE STATE SET TO: ON \n"); - break; - default: - break; - } - } - printf("\n"); - return 0; -} From 4fbe4e58e2a41fe621be1ef8d33183bbd106fe72 Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Thu, 21 Mar 2024 21:02:14 -0500 Subject: [PATCH 06/25] added return --- Tests/Test_BSP_ADC.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/Test_BSP_ADC.c b/Tests/Test_BSP_ADC.c index c84ddfe1e..95965392c 100644 --- a/Tests/Test_BSP_ADC.c +++ b/Tests/Test_BSP_ADC.c @@ -19,4 +19,6 @@ int main() { printf("Accelerator: %5.1d\tBrake: %5.1d\r", BSP_ADC_Get_Millivoltage(Accelerator_ADC), BSP_ADC_Get_Millivoltage(Brake_ADC)); } + + return 0; } From 316917e4b14de3cbb5081bd1594ac4ab922e2821 Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Thu, 21 Mar 2024 21:32:01 -0500 Subject: [PATCH 07/25] fixed up uart test comments and naming --- Tests/Test_BSP_UART.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Tests/Test_BSP_UART.c b/Tests/Test_BSP_UART.c index 69179552a..8d0613ee7 100644 --- a/Tests/Test_BSP_UART.c +++ b/Tests/Test_BSP_UART.c @@ -14,7 +14,7 @@ * Read a line using UART * Print the first 4 chars using UART */ -void TEST_UART_2_Read_Write(){ +void Test_UART_2_Read_Write(){ const char* testStr = "Enter your favorite number:\n\r"; BSP_UART_Write(UART_2, (char*) testStr , strlen(testStr)); @@ -38,6 +38,10 @@ void Test_UART_2_Printf_Scanf(){ printf("\n\r%d", num + 1); } +/** + * Write a 32 bit number to UART 3 and read it back + * on a logic analyzer +*/ void Test_UART_3_Write(){ const uint32_t test = 0xdeadbeef; BSP_UART_Write(UART_3, (char*) &test , 4); @@ -45,11 +49,10 @@ void Test_UART_3_Write(){ int main(void) { BSP_UART_Init(UART_2); - - //Test_UART_2_Read_Write(); - //Test_UART_2_Printf_Scanf(); - BSP_UART_Init(UART_3); + + Test_UART_2_Read_Write(); + Test_UART_2_Printf_Scanf(); Test_UART_3_Write(); while(1); From 2a3ea1bed58ce88905f16e2f7934c34425b86d43 Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Fri, 22 Mar 2024 15:41:20 -0500 Subject: [PATCH 08/25] clerical changes --- Embedded-Sharepoint | 2 +- Tests/Test_BSP_CAN.c | 45 ----------------------------- Tests/Test_BSP_CAN_loopback.c | 53 +++++------------------------------ Tests/Test_BSP_UART.c | 7 +++-- 4 files changed, 13 insertions(+), 94 deletions(-) delete mode 100644 Tests/Test_BSP_CAN.c diff --git a/Embedded-Sharepoint b/Embedded-Sharepoint index 7584311df..0d80b95ab 160000 --- a/Embedded-Sharepoint +++ b/Embedded-Sharepoint @@ -1 +1 @@ -Subproject commit 7584311df293c27ac40d60bcb29cb662496a792e +Subproject commit 0d80b95ab47648b09034cc27a8b755bd89a4589b diff --git a/Tests/Test_BSP_CAN.c b/Tests/Test_BSP_CAN.c deleted file mode 100644 index 1939d07f9..000000000 --- a/Tests/Test_BSP_CAN.c +++ /dev/null @@ -1,45 +0,0 @@ -#include "common.h" -#include "CANbus.h" -#include "config.h" - -int generalTest(void){ - // Tests sending and receiving messages - uint32_t ids[10] = {0x242, 0x243, 0x244, 0x245, 0x246, 0x247, 0x24B, 0x24E, 0x580, CHARGE_ENABLE}; - uint8_t buffer[8]; - - CANData_t data; - data.d = 0x87654321; - - CANPayload_t payload; - payload.data = data; - payload.bytes = 4; - - for(int i=0; i Date: Sat, 23 Mar 2024 12:20:03 -0500 Subject: [PATCH 09/25] Added BSP_CAN test and deleted some olde tests --- Tests/Test_BPSFault.c | 96 ----------------------------------- Tests/Test_BSP_CAN.c | 48 ++++++++++++++++++ Tests/Test_BSP_CAN_loopback.c | 20 -------- 3 files changed, 48 insertions(+), 116 deletions(-) delete mode 100644 Tests/Test_BPSFault.c create mode 100644 Tests/Test_BSP_CAN.c delete mode 100644 Tests/Test_BSP_CAN_loopback.c diff --git a/Tests/Test_BPSFault.c b/Tests/Test_BPSFault.c deleted file mode 100644 index c80b70983..000000000 --- a/Tests/Test_BPSFault.c +++ /dev/null @@ -1,96 +0,0 @@ -/* Copyright (c) 2020 UT Longhorn Racing Solar */ - -#include "Tasks.h" -#include "CANbus.h" -#include "CAN_Queue.h" -#include "ReadCarCAN.h" -#include "Display.h" -#include "Contactors.h" -#include "CANConfig.h" - -/* - * NOTE: This test must be run with car CAN in loopback mode - * TODO: automate this, either with arguments to BSP or #define -*/ - -static OS_TCB Task1_TCB; -#define STACK_SIZE 256 -static CPU_STK Task1_Stk[STACK_SIZE]; - -#define CARCAN_FILTER_SIZE (sizeof carCANFilterList / sizeof(CANId_t)) - -void Task1(){ - OS_ERR err; - - CPU_Init(); - OS_CPU_SysTickInit(SystemCoreClock / (CPU_INT32U) OSCfg_TickRate_Hz); - CANbus_Init(CARCAN, carCANFilterList, CARCAN_FILTER_SIZE); - Contactors_Init(); - - // Send a BPS trip - CANDATA_t data = {.ID = BPS_TRIP, .idx = 0, .data = {1}}; - CANbus_Send(data, true, CARCAN); - OSTaskDel(NULL, &err); -} - -int main(){ - OS_ERR err; - OSInit(&err); - assertOSError(err); - TaskSwHook_Init(); - - OSSemCreate(&FaultState_Sem4, "Fault State Semaphore", 0, &err); - OSTaskCreate( - (OS_TCB*)&Task1_TCB, - (CPU_CHAR*)"Task1", - (OS_TASK_PTR)Task1, - (void*)NULL, - (OS_PRIO)4, - (CPU_STK*)Task1_Stk, - (CPU_STK_SIZE)STACK_SIZE/10, - (CPU_STK_SIZE)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 - ); - assertOSError(err); - - OSTaskCreate( - (OS_TCB*)&FaultState_TCB, - (CPU_CHAR*)"Fault State", - (OS_TASK_PTR)Task_FaultState, - (void*)NULL, - (OS_PRIO)TASK_FAULT_STATE_PRIO, - (CPU_STK*)FaultState_Stk, - (CPU_STK_SIZE)STACK_SIZE/10, - (CPU_STK_SIZE)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 - ); - assertOSError(err); - - OSTaskCreate( - (OS_TCB*)&ReadCarCAN_TCB, - (CPU_CHAR*)"ReadCarCAN", - (OS_TASK_PTR)Task_ReadCarCAN, - (void*)NULL, - (OS_PRIO)TASK_READ_CAR_CAN_PRIO, - (CPU_STK*)ReadCarCAN_Stk, - (CPU_STK_SIZE)STACK_SIZE/10, - (CPU_STK_SIZE)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 - ); - assertOSError(err); - - OSStart(&err); - assertOSError(err); -} diff --git a/Tests/Test_BSP_CAN.c b/Tests/Test_BSP_CAN.c new file mode 100644 index 000000000..c8985e676 --- /dev/null +++ b/Tests/Test_BSP_CAN.c @@ -0,0 +1,48 @@ +/** + * Test file for BSP_CAN + * + * Use test_send to send and test_read to read + * + * Parameter for the test is the bus you want to test on +*/ + +#include "BSP_CAN.h" + +void test_send(CAN_t bus); +void test_read(CAN_t bus); + +int main(void) { + // test_send(CAN_1); + test_read(CAN_1); + while(1) { } +} + +void test_send(CAN_t bus) { + BSP_CAN_Init(bus, NULL, NULL, NULL, 0); + + uint8_t data[8] = {1, 2, 3, 4, 5, 6, 7, 8}; + + BSP_CAN_Write(bus, 0x001, data, 8); +} + +void test_read(CAN_t bus) { + BSP_CAN_Init(bus, NULL, NULL, NULL, 0); + BSP_UART_Init(UART_2); + + uint8_t tx_data[8] = {1, 2, 3, 4, 5, 6, 7, 8}; + + BSP_CAN_Write(bus, 0x001, tx_data, 8); + + uint32_t rx_id; + uint8_t rx_data[8]; + + for(int i = 0; i < 999999; i++) {} // delay for hardware of read hardware to update + + BSP_CAN_Read(bus, &rx_id, rx_data); + + printf("%ld\n\r", rx_id); + for(int i = 0; i < 8; i++) { + printf("%x ", rx_data[i]); + } + printf("\n\r"); +} diff --git a/Tests/Test_BSP_CAN_loopback.c b/Tests/Test_BSP_CAN_loopback.c deleted file mode 100644 index 5efdf4947..000000000 --- a/Tests/Test_BSP_CAN_loopback.c +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Test file for CAN - * - * - */ - -#include "common.h" -#include "Tasks.h" -#include "BSP_CAN.h" - -void - -int main(){ - BSP_CAN_Init(CAN_1, NULL, NULL, NULL, 0); - BSP_CAN_Init(CAN_3, NULL, NULL, NULL, 0); - - - - while(1){}; -} From 05113fe40859dcd92c804dcfafbbca7894e39879 Mon Sep 17 00:00:00 2001 From: Nathaniel Delgado Date: Sat, 23 Mar 2024 14:20:05 -0500 Subject: [PATCH 10/25] Wrote tests for Minions and Pedals --- Drivers/Inc/GPIOExpander.h | 54 --------------------- Tests/Test_Driver_Minions.c | 93 +++++++++++-------------------------- Tests/Test_Driver_Pedal_.c | 16 ++----- 3 files changed, 32 insertions(+), 131 deletions(-) delete mode 100644 Drivers/Inc/GPIOExpander.h diff --git a/Drivers/Inc/GPIOExpander.h b/Drivers/Inc/GPIOExpander.h deleted file mode 100644 index 5e8644c85..000000000 --- a/Drivers/Inc/GPIOExpander.h +++ /dev/null @@ -1,54 +0,0 @@ -/** - * @copyright Copyright (c) 2018-2023 UT Longhorn Racing Solar - * @file GPIOExpander.h - * @brief - * - * @defgroup GPIOExpander - * @addtogroup GPIOExpander - * @{ - */ - -/* Deprecated */ - -#ifndef __GPIOEXPANDER_H -#define __GPIOEXPANDER_H - -#include "common.h" - -typedef struct _spi_message { - int8_t opcode; - int8_t requestedPort; - int8_t data; -} spi_message; - - -// Opcodes -#define SPI_OPCODE_R 0x41 -#define SPI_OPCODE_W 0x40 - -// Register Addresses (BANK = 0) -#define SPI_IODIRA 0x00 -#define SPI_IOPOLA 0x02 -#define SPI_GPINTENA 0x04 -#define SPI_DEFVALA 0x06 -#define SPI_INTCONA 0x08 -#define SPI_IOCONA 0x0A -#define SPI_GPPUA 0x0C -#define SPI_INTFA 0x0E -#define SPI_INTCAPA 0x10 -#define SPI_GPIOA 0x12 - -#define SPI_IODIRB 0x01 -#define SPI_IOPOLB 0x03 -#define SPI_GPINTENB 0x05 -#define SPI_DEFVALB 0x07 -#define SPI_INTCONB 0x09 -#define SPI_GPPUAB 0x0D -#define SPI_INTFAB 0x0F -#define SPI_INTCAPB 0x11 -#define SPI_GPIOB 0x13 -#define SPI_OLATB 0x15 - -#endif - -/* @} */ diff --git a/Tests/Test_Driver_Minions.c b/Tests/Test_Driver_Minions.c index 7613a1656..618a96842 100644 --- a/Tests/Test_Driver_Minions.c +++ b/Tests/Test_Driver_Minions.c @@ -1,72 +1,35 @@ -/* Copyright (c) 2020 UT Longhorn Racing Solar */ +/** + * Test for Minons (high level abstraction layer of GPIO) + */ -#include "os.h" -#include "Tasks.h" #include "Minions.h" -#include -#include "config.h" -#include "common.h" -static OS_TCB Task1TCB; -static CPU_STK Task1Stk[DEFAULT_STACK_SIZE]; - -#define tof(b) (b ? "on" : "off") - -void Task1(void *arg) { - CPU_Init(); - OS_CPU_SysTickInit(SystemCoreClock / (CPU_INT32U)OSCfg_TickRate_Hz); - +void test(void) { BSP_UART_Init(UART_2); - Minion_Init(); - - OS_ERR err; - Minion_Error_t mErr; - bool brake_on = false; - bool ign1, ign2, regen_sw, for_sw, rev_sw, cruz_en, cruz_st; - - for (;;) { - Minion_Write_Output(BRAKELIGHT, brake_on, &mErr); - ign1 = !Minion_Read_Pin(IGN_1, &mErr); - ign2 = !Minion_Read_Pin(IGN_2, &mErr); - regen_sw = Minion_Read_Pin(REGEN_SW, &mErr); - for_sw = Minion_Read_Pin(FOR_SW, &mErr); - rev_sw = Minion_Read_Pin(REV_SW, &mErr); - cruz_en = Minion_Read_Pin(CRUZ_EN, &mErr); - cruz_st = Minion_Read_Pin(CRUZ_ST, &mErr); - printf( - "--------------------\r\nign1: %s\r\nign2: %s\r\n"\ - "regen_sw: %s\r\nfor_sw: %s\r\nrev_sw: %s\r\n"\ - "cruz_en: %s\r\ncruz_st: %s\r\n--------------------\r\n\r\n", - tof(ign1), tof(ign2), tof(regen_sw), tof(for_sw), - tof(rev_sw), tof(cruz_en), tof(cruz_st) - ); - - brake_on = !brake_on; - OSTimeDlyHMSM(0, 0, 1, 0, OS_OPT_TIME_HMSM_STRICT, &err); - } -}; + Minions_Init(); + + bool brake = 0; + int ign1, ign2, regen_sw, for_sw, rev_sw, cruz_en, cruz_st; + + Minions_Write(BRAKELIGHT, brake); + ign1 = Minions_Read(IGN_1); + ign2 = Minions_Read(IGN_2); + regen_sw = Minions_Read(REGEN_SW); + for_sw = Minions_Read(FOR_SW); + rev_sw = Minions_Read(REV_SW); + cruz_en = Minions_Read(CRUZ_EN); + cruz_st = Minions_Read(CRUZ_ST); + printf( + "--------------------\r\nign1 : %d\r\nign2 : %d\r\nregen_sw : %d\r\nfor_sw : %d\r\nrev_sw : %d\r\ncruz_en : %d\r\ncruz_st : %d\r\n--------------------\r\n\r\n", + ign1, ign2, regen_sw, for_sw, + rev_sw, cruz_en, cruz_st); + + brake = !brake; + + for (int i = 0; i < 999999999; i++) {} +} int main(void) { - OS_ERR err; - OSInit(&err); - - // create tester thread - OSTaskCreate( - (OS_TCB *)&Task1TCB, - (CPU_CHAR *)"Task 1", - (OS_TASK_PTR)Task1, - (void *)NULL, - (OS_PRIO)13, - (CPU_STK *)Task1Stk, - (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_ERR *)&err); - assertOSError(err); - - OSStart(&err); + test(); + while(1) {} } - diff --git a/Tests/Test_Driver_Pedal_.c b/Tests/Test_Driver_Pedal_.c index 1bf737e02..781cbd2dd 100644 --- a/Tests/Test_Driver_Pedal_.c +++ b/Tests/Test_Driver_Pedal_.c @@ -1,25 +1,17 @@ /** * Test file for library to interact with the pedal driver file * - * Run this test in conjunction with the simulator - * GUI. As you move the accelerator and brake on the GUI, the respective - * pressed/slided percentage will change from '0' to '100' on the terminal and display - * to show that sliding the pedals is read by the BSP + * Reads the Acceleration and Brake signals and prints them out * */ -#include "common.h" -#include "config.h" #include "Pedals.h" -#include - -int main() { +int main(void) { Pedals_Init(); while(1) { - printf("Accelerator: %5.1d%%\tBrake: %5.1d%%\r", - Pedals_Read(ACCELERATOR),Pedals_Read(BRAKE)); + printf("Accelerator: %5.1d%%\tBrake: %5.1d%%\n\r", + Pedals_Read(ACCELERATOR), Pedals_Read(BRAKE)); } } - From 6d531d46c2a1fb2fea541fd35409f58c1c8843c4 Mon Sep 17 00:00:00 2001 From: Nathaniel Delgado Date: Sat, 23 Mar 2024 15:26:00 -0500 Subject: [PATCH 11/25] Rewrote tests for Display, Contactors, and CANbus --- Tests/Test_BasicCAN.c | 55 ------------------- Tests/Test_Driver_CANbus.c | 42 +++++++-------- Tests/Test_Driver_Contactors.c | 37 +++++++------ Tests/Test_Driver_Display.c | 98 +++++++++++++--------------------- Tests/Test_Drivers.c | 60 --------------------- 5 files changed, 75 insertions(+), 217 deletions(-) delete mode 100644 Tests/Test_BasicCAN.c delete mode 100644 Tests/Test_Drivers.c diff --git a/Tests/Test_BasicCAN.c b/Tests/Test_BasicCAN.c deleted file mode 100644 index 81ff001bb..000000000 --- a/Tests/Test_BasicCAN.c +++ /dev/null @@ -1,55 +0,0 @@ -#include "Tasks.h" -#include "CANbus.h" -#include "CANConfig.h" - -OS_TCB Task1_TCB; -static CPU_STK Task1_Stk[DEFAULT_STACK_SIZE]; - -/* - * Run this test with MotorCAN in loopback mode! - */ - -void Task1(void *p_arg) { - CPU_Init(); - OS_CPU_SysTickInit(SystemCoreClock / (CPU_INT32U) OSCfg_TickRate_Hz); - CANbus_Init(CARCAN, carCANFilterList, sizeof carCANFilterList); - BSP_UART_Init(UART_2); - - CANDATA_t msg, out; - msg.ID = VELOCITY; - msg.idx = 0; - memset(&msg.data, 0xa5, sizeof msg.data); - - while (1) { - CANbus_Send(msg, true, CARCAN); - CANbus_Read(&out, true, CARCAN); - printf("Read stuff\n\r"); - } -} - -int main(){ - OS_ERR err; - OSInit(&err); - - TaskSwHook_Init(); - - OSTaskCreate( - (OS_TCB*)&Task1_TCB, - (CPU_CHAR*)"Task1", - (OS_TASK_PTR)Task1, - (void*)NULL, - (OS_PRIO)4, - (CPU_STK*)Task1_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 - ); - assertOSError(err); - - OSStart(&err); - assertOSError(err); -} diff --git a/Tests/Test_Driver_CANbus.c b/Tests/Test_Driver_CANbus.c index c410484d9..98e8eba7c 100644 --- a/Tests/Test_Driver_CANbus.c +++ b/Tests/Test_Driver_CANbus.c @@ -1,12 +1,17 @@ +/** + * Test for CANbus + * + * Must be run in loopback mode +*/ + #include "Tasks.h" #include "CANbus.h" #include "BSP_UART.h" #include "CANConfig.h" -static OS_TCB Task1_TCB; -static CPU_STK Task1_Stk[128]; - #define STACK_SIZE 128 +static CPU_STK Task1_Stk[128]; +static OS_TCB Task1_TCB; #define CARCAN_FILTER_SIZE (sizeof carCANFilterList / sizeof(CANId_t)) @@ -15,11 +20,6 @@ static void assert(bool); CANDATA_t dataBuf, resultBuf; uint64_t data = 0xdeadbeef12345678; -/* - * NOTE: This test must be run with car CAN in loopback mode - * TODO: automate this, either with arguments to BSP or #define - */ - void Task1(void *p_arg) { (void) p_arg; @@ -28,9 +28,10 @@ void Task1(void *p_arg) { CANbus_Init(CARCAN, carCANFilterList, NUM_CARCAN_FILTERS); - dataBuf.ID = CHARGE_ENABLE; // First, send a value that we want to be able to receive + dataBuf.ID = SLIP_SPEED; memcpy(&dataBuf.data, &data, sizeof data); + // First, send a value that we want to be able to receive assert(CANbus_Send(dataBuf, true, CARCAN) == SUCCESS); assert(CANbus_Read(&resultBuf, true, CARCAN) == SUCCESS); assert(memcmp(&dataBuf, &resultBuf, sizeof dataBuf) == 0); @@ -61,17 +62,15 @@ void Task1(void *p_arg) { assert(CANbus_Read(&resultBuf, false, CARCAN) == ERROR); // No more messages printf("Success!\r\n"); - for (;;); + while(1) {} } -int main(void){ //initialize things and spawn task - OS_ERR err; - OSInit(&err); - if(err != OS_ERR_NONE){ - printf("OS error code %d\n\r",err); - } +int main(void) { + OS_ERR err = 0; BSP_UART_Init(UART_2); + OSInit(&err); + if (err != OS_ERR_NONE) printf("OS error code %d\n\r",err); OSTaskCreate( (OS_TCB*)&Task1_TCB, @@ -88,17 +87,12 @@ int main(void){ //initialize things and spawn task (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_STK_CHK), (OS_ERR*)&err ); + if (err != OS_ERR_NONE) printf("Task1 error code %d\n\r", err); - - if (err != OS_ERR_NONE) { - printf("Task1 error code %d\n\r", err); - } OSStart(&err); - if (err != OS_ERR_NONE) { - printf("OS error code %d\n\r", err); - } - return 0; + if (err != OS_ERR_NONE) printf("OS error code %d\n\r", err); + while(1) {} } static void assert(bool cond) { diff --git a/Tests/Test_Driver_Contactors.c b/Tests/Test_Driver_Contactors.c index 521d8e27d..5c4b42d42 100644 --- a/Tests/Test_Driver_Contactors.c +++ b/Tests/Test_Driver_Contactors.c @@ -1,35 +1,40 @@ +/** + * Test for Contactors + * + * When running this test on the motor testbench, hardcode the SendTritium task + * to always send an unobtainable velocity. This ensures that no regen braking + * takes place +*/ + #include "Tasks.h" #include "Contactors.h" -static OS_TCB Task1_TCB; #define STACK_SIZE 128 static CPU_STK Task1_Stk[STACK_SIZE]; +static OS_TCB Task1_TCB; - -/* - * When running this test on the motor testbench, hardcode the SendTritium task - * to always send an unobtainable velocity. This ensures that no regen braking - * takes place - */ - -void Task1(){ - OS_ERR err; +void Task1(void) { + OS_ERR err = 0; CPU_Init(); OS_CPU_SysTickInit(SystemCoreClock / (CPU_INT32U) OSCfg_TickRate_Hz); + BSP_UART_Init(UART_2); Contactors_Init(); - for (;;) { - bool set = Contactors_Get(ARRAY_CONTACTOR); - printf("Turning contactor %s\r\n", set ? "off" : "on"); - Contactors_Set(ARRAY_CONTACTOR, !set, true); + while(1) { + bool set = Contactors_Get(ARRAY_PRECHARGE_BYPASS_CONTACTOR); + printf("Turning contactors %s\r\n", set ? "off" : "on"); + Contactors_Set(ARRAY_PRECHARGE_BYPASS_CONTACTOR, !set, true); + Contactors_Set(MOTOR_CONTROLLER_PRECHARGE_BYPASS_CONTACTOR, !set, true); + OSTimeDlyHMSM(0, 0, 5, 0, OS_OPT_TIME_HMSM_STRICT, &err); } } -int main(){ - OS_ERR err; +int main(void) { + OS_ERR err = 0; + OSInit(&err); assertOSError(err); diff --git a/Tests/Test_Driver_Display.c b/Tests/Test_Driver_Display.c index b0dd1a9de..bfefc4429 100644 --- a/Tests/Test_Driver_Display.c +++ b/Tests/Test_Driver_Display.c @@ -1,38 +1,20 @@ /** - * @file Test_DisplayDriver.c - * @author Nathaniel Delgado (nathaniel.delgado@utexas.edu) - * @brief Tests the driver code for display - * @version 0.1 - * @date 2022-10-00 - * - * @copyright Copyright (c) 2022 - * - */ + * Test for Display +*/ -// #include "common.h" -// #include "config.h" -// #include "os.h" -#include "Tasks.h" -// #include "Display.h" -// #include "bsp.h" -// #include "Contactors.h" #include "Display.h" -// Stolen from UpdateDisplay.c /** * Enum and corresponding array for easy component selection. + * + * Stolen from UpdateDisplay.c */ -typedef enum -{ +typedef enum{ // Boolean components - LEFT = 0, - HEAD, - RIGHT, - HZD, - ARRAY, + ARRAY=0, MOTOR, // Non-boolean components - VELOCITY, + VELOCITY_DISPLAY, ACCEL_METER, SOC, SUPP_BATT, @@ -44,42 +26,36 @@ typedef enum FAULT_CODE } Component_t; -static char *compStrings[15] = { - // Boolean components - "ltime", - "head", - "rtime", - "hzd", - "arr", - "mot", - // Non-boolean components - "vel", - "accel", - "soc", - "supp", - "cruiseSt", - "rbsSt", - "gear", - // Fault code components - "oserr", - "faulterr"}; +char* test_compStrings[15]= { + // Boolean components + "arr", + "mot", + // Non-boolean components + "vel", + "accel", + "soc", + "supp", + "cruiseSt", + "rbsSt", + "gear", + // Fault code components + "oserr", + "faulterr" +}; // Delay; Don't know how long -void delay(void) -{ +void delay(void) { volatile int j; - for (j = 0; j < 9999999; j++) - { + for (j = 0; j < 9999999; j++) { continue; } } -int main() -{ - DisplayError_t err; +int main(void) { + DisplayError_t err = 0; err = Display_Init(); - assertDisplayError(err); + if(err) printf("%d", err); delay(); // Display the fault page @@ -91,7 +67,7 @@ int main() .argTypes = {true}, {{.num = FAULT}}}; err = Display_Send(pgCmd); - //assertDisplayError(err); + if(err) printf("%d", err); delay(); // Display the info page @@ -103,7 +79,7 @@ int main() .argTypes = {true}, {{.num = INFO}}}; err = Display_Send(pgCmd); - //assertDisplayError(err); + if(err) printf("%d", err); delay(); // Show the array icon @@ -113,9 +89,9 @@ int main() .op = NULL, .numArgs = 2, .argTypes = {STR_ARG, INT_ARG}, - {{.str = compStrings[ARRAY]}, {.num = 1}}}; + {{.str = test_compStrings[ARRAY]}, {.num = 1}}}; err = Display_Send(toggleCmd); - //assertDisplayError(err); + if(err) printf("%d", err); delay(); // Don't show the array icon @@ -125,17 +101,15 @@ int main() .op = NULL, .numArgs = 2, .argTypes = {STR_ARG, INT_ARG}, - {{.str = compStrings[ARRAY]}, {.num = 0}}}; + {{.str = test_compStrings[ARRAY]}, {.num = 0}}}; err = Display_Send(toggleCmd); - //assertDisplayError(err); + if(err) printf("%d", err); delay(); // Test the fault screen error_code_t faultCode = 0x69; err = Display_Error(faultCode); - //assertDisplayError(err); + if(err) printf("%d", err); - while (1) - { - } + while(1) {} } \ No newline at end of file diff --git a/Tests/Test_Drivers.c b/Tests/Test_Drivers.c deleted file mode 100644 index 23334cb19..000000000 --- a/Tests/Test_Drivers.c +++ /dev/null @@ -1,60 +0,0 @@ -#include "common.h" -#include "config.h" - -#include "Pedals.h" -#include "Display.h" -#include "CANbus.h" - -int main() { - //CAN Test - printf("Testing CAN module:"); - CANbus_Init(); - uint32_t ids[10] = {0x242, 0x243, 0x244, 0x245, 0x246, 0x247, 0x24B, 0x24E, 0x580, CHARGE_ENABLE}; - uint8_t buffer[8]; - CANData_t data; - data.w = 0x87654321; - CANPayload_t payload; - payload.data = data; - payload.bytes = 4; - - for(int i=0; i Date: Sat, 23 Mar 2024 15:27:54 -0600 Subject: [PATCH 12/25] CANbus drive test fix --- Tests/Test_Driver_CANbus.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Tests/Test_Driver_CANbus.c b/Tests/Test_Driver_CANbus.c index 98e8eba7c..2424f2ead 100644 --- a/Tests/Test_Driver_CANbus.c +++ b/Tests/Test_Driver_CANbus.c @@ -28,29 +28,35 @@ void Task1(void *p_arg) { CANbus_Init(CARCAN, carCANFilterList, NUM_CARCAN_FILTERS); - dataBuf.ID = SLIP_SPEED; + dataBuf.ID = BPS_TRIP; memcpy(&dataBuf.data, &data, sizeof data); // First, send a value that we want to be able to receive assert(CANbus_Send(dataBuf, true, CARCAN) == SUCCESS); + for(int i = 0; i < 999999; i++); assert(CANbus_Read(&resultBuf, true, CARCAN) == SUCCESS); assert(memcmp(&dataBuf, &resultBuf, sizeof dataBuf) == 0); dataBuf.ID = ODOMETER_AMPHOURS; // Now, send a message that we shouldn't receive assert(CANbus_Send(dataBuf, true, CARCAN) == SUCCESS); + for(int i = 0; i < 999999; i++); assert(CANbus_Read(&resultBuf, false, CARCAN) == ERROR); // check that no can message is read // Now send a bunch of messages that should be ignored, followed by those that shouldn't for (int i=0; i<10; i++) { assert(CANbus_Send(dataBuf, true, CARCAN) == SUCCESS); + for(int i = 0; i < 999999; i++); } dataBuf.ID = BPS_TRIP; assert(CANbus_Send(dataBuf, true, CARCAN) == SUCCESS); + for(int i = 0; i < 999999; i++); dataBuf.ID = STATE_OF_CHARGE; assert(CANbus_Send(dataBuf, true, CARCAN) == SUCCESS); + for(int i = 0; i < 999999; i++); dataBuf.ID = SUPPLEMENTAL_VOLTAGE; assert(CANbus_Send(dataBuf, true, CARCAN) == SUCCESS); + for(int i = 0; i < 999999; i++); // Make sure that only three messages make it through assert(CANbus_Read(&resultBuf, true, CARCAN) == SUCCESS); @@ -65,6 +71,7 @@ void Task1(void *p_arg) { while(1) {} } +//May take 5 seconds to get a result from the test int main(void) { OS_ERR err = 0; From bdec7c8afccc5e5fb56e776ee000977f75800b7f Mon Sep 17 00:00:00 2001 From: MichaelMohn Date: Sat, 23 Mar 2024 18:36:11 -0600 Subject: [PATCH 13/25] Contactor Code (DOESNT WORK ON GOOD BOARD) --- Tests/Test_Driver_Contactors.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Tests/Test_Driver_Contactors.c b/Tests/Test_Driver_Contactors.c index 5c4b42d42..f6a03aaec 100644 --- a/Tests/Test_Driver_Contactors.c +++ b/Tests/Test_Driver_Contactors.c @@ -14,7 +14,6 @@ static CPU_STK Task1_Stk[STACK_SIZE]; static OS_TCB Task1_TCB; void Task1(void) { - OS_ERR err = 0; CPU_Init(); OS_CPU_SysTickInit(SystemCoreClock / (CPU_INT32U) OSCfg_TickRate_Hz); @@ -22,13 +21,15 @@ void Task1(void) { BSP_UART_Init(UART_2); Contactors_Init(); + printf("We did a thing\n\r"); + while(1) { bool set = Contactors_Get(ARRAY_PRECHARGE_BYPASS_CONTACTOR); printf("Turning contactors %s\r\n", set ? "off" : "on"); Contactors_Set(ARRAY_PRECHARGE_BYPASS_CONTACTOR, !set, true); Contactors_Set(MOTOR_CONTROLLER_PRECHARGE_BYPASS_CONTACTOR, !set, true); - OSTimeDlyHMSM(0, 0, 5, 0, OS_OPT_TIME_HMSM_STRICT, &err); + //for(int i = 0; i < 999999; i++); } } From b397118bdf35d5f77e2eefe8670cc509e92ba6a8 Mon Sep 17 00:00:00 2001 From: MichaelMohn Date: Sat, 30 Mar 2024 10:31:26 -0600 Subject: [PATCH 14/25] Comments added (not tested) --- Tests/Test_App_UpdateDisplay.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Tests/Test_App_UpdateDisplay.c b/Tests/Test_App_UpdateDisplay.c index 2585e1207..7589a03dc 100644 --- a/Tests/Test_App_UpdateDisplay.c +++ b/Tests/Test_App_UpdateDisplay.c @@ -57,7 +57,7 @@ void testTriStateComp(UpdateDisplayError_t(*function)(TriState_t)){ function(STATE_2); // DISP_ACTIVE & DISP_REVERSE OSTimeDlyHMSM(0, 0, 0, 200, OS_OPT_TIME_HMSM_STRICT, &e); - function(STATE_0); + function(STATE_0); // DISP_DISABLED & DISP_NEUTRAL OSTimeDlyHMSM(0, 0, 0, 200, OS_OPT_TIME_HMSM_STRICT, &e); } @@ -93,24 +93,28 @@ void Task1(void *arg) OSTimeDlyHMSM(0, 0, 7, 0, OS_OPT_TIME_HMSM_STRICT, &e); + //Cycle through all gear settings testTriStateComp(&UpdateDisplay_SetGear); + + //Cycle through various velocities UpdateDisplay_SetVelocity(12); - OSTimeDlyHMSM(0, 0, 0, 200, OS_OPT_TIME_HMSM_STRICT, &e); UpdateDisplay_SetVelocity(345); - OSTimeDlyHMSM(0, 0, 0, 200, OS_OPT_TIME_HMSM_STRICT, &e); UpdateDisplay_SetVelocity(6789); - OSTimeDlyHMSM(0, 0, 0, 200, OS_OPT_TIME_HMSM_STRICT, &e); + //Cycle through the tritium statuses testTriStateComp(&UpdateDisplay_SetCruiseState); testTriStateComp(&UpdateDisplay_SetRegenState); + + //Set Boolean statuses testBoolComp(&UpdateDisplay_SetMotor); testBoolComp(&UpdateDisplay_SetArray); - testPercentageComp(&UpdateDisplay_SetSOC); + //Various Other Tests + testPercentageComp(&UpdateDisplay_SetSOC); UpdateDisplay_SetSBPV(12); OSTimeDlyHMSM(0, 0, 0, 200, OS_OPT_TIME_HMSM_STRICT, &e); @@ -120,7 +124,6 @@ void Task1(void *arg) UpdateDisplay_SetSBPV(6789); OSTimeDlyHMSM(0, 0, 0, 200, OS_OPT_TIME_HMSM_STRICT, &e); - testPercentageComp(&UpdateDisplay_SetAccel); Display_Error((error_code_t)error); // Testing Display_Error From 4a8ebd30f36986b93b8ffcd58bf68453cd74ad61 Mon Sep 17 00:00:00 2001 From: Akshay G Date: Sat, 30 Mar 2024 12:26:10 -0500 Subject: [PATCH 15/25] untested but done? --- .vscode/c_cpp_properties.json | 1 - Embedded-Sharepoint | 2 +- Tests/Test_BSP_GPIO.c | 99 +++++++++++++++++++++-------------- 3 files changed, 61 insertions(+), 41 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 95b093be7..55b800816 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -25,7 +25,6 @@ "STM32F413_423xx", "USE_STDPERIPH_DRIVER" ], - "compilerPath": "/usr/bin/gcc", "cStandard": "c11", "intelliSenseMode": "clang-x64" } diff --git a/Embedded-Sharepoint b/Embedded-Sharepoint index 0d80b95ab..6ec59e42a 160000 --- a/Embedded-Sharepoint +++ b/Embedded-Sharepoint @@ -1 +1 @@ -Subproject commit 0d80b95ab47648b09034cc27a8b755bd89a4589b +Subproject commit 6ec59e42a397c74458a35866d27df586603eca90 diff --git a/Tests/Test_BSP_GPIO.c b/Tests/Test_BSP_GPIO.c index c013bae8c..d1367140b 100644 --- a/Tests/Test_BSP_GPIO.c +++ b/Tests/Test_BSP_GPIO.c @@ -1,44 +1,65 @@ -#include "common.h" -#include "config.h" -#include +#include "BSP_GPIO.h" int main(void) { + uint16_t input_port_a[] = {GPIO_Pin_0, + GPIO_Pin_1, + GPIO_Pin_4, + GPIO_Pin_5, + GPIO_Pin_6, + GPIO_Pin_7}; + + // input pin for port B is GPIO_Pin_4 + // output pin for port B is GPIO_Pin_5 - BSP_GPIO_Init(PORTA, 0xFFFF, 0); - BSP_GPIO_Init(PORTB, 0xFFFF, 1); - - char port; - char rw; - uint16_t data = 0; - - while (1) { - /*printf("Choose Port (A, B): "); - port = getchar(); - getchar(); - - if (port - 'A' >= NUM_PORTS) { - printf("Invalid input\n\r"); - continue; - }*/ - - printf("All pins in Port A are only read, all pins in Port B are only write\n"); - printf("Choose read (from Port A) or write (to Port B)(r/w): "); - rw = getchar(); - getchar(); - - if (rw == 'r' || rw == 'R') { - port = 'A'; - data = BSP_GPIO_Read(PORTA); - printf("Data from Port A: %d\n\r\n\r", data); - } else if (rw == 'w' || rw == 'W') { - printf("Enter the data: "); - char buffer[10] = {0}; - fgets(buffer, 10, stdin); - data = atoi(buffer); - printf("\n\r"); - BSP_GPIO_Write(PORTB, data); - } else { - printf("Invalid input\n\r"); - } + uint8_t data; + + printf("\n\n-------INIT PINS-------\n\n"); + + printf("Initializing PORT A input pins (all)\n"); + BSP_GPIO_Init(PORTA, 0x00F3, INPUT); + printf("INIT SUCCESS\n"); + + printf("Initializing PORT B input pin\n"); + BSP_GPIO_Init(PORTB, 0x0010, INPUT); + printf("INIT SUCCESS\n"); + + printf("Initializing PORT B output pin\n"); + BSP_GPIO_Init(PORTB, 0x0020, OUTPUT); + printf("INIT SUCCESS\n"); + + printf("\n\n-------INPUT PINS-------\n\n"); + for (int i = 0; i < 6; i++) { + printf("Reading port A, pin %X\n", input_port_a[i]); + data = BSP_GPIO_Read_Pin(PORTA, input_port_a[i]); + printf("Pin: %X, data read: %X\n", input_port_a[i], data); } + + printf("\nReading port B, pin %X\n", GPIO_Pin_4); + data = BSP_GPIO_Read_Pin(PORTB, GPIO_Pin_4); + printf("Pin: %X, data read: %X\n", GPIO_Pin_4, data); + + + printf("\n\n-------OUTPUT PINS-------\n\n"); + + bool write = 0; + printf("Writing port B, pin %X\n", GPIO_Pin_5); + BSP_GPIO_Write_Pin(PORTB, GPIO_Pin_5, write); + printf("Pin: %X, data write: %d\n", GPIO_Pin_5, write); + + printf("Get state port B, pin %X\n", GPIO_Pin_5); + data = BSP_GPIO_Get_State(PORTB, GPIO_Pin_5); + printf("Pin: %X, data read: %X\n", GPIO_Pin_5, data); + + printf("Type 'n' and hit enter to continue.\n"); + while (getchar() != 'n') {} + + write = 1; + printf("\nWriting port B, pin %X\n", GPIO_Pin_5); + BSP_GPIO_Write_Pin(PORTB, GPIO_Pin_5, write); + printf("Pin: %X, data write: %d\n", GPIO_Pin_5, write); + + printf("Get state port B, pin %X\n", GPIO_Pin_5); + data = BSP_GPIO_Get_State(PORTB, GPIO_Pin_5); + printf("Pin: %X, data read: %X\n", GPIO_Pin_5, data); + } \ No newline at end of file From 64e6f2f4edddf09c7d038b0c868a3abae87259e3 Mon Sep 17 00:00:00 2001 From: diyarajon Date: Sat, 30 Mar 2024 17:01:22 -0500 Subject: [PATCH 16/25] Contactor Fix perhaps??? --- Apps/Src/ReadCarCAN.c | 6 +-- Apps/Src/Tasks.c | 4 +- Drivers/Inc/Contactors.h | 8 ++-- Drivers/Src/Contactors.c | 15 ++++--- Embedded-Sharepoint | 2 +- Tests/Test_App_ReadCarCAN.c | 80 ---------------------------------- Tests/Test_BSP_GPIO copy.c | 44 +++++++++++++++++++ Tests/Test_Driver_Contactors.c | 4 +- Tests/Test_ReadCarCANrewrite.c | 25 ++++++++++- 9 files changed, 90 insertions(+), 98 deletions(-) delete mode 100644 Tests/Test_App_ReadCarCAN.c create mode 100644 Tests/Test_BSP_GPIO copy.c diff --git a/Apps/Src/ReadCarCAN.c b/Apps/Src/ReadCarCAN.c index 0965c6e5d..02150b9c7 100644 --- a/Apps/Src/ReadCarCAN.c +++ b/Apps/Src/ReadCarCAN.c @@ -401,7 +401,7 @@ static void handler_ReadCarCAN_chargeDisable(void) { updateHVArraySaturation(DISABLE_SATURATION_MSG); // Kill contactor using a direct write to avoid blocking calls when the scheduler is locked - BSP_GPIO_Write_Pin(CONTACTORS_PORT, ARRAY_PRECHARGE_BYPASS_PIN, false); + BSP_GPIO_Write_Pin(ARRAY_CONTACTOR_PORT, ARRAY_PRECHARGE_BYPASS_PIN, false); // Check that the contactor was successfully turned off bool ret = (bool)Contactors_Get(ARRAY_PRECHARGE_BYPASS_CONTACTOR); @@ -423,8 +423,8 @@ static void handler_ReadCarCAN_contactorsDisable(void) { updateHVPlusMinusSaturation(DISABLE_SATURATION_MSG); // Kill contactor using a direct write to avoid blocking calls when the scheduler is locked - BSP_GPIO_Write_Pin(CONTACTORS_PORT, ARRAY_PRECHARGE_BYPASS_PIN, false); - BSP_GPIO_Write_Pin(CONTACTORS_PORT, MOTOR_CONTROLLER_PRECHARGE_BYPASS_PIN, false); + BSP_GPIO_Write_Pin(ARRAY_CONTACTOR_PORT, ARRAY_PRECHARGE_BYPASS_PIN, false); + BSP_GPIO_Write_Pin(MCONT_CONTACTOR_PORT, MOTOR_CONTROLLER_PRECHARGE_BYPASS_PIN, false); // Fills buffers with disable messages memset(HVArrayChargeMsgBuffer, DISABLE_SATURATION_MSG, sizeof(HVArrayChargeMsgBuffer)); diff --git a/Apps/Src/Tasks.c b/Apps/Src/Tasks.c index af6382e1d..39db7971e 100644 --- a/Apps/Src/Tasks.c +++ b/Apps/Src/Tasks.c @@ -135,8 +135,8 @@ void throwTaskError(error_code_t errorCode, callback_t errorCallback, error_sche */ void EmergencyContactorOpen() { // Array motor kill - BSP_GPIO_Write_Pin(CONTACTORS_PORT, MOTOR_CONTROLLER_PRECHARGE_BYPASS_PIN, OFF); - BSP_GPIO_Write_Pin(CONTACTORS_PORT, ARRAY_PRECHARGE_BYPASS_PIN, OFF); + BSP_GPIO_Write_Pin(MCONT_CONTACTOR_PORT, MOTOR_CONTROLLER_PRECHARGE_BYPASS_PIN, OFF); + BSP_GPIO_Write_Pin(ARRAY_CONTACTOR_PORT, ARRAY_PRECHARGE_BYPASS_PIN, OFF); // Turn additional brakelight on to indicate critical error BSP_GPIO_Write_Pin(PININFO_LUT[BRAKELIGHT].port, PININFO_LUT[BRAKELIGHT].pinMask, true); diff --git a/Drivers/Inc/Contactors.h b/Drivers/Inc/Contactors.h index 77cf7ec15..4e75097bc 100644 --- a/Drivers/Inc/Contactors.h +++ b/Drivers/Inc/Contactors.h @@ -17,9 +17,11 @@ #include "stm32f4xx_gpio.h" -#define CONTACTORS_PORT PORTC -#define ARRAY_PRECHARGE_BYPASS_PIN GPIO_Pin_10 -#define MOTOR_CONTROLLER_PRECHARGE_BYPASS_PIN GPIO_Pin_12 +#define ARRAY_CONTACTOR_PORT PORTC +#define MCONT_CONTACTOR_PORT PORTD + +#define ARRAY_PRECHARGE_BYPASS_PIN GPIO_Pin_11 +#define MOTOR_CONTROLLER_PRECHARGE_BYPASS_PIN GPIO_Pin_2 #define FOREACH_contactor(contactor) \ contactor(ARRAY_PRECHARGE_BYPASS_CONTACTOR), \ diff --git a/Drivers/Src/Contactors.c b/Drivers/Src/Contactors.c index 66ec45e0f..76744a43e 100644 --- a/Drivers/Src/Contactors.c +++ b/Drivers/Src/Contactors.c @@ -22,10 +22,10 @@ static OS_MUTEX contactorsMutex; static void setContactor(contactor_t contactor, bool state) { switch (contactor) { case ARRAY_PRECHARGE_BYPASS_CONTACTOR : - BSP_GPIO_Write_Pin(CONTACTORS_PORT, ARRAY_PRECHARGE_BYPASS_PIN, state); + BSP_GPIO_Write_Pin(ARRAY_CONTACTOR_PORT, ARRAY_PRECHARGE_BYPASS_PIN, state); break; case MOTOR_CONTROLLER_PRECHARGE_BYPASS_CONTACTOR : - BSP_GPIO_Write_Pin(CONTACTORS_PORT, MOTOR_CONTROLLER_PRECHARGE_BYPASS_PIN, state); + BSP_GPIO_Write_Pin(MCONT_CONTACTOR_PORT, MOTOR_CONTROLLER_PRECHARGE_BYPASS_PIN, state); break; default: break; @@ -38,8 +38,11 @@ static void setContactor(contactor_t contactor, bool state) { * @return None */ void Contactors_Init() { - BSP_GPIO_Init(CONTACTORS_PORT, - (ARRAY_PRECHARGE_BYPASS_PIN) | + BSP_GPIO_Init(ARRAY_CONTACTOR_PORT, + (ARRAY_PRECHARGE_BYPASS_PIN), + 1); + + BSP_GPIO_Init(MCONT_CONTACTOR_PORT, (MOTOR_CONTROLLER_PRECHARGE_BYPASS_PIN), 1); @@ -66,10 +69,10 @@ bool Contactors_Get(contactor_t contactor) { switch (contactor) { case ARRAY_PRECHARGE_BYPASS_CONTACTOR : - state = BSP_GPIO_Get_State(CONTACTORS_PORT, ARRAY_PRECHARGE_BYPASS_PIN); + state = BSP_GPIO_Get_State(ARRAY_CONTACTOR_PORT, ARRAY_PRECHARGE_BYPASS_PIN); break; case MOTOR_CONTROLLER_PRECHARGE_BYPASS_CONTACTOR : - state = BSP_GPIO_Get_State(CONTACTORS_PORT, MOTOR_CONTROLLER_PRECHARGE_BYPASS_PIN); + state = BSP_GPIO_Get_State(MCONT_CONTACTOR_PORT, MOTOR_CONTROLLER_PRECHARGE_BYPASS_PIN); break; default: break; diff --git a/Embedded-Sharepoint b/Embedded-Sharepoint index 6ec59e42a..0d80b95ab 160000 --- a/Embedded-Sharepoint +++ b/Embedded-Sharepoint @@ -1 +1 @@ -Subproject commit 6ec59e42a397c74458a35866d27df586603eca90 +Subproject commit 0d80b95ab47648b09034cc27a8b755bd89a4589b diff --git a/Tests/Test_App_ReadCarCAN.c b/Tests/Test_App_ReadCarCAN.c deleted file mode 100644 index 93db729dc..000000000 --- a/Tests/Test_App_ReadCarCAN.c +++ /dev/null @@ -1,80 +0,0 @@ -#include "Tasks.h" -#include "CANbus.h" -#include "ReadCarCAN.h" -#include "Contactors.h" -#include "Display.h" -#include "UpdateDisplay.h" -#include "CANConfig.h" - -static OS_TCB Task1_TCB; -#define STACK_SIZE 128 -static CPU_STK Task1_Stk[STACK_SIZE]; - -#define CARCAN_FILTER_SIZE (sizeof carCANFilterList / sizeof(CANId_t)) - -void Task1(){ - OS_ERR err; - - CPU_Init(); - OS_CPU_SysTickInit(SystemCoreClock / (CPU_INT32U) OSCfg_TickRate_Hz); - Contactors_Init(); - Contactors_Enable(ARRAY_CONTACTOR); - Contactors_Enable(MOTOR_CONTACTOR); - Contactors_Enable(ARRAY_PRECHARGE); - CANbus_Init(CARCAN, &carCANFilterList, CARCAN_FILTER_SIZE); - Display_Init(); - UpdateDisplay_Init(); - BSP_UART_Init(UART_2); - - OSTaskCreate( - (OS_TCB*)&ReadCarCAN_TCB, - (CPU_CHAR*)"ReadCarCAN", - (OS_TASK_PTR)Task_ReadCarCAN, - (void*)NULL, - (OS_PRIO)3, - (CPU_STK*)ReadCarCAN_Stk, - (CPU_STK_SIZE)STACK_SIZE/10, - (CPU_STK_SIZE)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 - ); - assertOSError(err); - - while(1){ - printf("\nchargeEnable: %d", chargeEnable_Get()); - OSTimeDlyHMSM(0, 0, 0, 100, OS_OPT_TIME_HMSM_STRICT, &err); - assertOSError(err); - } -} - -int main(){ - OS_ERR err; - OSInit(&err); - - if(err != OS_ERR_NONE){ - printf("OS error code %d\n",err); - } - OSSemCreate(&FaultState_Sem4, "Fault State Semaphore", 0, &err); - OSTaskCreate( - (OS_TCB*)&Task1_TCB, - (CPU_CHAR*)"Task1", - (OS_TASK_PTR)Task1, - (void*)NULL, - (OS_PRIO)4, - (CPU_STK*)Task1_Stk, - (CPU_STK_SIZE)STACK_SIZE/10, - (CPU_STK_SIZE)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 - ); - assertOSError(err); - - OSStart(&err); - assertOSError(err); -} \ No newline at end of file diff --git a/Tests/Test_BSP_GPIO copy.c b/Tests/Test_BSP_GPIO copy.c new file mode 100644 index 000000000..050bb8634 --- /dev/null +++ b/Tests/Test_BSP_GPIO copy.c @@ -0,0 +1,44 @@ +#include "common.h" +#include "config.h" +#include + +int main(void) { + + BspGpioInit(kPortA, 0xFFFF, 0); + BspGpioInit(kPortB, 0xFFFF, 1); + + char port; + char rw; + uint16_t data = 0; + + while (1) { + /*printf("Choose Port (A, B): "); + port = getchar(); + getchar(); + + if (port - 'A' >= NUM_PORTS) { + printf("Invalid input\n\r"); + continue; + }*/ + + printf("All pins in Port A are only read, all pins in Port B are only write\n"); + printf("Choose read (from Port A) or write (to Port B)(r/w): "); + rw = getchar(); + getchar(); + + if (rw == 'r' || rw == 'R') { + port = 'A'; + data = BspGpioReadPin(kPortA); + printf("Data from Port A: %d\n\r\n\r", data); + } else if (rw == 'w' || rw == 'W') { + printf("Enter the data: "); + char buffer[10] = {0}; + fgets(buffer, 10, stdin); + data = atoi(buffer); + printf("\n\r"); + BspGpioWritePin(kPortB, data); + } else { + printf("Invalid input\n\r"); + } + } +} \ No newline at end of file diff --git a/Tests/Test_Driver_Contactors.c b/Tests/Test_Driver_Contactors.c index f6a03aaec..4542e4144 100644 --- a/Tests/Test_Driver_Contactors.c +++ b/Tests/Test_Driver_Contactors.c @@ -26,8 +26,8 @@ void Task1(void) { while(1) { bool set = Contactors_Get(ARRAY_PRECHARGE_BYPASS_CONTACTOR); printf("Turning contactors %s\r\n", set ? "off" : "on"); - Contactors_Set(ARRAY_PRECHARGE_BYPASS_CONTACTOR, !set, true); - Contactors_Set(MOTOR_CONTROLLER_PRECHARGE_BYPASS_CONTACTOR, !set, true); + Contactors_Set(ARRAY_PRECHARGE_BYPASS_CONTACTOR, true, true); + Contactors_Set(MOTOR_CONTROLLER_PRECHARGE_BYPASS_CONTACTOR, true, true); //for(int i = 0; i < 999999; i++); } diff --git a/Tests/Test_ReadCarCANrewrite.c b/Tests/Test_ReadCarCANrewrite.c index 8ce93c952..28f558b27 100644 --- a/Tests/Test_ReadCarCANrewrite.c +++ b/Tests/Test_ReadCarCANrewrite.c @@ -19,7 +19,6 @@ #include "Tasks.h" #include "CANbus.h" -#include "CAN_Queue.h" #include "ReadCarCAN.h" #include "Contactors.h" #include "CANConfig.h" @@ -329,6 +328,12 @@ void Task1(){ #endif OS_ERR err; #ifdef TEST_HARDWARE_HV_ARRAY_ON + /* + OFF - OFF + LV - OFF + ARR - ARR ON + MOTOR - ARR ON , MOTOR OFF + */ while(1){ CANbus_Send(HV_Array_Msg, CAN_BLOCKING, CARCAN); // HV Array messages printf("\r\nArray PBC: %d", Contactors_Get(ARRAY_PRECHARGE_BYPASS_CONTACTOR)); @@ -339,6 +344,12 @@ void Task1(){ #endif #ifdef TEST_HARDWARE_HV_PLUS_MINUS_ON + /* + OFF - OFF + LV - OFF + ARR - ARR OFF + MOTOR - ARR OFF + */ while(1){ CANbus_Send(HV_MC_Msg, CAN_BLOCKING, CARCAN); // HV Motor Controller messages printf("\r\nArray PBC: %d", Contactors_Get(ARRAY_PRECHARGE_BYPASS_CONTACTOR)); @@ -350,6 +361,12 @@ void Task1(){ #ifdef TEST_HARDWARE_HV_CONTACTORS_BOTH_ON while(1){ + /* + OFF - OFF + LV - OFF + ARR - ARR ON + MOTOR - ARR ON, MOTOR ON + */ CANbus_Send(HV_Enabled_Msg, CAN_BLOCKING, CARCAN); // HV Enable messages printf("\r\nArray PBC: %d", Contactors_Get(ARRAY_PRECHARGE_BYPASS_CONTACTOR)); printf("\r\nMC PBC: %d", Contactors_Get(MOTOR_CONTROLLER_PRECHARGE_BYPASS_CONTACTOR)); @@ -359,6 +376,12 @@ void Task1(){ #endif #ifdef TEST_HARDWARE_HV_CONTACTORS_BOTH_OFF + /* + OFF - OFF + LV - OFF + ARR - ARR OFF + MOTOR - ARR OFF + */ while(1){ CANbus_Send(HV_Disable_Msg, CAN_BLOCKING, CARCAN); // Disable messages printf("\r\nArray PBC: %d", Contactors_Get(ARRAY_PRECHARGE_BYPASS_CONTACTOR)); From 3d75cecb320ba8f713375a4748f4d83b5cb013d1 Mon Sep 17 00:00:00 2001 From: Madeleine Lee Date: Sun, 31 Mar 2024 14:28:51 -0500 Subject: [PATCH 17/25] Updating SendTritium and its test file for Renode simulation so that it works. Added OSInit() so that the test runs; next step is to work through commented-out code and rename test file as Renode-only. --- Apps/Inc/SendTritium.h | 27 ++++++++++++++------------- Apps/Src/SendTritium.c | 4 ++-- Tests/Test_App_SendTritium.c | 29 +++-------------------------- 3 files changed, 19 insertions(+), 41 deletions(-) diff --git a/Apps/Inc/SendTritium.h b/Apps/Inc/SendTritium.h index 8791f3833..46c3db240 100644 --- a/Apps/Inc/SendTritium.h +++ b/Apps/Inc/SendTritium.h @@ -13,6 +13,7 @@ #include "common.h" //#define SENDTRITIUM_PRINT_MES +#define SENDTRITIUM_EXPOSE_VARS #define MOTOR_MSG_PERIOD 100 // in ms #define FSM_PERIOD 100 // in ms @@ -49,22 +50,22 @@ typedef struct TritiumState{ void (*stateDecider)(void); } TritiumState_t; -#ifdef SENDTRITIUM_EXPOSE_VARS -// Inputs -extern bool cruiseEnable; -extern bool cruiseSet; -extern bool onePedalEnable; -extern bool regenEnable; +// #ifdef SENDTRITIUM_EXPOSE_VARS +// // Inputs +// extern bool cruiseEnable; +// extern bool cruiseSet; +// extern bool onePedalEnable; +// extern bool regenEnable; -extern uint8_t brakePedalPercent; -extern uint8_t accelPedalPercent; +// extern uint8_t brakePedalPercent; +// extern uint8_t accelPedalPercent; -extern Gear_t gear; +// extern Gear_t gear; -extern TritiumState_t state; -extern float velocityObserved; -extern float cruiseVelSetpoint; -#endif +// extern TritiumState_t state; +// extern float velocityObserved; +// extern float cruiseVelSetpoint; +// #endif // Getter functions for local variables in SendTritium.c EXPOSE_GETTER(bool, cruiseEnable) diff --git a/Apps/Src/SendTritium.c b/Apps/Src/SendTritium.c index 5f299f1cd..36bb85d5d 100644 --- a/Apps/Src/SendTritium.c +++ b/Apps/Src/SendTritium.c @@ -63,7 +63,7 @@ float cruiseVelSetpoint = 0; // Current observed velocity static float velocityObserved = 0; - +#ifndef SENDTRITIUM_EXPOSE_VARS // Counter for sending setpoints to motor static uint8_t motorMsgCounter = 0; @@ -78,7 +78,7 @@ static bool onePedalPrevious = false; static bool cruiseEnableButton = false; static bool cruiseEnablePrevious = false; - +#endif // FSM static TritiumState_t prevState; // Previous state static TritiumState_t state; // Current state diff --git a/Tests/Test_App_SendTritium.c b/Tests/Test_App_SendTritium.c index ba3160a1e..54bfe66bf 100644 --- a/Tests/Test_App_SendTritium.c +++ b/Tests/Test_App_SendTritium.c @@ -1,6 +1,5 @@ #include "Minions.h" #include "Pedals.h" -#include "FaultState.h" #include "CANbus.h" #include "UpdateDisplay.h" #include "ReadCarCAN.h" @@ -126,13 +125,13 @@ void Task1(void *arg) OS_ERR err; CPU_Init(); + OS_CPU_SysTickInit(SystemCoreClock / (CPU_INT32U)OSCfg_TickRate_Hz); BSP_UART_Init(UART_2); Pedals_Init(); CANbus_Init(MOTORCAN, NULL, 0); Minions_Init(); - UpdateDisplay_Init(); - OS_CPU_SysTickInit(SystemCoreClock / (CPU_INT32U)OSCfg_TickRate_Hz); + UpdateDisplay_Init(); set_regenEnable(ON); OSTaskCreate( @@ -606,29 +605,7 @@ int main() { OS_ERR err; OSInit(&err); - OSSemCreate( // create fault sem4 - &FaultState_Sem4, - "Fault State Semaphore", - 0, - &err); - assertOSError(err); - - OSTaskCreate( // create fault task - (OS_TCB *)&FaultState_TCB, - (CPU_CHAR *)"Fault State", - (OS_TASK_PTR)&Task_FaultState, - (void *)NULL, - (OS_PRIO)1, - (CPU_STK *)FaultState_Stk, - (CPU_STK_SIZE)128 / 10, - (CPU_STK_SIZE)128, - (OS_MSG_QTY)0, - (OS_TICK)NULL, - (void *)NULL, - (OS_OPT)(OS_OPT_TASK_STK_CLR), - (OS_ERR *)&err); - assertOSError(err); - + // create tester thread OSTaskCreate( (OS_TCB *)&Task1TCB, From 8a5155d897d3f01727bfcfaa1b33ca99fee2bf42 Mon Sep 17 00:00:00 2001 From: Madeleine Lee Date: Sun, 7 Apr 2024 18:51:44 -0500 Subject: [PATCH 18/25] Updated SendTritium & Test_App_SendTritium for a working Renode test. Removed call to put control mode on CAN when testing (based on SENDTRITIUM_EXPOSE_VARS), updated brake pedal test value to be greater than new brake pedal percent threshold, added UpdateDisplay task since the fifo was filling up. --- Apps/Src/SendTritium.c | 7 ++++++- Tests/Test_App_SendTritium.c | 40 ++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/Apps/Src/SendTritium.c b/Apps/Src/SendTritium.c index 36bb85d5d..6219a0c0a 100644 --- a/Apps/Src/SendTritium.c +++ b/Apps/Src/SendTritium.c @@ -323,6 +323,7 @@ static uint8_t map(uint8_t input, uint8_t in_min, uint8_t in_max, uint8_t out_mi * @brief Put the CONTROL_MODE message onto the CarCAN bus, detailing * the current mode of control. */ +#ifndef SENDTRITIUM_EXPOSE_VARS static void putControlModeCAN(){ CANDATA_t message; memset(&message, 0, sizeof(message)); @@ -331,6 +332,7 @@ static void putControlModeCAN(){ SendCarCAN_Put(message); } +#endif // State Handlers & Deciders @@ -682,9 +684,12 @@ void Task_SendTritium(void *p_arg){ }else{ motorMsgCounter++; } + + putControlModeCAN(); + #endif - putControlModeCAN(); + // Delay of MOTOR_MSG_PERIOD ms OSTimeDlyHMSM(0, 0, 0, MOTOR_MSG_PERIOD, OS_OPT_TIME_HMSM_STRICT, &err); diff --git a/Tests/Test_App_SendTritium.c b/Tests/Test_App_SendTritium.c index 54bfe66bf..44d95d556 100644 --- a/Tests/Test_App_SendTritium.c +++ b/Tests/Test_App_SendTritium.c @@ -10,16 +10,17 @@ static OS_TCB Task1TCB; static CPU_STK Task1Stk[DEFAULT_STACK_SIZE]; +#define BRAKE_TEST_VAL 60 void stateBuffer(){ OS_ERR err; - OSTimeDlyHMSM(0, 0, 0, 500, OS_OPT_TIME_HMSM_STRICT, &err); + OSTimeDlyHMSM(0, 0, 0, 100, OS_OPT_TIME_HMSM_STRICT, &err); // Just want enough time for SendTritium to run a cycle (but not delay) assertOSError(err); } void goToBrakeState(){ // Brake State - set_brakePedalPercent(15); + set_brakePedalPercent(BRAKE_TEST_VAL); stateBuffer(); while(get_state().name != BRAKE_STATE){} } @@ -130,9 +131,26 @@ void Task1(void *arg) Pedals_Init(); CANbus_Init(MOTORCAN, NULL, 0); Minions_Init(); + Display_Init(); UpdateDisplay_Init(); set_regenEnable(ON); + + OSTaskCreate( + (OS_TCB *)&UpdateDisplay_TCB, + (CPU_CHAR *)"UpdateDisplay_TCB", + (OS_TASK_PTR)Task_UpdateDisplay, + (void *)NULL, + (OS_PRIO)13, + (CPU_STK *)UpdateDisplay_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_ERR *)&err); + assertOSError(err); OSTaskCreate( (OS_TCB*)&SendTritium_TCB, @@ -149,7 +167,7 @@ void Task1(void *arg) (OS_OPT)(OS_OPT_TASK_STK_CLR), (OS_ERR*)&err ); - //assertOSError(err); + assertOSError(err); /** * ======= Forward Drive ========== * State Transitions: @@ -160,7 +178,7 @@ void Task1(void *arg) // Forward Drive to Brake printf("\n\rTesting: Forward Drive -> Brake\n\r"); goToForwardDrive(); - set_brakePedalPercent(15); + set_brakePedalPercent(BRAKE_TEST_VAL); stateBuffer(); while(get_state().name != BRAKE_STATE){} @@ -210,7 +228,7 @@ void Task1(void *arg) // Neutral Drive to Brake printf("\n\rTesting: Neutral Drive -> Brake\n\r"); goToNeutralDrive(); - set_brakePedalPercent(15); + set_brakePedalPercent(BRAKE_TEST_VAL); stateBuffer(); while(get_state().name != BRAKE_STATE){} @@ -244,7 +262,7 @@ void Task1(void *arg) // Reverse Drive to Brake printf("\n\rTesting: Reverse Drive -> Brake\n\r"); goToReverseDrive(); - set_brakePedalPercent(15); + set_brakePedalPercent(BRAKE_TEST_VAL); stateBuffer(); while(get_state().name != BRAKE_STATE){} @@ -276,7 +294,7 @@ void Task1(void *arg) // Record Velocity to Brake State printf("\n\rTesting: Record Velocity -> Brake\n\r"); goToRecordVelocity(); - set_brakePedalPercent(15); + set_brakePedalPercent(BRAKE_TEST_VAL); stateBuffer(); while(get_state().name != BRAKE_STATE){} @@ -329,7 +347,7 @@ void Task1(void *arg) // // Powered Cruise to Brake State // printf("\n\rTesting: Powered Cruise -> Brake\n\r"); // goToPoweredCruise(); - // set_brakePedalPercent(15); + // set_brakePedalPercent(BRAKE_TEST_VAL); // stateBuffer(); // while(get_state().name != BRAKE_STATE){} @@ -398,7 +416,7 @@ void Task1(void *arg) // // Coasting Cruise to Brake State // printf("\n\rTesting: Coasting Cruise -> Brake\n\r"); // goToCoastingCruise(); - // set_brakePedalPercent(15); + // set_brakePedalPercent(BRAKE_TEST_VAL); // stateBuffer(); // while(get_state().name != BRAKE_STATE){} @@ -467,7 +485,7 @@ void Task1(void *arg) // // Accelerate Cruise to Brake State // printf("\n\rTesting: Accelerate Cruise -> Brake\n\r"); // goToAccelerateCruise(); - // set_brakePedalPercent(15); + // set_brakePedalPercent(BRAKE_TEST_VAL); // stateBuffer(); // while(get_state().name != BRAKE_STATE){} @@ -528,7 +546,7 @@ void Task1(void *arg) // One Pedal Drive to Brake printf("\n\rTesting: One Pedal Drive -> Brake\n\r"); goToOnePedalDrive(); - set_brakePedalPercent(15); + set_brakePedalPercent(BRAKE_TEST_VAL); stateBuffer(); while(get_state().name != BRAKE_STATE){} From 0ff5c8a175ee121e29716a0d10807f36af533ee0 Mon Sep 17 00:00:00 2001 From: Madeleine Lee Date: Sun, 7 Apr 2024 19:36:46 -0500 Subject: [PATCH 19/25] Uncommented-out cruise control tests; all tests now passed. Issue may have been the FSM logic which was fixed in the gear/display issue ticket. --- Tests/Test_App_SendTritium.c | 361 +++++++++++++++++------------------ 1 file changed, 178 insertions(+), 183 deletions(-) diff --git a/Tests/Test_App_SendTritium.c b/Tests/Test_App_SendTritium.c index 44d95d556..ca5395b5d 100644 --- a/Tests/Test_App_SendTritium.c +++ b/Tests/Test_App_SendTritium.c @@ -330,12 +330,12 @@ void Task1(void *arg) while(get_state().name != FORWARD_DRIVE){} // Record Velocity to Powered Cruise - // printf("\n\rTesting: Record Velocity -> Powered Cruise\n\r"); - // goToRecordVelocity(); - // set_cruiseEnable(true); - // set_cruiseSet(false); - // stateBuffer(); - // while(get_state().name != POWERED_CRUISE){} + printf("\n\rTesting: Record Velocity -> Powered Cruise\n\r"); + goToRecordVelocity(); + set_cruiseEnable(true); + set_cruiseSet(false); + stateBuffer(); + while(get_state().name != POWERED_CRUISE){} /** * ======= Powered Cruise ========== @@ -344,66 +344,66 @@ void Task1(void *arg) */ printf("\n\r============ Testing Powered Cruise State ============\n\r"); - // // Powered Cruise to Brake State - // printf("\n\rTesting: Powered Cruise -> Brake\n\r"); - // goToPoweredCruise(); - // set_brakePedalPercent(BRAKE_TEST_VAL); - // stateBuffer(); - // while(get_state().name != BRAKE_STATE){} - - // // Powered Cruise to Neutral Drive - // printf("\n\rTesting: Powered Cruise -> Neutral Drive\n\r"); - // goToPoweredCruise(); - // set_gear(NEUTRAL_GEAR); - // stateBuffer(); - // while(get_state().name != NEUTRAL_DRIVE){} + // Powered Cruise to Brake State + printf("\n\rTesting: Powered Cruise -> Brake\n\r"); + goToPoweredCruise(); + set_brakePedalPercent(BRAKE_TEST_VAL); + stateBuffer(); + while(get_state().name != BRAKE_STATE){} + + // Powered Cruise to Neutral Drive + printf("\n\rTesting: Powered Cruise -> Neutral Drive\n\r"); + goToPoweredCruise(); + set_gear(NEUTRAL_GEAR); + stateBuffer(); + while(get_state().name != NEUTRAL_DRIVE){} + + // Powered Cruise to Reverse Drive + printf("\n\rTesting: Powered Cruise -> Reverse Drive\n\r"); + goToPoweredCruise(); + set_gear(REVERSE_GEAR); + set_velocityObserved(mpsToRpm(35)); + stateBuffer(); + set_velocityObserved(mpsToRpm(5)); + stateBuffer(); + while(get_state().name != REVERSE_DRIVE){} + + // Powered Cruise to One Pedal Drive + printf("\n\rTesting: Powered Cruise -> One Pedal Drive\n\r"); + goToPoweredCruise(); + set_onePedalEnable(true); + stateBuffer(); + while(get_state().name != ONEPEDAL){} + + // Powered Cruise to Forward Drive + printf("\n\rTesting: Powered Cruise -> Forward Drive\n\r"); + goToPoweredCruise(); + set_cruiseEnable(false); + stateBuffer(); + while(get_state().name != FORWARD_DRIVE){} - // // Powered Cruise to Reverse Drive - // printf("\n\rTesting: Powered Cruise -> Reverse Drive\n\r"); - // goToPoweredCruise(); - // set_gear(REVERSE_GEAR); - // set_velocityObserved(mpsToRpm(35)); - // stateBuffer(); - // set_velocityObserved(mpsToRpm(5)); - // stateBuffer(); - // while(get_state().name != REVERSE_DRIVE){} - - // // Powered Cruise to One Pedal Drive - // printf("\n\rTesting: Powered Cruise -> One Pedal Drive\n\r"); - // goToPoweredCruise(); - // set_onePedalEnable(true); - // stateBuffer(); - // while(get_state().name != ONEPEDAL){} - - // // Powered Cruise to Forward Drive - // printf("\n\rTesting: Powered Cruise -> Forward Drive\n\r"); - // goToPoweredCruise(); - // set_cruiseEnable(false); - // stateBuffer(); - // while(get_state().name != FORWARD_DRIVE){} - - // // Powered Cruise to Record Velocity - // printf("\n\rTesting: Powered Cruise -> Record Velocity\n\r"); - // goToPoweredCruise(); - // set_cruiseSet(true); - // stateBuffer(); - // while(get_state().name != RECORD_VELOCITY){} - - // // Powered Cruise to Accelerate Cruise - // printf("\n\rTesting: Powered Cruise -> Accelerate Cruise\n\r"); - // goToPoweredCruise(); - // set_accelPedalPercent(10); - // stateBuffer(); - // while(get_state().name != ACCELERATE_CRUISE){} - - // // Powered Cruise to Coasting Cruise - // printf("\n\rTesting: Powered Cruise -> Coasting Cruise\n\r"); - // goToPoweredCruise(); - // set_accelPedalPercent(0); - // set_velocityObserved(mpsToRpm(40)); - // set_cruiseVelSetpoint(mpsToRpm(30)); - // stateBuffer(); - // while(get_state().name != COASTING_CRUISE){} + // Powered Cruise to Record Velocity + printf("\n\rTesting: Powered Cruise -> Record Velocity\n\r"); + goToPoweredCruise(); + set_cruiseSet(true); + stateBuffer(); + while(get_state().name != RECORD_VELOCITY){} + + // Powered Cruise to Accelerate Cruise + printf("\n\rTesting: Powered Cruise -> Accelerate Cruise\n\r"); + goToPoweredCruise(); + set_accelPedalPercent(10); + stateBuffer(); + while(get_state().name != ACCELERATE_CRUISE){} + + // Powered Cruise to Coasting Cruise + printf("\n\rTesting: Powered Cruise -> Coasting Cruise\n\r"); + goToPoweredCruise(); + set_accelPedalPercent(0); + set_velocityObserved(mpsToRpm(40)); + set_cruiseVelSetpoint(mpsToRpm(30)); + stateBuffer(); + while(get_state().name != COASTING_CRUISE){} /** * ======= Coasting Cruise ========== @@ -413,67 +413,62 @@ void Task1(void *arg) */ printf("\n\r============ Testing Coasting Cruise State ============\n\r"); - // // Coasting Cruise to Brake State - // printf("\n\rTesting: Coasting Cruise -> Brake\n\r"); - // goToCoastingCruise(); - // set_brakePedalPercent(BRAKE_TEST_VAL); - // stateBuffer(); - // while(get_state().name != BRAKE_STATE){} - - // // Coasting Cruise to Neutral Drive - // printf("\n\rTesting: Coasting Cruise -> Neutral Drive\n\r"); - // goToCoastingCruise(); - // set_gear(NEUTRAL_GEAR); - // stateBuffer(); - // while(get_state().name != NEUTRAL_DRIVE){} + // Coasting Cruise to Brake State + printf("\n\rTesting: Coasting Cruise -> Brake\n\r"); + goToCoastingCruise(); + set_brakePedalPercent(BRAKE_TEST_VAL); + stateBuffer(); + while(get_state().name != BRAKE_STATE){} + + // Coasting Cruise to Neutral Drive + printf("\n\rTesting: Coasting Cruise -> Neutral Drive\n\r"); + goToCoastingCruise(); + set_gear(NEUTRAL_GEAR); + stateBuffer(); + while(get_state().name != NEUTRAL_DRIVE){} + + // Coasting Cruise to Reverse Drive + printf("\n\rTesting: Coasting Cruise -> Reverse Drive\n\r"); + goToCoastingCruise(); + set_gear(REVERSE_GEAR); + set_velocityObserved(mpsToRpm(35)); + stateBuffer(); + set_velocityObserved(mpsToRpm(5)); + stateBuffer(); + while(get_state().name != REVERSE_DRIVE){} - // // Coasting Cruise to Reverse Drive - // printf("\n\rTesting: Coasting Cruise -> Reverse Drive\n\r"); - // goToCoastingCruise(); - // set_gear(REVERSE_GEAR); - // set_velocityObserved(mpsToRpm(35)); - // stateBuffer(); - // set_velocityObserved(mpsToRpm(5)); - // stateBuffer(); - // while(get_state().name != REVERSE_DRIVE){} - - // // Coasting Cruise to One Pedal Drive - // printf("\n\rTesting: Coasting Cruise -> One Pedal Drive\n\r"); - // goToCoastingCruise(); - // set_onePedalEnable(true); - // stateBuffer(); - // while(get_state().name != ONEPEDAL){} - - // // Coasting Cruise to Forward Drive - // printf("\n\rTesting: Coasting Cruise -> Forward Drive\n\r"); - // goToCoastingCruise(); - // set_cruiseEnable(false); - // stateBuffer(); - // while(get_state().name != FORWARD_DRIVE){} - - // // Coasting Cruise to Record Velocity - // printf("\n\rTesting: Coasting Cruise -> Record Velocity\n\r"); - // goToCoastingCruise(); - // set_cruiseSet(true); - // set_velocityObserved(mpsToRpm(25.0)); - // stateBuffer(); - // while(get_state().name != RECORD_VELOCITY){} - - // // Coasting Cruise to Accelerate Cruise - // printf("\n\rTesting: Coasting Cruise -> Accelerate Cruise\n\r"); - // goToCoastingCruise(); - // set_accelPedalPercent(10); - // stateBuffer(); - // while(get_state().name != ACCELERATE_CRUISE){} - - // // Coasting Cruise to Powered Cruise - // printf("\n\rTesting: Coasting Cruise -> Powered Cruise\n\r"); - // goToCoastingCruise(); - // set_accelPedalPercent(0); - // set_velocityObserved(mpsToRpm(29)); - // set_cruiseVelSetpoint(mpsToRpm(30)); - // stateBuffer(); - // while(get_state().name != POWERED_CRUISE){} + // Coasting Cruise to One Pedal Drive + printf("\n\rTesting: Coasting Cruise -> One Pedal Drive\n\r"); + goToCoastingCruise(); + set_onePedalEnable(true); + stateBuffer(); + while(get_state().name != ONEPEDAL){} + + // Coasting Cruise to Forward Drive + printf("\n\rTesting: Coasting Cruise -> Forward Drive\n\r"); + goToCoastingCruise(); + set_cruiseEnable(false); + stateBuffer(); + while(get_state().name != FORWARD_DRIVE){} + + // Coasting Cruise to Record Velocity + printf("\n\rTesting: Coasting Cruise -> Record Velocity\n\r"); + goToCoastingCruise(); + set_cruiseSet(true); + set_velocityObserved(mpsToRpm(25.0)); + stateBuffer(); + while(get_state().name != RECORD_VELOCITY){} + + + + // Coasting Cruise to Powered Cruise + printf("\n\rTesting: Coasting Cruise -> Powered Cruise\n\r"); + goToCoastingCruise(); + set_accelPedalPercent(0); + set_velocityObserved(mpsToRpm(29)); + set_cruiseVelSetpoint(mpsToRpm(30)); + stateBuffer(); + while(get_state().name != POWERED_CRUISE){} /** * ======= Accelerate Cruise State ========== @@ -482,58 +477,58 @@ void Task1(void *arg) */ printf("\n\r============ Testing Accelerate Cruise State ============\n\r"); - // // Accelerate Cruise to Brake State - // printf("\n\rTesting: Accelerate Cruise -> Brake\n\r"); - // goToAccelerateCruise(); - // set_brakePedalPercent(BRAKE_TEST_VAL); - // stateBuffer(); - // while(get_state().name != BRAKE_STATE){} - - // // Accelerate Cruise to Neutral Drive - // printf("\n\rTesting: Accelerate Cruise -> Neutral Drive\n\r"); - // goToAccelerateCruise(); - // set_gear(NEUTRAL_GEAR); - // stateBuffer(); - // while(get_state().name != NEUTRAL_DRIVE){} + // Accelerate Cruise to Brake State + printf("\n\rTesting: Accelerate Cruise -> Brake\n\r"); + goToAccelerateCruise(); + set_brakePedalPercent(BRAKE_TEST_VAL); + stateBuffer(); + while(get_state().name != BRAKE_STATE){} + + // Accelerate Cruise to Neutral Drive + printf("\n\rTesting: Accelerate Cruise -> Neutral Drive\n\r"); + goToAccelerateCruise(); + set_gear(NEUTRAL_GEAR); + stateBuffer(); + while(get_state().name != NEUTRAL_DRIVE){} - // // Accelerate Cruise to Reverse Drive - // printf("\n\rTesting: Accelerate Cruise -> Reverse Drive\n\r"); - // goToAccelerateCruise(); - // set_gear(REVERSE_GEAR); - // set_velocityObserved(mpsToRpm(35)); - // stateBuffer(); - // set_velocityObserved(mpsToRpm(5)); - // stateBuffer(); - // while(get_state().name != REVERSE_DRIVE){} - - // // Accelerate Cruise to One Pedal Drive - // printf("\n\rTesting: Accelerate Cruise -> One Pedal Drive\n\r"); - // goToAccelerateCruise(); - // set_onePedalEnable(true); - // stateBuffer(); - // while(get_state().name != ONEPEDAL){} - - // // Accelerate Cruise to Forward Drive - // printf("\n\rTesting: Accelerate Cruise -> Forward Drive\n\r"); - // goToAccelerateCruise(); - // set_cruiseEnable(false); - // stateBuffer(); - // while(get_state().name != FORWARD_DRIVE){} - - // // Accelerate Cruise to Record Velocity - // printf("\n\rTesting: Accelerate Cruise -> Record Velocity\n\r"); - // goToAccelerateCruise(); - // set_cruiseSet(true); - // set_velocityObserved(mpsToRpm(25.0)); - // stateBuffer(); - // while(get_state().name != RECORD_VELOCITY){} - - // // Accelerate Cruise to Coasting Cruise - // printf("\n\rTesting: Accelerate Cruise -> Coasting Cruise\n\r"); - // goToAccelerateCruise(); - // set_accelPedalPercent(0); - // stateBuffer(); - // while(get_state().name != COASTING_CRUISE){} + // Accelerate Cruise to Reverse Drive + printf("\n\rTesting: Accelerate Cruise -> Reverse Drive\n\r"); + goToAccelerateCruise(); + set_gear(REVERSE_GEAR); + set_velocityObserved(mpsToRpm(35)); + stateBuffer(); + set_velocityObserved(mpsToRpm(5)); + stateBuffer(); + while(get_state().name != REVERSE_DRIVE){} + + // Accelerate Cruise to One Pedal Drive + printf("\n\rTesting: Accelerate Cruise -> One Pedal Drive\n\r"); + goToAccelerateCruise(); + set_onePedalEnable(true); + stateBuffer(); + while(get_state().name != ONEPEDAL){} + + // Accelerate Cruise to Forward Drive + printf("\n\rTesting: Accelerate Cruise -> Forward Drive\n\r"); + goToAccelerateCruise(); + set_cruiseEnable(false); + stateBuffer(); + while(get_state().name != FORWARD_DRIVE){} + + // Accelerate Cruise to Record Velocity + printf("\n\rTesting: Accelerate Cruise -> Record Velocity\n\r"); + goToAccelerateCruise(); + set_cruiseSet(true); + set_velocityObserved(mpsToRpm(25.0)); + stateBuffer(); + while(get_state().name != RECORD_VELOCITY){} + + // Accelerate Cruise to Coasting Cruise + printf("\n\rTesting: Accelerate Cruise -> Coasting Cruise\n\r"); + goToAccelerateCruise(); + set_accelPedalPercent(0); + stateBuffer(); + while(get_state().name != COASTING_CRUISE){} /** * ======= One Pedal Drive ========== @@ -568,13 +563,13 @@ void Task1(void *arg) while(get_state().name != REVERSE_DRIVE){} // One Pedal Drive to Record Velocity - // printf("\n\rTesting: One Pedal Drive -> Record Velocity\n\r"); - // goToOnePedalDrive(); - // set_cruiseSet(true); // DOES WORK BUT NEEDS TO ENFORCE 1 TRANSITION - // set_cruiseEnable(true); - // set_velocityObserved(mpsToRpm(25.0)); - // stateBuffer(); - // while(get_state().name != RECORD_VELOCITY){} + printf("\n\rTesting: One Pedal Drive -> Record Velocity\n\r"); + goToOnePedalDrive(); + set_cruiseSet(true); // DOES WORK BUT NEEDS TO ENFORCE 1 TRANSITION + set_cruiseEnable(true); + set_velocityObserved(mpsToRpm(25.0)); + stateBuffer(); + while(get_state().name != RECORD_VELOCITY){} /** * ======= Brake State ========== From 514b8235ca28031b6375a971b810d26e9c059772 Mon Sep 17 00:00:00 2001 From: Madeleine Lee Date: Sun, 7 Apr 2024 19:42:14 -0500 Subject: [PATCH 20/25] Renamed SendTritium test to indicate that it is intended for Renode since in a full hardware test, we would probably want to manipulate the inputs ourselves. We would also need to spin up other tasks if we wanted to run the motor. --- Tests/{Test_App_SendTritium.c => Test_App_SendTritium_Renode.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Tests/{Test_App_SendTritium.c => Test_App_SendTritium_Renode.c} (100%) diff --git a/Tests/Test_App_SendTritium.c b/Tests/Test_App_SendTritium_Renode.c similarity index 100% rename from Tests/Test_App_SendTritium.c rename to Tests/Test_App_SendTritium_Renode.c From 35d38dd4120b8a44709abe68c86ad8a73c5d14d4 Mon Sep 17 00:00:00 2001 From: Madeleine Lee Date: Sat, 13 Apr 2024 15:43:06 -0500 Subject: [PATCH 21/25] Deleted outdated Faultstate test. --- Tests/Test_App_FaultState.c | 69 ------------------------------------- 1 file changed, 69 deletions(-) delete mode 100644 Tests/Test_App_FaultState.c diff --git a/Tests/Test_App_FaultState.c b/Tests/Test_App_FaultState.c deleted file mode 100644 index 42c505224..000000000 --- a/Tests/Test_App_FaultState.c +++ /dev/null @@ -1,69 +0,0 @@ -#include "common.h" -#include "config.h" -#include "os.h" -#include "Tasks.h" -#include "bsp.h" -static OS_TCB Task1TCB; -static CPU_STK Task1Stk[DEFAULT_STACK_SIZE]; - - -void Task1(void* arg){ - CPU_Init(); - OS_CPU_SysTickInit(SystemCoreClock / (CPU_INT32U) OSCfg_TickRate_Hz); - OS_ERR err; - OS_MUTEX testMut; - OS_TICK tick = (OS_TICK)0; - CPU_TS ts; - OSMutexPend(&testMut,tick, OS_OPT_POST_NONE, &ts,&err); - assertOSError(err); - -}; - -int main(){ - OS_ERR err; - OSInit(&err); - OSSemCreate( //create fault sem4 - &FaultState_Sem4, - "Fault State Semaphore", - 0, - &err - ); - assertOSError(err); - - OSTaskCreate( //create fault task - (OS_TCB*)&FaultState_TCB, - (CPU_CHAR*)"Fault State", - (OS_TASK_PTR)&Task_FaultState, - (void*)NULL, - (OS_PRIO)1, - (CPU_STK*)FaultState_Stk, - (CPU_STK_SIZE)128/10, - (CPU_STK_SIZE)128, - (OS_MSG_QTY)0, - (OS_TICK)NULL, - (void*)NULL, - (OS_OPT)(OS_OPT_TASK_STK_CLR), - (OS_ERR*)&err - ); - assertOSError(err); - - //create tester thread - OSTaskCreate( - (OS_TCB*)&Task1TCB, - (CPU_CHAR*)"Task 1", - (OS_TASK_PTR)Task1, - (void*)NULL, - (OS_PRIO)13, - (CPU_STK*)Task1Stk, - (CPU_STK_SIZE)128/10, - (CPU_STK_SIZE)128, - (OS_MSG_QTY)0, - (OS_TICK)NULL, - (void*)NULL, - (OS_OPT)(OS_OPT_TASK_STK_CLR), - (OS_ERR*)&err - ); - assertOSError(err); - - OSStart(&err); -} \ No newline at end of file From 2b659a6544b072638a1380bc17d5dd1c1003f859 Mon Sep 17 00:00:00 2001 From: Madeleine Lee Date: Sat, 13 Apr 2024 15:43:41 -0500 Subject: [PATCH 22/25] Updated assertOSError calls to no longer inclue OS_ERR_LOC parameter. --- Tests/Test_ReadTritium.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Test_ReadTritium.c b/Tests/Test_ReadTritium.c index 078bf92e5..56c97fc6c 100644 --- a/Tests/Test_ReadTritium.c +++ b/Tests/Test_ReadTritium.c @@ -33,7 +33,7 @@ void Task1(void *p_arg) { (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_STK_CHK), (OS_ERR*)&err ); - assertOSError(OS_MAIN_LOC, err); + assertOSError(err); CANDATA_t msg; msg.ID = VELOCITY; @@ -74,8 +74,8 @@ int main(){ (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_STK_CHK), (OS_ERR*)&err ); - assertOSError(OS_MAIN_LOC, err); + assertOSError(err); OSStart(&err); - assertOSError(OS_MAIN_LOC, err); + assertOSError(err); } From b0c46228565b1e4bf20148433e52729a394c9ed4 Mon Sep 17 00:00:00 2001 From: Madeleine Lee Date: Sat, 13 Apr 2024 16:13:20 -0500 Subject: [PATCH 23/25] Renamed ReadCarCan test to match naming scheme. --- Tests/{Test_ReadCarCANrewrite.c => Test_App_ReadCarCAN.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Tests/{Test_ReadCarCANrewrite.c => Test_App_ReadCarCAN.c} (100%) diff --git a/Tests/Test_ReadCarCANrewrite.c b/Tests/Test_App_ReadCarCAN.c similarity index 100% rename from Tests/Test_ReadCarCANrewrite.c rename to Tests/Test_App_ReadCarCAN.c From 2a6240e24ce56fca7d0653cdf5dbf552324938e2 Mon Sep 17 00:00:00 2001 From: Madeleine Lee Date: Sun, 14 Apr 2024 00:45:56 -0500 Subject: [PATCH 24/25] Renamed Test_ReadTritium to match the naming scheme of App_Testname. All app tests compile, but whether or not or are useful is another story. --- Tests/{Test_ReadTritium.c => Test_App_ReadTritium.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Tests/{Test_ReadTritium.c => Test_App_ReadTritium.c} (100%) diff --git a/Tests/Test_ReadTritium.c b/Tests/Test_App_ReadTritium.c similarity index 100% rename from Tests/Test_ReadTritium.c rename to Tests/Test_App_ReadTritium.c From 9b81504522957f95dc0b1c9f489401eeadc943b2 Mon Sep 17 00:00:00 2001 From: Madeleine Lee Date: Sun, 28 Apr 2024 00:58:24 -0500 Subject: [PATCH 25/25] Commented out test macro for SendTritium software test. --- Apps/Inc/SendTritium.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Apps/Inc/SendTritium.h b/Apps/Inc/SendTritium.h index 46c3db240..4de0e41a9 100644 --- a/Apps/Inc/SendTritium.h +++ b/Apps/Inc/SendTritium.h @@ -13,7 +13,7 @@ #include "common.h" //#define SENDTRITIUM_PRINT_MES -#define SENDTRITIUM_EXPOSE_VARS +//#define SENDTRITIUM_EXPOSE_VARS #define MOTOR_MSG_PERIOD 100 // in ms #define FSM_PERIOD 100 // in ms