From 2e8460cffe99f9fe880360c32f23845b2940593d Mon Sep 17 00:00:00 2001 From: Cam0Cow Date: Sat, 30 Sep 2023 14:34:20 -0500 Subject: [PATCH 01/28] Remove contactor handling and extraneous delays from main --- Apps/Src/main.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/Apps/Src/main.c b/Apps/Src/main.c index 56655828c..bd1254ce2 100644 --- a/Apps/Src/main.c +++ b/Apps/Src/main.c @@ -70,15 +70,9 @@ void Task_Init(void *p_arg){ // Start systick OS_CPU_SysTickInit(SystemCoreClock / (CPU_INT32U) OSCfg_TickRate_Hz); - - OSTimeDlyHMSM(0,0,5,0,OS_OPT_TIME_HMSM_STRICT,&err); - - assertOSError(OS_MAIN_LOC, err); // Initialize drivers Pedals_Init(); - OSTimeDlyHMSM(0,0,5,0,OS_OPT_TIME_HMSM_STRICT,&err); - OSTimeDlyHMSM(0,0,10,0,OS_OPT_TIME_HMSM_STRICT,&err); BSP_UART_Init(UART_2); CANbus_Init(CARCAN, (CANId_t*)carCANFilterList, NUM_CARCAN_FILTERS); CANbus_Init(MOTORCAN, NULL, NUM_MOTORCAN_FILTERS); @@ -198,10 +192,5 @@ void Task_Init(void *p_arg){ ); assertOSError(OS_MAIN_LOC, err); - - while(1){ - Contactors_Set(MOTOR_CONTACTOR, Minions_Read(IGN_2), true); //turn on the contactor if the ign switch lets us - assertOSError(OS_MINIONS_LOC, err); - OSTimeDlyHMSM(0, 0, 0, IGN_CONT_PERIOD, OS_OPT_TIME_HMSM_NON_STRICT, &err); - } + OSTaskDel(NULL, &err); } From b6fd25ee439da6da952d608432c11481b91ee374 Mon Sep 17 00:00:00 2001 From: Cam0Cow Date: Sat, 30 Sep 2023 14:43:43 -0500 Subject: [PATCH 02/28] Create CommandLine task in main.c --- Apps/Src/main.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/Apps/Src/main.c b/Apps/Src/main.c index bd1254ce2..880ae1749 100644 --- a/Apps/Src/main.c +++ b/Apps/Src/main.c @@ -102,6 +102,24 @@ void Task_Init(void *p_arg){ ); assertOSError(OS_MAIN_LOC, err); + // Initialize ReadTritium + OSTaskCreate( + (OS_TCB*)&ReadTritium_TCB, + (CPU_CHAR*)"ReadTritium", + (OS_TASK_PTR)Task_ReadTritium, + (void*)NULL, + (OS_PRIO)TASK_READ_TRITIUM_PRIO, + (CPU_STK*)ReadTritium_Stk, + (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, + (CPU_STK_SIZE)TASK_READ_TRITIUM_STACK_SIZE, + (OS_MSG_QTY)0, + (OS_TICK)0, + (void*)NULL, + (OS_OPT)(OS_OPT_TASK_STK_CLR), + (OS_ERR*)&err + ); + assertOSError(OS_MAIN_LOC, err); + // Initialize SendTritium OSTaskCreate( (OS_TCB*)&SendTritium_TCB, @@ -156,16 +174,16 @@ void Task_Init(void *p_arg){ ); assertOSError(OS_MAIN_LOC, err); - // Initialize ReadTritium + // Initialize SendCarCAN OSTaskCreate( - (OS_TCB*)&ReadTritium_TCB, - (CPU_CHAR*)"ReadTritium", - (OS_TASK_PTR)Task_ReadTritium, + (OS_TCB*)&SendCarCAN_TCB, + (CPU_CHAR*)"SendCarCAN", + (OS_TASK_PTR)Task_SendCarCAN, (void*)NULL, - (OS_PRIO)TASK_READ_TRITIUM_PRIO, - (CPU_STK*)ReadTritium_Stk, + (OS_PRIO)TASK_SEND_CAR_CAN_PRIO, + (CPU_STK*)SendCarCAN_Stk, (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, - (CPU_STK_SIZE)TASK_READ_TRITIUM_STACK_SIZE, + (CPU_STK_SIZE)TASK_SEND_CAR_CAN_STACK_SIZE, (OS_MSG_QTY)0, (OS_TICK)0, (void*)NULL, @@ -174,16 +192,16 @@ void Task_Init(void *p_arg){ ); assertOSError(OS_MAIN_LOC, err); - // Initialize SendCarCAN + // Initialize CommandLine OSTaskCreate( - (OS_TCB*)&SendCarCAN_TCB, - (CPU_CHAR*)"SendCarCAN", - (OS_TASK_PTR)Task_SendCarCAN, + (OS_TCB*)&CommandLine_TCB, + (CPU_CHAR*)"CommandLine", + (OS_TASK_PTR)Task_CommandLine, (void*)NULL, - (OS_PRIO)TASK_SEND_CAR_CAN_PRIO, - (CPU_STK*)SendCarCAN_Stk, + (OS_PRIO)TASK_COMMAND_LINE_PRIO, + (CPU_STK*)CommandLine_Stk, (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, - (CPU_STK_SIZE)TASK_SEND_CAR_CAN_STACK_SIZE, + (CPU_STK_SIZE)TASK_COMMAND_LINE_STACK_SIZE, (OS_MSG_QTY)0, (OS_TICK)0, (void*)NULL, From 92ac2077d5005c30b2a4d3663aec855038e0e00b Mon Sep 17 00:00:00 2001 From: ishdeshpa Date: Fri, 10 Nov 2023 03:30:50 +0000 Subject: [PATCH 03/28] changed ordering of task prios --- Apps/Inc/Tasks.h | 8 ++++---- Apps/Src/main.c | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Apps/Inc/Tasks.h b/Apps/Inc/Tasks.h index a43860440..455925b45 100644 --- a/Apps/Inc/Tasks.h +++ b/Apps/Inc/Tasks.h @@ -32,10 +32,10 @@ #define TASK_SEND_TRITIUM_PRIO 4 #define TASK_READ_CAR_CAN_PRIO 5 #define TASK_UPDATE_DISPLAY_PRIO 6 -#define TASK_SEND_CAR_CAN_PRIO 8 -#define TASK_TELEMETRY_PRIO 9 -#define TASK_DEBUG_DUMP_PRIO 10 -#define TASK_COMMAND_LINE_PRIO 11 +#define TASK_SEND_CAR_CAN_PRIO 7 +#define TASK_TELEMETRY_PRIO 8 +#define TASK_DEBUG_DUMP_PRIO 9 +#define TASK_COMMAND_LINE_PRIO 10 /** * Stack Sizes diff --git a/Apps/Src/main.c b/Apps/Src/main.c index a54202d51..7465046f6 100644 --- a/Apps/Src/main.c +++ b/Apps/Src/main.c @@ -18,8 +18,6 @@ #include "CAN_Queue.h" #include "UpdateDisplay.h" -#define IGN_CONT_PERIOD 100 - int main(void) { // Disable interrupts __disable_irq(); From e8c22a1de0477660dc2a6d9c6dca235598317da0 Mon Sep 17 00:00:00 2001 From: Cam0Cow Date: Sat, 25 Nov 2023 11:28:53 -0600 Subject: [PATCH 04/28] Actually switch to hard floats, remove duplicated flags --- Apps/Src/main.c | 30 +++++------------------------- BSP/STM32F413/Makefile | 2 +- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/Apps/Src/main.c b/Apps/Src/main.c index 351d0e0b3..7aa6bbb2a 100644 --- a/Apps/Src/main.c +++ b/Apps/Src/main.c @@ -54,8 +54,6 @@ int main(void) { assertOSError(err); while(1); - - return 0; } void Task_Init(void *p_arg){ @@ -90,7 +88,7 @@ void Task_Init(void *p_arg){ (OS_MSG_QTY)0, (OS_TICK)0, (void*)NULL, - (OS_OPT)(OS_OPT_TASK_STK_CLR), + (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), (OS_ERR*)&err ); assertOSError(err); @@ -108,7 +106,7 @@ void Task_Init(void *p_arg){ (OS_MSG_QTY)0, (OS_TICK)0, (void*)NULL, - (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP|OS_OPT_TASK_SAVE_FP), + (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), (OS_ERR*)&err ); assertOSError(err); @@ -126,7 +124,7 @@ void Task_Init(void *p_arg){ (OS_MSG_QTY)0, (OS_TICK)0, (void*)NULL, - (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP|OS_OPT_TASK_SAVE_FP), + (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), (OS_ERR*)&err ); assertOSError(err); @@ -144,7 +142,7 @@ void Task_Init(void *p_arg){ (OS_MSG_QTY)0, (OS_TICK)0, (void*)NULL, - (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP|OS_OPT_TASK_SAVE_FP), + (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), (OS_ERR*)&err ); assertOSError(err); @@ -161,25 +159,7 @@ void Task_Init(void *p_arg){ (OS_MSG_QTY)0, (OS_TICK)0, (void*)NULL, - (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP|OS_OPT_TASK_SAVE_FP), - (OS_ERR*)&err - ); - assertOSError(err); - - // Initialize CommandLine - OSTaskCreate( - (OS_TCB*)&CommandLine_TCB, - (CPU_CHAR*)"CommandLine", - (OS_TASK_PTR)Task_CommandLine, - (void*)NULL, - (OS_PRIO)TASK_COMMAND_LINE_PRIO, - (CPU_STK*)CommandLine_Stk, - (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, - (CPU_STK_SIZE)TASK_COMMAND_LINE_STACK_SIZE, - (OS_MSG_QTY)0, - (OS_TICK)0, - (void*)NULL, - (OS_OPT)(OS_OPT_TASK_STK_CLR), + (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), (OS_ERR*)&err ); assertOSError(err); diff --git a/BSP/STM32F413/Makefile b/BSP/STM32F413/Makefile index 987b35b87..d54ff4d2f 100644 --- a/BSP/STM32F413/Makefile +++ b/BSP/STM32F413/Makefile @@ -77,7 +77,7 @@ SF = st-flash CPU = -mcpu=cortex-m4 # float-abi -FLOAT-ABI = -mfloat-abi=soft +FLOAT-ABI = -mfloat-abi=hard # mcu MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI) From fa89f232efb1d20c3464872906c14f0a6d862290 Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Sat, 25 Nov 2023 14:23:56 -0600 Subject: [PATCH 05/28] disabled regen --- Apps/Src/SendTritium.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Apps/Src/SendTritium.c b/Apps/Src/SendTritium.c index 3a34e72e1..c244c2795 100644 --- a/Apps/Src/SendTritium.c +++ b/Apps/Src/SendTritium.c @@ -650,6 +650,8 @@ void Task_SendTritium(void *p_arg){ #endif state.stateDecider(); // decide what the next state is + velocitySetpoint = (velocitySetpoint>0)?MAX_VELOCITY:-MAX_VELOCITY; + // Drive #ifdef SENDTRITIUM_PRINT_MES dumpInfo(); From 8b5a3dba66612dde3298cdef622ac21d12a209f8 Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Sat, 25 Nov 2023 14:33:05 -0600 Subject: [PATCH 06/28] Squashed commit of the following: commit f72917bb95438dbe4a7c40fe6b31e47cffdf73a7 Author: Madeleine Lee Date: Fri Nov 17 15:55:26 2023 +0000 Fixed accidental deletion in docs. commit 2755a693aa4ce4e8d2e189f74227da6f986a68c2 Author: Madeleine Lee Date: Fri Nov 17 15:50:32 2023 +0000 Memset the gTxMessage.Data to zero since one-byte messages weren't clearing out old data in the rest of the bytes, updated comments in the test file. commit 5d3ddfb36be8605b5ba103f30473b5ab5bdab435 Author: Madeleine Lee Date: Fri Nov 17 14:50:01 2023 +0000 Added commas to enum to match new enum generation format. commit 347ef980fd991fc14332054d30169b0e03d6298b Author: Madeleine Lee Date: Fri Nov 17 14:27:58 2023 +0000 Updated NUM_CAN_IDS to MAX_CAN_ID in the CANId enum. commit 03f262c1f8e83056f3afbd54f4615c04a33ebf5f Merge: 362628e e6c9fb6 Author: Madeleine Lee Date: Fri Nov 17 10:31:31 2023 +0000 Merge branch 'master' into sendcarcan-telemetry-merge commit 362628e0a55301fd40873f7a0224b38fca461831 Author: Madeleine Lee Date: Fri Nov 17 10:24:37 2023 +0000 Revisions to SendCarCAN and test file to allow messages to be inspected in GDB using variables instead of prints which were overwhelming UART. commit 8bdf6bbe498cccb5ab72a0a3312e04d5a4735030 Author: Madeleine Lee Date: Mon Nov 13 23:04:14 2023 +0000 Addressing review comments: updated SendTritium macros, removed motorMsgCount queue, downsized SendCarCAN FIFO. commit 0079ce4b71d0d315383bee4364b4cff93dbf754b Author: Madeleine Lee Date: Sat Nov 11 17:57:19 2023 +0000 Test file changes for last minute panic debugging. Added an array to see what IDS are being received. commit de12ac1df64358862dc6955b917713c37ae5013f Author: Madeleine Lee Date: Sat Nov 11 17:32:41 2023 +0000 Added while loop to putIOState commit ff4bf0ac2de725652297c4238b1372e51c391809 Author: Madeleine Lee Date: Sat Nov 11 08:16:23 2023 +0000 Updates from hardware testing: added counter array to reduce frequency at which we forwared motor messages onto CarCAN, moved init functions in test file, added Renode independent watchdog fix. commit 77dbc2ab63e87b7b2011c40121fc54c6a39bd0b7 Author: Madeleine Lee Date: Sat Nov 11 03:22:40 2023 +0000 Changed PutIOState to send directly instead of putting messages in the queue to be sent by SendCarCAN later. commit ce1d74a4fd8c05719046ec05d3ff7b086e72557d Author: Madeleine Lee Date: Sat Nov 11 03:20:33 2023 +0000 Moved mutex, semaphore creation and fifo renewal to a new SendCarCAN_Init function so that other tasks can put things into the queue before SendCarCAN is ready. Additionally, created a new static task in SendCarCAN.c called PutIOState which periodically sends messages over CarCAN. commit 9043b7beab3086a8b3a7344dc27ab02ab4f24377 Author: Madeleine Lee Date: Fri Nov 10 23:57:18 2023 +0000 Deleted extra lines added when merging. commit a5e63dfaa2060d6d01fad9163c4d75cd2f60d31e Merge: d303e9b 5ae3439 Author: Madeleine Lee Date: Fri Nov 10 23:41:44 2023 +0000 Merge branch 'master' into sendcarcan-telemetry-merge commit d303e9b400cc5ce1f39233f80cfb40ba1d2068fe Author: Madeleine Lee Date: Fri Nov 10 23:07:18 2023 +0000 Test file updates from testing on hardware. commit 9c755baa4bf7f5b14c78b72c15c519589ded83d6 Author: Madeleine Lee Date: Sat Nov 4 21:08:49 2023 +0000 Added ability to print FIFO queue indexes, added ReadTritium task in SendCarCAN test, fixed CAN initialization to read CarCAN but also initialize MOTORCAN. commit 489a494b020df9d0af151e5d631ca8a13c75e62a Author: Madeleine Lee Date: Fri Oct 27 14:44:45 2023 +0000 Cleaned up and worked on test file, removed attempt to put fifo in header file and added a wrapper instead. Test compiles but hasn't been verified to work successfully yet. commit c38a3d7463449658034411a5998774e1411e853f Author: Madeleine Lee Date: Sat Oct 21 04:57:18 2023 +0000 SendCarCAN test file compiles! But at what cost... commit ad84abfbd1917085e24fb0ae67ada039f8fc305c Author: Madeleine Lee Date: Sat Oct 21 04:47:33 2023 +0000 Made aa first draft of the SendCarCAN test file and attempted to get at the SendCarCAN file by exposing it with a macro mess. controls-leader code compiles, but the test file does not compile yet. commit 3d1d906fea78c672493be72a1eccc81b8928258e Author: Madeleine Lee Date: Fri Oct 20 21:06:52 2023 +0000 Altered test macros so that we can define __TEST_SENDTRITIUM and print info while running tests on hardware or also define __TEST_SENDTRITIUM_SOFTWAREONLY to bypass hardware inputs/outputs. commit 73dddf7c6b9f5f71e875b01c0f783f4e364ea6ff Author: Madeleine Lee Date: Fri Oct 20 03:02:13 2023 +0000 Added line to put messages from the motor into the CarCAN queue to be sent. commit 90cb9c64e7d499e54d4dbc4c3e33c16a98a7bb48 Author: Madeleine Lee Date: Fri Oct 20 02:50:50 2023 +0000 Deleted most putIOStateTimer thigns, added a macro and counter in the sendCarCAN loop to send the IO message at approximately the same frequency as before (250 ms), but this time using loops, delays, and counters. It won't be as accurate, but it should still be at a relatively similar frequency. commit 5185426b40463dafb0384e46b9b3efdbe84a2531 Author: Madeleine Lee Date: Sat Oct 14 20:29:23 2023 +0000 Changed main loop to check the queue periodically instead of pending on a semaphore. The loop will check two semaphores- one to see if it's time to put an IO State message in the queue (based on if the putIOState timer has expired or not) and one to see if there's a message in the queuethat we should send. commit 2d7dbbff551466e165eac644f4f62c9e2b63174e Author: Madeleine Lee Date: Sat Oct 7 23:21:43 2023 +0000 Started a test file for SendCarCAN. commit 2f451007f3b20bfa60460d062de935d7839aac23 Merge: 6f69ba9 fd33899 Author: ishdeshpa Date: Tue Sep 26 00:09:02 2023 +0000 merged in master, now builds. test still needs to be written and bugfixes made. also ignition switch message needs to be added. commit 6f69ba9ae324bc6fd07627de7da5897f3705a2e2 Author: ishdeshpa Date: Mon Sep 25 23:50:29 2023 +0000 merge conflict resolved commit de426c5249b2142e6209d5b1e642c6f1e37d223a Author: ishdeshpa Date: Mon Jul 10 19:36:13 2023 +0000 adapted CAN_Queue into a library file and integrated with SendCarCAN commit cfd0b7c014c65c6fadae1094dff67283cc14bf52 Author: ishdeshpa Date: Sun Jul 9 22:16:56 2023 +0000 renamed telemetry to send car can commit 771a916604dde3cfb1bcc0ff681106101ccc2677 Author: Nathaniel Delgado Date: Sat Jul 8 03:13:27 2023 +0000 Merged functionality of SendCarCAN into Telemetry and removed SendCarCAN remnants --- Apps/Inc/CAN_Queue.h | 25 --- Apps/Inc/SendCarCAN.h | 21 ++ Apps/Inc/SendTritium.h | 25 ++- Apps/Inc/Tasks.h | 8 +- Apps/Inc/common.h | 4 +- Apps/Inc/fifo.h | 2 + Apps/Src/CAN_Queue.c | 69 ------ Apps/Src/DebugDump.c | 1 - Apps/Src/ReadTritium.c | 6 +- Apps/Src/SendCarCAN.c | 167 ++++++++++++-- Apps/Src/SendTritium.c | 33 ++- Apps/Src/Tasks.c | 2 - Apps/Src/Telemetry.c | 65 ------ Apps/Src/common.c | 10 +- Apps/Src/main.c | 4 +- BSP/STM32F413/Src/BSP_CAN.c | 1 + Docs/source/Apps/ExtraFiles.rst | 20 -- Drivers/Inc/CANConfig.h | 2 +- Drivers/Inc/CANbus.h | 3 +- Drivers/Inc/Contactors.h | 4 +- Drivers/Inc/Minions.h | 19 +- Drivers/Src/CANConfig.c | 7 +- Tests/Test_App_ReadCarCAN.c | 1 - Tests/Test_App_SendCarCAN.c | 370 ++++++++++++++++++++++++++------ Tests/Test_App_Telemetry.c | 95 -------- Tests/Test_Renode_CANBPSFault.c | 1 - 26 files changed, 568 insertions(+), 397 deletions(-) delete mode 100644 Apps/Inc/CAN_Queue.h create mode 100644 Apps/Inc/SendCarCAN.h delete mode 100644 Apps/Src/CAN_Queue.c delete mode 100644 Apps/Src/Telemetry.c delete mode 100644 Tests/Test_App_Telemetry.c diff --git a/Apps/Inc/CAN_Queue.h b/Apps/Inc/CAN_Queue.h deleted file mode 100644 index 5425b4a20..000000000 --- a/Apps/Inc/CAN_Queue.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * @copyright Copyright (c) 2018-2023 UT Longhorn Racing Solar - * @file CAN_Queue.h - * @brief Queue that holds all CAN messages that Task_CANBusConsumer needs to send. - * - * @defgroup CAN_Queue - * @addtogroup CAN_Queue - * @{ - */ - -#ifndef CAN_QUEUE_H -#define CAN_QUEUE_H - -#include "CANbus.h" - -void CAN_Queue_Init(void); - -ErrorStatus CAN_Queue_Post(CANDATA_t message); - -ErrorStatus CAN_Queue_Pend(CANDATA_t *message); - -#endif - - -/* @} */ diff --git a/Apps/Inc/SendCarCAN.h b/Apps/Inc/SendCarCAN.h new file mode 100644 index 000000000..61ddca481 --- /dev/null +++ b/Apps/Inc/SendCarCAN.h @@ -0,0 +1,21 @@ +#ifndef __SENDCARCAN_H +#define __SENDCARCAN_H + +#include "CANbus.h" + +/** + * @brief Initialize SendCarCAN +*/ +void SendCarCAN_Init(); + +/** + * @brief Wrapper to put new message in the CAN queue +*/ +void SendCarCAN_Put(CANDATA_t message); + +/** + * @brief return the space left in SendCarCAN_Q for debug purposes +*/ +uint8_t get_SendCarCAN_Q_Space(void); + +#endif \ No newline at end of file diff --git a/Apps/Inc/SendTritium.h b/Apps/Inc/SendTritium.h index a132d64a7..65ed7be29 100644 --- a/Apps/Inc/SendTritium.h +++ b/Apps/Inc/SendTritium.h @@ -12,7 +12,7 @@ #include "common.h" -// #define SENDTRITIUM_PRINT_MES +#define SENDTRITIUM_PRINT_MES #define MOTOR_MSG_PERIOD 100 #define FSM_PERIOD 100 @@ -20,9 +20,9 @@ #define MOTOR_MSG_COUNTER_THRESHOLD (MOTOR_MSG_PERIOD)/(FSM_PERIOD) #define FOREACH_Gear(GEAR) \ - GEAR(FORWARD_GEAR) \ - GEAR(NEUTRAL_GEAR) \ - GEAR(REVERSE_GEAR) \ + GEAR(FORWARD_GEAR), \ + GEAR(NEUTRAL_GEAR), \ + GEAR(REVERSE_GEAR), \ typedef enum GEAR_ENUM { FOREACH_Gear(GENERATE_ENUM) @@ -49,6 +49,23 @@ 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; + +extern uint8_t brakePedalPercent; +extern uint8_t accelPedalPercent; + +extern Gear_t gear; + +extern TritiumState_t state; +extern float velocityObserved; +extern float cruiseVelSetpoint; +#endif + // Getter functions for local variables in SendTritium.c EXPOSE_GETTER(bool, cruiseEnable) EXPOSE_GETTER(bool, cruiseSet) diff --git a/Apps/Inc/Tasks.h b/Apps/Inc/Tasks.h index def422c92..c0b2e036c 100644 --- a/Apps/Inc/Tasks.h +++ b/Apps/Inc/Tasks.h @@ -32,8 +32,7 @@ #define TASK_SEND_TRITIUM_PRIO 4 #define TASK_READ_CAR_CAN_PRIO 5 #define TASK_UPDATE_DISPLAY_PRIO 6 -#define TASK_SEND_CAR_CAN_PRIO 7 -#define TASK_TELEMETRY_PRIO 8 +#define TASK_SEND_CAR_CAN_PRIO 8 #define TASK_DEBUG_DUMP_PRIO 9 #define TASK_COMMAND_LINE_PRIO 10 @@ -49,7 +48,6 @@ #define TASK_UPDATE_DISPLAY_STACK_SIZE DEFAULT_STACK_SIZE #define TASK_READ_TRITIUM_STACK_SIZE DEFAULT_STACK_SIZE #define TASK_SEND_CAR_CAN_STACK_SIZE DEFAULT_STACK_SIZE -#define TASK_TELEMETRY_STACK_SIZE DEFAULT_STACK_SIZE #define TASK_DEBUG_DUMP_STACK_SIZE DEFAULT_STACK_SIZE #define TASK_COMMAND_LINE_STACK_SIZE DEFAULT_STACK_SIZE @@ -73,8 +71,6 @@ void Task_ReadTritium(void* p_arg); void Task_SendCarCAN(void* p_arg); -void Task_Telemetry(void* p_arg); - void Task_DebugDump(void *p_arg); void Task_CommandLine(void* p_arg); @@ -90,7 +86,6 @@ extern OS_TCB ReadCarCAN_TCB; extern OS_TCB UpdateDisplay_TCB; extern OS_TCB ReadTritium_TCB; extern OS_TCB SendCarCAN_TCB; -extern OS_TCB Telemetry_TCB; extern OS_TCB DebugDump_TCB; extern OS_TCB CommandLine_TCB; @@ -104,7 +99,6 @@ extern CPU_STK ReadCarCAN_Stk[TASK_READ_CAR_CAN_STACK_SIZE]; extern CPU_STK UpdateDisplay_Stk[TASK_UPDATE_DISPLAY_STACK_SIZE]; extern CPU_STK ReadTritium_Stk[TASK_READ_TRITIUM_STACK_SIZE]; extern CPU_STK SendCarCAN_Stk[TASK_SEND_CAR_CAN_STACK_SIZE]; -extern CPU_STK Telemetry_Stk[TASK_TELEMETRY_STACK_SIZE]; extern CPU_STK DebugDump_Stk[TASK_DEBUG_DUMP_STACK_SIZE]; extern CPU_STK CommandLine_Stk[TASK_COMMAND_LINE_STACK_SIZE]; diff --git a/Apps/Inc/common.h b/Apps/Inc/common.h index a8475f8c3..3c5d7722e 100644 --- a/Apps/Inc/common.h +++ b/Apps/Inc/common.h @@ -21,8 +21,8 @@ #include "config.h" /* Used for generating ENUMS */ -#define GENERATE_ENUM(ENUM) ENUM, -#define GENERATE_STRING(STRING) #STRING, +#define GENERATE_ENUM(ENUM) ENUM +#define GENERATE_STRING(STRING) #STRING /** * Used for creating getter functions (returns the value based on given inputs) diff --git a/Apps/Inc/fifo.h b/Apps/Inc/fifo.h index 2f821c91d..2431d1d0e 100644 --- a/Apps/Inc/fifo.h +++ b/Apps/Inc/fifo.h @@ -42,6 +42,8 @@ #ifndef __FIFO_H #define __FIFO_H #include +#include +#include "common.h" #endif // The type of the fifo diff --git a/Apps/Src/CAN_Queue.c b/Apps/Src/CAN_Queue.c deleted file mode 100644 index 98daa1f06..000000000 --- a/Apps/Src/CAN_Queue.c +++ /dev/null @@ -1,69 +0,0 @@ -/** - * @copyright Copyright (c) 2018-2023 UT Longhorn Racing Solar - * @file CAN_Queue.c - * @brief - * - */ - -#include "CAN_Queue.h" -#include "os.h" -#include "CANbus.h" -#include "Tasks.h" - -// fifo -#define FIFO_TYPE CANDATA_t -#define FIFO_SIZE 256 -#define FIFO_NAME CAN_fifo -#include "fifo.h" - -static CAN_fifo_t canFifo; -static OS_SEM canFifo_Sem4; -static OS_MUTEX canFifo_Mutex; - -void CAN_Queue_Init(void) { - OS_ERR err; - CPU_TS ticks; - OSMutexCreate(&canFifo_Mutex, "CAN queue mutex", &err); - assertOSError(err); - OSSemCreate(&canFifo_Sem4, - "CAN queue semaphore", - 0, - &err); - assertOSError(err); - OSMutexPend(&canFifo_Mutex, 0, OS_OPT_POST_NONE, &ticks, &err); - assertOSError(err); - CAN_fifo_renew(&canFifo); - OSMutexPost(&canFifo_Mutex, OS_OPT_POST_NONE, &err); - assertOSError(err); -} - -ErrorStatus CAN_Queue_Post(CANDATA_t message) { - OS_ERR err; - CPU_TS ticks; - OSMutexPend(&canFifo_Mutex, 0, OS_OPT_POST_NONE, &ticks, &err); - assertOSError(err); - bool success = CAN_fifo_put(&canFifo, message); - OSMutexPost(&canFifo_Mutex, OS_OPT_POST_NONE, &err); - assertOSError(err); - - if (success) { - OSSemPost(&canFifo_Sem4, OS_OPT_POST_1, &err); - assertOSError(err); - } - - return success ? SUCCESS : ERROR; -} - -ErrorStatus CAN_Queue_Pend(CANDATA_t *message) { - OS_ERR err; - CPU_TS ticks; - - OSSemPend(&canFifo_Sem4, 0, OS_OPT_PEND_BLOCKING, &ticks, &err); - assertOSError(err); - OSMutexPend(&canFifo_Mutex, 0, OS_OPT_POST_NONE, &ticks, &err); - assertOSError(err); - bool result = CAN_fifo_get(&canFifo, message); - OSMutexPost(&canFifo_Mutex, OS_OPT_POST_NONE, &err); - assertOSError(err); - return result ? SUCCESS : ERROR; -} diff --git a/Apps/Src/DebugDump.c b/Apps/Src/DebugDump.c index 672f04ffc..15cd48e98 100644 --- a/Apps/Src/DebugDump.c +++ b/Apps/Src/DebugDump.c @@ -2,7 +2,6 @@ #include "Tasks.h" #include "bsp.h" #include "CANbus.h" -#include "CAN_Queue.h" #include "Pedals.h" #include "Minions.h" #include "Contactors.h" diff --git a/Apps/Src/ReadTritium.c b/Apps/Src/ReadTritium.c index 22f1b4ef3..3b08c339b 100755 --- a/Apps/Src/ReadTritium.c +++ b/Apps/Src/ReadTritium.c @@ -6,9 +6,9 @@ */ #include "ReadTritium.h" -#include "CAN_Queue.h" #include "CANbus.h" #include "UpdateDisplay.h" +#include "SendCarCAN.h" #include "os_cfg_app.h" #include @@ -43,7 +43,7 @@ Objective 1: - if error - assertOSError - determine information important to telementry - - SendCarCAN + - Telemetry - determine information important for storage - acquire mutex on Storage Array - Store information in Storage Array (based on index) @@ -104,6 +104,8 @@ void Task_ReadTritium(void *p_arg){ } } + + SendCarCAN_Put(dataBuf); // Forward message on CarCAN for telemetry } OSTimeDlyHMSM(0, 0, 0, 10, OS_OPT_TIME_HMSM_NON_STRICT, &err); diff --git a/Apps/Src/SendCarCAN.c b/Apps/Src/SendCarCAN.c index 8079707c3..93e6a62dc 100644 --- a/Apps/Src/SendCarCAN.c +++ b/Apps/Src/SendCarCAN.c @@ -1,36 +1,163 @@ /** * @copyright Copyright (c) 2018-2023 UT Longhorn Racing Solar * @file SendCarCAN.c - * @brief Implements the SendCarCAN Task + * @brief Function implementations for the SendCarCAN application. * - * Resends the feedback from the motor controller + * This contains functions relevant to placing CAN messages in a CarCAN queue and periodically sending + * those messages in the SendCarCAN task. * */ -#include "Tasks.h" -#include "CANbus.h" -#include "CAN_Queue.h" #include "common.h" +#include "os_cfg_app.h" +#include "CANbus.h" +#include "Minions.h" +#include "Contactors.h" +#include "Pedals.h" +#include "Tasks.h" +#include "SendCarCAN.h" +#include "SendTritium.h" + +#define IO_STATE_DLY_MS 250u + +// Task_PutIOState +OS_TCB putIOState_TCB; +CPU_STK putIOState_Stk[TASK_SEND_CAR_CAN_STACK_SIZE]; + +//fifo +#define FIFO_TYPE CANDATA_t +#define FIFO_SIZE 16 +#define FIFO_NAME SendCarCAN_Q +#include "fifo.h" + +static SendCarCAN_Q_t CANFifo; + +static OS_SEM CarCAN_Sem4; +static OS_MUTEX CarCAN_Mtx; + +static void Task_PutIOState(void *p_arg); /** - * @brief Sends the feedback from the motor controller to be read by telemetry and - * sends pedal, switch, light, and contactor information to be read by telemetry - * - * @param p_arg - */ + * @brief return the space left in SendCarCAN_Q for debug purposes +*/ +uint8_t get_SendCarCAN_Q_Space(void) { + return (CANFifo.get - CANFifo.put - 1) % (sizeof CANFifo.buffer / sizeof CANFifo.buffer[0]); +} + +/** + * @brief Wrapper to put new message in the CAN queue +*/ +void SendCarCAN_Put(CANDATA_t message){ + OS_ERR err; + CPU_TS ticks; + + OSMutexPend(&CarCAN_Mtx, 0, OS_OPT_PEND_BLOCKING, &ticks, &err); + assertOSError(err); + + bool success = SendCarCAN_Q_put(&CANFifo, message); + + OSMutexPost(&CarCAN_Mtx, OS_OPT_POST_NONE, &err); + assertOSError(err); + + if(success) OSSemPost(&CarCAN_Sem4, OS_OPT_POST_1, &err); + assertOSError(err); +} + +/** + * @brief Initialize SendCarCAN +*/ +void SendCarCAN_Init(void) { + OS_ERR err; + + OSMutexCreate(&CarCAN_Mtx, "CarCAN_Mtx", &err); + assertOSError(err); + + OSSemCreate(&CarCAN_Sem4, "CarCAN_Sem4", 0, &err); + assertOSError(err); + + SendCarCAN_Q_renew(&CANFifo); +} + +/** + * @brief Grabs the latest messages from the queue and sends over CarCAN +*/ void Task_SendCarCAN(void *p_arg){ - CANDATA_t motorMsg; OS_ERR err; + CPU_TS ticks; + + CANDATA_t message; + memset(&message, 0, sizeof message); + + // PutIOState + OSTaskCreate( + (OS_TCB*)&putIOState_TCB, + (CPU_CHAR*)"PutIOState", + (OS_TASK_PTR)Task_PutIOState, + (void*)NULL, + (OS_PRIO)TASK_SEND_CAR_CAN_PRIO, // Round-robin with SendCarCAN task + (CPU_STK*)putIOState_Stk, + (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, + (CPU_STK_SIZE)TASK_SEND_CAR_CAN_STACK_SIZE, + (OS_MSG_QTY)0, + (OS_TICK)0, + (void*)NULL, + (OS_OPT)(OS_OPT_TASK_STK_CLR), + (OS_ERR*)&err + ); + assertOSError(err); + + while (1) { + + // Check if there's something to send in the queue (either IOState or Car state from sendTritium) + OSSemPend(&CarCAN_Sem4, 0, OS_OPT_PEND_BLOCKING, &ticks, &err); + assertOSError(err); + + OSMutexPend(&CarCAN_Mtx, 0, OS_OPT_PEND_BLOCKING, &ticks, &err); + assertOSError(err); + + bool res = SendCarCAN_Q_get(&CANFifo, &message); + assertOSError(err); + + OSMutexPost(&CarCAN_Mtx, OS_OPT_POST_NONE, &err); + assertOSError(err); + if(res) CANbus_Send(message, true, CARCAN); + + } +} + +static void putIOState(void){ + CANDATA_t message; + memset(&message, 0, sizeof message); + message.ID = IO_STATE; + + // Get pedal information + message.data[0] = Pedals_Read(ACCELERATOR); + message.data[1] = Pedals_Read(BRAKE); + + // Get minion information + for(pin_t pin = 0; pin < NUM_PINS; pin++){ + bool pinState = Minions_Read(pin); + message.data[2] |= pinState << pin; + } + + // Get contactor info + for(contactor_t contactor = 0; contactor < NUM_CONTACTORS; contactor++){ + bool contactorState = (Contactors_Get(contactor) == ON) ? true : false; + message.data[3] |= contactorState << contactor; + } + + CANbus_Send(message, true, CARCAN); +} + +/** + * @brief sends IO information over CarCAN every IO_STATE_DLY_MS +*/ +static void Task_PutIOState(void *p_arg) { + OS_ERR err; while (1) { - // Send motor msg - CAN_Queue_Pend(&motorMsg); - CANbus_Send(motorMsg, true, CARCAN); - - // Delay of few milliseconds (100) - OSTimeDlyHMSM(0, 0, 0, 100, OS_OPT_TIME_HMSM_STRICT, &err); - if (err != OS_ERR_NONE){ - assertOSError(err); - } + putIOState(); + OSTimeDlyHMSM(0, 0, 0, IO_STATE_DLY_MS, OS_OPT_TIME_HMSM_STRICT, &err); } + } diff --git a/Apps/Src/SendTritium.c b/Apps/Src/SendTritium.c index c244c2795..45be6adf6 100644 --- a/Apps/Src/SendTritium.c +++ b/Apps/Src/SendTritium.c @@ -8,9 +8,11 @@ * controlled mode, a one-pedal driving mode (with regenerative braking), and cruise control. * The logic is determined through a finite state machine implementation. * - * If the macro DEBUG is defined prior to including SendTritium.h, relevant - * setters will be exposed for unit testing. - * + * If the macro SENDTRITIUM_EXPOSE_VARS is defined prior to including SendTritium.h, + * relevant setters will be exposed as externs for unit testing + * and hardware inputs won't be read and motor commands won't be sent over MotorCAN. + * If the macro SENDTRITIUM_PRINT_MES is also defined prior to including SendTritium.h, + * debug info will be printed via UART. */ #include "Pedals.h" @@ -18,6 +20,7 @@ #include "Minions.h" #include "SendTritium.h" #include "ReadTritium.h" +#include "SendCarCAN.h" #include "CANbus.h" #include "UpdateDisplay.h" #include "CANConfig.h" @@ -59,9 +62,10 @@ float velocitySetpoint = 0; float cruiseVelSetpoint = 0; // Current observed velocity + +#ifndef SENDTRITIUM_EXPOSE_VARS static float velocityObserved = 0; -#ifndef SENDTRITIUM_PRINT_MES // Counter for sending setpoints to motor static uint8_t motorMsgCounter = 0; #endif @@ -317,6 +321,20 @@ 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. +*/ +static void putControlModeCAN(){ + CANDATA_t message; + memset(&message, 0, sizeof(message)); + message.ID = CONTROL_MODE; + message.data[0] = state.name; + + SendCarCAN_Put(message); +} + // State Handlers & Deciders /** @@ -632,7 +650,7 @@ void Task_SendTritium(void *p_arg){ state = FSM[NEUTRAL_DRIVE]; prevState = FSM[NEUTRAL_DRIVE]; - #ifndef SENDTRITIUM_PRINT_MES + #ifndef SENDTRITIUM_EXPOSE_VARS CANDATA_t driveCmd = { .ID=MOTOR_DRIVE, .idx=0, @@ -655,7 +673,8 @@ void Task_SendTritium(void *p_arg){ // Drive #ifdef SENDTRITIUM_PRINT_MES dumpInfo(); - #else + #endif + #ifndef SENDTRITIUM_EXPOSE_VARS if(MOTOR_MSG_COUNTER_THRESHOLD == motorMsgCounter){ memcpy(&driveCmd.data[4], ¤tSetpoint, sizeof(float)); memcpy(&driveCmd.data[0], &velocitySetpoint, sizeof(float)); @@ -666,6 +685,8 @@ void Task_SendTritium(void *p_arg){ } #endif + putControlModeCAN(); + // Delay of MOTOR_MSG_PERIOD ms OSTimeDlyHMSM(0, 0, 0, MOTOR_MSG_PERIOD, OS_OPT_TIME_HMSM_STRICT, &err); if (err != OS_ERR_NONE){ diff --git a/Apps/Src/Tasks.c b/Apps/Src/Tasks.c index 8ec996ba0..02b71c6e2 100644 --- a/Apps/Src/Tasks.c +++ b/Apps/Src/Tasks.c @@ -26,7 +26,6 @@ OS_TCB ReadCarCAN_TCB; OS_TCB UpdateDisplay_TCB; OS_TCB ReadTritium_TCB; OS_TCB SendCarCAN_TCB; -OS_TCB Telemetry_TCB; OS_TCB DebugDump_TCB; OS_TCB CommandLine_TCB; @@ -41,7 +40,6 @@ CPU_STK ReadCarCAN_Stk[TASK_READ_CAR_CAN_STACK_SIZE]; CPU_STK UpdateDisplay_Stk[TASK_UPDATE_DISPLAY_STACK_SIZE]; CPU_STK ReadTritium_Stk[TASK_READ_TRITIUM_STACK_SIZE]; CPU_STK SendCarCAN_Stk[TASK_SEND_CAR_CAN_STACK_SIZE]; -CPU_STK Telemetry_Stk[TASK_TELEMETRY_STACK_SIZE]; CPU_STK DebugDump_Stk[TASK_DEBUG_DUMP_STACK_SIZE]; CPU_STK CommandLine_Stk[TASK_COMMAND_LINE_STACK_SIZE]; diff --git a/Apps/Src/Telemetry.c b/Apps/Src/Telemetry.c deleted file mode 100644 index dba4dc738..000000000 --- a/Apps/Src/Telemetry.c +++ /dev/null @@ -1,65 +0,0 @@ -/** - * @copyright Copyright (c) 2018-2023 UT Longhorn Racing Solar - * @file Telemetry.c - * @brief Implements the SendCarCAN Task - * - * Creates a datatype to house the data to be read by telemetry - * - * Gathers the information of the pedals, lights, switches, and contactors - * to be read by telemetry - * - */ - -#include "Tasks.h" -#include "CANbus.h" -#include "CAN_Queue.h" -#include "Pedals.h" -#include "Minions.h" -#include "Contactors.h" -#include "common.h" - -// Make sure updated to the CarData_t and carMSGID are reflected in the CAN Bus IDs excel sheet - -/** - * @brief Sends pedal, switch, light, and contactor information to be read by telemetry - * - * @param p_arg - */ -void Task_Telemetry(void *p_arg){ - CANDATA_t carMsg; - carMsg.ID = CARDATA; // ID is wrong - for(int i = 4; i < 8; i++){ - carMsg.data[i] = 0; - } - OS_ERR err; - - - while (1) { - // Get pedal information - carMsg.data[0] = Pedals_Read(ACCELERATOR); - carMsg.data[1] = Pedals_Read(BRAKE); - - // Get minion information - carMsg.data[2] = 0; - for(pin_t pin = 0; pin < NUM_PINS; pin++){ - bool pinState = Minions_Read(pin); - carMsg.data[2] |= pinState << pin; - } - - // Get contactor info - carMsg.data[3] = 0; - for(contactor_t contactor = 0; contactor < NUM_CONTACTORS; contactor++){ - bool contactorState = Contactors_Get(contactor) == ON ? true : false; - carMsg.data[3] |= contactorState << contactor; - } - - // Send car msg - CANbus_Send(carMsg, true, CARCAN); - - // Delay of few milliseconds (500) - OSTimeDlyHMSM(0, 0, 0, 500, OS_OPT_TIME_HMSM_STRICT, &err); - if (err != OS_ERR_NONE){ - assertOSError(err); - } - } -} diff --git a/Apps/Src/common.c b/Apps/Src/common.c index 02a769319..0ad5e1d01 100644 --- a/Apps/Src/common.c +++ b/Apps/Src/common.c @@ -1,7 +1,7 @@ #include "common.h" void print_float(char * str, float f) { - if(str) printf(str); + if(str) printf("%s", str); int32_t n = (int32_t)f; f -= n; @@ -9,3 +9,11 @@ void print_float(char * str, float f) { int32_t d = (f<0)?-f:f; printf("%d.%02d\n\r", (int)n, (int)d); } + +void print_bin(char * str, uint32_t i){ + if(str) printf("%s", str); + + for(uint32_t mask=0x80000000L; mask > 0L; mask >>= 1){ + printf("%d\n\r",(mask & i)?1:0); + } +} \ No newline at end of file diff --git a/Apps/Src/main.c b/Apps/Src/main.c index 7aa6bbb2a..ea9a98814 100644 --- a/Apps/Src/main.c +++ b/Apps/Src/main.c @@ -15,8 +15,8 @@ #include "Display.h" #include "Minions.h" #include "Pedals.h" -#include "CAN_Queue.h" #include "UpdateDisplay.h" +#include "SendCarCAN.h" int main(void) { // Disable interrupts @@ -70,10 +70,10 @@ void Task_Init(void *p_arg){ Contactors_Init(); Display_Init(); Minions_Init(); - CAN_Queue_Init(); // Initialize applications UpdateDisplay_Init(); + SendCarCAN_Init(); // Initialize ReadTritium OSTaskCreate( diff --git a/BSP/STM32F413/Src/BSP_CAN.c b/BSP/STM32F413/Src/BSP_CAN.c index a45ef70c3..60dbbc65f 100644 --- a/BSP/STM32F413/Src/BSP_CAN.c +++ b/BSP/STM32F413/Src/BSP_CAN.c @@ -332,6 +332,7 @@ void BSP_CAN3_Init(uint16_t* idWhitelist, uint8_t idWhitelistSize) ErrorStatus BSP_CAN_Write(CAN_t bus, uint32_t id, uint8_t data[8], uint8_t length) { + memset(gTxMessage[bus].Data, 0, sizeof gTxMessage[bus].Data); gTxMessage[bus].StdId = id; gTxMessage[bus].DLC = length; for (int i = 0; i < length; i++) diff --git a/Docs/source/Apps/ExtraFiles.rst b/Docs/source/Apps/ExtraFiles.rst index b8a99f62b..77148c911 100644 --- a/Docs/source/Apps/ExtraFiles.rst +++ b/Docs/source/Apps/ExtraFiles.rst @@ -4,26 +4,6 @@ Extra Files Some files in the Apps folder don't contain any task code, but instead contain higher level interfaces, calibration data, and supporting structures. Some of these files will likely be relocated in the future. -.. _can-queue: - -========= -CAN Queue -========= - -Multiple tasks need to send messages over the car CAN bus. Sending is rather slow, so a queue is employed to absorbed the bursty nature of sending CAN messages. This way, multiple tasks can just post can messages to the queue, and another task (SendCarCAN) takes care to consume and send them to the CAN bus. - -The public interface of the file includes: - -``void CAN_Queue_Init(void)`` — Initialize the queue and its associated mutex. - -``ErrorStatus CAN_Queue_Post(CANDATA_t message)`` — Used by tasks that want to post CAN messages. The messages are held in a FIFO queue. - -``ErrorStatus CAN_Queue_Pend(CANDATA_t *message)`` — Used by SendCarCAN to consume the queue. This function blocks the caller until the queue contains at least one message, at which point it will return message and remove it from the queue. - -.. doxygengroup:: CAN_Queue - :project: doxygen - :path: "/doxygen/xml/group__CAN_Queue.xml" - ================ Pedal to Percent ================ diff --git a/Drivers/Inc/CANConfig.h b/Drivers/Inc/CANConfig.h index 3f6832132..9364a4bf3 100644 --- a/Drivers/Inc/CANConfig.h +++ b/Drivers/Inc/CANConfig.h @@ -14,7 +14,7 @@ /** * Filter Lists for CarCAN and MotorCAN */ -#define NUM_CARCAN_FILTERS 4 +#define NUM_CARCAN_FILTERS 6 #define NUM_MOTORCAN_FILTERS 0 extern CANId_t carCANFilterList[NUM_CARCAN_FILTERS]; extern CANId_t motorCANFilterList[NUM_MOTORCAN_FILTERS]; diff --git a/Drivers/Inc/CANbus.h b/Drivers/Inc/CANbus.h index 08779614d..46e8b8447 100644 --- a/Drivers/Inc/CANbus.h +++ b/Drivers/Inc/CANbus.h @@ -45,7 +45,8 @@ typedef enum { TEMPERATURE = 0x24B, ODOMETER_AMPHOURS = 0x24E, ARRAY_CONTACTOR_STATE_CHANGE = 0x24F, - CARDATA = 0x581, + CONTROL_MODE = 0x580, + IO_STATE = 0x581, MAX_CAN_ID } CANId_t; diff --git a/Drivers/Inc/Contactors.h b/Drivers/Inc/Contactors.h index d9cb83efe..77cf7ec15 100644 --- a/Drivers/Inc/Contactors.h +++ b/Drivers/Inc/Contactors.h @@ -22,8 +22,8 @@ #define MOTOR_CONTROLLER_PRECHARGE_BYPASS_PIN GPIO_Pin_12 #define FOREACH_contactor(contactor) \ - contactor(ARRAY_PRECHARGE_BYPASS_CONTACTOR) \ - contactor(MOTOR_CONTROLLER_PRECHARGE_BYPASS_CONTACTOR) \ + contactor(ARRAY_PRECHARGE_BYPASS_CONTACTOR), \ + contactor(MOTOR_CONTROLLER_PRECHARGE_BYPASS_CONTACTOR), \ typedef enum contactor_ENUM { FOREACH_contactor(GENERATE_ENUM) diff --git a/Drivers/Inc/Minions.h b/Drivers/Inc/Minions.h index 52d628f05..4ef240c22 100644 --- a/Drivers/Inc/Minions.h +++ b/Drivers/Inc/Minions.h @@ -17,16 +17,17 @@ #include #include "BSP_GPIO.h" -/* Should keep in line with the LUT in Minions.c */ +// used to index into lookup table +// if changed, PINS_LOOKARR should be changed in Minions.c #define FOREACH_PIN(PIN) \ - PIN(IGN_1) \ - PIN(IGN_2) \ - PIN(REGEN_SW) \ - PIN(FOR_SW) \ - PIN(REV_SW) \ - PIN(CRUZ_EN) \ - PIN(CRUZ_ST) \ - PIN(BRAKELIGHT) \ + PIN(IGN_1), \ + PIN(IGN_2), \ + PIN(REGEN_SW), \ + PIN(FOR_SW), \ + PIN(REV_SW), \ + PIN(CRUZ_EN), \ + PIN(CRUZ_ST), \ + PIN(BRAKELIGHT), \ typedef enum MINIONPIN_ENUM { FOREACH_PIN(GENERATE_ENUM) diff --git a/Drivers/Src/CANConfig.c b/Drivers/Src/CANConfig.c index 6afe3c07a..ce8548d1f 100644 --- a/Drivers/Src/CANConfig.c +++ b/Drivers/Src/CANConfig.c @@ -35,7 +35,12 @@ const CANLUT_T CANLUT[MAX_CAN_ID] = { [TEMPERATURE] = {NOIDX, DOUBLE}, /** TEMPERATURE **/ [ODOMETER_AMPHOURS] = {NOIDX, DOUBLE}, /** ODOMETER_AMPHOURS **/ [ARRAY_CONTACTOR_STATE_CHANGE] = {NOIDX, BYTE }, /** ARRAY_CONTACTOR_STATE_CHANGE **/ - [CARDATA] = {NOIDX, DOUBLE}, /** CARDATA **/ + [MOTOR_DRIVE] = {NOIDX, DOUBLE}, /** MOTOR_DRIVE **/ + [MOTOR_POWER] = {NOIDX, DOUBLE}, /** MOTOR_POWER **/ + [MOTOR_RESET] = {NOIDX, DOUBLE}, /** MOTOR_RESET **/ + [MOTOR_STATUS] = {NOIDX, DOUBLE}, /** MOTOR_STATUS **/ + [IO_STATE] = {NOIDX, DOUBLE}, /** IO_STATE **/ + [CONTROL_MODE] = {NOIDX, BYTE }, /** CONTROL_MODE **/ }; /** diff --git a/Tests/Test_App_ReadCarCAN.c b/Tests/Test_App_ReadCarCAN.c index d9805cdc5..93db729dc 100644 --- a/Tests/Test_App_ReadCarCAN.c +++ b/Tests/Test_App_ReadCarCAN.c @@ -1,6 +1,5 @@ #include "Tasks.h" #include "CANbus.h" -#include "CAN_Queue.h" #include "ReadCarCAN.h" #include "Contactors.h" #include "Display.h" diff --git a/Tests/Test_App_SendCarCAN.c b/Tests/Test_App_SendCarCAN.c index 78ef52c9f..406b53a63 100644 --- a/Tests/Test_App_SendCarCAN.c +++ b/Tests/Test_App_SendCarCAN.c @@ -1,89 +1,339 @@ +/** + * This test file for SendCarCAN checks if messages added to the queue are sent on CarCAN. + * It does this by starting the SendTritium, SendCarCAN, and ReadTritium tasks, + * which place messages into the SendCarCAN_Q, and then counting the CarCAN messages it receives in msgReadCount. + * It also prints the IO State and, if the SendTritium macro SENDTRITIUM_PRINT_MES is defined, the control mode + * for comparison to see if the data received on CarCAN is accurate. + * + * This test is intended to be run on hardware with CarCAN in LoopBack mode and the motor controller connected. + * The idea is to display the struct msgReadCount using a debugger view what messages we've received. + * Alternatively, you can just use it to spin up tasks and then check output using a logic analyzer. + * + * If TEST_SOFTWARE is defined prior to compilation, then a fake "motor controller" task + * will also be created to send us motor messages. + * In this case, MotorCAN should also be in LoopBack mode. +*/ + #include "Tasks.h" +#include "BSP_UART.h" #include "CANbus.h" -#include "stm32f4xx.h" -#include "CAN_Queue.h" +#include "os_cfg_app.h" +#include "SendCarCAN.h" +#include "Minions.h" +#include "CANConfig.h" +#include "SendTritium.h" +#include "Contactors.h" +#include "Pedals.h" +#include "Display.h" +#include "UpdateDisplay.h" + +#define TEST_SOFTWARE + +#define NUM_MOTOR_MSGS 15 // Messages we forward from the motor controller +#define NUM_NONMOTOR_MSGS 2 // We also send IO_STATE and CONTROL_MODE + +// indexes in msgArray for tracking info +#define IO_STATE_IDX 0 +#define CONTROL_MODE_IDX 1 + +#define MOTOR_MSG_BASE_ADDRESS 0x240 // Offset to index into msgCount array +// Test data stored for an individual message type +typedef struct { + CANDATA_t lastMsg; + uint16_t numReceived; +} msgInfo; + +// Struct containing all test file message data +typedef struct { + uint32_t lastReceiveTime_ms; + uint16_t lastMsgReceived; + msgInfo msgArray[NUM_MOTOR_MSGS + NUM_NONMOTOR_MSGS + 1]; // Message types we send plus an extra space + uint8_t SpaceLeftInQ; +} CANInfo; + static OS_TCB Task1_TCB; -static CPU_STK Task1_Stk[128]; +static CPU_STK Task1Stk[DEFAULT_STACK_SIZE]; +#ifdef TEST_SOFTWARE +static OS_TCB TaskMC_TCB; +static CPU_STK TaskMC_Stk[DEFAULT_STACK_SIZE]; +#endif +static OS_TCB TaskReadCAN_TCB; +static CPU_STK TaskReadCAN_Stk[DEFAULT_STACK_SIZE]; -#define STACK_SIZE 128 +static CANInfo msgReadCount = {0}; -void Task1(void *p_arg){ - CPU_Init(); - // OS_CPU_SysTickInit(); - OS_CPU_SysTickInit(SystemCoreClock / (CPU_INT32U) OSCfg_TickRate_Hz); +// Reads CarCAN and saves message statistics in the msgReadCount struct +void Task_ReadCAN(void *arg) +{ + OS_ERR err; + CANDATA_t dataBuf = {0}; + + + while (1) { + ErrorStatus status = CANbus_Read(&dataBuf, true, CARCAN); + + if (status == SUCCESS){ + switch(dataBuf.ID) { + case IO_STATE: { + msgReadCount.msgArray[IO_STATE_IDX].numReceived++; + msgReadCount.msgArray[IO_STATE_IDX].lastMsg = dataBuf; + break; + } + + case CONTROL_MODE: { + msgReadCount.msgArray[CONTROL_MODE_IDX].numReceived++; + memcpy((void *)&msgReadCount.msgArray[CONTROL_MODE_IDX].lastMsg, &dataBuf, sizeof dataBuf); + break; + } + + default: { + uint8_t msgIdx = dataBuf.ID - MOTOR_MSG_BASE_ADDRESS; + + if (msgIdx >= 0 && msgIdx < NUM_MOTOR_MSGS) { // Check if the message is from the motor controller + msgReadCount.msgArray[msgIdx + NUM_NONMOTOR_MSGS].numReceived++; // If so, increment based on the ID + memcpy((void *)&msgReadCount.msgArray[msgIdx + NUM_NONMOTOR_MSGS].lastMsg, &dataBuf, sizeof dataBuf); + + } else { // Place messages not otherwise accounted for into the last index of the array + msgReadCount.msgArray[NUM_MOTOR_MSGS + NUM_NONMOTOR_MSGS].numReceived++; + memcpy((void *)(&msgReadCount.msgArray[NUM_MOTOR_MSGS + NUM_NONMOTOR_MSGS].lastMsg), &dataBuf, sizeof dataBuf); + + } + + } + + } + + // Other CAN stats + msgReadCount.lastReceiveTime_ms = (OSTimeGet(&err) / OS_CFG_TICK_RATE_HZ); + msgReadCount.lastMsgReceived = dataBuf.ID; + msgReadCount.SpaceLeftInQ = get_SendCarCAN_Q_Space(); + + } else { + // CANbus read is unsuccessful + printf("\n\rCANbus_Read error of %x", status); + } + } + + +} + +#ifdef TEST_SOFTWARE +// Create a fake motor controller to send messages to the controls system via MotorCAN +void Task_MC(void *arg) { OS_ERR err; - // CPU_TS ts; - CAN_Queue_Init(); - CANbus_Init(CARCAN); + uint8_t loopCount = 0; + CANDATA_t motorMsg = { + .ID=VELOCITY, + .idx=0, + .data={0xD, 0xE, 0xA, 0xD, 0x0, 0x0, 0xE, 0xF}, // Bytes 4-5 store error flags and must be empty + }; + + while(1) { + if (++loopCount == 5) { // Only send these messages every 1000ms + loopCount = 0; + motorMsg.ID=TEMPERATURE; + CANbus_Send(motorMsg, CAN_NON_BLOCKING, MOTORCAN); + motorMsg.ID=ODOMETER_AMPHOURS; + CANbus_Send(motorMsg, CAN_NON_BLOCKING, MOTORCAN); + } + // Send these messages every 200ms + motorMsg.ID=MOTOR_STATUS; + CANbus_Send(motorMsg, CAN_NON_BLOCKING, MOTORCAN); + motorMsg.ID=MC_BUS; + CANbus_Send(motorMsg, CAN_NON_BLOCKING, MOTORCAN); + motorMsg.ID=MC_PHASE_CURRENT; + CANbus_Send(motorMsg, CAN_NON_BLOCKING, MOTORCAN); + motorMsg.ID=VOLTAGE_VEC; + CANbus_Send(motorMsg, CAN_NON_BLOCKING, MOTORCAN); + motorMsg.ID=CURRENT_VEC; + CANbus_Send(motorMsg, CAN_NON_BLOCKING, MOTORCAN); + motorMsg.ID=BACKEMF; + CANbus_Send(motorMsg, CAN_NON_BLOCKING, MOTORCAN); + OSTimeDlyHMSM(0, 0, 0, 200, OS_OPT_TIME_HMSM_STRICT, &err); + } - //spawn can send task +} +#endif + + +// Initialize other tasks and print IO state +void Task1(void *arg) +{ + OS_ERR err; + + UpdateDisplay_Init(); + + // Initialize SendCarCAN OSTaskCreate( (OS_TCB*)&SendCarCAN_TCB, - (CPU_CHAR*)"SendCarCan", + (CPU_CHAR*)"SendCarCAN", (OS_TASK_PTR)Task_SendCarCAN, (void*)NULL, - (OS_PRIO)3, + (OS_PRIO)TASK_SEND_CAR_CAN_PRIO, (CPU_STK*)SendCarCAN_Stk, - (CPU_STK_SIZE)STACK_SIZE/10, - (CPU_STK_SIZE)STACK_SIZE, + (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, + (CPU_STK_SIZE)TASK_SEND_CAR_CAN_STACK_SIZE, (OS_MSG_QTY)0, - (OS_TICK)NULL, + (OS_TICK)0, + (void*)NULL, + (OS_OPT)(OS_OPT_TASK_STK_CLR), + (OS_ERR*)&err + ); + assertOSError(err); + + // Initialize SendTritium + OSTaskCreate( + (OS_TCB*)&SendTritium_TCB, + (CPU_CHAR*)"SendTritium", + (OS_TASK_PTR)Task_SendTritium, + (void*)NULL, + (OS_PRIO)TASK_SEND_TRITIUM_PRIO, + (CPU_STK*)SendTritium_Stk, + (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, + (CPU_STK_SIZE)TASK_SEND_TRITIUM_STACK_SIZE, + (OS_MSG_QTY)0, + (OS_TICK)0, + (void*)NULL, + (OS_OPT)(OS_OPT_TASK_STK_CLR), + (OS_ERR*)&err + ); + assertOSError(err); + + // Initialize ReadTritium + OSTaskCreate( + (OS_TCB*)&ReadTritium_TCB, + (CPU_CHAR*)"ReadTritium", + (OS_TASK_PTR)Task_ReadTritium, + (void*)NULL, + (OS_PRIO)TASK_READ_TRITIUM_PRIO, + (CPU_STK*)ReadTritium_Stk, + (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, + (CPU_STK_SIZE)TASK_READ_TRITIUM_STACK_SIZE, + (OS_MSG_QTY)0, + (OS_TICK)0, + (void*)NULL, + (OS_OPT)(OS_OPT_TASK_STK_CLR), + (OS_ERR*)&err + ); + assertOSError(err); + + // Create task to read CANbus + OSTaskCreate( + (OS_TCB*)&TaskReadCAN_TCB, + (CPU_CHAR*)"Task_ReadCAN", + (OS_TASK_PTR)Task_ReadCAN, + (void*)NULL, + (OS_PRIO)13, // Lower prio than other running tasks + (CPU_STK*)TaskReadCAN_Stk, + (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, + (CPU_STK_SIZE)DEFAULT_STACK_SIZE, + (OS_MSG_QTY)0, + (OS_TICK)0, + (void*)NULL, + (OS_OPT)(OS_OPT_TASK_STK_CLR), + (OS_ERR*)&err + ); + assertOSError(err); + + // Initialize UpdateDisplay + OSTaskCreate( + (OS_TCB*)&UpdateDisplay_TCB, + (CPU_CHAR*)"UpdateDisplay", + (OS_TASK_PTR)Task_UpdateDisplay, + (void*)NULL, + (OS_PRIO)TASK_UPDATE_DISPLAY_PRIO, + (CPU_STK*)UpdateDisplay_Stk, + (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, + (CPU_STK_SIZE)TASK_UPDATE_DISPLAY_STACK_SIZE, + (OS_MSG_QTY)0, + (OS_TICK)0, + (void*)NULL, + (OS_OPT)(OS_OPT_TASK_STK_CLR), + (OS_ERR*)&err + ); + assertOSError(err); + + #ifdef TEST_SOFTWARE + // Create a task to simulate the motor controller + OSTaskCreate( + (OS_TCB*)&TaskMC_TCB, + (CPU_CHAR*)"Task_MC", + (OS_TASK_PTR)&Task_MC, + (void*)NULL, + (OS_PRIO)2, // The motor controller is "external" and shouldn't be delayed by other tasks + (CPU_STK*)TaskMC_Stk, + (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, + (CPU_STK_SIZE)DEFAULT_STACK_SIZE, + (OS_MSG_QTY)0, + (OS_TICK)0, (void*)NULL, - (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_STK_CHK), + (OS_OPT)(OS_OPT_TASK_STK_CLR), (OS_ERR*)&err ); + assertOSError(err); + #endif + + + while (1) { + // (SendTritium task will print Control Mode for us) - CANDATA_t msg; - msg.ID = MOTOR_STATUS; - msg.idx = 0; - msg.data[0] = 0x12; - msg.data[1] = 0x34; - msg.data[2] = 0x56; - msg.data[3] = 0x78; - msg.data[4] = 0x9A; - msg.data[5] = 0xBC; - msg.data[6] = 0xDE; - msg.data[7] = 0xF0; - while(1){ - (msg.ID)++; - if(msg.ID > 0x24F){ - msg.ID = MOTOR_STATUS; + // Print IO State + printf("\n\r---- IO State ----"); + printf("\n\rAccelerator: %d", Pedals_Read(ACCELERATOR)); + printf("\n\rBrake: %d", Pedals_Read(BRAKE)); + uint8_t pins = 0; + for(pin_t pin = 0; pin < NUM_PINS; pin++){ + bool pinState = Minions_Read(pin); + pins |= pinState << pin; } - CAN_Queue_Post(msg); - OSTimeDlyHMSM(0, 0, 0, 100, OS_OPT_TIME_HMSM_STRICT, &err); - } + printf("\n\rMinions: %x", pins); + uint8_t contactors = 0; + for(contactor_t contactor = 0; contactor < NUM_CONTACTORS; contactor++){ + bool contactorState = (Contactors_Get(contactor) == ON) ? true : false; + contactors |= contactorState << contactor; + } + printf("\n\rContactors: %x", contactors); + OSTimeDlyHMSM(0, 0, 0, 10 * FSM_PERIOD, OS_OPT_TIME_HMSM_STRICT, &err); + } } -int main(void){ //startup OS stuff, spawn test task - + + +int main(void) +{ OS_ERR err; OSInit(&err); - if(err != OS_ERR_NONE){ - printf("OS error code %d\n",err); - } + + OS_CPU_SysTickInit(SystemCoreClock / (CPU_INT32U)OSCfg_TickRate_Hz); + + CPU_Init(); + BSP_UART_Init(UART_2); + Pedals_Init(); + CANbus_Init(CARCAN, NULL, NUM_CARCAN_FILTERS); // CarCAN filter list is normally (CANId_t*)carCANFilterList + CANbus_Init(MOTORCAN, NULL, NUM_MOTORCAN_FILTERS); // but for testing, we'd like to receive all messages + SendCarCAN_Init(); + Minions_Init(); + Display_Init(); + 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)STACK_SIZE/10, - (CPU_STK_SIZE)STACK_SIZE, - (OS_MSG_QTY)0, + (OS_TCB *)&Task1_TCB, + (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_OPT_TASK_STK_CHK), - (OS_ERR*)&err + (void *)NULL, + (OS_OPT)(OS_OPT_TASK_STK_CLR), + (OS_ERR *)&err ); + assertOSError(err); - if (err != OS_ERR_NONE) { - printf("Task1 error code %d\n", err); - } OSStart(&err); - if (err != OS_ERR_NONE) { - printf("OS error code %d\n", err); - } - return 0; + assertOSError(err); } \ No newline at end of file diff --git a/Tests/Test_App_Telemetry.c b/Tests/Test_App_Telemetry.c deleted file mode 100644 index ee2659239..000000000 --- a/Tests/Test_App_Telemetry.c +++ /dev/null @@ -1,95 +0,0 @@ -#include "os.h" -#include "Tasks.h" -#include -#include "config.h" -#include "common.h" -#include "Pedals.h" -#include "Minions.h" -#include "Contactors.h" -#include "CANbus.h" -#include "CAN_Queue.h" - -static OS_TCB Task1TCB; -static CPU_STK Task1Stk[DEFAULT_STACK_SIZE]; - -void Task1(void *arg) -{ - CPU_Init(); - - CANbus_Init(CARCAN); - CAN_Queue_Init(); - // BSP_UART_Init(UART_2); - Pedals_Init(); - Minions_Init(); - Contactors_Init(); - - OS_CPU_SysTickInit(SystemCoreClock / (CPU_INT32U)OSCfg_TickRate_Hz); - - OS_ERR err; - - // Initialize Telemetry - OSTaskCreate( - (OS_TCB*)&Telemetry_TCB, - (CPU_CHAR*)"Telemetry", - (OS_TASK_PTR)Task_Telemetry, - (void*)NULL, - (OS_PRIO)TASK_TELEMETRY_PRIO, - (CPU_STK*)Telemetry_Stk, - (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, - (CPU_STK_SIZE)TASK_TELEMETRY_STACK_SIZE, - (OS_MSG_QTY)0, - (OS_TICK)0, - (void*)NULL, - (OS_OPT)(OS_OPT_TASK_STK_CLR), - (OS_ERR*)&err - ); - assertOSError(err); - - bool lightState = false; - State contactorState = OFF; - - CANDATA_t msg; - - while (1){ - // Switches can be modified through hardware - - // Check light - lightState = !lightState; - Minions_Write(BRAKELIGHT, lightState); - - // Check contactors (HAVE NOTHING HOOKED UP TO CONTACTORS) - contactorState = contactorState == OFF ? ON : OFF; - Contactors_Set(MOTOR_CONTROLLER_BYPASS_PRECHARGE_CONTACTOR, contactorState, true); - Contactors_Set(ARRAY_PRECHARGE_BYPASS_CONTACTOR, contactorState, true); - - CANbus_Read(&msg, CAN_BLOCKING, CARCAN); - - OSTimeDlyHMSM(0, 0, 0, 500, OS_OPT_TIME_HMSM_STRICT, &err); - // Use a logic analyzer to read the CAN line and see if the data shows up correctly - } -} - -int main() -{ - OS_ERR err; - OSInit(&err); - - // create tester thread - OSTaskCreate( - (OS_TCB *)&Task1TCB, - (CPU_CHAR *)"Task 1", - (OS_TASK_PTR)Task1, - (void *)NULL, - (OS_PRIO)5, - (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); -} \ No newline at end of file diff --git a/Tests/Test_Renode_CANBPSFault.c b/Tests/Test_Renode_CANBPSFault.c index 6597ce123..2ae360b15 100644 --- a/Tests/Test_Renode_CANBPSFault.c +++ b/Tests/Test_Renode_CANBPSFault.c @@ -8,7 +8,6 @@ #include "CANbus.h" #include "Contactors.h" #include "ReadCarCAN.h" -#include "CAN_Queue.h" #include "Minions.h" #include "BSP_UART.h" #include "Display.h" From 7b16d4d122208515943c4ecd0936362fe392553c Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Sat, 2 Dec 2023 15:45:23 -0600 Subject: [PATCH 07/28] test commit --- Apps/Inc/Tasks.h | 3 +- Apps/Src/SendCarCAN.c | 27 +++++---- Apps/Src/main.c | 131 +++++++++++++++++++++--------------------- Drivers/Src/CANbus.c | 2 - 4 files changed, 81 insertions(+), 82 deletions(-) diff --git a/Apps/Inc/Tasks.h b/Apps/Inc/Tasks.h index c0b2e036c..4b62b3c76 100644 --- a/Apps/Inc/Tasks.h +++ b/Apps/Inc/Tasks.h @@ -31,7 +31,8 @@ #define TASK_READ_TRITIUM_PRIO 3 #define TASK_SEND_TRITIUM_PRIO 4 #define TASK_READ_CAR_CAN_PRIO 5 -#define TASK_UPDATE_DISPLAY_PRIO 6 +#define TASK_PUT_IOSTATE_PRIO 6 +#define TASK_UPDATE_DISPLAY_PRIO 7 #define TASK_SEND_CAR_CAN_PRIO 8 #define TASK_DEBUG_DUMP_PRIO 9 #define TASK_COMMAND_LINE_PRIO 10 diff --git a/Apps/Src/SendCarCAN.c b/Apps/Src/SendCarCAN.c index 93e6a62dc..7eddc1193 100644 --- a/Apps/Src/SendCarCAN.c +++ b/Apps/Src/SendCarCAN.c @@ -83,7 +83,7 @@ void SendCarCAN_Init(void) { */ void Task_SendCarCAN(void *p_arg){ OS_ERR err; - CPU_TS ticks; + // CPU_TS ticks; CANDATA_t message; memset(&message, 0, sizeof message); @@ -94,7 +94,7 @@ void Task_SendCarCAN(void *p_arg){ (CPU_CHAR*)"PutIOState", (OS_TASK_PTR)Task_PutIOState, (void*)NULL, - (OS_PRIO)TASK_SEND_CAR_CAN_PRIO, // Round-robin with SendCarCAN task + (OS_PRIO)TASK_PUT_IOSTATE_PRIO, (CPU_STK*)putIOState_Stk, (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, (CPU_STK_SIZE)TASK_SEND_CAR_CAN_STACK_SIZE, @@ -109,20 +109,20 @@ void Task_SendCarCAN(void *p_arg){ while (1) { // Check if there's something to send in the queue (either IOState or Car state from sendTritium) - OSSemPend(&CarCAN_Sem4, 0, OS_OPT_PEND_BLOCKING, &ticks, &err); - assertOSError(err); + // OSSemPend(&CarCAN_Sem4, 0, OS_OPT_PEND_BLOCKING, &ticks, &err); + // assertOSError(err); - OSMutexPend(&CarCAN_Mtx, 0, OS_OPT_PEND_BLOCKING, &ticks, &err); - assertOSError(err); + // OSMutexPend(&CarCAN_Mtx, 0, OS_OPT_PEND_BLOCKING, &ticks, &err); + // assertOSError(err); - bool res = SendCarCAN_Q_get(&CANFifo, &message); - assertOSError(err); + // bool res = SendCarCAN_Q_get(&CANFifo, &message); + // assertOSError(err); - OSMutexPost(&CarCAN_Mtx, OS_OPT_POST_NONE, &err); - assertOSError(err); + // OSMutexPost(&CarCAN_Mtx, OS_OPT_POST_NONE, &err); + // assertOSError(err); - if(res) CANbus_Send(message, true, CARCAN); - + // if(res) CANbus_Send(message, true, CARCAN); + OSTimeDlyHMSM(0, 0, 0, 100, OS_OPT_NONE, &err); } } @@ -158,6 +158,5 @@ static void Task_PutIOState(void *p_arg) { while (1) { putIOState(); OSTimeDlyHMSM(0, 0, 0, IO_STATE_DLY_MS, OS_OPT_TIME_HMSM_STRICT, &err); - } - + } } diff --git a/Apps/Src/main.c b/Apps/Src/main.c index ea9a98814..5bc1cf865 100644 --- a/Apps/Src/main.c +++ b/Apps/Src/main.c @@ -65,7 +65,7 @@ void Task_Init(void *p_arg){ // Initialize drivers Pedals_Init(); BSP_UART_Init(UART_2); - CANbus_Init(CARCAN, (CANId_t*)carCANFilterList, NUM_CARCAN_FILTERS); + CANbus_Init(CARCAN, NULL, NUM_CARCAN_FILTERS); CANbus_Init(MOTORCAN, NULL, NUM_MOTORCAN_FILTERS); Contactors_Init(); Display_Init(); @@ -76,76 +76,77 @@ void Task_Init(void *p_arg){ SendCarCAN_Init(); // Initialize ReadTritium - OSTaskCreate( - (OS_TCB*)&ReadTritium_TCB, - (CPU_CHAR*)"ReadTritium", - (OS_TASK_PTR)Task_ReadTritium, - (void*)NULL, - (OS_PRIO)TASK_READ_TRITIUM_PRIO, - (CPU_STK*)ReadTritium_Stk, - (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, - (CPU_STK_SIZE)TASK_READ_TRITIUM_STACK_SIZE, - (OS_MSG_QTY)0, - (OS_TICK)0, - (void*)NULL, - (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), - (OS_ERR*)&err - ); - assertOSError(err); + // OSTaskCreate( + // (OS_TCB*)&ReadTritium_TCB, + // (CPU_CHAR*)"ReadTritium", + // (OS_TASK_PTR)Task_ReadTritium, + // (void*)NULL, + // (OS_PRIO)TASK_READ_TRITIUM_PRIO, + // (CPU_STK*)ReadTritium_Stk, + // (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, + // (CPU_STK_SIZE)TASK_READ_TRITIUM_STACK_SIZE, + // (OS_MSG_QTY)0, + // (OS_TICK)0, + // (void*)NULL, + // (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), + // (OS_ERR*)&err + // ); + // assertOSError(err); // Initialize SendTritium - OSTaskCreate( - (OS_TCB*)&SendTritium_TCB, - (CPU_CHAR*)"SendTritium", - (OS_TASK_PTR)Task_SendTritium, - (void*)NULL, - (OS_PRIO)TASK_SEND_TRITIUM_PRIO, - (CPU_STK*)SendTritium_Stk, - (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, - (CPU_STK_SIZE)TASK_SEND_TRITIUM_STACK_SIZE, - (OS_MSG_QTY)0, - (OS_TICK)0, - (void*)NULL, - (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), - (OS_ERR*)&err - ); - assertOSError(err); + // OSTaskCreate( + // (OS_TCB*)&SendTritium_TCB, + // (CPU_CHAR*)"SendTritium", + // (OS_TASK_PTR)Task_SendTritium, + // (void*)NULL, + // (OS_PRIO)TASK_SEND_TRITIUM_PRIO, + // (CPU_STK*)SendTritium_Stk, + // (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, + // (CPU_STK_SIZE)TASK_SEND_TRITIUM_STACK_SIZE, + // (OS_MSG_QTY)0, + // (OS_TICK)0, + // (void*)NULL, + // (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), + // (OS_ERR*)&err + // ); + // assertOSError(err); // Initialize ReadCarCAN - 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)WATERMARK_STACK_LIMIT, - (CPU_STK_SIZE)TASK_READ_CAR_CAN_STACK_SIZE, - (OS_MSG_QTY)0, - (OS_TICK)0, - (void*)NULL, - (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), - (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)WATERMARK_STACK_LIMIT, + // (CPU_STK_SIZE)TASK_READ_CAR_CAN_STACK_SIZE, + // (OS_MSG_QTY)0, + // (OS_TICK)0, + // (void*)NULL, + // (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), + // (OS_ERR*)&err + // ); + // assertOSError(err); // Initialize UpdateDisplay - OSTaskCreate( - (OS_TCB*)&UpdateDisplay_TCB, - (CPU_CHAR*)"UpdateDisplay", - (OS_TASK_PTR)Task_UpdateDisplay, - (void*)NULL, - (OS_PRIO)TASK_UPDATE_DISPLAY_PRIO, - (CPU_STK*)UpdateDisplay_Stk, - (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, - (CPU_STK_SIZE)TASK_UPDATE_DISPLAY_STACK_SIZE, - (OS_MSG_QTY)0, - (OS_TICK)0, - (void*)NULL, - (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), - (OS_ERR*)&err - ); - assertOSError(err); + // OSTaskCreate( + // (OS_TCB*)&UpdateDisplay_TCB, + // (CPU_CHAR*)"UpdateDisplay", + // (OS_TASK_PTR)Task_UpdateDisplay, + // (void*)NULL, + // (OS_PRIO)TASK_UPDATE_DISPLAY_PRIO, + // (CPU_STK*)UpdateDisplay_Stk, + // (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, + // (CPU_STK_SIZE)TASK_UPDATE_DISPLAY_STACK_SIZE, + // (OS_MSG_QTY)0, + // (OS_TICK)0, + // (void*)NULL, + // (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), + // (OS_ERR*)&err + // ); + // assertOSError(err); + // Initialize SendCarCAN OSTaskCreate( (OS_TCB*)&SendCarCAN_TCB, diff --git a/Drivers/Src/CANbus.c b/Drivers/Src/CANbus.c index 68ab5ddbf..413a5c734 100755 --- a/Drivers/Src/CANbus.c +++ b/Drivers/Src/CANbus.c @@ -15,8 +15,6 @@ static OS_SEM CANBus_ReceiveSem4[NUM_CAN]; // sem4 to count how many msgs in our static OS_MUTEX CANbus_TxMutex[NUM_CAN]; // mutex to lock tx line static OS_MUTEX CANbus_RxMutex[NUM_CAN]; // mutex to lock Rx line - - /** * @brief this function will be passed down to the BSP layer to trigger on RX events. Increments the receive semaphore to signal message in hardware mailbox. Do not access directly outside this driver. * @param bus The CAN bus to operate on. Should be CARCAN or MOTORCAN. From 5cb19e25e6615b7685a12d61a85a0142447e0170 Mon Sep 17 00:00:00 2001 From: Madeleine Lee Date: Sun, 3 Dec 2023 05:53:27 +0000 Subject: [PATCH 08/28] Changes from integration with BPS: uncommented initialization of Task_ReadCarCAN, changed BPS_CONTACTOR CAN message ID to 0x102 instead of x101 (which is for BPS All Clear) --- Apps/Src/main.c | 32 ++++++++++++++++---------------- Drivers/Inc/CANbus.h | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Apps/Src/main.c b/Apps/Src/main.c index 5bc1cf865..7905f7d40 100644 --- a/Apps/Src/main.c +++ b/Apps/Src/main.c @@ -112,22 +112,22 @@ void Task_Init(void *p_arg){ // assertOSError(err); // Initialize ReadCarCAN - // 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)WATERMARK_STACK_LIMIT, - // (CPU_STK_SIZE)TASK_READ_CAR_CAN_STACK_SIZE, - // (OS_MSG_QTY)0, - // (OS_TICK)0, - // (void*)NULL, - // (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), - // (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)WATERMARK_STACK_LIMIT, + (CPU_STK_SIZE)TASK_READ_CAR_CAN_STACK_SIZE, + (OS_MSG_QTY)0, + (OS_TICK)0, + (void*)NULL, + (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), + (OS_ERR*)&err + ); + assertOSError(err); // Initialize UpdateDisplay // OSTaskCreate( diff --git a/Drivers/Inc/CANbus.h b/Drivers/Inc/CANbus.h index 46e8b8447..52d8117be 100644 --- a/Drivers/Inc/CANbus.h +++ b/Drivers/Inc/CANbus.h @@ -29,7 +29,7 @@ */ typedef enum { BPS_TRIP = 0x002, - BPS_CONTACTOR = 0x101, + BPS_CONTACTOR = 0x102, STATE_OF_CHARGE = 0x106, SUPPLEMENTAL_VOLTAGE = 0x10B, MOTOR_DRIVE = 0x221, From 86151374a8893dc2b367ad5f1f4a8db73489703d Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Sat, 9 Dec 2023 17:41:51 -0600 Subject: [PATCH 09/28] test commit --- Apps/Inc/SendTritium.h | 2 +- Apps/Inc/Tasks.h | 6 +-- Apps/Src/ReadTritium.c | 17 +++++-- Apps/Src/SendCarCAN.c | 45 +++++++++-------- Apps/Src/SendTritium.c | 2 +- Apps/Src/Tasks.c | 18 +++---- Apps/Src/main.c | 98 +++++++++++++++++++------------------- Drivers/Inc/CANConfig.h | 2 +- Drivers/Inc/CANbus.h | 1 + Drivers/Src/CANConfig.c | 12 ++++- Tests/Test_TrailingZeros.c | 34 +++++++++++++ 11 files changed, 148 insertions(+), 89 deletions(-) create mode 100644 Tests/Test_TrailingZeros.c diff --git a/Apps/Inc/SendTritium.h b/Apps/Inc/SendTritium.h index 65ed7be29..c4cd03851 100644 --- a/Apps/Inc/SendTritium.h +++ b/Apps/Inc/SendTritium.h @@ -12,7 +12,7 @@ #include "common.h" -#define SENDTRITIUM_PRINT_MES +//#define SENDTRITIUM_PRINT_MES #define MOTOR_MSG_PERIOD 100 #define FSM_PERIOD 100 diff --git a/Apps/Inc/Tasks.h b/Apps/Inc/Tasks.h index 4b62b3c76..ad052d3d3 100644 --- a/Apps/Inc/Tasks.h +++ b/Apps/Inc/Tasks.h @@ -31,9 +31,9 @@ #define TASK_READ_TRITIUM_PRIO 3 #define TASK_SEND_TRITIUM_PRIO 4 #define TASK_READ_CAR_CAN_PRIO 5 -#define TASK_PUT_IOSTATE_PRIO 6 -#define TASK_UPDATE_DISPLAY_PRIO 7 -#define TASK_SEND_CAR_CAN_PRIO 8 +#define TASK_SEND_CAR_CAN_PRIO 6 +#define TASK_PUT_IOSTATE_PRIO 7 +#define TASK_UPDATE_DISPLAY_PRIO 8 #define TASK_DEBUG_DUMP_PRIO 9 #define TASK_COMMAND_LINE_PRIO 10 diff --git a/Apps/Src/ReadTritium.c b/Apps/Src/ReadTritium.c index 3b08c339b..6c7cd7a3c 100755 --- a/Apps/Src/ReadTritium.c +++ b/Apps/Src/ReadTritium.c @@ -62,15 +62,22 @@ void Task_ReadTritium(void *p_arg){ CANDATA_t dataBuf = {0}; // Timer doesn't seem to trigger without initial delay? Might be an RTOS bug - OSTmrCreate(&MotorWatchdog, "Motor watchdog", MOTOR_TIMEOUT_TICKS, MOTOR_TIMEOUT_TICKS, OS_OPT_TMR_PERIODIC, motorWatchdog, NULL, &err); - assertOSError(err); - OSTmrStart(&MotorWatchdog, &err); - assertOSError(err); + static bool watchdogCreated = false; while (1){ ErrorStatus status = CANbus_Read(&dataBuf, true, MOTORCAN); if (status == SUCCESS){ + if(!watchdogCreated){ + OSTmrCreate(&MotorWatchdog, "Motor watchdog", MOTOR_TIMEOUT_TICKS, MOTOR_TIMEOUT_TICKS, OS_OPT_TMR_PERIODIC, motorWatchdog, NULL, &err); + assertOSError(err); + + OSTmrStart(&MotorWatchdog, &err); + assertOSError(err); + + watchdogCreated = true; + } + switch(dataBuf.ID){ case MOTOR_STATUS:{ // motor status error flags is in bytes 4-5 @@ -108,7 +115,7 @@ void Task_ReadTritium(void *p_arg){ SendCarCAN_Put(dataBuf); // Forward message on CarCAN for telemetry } - OSTimeDlyHMSM(0, 0, 0, 10, OS_OPT_TIME_HMSM_NON_STRICT, &err); + // OSTimeDlyHMSM(0, 0, 0, 10, OS_OPT_TIME_HMSM_NON_STRICT, &err); assertOSError(err); } } diff --git a/Apps/Src/SendCarCAN.c b/Apps/Src/SendCarCAN.c index 7eddc1193..2a8ab1a7e 100644 --- a/Apps/Src/SendCarCAN.c +++ b/Apps/Src/SendCarCAN.c @@ -26,7 +26,7 @@ CPU_STK putIOState_Stk[TASK_SEND_CAR_CAN_STACK_SIZE]; //fifo #define FIFO_TYPE CANDATA_t -#define FIFO_SIZE 16 +#define FIFO_SIZE 50 #define FIFO_NAME SendCarCAN_Q #include "fifo.h" @@ -48,16 +48,25 @@ uint8_t get_SendCarCAN_Q_Space(void) { * @brief Wrapper to put new message in the CAN queue */ void SendCarCAN_Put(CANDATA_t message){ - OS_ERR err; + OS_ERR err = OS_ERR_NONE; CPU_TS ticks; - - OSMutexPend(&CarCAN_Mtx, 0, OS_OPT_PEND_BLOCKING, &ticks, &err); - assertOSError(err); + bool success = false; - bool success = SendCarCAN_Q_put(&CANFifo, message); + static uint8_t carcan_ctr = 0; + + if(carcan_ctr > 3){ + OSMutexPend(&CarCAN_Mtx, 0, OS_OPT_PEND_BLOCKING, &ticks, &err); + assertOSError(err); + + success = SendCarCAN_Q_put(&CANFifo, message); + + OSMutexPost(&CarCAN_Mtx, OS_OPT_POST_NONE, &err); + assertOSError(err); + + carcan_ctr = 0; + } + carcan_ctr++; - OSMutexPost(&CarCAN_Mtx, OS_OPT_POST_NONE, &err); - assertOSError(err); if(success) OSSemPost(&CarCAN_Sem4, OS_OPT_POST_1, &err); assertOSError(err); @@ -83,7 +92,7 @@ void SendCarCAN_Init(void) { */ void Task_SendCarCAN(void *p_arg){ OS_ERR err; - // CPU_TS ticks; + CPU_TS ticks; CANDATA_t message; memset(&message, 0, sizeof message); @@ -109,20 +118,18 @@ void Task_SendCarCAN(void *p_arg){ while (1) { // Check if there's something to send in the queue (either IOState or Car state from sendTritium) - // OSSemPend(&CarCAN_Sem4, 0, OS_OPT_PEND_BLOCKING, &ticks, &err); - // assertOSError(err); + OSSemPend(&CarCAN_Sem4, 0, OS_OPT_PEND_BLOCKING, &ticks, &err); + assertOSError(err); - // OSMutexPend(&CarCAN_Mtx, 0, OS_OPT_PEND_BLOCKING, &ticks, &err); - // assertOSError(err); + OSMutexPend(&CarCAN_Mtx, 0, OS_OPT_PEND_BLOCKING, &ticks, &err); + assertOSError(err); - // bool res = SendCarCAN_Q_get(&CANFifo, &message); - // assertOSError(err); + bool res = SendCarCAN_Q_get(&CANFifo, &message); - // OSMutexPost(&CarCAN_Mtx, OS_OPT_POST_NONE, &err); - // assertOSError(err); + OSMutexPost(&CarCAN_Mtx, OS_OPT_POST_NONE, &err); + assertOSError(err); - // if(res) CANbus_Send(message, true, CARCAN); - OSTimeDlyHMSM(0, 0, 0, 100, OS_OPT_NONE, &err); + if(res) CANbus_Send(message, true, CARCAN); } } diff --git a/Apps/Src/SendTritium.c b/Apps/Src/SendTritium.c index 45be6adf6..e12f75edb 100644 --- a/Apps/Src/SendTritium.c +++ b/Apps/Src/SendTritium.c @@ -32,7 +32,7 @@ #define MIN_CRUISE_VELOCITY mpsToRpm(20.0f) // rpm #define MAX_GEARSWITCH_VELOCITY mpsToRpm(8.0f) // rpm -#define BRAKE_PEDAL_THRESHOLD 15 // percent +#define BRAKE_PEDAL_THRESHOLD 30 // percent #define ACCEL_PEDAL_THRESHOLD 10 // percent #define ONEPEDAL_BRAKE_THRESHOLD 25 // percent diff --git a/Apps/Src/Tasks.c b/Apps/Src/Tasks.c index 02b71c6e2..af6382e1d 100644 --- a/Apps/Src/Tasks.c +++ b/Apps/Src/Tasks.c @@ -103,17 +103,17 @@ void throwTaskError(error_code_t errorCode, callback_t errorCallback, error_sche #if DEBUG == 1 // Print the error that caused this fault - printf("\n\rCurrent Error Code: 0x%04x\n\r", errorCode); + // printf("\n\rCurrent Error Code: 0x%04x\n\r", errorCode); - // Print the errors for each applications with error data - printf("\n\rAll application errors:\n\r"); - printf("Error_ReadCarCAN: 0x%04x\n\r", Error_ReadCarCAN); - printf("Error_ReadTritium: 0x%04x\n\r", Error_ReadTritium); - printf("Error_UpdateDisplay: 0x%04x\n\r", Error_UpdateDisplay); + // // Print the errors for each applications with error data + // printf("\n\rAll application errors:\n\r"); + // printf("Error_ReadCarCAN: 0x%04x\n\r", Error_ReadCarCAN); + // printf("Error_ReadTritium: 0x%04x\n\r", Error_ReadTritium); + // printf("Error_UpdateDisplay: 0x%04x\n\r", Error_UpdateDisplay); - // Delay so that we're not constantly printing - for (int i = 0; i < 9999999; i++) { - } + // // Delay so that we're not constantly printing + // for (int i = 0; i < 9999999; i++) { + // } #endif } diff --git a/Apps/Src/main.c b/Apps/Src/main.c index 7905f7d40..62a8f33ba 100644 --- a/Apps/Src/main.c +++ b/Apps/Src/main.c @@ -65,7 +65,7 @@ void Task_Init(void *p_arg){ // Initialize drivers Pedals_Init(); BSP_UART_Init(UART_2); - CANbus_Init(CARCAN, NULL, NUM_CARCAN_FILTERS); + CANbus_Init(CARCAN, carCANFilterList, NUM_CARCAN_FILTERS); CANbus_Init(MOTORCAN, NULL, NUM_MOTORCAN_FILTERS); Contactors_Init(); Display_Init(); @@ -76,40 +76,40 @@ void Task_Init(void *p_arg){ SendCarCAN_Init(); // Initialize ReadTritium - // OSTaskCreate( - // (OS_TCB*)&ReadTritium_TCB, - // (CPU_CHAR*)"ReadTritium", - // (OS_TASK_PTR)Task_ReadTritium, - // (void*)NULL, - // (OS_PRIO)TASK_READ_TRITIUM_PRIO, - // (CPU_STK*)ReadTritium_Stk, - // (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, - // (CPU_STK_SIZE)TASK_READ_TRITIUM_STACK_SIZE, - // (OS_MSG_QTY)0, - // (OS_TICK)0, - // (void*)NULL, - // (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), - // (OS_ERR*)&err - // ); - // assertOSError(err); + OSTaskCreate( + (OS_TCB*)&ReadTritium_TCB, + (CPU_CHAR*)"ReadTritium", + (OS_TASK_PTR)Task_ReadTritium, + (void*)NULL, + (OS_PRIO)TASK_READ_TRITIUM_PRIO, + (CPU_STK*)ReadTritium_Stk, + (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, + (CPU_STK_SIZE)TASK_READ_TRITIUM_STACK_SIZE, + (OS_MSG_QTY)0, + (OS_TICK)0, + (void*)NULL, + (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), + (OS_ERR*)&err + ); + assertOSError(err); // Initialize SendTritium - // OSTaskCreate( - // (OS_TCB*)&SendTritium_TCB, - // (CPU_CHAR*)"SendTritium", - // (OS_TASK_PTR)Task_SendTritium, - // (void*)NULL, - // (OS_PRIO)TASK_SEND_TRITIUM_PRIO, - // (CPU_STK*)SendTritium_Stk, - // (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, - // (CPU_STK_SIZE)TASK_SEND_TRITIUM_STACK_SIZE, - // (OS_MSG_QTY)0, - // (OS_TICK)0, - // (void*)NULL, - // (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), - // (OS_ERR*)&err - // ); - // assertOSError(err); + OSTaskCreate( + (OS_TCB*)&SendTritium_TCB, + (CPU_CHAR*)"SendTritium", + (OS_TASK_PTR)Task_SendTritium, + (void*)NULL, + (OS_PRIO)TASK_SEND_TRITIUM_PRIO, + (CPU_STK*)SendTritium_Stk, + (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, + (CPU_STK_SIZE)TASK_SEND_TRITIUM_STACK_SIZE, + (OS_MSG_QTY)0, + (OS_TICK)0, + (void*)NULL, + (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), + (OS_ERR*)&err + ); + assertOSError(err); // Initialize ReadCarCAN OSTaskCreate( @@ -130,22 +130,22 @@ void Task_Init(void *p_arg){ assertOSError(err); // Initialize UpdateDisplay - // OSTaskCreate( - // (OS_TCB*)&UpdateDisplay_TCB, - // (CPU_CHAR*)"UpdateDisplay", - // (OS_TASK_PTR)Task_UpdateDisplay, - // (void*)NULL, - // (OS_PRIO)TASK_UPDATE_DISPLAY_PRIO, - // (CPU_STK*)UpdateDisplay_Stk, - // (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, - // (CPU_STK_SIZE)TASK_UPDATE_DISPLAY_STACK_SIZE, - // (OS_MSG_QTY)0, - // (OS_TICK)0, - // (void*)NULL, - // (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), - // (OS_ERR*)&err - // ); - // assertOSError(err); + OSTaskCreate( + (OS_TCB*)&UpdateDisplay_TCB, + (CPU_CHAR*)"UpdateDisplay", + (OS_TASK_PTR)Task_UpdateDisplay, + (void*)NULL, + (OS_PRIO)TASK_UPDATE_DISPLAY_PRIO, + (CPU_STK*)UpdateDisplay_Stk, + (CPU_STK_SIZE)WATERMARK_STACK_LIMIT, + (CPU_STK_SIZE)TASK_UPDATE_DISPLAY_STACK_SIZE, + (OS_MSG_QTY)0, + (OS_TICK)0, + (void*)NULL, + (OS_OPT)(OS_OPT_TASK_STK_CLR|OS_OPT_TASK_SAVE_FP), + (OS_ERR*)&err + ); + assertOSError(err); // Initialize SendCarCAN OSTaskCreate( diff --git a/Drivers/Inc/CANConfig.h b/Drivers/Inc/CANConfig.h index 9364a4bf3..22c1f4577 100644 --- a/Drivers/Inc/CANConfig.h +++ b/Drivers/Inc/CANConfig.h @@ -15,7 +15,7 @@ * Filter Lists for CarCAN and MotorCAN */ #define NUM_CARCAN_FILTERS 6 -#define NUM_MOTORCAN_FILTERS 0 +#define NUM_MOTORCAN_FILTERS 7 extern CANId_t carCANFilterList[NUM_CARCAN_FILTERS]; extern CANId_t motorCANFilterList[NUM_MOTORCAN_FILTERS]; diff --git a/Drivers/Inc/CANbus.h b/Drivers/Inc/CANbus.h index 52d8117be..fcc01383e 100644 --- a/Drivers/Inc/CANbus.h +++ b/Drivers/Inc/CANbus.h @@ -45,6 +45,7 @@ typedef enum { TEMPERATURE = 0x24B, ODOMETER_AMPHOURS = 0x24E, ARRAY_CONTACTOR_STATE_CHANGE = 0x24F, + SLIP_SPEED = 0x257, CONTROL_MODE = 0x580, IO_STATE = 0x581, MAX_CAN_ID diff --git a/Drivers/Src/CANConfig.c b/Drivers/Src/CANConfig.c index ce8548d1f..23135d00b 100644 --- a/Drivers/Src/CANConfig.c +++ b/Drivers/Src/CANConfig.c @@ -35,6 +35,7 @@ const CANLUT_T CANLUT[MAX_CAN_ID] = { [TEMPERATURE] = {NOIDX, DOUBLE}, /** TEMPERATURE **/ [ODOMETER_AMPHOURS] = {NOIDX, DOUBLE}, /** ODOMETER_AMPHOURS **/ [ARRAY_CONTACTOR_STATE_CHANGE] = {NOIDX, BYTE }, /** ARRAY_CONTACTOR_STATE_CHANGE **/ + [SLIP_SPEED] = {NOIDX, DOUBLE}, [MOTOR_DRIVE] = {NOIDX, DOUBLE}, /** MOTOR_DRIVE **/ [MOTOR_POWER] = {NOIDX, DOUBLE}, /** MOTOR_POWER **/ [MOTOR_RESET] = {NOIDX, DOUBLE}, /** MOTOR_RESET **/ @@ -53,4 +54,13 @@ CANId_t carCANFilterList[NUM_CARCAN_FILTERS] = { STATE_OF_CHARGE, SUPPLEMENTAL_VOLTAGE }; -CANId_t motorCANFilterList[NUM_MOTORCAN_FILTERS] = {}; + +CANId_t motorCANFilterList[NUM_MOTORCAN_FILTERS] = { + MC_BUS, + VELOCITY, + BACKEMF, + TEMPERATURE, + ODOMETER_AMPHOURS, + SLIP_SPEED, + MOTOR_STATUS +}; diff --git a/Tests/Test_TrailingZeros.c b/Tests/Test_TrailingZeros.c new file mode 100644 index 000000000..732a6e698 --- /dev/null +++ b/Tests/Test_TrailingZeros.c @@ -0,0 +1,34 @@ +/* + * C Program to Count the Number of Trailing Zeroes in Integer + */ +#include "common.h" +#include "config.h" +#include + +int main() +{ + BSP_UART_Init(UART_2); + + int count = 0; + unsigned int num; + + num = 176; + while (num != 0) + { + if ((num & 1) == 1) + { + break; + } + else + { + count++; + num = num >> 1; + + } + } + printf("\n%d", count); + + while(1); + + return 0; +} \ No newline at end of file From d3a4e9034000b21ab7821fa6386a5669e68c4ffa Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Wed, 13 Dec 2023 10:40:23 -0600 Subject: [PATCH 10/28] Squashed commit of the following: commit 6cf79967dd9e64e2b4132f59b75c3160574a280d Author: Madeleine Lee Date: Sun Dec 3 05:59:52 2023 +0000 Changes from integration with BPS: flipped reading of ignition pins in PutIOState to account for the inverted logic, added a new bit of information to PutIOState in byte 3, bit 2 which tells BPS if the array contactor should be turned on or not (true if IGN_1 or IGN_2 are on). This is necessary because when the ignition is switched to motor state, the array pin is turned off (only one or the other is on at a time). Note: in the future we'd like to use the GPIO read settings to account for the inverted ignition logic so we don't have to negate every Minions_Read. commit f72917bb95438dbe4a7c40fe6b31e47cffdf73a7 Author: Madeleine Lee Date: Fri Nov 17 15:55:26 2023 +0000 Fixed accidental deletion in docs. commit 2755a693aa4ce4e8d2e189f74227da6f986a68c2 Author: Madeleine Lee Date: Fri Nov 17 15:50:32 2023 +0000 Memset the gTxMessage.Data to zero since one-byte messages weren't clearing out old data in the rest of the bytes, updated comments in the test file. commit 5d3ddfb36be8605b5ba103f30473b5ab5bdab435 Author: Madeleine Lee Date: Fri Nov 17 14:50:01 2023 +0000 Added commas to enum to match new enum generation format. commit 347ef980fd991fc14332054d30169b0e03d6298b Author: Madeleine Lee Date: Fri Nov 17 14:27:58 2023 +0000 Updated NUM_CAN_IDS to MAX_CAN_ID in the CANId enum. commit 03f262c1f8e83056f3afbd54f4615c04a33ebf5f Merge: 362628e e6c9fb6 Author: Madeleine Lee Date: Fri Nov 17 10:31:31 2023 +0000 Merge branch 'master' into sendcarcan-telemetry-merge commit 362628e0a55301fd40873f7a0224b38fca461831 Author: Madeleine Lee Date: Fri Nov 17 10:24:37 2023 +0000 Revisions to SendCarCAN and test file to allow messages to be inspected in GDB using variables instead of prints which were overwhelming UART. commit 8bdf6bbe498cccb5ab72a0a3312e04d5a4735030 Author: Madeleine Lee Date: Mon Nov 13 23:04:14 2023 +0000 Addressing review comments: updated SendTritium macros, removed motorMsgCount queue, downsized SendCarCAN FIFO. commit 0079ce4b71d0d315383bee4364b4cff93dbf754b Author: Madeleine Lee Date: Sat Nov 11 17:57:19 2023 +0000 Test file changes for last minute panic debugging. Added an array to see what IDS are being received. commit de12ac1df64358862dc6955b917713c37ae5013f Author: Madeleine Lee Date: Sat Nov 11 17:32:41 2023 +0000 Added while loop to putIOState commit ff4bf0ac2de725652297c4238b1372e51c391809 Author: Madeleine Lee Date: Sat Nov 11 08:16:23 2023 +0000 Updates from hardware testing: added counter array to reduce frequency at which we forwared motor messages onto CarCAN, moved init functions in test file, added Renode independent watchdog fix. commit 77dbc2ab63e87b7b2011c40121fc54c6a39bd0b7 Author: Madeleine Lee Date: Sat Nov 11 03:22:40 2023 +0000 Changed PutIOState to send directly instead of putting messages in the queue to be sent by SendCarCAN later. commit ce1d74a4fd8c05719046ec05d3ff7b086e72557d Author: Madeleine Lee Date: Sat Nov 11 03:20:33 2023 +0000 Moved mutex, semaphore creation and fifo renewal to a new SendCarCAN_Init function so that other tasks can put things into the queue before SendCarCAN is ready. Additionally, created a new static task in SendCarCAN.c called PutIOState which periodically sends messages over CarCAN. commit 9043b7beab3086a8b3a7344dc27ab02ab4f24377 Author: Madeleine Lee Date: Fri Nov 10 23:57:18 2023 +0000 Deleted extra lines added when merging. commit a5e63dfaa2060d6d01fad9163c4d75cd2f60d31e Merge: d303e9b 5ae3439 Author: Madeleine Lee Date: Fri Nov 10 23:41:44 2023 +0000 Merge branch 'master' into sendcarcan-telemetry-merge commit d303e9b400cc5ce1f39233f80cfb40ba1d2068fe Author: Madeleine Lee Date: Fri Nov 10 23:07:18 2023 +0000 Test file updates from testing on hardware. commit 9c755baa4bf7f5b14c78b72c15c519589ded83d6 Author: Madeleine Lee Date: Sat Nov 4 21:08:49 2023 +0000 Added ability to print FIFO queue indexes, added ReadTritium task in SendCarCAN test, fixed CAN initialization to read CarCAN but also initialize MOTORCAN. commit 489a494b020df9d0af151e5d631ca8a13c75e62a Author: Madeleine Lee Date: Fri Oct 27 14:44:45 2023 +0000 Cleaned up and worked on test file, removed attempt to put fifo in header file and added a wrapper instead. Test compiles but hasn't been verified to work successfully yet. commit c38a3d7463449658034411a5998774e1411e853f Author: Madeleine Lee Date: Sat Oct 21 04:57:18 2023 +0000 SendCarCAN test file compiles! But at what cost... commit ad84abfbd1917085e24fb0ae67ada039f8fc305c Author: Madeleine Lee Date: Sat Oct 21 04:47:33 2023 +0000 Made aa first draft of the SendCarCAN test file and attempted to get at the SendCarCAN file by exposing it with a macro mess. controls-leader code compiles, but the test file does not compile yet. commit 3d1d906fea78c672493be72a1eccc81b8928258e Author: Madeleine Lee Date: Fri Oct 20 21:06:52 2023 +0000 Altered test macros so that we can define __TEST_SENDTRITIUM and print info while running tests on hardware or also define __TEST_SENDTRITIUM_SOFTWAREONLY to bypass hardware inputs/outputs. commit 73dddf7c6b9f5f71e875b01c0f783f4e364ea6ff Author: Madeleine Lee Date: Fri Oct 20 03:02:13 2023 +0000 Added line to put messages from the motor into the CarCAN queue to be sent. commit 90cb9c64e7d499e54d4dbc4c3e33c16a98a7bb48 Author: Madeleine Lee Date: Fri Oct 20 02:50:50 2023 +0000 Deleted most putIOStateTimer thigns, added a macro and counter in the sendCarCAN loop to send the IO message at approximately the same frequency as before (250 ms), but this time using loops, delays, and counters. It won't be as accurate, but it should still be at a relatively similar frequency. commit 5185426b40463dafb0384e46b9b3efdbe84a2531 Author: Madeleine Lee Date: Sat Oct 14 20:29:23 2023 +0000 Changed main loop to check the queue periodically instead of pending on a semaphore. The loop will check two semaphores- one to see if it's time to put an IO State message in the queue (based on if the putIOState timer has expired or not) and one to see if there's a message in the queuethat we should send. commit 2d7dbbff551466e165eac644f4f62c9e2b63174e Author: Madeleine Lee Date: Sat Oct 7 23:21:43 2023 +0000 Started a test file for SendCarCAN. commit 2f451007f3b20bfa60460d062de935d7839aac23 Merge: 6f69ba9 fd33899 Author: ishdeshpa Date: Tue Sep 26 00:09:02 2023 +0000 merged in master, now builds. test still needs to be written and bugfixes made. also ignition switch message needs to be added. commit 6f69ba9ae324bc6fd07627de7da5897f3705a2e2 Author: ishdeshpa Date: Mon Sep 25 23:50:29 2023 +0000 merge conflict resolved commit de426c5249b2142e6209d5b1e642c6f1e37d223a Author: ishdeshpa Date: Mon Jul 10 19:36:13 2023 +0000 adapted CAN_Queue into a library file and integrated with SendCarCAN commit cfd0b7c014c65c6fadae1094dff67283cc14bf52 Author: ishdeshpa Date: Sun Jul 9 22:16:56 2023 +0000 renamed telemetry to send car can commit 771a916604dde3cfb1bcc0ff681106101ccc2677 Author: Nathaniel Delgado Date: Sat Jul 8 03:13:27 2023 +0000 Merged functionality of SendCarCAN into Telemetry and removed SendCarCAN remnants --- Apps/Src/SendCarCAN.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Apps/Src/SendCarCAN.c b/Apps/Src/SendCarCAN.c index 2a8ab1a7e..cd1f79c34 100644 --- a/Apps/Src/SendCarCAN.c +++ b/Apps/Src/SendCarCAN.c @@ -154,6 +154,9 @@ static void putIOState(void){ message.data[3] |= contactorState << contactor; } + // Tell BPS if the array contactor should be on + message.data[3] |= (!Minions_Read(IGN_1) || !Minions_Read(IGN_2)) << 2; + CANbus_Send(message, true, CARCAN); } From 8c3c16a130a910e368e0070e8573ccb54cef1c31 Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Wed, 13 Dec 2023 14:32:04 -0600 Subject: [PATCH 11/28] mostly working --- Apps/Src/ReadCarCAN.c | 6 +++--- Apps/Src/ReadTritium.c | 21 --------------------- Apps/Src/SendTritium.c | 2 +- Apps/Src/Tasks.c | 1 + 4 files changed, 5 insertions(+), 25 deletions(-) diff --git a/Apps/Src/ReadCarCAN.c b/Apps/Src/ReadCarCAN.c index 07e7f39dc..64897dd4b 100644 --- a/Apps/Src/ReadCarCAN.c +++ b/Apps/Src/ReadCarCAN.c @@ -235,9 +235,9 @@ static void updateHVPlusMinusSaturation(int8_t messageState){ */ void attemptTurnMotorControllerPBCOn(void){ if(mcPBCComplete){ - Contactors_Set(MOTOR_CONTROLLER_PRECHARGE_BYPASS_CONTACTOR, ON, true); - UpdateDisplay_SetMotor(true); - } + Contactors_Set(MOTOR_CONTROLLER_PRECHARGE_BYPASS_CONTACTOR, ON, true); + UpdateDisplay_SetMotor(true); + } } /** diff --git a/Apps/Src/ReadTritium.c b/Apps/Src/ReadTritium.c index 6c7cd7a3c..85b0c3364 100755 --- a/Apps/Src/ReadTritium.c +++ b/Apps/Src/ReadTritium.c @@ -36,27 +36,6 @@ static void motorWatchdog(void *tmr, void *p_arg) { } -/* OBJECTIVES: -Objective 1: -- Receive motor status message from MotorController (18.4.2) -- interpret error status - - if error - - assertOSError -- determine information important to telementry - - Telemetry -- determine information important for storage - - acquire mutex on Storage Array - - Store information in Storage Array (based on index) - - release mutex on Storage Array - -Objective 2: -- create function able to read data from Storage Array - - pend on Storage Array mutex - - acquire Storage Array mutex - - read information of array index - - release Storage Array mutex -*/ - void Task_ReadTritium(void *p_arg){ OS_ERR err; CANDATA_t dataBuf = {0}; diff --git a/Apps/Src/SendTritium.c b/Apps/Src/SendTritium.c index e12f75edb..d5783d664 100644 --- a/Apps/Src/SendTritium.c +++ b/Apps/Src/SendTritium.c @@ -32,7 +32,7 @@ #define MIN_CRUISE_VELOCITY mpsToRpm(20.0f) // rpm #define MAX_GEARSWITCH_VELOCITY mpsToRpm(8.0f) // rpm -#define BRAKE_PEDAL_THRESHOLD 30 // percent +#define BRAKE_PEDAL_THRESHOLD 50 // percent #define ACCEL_PEDAL_THRESHOLD 10 // percent #define ONEPEDAL_BRAKE_THRESHOLD 25 // percent diff --git a/Apps/Src/Tasks.c b/Apps/Src/Tasks.c index af6382e1d..de86becae 100644 --- a/Apps/Src/Tasks.c +++ b/Apps/Src/Tasks.c @@ -89,6 +89,7 @@ void throwTaskError(error_code_t errorCode, callback_t errorCallback, error_sche EmergencyContactorOpen(); Display_Error(errorCode); // Needs to happen before callback so that tasks can change the screen // (ex: readCarCAN and evac screen for BPS trip) + // printf(errorCode); UpdateDisplay_ClearQueue(); // Clear message queue to ensure no other commands overwrite the error screen } From 84a04c0496e3b50bd19c0803fed8d65b0c903cca Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Wed, 13 Dec 2023 14:46:48 -0600 Subject: [PATCH 12/28] ReadTritium fixes --- Apps/Src/ReadTritium.c | 3 --- Apps/Src/Tasks.c | 5 +++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Apps/Src/ReadTritium.c b/Apps/Src/ReadTritium.c index 85b0c3364..23e27dbe1 100755 --- a/Apps/Src/ReadTritium.c +++ b/Apps/Src/ReadTritium.c @@ -93,9 +93,6 @@ void Task_ReadTritium(void *p_arg){ SendCarCAN_Put(dataBuf); // Forward message on CarCAN for telemetry } - - // OSTimeDlyHMSM(0, 0, 0, 10, OS_OPT_TIME_HMSM_NON_STRICT, &err); - assertOSError(err); } } diff --git a/Apps/Src/Tasks.c b/Apps/Src/Tasks.c index de86becae..d68e85e00 100644 --- a/Apps/Src/Tasks.c +++ b/Apps/Src/Tasks.c @@ -54,12 +54,13 @@ extern const pinInfo_t PININFO_LUT[]; // For GPIO writes. Externed from Minions * Error assertion-related functions */ -void _assertOSError(OS_ERR err) +void _assertOSError(volatile OS_ERR err) { if (err != OS_ERR_NONE) { EmergencyContactorOpen(); // Turn off contactors and turn on the brakelight to indicate an emergency Display_Error(err); // Display the location and error code + printf("%d\n\r", err); while(1){;} //nonrecoverable } } @@ -89,7 +90,7 @@ void throwTaskError(error_code_t errorCode, callback_t errorCallback, error_sche EmergencyContactorOpen(); Display_Error(errorCode); // Needs to happen before callback so that tasks can change the screen // (ex: readCarCAN and evac screen for BPS trip) - // printf(errorCode); + printf("%d\n\r", errorCode); UpdateDisplay_ClearQueue(); // Clear message queue to ensure no other commands overwrite the error screen } From e0c40ec4ccb56d27ed7a4fcc33c0f1d1792bd0e7 Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Sat, 16 Dec 2023 20:06:18 -0600 Subject: [PATCH 13/28] Squashed commit of the following: commit 66958b8c9d714b94331c72eccdf5d6ea67b1d235 Author: Nathaniel Delgado <89701060+NathanielDelgado@users.noreply.github.com> Date: Sat Dec 16 18:29:35 2023 -0600 SendCarCAN Restructure (#337) * Merged functionality of SendCarCAN into Telemetry and removed SendCarCAN remnants * renamed telemetry to send car can * adapted CAN_Queue into a library file and integrated with SendCarCAN * merge conflict resolved * Started a test file for SendCarCAN. * Changed main loop to check the queue periodically instead of pending on a semaphore. The loop will check two semaphores- one to see if it's time to put an IO State message in the queue (based on if the putIOState timer has expired or not) and one to see if there's a message in the queuethat we should send. * Deleted most putIOStateTimer thigns, added a macro and counter in the sendCarCAN loop to send the IO message at approximately the same frequency as before (250 ms), but this time using loops, delays, and counters. It won't be as accurate, but it should still be at a relatively similar frequency. * Added line to put messages from the motor into the CarCAN queue to be sent. * Altered test macros so that we can define __TEST_SENDTRITIUM and print info while running tests on hardware or also define __TEST_SENDTRITIUM_SOFTWAREONLY to bypass hardware inputs/outputs. * Made aa first draft of the SendCarCAN test file and attempted to get at the SendCarCAN file by exposing it with a macro mess. controls-leader code compiles, but the test file does not compile yet. * SendCarCAN test file compiles! But at what cost... * Cleaned up and worked on test file, removed attempt to put fifo in header file and added a wrapper instead. Test compiles but hasn't been verified to work successfully yet. * Added ability to print FIFO queue indexes, added ReadTritium task in SendCarCAN test, fixed CAN initialization to read CarCAN but also initialize MOTORCAN. * Test file updates from testing on hardware. * Deleted extra lines added when merging. * Moved mutex, semaphore creation and fifo renewal to a new SendCarCAN_Init function so that other tasks can put things into the queue before SendCarCAN is ready. Additionally, created a new static task in SendCarCAN.c called PutIOState which periodically sends messages over CarCAN. * Changed PutIOState to send directly instead of putting messages in the queue to be sent by SendCarCAN later. * Updates from hardware testing: added counter array to reduce frequency at which we forwared motor messages onto CarCAN, moved init functions in test file, added Renode independent watchdog fix. * Added while loop to putIOState * Test file changes for last minute panic debugging. Added an array to see what IDS are being received. * Addressing review comments: updated SendTritium macros, removed motorMsgCount queue, downsized SendCarCAN FIFO. * Revisions to SendCarCAN and test file to allow messages to be inspected in GDB using variables instead of prints which were overwhelming UART. * Updated NUM_CAN_IDS to MAX_CAN_ID in the CANId enum. * Added commas to enum to match new enum generation format. * Memset the gTxMessage.Data to zero since one-byte messages weren't clearing out old data in the rest of the bytes, updated comments in the test file. * Fixed accidental deletion in docs. * Changes from integration with BPS: flipped reading of ignition pins in PutIOState to account for the inverted logic, added a new bit of information to PutIOState in byte 3, bit 2 which tells BPS if the array contactor should be turned on or not (true if IGN_1 or IGN_2 are on). This is necessary because when the ignition is switched to motor state, the array pin is turned off (only one or the other is on at a time). Note: in the future we'd like to use the GPIO read settings to account for the inverted ignition logic so we don't have to negate every Minions_Read. * Addressed review comments: Shifted task priorities to be next to each other, added to the comment for SendCarCAN_Put. * addressed review comments --------- Co-authored-by: ishdeshpa Co-authored-by: Madeleine Lee commit 5c13022112bf14410daf4bcecffa047ecd0ed1ae Author: Nathaniel Delgado Date: Wed Dec 13 14:59:37 2023 -0600 Added bps can sim for integration simulation --- Apps/Inc/SendCarCAN.h | 2 ++ Apps/Inc/SendTritium.h | 20 ++++++++++++++++ Apps/Src/SendCarCAN.c | 5 ++++ Scripts/bps_sim_can.py | 52 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 Scripts/bps_sim_can.py diff --git a/Apps/Inc/SendCarCAN.h b/Apps/Inc/SendCarCAN.h index 61ddca481..99772bfb3 100644 --- a/Apps/Inc/SendCarCAN.h +++ b/Apps/Inc/SendCarCAN.h @@ -16,6 +16,8 @@ void SendCarCAN_Put(CANDATA_t message); /** * @brief return the space left in SendCarCAN_Q for debug purposes */ +#ifdef DEBUG uint8_t get_SendCarCAN_Q_Space(void); +#endif #endif \ No newline at end of file diff --git a/Apps/Inc/SendTritium.h b/Apps/Inc/SendTritium.h index c4cd03851..3670a5aa9 100644 --- a/Apps/Inc/SendTritium.h +++ b/Apps/Inc/SendTritium.h @@ -23,6 +23,9 @@ GEAR(FORWARD_GEAR), \ GEAR(NEUTRAL_GEAR), \ GEAR(REVERSE_GEAR), \ + GEAR(FORWARD_GEAR), \ + GEAR(NEUTRAL_GEAR), \ + GEAR(REVERSE_GEAR), \ typedef enum GEAR_ENUM { FOREACH_Gear(GENERATE_ENUM) @@ -66,6 +69,23 @@ extern float velocityObserved; extern float cruiseVelSetpoint; #endif +#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 Gear_t gear; + +extern TritiumState_t state; +extern float velocityObserved; +extern float cruiseVelSetpoint; +#endif + // Getter functions for local variables in SendTritium.c EXPOSE_GETTER(bool, cruiseEnable) EXPOSE_GETTER(bool, cruiseSet) diff --git a/Apps/Src/SendCarCAN.c b/Apps/Src/SendCarCAN.c index cd1f79c34..e28191ab7 100644 --- a/Apps/Src/SendCarCAN.c +++ b/Apps/Src/SendCarCAN.c @@ -2,9 +2,12 @@ * @copyright Copyright (c) 2018-2023 UT Longhorn Racing Solar * @file SendCarCAN.c * @brief Function implementations for the SendCarCAN application. + * @brief Function implementations for the SendCarCAN application. * * This contains functions relevant to placing CAN messages in a CarCAN queue and periodically sending * those messages in the SendCarCAN task. + * This contains functions relevant to placing CAN messages in a CarCAN queue and periodically sending + * those messages in the SendCarCAN task. * */ @@ -40,9 +43,11 @@ static void Task_PutIOState(void *p_arg); /** * @brief return the space left in SendCarCAN_Q for debug purposes */ +#ifdef DEBUG uint8_t get_SendCarCAN_Q_Space(void) { return (CANFifo.get - CANFifo.put - 1) % (sizeof CANFifo.buffer / sizeof CANFifo.buffer[0]); } +#endif /** * @brief Wrapper to put new message in the CAN queue diff --git a/Scripts/bps_sim_can.py b/Scripts/bps_sim_can.py new file mode 100644 index 000000000..39cc28677 --- /dev/null +++ b/Scripts/bps_sim_can.py @@ -0,0 +1,52 @@ +import time +import serial +import threading + +# take in parameters +com_num = input('Enter COM number: ') +# baudrate = input('Enter baudrate (921600 default): ') +# baudrate = 921600 if baudrate == '' else int(baudrate) + +# establish connection +ser = serial.Serial( + port='COM' + com_num, + baudrate=921600, + parity=serial.PARITY_NONE, + stopbits=serial.STOPBITS_ONE, + bytesize=serial.EIGHTBITS, +) + +out = 'S4' + chr(13) +ser.write(out.encode('ascii')) + +out = 'O' + chr(13) +ser.write(out.encode('ascii')) + +ign_val = False + +# act as terminal + +def rec(): + global ign_val + while 1: + inp = '' + while ser.in_waiting > 0: + inp += ser.read(1).decode("ascii") + + # print feedback if available + if inp[1:4] == '581': + ign_val = (int(inp[11:13]) >= 4) + + # print('EN HVARR CONTACTOR: ' + str(ign_val)) + +def send(): + global ign_val + while 1: + out = 'T1021' + ('07' if ign_val else '06') + chr(13) + ser.write(out.encode('ascii')) + + print('SENDING ' + str(ign_val)) + time.sleep(0.25) + +threading.Thread(target=rec).start() +threading.Thread(target=send).start() From 8d7e9359999b5080bbcd3af3cb7cd05a9c81637b Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Sat, 16 Dec 2023 21:13:36 -0600 Subject: [PATCH 14/28] removed duplicates --- Apps/Inc/SendTritium.h | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/Apps/Inc/SendTritium.h b/Apps/Inc/SendTritium.h index 3670a5aa9..c4cd03851 100644 --- a/Apps/Inc/SendTritium.h +++ b/Apps/Inc/SendTritium.h @@ -23,9 +23,6 @@ GEAR(FORWARD_GEAR), \ GEAR(NEUTRAL_GEAR), \ GEAR(REVERSE_GEAR), \ - GEAR(FORWARD_GEAR), \ - GEAR(NEUTRAL_GEAR), \ - GEAR(REVERSE_GEAR), \ typedef enum GEAR_ENUM { FOREACH_Gear(GENERATE_ENUM) @@ -69,23 +66,6 @@ extern float velocityObserved; extern float cruiseVelSetpoint; #endif -#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 Gear_t gear; - -extern TritiumState_t state; -extern float velocityObserved; -extern float cruiseVelSetpoint; -#endif - // Getter functions for local variables in SendTritium.c EXPOSE_GETTER(bool, cruiseEnable) EXPOSE_GETTER(bool, cruiseSet) From c7808fa7cb0cc1722c2ba665badd1c472abec739 Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Sat, 16 Dec 2023 23:41:00 -0600 Subject: [PATCH 15/28] fixed merge issue in SendTritium.c (closes #381) --- Apps/Src/SendTritium.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/Apps/Src/SendTritium.c b/Apps/Src/SendTritium.c index d5783d664..db0865908 100644 --- a/Apps/Src/SendTritium.c +++ b/Apps/Src/SendTritium.c @@ -62,13 +62,10 @@ float velocitySetpoint = 0; float cruiseVelSetpoint = 0; // Current observed velocity - -#ifndef SENDTRITIUM_EXPOSE_VARS static float velocityObserved = 0; // Counter for sending setpoints to motor static uint8_t motorMsgCounter = 0; -#endif // Debouncing counters static uint8_t onePedalCounter = 0; From 47d011fce97f467f3c6e5cd5fd2c4bc009a1bb95 Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Mon, 18 Dec 2023 19:36:39 -0600 Subject: [PATCH 16/28] moved macros from ReadCarCAN.c to ReadCarCAN.h so they are visible in docs --- Apps/Inc/ReadCarCAN.h | 19 +++++++++++++++++++ Apps/Src/ReadCarCAN.c | 19 ------------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Apps/Inc/ReadCarCAN.h b/Apps/Inc/ReadCarCAN.h index a082bf312..39ba3df91 100644 --- a/Apps/Inc/ReadCarCAN.h +++ b/Apps/Inc/ReadCarCAN.h @@ -16,6 +16,25 @@ #include "Tasks.h" #include "CANbus.h" +// Length of the array and motor PBC saturation buffers +#define SAT_BUF_LENGTH 5 + +// The Array/Motor Controller Saturation Threshold is used to determine if Controls has +// received a sufficient number of BPS's HV Array/Plus-Minus Enable Messages. +// BPS Array and Plus/Minus saturation threshold is halfway between 0 and max saturation value. +#define ARRAY_SATURATION_THRESHOLD (((SAT_BUF_LENGTH + 1) * SAT_BUF_LENGTH) / 4) +#define PLUS_MINUS_SATURATION_THRESHOLD (((SAT_BUF_LENGTH + 1) * SAT_BUF_LENGTH) / 4) + +// Timer delay constants +#define CAN_WATCH_TMR_DLY_MS 500u // 500 ms +#define CAN_WATCH_TMR_DLY_TMR_TS ((CAN_WATCH_TMR_DLY_MS * OS_CFG_TMR_TASK_RATE_HZ) / (1000u)) // 1000 for ms -> s conversion + +// Precharge Delay times in milliseconds +#define PRECHARGE_PLUS_MINUS_DELAY 100u // 100 ms, as this the smallest time delay that the RTOS can work with +#define PRECHARGE_ARRAY_DELAY 100u // 100 ms +#define ARRAY_PRECHARGE_BYPASS_DLY_TMR_TS ((PRECHARGE_ARRAY_DELAY * OS_CFG_TMR_TASK_RATE_HZ) / (1000u)) +#define MOTOR_CONTROLLER_PRECHARGE_BYPASS_DLY_TMR_TS ((PRECHARGE_PLUS_MINUS_DELAY * OS_CFG_TMR_TASK_RATE_HZ) / (1000u)) + /** * Error types */ diff --git a/Apps/Src/ReadCarCAN.c b/Apps/Src/ReadCarCAN.c index 64897dd4b..b51f9bb0d 100644 --- a/Apps/Src/ReadCarCAN.c +++ b/Apps/Src/ReadCarCAN.c @@ -13,25 +13,6 @@ #include "os_cfg_app.h" #include "Display.h" -// Length of the array and motor PBC saturation buffers -#define SAT_BUF_LENGTH 5 - -// The Array/Motor Controller Saturation Threshold is used to determine if Controls has -// received a sufficient number of BPS's HV Array/Plus-Minus Enable Messages. -// BPS Array and Plus/Minus saturation threshold is halfway between 0 and max saturation value. -#define ARRAY_SATURATION_THRESHOLD (((SAT_BUF_LENGTH + 1) * SAT_BUF_LENGTH) / 4) -#define PLUS_MINUS_SATURATION_THRESHOLD (((SAT_BUF_LENGTH + 1) * SAT_BUF_LENGTH) / 4) - -// Timer delay constants -#define CAN_WATCH_TMR_DLY_MS 500u // 500 ms -#define CAN_WATCH_TMR_DLY_TMR_TS ((CAN_WATCH_TMR_DLY_MS * OS_CFG_TMR_TASK_RATE_HZ) / (1000u)) // 1000 for ms -> s conversion - -// Precharge Delay times in milliseconds -#define PRECHARGE_PLUS_MINUS_DELAY 100u // 100 ms, as this the smallest time delay that the RTOS can work with -#define PRECHARGE_ARRAY_DELAY 100u // 100 ms -#define ARRAY_PRECHARGE_BYPASS_DLY_TMR_TS ((PRECHARGE_ARRAY_DELAY * OS_CFG_TMR_TASK_RATE_HZ) / (1000u)) -#define MOTOR_CONTROLLER_PRECHARGE_BYPASS_DLY_TMR_TS ((PRECHARGE_PLUS_MINUS_DELAY * OS_CFG_TMR_TASK_RATE_HZ) / (1000u)) - // High Voltage BPS Contactor bit mapping #define HV_ARRAY_CONTACTOR_BIT 1 //0b001 #define HV_MINUS_CONTACTOR_BIT 2 //0b010 From dd36bc4d0c250415107fd860ec10e8cbd0dc4e72 Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Tue, 19 Dec 2023 00:33:33 -0600 Subject: [PATCH 17/28] fixed header comment so doxygen recognizes it --- Apps/Inc/ReadTritium.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Apps/Inc/ReadTritium.h b/Apps/Inc/ReadTritium.h index 0d1f76338..a4b16b415 100755 --- a/Apps/Inc/ReadTritium.h +++ b/Apps/Inc/ReadTritium.h @@ -1,4 +1,5 @@ -/* Copyright (c) 2021 UT Longhorn Racing Solar +/** + * @copyright Copyright (c) 2021 UT Longhorn Racing Solar * @file ReadTritium.h * @brief * From 929f2422aabc8d6ba66486d14d2e20f1aeb06348 Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Tue, 19 Dec 2023 00:37:43 -0600 Subject: [PATCH 18/28] changed lang to en --- Docs/source/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Docs/source/conf.py b/Docs/source/conf.py index a7f1f3986..7e68dec96 100644 --- a/Docs/source/conf.py +++ b/Docs/source/conf.py @@ -59,7 +59,7 @@ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = 'en' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. From a9a9b4ef2f356e7add09fa11b272b28bda9fadbf Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Tue, 19 Dec 2023 01:19:43 -0600 Subject: [PATCH 19/28] created helper script for printing all sphinx references --- Docs/print_sphinx_refs.py | 11 +++++++++++ Docs/source/conf.py | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 Docs/print_sphinx_refs.py diff --git a/Docs/print_sphinx_refs.py b/Docs/print_sphinx_refs.py new file mode 100644 index 000000000..20b8f4d36 --- /dev/null +++ b/Docs/print_sphinx_refs.py @@ -0,0 +1,11 @@ +import pickle +import os +dirname = os.path.dirname(__file__) + +envfile = open(f'{dirname}/build/doctrees/environment.pickle', 'rb') +environ = pickle.load(envfile) +elabels = environ.domaindata['std']['labels'] + +for k,v in elabels.items(): + # docname, (nodeid, title) + print(f"{k}: {v}") \ No newline at end of file diff --git a/Docs/source/conf.py b/Docs/source/conf.py index 7e68dec96..0a4b1afe7 100644 --- a/Docs/source/conf.py +++ b/Docs/source/conf.py @@ -174,7 +174,13 @@ epub_exclude_files = ['search.html'] # Breathe configurations -extensions = ['breathe'] +extensions = [ + 'breathe', + 'sphinx.ext.autosectionlabel' +] + breathe_projects = {"doxygen": "../doxygen/xml/"} breathe_default_project = "doxygen" breathe_show_define_initializer = True + +autosectionlabel_prefix_document = True \ No newline at end of file From 6c10365111d05171ef57dc23a015b0ddfc33e138 Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Tue, 19 Dec 2023 01:23:21 -0600 Subject: [PATCH 20/28] updated readtritium docs --- Docs/source/Apps/ReadTritium.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Docs/source/Apps/ReadTritium.rst b/Docs/source/Apps/ReadTritium.rst index e50be62e1..aa8d7d8d7 100644 --- a/Docs/source/Apps/ReadTritium.rst +++ b/Docs/source/Apps/ReadTritium.rst @@ -2,8 +2,8 @@ Read Tritium Task ***************** -In its current iteration, the Read Tritium task forwards all incoming messages from motor CAN to car CAN. It does this using :ref:`can-queue`: The task posts messages to the queue, which are then read out by the SendCarCAN task. +In its current iteration, the Read Tritium task forwards all incoming messages from Motor CAN to CarCAN. It does this using the FIFO defined in :doc:`SendCarCAN`: The task posts messages to the queue, which are then read out by the SendCarCAN task. .. doxygengroup:: ReadTritium :project: doxygen - :path: "/doxygen/xml/group__ReadTritium.xml" + :path: "/doxygen/xml/group__ReadTritium.xml" \ No newline at end of file From 96aab882b32d89af3285694d09cbc14495589538 Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Tue, 19 Dec 2023 01:39:22 -0600 Subject: [PATCH 21/28] updated Minions.rst --- Docs/source/Drivers/Minions.rst | 43 ++++++--------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/Docs/source/Drivers/Minions.rst b/Docs/source/Drivers/Minions.rst index 2192af7c6..270895914 100644 --- a/Docs/source/Drivers/Minions.rst +++ b/Docs/source/Drivers/Minions.rst @@ -1,46 +1,19 @@ -.. _minions-driver: - -.. _minion: - ************** Minions Driver ************** -The Minions driver is responsible for all lights and switches in the system, and in particular those that are present on the minion board. The driver implements the SPI protocol necessary to talk to the GPIO expander on the minion board. The driver exposes the following public interface: - -The driver defines two enums: ``switches_t`` and ``light_t``. The former is used to distinguish switches in function calls, and the latter is the same for the lights. The exct enum values can be found in ``Drivers/Inc/Minions.h``. - -The following public functions use these types heavily. - -``void Minions_Init(void)`` — Creates a mutex to ensure that SPI access are thread-safe. Initializes SPI, as well as calling private functions to initialize both the lights and the switches seperately. Finally, the function sets up a filter to make switch readings more reliable over SPI. See :ref:`minions-impl` for more information about the filter. - -``State Switches_Read(switches_t sw)`` — Reads the state of the given switch as stored in the driver. This does *not* query the hardware. - -``State Lights_Read(light_t light)`` — Reads the state of the given light as stored in the driver. This does *not* query the hardware. - -``void Switches_UpdateStates(void)`` — Queries GPIO pins and SPI to get the most up-to-date switch states. This function acquires the mutex to ensure that it is thread-safe. It also uses the filter (see :ref:`minions-impl`) to ensure that that switches connected over SPI return stable values. This function should be called fairly often (currently called every 10 ms) in order to make sure that we always have the most recent switch states stored by the driver. - -``void Lights_Set(light_t light, State state)`` - -``uint16_t Lights_Bitmap_Read(void)`` — Returns a bitmap of light values, as stored by the driver. The least significant bit corresponds to a ``light_t`` value of zero. - -``void Lights_Toggle(light_t light)`` — Toggles the given light. - -``void Lights_Toggle_Set(light_t light, State state)`` — Set a specific light in the internal toggle bitmaps. This is used for lights that need to be toggled often, but can be easily extended in the future if necessary. - -``State Lights_Toggle_Read(light_t light)`` — Reads the state of the internal toggle bitmap for the given light. This simplifies application-level toggling logic greatly. - -``uint8_t Lights_Toggle_Bitmap_Read(void)`` — Returns the full internal toggle bitmap. This isn't used by any application code right now, but it might find some use in the future. - - -.. _minions-impl: +The Minions driver is responsible for most of the lights and switches in the system, and in particular those that are present on the Controls Lighting board. The driver uses GPIO to set/read pins on the MCU, which in turn are connected to the Lighting Board. Implementation Details ====================== -Some of the switches and lights are connected through GPIO. These are the ignition switch, the headlights, and the external blinkers. The rest of the lights and switches are on the minion board and connected through SPI. **NOTE: CURRENTLY, THE LIGHTS ON THE MINON BOARD ARE NON-FUNCTIONAL; THEY'RE SHOWN ON THE DISPLAY INSTEAD. THE SPI COMMANDS ARE STILL SENT, HOWEVER.** - -The minion board is placed far away from the Controls leaderboard. As such, the SPI wires connecting the two are unusually long. This results in quite a bit of interference, which makes the lights on the minion board quite unreliable. The switches still work reliably due to the median filter used. The median filter keeps the last ten samples for each switch, and uses the median (since a switch is either on or off, this is equivalent to a majority check i.e. do we have more ones or more zeros) to determine the used state for each switch. This filter will hopefully be made redundant by a hardware redesign of the minon board to leaderboard connection. +All of the switches and lights that are controllable via software are connected through GPIO. These include: +* Ignition Switch 1 & 2 (ARR_ON and MOTOR_ON) +* Regen Enable Button +* Gear Switch (Forward and Reverse) (note: if both Forward and Reverse are off, the gear switch is assumed to be in Neutral state) +* Cruise Enable Button +* Cruise Set Button +* Brakelight .. doxygengroup:: Minions :project: doxygen From bf453fa19d5fd598115f8ee3b23c359b4c52778b Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Tue, 19 Dec 2023 17:43:40 -0600 Subject: [PATCH 22/28] Revert mistakenly pushed docs commits. Revert "updated Minions.rst" This reverts commit 96aab882b32d89af3285694d09cbc14495589538. Revert "updated readtritium docs" This reverts commit 6c10365111d05171ef57dc23a015b0ddfc33e138. Revert "created helper script for printing all sphinx references" This reverts commit a9a9b4ef2f356e7add09fa11b272b28bda9fadbf. Revert "changed lang to en" This reverts commit 929f2422aabc8d6ba66486d14d2e20f1aeb06348. Revert "fixed header comment so doxygen recognizes it" This reverts commit dd36bc4d0c250415107fd860ec10e8cbd0dc4e72. Revert "moved macros from ReadCarCAN.c to ReadCarCAN.h so they are visible in docs" This reverts commit 47d011fce97f467f3c6e5cd5fd2c4bc009a1bb95. --- Apps/Inc/ReadCarCAN.h | 19 -------------- Apps/Inc/ReadTritium.h | 3 +-- Apps/Src/ReadCarCAN.c | 19 ++++++++++++++ Docs/print_sphinx_refs.py | 11 -------- Docs/source/Apps/ReadTritium.rst | 4 +-- Docs/source/Drivers/Minions.rst | 43 ++++++++++++++++++++++++++------ Docs/source/conf.py | 10 ++------ 7 files changed, 59 insertions(+), 50 deletions(-) delete mode 100644 Docs/print_sphinx_refs.py diff --git a/Apps/Inc/ReadCarCAN.h b/Apps/Inc/ReadCarCAN.h index 39ba3df91..a082bf312 100644 --- a/Apps/Inc/ReadCarCAN.h +++ b/Apps/Inc/ReadCarCAN.h @@ -16,25 +16,6 @@ #include "Tasks.h" #include "CANbus.h" -// Length of the array and motor PBC saturation buffers -#define SAT_BUF_LENGTH 5 - -// The Array/Motor Controller Saturation Threshold is used to determine if Controls has -// received a sufficient number of BPS's HV Array/Plus-Minus Enable Messages. -// BPS Array and Plus/Minus saturation threshold is halfway between 0 and max saturation value. -#define ARRAY_SATURATION_THRESHOLD (((SAT_BUF_LENGTH + 1) * SAT_BUF_LENGTH) / 4) -#define PLUS_MINUS_SATURATION_THRESHOLD (((SAT_BUF_LENGTH + 1) * SAT_BUF_LENGTH) / 4) - -// Timer delay constants -#define CAN_WATCH_TMR_DLY_MS 500u // 500 ms -#define CAN_WATCH_TMR_DLY_TMR_TS ((CAN_WATCH_TMR_DLY_MS * OS_CFG_TMR_TASK_RATE_HZ) / (1000u)) // 1000 for ms -> s conversion - -// Precharge Delay times in milliseconds -#define PRECHARGE_PLUS_MINUS_DELAY 100u // 100 ms, as this the smallest time delay that the RTOS can work with -#define PRECHARGE_ARRAY_DELAY 100u // 100 ms -#define ARRAY_PRECHARGE_BYPASS_DLY_TMR_TS ((PRECHARGE_ARRAY_DELAY * OS_CFG_TMR_TASK_RATE_HZ) / (1000u)) -#define MOTOR_CONTROLLER_PRECHARGE_BYPASS_DLY_TMR_TS ((PRECHARGE_PLUS_MINUS_DELAY * OS_CFG_TMR_TASK_RATE_HZ) / (1000u)) - /** * Error types */ diff --git a/Apps/Inc/ReadTritium.h b/Apps/Inc/ReadTritium.h index a4b16b415..0d1f76338 100755 --- a/Apps/Inc/ReadTritium.h +++ b/Apps/Inc/ReadTritium.h @@ -1,5 +1,4 @@ -/** - * @copyright Copyright (c) 2021 UT Longhorn Racing Solar +/* Copyright (c) 2021 UT Longhorn Racing Solar * @file ReadTritium.h * @brief * diff --git a/Apps/Src/ReadCarCAN.c b/Apps/Src/ReadCarCAN.c index b51f9bb0d..64897dd4b 100644 --- a/Apps/Src/ReadCarCAN.c +++ b/Apps/Src/ReadCarCAN.c @@ -13,6 +13,25 @@ #include "os_cfg_app.h" #include "Display.h" +// Length of the array and motor PBC saturation buffers +#define SAT_BUF_LENGTH 5 + +// The Array/Motor Controller Saturation Threshold is used to determine if Controls has +// received a sufficient number of BPS's HV Array/Plus-Minus Enable Messages. +// BPS Array and Plus/Minus saturation threshold is halfway between 0 and max saturation value. +#define ARRAY_SATURATION_THRESHOLD (((SAT_BUF_LENGTH + 1) * SAT_BUF_LENGTH) / 4) +#define PLUS_MINUS_SATURATION_THRESHOLD (((SAT_BUF_LENGTH + 1) * SAT_BUF_LENGTH) / 4) + +// Timer delay constants +#define CAN_WATCH_TMR_DLY_MS 500u // 500 ms +#define CAN_WATCH_TMR_DLY_TMR_TS ((CAN_WATCH_TMR_DLY_MS * OS_CFG_TMR_TASK_RATE_HZ) / (1000u)) // 1000 for ms -> s conversion + +// Precharge Delay times in milliseconds +#define PRECHARGE_PLUS_MINUS_DELAY 100u // 100 ms, as this the smallest time delay that the RTOS can work with +#define PRECHARGE_ARRAY_DELAY 100u // 100 ms +#define ARRAY_PRECHARGE_BYPASS_DLY_TMR_TS ((PRECHARGE_ARRAY_DELAY * OS_CFG_TMR_TASK_RATE_HZ) / (1000u)) +#define MOTOR_CONTROLLER_PRECHARGE_BYPASS_DLY_TMR_TS ((PRECHARGE_PLUS_MINUS_DELAY * OS_CFG_TMR_TASK_RATE_HZ) / (1000u)) + // High Voltage BPS Contactor bit mapping #define HV_ARRAY_CONTACTOR_BIT 1 //0b001 #define HV_MINUS_CONTACTOR_BIT 2 //0b010 diff --git a/Docs/print_sphinx_refs.py b/Docs/print_sphinx_refs.py deleted file mode 100644 index 20b8f4d36..000000000 --- a/Docs/print_sphinx_refs.py +++ /dev/null @@ -1,11 +0,0 @@ -import pickle -import os -dirname = os.path.dirname(__file__) - -envfile = open(f'{dirname}/build/doctrees/environment.pickle', 'rb') -environ = pickle.load(envfile) -elabels = environ.domaindata['std']['labels'] - -for k,v in elabels.items(): - # docname, (nodeid, title) - print(f"{k}: {v}") \ No newline at end of file diff --git a/Docs/source/Apps/ReadTritium.rst b/Docs/source/Apps/ReadTritium.rst index aa8d7d8d7..e50be62e1 100644 --- a/Docs/source/Apps/ReadTritium.rst +++ b/Docs/source/Apps/ReadTritium.rst @@ -2,8 +2,8 @@ Read Tritium Task ***************** -In its current iteration, the Read Tritium task forwards all incoming messages from Motor CAN to CarCAN. It does this using the FIFO defined in :doc:`SendCarCAN`: The task posts messages to the queue, which are then read out by the SendCarCAN task. +In its current iteration, the Read Tritium task forwards all incoming messages from motor CAN to car CAN. It does this using :ref:`can-queue`: The task posts messages to the queue, which are then read out by the SendCarCAN task. .. doxygengroup:: ReadTritium :project: doxygen - :path: "/doxygen/xml/group__ReadTritium.xml" \ No newline at end of file + :path: "/doxygen/xml/group__ReadTritium.xml" diff --git a/Docs/source/Drivers/Minions.rst b/Docs/source/Drivers/Minions.rst index 270895914..2192af7c6 100644 --- a/Docs/source/Drivers/Minions.rst +++ b/Docs/source/Drivers/Minions.rst @@ -1,19 +1,46 @@ +.. _minions-driver: + +.. _minion: + ************** Minions Driver ************** -The Minions driver is responsible for most of the lights and switches in the system, and in particular those that are present on the Controls Lighting board. The driver uses GPIO to set/read pins on the MCU, which in turn are connected to the Lighting Board. +The Minions driver is responsible for all lights and switches in the system, and in particular those that are present on the minion board. The driver implements the SPI protocol necessary to talk to the GPIO expander on the minion board. The driver exposes the following public interface: + +The driver defines two enums: ``switches_t`` and ``light_t``. The former is used to distinguish switches in function calls, and the latter is the same for the lights. The exct enum values can be found in ``Drivers/Inc/Minions.h``. + +The following public functions use these types heavily. + +``void Minions_Init(void)`` — Creates a mutex to ensure that SPI access are thread-safe. Initializes SPI, as well as calling private functions to initialize both the lights and the switches seperately. Finally, the function sets up a filter to make switch readings more reliable over SPI. See :ref:`minions-impl` for more information about the filter. + +``State Switches_Read(switches_t sw)`` — Reads the state of the given switch as stored in the driver. This does *not* query the hardware. + +``State Lights_Read(light_t light)`` — Reads the state of the given light as stored in the driver. This does *not* query the hardware. + +``void Switches_UpdateStates(void)`` — Queries GPIO pins and SPI to get the most up-to-date switch states. This function acquires the mutex to ensure that it is thread-safe. It also uses the filter (see :ref:`minions-impl`) to ensure that that switches connected over SPI return stable values. This function should be called fairly often (currently called every 10 ms) in order to make sure that we always have the most recent switch states stored by the driver. + +``void Lights_Set(light_t light, State state)`` + +``uint16_t Lights_Bitmap_Read(void)`` — Returns a bitmap of light values, as stored by the driver. The least significant bit corresponds to a ``light_t`` value of zero. + +``void Lights_Toggle(light_t light)`` — Toggles the given light. + +``void Lights_Toggle_Set(light_t light, State state)`` — Set a specific light in the internal toggle bitmaps. This is used for lights that need to be toggled often, but can be easily extended in the future if necessary. + +``State Lights_Toggle_Read(light_t light)`` — Reads the state of the internal toggle bitmap for the given light. This simplifies application-level toggling logic greatly. + +``uint8_t Lights_Toggle_Bitmap_Read(void)`` — Returns the full internal toggle bitmap. This isn't used by any application code right now, but it might find some use in the future. + + +.. _minions-impl: Implementation Details ====================== -All of the switches and lights that are controllable via software are connected through GPIO. These include: -* Ignition Switch 1 & 2 (ARR_ON and MOTOR_ON) -* Regen Enable Button -* Gear Switch (Forward and Reverse) (note: if both Forward and Reverse are off, the gear switch is assumed to be in Neutral state) -* Cruise Enable Button -* Cruise Set Button -* Brakelight +Some of the switches and lights are connected through GPIO. These are the ignition switch, the headlights, and the external blinkers. The rest of the lights and switches are on the minion board and connected through SPI. **NOTE: CURRENTLY, THE LIGHTS ON THE MINON BOARD ARE NON-FUNCTIONAL; THEY'RE SHOWN ON THE DISPLAY INSTEAD. THE SPI COMMANDS ARE STILL SENT, HOWEVER.** + +The minion board is placed far away from the Controls leaderboard. As such, the SPI wires connecting the two are unusually long. This results in quite a bit of interference, which makes the lights on the minion board quite unreliable. The switches still work reliably due to the median filter used. The median filter keeps the last ten samples for each switch, and uses the median (since a switch is either on or off, this is equivalent to a majority check i.e. do we have more ones or more zeros) to determine the used state for each switch. This filter will hopefully be made redundant by a hardware redesign of the minon board to leaderboard connection. .. doxygengroup:: Minions :project: doxygen diff --git a/Docs/source/conf.py b/Docs/source/conf.py index 0a4b1afe7..a7f1f3986 100644 --- a/Docs/source/conf.py +++ b/Docs/source/conf.py @@ -59,7 +59,7 @@ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = 'en' +language = None # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -174,13 +174,7 @@ epub_exclude_files = ['search.html'] # Breathe configurations -extensions = [ - 'breathe', - 'sphinx.ext.autosectionlabel' -] - +extensions = ['breathe'] breathe_projects = {"doxygen": "../doxygen/xml/"} breathe_default_project = "doxygen" breathe_show_define_initializer = True - -autosectionlabel_prefix_document = True \ No newline at end of file From 9c2e234877b279313856c80e6e34c7c54faf8f0a Mon Sep 17 00:00:00 2001 From: Nathaniel Delgado Date: Wed, 27 Dec 2023 01:44:02 -0600 Subject: [PATCH 23/28] Removed redundant code --- Apps/Inc/fifo.h | 2 -- Apps/Src/ReadTritium.c | 1 - Tests/Test_TrailingZeros.c | 34 ---------------------------------- 3 files changed, 37 deletions(-) delete mode 100644 Tests/Test_TrailingZeros.c diff --git a/Apps/Inc/fifo.h b/Apps/Inc/fifo.h index 2431d1d0e..2f821c91d 100644 --- a/Apps/Inc/fifo.h +++ b/Apps/Inc/fifo.h @@ -42,8 +42,6 @@ #ifndef __FIFO_H #define __FIFO_H #include -#include -#include "common.h" #endif // The type of the fifo diff --git a/Apps/Src/ReadTritium.c b/Apps/Src/ReadTritium.c index bd896a7dd..23e27dbe1 100755 --- a/Apps/Src/ReadTritium.c +++ b/Apps/Src/ReadTritium.c @@ -9,7 +9,6 @@ #include "CANbus.h" #include "UpdateDisplay.h" #include "SendCarCAN.h" -#include "SendCarCAN.h" #include "os_cfg_app.h" #include diff --git a/Tests/Test_TrailingZeros.c b/Tests/Test_TrailingZeros.c deleted file mode 100644 index 732a6e698..000000000 --- a/Tests/Test_TrailingZeros.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * C Program to Count the Number of Trailing Zeroes in Integer - */ -#include "common.h" -#include "config.h" -#include - -int main() -{ - BSP_UART_Init(UART_2); - - int count = 0; - unsigned int num; - - num = 176; - while (num != 0) - { - if ((num & 1) == 1) - { - break; - } - else - { - count++; - num = num >> 1; - - } - } - printf("\n%d", count); - - while(1); - - return 0; -} \ No newline at end of file From 2bf5ea54c0f3376165b4ebecc028e4ea19ccfe6c Mon Sep 17 00:00:00 2001 From: Ishan Deshpande Date: Sun, 31 Dec 2023 18:39:19 -0600 Subject: [PATCH 24/28] Apply suggestions from code review Co-authored-by: Diya Rajon <45317290+diyarajon@users.noreply.github.com> Co-authored-by: Madeleine Lee <74027612+KnockbackNemo@users.noreply.github.com> --- Apps/Inc/SendTritium.h | 4 ++-- Apps/Src/ReadTritium.c | 3 +-- Apps/Src/SendCarCAN.c | 3 --- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Apps/Inc/SendTritium.h b/Apps/Inc/SendTritium.h index c4cd03851..8791f3833 100644 --- a/Apps/Inc/SendTritium.h +++ b/Apps/Inc/SendTritium.h @@ -14,8 +14,8 @@ //#define SENDTRITIUM_PRINT_MES -#define MOTOR_MSG_PERIOD 100 -#define FSM_PERIOD 100 +#define MOTOR_MSG_PERIOD 100 // in ms +#define FSM_PERIOD 100 // in ms #define DEBOUNCE_PERIOD 2 // in units of FSM_PERIOD #define MOTOR_MSG_COUNTER_THRESHOLD (MOTOR_MSG_PERIOD)/(FSM_PERIOD) diff --git a/Apps/Src/ReadTritium.c b/Apps/Src/ReadTritium.c index 23e27dbe1..6b1055ce6 100755 --- a/Apps/Src/ReadTritium.c +++ b/Apps/Src/ReadTritium.c @@ -40,14 +40,13 @@ void Task_ReadTritium(void *p_arg){ OS_ERR err; CANDATA_t dataBuf = {0}; - // Timer doesn't seem to trigger without initial delay? Might be an RTOS bug static bool watchdogCreated = false; while (1){ ErrorStatus status = CANbus_Read(&dataBuf, true, MOTORCAN); if (status == SUCCESS){ - if(!watchdogCreated){ + if(!watchdogCreated){ // Timer doesn't seem to trigger without initial delay? Might be an RTOS bug OSTmrCreate(&MotorWatchdog, "Motor watchdog", MOTOR_TIMEOUT_TICKS, MOTOR_TIMEOUT_TICKS, OS_OPT_TMR_PERIODIC, motorWatchdog, NULL, &err); assertOSError(err); diff --git a/Apps/Src/SendCarCAN.c b/Apps/Src/SendCarCAN.c index e28191ab7..06e3083ed 100644 --- a/Apps/Src/SendCarCAN.c +++ b/Apps/Src/SendCarCAN.c @@ -2,12 +2,9 @@ * @copyright Copyright (c) 2018-2023 UT Longhorn Racing Solar * @file SendCarCAN.c * @brief Function implementations for the SendCarCAN application. - * @brief Function implementations for the SendCarCAN application. * * This contains functions relevant to placing CAN messages in a CarCAN queue and periodically sending * those messages in the SendCarCAN task. - * This contains functions relevant to placing CAN messages in a CarCAN queue and periodically sending - * those messages in the SendCarCAN task. * */ From c6c4cf16ce1965f04199b907c4c00a97ac8f4520 Mon Sep 17 00:00:00 2001 From: Ishan Deshpande Date: Sun, 31 Dec 2023 21:15:59 -0600 Subject: [PATCH 25/28] Feature/GitHub workflow fix (#396) * Changed github actions workflow to use install script from Embedded-Sharepoint * initialize submodules before install tools * fixed directory * changed flags * changed the target that is the phony so that later we could add additional targets and change what 'leader' points to --- .github/workflows/c-cpp.yml | 10 +++++----- Makefile | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index d031e92a0..2c1b365dd 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -11,13 +11,13 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Initialize Submodules + run: git submodule update --init --recursive - name: Install tools run: | + ./Embedded-Sharepoint/Scripts/install.sh -i sudo apt -y update - sudo apt -y install gcc-arm-none-eabi - - name: Initialize Submodules - run: git submodule update --init --recursive - name: clean run: make clean - - name: make stm32f413 - run: make stm32f413 + - name: make leader + run: make leader diff --git a/Makefile b/Makefile index afea3bbe3..3a5cc919e 100644 --- a/Makefile +++ b/Makefile @@ -29,10 +29,10 @@ LEADER = controls-leader all: @echo "${RED}Not enough arguments. Call: ${ORANGE}make help${NC}" -.PHONY: stm32f413 -stm32f413: leader +.PHONY: leader +leader: stm32f413 -leader: +stm32f413: @echo "${YELLOW}Compiling for leader...${NC}" $(MAKE) -C BSP -C STM32F413 -j TARGET=$(LEADER) TEST=$(TEST_LEADER) @echo "${BLUE}Compiled for leader! Jolly Good!${NC}" From 3f208131e928d962dd3ff5bfb2aa3ca5ffd95e3d Mon Sep 17 00:00:00 2001 From: IshDeshpa Date: Sun, 31 Dec 2023 21:43:46 -0600 Subject: [PATCH 26/28] addressed more review comments --- Apps/Src/SendCarCAN.c | 4 +++- Apps/Src/SendTritium.c | 2 ++ Apps/Src/Tasks.c | 4 +--- Drivers/Inc/CANConfig.h | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Apps/Src/SendCarCAN.c b/Apps/Src/SendCarCAN.c index 06e3083ed..7a11c2020 100644 --- a/Apps/Src/SendCarCAN.c +++ b/Apps/Src/SendCarCAN.c @@ -20,6 +20,8 @@ #define IO_STATE_DLY_MS 250u +#define SENDCARCAN_MSG_SKIP_CTR 3 + // Task_PutIOState OS_TCB putIOState_TCB; CPU_STK putIOState_Stk[TASK_SEND_CAR_CAN_STACK_SIZE]; @@ -56,7 +58,7 @@ void SendCarCAN_Put(CANDATA_t message){ static uint8_t carcan_ctr = 0; - if(carcan_ctr > 3){ + if(carcan_ctr > SENDCARCAN_MSG_SKIP_CTR){ OSMutexPend(&CarCAN_Mtx, 0, OS_OPT_PEND_BLOCKING, &ticks, &err); assertOSError(err); diff --git a/Apps/Src/SendTritium.c b/Apps/Src/SendTritium.c index db0865908..9f6f85307 100644 --- a/Apps/Src/SendTritium.c +++ b/Apps/Src/SendTritium.c @@ -665,6 +665,8 @@ void Task_SendTritium(void *p_arg){ #endif state.stateDecider(); // decide what the next state is + // Disable velocity controlled mode by always overwriting velocity to the maximum + // in the appropriate direction. velocitySetpoint = (velocitySetpoint>0)?MAX_VELOCITY:-MAX_VELOCITY; // Drive diff --git a/Apps/Src/Tasks.c b/Apps/Src/Tasks.c index d68e85e00..af6382e1d 100644 --- a/Apps/Src/Tasks.c +++ b/Apps/Src/Tasks.c @@ -54,13 +54,12 @@ extern const pinInfo_t PININFO_LUT[]; // For GPIO writes. Externed from Minions * Error assertion-related functions */ -void _assertOSError(volatile OS_ERR err) +void _assertOSError(OS_ERR err) { if (err != OS_ERR_NONE) { EmergencyContactorOpen(); // Turn off contactors and turn on the brakelight to indicate an emergency Display_Error(err); // Display the location and error code - printf("%d\n\r", err); while(1){;} //nonrecoverable } } @@ -90,7 +89,6 @@ void throwTaskError(error_code_t errorCode, callback_t errorCallback, error_sche EmergencyContactorOpen(); Display_Error(errorCode); // Needs to happen before callback so that tasks can change the screen // (ex: readCarCAN and evac screen for BPS trip) - printf("%d\n\r", errorCode); UpdateDisplay_ClearQueue(); // Clear message queue to ensure no other commands overwrite the error screen } diff --git a/Drivers/Inc/CANConfig.h b/Drivers/Inc/CANConfig.h index 22c1f4577..0035e2f37 100644 --- a/Drivers/Inc/CANConfig.h +++ b/Drivers/Inc/CANConfig.h @@ -14,7 +14,7 @@ /** * Filter Lists for CarCAN and MotorCAN */ -#define NUM_CARCAN_FILTERS 6 +#define NUM_CARCAN_FILTERS 4 #define NUM_MOTORCAN_FILTERS 7 extern CANId_t carCANFilterList[NUM_CARCAN_FILTERS]; extern CANId_t motorCANFilterList[NUM_MOTORCAN_FILTERS]; From 5b7314b8318672f3b4397175fdfaa07d367a4750 Mon Sep 17 00:00:00 2001 From: Ishan Deshpande Date: Mon, 1 Jan 2024 23:51:52 -0600 Subject: [PATCH 27/28] Apply suggestions from code review Co-authored-by: Madeleine Lee <74027612+KnockbackNemo@users.noreply.github.com> --- Apps/Src/SendCarCAN.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Apps/Src/SendCarCAN.c b/Apps/Src/SendCarCAN.c index 7a11c2020..8c35cb843 100644 --- a/Apps/Src/SendCarCAN.c +++ b/Apps/Src/SendCarCAN.c @@ -52,7 +52,7 @@ uint8_t get_SendCarCAN_Q_Space(void) { * @brief Wrapper to put new message in the CAN queue */ void SendCarCAN_Put(CANDATA_t message){ - OS_ERR err = OS_ERR_NONE; + OS_ERR err; CPU_TS ticks; bool success = false; @@ -72,8 +72,10 @@ void SendCarCAN_Put(CANDATA_t message){ carcan_ctr++; - if(success) OSSemPost(&CarCAN_Sem4, OS_OPT_POST_1, &err); - assertOSError(err); + if(success) { + OSSemPost(&CarCAN_Sem4, OS_OPT_POST_1, &err); + assertOSError(err); + } } /** From 0b55f3930a61eeb784e523edff712a70622363ef Mon Sep 17 00:00:00 2001 From: Ishan Deshpande Date: Tue, 2 Jan 2024 13:58:08 -0600 Subject: [PATCH 28/28] Apply suggestions from code review Co-authored-by: Diya Rajon <45317290+diyarajon@users.noreply.github.com> --- Apps/Src/SendCarCAN.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Apps/Src/SendCarCAN.c b/Apps/Src/SendCarCAN.c index 8c35cb843..0272b8b6d 100644 --- a/Apps/Src/SendCarCAN.c +++ b/Apps/Src/SendCarCAN.c @@ -174,5 +174,6 @@ static void Task_PutIOState(void *p_arg) { while (1) { putIOState(); OSTimeDlyHMSM(0, 0, 0, IO_STATE_DLY_MS, OS_OPT_TIME_HMSM_STRICT, &err); + assertOSError(err); } }