Move clock sync logic to separate files
This commit is contained in:
		@ -21,7 +21,7 @@
 | 
			
		||||
#define SLAVE_STATUS_BASE_ADDRESS 0x600
 | 
			
		||||
#define SLAVE_CMD_BASE_ADDRESS 0x500  //
 | 
			
		||||
#define SLAVE_EMERGENCY_ADDRESS 0x001 // Emergency Frame
 | 
			
		||||
#define TIME_SYNC_ADDRESS 0x002
 | 
			
		||||
#define CLOCK_SYNC_ADDRESS 0x002
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
  int16_t FrameID;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										11
									
								
								Core/Inc/Clock_Sync.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Core/Inc/Clock_Sync.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
#ifndef INC_CLOCK_SYNC_H_
 | 
			
		||||
#define INC_CLOCK_SYNC_H_
 | 
			
		||||
 | 
			
		||||
#include "stm32g4xx_hal.h"
 | 
			
		||||
#include "stm32g4xx_hal_fdcan.h"
 | 
			
		||||
 | 
			
		||||
void clock_sync_init(FDCAN_HandleTypeDef* can, TIM_HandleTypeDef* timer);
 | 
			
		||||
 | 
			
		||||
void clock_sync_handle_timer_complete();
 | 
			
		||||
 | 
			
		||||
#endif // INC_CLOCK_SYNC_H_
 | 
			
		||||
							
								
								
									
										20
									
								
								Core/Src/Clock_Sync.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								Core/Src/Clock_Sync.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,20 @@
 | 
			
		||||
#include "Clock_Sync.h"
 | 
			
		||||
 | 
			
		||||
#include "CAN_Communication.h"
 | 
			
		||||
 | 
			
		||||
#include "stm32g4xx_hal_fdcan.h"
 | 
			
		||||
#include "stm32g4xx_hal_tim.h"
 | 
			
		||||
 | 
			
		||||
static FDCAN_HandleTypeDef* can;
 | 
			
		||||
static TIM_HandleTypeDef* timer;
 | 
			
		||||
 | 
			
		||||
void clock_sync_init(FDCAN_HandleTypeDef* can_handle,
 | 
			
		||||
                     TIM_HandleTypeDef* timer_handle) {
 | 
			
		||||
  can = can_handle;
 | 
			
		||||
  timer = timer_handle;
 | 
			
		||||
  HAL_TIM_Base_Start_IT(timer);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void clock_sync_handle_timer_complete() {
 | 
			
		||||
  CAN_Transmit(can, CLOCK_SYNC_ADDRESS, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
@ -25,6 +25,7 @@
 | 
			
		||||
#include "AIR_State_Maschine.h"
 | 
			
		||||
#include "AMS_Errorcodes.h"
 | 
			
		||||
#include "CAN_Communication.h"
 | 
			
		||||
#include "Clock_Sync.h"
 | 
			
		||||
#include "Error_Check.h"
 | 
			
		||||
#include "SPI_Slave_Communication.h"
 | 
			
		||||
#include "Slave_Monitoring.h"
 | 
			
		||||
@ -75,7 +76,7 @@ void setAMSError(void);
 | 
			
		||||
/* USER CODE BEGIN 0 */
 | 
			
		||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim) {
 | 
			
		||||
  if (htim == &htim1) {
 | 
			
		||||
    CAN_Transmit(&hfdcan1, TIME_SYNC_ADDRESS, NULL, 0);
 | 
			
		||||
    clock_sync_handle_timer_complete();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -119,11 +120,11 @@ int main(void) {
 | 
			
		||||
  /* USER CODE BEGIN 2 */
 | 
			
		||||
 | 
			
		||||
  airstates = init_AIR_State_Maschine();
 | 
			
		||||
  initSlaves();
 | 
			
		||||
  set_SPI_errorInfo(&defaulterrorhandle);
 | 
			
		||||
  spi_communication_init(&hspi1, &airstates);
 | 
			
		||||
  CAN_Init(&hfdcan1);
 | 
			
		||||
  HAL_TIM_Base_Start_IT(&htim1);
 | 
			
		||||
  clock_sync_init(&hfdcan1, &htim1);
 | 
			
		||||
  initSlaves();
 | 
			
		||||
 | 
			
		||||
  HAL_GPIO_WritePin(Status_LED_GPIO_Port, Status_LED_Pin, GPIO_PIN_SET);
 | 
			
		||||
  // setAMSError();
 | 
			
		||||
 | 
			
		||||
@ -38,6 +38,7 @@ BUILD_DIR = build
 | 
			
		||||
C_SOURCES =  \
 | 
			
		||||
Core/Src/AIR_State_Maschine.c \
 | 
			
		||||
Core/Src/CAN_Communication.c \
 | 
			
		||||
Core/Src/Clock_Sync.c \
 | 
			
		||||
Core/Src/Error_Check.c \
 | 
			
		||||
Core/Src/SPI_Slave_Communication.c \
 | 
			
		||||
Core/Src/Slave_Monitoring.c \
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user