60 lines
1.4 KiB
C
60 lines
1.4 KiB
C
//
|
|
// Created by cfif on 07.09.22.
|
|
//
|
|
#include <SystemDelayInterface.h>
|
|
#include "LinAt32.h"
|
|
#include "SerialPortLinArtery.h"
|
|
|
|
void LIN_Initial(
|
|
tLinAt32 *env,
|
|
tSerialPortIO *serialPortIO,
|
|
void *linData
|
|
) {
|
|
env->serialPortIO = serialPortIO;
|
|
env->linData = linData;
|
|
}
|
|
|
|
static uint8_t vLinRunCommand(tLinAt32 *env, uint32_t timeout) {
|
|
|
|
lin_frame_t txFrame;
|
|
|
|
txFrame.dataLen = env->linData->g_aTxBufferLen;
|
|
for (uint8_t i = 0; i < env->linData->g_aTxBufferLen; ++i) {
|
|
txFrame.data[i] = env->linData->g_aTxBuffer[i];
|
|
}
|
|
|
|
bool result = vSerialPortSendLinFrame(env->serialPortIO->env, &txFrame, timeout);
|
|
|
|
if (result) {
|
|
return LIN_RX_COMPLETED;
|
|
}
|
|
|
|
return LIN_TIMEOUT;
|
|
}
|
|
|
|
static uint8_t vLinGetCommand(tLinAt32 *env, uint32_t timeout) {
|
|
lin_frame_t rxFrame;
|
|
|
|
uint16_t len = SerialPortReceive(env->serialPortIO, (void *) &rxFrame, sizeof(lin_frame_t), timeout);
|
|
|
|
if (len == 0) {
|
|
return LIN_NO_EVENT;
|
|
}
|
|
|
|
env->linData->g_aRxBufferLen = rxFrame.dataLen;
|
|
for (uint8_t i = 0; i < rxFrame.dataLen; ++i) {
|
|
env->linData->g_aRxBuffer[i] = rxFrame.data[i];
|
|
}
|
|
|
|
return rxFrame.event;
|
|
|
|
}
|
|
|
|
tLinIO vLinGetIo(tLinAt32 *env) {
|
|
tLinIO io = {
|
|
.env = env,
|
|
.runCommand = (LinIOTransaction) vLinRunCommand,
|
|
.getCommand = (LinIOTransaction) vLinGetCommand
|
|
};
|
|
return io;
|
|
} |