Send counter with clock sync frames

This allows for a simple sanity check on the slave to catch missed
frames.
This commit is contained in:
jazzpi 2022-08-02 18:25:51 +02:00
parent 5ad45cf53d
commit 3d4f9eab74
1 changed files with 4 additions and 1 deletions

View File

@ -10,6 +10,8 @@ static FDCAN_HandleTypeDef* can;
static TIM_HandleTypeDef* sync_timer; static TIM_HandleTypeDef* sync_timer;
static TIM_HandleTypeDef* heartbeat_timer; static TIM_HandleTypeDef* heartbeat_timer;
static uint8_t clock_sync_counter = 0;
void clock_sync_init(FDCAN_HandleTypeDef* can_handle, void clock_sync_init(FDCAN_HandleTypeDef* can_handle,
TIM_HandleTypeDef* sync_timer_handle, TIM_HandleTypeDef* sync_timer_handle,
TIM_HandleTypeDef* heartbeat_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) { void clock_sync_handle_timer_complete(TIM_HandleTypeDef* timer) {
if (timer == sync_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) { } else if (timer == heartbeat_timer) {
CAN_Transmit(can, MASTER_HEARTBEAT_ADDRESS, NULL, 0); CAN_Transmit(can, MASTER_HEARTBEAT_ADDRESS, NULL, 0);
} }