Update FSFW #25

Merged
muellerr merged 89 commits from mueller/master into master 2021-10-05 20:21:44 +02:00
4 changed files with 26 additions and 17 deletions
Showing only changes of commit bfae25ff2d - Show all commits

View File

@ -15,11 +15,6 @@
#include <cerrno> #include <cerrno>
#include <cstring> #include <cstring>
/* Can be used for low-level debugging of the SPI bus */
#ifndef FSFW_HAL_LINUX_SPI_WIRETAPPING
#define FSFW_HAL_LINUX_SPI_WIRETAPPING 0
#endif
SpiComIF::SpiComIF(object_id_t objectId, GpioIF* gpioComIF): SpiComIF::SpiComIF(object_id_t objectId, GpioIF* gpioComIF):
SystemObject(objectId), gpioComIF(gpioComIF) { SystemObject(objectId), gpioComIF(gpioComIF) {
if(gpioComIF == nullptr) { if(gpioComIF == nullptr) {
@ -146,8 +141,8 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
if(sendLen > spiCookie->getMaxBufferSize()) { if(sendLen > spiCookie->getMaxBufferSize()) {
#if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "SpiComIF::sendMessage: Too much data sent, send length" << sendLen << sif::warning << "SpiComIF::sendMessage: Too much data sent, send length " << sendLen <<
"larger than maximum buffer length" << spiCookie->getMaxBufferSize() << std::endl; "larger than maximum buffer length " << spiCookie->getMaxBufferSize() << std::endl;
#else #else
sif::printWarning("SpiComIF::sendMessage: Too much data sent, send length %lu larger " sif::printWarning("SpiComIF::sendMessage: Too much data sent, send length %lu larger "
"than maximum buffer length %lu!\n", static_cast<unsigned long>(sendLen), "than maximum buffer length %lu!\n", static_cast<unsigned long>(sendLen),
@ -193,7 +188,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
spiCookie->getSpiParameters(spiMode, spiSpeed, nullptr); spiCookie->getSpiParameters(spiMode, spiSpeed, nullptr);
setSpiSpeedAndMode(fileDescriptor, spiMode, spiSpeed); setSpiSpeedAndMode(fileDescriptor, spiMode, spiSpeed);
spiCookie->assignWriteBuffer(sendData); spiCookie->assignWriteBuffer(sendData);
spiCookie->assignTransferSize(sendLen); spiCookie->setTransferSize(sendLen);
bool fullDuplex = spiCookie->isFullDuplex(); bool fullDuplex = spiCookie->isFullDuplex();
gpioId_t gpioId = spiCookie->getChipSelectPin(); gpioId_t gpioId = spiCookie->getChipSelectPin();
@ -202,12 +197,26 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
if(gpioId != gpio::NO_GPIO) { if(gpioId != gpio::NO_GPIO) {
result = spiMutex->lockMutex(timeoutType, timeoutMs); result = spiMutex->lockMutex(timeoutType, timeoutMs);
if (result != RETURN_OK) { if (result != RETURN_OK) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "SpiComIF::sendMessage: Failed to lock mutex" << std::endl; sif::error << "SpiComIF::sendMessage: Failed to lock mutex" << std::endl;
#else
sif::printError("SpiComIF::sendMessage: Failed to lock mutex\n");
#endif
#endif
return result;
}
ReturnValue_t result = gpioComIF->pullLow(gpioId);
if(result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "SpiComIF::sendMessage: Pulling low CS pin failed" << std::endl;
#else
sif::printWarning("SpiComIF::sendMessage: Pulling low CS pin failed");
#endif
#endif #endif
return result; return result;
} }
gpioComIF->pullLow(gpioId);
} }
/* Execute transfer */ /* Execute transfer */
@ -218,7 +227,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
utility::handleIoctlError("SpiComIF::sendMessage: ioctl error."); utility::handleIoctlError("SpiComIF::sendMessage: ioctl error.");
result = FULL_DUPLEX_TRANSFER_FAILED; result = FULL_DUPLEX_TRANSFER_FAILED;
} }
#if FSFW_HAL_LINUX_SPI_WIRETAPPING == 1 #if FSFW_HAL_SPI_WIRETAPPING == 1
performSpiWiretapping(spiCookie); performSpiWiretapping(spiCookie);
#endif /* FSFW_LINUX_SPI_WIRETAPPING == 1 */ #endif /* FSFW_LINUX_SPI_WIRETAPPING == 1 */
} }
@ -335,6 +344,7 @@ ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
*buffer = rxBuf; *buffer = rxBuf;
*size = spiCookie->getCurrentTransferSize(); *size = spiCookie->getCurrentTransferSize();
spiCookie->setTransferSize(0);
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
@ -388,11 +398,11 @@ GpioIF* SpiComIF::getGpioInterface() {
void SpiComIF::setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed) { void SpiComIF::setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed) {
int retval = ioctl(spiFd, SPI_IOC_WR_MODE, reinterpret_cast<uint8_t*>(&mode)); int retval = ioctl(spiFd, SPI_IOC_WR_MODE, reinterpret_cast<uint8_t*>(&mode));
if(retval != 0) { if(retval != 0) {
utility::handleIoctlError("SpiTestClass::performRm3100Test: Setting SPI mode failed!"); utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Setting SPI mode failed");
} }
retval = ioctl(spiFd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); retval = ioctl(spiFd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
if(retval != 0) { if(retval != 0) {
utility::handleIoctlError("SpiTestClass::performRm3100Test: Setting SPI speed failed!"); utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Setting SPI speed failed");
} }
} }

View File

@ -1,6 +1,7 @@
#ifndef LINUX_SPI_SPICOMIF_H_ #ifndef LINUX_SPI_SPICOMIF_H_
#define LINUX_SPI_SPICOMIF_H_ #define LINUX_SPI_SPICOMIF_H_
#include "fsfw/FSFW.h"
#include "spiDefinitions.h" #include "spiDefinitions.h"
#include "returnvalues/classIds.h" #include "returnvalues/classIds.h"
#include "fsfw_hal/common/gpio/GpioIF.h" #include "fsfw_hal/common/gpio/GpioIF.h"

View File

@ -121,7 +121,7 @@ bool SpiCookie::isFullDuplex() const {
return not this->halfDuplex; return not this->halfDuplex;
} }
void SpiCookie::assignTransferSize(size_t transferSize) { void SpiCookie::setTransferSize(size_t transferSize) {
spiTransferStruct.len = transferSize; spiTransferStruct.len = transferSize;
} }

View File

@ -103,10 +103,10 @@ public:
void assignReadBuffer(uint8_t* rx); void assignReadBuffer(uint8_t* rx);
void assignWriteBuffer(const uint8_t* tx); void assignWriteBuffer(const uint8_t* tx);
/** /**
* Assign size for the next transfer. * Set size for the next transfer. Set to 0 for no transfer
* @param transferSize * @param transferSize
*/ */
void assignTransferSize(size_t transferSize); void setTransferSize(size_t transferSize);
size_t getCurrentTransferSize() const; size_t getCurrentTransferSize() const;
struct UncommonParameters { struct UncommonParameters {
@ -158,8 +158,6 @@ private:
std::string spiDev, const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed, std::string spiDev, const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed,
spi::send_callback_function_t callback, void* args); spi::send_callback_function_t callback, void* args);
size_t currentTransferSize = 0;
address_t spiAddress; address_t spiAddress;
gpioId_t chipSelectPin; gpioId_t chipSelectPin;
std::string spiDevice; std::string spiDevice;