From 8113a71c79b94ae7b72ff6d5cc4d26715d7ce497 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 31 May 2023 14:15:54 +0200 Subject: [PATCH 1/4] PAPB VC simplification --- linux/ipcore/PapbVcInterface.cpp | 93 ++++++++++++++++---------------- linux/ipcore/PapbVcInterface.h | 3 +- 2 files changed, 47 insertions(+), 49 deletions(-) diff --git a/linux/ipcore/PapbVcInterface.cpp b/linux/ipcore/PapbVcInterface.cpp index 97eb9954..1920e932 100644 --- a/linux/ipcore/PapbVcInterface.cpp +++ b/linux/ipcore/PapbVcInterface.cpp @@ -28,7 +28,7 @@ ReturnValue_t PapbVcInterface::write(const uint8_t* data, size_t size) { if (size < 4) { return returnvalue::FAILED; } - if (pollInterfaceReadiness(0, true) == returnvalue::OK) { + if (not pollReadyForPacket()) { startPacketTransfer(ByteWidthCfg::ONE); } else { return DirectTmSinkIF::IS_BUSY; @@ -65,19 +65,19 @@ ReturnValue_t PapbVcInterface::write(const uint8_t* data, size_t size) { // idx += 4; // } for (size_t idx = 0; idx < size; idx++) { - if (pollInterfaceReadiness(2, false) == returnvalue::OK) { - *(vcBaseReg + DATA_REG_OFFSET) = static_cast(data[idx]); - } else { - abortPacketTransfer(); - return returnvalue::FAILED; - } - } - if (pollInterfaceReadiness(2, false) == returnvalue::OK) { - completePacketTransfer(); - } else { - abortPacketTransfer(); - return returnvalue::FAILED; + // if (pollInterfaceReadiness(2, false) == returnvalue::OK) { + *(vcBaseReg + DATA_REG_OFFSET) = static_cast(data[idx]); + //} else { + // abortPacketTransfer(); + // return returnvalue::FAILED; + //} } + // if (pollInterfaceReadiness(2, false) == returnvalue::OK) { + completePacketTransfer(); + //} else { + // abortPacketTransfer(); + // return returnvalue::FAILED; + //} return returnvalue::OK; } @@ -87,40 +87,39 @@ void PapbVcInterface::startPacketTransfer(ByteWidthCfg initWidth) { void PapbVcInterface::completePacketTransfer() { *vcBaseReg = CONFIG_END; } -ReturnValue_t PapbVcInterface::pollInterfaceReadiness(uint32_t maxPollRetries, - bool checkReadyForPacketState) const { - uint32_t busyIdx = 0; - nextDelay.tv_nsec = FIRST_DELAY_PAPB_POLLING_NS; +bool PapbVcInterface::pollReadyForPacket() const { + // uint32_t busyIdx = 0; + // nextDelay.tv_nsec = FIRST_DELAY_PAPB_POLLING_NS; - while (true) { - // Check if PAPB interface is ready to receive data. Use the configuration register for this. - // Bit 5, see PTME ptme_001_01-0-7-r2 Table 31. - uint32_t reg = *vcBaseReg; - bool busy = (reg >> 5) & 0b1; - bool readyForPacket = (reg >> 6) & 0b1; - if (checkReadyForPacketState) { - if (not busy and readyForPacket) { - return returnvalue::OK; - } else if (not busy and not readyForPacket) { - return PAPB_BUSY; - } - } else if (not busy) { - return returnvalue::OK; - } - - busyIdx++; - if (busyIdx >= maxPollRetries) { - return PAPB_BUSY; - } - - // Ignore signal handling here for now. - nanosleep(&nextDelay, &remDelay); - // Adaptive delay. - if (nextDelay.tv_nsec * 2 <= MAX_DELAY_PAPB_POLLING_NS) { - nextDelay.tv_nsec *= 2; - } - } - return returnvalue::OK; + // while (true) { + // Check if PAPB interface is ready to receive data. Use the configuration register for this. + // Bit 5, see PTME ptme_001_01-0-7-r2 Table 31. + uint32_t reg = *vcBaseReg; + // bool busy = (reg >> 5) & 0b1; + return (reg >> 6) & 0b1; + // if (checkReadyForPacketState) { + // if (not busy and readyForPacket) { + // return returnvalue::OK; + // } else if (not busy and not readyForPacket) { + // return PAPB_BUSY; + // } + // } else if (not busy) { + // return returnvalue::OK; + // } + // + // busyIdx++; + // if (busyIdx >= maxPollRetries) { + // return PAPB_BUSY; + // } + // + // // Ignore signal handling here for now. + // nanosleep(&nextDelay, &remDelay); + // // Adaptive delay. + // if (nextDelay.tv_nsec * 2 <= MAX_DELAY_PAPB_POLLING_NS) { + // nextDelay.tv_nsec *= 2; + // } + // } + // return returnvalue::OK; } bool PapbVcInterface::isVcInterfaceBufferEmpty() { @@ -141,7 +140,7 @@ bool PapbVcInterface::isVcInterfaceBufferEmpty() { return false; } -bool PapbVcInterface::isBusy() const { return pollInterfaceReadiness(0, true) == PAPB_BUSY; } +bool PapbVcInterface::isBusy() const { return not pollReadyForPacket(); } void PapbVcInterface::cancelTransfer() { abortPacketTransfer(); } diff --git a/linux/ipcore/PapbVcInterface.h b/linux/ipcore/PapbVcInterface.h index 71dd143b..ba6063b5 100644 --- a/linux/ipcore/PapbVcInterface.h +++ b/linux/ipcore/PapbVcInterface.h @@ -116,8 +116,7 @@ class PapbVcInterface : public VirtualChannelIF { * * @return returnvalue::OK when ready to receive data else PAPB_BUSY. */ - inline ReturnValue_t pollInterfaceReadiness(uint32_t maxPollRetries, - bool checkReadyForPacketState) const; + inline bool pollReadyForPacket() const; /** * @brief This function can be used for debugging to check whether there are packets in -- 2.34.1 From 442b1c94a62781f8f08f0a2fb1ec21426f09c1dc Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 31 May 2023 15:02:11 +0200 Subject: [PATCH 2/4] small fix --- linux/ipcore/PapbVcInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/ipcore/PapbVcInterface.cpp b/linux/ipcore/PapbVcInterface.cpp index 1920e932..fbc13fc5 100644 --- a/linux/ipcore/PapbVcInterface.cpp +++ b/linux/ipcore/PapbVcInterface.cpp @@ -28,7 +28,7 @@ ReturnValue_t PapbVcInterface::write(const uint8_t* data, size_t size) { if (size < 4) { return returnvalue::FAILED; } - if (not pollReadyForPacket()) { + if (pollReadyForPacket()) { startPacketTransfer(ByteWidthCfg::ONE); } else { return DirectTmSinkIF::IS_BUSY; -- 2.34.1 From 998110dea41ef042681134aec5c49e6de9cfad87 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 31 May 2023 16:10:52 +0200 Subject: [PATCH 3/4] back to somethng simple --- linux/ipcore/PapbVcInterface.cpp | 67 -------------------------------- 1 file changed, 67 deletions(-) diff --git a/linux/ipcore/PapbVcInterface.cpp b/linux/ipcore/PapbVcInterface.cpp index fbc13fc5..404f3653 100644 --- a/linux/ipcore/PapbVcInterface.cpp +++ b/linux/ipcore/PapbVcInterface.cpp @@ -33,51 +33,11 @@ ReturnValue_t PapbVcInterface::write(const uint8_t* data, size_t size) { } else { return DirectTmSinkIF::IS_BUSY; } - // TODO: This should work but does not.. :( - // size_t idx = 0; - // while (idx < size) { - // - // nanosleep(&BETWEEN_POLL_DELAY, &remDelay); - // if ((size - idx) < 4) { - // *vcBaseReg = CONFIG_DATA_INPUT | (size - idx - 1); - // usleep(1); - // } - // if (pollPapbBusySignal(2) == returnvalue::OK) { - // // vcBaseReg + DATA_REG_OFFSET + 3 = static_cast(data + idx); - // // vcBaseReg + DATA_REG_OFFSET + 2 = static_cast(data + idx + 1); - // // vcBaseReg + DATA_REG_OFFSET + 1 = static_cast(data + idx + 2); - // // vcBaseReg + DATA_REG_OFFSET = static_cast(data + idx + 3); - // - // // std::memcpy((vcBaseReg + DATA_REG_OFFSET), data + idx , nextWriteSize); - // *(vcBaseReg + DATA_REG_OFFSET) = *reinterpret_cast(data + idx); - // //uint8_t* byteReg = reinterpret_cast(vcBaseReg + DATA_REG_OFFSET); - // - // //byteReg[0] = data[idx]; - // //byteReg[1] = data[idx]; - // } else { - // abortPacketTransfer(); - // return returnvalue::FAILED; - // } - // // TODO: Change this after the bugfix. Right now, the PAPB ignores the content of the byte - // // width configuration.5 - // // It's okay to increment by a larger amount for the last segment here, loop will be over - // // in any case. - // idx += 4; - // } for (size_t idx = 0; idx < size; idx++) { // if (pollInterfaceReadiness(2, false) == returnvalue::OK) { *(vcBaseReg + DATA_REG_OFFSET) = static_cast(data[idx]); - //} else { - // abortPacketTransfer(); - // return returnvalue::FAILED; - //} } - // if (pollInterfaceReadiness(2, false) == returnvalue::OK) { completePacketTransfer(); - //} else { - // abortPacketTransfer(); - // return returnvalue::FAILED; - //} return returnvalue::OK; } @@ -88,38 +48,11 @@ void PapbVcInterface::startPacketTransfer(ByteWidthCfg initWidth) { void PapbVcInterface::completePacketTransfer() { *vcBaseReg = CONFIG_END; } bool PapbVcInterface::pollReadyForPacket() const { - // uint32_t busyIdx = 0; - // nextDelay.tv_nsec = FIRST_DELAY_PAPB_POLLING_NS; - - // while (true) { // Check if PAPB interface is ready to receive data. Use the configuration register for this. // Bit 5, see PTME ptme_001_01-0-7-r2 Table 31. uint32_t reg = *vcBaseReg; // bool busy = (reg >> 5) & 0b1; return (reg >> 6) & 0b1; - // if (checkReadyForPacketState) { - // if (not busy and readyForPacket) { - // return returnvalue::OK; - // } else if (not busy and not readyForPacket) { - // return PAPB_BUSY; - // } - // } else if (not busy) { - // return returnvalue::OK; - // } - // - // busyIdx++; - // if (busyIdx >= maxPollRetries) { - // return PAPB_BUSY; - // } - // - // // Ignore signal handling here for now. - // nanosleep(&nextDelay, &remDelay); - // // Adaptive delay. - // if (nextDelay.tv_nsec * 2 <= MAX_DELAY_PAPB_POLLING_NS) { - // nextDelay.tv_nsec *= 2; - // } - // } - // return returnvalue::OK; } bool PapbVcInterface::isVcInterfaceBufferEmpty() { -- 2.34.1 From a85b0a4a762c173d942d701e9185237601dd4ed6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 31 May 2023 16:31:50 +0200 Subject: [PATCH 4/4] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffce15e8..87083265 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ TODO: New firmware package version. ## Changed - Removed PTME busy/ready signals. Those were not used anyway because register reads are used now. +- APB bus access busy checking is not done anymore as this is performed by the bus itself now. # [v3.0.0] to be released -- 2.34.1