75 lines
2.1 KiB
C
75 lines
2.1 KiB
C
//
|
|
// Created by cfif on 03.10.22.
|
|
//
|
|
|
|
#include "SerialPortHalfDuplexIO.h"
|
|
#include "SystemDelayInterface.h"
|
|
|
|
static uint16_t vSerialPortHalfDuplexReceive(tSerialPortHalfDuplex *io, uint8_t *data, uint16_t size,
|
|
uint32_t timeout) {
|
|
|
|
// tSerialPortHalfDuplex *serialPortHalfDuplex = (void *) io;
|
|
|
|
GpioPinSet(io->transmitePin, false);
|
|
GpioPinSet(io->recivePin, true);
|
|
|
|
uint16_t result = io->serialPortIo->receive(io->serialPortIo->env, data, size, timeout);
|
|
|
|
return result;
|
|
}
|
|
|
|
/*
|
|
static uint16_t vSerialPortHalfDuplexTransmit(tSerialPortIO *io, uint8_t *data, uint16_t size, uint32_t timeout) {
|
|
|
|
tSerialPortHalfDuplex *serialPortHalfDuplex = io->env;
|
|
|
|
GpioPinSet(serialPortHalfDuplex->transmitePin, true);
|
|
GpioPinSet(serialPortHalfDuplex->recivePin, false);
|
|
uint16_t result = serialPortHalfDuplex->serialPortIo->transmit(serialPortHalfDuplex->serialPortIo->env, data, size, timeout);
|
|
|
|
return result;
|
|
}
|
|
*/
|
|
|
|
static uint16_t vSerialPortHalfDuplexTransmit(tSerialPortHalfDuplex *io, uint8_t *data, uint16_t size, uint32_t timeout) {
|
|
|
|
// tSerialPortHalfDuplex *serialPortHalfDuplex = (void *) io;
|
|
|
|
GpioPinSet(io->recivePin, false);
|
|
GpioPinSet(io->transmitePin, true);
|
|
|
|
uint16_t result = io->serialPortIo->transmit(io->serialPortIo->env, data, size, timeout);
|
|
|
|
|
|
#ifndef HALF_DUPLEX_NO_DELAY
|
|
SystemDelayMs(5);
|
|
#else
|
|
|
|
#endif
|
|
|
|
GpioPinSet(io->transmitePin, false);
|
|
GpioPinSet(io->recivePin, true);
|
|
|
|
return result;
|
|
}
|
|
|
|
tSerialPortHalfDuplex vSerialPortHalfDuplexInit(
|
|
tSerialPortIO *serialPortIo, tGpioPin *transmitePin, tGpioPin *recivePin
|
|
) {
|
|
tSerialPortHalfDuplex port = {
|
|
.serialPortIo = serialPortIo,
|
|
.transmitePin = transmitePin,
|
|
.recivePin = recivePin
|
|
};
|
|
return port;
|
|
}
|
|
|
|
tSerialPortIO vSerialPortHalfDuplexGetIo(tSerialPortHalfDuplex *serialPortHalfDuplex) {
|
|
|
|
tSerialPortIO io = {
|
|
.env = serialPortHalfDuplex,
|
|
.receive = (SerialPortIOTransaction) vSerialPortHalfDuplexReceive,
|
|
.transmit = (SerialPortIOTransaction) vSerialPortHalfDuplexTransmit
|
|
};
|
|
return io;
|
|
} |