Обновление

This commit is contained in:
cfif 2025-10-29 11:17:05 +03:00
commit fdfa36a496
3 changed files with 110 additions and 0 deletions

27
Inc/SerialPortCan.h Normal file
View File

@ -0,0 +1,27 @@
//
// Created by cfif on 12.11.2024.
//
#ifndef HVAC_SERIALPORTCAN_H
#define HVAC_SERIALPORTCAN_H
#include "cmsis_os2.h"
#include "SerialPortIO.h"
#include "SerialPortFrameIO.h"
typedef struct {
tSerialPortFrameIO *CanIO;
osMessageQueueId_t queue;
uint32_t adr;
} tSerialPortCan;
void vSerialPortCanInit(
tSerialPortCan *env,
tSerialPortFrameIO *CanIO,
uint32_t adr,
uint32_t rxBufferLength
);
tSerialPortIO vSerialPortCanGetIo(tSerialPortCan *env);
#endif //HVAC_SERIALPORTCAN_H

73
Src/SerialPortCan.c Normal file
View File

@ -0,0 +1,73 @@
//
// Created by cfif on 12.11.2024.
//
#include "SerialPortCan.h"
#include "SystemDelayInterface.h"
#include "CanSerialPortFrame.h"
void vSerialPortCanInit(
tSerialPortCan *env,
tSerialPortFrameIO *CanIO,
uint32_t adr,
uint32_t rxBufferLength
) {
env->CanIO = CanIO;
env->queue = osMessageQueueNew(rxBufferLength, 1, NULL);
env->adr = adr;
}
static uint16_t vSerialPortReceiveQueue(tSerialPortCan *env, uint8_t *data, uint16_t size, uint32_t timeout,
osMessageQueueId_t queueId) {
uint16_t received = 0;
if (timeout) {
uint32_t endMs = SystemGetMs() + timeout;
uint32_t leftMs;
while (size && ((timeout == SystemWaitForever) || (endMs > SystemGetMs()))) {
leftMs = endMs - SystemGetMs();
if (osMessageQueueGet(queueId, data, NULL, leftMs) == osOK) {
--size;
++received;
++data;
}
}
} else {
while (size) {
if (osMessageQueueGet(queueId, data, NULL, 0) == osOK) {
--size;
++received;
++data;
} else {
return received;
}
}
}
return received;
}
static uint16_t vSerialPortReceive(tSerialPortCan *env, uint8_t *data, uint16_t size, uint32_t timeout) {
return vSerialPortReceiveQueue(env, data, size, timeout, env->queue);
}
static uint16_t vSerialPortTransmit(tSerialPortCan *env, uint8_t *data, uint16_t size, uint32_t timeout) {
CanSerialPortFrameSetId(env->CanIO->env, env->adr);
uint16_t sent = env->CanIO->transmit(env->CanIO->env, data, size, timeout);
return sent;
}
tSerialPortIO vSerialPortCanGetIo(tSerialPortCan *env) {
tSerialPortIO io = {
.env = env,
.receive = (SerialPortIOTransaction) vSerialPortReceive,
.transmit = (SerialPortIOTransaction) vSerialPortTransmit
};
return io;
}

10
modular.json Normal file
View File

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