added lib CLS

- CLS Address management
- CLS Hartbeat timer
This commit is contained in:
2024-02-05 01:22:46 +01:00
parent bfc28e6c94
commit 4dfe9060fa
10 changed files with 157 additions and 8 deletions

48
Application/CLS/CLS.c Normal file
View File

@@ -0,0 +1,48 @@
#include "CLS.h"
#include "CLSAddress.h"
#include "cmsis_os2.h"
#include "fdcan.h"
osTimerId_t CLS_HeatbeatTimerId; // Timer ID
static const CLSAddress address = {
.code = CLS_CODE_STATUS,
.device = CLS_DEVICE,
.channel = CLS_CH_STA_HEATBEAT,
};
static uint8_t cls_hartbeat_counter = 0;
static FDCAN_TxHeaderTypeDef cls_hartbeat_header = {
.IdType = FDCAN_STANDARD_ID,
.Identifier = GENERATE_CLS_ADDRESS(CLS_CODE_STATUS,CLS_DEVICE,CLS_CH_STA_HEATBEAT),
.TxFrameType = FDCAN_DATA_FRAME,
.DataLength = FDCAN_DLC_BYTES_1,
.ErrorStateIndicator = FDCAN_ESI_PASSIVE,
.BitRateSwitch = FDCAN_BRS_OFF,
.FDFormat = FDCAN_CLASSIC_CAN,
.TxEventFifoControl = FDCAN_NO_TX_EVENTS,
.MessageMarker = 0xCC,
};
void CLS_Heatbeat(void *argument) {
// Code to be executed every 500ms
cls_hartbeat_counter++;
HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &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
}
}
}