diff --git a/bsp_q7s/boardconfig/busConf.h b/bsp_q7s/boardconfig/busConf.h index 5abd109b..3e8a4b49 100644 --- a/bsp_q7s/boardconfig/busConf.h +++ b/bsp_q7s/boardconfig/busConf.h @@ -17,7 +17,16 @@ static constexpr char UART_STAR_TRACKER_DEV[] = "/dev/ttyUL7"; static constexpr char UIO_PDEC_REGISTERS[] = "/dev/uio0"; static constexpr char UIO_PDEC_CONFIG_MEMORY[] = "/dev/uio2"; static constexpr char UIO_PDEC_RAM[] = "/dev/uio3"; -static constexpr char UIO_PTME_CONFIG[] = "/dev/uio4"; +static constexpr char UIO_PTME[] = "/dev/uio1"; +static constexpr int MAP_ID_PTME_CONFIG = 3; + +namespace uiomapids { + static const int PTME_VC0 = 0; + static const int PTME_VC1 = 1; + static const int PTME_VC2 = 2; + static const int PTME_VC3 = 3; + static const int PTME_CONFIG = 4; +} namespace gpioNames { static constexpr char GYRO_0_ADIS_CS[] = "gyro_0_adis_chip_select"; diff --git a/bsp_q7s/core/InitMission.cpp b/bsp_q7s/core/InitMission.cpp index 96a43a81..1828349b 100644 --- a/bsp_q7s/core/InitMission.cpp +++ b/bsp_q7s/core/InitMission.cpp @@ -115,12 +115,14 @@ void initmission::initTasks() { } #endif /* OBSW_USE_CCSDS_IP_CORE == 1 */ +#if OBSW_ADD_ACS_HANDLERS == 1 PeriodicTaskIF* acsCtrl = factory->createPeriodicTask( "ACS_CTRL", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.4, missedDeadlineFunc); result = acsCtrl->addComponent(objects::GPS_CONTROLLER); if (result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("ACS_CTRL", objects::GPS_CONTROLLER); } +#endif /* OBSW_ADD_ACS_HANDLERS */ #if BOARD_TE0720 == 0 // FS task, task interval does not matter because it runs in permanent loop, priority low diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index 6db63f30..a801852e 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -928,14 +928,18 @@ void ObjectFactory::createCcsdsComponents(LinuxLibgpioIF* gpioComIF) { gpioComIF->addGpios(gpioCookiePtmeIp); // Creating virtual channel interfaces - VcInterfaceIF* vc0 = new PapbVcInterface(objects::PAPB_VC0, gpioComIF, gpioIds::VC0_PAPB_BUSY, - gpioIds::VC0_PAPB_EMPTY, PtmeConfig::VC0_OFFSETT); - VcInterfaceIF* vc1 = new PapbVcInterface(objects::PAPB_VC1, gpioComIF, gpioIds::VC1_PAPB_BUSY, - gpioIds::VC1_PAPB_EMPTY, PtmeConfig::VC1_OFFSETT); - VcInterfaceIF* vc2 = new PapbVcInterface(objects::PAPB_VC2, gpioComIF, gpioIds::VC2_PAPB_BUSY, - gpioIds::VC2_PAPB_EMPTY, PtmeConfig::VC2_OFFSETT); - VcInterfaceIF* vc3 = new PapbVcInterface(objects::PAPB_VC3, gpioComIF, gpioIds::VC3_PAPB_BUSY, - gpioIds::VC3_PAPB_EMPTY, PtmeConfig::VC3_OFFSETT); + VcInterfaceIF* vc0 = + new PapbVcInterface(objects::PAPB_VC0, gpioComIF, gpioIds::VC0_PAPB_BUSY, + gpioIds::VC0_PAPB_EMPTY, q7s::UIO_PTME, q7s::uiomapids::PTME_VC0); + VcInterfaceIF* vc1 = + new PapbVcInterface(objects::PAPB_VC1, gpioComIF, gpioIds::VC1_PAPB_BUSY, + gpioIds::VC1_PAPB_EMPTY, q7s::UIO_PTME, q7s::uiomapids::PTME_VC1); + VcInterfaceIF* vc2 = + new PapbVcInterface(objects::PAPB_VC2, gpioComIF, gpioIds::VC2_PAPB_BUSY, + gpioIds::VC2_PAPB_EMPTY, q7s::UIO_PTME, q7s::uiomapids::PTME_VC2); + VcInterfaceIF* vc3 = + new PapbVcInterface(objects::PAPB_VC3, gpioComIF, gpioIds::VC3_PAPB_BUSY, + gpioIds::VC3_PAPB_EMPTY, q7s::UIO_PTME, q7s::uiomapids::PTME_VC3); // Creating ptme object and adding virtual channel interfaces Ptme* ptme = new Ptme(objects::PTME); @@ -944,8 +948,8 @@ void ObjectFactory::createCcsdsComponents(LinuxLibgpioIF* gpioComIF) { ptme->addVcInterface(ccsds::VC2, vc2); ptme->addVcInterface(ccsds::VC3, vc3); - PtmeAxiConfig* ptmeAxiConfig = new PtmeAxiConfig(objects::PTME_AXI_CONFIG, - std::string(q7s::UIO_PTME_CONFIG)); + PtmeAxiConfig* ptmeAxiConfig = + new PtmeAxiConfig(objects::PTME_AXI_CONFIG, q7s::UIO_PTME, q7s::uiomapids::PTME_CONFIG); TxRateSetterIF* txRateSetterIF = new PtmeRateSetter(objects::TX_RATE_SETTER, ptmeAxiConfig); CCSDSHandler* ccsdsHandler = new CCSDSHandler( objects::CCSDS_HANDLER, objects::PTME, objects::CCSDS_PACKET_DISTRIBUTOR, txRateSetterIF, diff --git a/linux/obc/PapbVcInterface.cpp b/linux/obc/PapbVcInterface.cpp index f144306c..50cee1d3 100644 --- a/linux/obc/PapbVcInterface.cpp +++ b/linux/obc/PapbVcInterface.cpp @@ -1,98 +1,101 @@ #include - +#include #include "fsfw/serviceinterface/ServiceInterface.h" PapbVcInterface::PapbVcInterface(object_id_t objectId, LinuxLibgpioIF* gpioComIF, - gpioId_t papbBusyId, gpioId_t papbEmptyId, uint32_t vcOffset) - : SystemObject(objectId), - gpioComIF(gpioComIF), - papbBusyId(papbBusyId), - papbEmptyId(papbEmptyId), - vcOffset(vcOffset) {} + gpioId_t papbBusyId, gpioId_t papbEmptyId, std::string uioFile, int mapNum) : + SystemObject(objectId), gpioComIF(gpioComIF), papbBusyId(papbBusyId), papbEmptyId( + papbEmptyId), uioFile(uioFile), mapNum(mapNum) { +} -PapbVcInterface::~PapbVcInterface() {} +PapbVcInterface::~PapbVcInterface() { +} -void PapbVcInterface::setRegisterAddress(uint32_t* ptmeBaseAddress) { - vcBaseReg = ptmeBaseAddress + vcOffset; +ReturnValue_t PapbVcInterface::initialize() { + UioMapper uioMapper(uioFile, mapNum); + return uioMapper.getMappedAdress(&vcBaseReg, UioMapper::Permissions::WRITE_ONLY); } ReturnValue_t PapbVcInterface::write(const uint8_t* data, size_t size) { - if (pollPapbBusySignal() == RETURN_OK) { - startPacketTransfer(); - } - - for (size_t idx = 0; idx < size; idx++) { if (pollPapbBusySignal() == RETURN_OK) { - *(vcBaseReg + DATA_REG_OFFSET) = static_cast(*(data + idx)); - } else { - sif::warning << "PapbVcInterface::write: Only written " << idx << " of " << size << " data" - << std::endl; - return RETURN_FAILED; + startPacketTransfer(); } - } - - if (pollPapbBusySignal() == RETURN_OK) { - endPacketTransfer(); - } - return RETURN_OK; + for (size_t idx = 0; idx < size; idx++) { + if (pollPapbBusySignal() == RETURN_OK) { + *(vcBaseReg + DATA_REG_OFFSET) = static_cast(*(data + idx)); + } else { + sif::warning << "PapbVcInterface::write: Only written " << idx << " of " << size + << " data" << std::endl; + return RETURN_FAILED; + } + } + if (pollPapbBusySignal() == RETURN_OK) { + endPacketTransfer(); + } + return RETURN_OK; } -void PapbVcInterface::startPacketTransfer() { *vcBaseReg = CONFIG_START; } +void PapbVcInterface::startPacketTransfer() { + *vcBaseReg = CONFIG_START; +} -void PapbVcInterface::endPacketTransfer() { *vcBaseReg = CONFIG_END; } +void PapbVcInterface::endPacketTransfer() { + *vcBaseReg = CONFIG_END; +} ReturnValue_t PapbVcInterface::pollPapbBusySignal() { - int papbBusyState = 0; - ReturnValue_t result = RETURN_OK; + int papbBusyState = 0; + ReturnValue_t result = RETURN_OK; - /** Check if PAPB interface is ready to receive data */ - result = gpioComIF->readGpio(papbBusyId, &papbBusyState); - if (result != RETURN_OK) { - sif::warning << "PapbVcInterface::pollPapbBusySignal: Failed to read papb busy signal" - << std::endl; - return RETURN_FAILED; - } - if (!papbBusyState) { - sif::warning << "PapbVcInterface::pollPapbBusySignal: PAPB busy" << std::endl; - return PAPB_BUSY; - } + /** Check if PAPB interface is ready to receive data */ + result = gpioComIF->readGpio(papbBusyId, &papbBusyState); + if (result != RETURN_OK) { + sif::warning << "PapbVcInterface::pollPapbBusySignal: Failed to read papb busy signal" + << std::endl; + return RETURN_FAILED; + } + if (!papbBusyState) { + sif::warning << "PapbVcInterface::pollPapbBusySignal: PAPB busy" << std::endl; + return PAPB_BUSY; + } - return RETURN_OK; + return RETURN_OK; } void PapbVcInterface::isVcInterfaceBufferEmpty() { - ReturnValue_t result = RETURN_OK; - int papbEmptyState = 1; + ReturnValue_t result = RETURN_OK; + int papbEmptyState = 1; - result = gpioComIF->readGpio(papbEmptyId, &papbEmptyState); + result = gpioComIF->readGpio(papbEmptyId, &papbEmptyState); - if (result != RETURN_OK) { - sif::warning << "PapbVcInterface::isVcInterfaceBufferEmpty: Failed to read papb empty signal" - << std::endl; + if (result != RETURN_OK) { + sif::warning + << "PapbVcInterface::isVcInterfaceBufferEmpty: Failed to read papb empty signal" + << std::endl; + return; + } + + if (papbEmptyState == 1) { + sif::debug << "PapbVcInterface::isVcInterfaceBufferEmpty: Buffer is empty" << std::endl; + } else { + sif::debug << "PapbVcInterface::isVcInterfaceBufferEmpty: Buffer is not empty" << std::endl; + } return; - } - - if (papbEmptyState == 1) { - sif::debug << "PapbVcInterface::isVcInterfaceBufferEmpty: Buffer is empty" << std::endl; - } else { - sif::debug << "PapbVcInterface::isVcInterfaceBufferEmpty: Buffer is not empty" << std::endl; - } - return; } ReturnValue_t PapbVcInterface::sendTestFrame() { - /** Size of one complete transfer frame data field amounts to 1105 bytes */ - uint8_t testPacket[1105]; + /** Size of one complete transfer frame data field amounts to 1105 bytes */ + uint8_t testPacket[1105]; - /** Fill one test packet */ - for (int idx = 0; idx < 1105; idx++) { - testPacket[idx] = static_cast(idx & 0xFF); - } + /** Fill one test packet */ + for (int idx = 0; idx < 1105; idx++) { + testPacket[idx] = static_cast(idx & 0xFF); + } - ReturnValue_t result = write(testPacket, 1105); - if (result != RETURN_OK) { - return result; - } + ReturnValue_t result = write(testPacket, 1105); + if (result != RETURN_OK) { + return result; + } - return RETURN_OK; + return RETURN_OK; } diff --git a/linux/obc/PapbVcInterface.h b/linux/obc/PapbVcInterface.h index e7d03a70..465d1bf9 100644 --- a/linux/obc/PapbVcInterface.h +++ b/linux/obc/PapbVcInterface.h @@ -27,14 +27,16 @@ class PapbVcInterface : public SystemObject, public VcInterfaceIF, public HasRet * @param papbEmptyId The ID of the GPIO which is connected to the PAPBEmpty signal of the * VcInterface IP Core. The signal is high when there are no packets in the * external buffer memory (BRAM). + * @param uioFile UIO file providing access to the PAPB bus + * @param mapNum Map number of UIO map associated with this virtual channel */ PapbVcInterface(object_id_t objectId, LinuxLibgpioIF* gpioComIF, gpioId_t papbBusyId, - gpioId_t papbEmptyId, uint32_t vcOffset); + gpioId_t papbEmptyId, std::string uioFile, int mapNum); virtual ~PapbVcInterface(); ReturnValue_t write(const uint8_t* data, size_t size) override; - void setRegisterAddress(uint32_t* ptmeBaseAddress) override; + ReturnValue_t initialize() override; private: static const uint8_t INTERFACE_ID = CLASS_ID::CCSDS_IP_CORE_BRIDGE; @@ -69,6 +71,9 @@ class PapbVcInterface : public SystemObject, public VcInterfaceIF, public HasRet /** High when external buffer memory of virtual channel is empty */ gpioId_t papbEmptyId = gpio::NO_GPIO; + std::string uioFile; + int mapNum = 0; + uint32_t* vcBaseReg = nullptr; uint32_t vcOffset = 0; diff --git a/linux/obc/Ptme.cpp b/linux/obc/Ptme.cpp index 237e66ab..3c3403e0 100644 --- a/linux/obc/Ptme.cpp +++ b/linux/obc/Ptme.cpp @@ -1,7 +1,7 @@ #include #include #include - +#include #include "PtmeConfig.h" #include "fsfw/serviceinterface/ServiceInterface.h" @@ -20,7 +20,8 @@ ReturnValue_t Ptme::initialize() { * Map uio device in virtual address space * PROT_WRITE: Map uio device in writable only mode */ - ptmeBaseAddress = static_cast(mmap(NULL, MAP_SIZE, PROT_WRITE, MAP_SHARED, fd, 0)); + ptmeBaseAddress = static_cast(mmap(NULL, MAP_SIZE, PROT_WRITE, MAP_SHARED, fd, + 0 * getpagesize())); if (ptmeBaseAddress == MAP_FAILED) { sif::error << "Ptme::initialize: Failed to map uio address" << std::endl; @@ -29,7 +30,7 @@ ReturnValue_t Ptme::initialize() { VcInterfaceMapIter iter; for (iter = vcInterfaceMap.begin(); iter != vcInterfaceMap.end(); iter++) { - iter->second->setRegisterAddress(ptmeBaseAddress); + iter->second->initialize(); } return RETURN_OK; diff --git a/linux/obc/Ptme.h b/linux/obc/Ptme.h index d85885bc..4e4e6862 100644 --- a/linux/obc/Ptme.h +++ b/linux/obc/Ptme.h @@ -49,7 +49,7 @@ class Ptme : public PtmeIF, public SystemObject, public HasReturnvaluesIF { static const int MAP_SIZE = 0x40000; #else /** Size of mapped address space */ - static const int MAP_SIZE = 0x40000; + static const int MAP_SIZE = 0x1000; #endif /* BOARD_TE0720 == 1 */ /** diff --git a/linux/obc/PtmeAxiConfig.cpp b/linux/obc/PtmeAxiConfig.cpp index 3ec45faa..fdf810de 100644 --- a/linux/obc/PtmeAxiConfig.cpp +++ b/linux/obc/PtmeAxiConfig.cpp @@ -1,9 +1,8 @@ -#include -#include #include "PtmeAxiConfig.h" #include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw_hal/linux/uio/UioMapper.h" -PtmeAxiConfig::PtmeAxiConfig(object_id_t objectId, std::string configAxiUio) : +PtmeAxiConfig::PtmeAxiConfig(object_id_t objectId, std::string configAxiUio, int mapNum) : SystemObject(objectId), configAxiUio(configAxiUio) { mutex = MutexFactory::instance()->createMutex(); if (mutex == nullptr) { @@ -15,18 +14,11 @@ PtmeAxiConfig::~PtmeAxiConfig() { } ReturnValue_t PtmeAxiConfig::initialize() { - int fd = open(configAxiUio.c_str(), O_RDWR); - if (fd < 1) { - sif::warning << "PtmeAxiConfig::initialize: Invalid UIO device file" << std::endl; - return HasReturnvaluesIF::RETURN_FAILED; - } - - baseAddress = static_cast(mmap(NULL, MAP_SIZE, PROT_WRITE | PROT_READ, MAP_SHARED, - fd, 0)); - - if (baseAddress == MAP_FAILED) { - sif::warning << "PtmeAxiConfig::initialize: Failed to map uio address" << std::endl; - return HasReturnvaluesIF::RETURN_FAILED; + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + UioMapper uioMapper(configAxiUio, mapNum); + result = uioMapper.getMappedAdress(&baseAddress, UioMapper::Permissions::READ_WRITE); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; } return HasReturnvaluesIF::RETURN_OK; } diff --git a/linux/obc/PtmeAxiConfig.h b/linux/obc/PtmeAxiConfig.h index 2b3e9d26..1ea6c295 100644 --- a/linux/obc/PtmeAxiConfig.h +++ b/linux/obc/PtmeAxiConfig.h @@ -16,8 +16,9 @@ public: /** * @brief Constructor * @param configAxiUio Device file of UIO belonging to the AXI configuration interface. + * @param mapNum Number of map belonging to axi configuration interface. */ - PtmeAxiConfig(object_id_t objectId, std::string configAxiUio); + PtmeAxiConfig(object_id_t objectId, std::string configAxiUio, int mapNum); virtual ~PtmeAxiConfig(); virtual ReturnValue_t initialize() override; @@ -26,9 +27,10 @@ public: private: // Address of register storing the bitrate configuration parameter static const uint32_t CADU_BITRATE_REG = 0x0; - static const int MAP_SIZE = 0x1000; std::string configAxiUio; + std::string uioMap; + int mapNum = 0; MutexIF* mutex = nullptr; MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING; uint32_t mutexTimeout = 20; diff --git a/linux/obc/VcInterfaceIF.h b/linux/obc/VcInterfaceIF.h index 0aa95691..45226e21 100644 --- a/linux/obc/VcInterfaceIF.h +++ b/linux/obc/VcInterfaceIF.h @@ -24,7 +24,7 @@ class VcInterfaceIF { */ virtual ReturnValue_t write(const uint8_t* data, size_t size) = 0; - virtual void setRegisterAddress(uint32_t* ptmeBaseAddress) = 0; + virtual ReturnValue_t initialize() = 0; }; #endif /* LINUX_OBC_VCINTERFACEIF_H_ */