PAPB VC simplification
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good

This commit is contained in:
Robin Müller 2023-05-31 14:15:54 +02:00
parent cc60847bd0
commit 8113a71c79
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
2 changed files with 47 additions and 49 deletions

View File

@ -28,7 +28,7 @@ ReturnValue_t PapbVcInterface::write(const uint8_t* data, size_t size) {
if (size < 4) { if (size < 4) {
return returnvalue::FAILED; return returnvalue::FAILED;
} }
if (pollInterfaceReadiness(0, true) == returnvalue::OK) { if (not pollReadyForPacket()) {
startPacketTransfer(ByteWidthCfg::ONE); startPacketTransfer(ByteWidthCfg::ONE);
} else { } else {
return DirectTmSinkIF::IS_BUSY; return DirectTmSinkIF::IS_BUSY;
@ -65,19 +65,19 @@ ReturnValue_t PapbVcInterface::write(const uint8_t* data, size_t size) {
// idx += 4; // idx += 4;
// } // }
for (size_t idx = 0; idx < size; idx++) { for (size_t idx = 0; idx < size; idx++) {
if (pollInterfaceReadiness(2, false) == returnvalue::OK) { // if (pollInterfaceReadiness(2, false) == returnvalue::OK) {
*(vcBaseReg + DATA_REG_OFFSET) = static_cast<uint32_t>(data[idx]); *(vcBaseReg + DATA_REG_OFFSET) = static_cast<uint32_t>(data[idx]);
} else { //} else {
abortPacketTransfer(); // abortPacketTransfer();
return returnvalue::FAILED; // return returnvalue::FAILED;
} //}
}
if (pollInterfaceReadiness(2, false) == returnvalue::OK) {
completePacketTransfer();
} else {
abortPacketTransfer();
return returnvalue::FAILED;
} }
// if (pollInterfaceReadiness(2, false) == returnvalue::OK) {
completePacketTransfer();
//} else {
// abortPacketTransfer();
// return returnvalue::FAILED;
//}
return returnvalue::OK; return returnvalue::OK;
} }
@ -87,40 +87,39 @@ void PapbVcInterface::startPacketTransfer(ByteWidthCfg initWidth) {
void PapbVcInterface::completePacketTransfer() { *vcBaseReg = CONFIG_END; } void PapbVcInterface::completePacketTransfer() { *vcBaseReg = CONFIG_END; }
ReturnValue_t PapbVcInterface::pollInterfaceReadiness(uint32_t maxPollRetries, bool PapbVcInterface::pollReadyForPacket() const {
bool checkReadyForPacketState) const { // uint32_t busyIdx = 0;
uint32_t busyIdx = 0; // nextDelay.tv_nsec = FIRST_DELAY_PAPB_POLLING_NS;
nextDelay.tv_nsec = FIRST_DELAY_PAPB_POLLING_NS;
while (true) { // while (true) {
// Check if PAPB interface is ready to receive data. Use the configuration register for this. // 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. // Bit 5, see PTME ptme_001_01-0-7-r2 Table 31.
uint32_t reg = *vcBaseReg; uint32_t reg = *vcBaseReg;
bool busy = (reg >> 5) & 0b1; // bool busy = (reg >> 5) & 0b1;
bool readyForPacket = (reg >> 6) & 0b1; return (reg >> 6) & 0b1;
if (checkReadyForPacketState) { // if (checkReadyForPacketState) {
if (not busy and readyForPacket) { // if (not busy and readyForPacket) {
return returnvalue::OK; // return returnvalue::OK;
} else if (not busy and not readyForPacket) { // } else if (not busy and not readyForPacket) {
return PAPB_BUSY; // return PAPB_BUSY;
} // }
} else if (not busy) { // } else if (not busy) {
return returnvalue::OK; // return returnvalue::OK;
} // }
//
busyIdx++; // busyIdx++;
if (busyIdx >= maxPollRetries) { // if (busyIdx >= maxPollRetries) {
return PAPB_BUSY; // return PAPB_BUSY;
} // }
//
// Ignore signal handling here for now. // // Ignore signal handling here for now.
nanosleep(&nextDelay, &remDelay); // nanosleep(&nextDelay, &remDelay);
// Adaptive delay. // // Adaptive delay.
if (nextDelay.tv_nsec * 2 <= MAX_DELAY_PAPB_POLLING_NS) { // if (nextDelay.tv_nsec * 2 <= MAX_DELAY_PAPB_POLLING_NS) {
nextDelay.tv_nsec *= 2; // nextDelay.tv_nsec *= 2;
} // }
} // }
return returnvalue::OK; // return returnvalue::OK;
} }
bool PapbVcInterface::isVcInterfaceBufferEmpty() { bool PapbVcInterface::isVcInterfaceBufferEmpty() {
@ -141,7 +140,7 @@ bool PapbVcInterface::isVcInterfaceBufferEmpty() {
return false; return false;
} }
bool PapbVcInterface::isBusy() const { return pollInterfaceReadiness(0, true) == PAPB_BUSY; } bool PapbVcInterface::isBusy() const { return not pollReadyForPacket(); }
void PapbVcInterface::cancelTransfer() { abortPacketTransfer(); } void PapbVcInterface::cancelTransfer() { abortPacketTransfer(); }

View File

@ -116,8 +116,7 @@ class PapbVcInterface : public VirtualChannelIF {
* *
* @return returnvalue::OK when ready to receive data else PAPB_BUSY. * @return returnvalue::OK when ready to receive data else PAPB_BUSY.
*/ */
inline ReturnValue_t pollInterfaceReadiness(uint32_t maxPollRetries, inline bool pollReadyForPacket() const;
bool checkReadyForPacketState) const;
/** /**
* @brief This function can be used for debugging to check whether there are packets in * @brief This function can be used for debugging to check whether there are packets in