diff options
author | Christian Hammacher <bmasterc@gmail.com> | 2022-05-03 10:51:35 +0300 |
---|---|---|
committer | Christian Hammacher <bmasterc@gmail.com> | 2022-05-03 10:51:35 +0300 |
commit | dfdca829a063033685134e2df23b38ef5bb74208 (patch) | |
tree | dec27c68f3cd9a2781e2645f47898c5b1ca37fca | |
parent | 866309dc359ef71ee1d862d045206990f35eda94 (diff) |
Minor fixes for SBC mode
-rw-r--r-- | src/SBC/DataTransfer.cpp | 12 | ||||
-rw-r--r-- | src/SBC/DataTransfer.h | 3 | ||||
-rw-r--r-- | src/SBC/SbcInterface.cpp | 5 |
3 files changed, 8 insertions, 12 deletions
diff --git a/src/SBC/DataTransfer.cpp b/src/SBC/DataTransfer.cpp index f6fc1779..fe01c60d 100644 --- a/src/SBC/DataTransfer.cpp +++ b/src/SBC/DataTransfer.cpp @@ -996,22 +996,20 @@ void DataTransfer::StartNextTransfer() noexcept void DataTransfer::ResetConnection(bool fullReset) noexcept { - // The Sbc interface is no longer connected... + // Clear the remaining data to send disable_spi(); dataReceived = false; - - // Reset the sequence numbers and clear the data to send - lastTransferNumber = 0; - rxHeader.sequenceNumber = 0; - txHeader.sequenceNumber = 0; rxPointer = txPointer = 0; packetId = 0; - // Kick off a new transfer + // Reset the TfrRdy pin level and the seq numbers only if no communication is taking place if (fullReset) { transferReadyHigh = false; + lastTransferNumber = rxHeader.sequenceNumber = txHeader.sequenceNumber = 0; } + + // Kick off a new transfer StartNextTransfer(); } diff --git a/src/SBC/DataTransfer.h b/src/SBC/DataTransfer.h index 3520ed41..998a8b06 100644 --- a/src/SBC/DataTransfer.h +++ b/src/SBC/DataTransfer.h @@ -157,7 +157,8 @@ private: inline bool DataTransfer::IsConnectionReset() const noexcept { - return lastTransferNumber != 0 && (lastTransferNumber + 1 != rxHeader.sequenceNumber); + uint16_t nextTransferNumber = lastTransferNumber + 1u; + return (rxHeader.formatCode == SbcFormatCode) && (rxHeader.sequenceNumber != nextTransferNumber); } inline size_t DataTransfer::PacketsToRead() const noexcept diff --git a/src/SBC/SbcInterface.cpp b/src/SBC/SbcInterface.cpp index 7c039e95..0a7c68f3 100644 --- a/src/SBC/SbcInterface.cpp +++ b/src/SBC/SbcInterface.cpp @@ -180,10 +180,7 @@ void SbcInterface::Spin() noexcept } // Handle exchanged data and kick off the next transfer - if (!hadReset) - { - ExchangeData(); - } + ExchangeData(); transfer.StartNextTransfer(); } else if (hadTimeout || hadReset) |