From 5998ab9cfc6cfe39c40d9d6c9e239be139aae91f Mon Sep 17 00:00:00 2001 From: bjackson312006 Date: Sat, 23 Nov 2024 15:05:41 -0500 Subject: [PATCH 1/6] Added CAN messages for timer start/stop --- Core/Inc/can_handler.h | 3 ++- Core/Src/compute.c | 23 +++++++++++++++++++++++ Core/Src/stateMachine.c | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Core/Inc/can_handler.h b/Core/Inc/can_handler.h index 02c0b80..cb427b3 100644 --- a/Core/Inc/can_handler.h +++ b/Core/Inc/can_handler.h @@ -45,7 +45,8 @@ typedef enum { FAULT, NOISE, DEBUG, - RL_MSG_COUNT + RL_MSG_COUNT, + FAULT_TIMER } rate_lim_t; void can_receive_callback(CAN_HandleTypeDef *hcan); diff --git a/Core/Src/compute.c b/Core/Src/compute.c index 022c1ac..3495908 100644 --- a/Core/Src/compute.c +++ b/Core/Src/compute.c @@ -535,6 +535,29 @@ void compute_send_fault_message(uint8_t status, int16_t curr, int16_t in_dcl) queue_can_msg(bms_can_msgs[FAULT]); } +void compute_send_fault_timer_message(uint8_t start_or_stop, uint16_t fault_code, uint16_t value) +{ + struct __attribute__((__packed__)) { + uint8_t start_or_stop; + int16_t fault_code; + int16_t value; + } fault_timer_msg_data; + + fault_timer_msg_data.start_or_stop = start_or_stop; + fault_timer_msg_data.fault_code = fault_code; + fault_timer_msg_data.value = value; + + endian_swap(&fault_timer_msg_data.fault_code, + sizeof(fault_timer_msg_data.fault_code)); + endian_swap(&fault_timer_msg_data.value, sizeof(fault_timer_msg_data.value)); + + memcpy(bms_can_msgs[FAULT_TIMER].data, &fault_timer_msg_data, + sizeof(fault_timer_msg_data)); + + queue_can_msg(bms_can_msgs[FAULT_TIMER]); + +} + void compute_send_voltage_noise_message(acc_data_t *bmsdata) { struct __attribute__((__packed__)) { diff --git a/Core/Src/stateMachine.c b/Core/Src/stateMachine.c index e59f0a2..2aabb9c 100644 --- a/Core/Src/stateMachine.c +++ b/Core/Src/stateMachine.c @@ -303,6 +303,7 @@ uint32_t sm_fault_eval(fault_eval_t *index) if (!fault_present) { printf("\t\t\t*******Fault cleared: %s\r\n", index->id); cancel_timer(&index->timer); + compute_send_fault_timer_message(0, index->code, index->data_1); return 0; } @@ -321,6 +322,7 @@ uint32_t sm_fault_eval(fault_eval_t *index) else if (!is_timer_active(&index->timer) && fault_present) { printf("\t\t\t*******Starting fault timer: %s\r\n", index->id); start_timer(&index->timer, index->timeout); + compute_send_fault_timer_message(1, index->code, index->data_1); if (index->code == DISCHARGE_LIMIT_ENFORCEMENT_FAULT) { compute_send_fault_message(1, index->data_1, index->lim_1); From 10cbb651bddf96abf78c1b9404e19f72987ee4a9 Mon Sep 17 00:00:00 2001 From: bjackson312006 Date: Wed, 27 Nov 2024 19:46:20 -0500 Subject: [PATCH 2/6] Added CAN message for fault timers --- Core/Inc/can_handler.h | 5 +++-- Core/Inc/compute.h | 3 +++ Core/Src/can_handler.c | 8 ++++++++ Core/Src/compute.c | 17 +++++++++-------- Drivers/Embedded-Base | 2 +- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Core/Inc/can_handler.h b/Core/Inc/can_handler.h index cb427b3..6396a16 100644 --- a/Core/Inc/can_handler.h +++ b/Core/Inc/can_handler.h @@ -25,6 +25,7 @@ #define FAULT_CANID 0x703 #define NOISE_CANID 0x88 #define DEBUG_CANID 0x702 +#define FAULT_TIMER_CANID 0x701 typedef struct { uint32_t prev_tick; @@ -45,8 +46,8 @@ typedef enum { FAULT, NOISE, DEBUG, - RL_MSG_COUNT, - FAULT_TIMER + FAULT_TIMER, + RL_MSG_COUNT } rate_lim_t; void can_receive_callback(CAN_HandleTypeDef *hcan); diff --git a/Core/Inc/compute.h b/Core/Inc/compute.h index 176da20..03e0268 100644 --- a/Core/Inc/compute.h +++ b/Core/Inc/compute.h @@ -185,6 +185,9 @@ void compute_send_segment_temp_message(acc_data_t *bmsdata); void compute_send_fault_message(uint8_t status, int16_t curr, int16_t in_dcl); +void compute_send_fault_timer_message(uint8_t start_stop, uint16_t fault_code, + uint16_t data_1); + /** * @brief Send CAN message for debugging the car on the fly. * diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c index 0725ac0..745dc5a 100644 --- a/Core/Src/can_handler.c +++ b/Core/Src/can_handler.c @@ -96,6 +96,10 @@ void init_can_msg_config() debug_msg.id = DEBUG_CANID; debug_msg.len = 8; // yaml decodes this to 8 bytes + can_msg_t fault_timer_msg; + fault_timer_msg.id = FAULT_TIMER_CANID; + fault_timer_msg.len = 5; + // rl_data_t rl_discharge_data = { .msg_rate = 5000 }; // rl_data_t rl_charge_data = { .msg_rate = 0 }; @@ -112,6 +116,7 @@ void init_can_msg_config() bms_can_msgs[FAULT] = fault_msg; bms_can_msgs[NOISE] = noise_msg; bms_can_msgs[DEBUG] = debug_msg; + bms_can_msgs[FAULT_TIMER] = fault_timer_msg; // rl_data[DISCHARGE] = rl_discharge_data; // rl_data[CHARGE] = rl_charge_data; @@ -159,6 +164,9 @@ rl_data_t *get_rl_msg(uint32_t can_id) case DEBUG_CANID: return &rl_data[DEBUG]; break; + case FAULT_TIMER_CANID: + return &rl_data[FAULT_TIMER]; + break; default: break; } diff --git a/Core/Src/compute.c b/Core/Src/compute.c index 3495908..17f7243 100644 --- a/Core/Src/compute.c +++ b/Core/Src/compute.c @@ -535,27 +535,28 @@ void compute_send_fault_message(uint8_t status, int16_t curr, int16_t in_dcl) queue_can_msg(bms_can_msgs[FAULT]); } -void compute_send_fault_timer_message(uint8_t start_or_stop, uint16_t fault_code, uint16_t value) +void compute_send_fault_timer_message(uint8_t start_stop, uint16_t fault_code, + uint16_t data_1) { struct __attribute__((__packed__)) { - uint8_t start_or_stop; - int16_t fault_code; - int16_t value; + uint8_t start_stop; + uint16_t fault_code; + int16_t data_1; } fault_timer_msg_data; - fault_timer_msg_data.start_or_stop = start_or_stop; + fault_timer_msg_data.start_stop = start_stop; fault_timer_msg_data.fault_code = fault_code; - fault_timer_msg_data.value = value; + fault_timer_msg_data.data_1 = data_1; endian_swap(&fault_timer_msg_data.fault_code, sizeof(fault_timer_msg_data.fault_code)); - endian_swap(&fault_timer_msg_data.value, sizeof(fault_timer_msg_data.value)); + endian_swap(&fault_timer_msg_data.data_1, + sizeof(fault_timer_msg_data.data_1)); memcpy(bms_can_msgs[FAULT_TIMER].data, &fault_timer_msg_data, sizeof(fault_timer_msg_data)); queue_can_msg(bms_can_msgs[FAULT_TIMER]); - } void compute_send_voltage_noise_message(acc_data_t *bmsdata) diff --git a/Drivers/Embedded-Base b/Drivers/Embedded-Base index 8325863..970cceb 160000 --- a/Drivers/Embedded-Base +++ b/Drivers/Embedded-Base @@ -1 +1 @@ -Subproject commit 83258635fc749ac72adb4b52e61f4f1a42e1842f +Subproject commit 970cceb6d6589c23d21ff6e3d2c29696973902ff From c55fc7bf64a6d5ee48a529fd2c4612600bba8ece Mon Sep 17 00:00:00 2001 From: bjackson312006 Date: Wed, 27 Nov 2024 19:51:51 -0500 Subject: [PATCH 3/6] Formatting --- Core/Src/stateMachine.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/Src/stateMachine.c b/Core/Src/stateMachine.c index 2aabb9c..647bae8 100644 --- a/Core/Src/stateMachine.c +++ b/Core/Src/stateMachine.c @@ -303,7 +303,8 @@ uint32_t sm_fault_eval(fault_eval_t *index) if (!fault_present) { printf("\t\t\t*******Fault cleared: %s\r\n", index->id); cancel_timer(&index->timer); - compute_send_fault_timer_message(0, index->code, index->data_1); + compute_send_fault_timer_message(0, index->code, + index->data_1); return 0; } From 925ccc8551b753d2a3e1bb73f40efd0141d8965c Mon Sep 17 00:00:00 2001 From: bjackson312006 Date: Sat, 30 Nov 2024 00:11:18 -0500 Subject: [PATCH 4/6] Changed format of fault timer CAN --- Core/Inc/compute.h | 2 +- Core/Src/can_handler.c | 2 +- Core/Src/compute.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Core/Inc/compute.h b/Core/Inc/compute.h index 03e0268..269806b 100644 --- a/Core/Inc/compute.h +++ b/Core/Inc/compute.h @@ -185,7 +185,7 @@ void compute_send_segment_temp_message(acc_data_t *bmsdata); void compute_send_fault_message(uint8_t status, int16_t curr, int16_t in_dcl); -void compute_send_fault_timer_message(uint8_t start_stop, uint16_t fault_code, +void compute_send_fault_timer_message(uint8_t start_stop, int fault_code, uint16_t data_1); /** diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c index 745dc5a..fde3ea8 100644 --- a/Core/Src/can_handler.c +++ b/Core/Src/can_handler.c @@ -98,7 +98,7 @@ void init_can_msg_config() can_msg_t fault_timer_msg; fault_timer_msg.id = FAULT_TIMER_CANID; - fault_timer_msg.len = 5; + fault_timer_msg.len = 4; // rl_data_t rl_discharge_data = { .msg_rate = 5000 }; // rl_data_t rl_charge_data = { .msg_rate = 0 }; diff --git a/Core/Src/compute.c b/Core/Src/compute.c index 17f7243..80881e0 100644 --- a/Core/Src/compute.c +++ b/Core/Src/compute.c @@ -535,17 +535,17 @@ void compute_send_fault_message(uint8_t status, int16_t curr, int16_t in_dcl) queue_can_msg(bms_can_msgs[FAULT]); } -void compute_send_fault_timer_message(uint8_t start_stop, uint16_t fault_code, +void compute_send_fault_timer_message(uint8_t start_stop, int fault_code, uint16_t data_1) { struct __attribute__((__packed__)) { uint8_t start_stop; - uint16_t fault_code; + uint8_t fault_code; int16_t data_1; } fault_timer_msg_data; fault_timer_msg_data.start_stop = start_stop; - fault_timer_msg_data.fault_code = fault_code; + fault_timer_msg_data.fault_code = log2(fault_code); fault_timer_msg_data.data_1 = data_1; endian_swap(&fault_timer_msg_data.fault_code, From 622173ab7c8833890db33e1ab469ce1ff3a6b6e5 Mon Sep 17 00:00:00 2001 From: bjackson312006 Date: Sat, 30 Nov 2024 00:15:42 -0500 Subject: [PATCH 5/6] Changed fault_code to uint32_t --- Core/Inc/compute.h | 2 +- Core/Src/compute.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/Inc/compute.h b/Core/Inc/compute.h index 269806b..2f5f32e 100644 --- a/Core/Inc/compute.h +++ b/Core/Inc/compute.h @@ -185,7 +185,7 @@ void compute_send_segment_temp_message(acc_data_t *bmsdata); void compute_send_fault_message(uint8_t status, int16_t curr, int16_t in_dcl); -void compute_send_fault_timer_message(uint8_t start_stop, int fault_code, +void compute_send_fault_timer_message(uint8_t start_stop, uint32_t fault_code, uint16_t data_1); /** diff --git a/Core/Src/compute.c b/Core/Src/compute.c index 80881e0..89f863c 100644 --- a/Core/Src/compute.c +++ b/Core/Src/compute.c @@ -535,7 +535,7 @@ void compute_send_fault_message(uint8_t status, int16_t curr, int16_t in_dcl) queue_can_msg(bms_can_msgs[FAULT]); } -void compute_send_fault_timer_message(uint8_t start_stop, int fault_code, +void compute_send_fault_timer_message(uint8_t start_stop, uint32_t fault_code, uint16_t data_1) { struct __attribute__((__packed__)) { From b1cd849e5fad9aad8a5e08a04b986617054f5401 Mon Sep 17 00:00:00 2001 From: bjackson312006 Date: Sat, 30 Nov 2024 00:19:09 -0500 Subject: [PATCH 6/6] Changed fault timer can id --- Core/Inc/can_handler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/Inc/can_handler.h b/Core/Inc/can_handler.h index 6396a16..f16ee3d 100644 --- a/Core/Inc/can_handler.h +++ b/Core/Inc/can_handler.h @@ -25,7 +25,7 @@ #define FAULT_CANID 0x703 #define NOISE_CANID 0x88 #define DEBUG_CANID 0x702 -#define FAULT_TIMER_CANID 0x701 +#define FAULT_TIMER_CANID 0x6FF typedef struct { uint32_t prev_tick;