Send heartbeat packets every 100 ms

This commit is contained in:
jazzpi
2022-08-01 08:42:24 +02:00
parent bd9d86b168
commit 5ad45cf53d
7 changed files with 125 additions and 15 deletions

View File

@ -2,19 +2,31 @@
#include "CAN_Communication.h"
#include "stm32g4xx_hal.h"
#include "stm32g4xx_hal_fdcan.h"
#include "stm32g4xx_hal_tim.h"
static FDCAN_HandleTypeDef* can;
static TIM_HandleTypeDef* timer;
static TIM_HandleTypeDef* sync_timer;
static TIM_HandleTypeDef* heartbeat_timer;
void clock_sync_init(FDCAN_HandleTypeDef* can_handle,
TIM_HandleTypeDef* timer_handle) {
TIM_HandleTypeDef* sync_timer_handle,
TIM_HandleTypeDef* heartbeat_timer_handle) {
can = can_handle;
timer = timer_handle;
HAL_TIM_Base_Start_IT(timer);
sync_timer = sync_timer_handle;
heartbeat_timer = heartbeat_timer_handle;
HAL_TIM_Base_Start_IT(heartbeat_timer);
// Delay between starting the timers so the interrupts don't fire at the same
// time
HAL_Delay(50);
HAL_TIM_Base_Start_IT(sync_timer);
}
void clock_sync_handle_timer_complete() {
CAN_Transmit(can, CLOCK_SYNC_ADDRESS, NULL, 0);
void clock_sync_handle_timer_complete(TIM_HandleTypeDef* timer) {
if (timer == sync_timer) {
CAN_Transmit(can, CLOCK_SYNC_ADDRESS, NULL, 0);
} else if (timer == heartbeat_timer) {
CAN_Transmit(can, MASTER_HEARTBEAT_ADDRESS, NULL, 0);
}
}