From 3d4f9eab741de6d942835eb4cd0e0981ccd2513f Mon Sep 17 00:00:00 2001 From: jazzpi Date: Tue, 2 Aug 2022 18:25:51 +0200 Subject: [PATCH] Send counter with clock sync frames This allows for a simple sanity check on the slave to catch missed frames. --- Core/Src/Clock_Sync.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Core/Src/Clock_Sync.c b/Core/Src/Clock_Sync.c index 54d94c0..78f4067 100644 --- a/Core/Src/Clock_Sync.c +++ b/Core/Src/Clock_Sync.c @@ -10,6 +10,8 @@ static FDCAN_HandleTypeDef* can; static TIM_HandleTypeDef* sync_timer; static TIM_HandleTypeDef* heartbeat_timer; +static uint8_t clock_sync_counter = 0; + void clock_sync_init(FDCAN_HandleTypeDef* can_handle, TIM_HandleTypeDef* sync_timer_handle, TIM_HandleTypeDef* heartbeat_timer_handle) { @@ -25,7 +27,8 @@ void clock_sync_init(FDCAN_HandleTypeDef* can_handle, void clock_sync_handle_timer_complete(TIM_HandleTypeDef* timer) { if (timer == sync_timer) { - CAN_Transmit(can, CLOCK_SYNC_ADDRESS, NULL, 0); + CAN_Transmit(can, CLOCK_SYNC_ADDRESS, &clock_sync_counter, 1); + clock_sync_counter++; } else if (timer == heartbeat_timer) { CAN_Transmit(can, MASTER_HEARTBEAT_ADDRESS, NULL, 0); }