From 5173a0c9cbfa062da0ba2368e84d0fe8e65066ab Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 26 Oct 2022 17:11:57 +0200 Subject: [PATCH] its the rad sensor --- bsp_q7s/callbacks/rwSpiCallback.cpp | 28 ++++++++++++------------ bsp_q7s/core/ObjectFactory.cpp | 12 +++++----- bsp_q7s/core/ObjectFactory.h | 2 +- bsp_q7s/em/emObjectFactory.cpp | 10 +++++++-- bsp_q7s/fmObjectFactory.cpp | 8 ++++--- fsfw | 2 +- mission/devices/GyroADIS1650XHandler.cpp | 8 +++---- mission/devices/PayloadPcduHandler.cpp | 12 +++++----- 8 files changed, 46 insertions(+), 36 deletions(-) diff --git a/bsp_q7s/callbacks/rwSpiCallback.cpp b/bsp_q7s/callbacks/rwSpiCallback.cpp index ae23d64d..74ede602 100644 --- a/bsp_q7s/callbacks/rwSpiCallback.cpp +++ b/bsp_q7s/callbacks/rwSpiCallback.cpp @@ -41,19 +41,19 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen uint8_t writeSize = 0; gpioId_t gpioId = cookie->getChipSelectPin(); - GpioIF* gpioIF = comIf->getGpioInterface(); + GpioIF& gpioIF = comIf->getGpioInterface(); MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING; uint32_t timeoutMs = 0; MutexIF* mutex = comIf->getCsMutex(); cookie->getMutexParams(timeoutType, timeoutMs); - if (mutex == nullptr or gpioIF == nullptr) { + if (mutex == nullptr) { sif::debug << "rwSpiCallback::spiCallback: Mutex or GPIO interface invalid" << std::endl; return returnvalue::FAILED; } int fileDescriptor = 0; const std::string& dev = comIf->getSpiDev(); - result = openSpi(dev, O_RDWR, gpioIF, gpioId, mutex, timeoutType, timeoutMs, fileDescriptor); + result = openSpi(dev, O_RDWR, &gpioIF, gpioId, mutex, timeoutType, timeoutMs, fileDescriptor); if (result != returnvalue::OK) { return result; } @@ -75,7 +75,7 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen if (write(fileDescriptor, writeBuffer, writeSize) != static_cast(writeSize)) { sif::error << "rwSpiCallback::spiCallback: Write failed!" << std::endl; - closeSpi(fileDescriptor, gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, &gpioIF, mutex); return RwHandler::SPI_WRITE_FAILURE; } @@ -100,7 +100,7 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen } if (write(fileDescriptor, writeBuffer, writeSize) != static_cast(writeSize)) { sif::error << "rwSpiCallback::spiCallback: Write failed!" << std::endl; - closeSpi(fileDescriptor, gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, &gpioIF, mutex); return RwHandler::SPI_WRITE_FAILURE; } idx++; @@ -112,14 +112,14 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen if (write(fileDescriptor, writeBuffer, writeSize) != static_cast(writeSize)) { sif::error << "rwSpiCallback::spiCallback: Write failed!" << std::endl; - closeSpi(fileDescriptor, gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, &gpioIF, mutex); return RwHandler::SPI_WRITE_FAILURE; } uint8_t* rxBuf = nullptr; result = comIf->getReadBuffer(cookie->getSpiAddress(), &rxBuf); if (result != returnvalue::OK) { - closeSpi(fileDescriptor, gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, &gpioIF, mutex); return result; } @@ -127,9 +127,9 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen // There must be a delay of at least 20 ms after sending the command. // Delay for 70 ms here and release the SPI bus for that duration. - closeSpi(fileDescriptor, gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, &gpioIF, mutex); usleep(RwDefinitions::SPI_REPLY_DELAY); - result = openSpi(dev, O_RDWR, gpioIF, gpioId, mutex, timeoutType, timeoutMs, fileDescriptor); + result = openSpi(dev, O_RDWR, &gpioIF, gpioId, mutex, timeoutType, timeoutMs, fileDescriptor); if (result != returnvalue::OK) { return result; } @@ -142,13 +142,13 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen for (int idx = 0; idx < 10; idx++) { if (read(fileDescriptor, &byteRead, 1) != 1) { sif::error << "rwSpiCallback::spiCallback: Read failed" << std::endl; - closeSpi(fileDescriptor, gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, &gpioIF, mutex); return RwHandler::SPI_READ_FAILURE; } if (idx == 0) { if (byteRead != FLAG_BYTE) { sif::error << "Invalid data, expected start marker" << std::endl; - closeSpi(fileDescriptor, gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, &gpioIF, mutex); return RwHandler::NO_START_MARKER; } } @@ -159,7 +159,7 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen if (idx == 9) { sif::error << "rwSpiCallback::spiCallback: Empty frame timeout" << std::endl; - closeSpi(fileDescriptor, gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, &gpioIF, mutex); return RwHandler::NO_REPLY; } } @@ -199,7 +199,7 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen continue; } else { sif::error << "rwSpiCallback::spiCallback: Invalid substitute" << std::endl; - closeSpi(fileDescriptor, gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, &gpioIF, mutex); result = RwHandler::INVALID_SUBSTITUTE; break; } @@ -233,7 +233,7 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen cookie->setTransferSize(decodedFrameLen); - closeSpi(fileDescriptor, gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, &gpioIF, mutex); return result; } diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index 36a9d590..07f3fe9c 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -145,10 +145,8 @@ void ObjectFactory::createCommunicationInterfaces(LinuxLibgpioIF** gpioComIF, Ua new CspComIF(objects::CSP_COM_IF); *i2cComIF = new I2cComIF(objects::I2C_COM_IF); *uartComIF = new UartComIF(objects::UART_COM_IF); - *spiMainComIF = new SpiComIF(objects::SPI_MAIN_COM_IF, q7s::SPI_DEFAULT_DEV, *gpioComIF); - *spiRWComIF = new SpiComIF(objects::SPI_RW_COM_IF, q7s::SPI_RW_DEV, *gpioComIF); - /* Adding gpios for chip select decoding to the gpioComIf */ - q7s::gpioCallbacks::initSpiCsDecoder(*gpioComIF); + *spiMainComIF = new SpiComIF(objects::SPI_MAIN_COM_IF, q7s::SPI_DEFAULT_DEV, **gpioComIF); + *spiRWComIF = new SpiComIF(objects::SPI_RW_COM_IF, q7s::SPI_RW_DEV, **gpioComIF); } void ObjectFactory::createPcduComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchIF** pwrSwitcher) { @@ -193,8 +191,11 @@ void ObjectFactory::createPcduComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchI #endif } -void ObjectFactory::createRadSensorComponent(LinuxLibgpioIF* gpioComIF) { +ReturnValue_t ObjectFactory::createRadSensorComponent(LinuxLibgpioIF* gpioComIF) { using namespace gpio; + if(gpioComIF == nullptr) { + return returnvalue::FAILED; + } GpioCookie* gpioCookieRadSensor = new GpioCookie; std::stringstream consumer; consumer << "0x" << std::hex << objects::RAD_SENSOR; @@ -220,6 +221,7 @@ void ObjectFactory::createRadSensorComponent(LinuxLibgpioIF* gpioComIF) { #if OBSW_DEBUG_RAD_SENSOR == 1 radSensor->enablePeriodicDataPrint(true); #endif + return returnvalue::OK; } void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComIF* uartComIF, diff --git a/bsp_q7s/core/ObjectFactory.h b/bsp_q7s/core/ObjectFactory.h index 88881090..76660f30 100644 --- a/bsp_q7s/core/ObjectFactory.h +++ b/bsp_q7s/core/ObjectFactory.h @@ -26,7 +26,7 @@ void createPcduComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchIF** pwrSwitcher void createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF, PowerSwitchIF* pwrSwitcher); void createTmpComponents(); -void createRadSensorComponent(LinuxLibgpioIF* gpioComIF); +ReturnValue_t createRadSensorComponent(LinuxLibgpioIF* gpioComIF); void createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComIF* uartComIF, PowerSwitchIF* pwrSwitcher); void createHeaterComponents(GpioIF* gpioIF, PowerSwitchIF* pwrSwitcher, HealthTableIF* healthTable); diff --git a/bsp_q7s/em/emObjectFactory.cpp b/bsp_q7s/em/emObjectFactory.cpp index 5361eacb..4fd6df50 100644 --- a/bsp_q7s/em/emObjectFactory.cpp +++ b/bsp_q7s/em/emObjectFactory.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -24,6 +25,9 @@ void ObjectFactory::produce(void* args) { I2cComIF* i2cComIF = nullptr; SpiComIF* spiRwComIF = nullptr; createCommunicationInterfaces(&gpioComIF, &uartComIF, &spiMainComIF, &i2cComIF, &spiRwComIF); + /* Adding gpios for chip select decoding to the gpioComIf */ + q7s::gpioCallbacks::initSpiCsDecoder(gpioComIF); + gpioCallbacks::disableAllDecoder(gpioComIF); // Hardware is usually not connected to EM, so we need to create dummies which replace lower // level components. @@ -33,7 +37,6 @@ void ObjectFactory::produce(void* args) { new CoreController(objects::CORE_CONTROLLER); - gpioCallbacks::disableAllDecoder(gpioComIF); PowerSwitchIF* pwrSwitcher = new DummyPowerSwitcher(objects::PCDU_HANDLER, 18, 0); static_cast(pwrSwitcher); @@ -47,7 +50,10 @@ void ObjectFactory::produce(void* args) { // createSolarArrayDeploymentComponents(); // createPayloadComponents(gpioComIF); // createHeaterComponents(gpioComIF, pwrSwitcher, healthTable); - createRadSensorComponent(gpioComIF); + + // TODO: Careful! Swichting this on somehow messes with the communication with the ProASIC + // and will cause xsc_boot_copy commands to always boot to 0 0 + // createRadSensorComponent(gpioComIF); #if OBSW_ADD_ACS_BOARD == 1 createAcsBoardComponents(gpioComIF, uartComIF, pwrSwitcher); diff --git a/bsp_q7s/fmObjectFactory.cpp b/bsp_q7s/fmObjectFactory.cpp index f38621f7..885f0def 100644 --- a/bsp_q7s/fmObjectFactory.cpp +++ b/bsp_q7s/fmObjectFactory.cpp @@ -1,3 +1,4 @@ +#include #include #include "OBSWConfig.h" @@ -23,10 +24,11 @@ void ObjectFactory::produce(void* args) { PowerSwitchIF* pwrSwitcher = nullptr; SpiComIF* spiRwComIF = nullptr; createCommunicationInterfaces(&gpioComIF, &uartComIF, &spiMainComIF, &i2cComIF, &spiRwComIF); - createTmpComponents(); - new CoreController(objects::CORE_CONTROLLER); - + /* Adding gpios for chip select decoding to the gpioComIf */ + q7s::gpioCallbacks::initSpiCsDecoder(gpioComIF); gpioCallbacks::disableAllDecoder(gpioComIF); + + new CoreController(objects::CORE_CONTROLLER); createPcduComponents(gpioComIF, &pwrSwitcher); createRadSensorComponent(gpioComIF); createSunSensorComponents(gpioComIF, spiMainComIF, pwrSwitcher, q7s::SPI_DEFAULT_DEV); diff --git a/fsfw b/fsfw index 1f05e6b2..60ff4117 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 1f05e6b297af8a6d310394e959c4d0cf13632831 +Subproject commit 60ff411721909bd6e4c34523a2248d8dca2507b1 diff --git a/mission/devices/GyroADIS1650XHandler.cpp b/mission/devices/GyroADIS1650XHandler.cpp index 5ff84a96..fe8d07c6 100644 --- a/mission/devices/GyroADIS1650XHandler.cpp +++ b/mission/devices/GyroADIS1650XHandler.cpp @@ -422,12 +422,12 @@ ReturnValue_t GyroADIS1650XHandler::spiSendCallback(SpiComIF *comIf, SpiCookie * cookie->setTransferSize(2); gpioId_t gpioId = cookie->getChipSelectPin(); - GpioIF *gpioIF = comIf->getGpioInterface(); + GpioIF& gpioIF = comIf->getGpioInterface(); MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING; uint32_t timeoutMs = 0; MutexIF *mutex = comIf->getCsMutex(); cookie->getMutexParams(timeoutType, timeoutMs); - if (mutex == nullptr or gpioIF == nullptr) { + if (mutex == nullptr) { #if OBSW_VERBOSE_LEVEL >= 1 sif::warning << "GyroADIS16507Handler::spiSendCallback: " "Mutex or GPIO interface invalid" @@ -453,7 +453,7 @@ ReturnValue_t GyroADIS1650XHandler::spiSendCallback(SpiComIF *comIf, SpiCookie * while (idx < sendLen) { // Pull SPI CS low. For now, no support for active high given if (gpioId != gpio::NO_GPIO) { - gpioIF->pullLow(gpioId); + gpioIF.pullLow(gpioId); } // Execute transfer @@ -468,7 +468,7 @@ ReturnValue_t GyroADIS1650XHandler::spiSendCallback(SpiComIF *comIf, SpiCookie * #endif /* FSFW_LINUX_SPI_WIRETAPPING == 1 */ if (gpioId != gpio::NO_GPIO) { - gpioIF->pullHigh(gpioId); + gpioIF.pullHigh(gpioId); } idx += 2; diff --git a/mission/devices/PayloadPcduHandler.cpp b/mission/devices/PayloadPcduHandler.cpp index d9e41c7f..725e05df 100644 --- a/mission/devices/PayloadPcduHandler.cpp +++ b/mission/devices/PayloadPcduHandler.cpp @@ -719,11 +719,11 @@ ReturnValue_t PayloadPcduHandler::transferAsTwo(SpiComIF* comIf, SpiCookie* cook cookie->setTransferSize(transferLen); gpioId_t gpioId = cookie->getChipSelectPin(); - GpioIF* gpioIF = comIf->getGpioInterface(); + GpioIF& gpioIF = comIf->getGpioInterface(); MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING; uint32_t timeoutMs = 0; MutexIF* mutex = comIf->getCsMutex(); - if (mutex == nullptr or gpioIF == nullptr) { + if (mutex == nullptr) { #if OBSW_VERBOSE_LEVEL >= 1 sif::warning << "GyroADIS16507Handler::spiSendCallback: " "Mutex or GPIO interface invalid" @@ -753,7 +753,7 @@ ReturnValue_t PayloadPcduHandler::transferAsTwo(SpiComIF* comIf, SpiCookie* cook transferStruct->len = transferLen; // Pull SPI CS low. For now, no support for active high given if (gpioId != gpio::NO_GPIO) { - gpioIF->pullLow(gpioId); + gpioIF.pullLow(gpioId); } // Execute transfer @@ -768,14 +768,14 @@ ReturnValue_t PayloadPcduHandler::transferAsTwo(SpiComIF* comIf, SpiCookie* cook #endif /* FSFW_LINUX_SPI_WIRETAPPING == 1 */ if (gpioId != gpio::NO_GPIO) { - gpioIF->pullHigh(gpioId); + gpioIF.pullHigh(gpioId); } transferStruct->tx_buf += transferLen; transferStruct->rx_buf += transferLen; transferStruct->len = plpcdu::TEMP_REPLY_SIZE - 1; if (gpioId != gpio::NO_GPIO) { - gpioIF->pullLow(gpioId); + gpioIF.pullLow(gpioId); } // Execute transfer @@ -790,7 +790,7 @@ ReturnValue_t PayloadPcduHandler::transferAsTwo(SpiComIF* comIf, SpiCookie* cook #endif /* FSFW_LINUX_SPI_WIRETAPPING == 1 */ if (gpioId != gpio::NO_GPIO) { - gpioIF->pullHigh(gpioId); + gpioIF.pullHigh(gpioId); } transferStruct->tx_buf = origTx;