done and bugfree
This commit is contained in:
@ -5,18 +5,19 @@
|
||||
#include <fsfw/tasks/SemaphoreFactory.h>
|
||||
#include <fsfw/tasks/TaskFactory.h>
|
||||
#include <fsfw_hal/common/spi/spiCommon.h>
|
||||
#include <fsfw_hal/linux/utility.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "devConf.h"
|
||||
#include "mission/devices/devicedefinitions/rwHelpers.h"
|
||||
|
||||
RwPollingTask::RwPollingTask(object_id_t objectId, SpiComIF* spiIF)
|
||||
: SystemObject(objectId), spiIF(spiIF) {
|
||||
RwPollingTask::RwPollingTask(object_id_t objectId, const char* spiDev, GpioIF& gpioIF)
|
||||
: SystemObject(objectId), spiDev(spiDev), gpioIF(gpioIF) {
|
||||
semaphore = SemaphoreFactory::instance()->createBinarySemaphore();
|
||||
semaphore->acquire();
|
||||
ipcLock = MutexFactory::instance()->createMutex();
|
||||
spiLock = spiIF->getCsMutex();
|
||||
spiDev = spiIF->getSpiDev().c_str();
|
||||
spiLock = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
ReturnValue_t RwPollingTask::performOperation(uint8_t operationCode) {
|
||||
@ -79,13 +80,7 @@ ReturnValue_t RwPollingTask::performOperation(uint8_t operationCode) {
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t RwPollingTask::initialize() {
|
||||
if (spiDev == nullptr) {
|
||||
sif::error << "SPI device is invalid" << std::endl;
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
ReturnValue_t RwPollingTask::initialize() { return returnvalue::OK; }
|
||||
|
||||
ReturnValue_t RwPollingTask::initializeInterface(CookieIF* cookie) {
|
||||
// We don't need to set the speed because a SPI core is used, but the mode has to be set once
|
||||
@ -96,7 +91,16 @@ ReturnValue_t RwPollingTask::initializeInterface(CookieIF* cookie) {
|
||||
sif::error << "could not open RW SPI bus" << std::endl;
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
spiIF->setSpiSpeedAndMode(fd, spi::RW_MODE, spi::RW_SPEED);
|
||||
spi::SpiModes mode = spi::RW_MODE;
|
||||
int retval = ioctl(fd, SPI_IOC_WR_MODE, reinterpret_cast<uint8_t*>(&mode));
|
||||
if (retval != 0) {
|
||||
utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Setting SPI mode failed");
|
||||
}
|
||||
|
||||
retval = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &spi::RW_SPEED);
|
||||
if (retval != 0) {
|
||||
utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Setting SPI speed failed");
|
||||
}
|
||||
close(fd);
|
||||
modeAndSpeedWasSet = true;
|
||||
}
|
||||
@ -201,7 +205,6 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
int fd = 0;
|
||||
gpioId_t gpioId = rwCookie.getChipSelectPin();
|
||||
GpioIF& gpioIF = spiIF->getGpioInterface();
|
||||
pullCsLow(gpioId, spiLock, gpioIF);
|
||||
uint8_t byteRead = 0;
|
||||
for (unsigned idx = 0; idx < MAX_RETRIES_REPLY; idx++) {
|
||||
@ -439,7 +442,6 @@ void RwPollingTask::closeSpi(int fd) {
|
||||
|
||||
ReturnValue_t RwPollingTask::sendOneMessage(int fd, RwCookie& rwCookie) {
|
||||
gpioId_t gpioId = rwCookie.getChipSelectPin();
|
||||
GpioIF& gpioIF = spiIF->getGpioInterface();
|
||||
if (spiLock == nullptr) {
|
||||
sif::debug << "rwSpiCallback::spiCallback: Mutex or GPIO interface invalid" << std::endl;
|
||||
return returnvalue::FAILED;
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
#include <fsfw/tasks/ExecutableObjectIF.h>
|
||||
#include <fsfw/tasks/SemaphoreIF.h>
|
||||
#include <fsfw_hal/common/gpio/GpioIF.h>
|
||||
#include <fsfw_hal/linux/spi/SpiComIF.h>
|
||||
#include <fsfw_hal/linux/spi/SpiCookie.h>
|
||||
|
||||
@ -30,7 +31,7 @@ class RwCookie : public SpiCookie {
|
||||
|
||||
class RwPollingTask : public SystemObject, public ExecutableObjectIF, public DeviceCommunicationIF {
|
||||
public:
|
||||
RwPollingTask(object_id_t objectId, SpiComIF* spiIF);
|
||||
RwPollingTask(object_id_t objectId, const char* spiDev, GpioIF& gpioIF);
|
||||
|
||||
ReturnValue_t performOperation(uint8_t operationCode) override;
|
||||
ReturnValue_t initialize() override;
|
||||
@ -43,7 +44,7 @@ class RwPollingTask : public SystemObject, public ExecutableObjectIF, public Dev
|
||||
MutexIF* ipcLock;
|
||||
MutexIF* spiLock;
|
||||
const char* spiDev;
|
||||
SpiComIF* spiIF;
|
||||
GpioIF& gpioIF;
|
||||
std::array<bool, 4> skipCommandingForRw;
|
||||
std::array<DeviceCommandId_t, 4> specialRequestIds;
|
||||
std::array<RwCookie*, 4> rwCookies;
|
||||
|
Reference in New Issue
Block a user