1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-23 08:06:13 +01:00

Improved average CV read time

Anticipate more zeros than 1s in a typical CV value
This commit is contained in:
Asbelos 2020-06-07 17:02:22 +01:00
parent d1843fe38e
commit f2ee681479

25
DCC.cpp
View File

@ -145,15 +145,17 @@ const ackOp PROGMEM WRITE_BYTE_PROG[] = {
const ackOp PROGMEM READ_CV_PROG[] = { const ackOp PROGMEM READ_CV_PROG[] = {
BASELINE, BASELINE,
STARTMERGE, //clear bit and byte values ready for merge pass STARTMERGE, //clear bit and byte values ready for merge pass
// each bit is validated against 1 (no need for zero validation as entire byte is validated at the end) // each bit is validated against 0 and the result inverted in MERGE
V1, WACK, MERGE, // read and merge bit 0 // this is because there tend to be more zeros in cv values than ones.
V1, WACK, MERGE, // read and merge bit 1 etc // There is no need for one validation as entire byte is validated at the end
V1, WACK, MERGE, V0, WACK, MERGE, // read and merge bit 0
V1, WACK, MERGE, V0, WACK, MERGE, // read and merge bit 1 etc
V1, WACK, MERGE, V0, WACK, MERGE,
V1, WACK, MERGE, V0, WACK, MERGE,
V1, WACK, MERGE, V0, WACK, MERGE,
V1, WACK, MERGE, V0, WACK, MERGE,
V0, WACK, MERGE,
V0, WACK, MERGE,
VB, WACK, ITCB, // verify merged byte and return it if acked ok VB, WACK, ITCB, // verify merged byte and return it if acked ok
FAIL }; // verification failed FAIL }; // verification failed
@ -380,9 +382,10 @@ void DCC::ackManagerLoop() {
ackManagerByte=0; ackManagerByte=0;
break; break;
case MERGE: // Merge previous wack response with byte value and update bit number (use for reading CV bytes) case MERGE: // Merge previous Validate zero wack response with byte value and update bit number (use for reading CV bytes)
ackManagerByte <<= 1; ackManagerByte <<= 1;
if (ackReceived) ackManagerByte |= 1; // ackReceived means bit is zero.
if (!ackReceived) ackManagerByte |= 1;
ackManagerBitNum--; ackManagerBitNum--;
break; break;