Merge pull request 'Linux HAL updates' (#456) from mueller/hal-linux-spi-uart-update into mueller/restructuring

Reviewed-on: fsfw/fsfw#456
This commit is contained in:
Ulrich Mohr 2021-08-09 15:39:18 +02:00
commit 1fa59c5cae
3 changed files with 70 additions and 1 deletions

View File

@ -82,7 +82,7 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
gpioComIF->pullHigh(gpioId); gpioComIF->pullHigh(gpioId);
} }
size_t spiSpeed = 0; uint32_t spiSpeed = 0;
spi::SpiModes spiMode = spi::SpiModes::MODE_0; spi::SpiModes spiMode = spi::SpiModes::MODE_0;
SpiCookie::UncommonParameters params; SpiCookie::UncommonParameters params;

View File

@ -443,6 +443,60 @@ ReturnValue_t UartComIF::readReceivedMessage(CookieIF *cookie,
return RETURN_OK; return RETURN_OK;
} }
ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF *cookie) {
std::string deviceFile;
UartDeviceMapIter uartDeviceMapIter;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
if(uartCookie == nullptr) {
sif::warning << "UartComIF::flushUartRxBuffer: Invalid uart cookie!" << std::endl;
return NULLPOINTER;
}
deviceFile = uartCookie->getDeviceFile();
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
if(uartDeviceMapIter != uartDeviceMap.end()) {
int fd = uartDeviceMapIter->second.fileDescriptor;
tcflush(fd, TCIFLUSH);
return RETURN_OK;
}
return RETURN_FAILED;
}
ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF *cookie) {
std::string deviceFile;
UartDeviceMapIter uartDeviceMapIter;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
if(uartCookie == nullptr) {
sif::warning << "UartComIF::flushUartTxBuffer: Invalid uart cookie!" << std::endl;
return NULLPOINTER;
}
deviceFile = uartCookie->getDeviceFile();
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
if(uartDeviceMapIter != uartDeviceMap.end()) {
int fd = uartDeviceMapIter->second.fileDescriptor;
tcflush(fd, TCOFLUSH);
return RETURN_OK;
}
return RETURN_FAILED;
}
ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF *cookie) {
std::string deviceFile;
UartDeviceMapIter uartDeviceMapIter;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
if(uartCookie == nullptr) {
sif::warning << "UartComIF::flushUartTxAndRxBuf: Invalid uart cookie!" << std::endl;
return NULLPOINTER;
}
deviceFile = uartCookie->getDeviceFile();
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
if(uartDeviceMapIter != uartDeviceMap.end()) {
int fd = uartDeviceMapIter->second.fileDescriptor;
tcflush(fd, TCIOFLUSH);
return RETURN_OK;
}
return RETURN_FAILED;
}
void UartComIF::setUartMode(struct termios *options, UartCookie &uartCookie) { void UartComIF::setUartMode(struct termios *options, UartCookie &uartCookie) {
UartModes uartMode = uartCookie.getUartMode(); UartModes uartMode = uartCookie.getUartMode();
if(uartMode == UartModes::NON_CANONICAL) { if(uartMode == UartModes::NON_CANONICAL) {

View File

@ -41,6 +41,21 @@ public:
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
size_t *size) override; size_t *size) override;
/**
* @brief This function discards all data received but not read in the UART buffer.
*/
ReturnValue_t flushUartRxBuffer(CookieIF *cookie);
/**
* @brief This function discards all data in the transmit buffer of the UART driver.
*/
ReturnValue_t flushUartTxBuffer(CookieIF *cookie);
/**
* @brief This function discards both data in the transmit and receive buffer of the UART.
*/
ReturnValue_t flushUartTxAndRxBuf(CookieIF *cookie);
private: private:
using UartDeviceFile_t = std::string; using UartDeviceFile_t = std::string;