Обновление
This commit is contained in:
commit
fdfa36a496
|
|
@ -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
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"cmake": {
|
||||
"inc_dirs": [
|
||||
"Inc"
|
||||
],
|
||||
"srcs": [
|
||||
"Src/**.c"
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue