From 900a0037f17c0448b779609139af9ecb058dc068 Mon Sep 17 00:00:00 2001 From: cfif Date: Mon, 18 May 2026 17:40:41 +0300 Subject: [PATCH] Init --- Inc/LinAt32.h | 26 ++++++++++++++++++++++ Src/LinAt32.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ modular.json | 17 +++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 Inc/LinAt32.h create mode 100644 Src/LinAt32.c create mode 100644 modular.json diff --git a/Inc/LinAt32.h b/Inc/LinAt32.h new file mode 100644 index 0000000..d8b74ba --- /dev/null +++ b/Inc/LinAt32.h @@ -0,0 +1,26 @@ +// +// Created by cfif on 17.11.22. +// + +#ifndef LIN_AT32_H +#define LIN_AT32_H + +#include "LinIO.h" +#include "SerialPortIO.h" +#include "SerialPort.h" +#include "cmsis_os2.h" + +typedef struct { + tSerialPortIO *serialPortIO; + tLinData *linData; +} tLinAt32; + +void LIN_Initial( + tLinAt32 *env, + tSerialPortIO *serialPortIO, + void *linData +); + +tLinIO vLinGetIo(tLinAt32 *env); + +#endif //LIN_AT32_H diff --git a/Src/LinAt32.c b/Src/LinAt32.c new file mode 100644 index 0000000..8f1c004 --- /dev/null +++ b/Src/LinAt32.c @@ -0,0 +1,60 @@ +// +// Created by cfif on 07.09.22. +// +#include +#include "LinAt32.h" +#include "SerialPortArtery.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; +} \ No newline at end of file diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..19c9aca --- /dev/null +++ b/modular.json @@ -0,0 +1,17 @@ +{ + "dep": [ + { + "type": "git", + "provider": "HVAC_DEV", + "repo": "LinInterface" + } + ], + "cmake": { + "inc_dirs": [ + "Inc" + ], + "srcs": [ + "Src/**.c" + ] + } +} \ No newline at end of file