Files
libcls/CLS.c
2024-02-05 19:49:37 +01:00

33 lines
1007 B
C

#include "CLS_BSP.h"
#include "CLS.h"
#include "CLSAddress.h"
#include "cmsis_os2.h"
osTimerId_t CLS_HeatbeatTimerId; // Timer ID
static uint8_t cls_hartbeat_counter = 0;
static CLS_BSP_TxHeaderType cls_hartbeat_header = CREATE_BSP_CAN_HEADER(GENERATE_CLS_ADDRESS(CLS_CODE_STATUS,CLS_DEVICE,CLS_CH_STA_HEATBEAT), CLS_BSP_DLC_BYTES_1);
void CLS_Heatbeat(void *argument) {
// Code to be executed every 500ms
cls_hartbeat_counter++;
CLS_BSP_CAN_AddMessageToSend(&cls_hartbeat_header, &cls_hartbeat_counter);
}
void CLS_Init(void) {
osTimerAttr_t timerAttr;
timerAttr.name = "CLS_Heatbeat";
timerAttr.attr_bits = 0U;
timerAttr.cb_mem = NULL;
timerAttr.cb_size = 0U;
CLS_HeatbeatTimerId = osTimerNew((osTimerFunc_t)CLS_Heatbeat, osTimerPeriodic, NULL, &timerAttr);
if (CLS_HeatbeatTimerId != NULL) { // Timer object created
if (osTimerStart(CLS_HeatbeatTimerId, 500) == osOK) { // Timer started
// Timer started successfully
}
}
}