Обновление

This commit is contained in:
cfif 2025-10-17 13:26:07 +03:00
commit a7f9844a50
3 changed files with 237 additions and 0 deletions

54
Inc/LinFlagchip.h Normal file
View File

@ -0,0 +1,54 @@
//
// Created by cfif on 17.11.22.
//
#ifndef LIN_FLAGCHIP_H
#define LIN_FLAGCHIP_H
#include "LinIO.h"
#include "cmsis_os2.h"
#include "fc7xxx_driver_adc.h"
#include "fc7xxx_driver_pcc.h"
#include "interrupt_manager.h"
#include "fc7xxx_driver_lin.h"
// LIN protocol ID definition
#define LIN_MASTER_SEND_ID (0x01U)
#define LIN_MASTER_RECEIVE_ID (0x02U)
#define LIN_MASTER_GO_TO_SLEEP_ID (0x03U)
typedef struct {
uint8_t UART_INDEX;
FCUART_Type *UART;
osMessageQueueId_t rxDataQueue;
lin_config_t g_linMasterConfig;
lin_xfer_state_t g_xferMasterState;
uint8_t g_aTxBuffer[8];
uint8_t g_aRxBuffer[8];
} tLinFlagchip;
void LIN_Initial(
tLinFlagchip *env,
FCUART_Type *uart,
uint32_t BoundRate,
uint8 UART_INDEX, // UART0 = 0 ... UART7 = 7
IRQn_Type IRQ_UART, // FCUART0_IRQn ... FCUART7_IRQn
uint8 UART_PRIORITY,
lin_get_interval_time_t LIN_TimerGetTimeIntervalValue,
lin_callback_t LinCallbackHandler
);
void GetLinCallbackHandler(tLinFlagchip *env, uint8_t u8LinIndex, void *state);
void Get_LIN_Result(tLinFlagchip *env);
tLinIO vLinGetIo(tLinFlagchip *env);
#endif //LIN_FLAGCHIP_H

166
Src/LinFlagchip.c Normal file
View File

@ -0,0 +1,166 @@
//
// Created by cfif on 07.09.22.
//
#include <SystemDelayInterface.h>
#include "LinFlagchip.h"
static const PCC_ClkSrcType s_ePccUartTable[] =
{
PCC_CLK_FCUART0,
PCC_CLK_FCUART1,
PCC_CLK_FCUART2,
PCC_CLK_FCUART3,
PCC_CLK_FCUART4,
PCC_CLK_FCUART5,
PCC_CLK_FCUART6,
PCC_CLK_FCUART7
};
void GetLinCallbackHandler(tLinFlagchip *env, uint8_t u8LinIndex, void *state) {
lin_xfer_state_t *pXferState = state;
//uint32_t s_countIndex = 0U;
//bool s_rxError = false;
//LIN_DrvSetTimeOutCounter(env->UART_INDEX, 500);
switch (pXferState->currentEventId) {
case LIN_PID_OK:
if (pXferState->currentId == LIN_MASTER_SEND_ID) {
// Call to Send Frame DATA Function
LIN_DrvSendFrameNonBlocking(u8LinIndex, env->g_aTxBuffer, sizeof(env->g_aTxBuffer));
} else if (pXferState->currentId == LIN_MASTER_RECEIVE_ID) {
LIN_DrvReceiveFrameNonBlocking(u8LinIndex, env->g_aRxBuffer, sizeof(env->g_aRxBuffer));
} else if (pXferState->currentId == LIN_MASTER_GO_TO_SLEEP_ID) {
LIN_DrvGoToSleepMode(u8LinIndex);
} 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(env->UART_INDEX);
// FCUART_Printf(DEBUG_FCUART_INSTANCE, "Receive PID error!\r\n");
break;
case LIN_TX_COMPLETED:
// Go to IDLE state.
LIN_DrvGoToIdleMode(env->UART_INDEX);
// 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(env->UART_INDEX);
// 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(env->UART_INDEX);
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_Initial(
tLinFlagchip *env,
FCUART_Type *uart,
uint32_t BoundRate,
uint8 UART_INDEX, // UART0 = 0 ... UART7 = 7
IRQn_Type IRQ_UART, // FCUART0_IRQn ... FCUART7_IRQn
uint8 UART_PRIORITY,
lin_get_interval_time_t LIN_TimerGetTimeIntervalValue,
lin_callback_t LinCallbackHandler
) {
env->UART_INDEX = UART_INDEX;
env->UART = uart;
env->rxDataQueue = osMessageQueueNew(1, 1, NULL);
LIN_DrvGetDefaultConfig(LIN_NODE_MASTER, &env->g_linMasterConfig);
env->g_linMasterConfig.baudRate = BoundRate;
env->g_linMasterConfig.clockSrcFreq = PCC_GetPccFunctionClock(s_ePccUartTable[UART_INDEX]);
env->g_linMasterConfig.getIntervalTimeValueCallback = LIN_TimerGetTimeIntervalValue;
// Switch TJA1021 device to normal mode
// GPIO_WritePins(PORT_E, PORT_PIN_24, PORT_GPIO_HIGH);
LIN_DrvInit(UART_INDEX, &env->g_linMasterConfig);
env->g_xferMasterState.Callback = LinCallbackHandler;
LIN_DrvStart(UART_INDEX, &env->g_xferMasterState);
NVIC_SetPriority(IRQ_UART, UART_PRIORITY);
NVIC_EnableIRQ(IRQ_UART);
}
static uint8_t vLinRunCommand(tLinFlagchip *env, uint8_t command, uint32_t timeout) {
LIN_DrvSendHeader(env->UART_INDEX, command);
uint8_t state;
if (osMessageQueueGet(env->rxDataQueue, &state, NULL, timeout) == osOK) {
lin_event_id_t id = state;
return id;
}
return LIN_TIMEOUT;
}
tLinIO vLinGetIo(tLinFlagchip *env) {
tLinIO io = {
.env = env,
.runCommand = (LinIOTransaction) vLinRunCommand,
};
return io;
}

17
modular.json Normal file
View File

@ -0,0 +1,17 @@
{
"dep": [
{
"type": "git",
"provider": "HVAC_M7",
"repo": "LinInterface"
}
],
"cmake": {
"inc_dirs": [
"Inc"
],
"srcs": [
"Src/**.c"
]
}
}