Send heartbeat packets every 100 ms
This commit is contained in:
		@ -22,6 +22,7 @@
 | 
			
		||||
#define SLAVE_CMD_BASE_ADDRESS 0x500  //
 | 
			
		||||
#define SLAVE_EMERGENCY_ADDRESS 0x001 // Emergency Frame
 | 
			
		||||
#define CLOCK_SYNC_ADDRESS 0x002
 | 
			
		||||
#define MASTER_HEARTBEAT_ADDRESS 0x010
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
  int16_t FrameID;
 | 
			
		||||
 | 
			
		||||
@ -1,11 +1,34 @@
 | 
			
		||||
#ifndef INC_CLOCK_SYNC_H_
 | 
			
		||||
#define INC_CLOCK_SYNC_H_
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @file Clock_Sync.h
 | 
			
		||||
 * @author Jasper v. Blanckenburg (j.blanckenburg@fasttube.de)
 | 
			
		||||
 * @brief Clock synchronization mechanism -- master side
 | 
			
		||||
 * @version 0.1
 | 
			
		||||
 * @date 2022-08-01
 | 
			
		||||
 *
 | 
			
		||||
 * @copyright Copyright (c) 2022
 | 
			
		||||
 *
 | 
			
		||||
 * The slaves' clocks are fairly inaccurate -- too inaccurate for reliable CAN
 | 
			
		||||
 * communication. In order to synchronize the clock frequencies, the slaves need
 | 
			
		||||
 * an external clock source. Since the HSE doesn't work on all slaves, we use
 | 
			
		||||
 * the master as the external clock source. For more detail, take a look at the
 | 
			
		||||
 * clock sync section in the slave code.
 | 
			
		||||
 *
 | 
			
		||||
 * This file handles the master part of the clock sync mechanism: It sends
 | 
			
		||||
 * CLOCK_SYNC frames every 1000 ms and MASTER_HEARTBEAT frames every 100 ms. In
 | 
			
		||||
 * order to keep the time between packets accurate, they are sent from timer
 | 
			
		||||
 * interrupts.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "stm32g4xx_hal.h"
 | 
			
		||||
#include "stm32g4xx_hal_fdcan.h"
 | 
			
		||||
#include "stm32g4xx_hal_tim.h"
 | 
			
		||||
 | 
			
		||||
void clock_sync_init(FDCAN_HandleTypeDef* can, TIM_HandleTypeDef* timer);
 | 
			
		||||
void clock_sync_init(FDCAN_HandleTypeDef* can, TIM_HandleTypeDef* sync_timer,
 | 
			
		||||
                     TIM_HandleTypeDef* heartbeat_timer);
 | 
			
		||||
 | 
			
		||||
void clock_sync_handle_timer_complete();
 | 
			
		||||
void clock_sync_handle_timer_complete(TIM_HandleTypeDef* timer);
 | 
			
		||||
 | 
			
		||||
#endif // INC_CLOCK_SYNC_H_
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user