Обновление

This commit is contained in:
cfif 2025-11-21 13:18:04 +03:00
commit 2d2309e224
3 changed files with 185 additions and 0 deletions

142
LinTasks.c Normal file
View File

@ -0,0 +1,142 @@
//
// Created by cfif on 05.04.2024.
//
#include <SystemDelayInterface.h>
#include "LinTasks.h"
#include "CmsisRtosThreadUtils.h"
#include "CanPorts.h"
#include "fc7xxx_driver_lin.h"
//начало----------------------------------------- LIN 0 ----------------------------------------------------------------
//начало----------------------------------------- LIN 0 ----------------------------------------------------------------
//начало----------------------------------------- LIN 0 ----------------------------------------------------------------
//начало----------------------------------------- LIN 0 ----------------------------------------------------------------
void GetLin0CallbackHandler(tLinData *env, uint8_t u8LinIndex, void *state) {
lin_xfer_state_t *pXferState = state;
//uint32_t s_countIndex = 0U;
//bool s_rxError = false;
//LIN_DrvSetTimeOutCounter(u8LinIndex, 500);
switch (pXferState->currentEventId) {
case LIN_PID_OK:
if (env->direction == LIN_DIRECTION_SET) {
LIN_DrvSendFrameNonBlocking(u8LinIndex, env->g_aTxBuffer, env->g_aTxBufferLen);
} else if (env->direction == LIN_DIRECTION_GET) {
LIN_DrvReceiveFrameNonBlocking(u8LinIndex, env->g_aRxBuffer, env->g_aRxBufferLen);
} else {
// Misra check.
uint8_t data = LIN_TIMEOUT;
osMessageQueuePut(env->rxDataQueue, &data, 0x0, 0U);
return;
}
break;
case LIN_PID_ERROR:
// Go to idle mode
LIN_DrvGoToIdleMode(u8LinIndex);
// FCUART_Printf(DEBUG_FCUART_INSTANCE, "Receive PID error!\r\n");
break;
case LIN_TX_COMPLETED:
// Go to IDLE state.
LIN_DrvGoToIdleMode(u8LinIndex);
// FCUART_Printf(DEBUG_FCUART_INSTANCE, "This test case will send data to slave node. Send data: \r\n");
// for (s_countIndex = 0U; s_countIndex < sizeof(g_aTxBuffer); s_countIndex++) {
// FCUART_Printf(DEBUG_FCUART_INSTANCE, " 0x%x ", g_aTxBuffer[s_countIndex]);
// }
// FCUART_Printf(DEBUG_FCUART_INSTANCE, "\r\nMaster node send complete! \r\n");
break;
case LIN_RX_COMPLETED:
// Go to idle mode
LIN_DrvGoToIdleMode(u8LinIndex);
// FCUART_Printf(DEBUG_FCUART_INSTANCE, "Master node receive data:\r\n");
//for (s_countIndex = 0U; s_countIndex < sizeof(env->g_aRxBuffer); s_countIndex++) {
// FCUART_Printf(DEBUG_FCUART_INSTANCE, " 0x%x ", g_aRxBuffer[s_countIndex]);
//if (env->g_aRxBuffer[s_countIndex] != (env->g_aTxBuffer[s_countIndex] + 1U)) {
// s_rxError = true;
//}
//env->g_aRxBuffer[s_countIndex] = 0U;
//}
//if (true == s_rxError) {
// FCUART_Printf(DEBUG_FCUART_INSTANCE, "\r\nReceived data Error\r\n");
//} else {
// FCUART_Printf(DEBUG_FCUART_INSTANCE, "\r\nReveiced data matched!\r\n");
//}
break;
case LIN_CHECKSUM_ERROR:
// FCUART_Printf(DEBUG_FCUART_INSTANCE, "Receive checksum byte error!\r\n");
break;
case LIN_READBACK_ERROR:
// FCUART_Printf(DEBUG_FCUART_INSTANCE, "Read back error!\r\n");
break;
case LIN_FRAME_ERROR:
break;
case LIN_RECV_BREAK_FIELD_OK:
break;
case LIN_WAKEUP_SIGNAL:
// FCUART_Printf(DEBUG_FCUART_INSTANCE, "Wake up signal received!\r\n");
LIN_DrvGoToIdleMode(u8LinIndex);
break;
case LIN_TIMEOUT:
// FCUART_Printf(DEBUG_FCUART_INSTANCE, "LIN transfer timeout occurred!\r\n");
break;
case LIN_SYNC_ERROR:
break;
case LIN_BAUDRATE_ADJUSTED:
break;
case LIN_NO_EVENT:
break;
case LIN_SYNC_OK:
break;
default:
// do nothing
break;
}
osMessageQueuePut(env->rxDataQueue, (uint8_t *) &pXferState->currentEventId, 0x0, 0U);
}
void Lin_0_Init(tLinTaskActuator *env,
tLinData *linData,
tLinIO *linIO) {
env->linIo = linIO;
env->linData = linData;
env->access = osMutexNew(NULL);
InitThreadAtrStatic(&env->thread.attr, "Lin0", env->thread.controlBlock, env->thread.stack,
osPriorityNormal);
}
void Lin0_Scheduler(tLinTaskActuator *env) {
if (osMutexAcquire(env->access, 100) == osOK) {
osMutexRelease(env->access);
}
}
static _Noreturn void Lin0_Thread(tLinTaskActuator *env) {
for (;;) {
Lin0_Scheduler(env);
}
}
void Li0_StartThread(tLinTaskActuator *env) {
if (!env->thread.id) {
env->thread.id = osThreadNew((osThreadFunc_t) (Lin0_Thread), (void *) (env), &env->thread.attr);
}
}
//конец----------------------------------------- LIN 0 ----------------------------------------------------------------
//конец----------------------------------------- LIN 0 ----------------------------------------------------------------
//конец----------------------------------------- LIN 0 ----------------------------------------------------------------
//конец----------------------------------------- LIN 0 ----------------------------------------------------------------

33
LinTasks.h Normal file
View File

@ -0,0 +1,33 @@
//
// Created by cfif on 05.04.2024.
//
#ifndef HVAC_LIN_TASKS_H
#define HVAC_LIN_TASKS_H
#include <cmsis_os.h>
#include "LinIO.h"
typedef struct {
tLinIO *linIo;
osMutexId_t access;
tLinData *linData;
struct {
osThreadId_t id;
uint32_t stack[512];
StaticTask_t controlBlock;
osThreadAttr_t attr;
} thread;
} tLinTaskActuator;
void Lin_0_Init(tLinTaskActuator *env,
tLinData *linData,
tLinIO *linIO);
void Li0_StartThread(tLinTaskActuator *env);
void GetLin0CallbackHandler(tLinData *env, uint8_t u8LinIndex, void *state);
#endif //HVAC_LIN_TASKS_H

10
modular.json Executable file
View File

@ -0,0 +1,10 @@
{
"cmake": {
"inc_dirs": [
"./"
],
"srcs": [
"./**.c"
]
}
}