diff --git a/DCC.cpp b/DCC.cpp index e60cf25b..b2237617 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -309,6 +309,7 @@ void DCC::setAccessory(int address, byte port, bool gate, byte onoff /*= 2*/) { b[0] = address % 64 + 128; b[1] = ((((address / 64) % 8) << 4) + (port % 4 << 1) + gate % 2) ^ 0xF8; if (onoff != 0) { + DIAG(F("DCC::setAccessory(%d,%d,%d) ON"), address, port, gate); DCCWaveform::mainTrack.schedulePacket(b, 2, 3); // Repeat on packet three times #if defined(EXRAIL_ACTIVE) RMFT2::activateEvent(address<<2|port,gate); @@ -316,6 +317,7 @@ void DCC::setAccessory(int address, byte port, bool gate, byte onoff /*= 2*/) { } if (onoff != 1) { b[1] &= ~0x08; // set C to 0 + DIAG(F("DCC::setAccessory(%d,%d,%d) OFF"), address, port, gate); DCCWaveform::mainTrack.schedulePacket(b, 2, 3); // Repeat off packet three times } } diff --git a/DCCRMT.cpp b/DCCRMT.cpp index 24a6e000..f03f4908 100644 --- a/DCCRMT.cpp +++ b/DCCRMT.cpp @@ -86,6 +86,14 @@ void setDCCBit0Long(rmt_item32_t* item) { item->duration1 = DCC_0_HALFPERIOD + DCC_0_HALFPERIOD/10; } +// special short one to trigger scope +void setDCCBit1Short(rmt_item32_t* item) { + item->level0 = 1; + item->duration0 = DCC_1_HALFPERIOD/2; + item->level1 = 0; + item->duration1 = DCC_1_HALFPERIOD/2; +} + void setEOT(rmt_item32_t* item) { item->val = 0; } @@ -135,11 +143,17 @@ RMTChannel::RMTChannel(pinpair pins, bool isMain) { // preamble preambleLen = plen+2; // plen 1 bits, one 0 bit and one EOF marker preamble = (rmt_item32_t*)malloc(preambleLen*sizeof(rmt_item32_t)); - for (byte n=0; n 0) // we have still old work to do - return dataRepeat; + ret = dataRepeat; if (dataReady == true) // the packet is not copied out yet - return 1000; + ret = 1000; + if (buffer[0] == 129) { + DIAG(F("RMTfillData 129 %d %d"), buffer[1], ret); + } + if (ret > 0) + return ret; if (DATA_LEN(byteCount) > maxDataLen) { // this would overun our allocated memory for data DIAG(F("Can not convert DCC bytes # %d to DCC bits %d, buffer too small"), byteCount, maxDataLen); return -1; // something very broken, can not convert packet diff --git a/DCCRMT.h b/DCCRMT.h index 33257a04..691ca15c 100644 --- a/DCCRMT.h +++ b/DCCRMT.h @@ -39,6 +39,13 @@ class RMTChannel { void RMTprefill(); //int RMTfillData(dccPacket packet); int RMTfillData(const byte buffer[], byte byteCount, byte repeatCount); + inline void waitForDataCopy() { + while(1) { + if (dataReady == false) + break; + //DIAG(F("%d %d"), dataReady, dataRepeat); + } //do nothing and wait for interrupt to happen + }; inline bool busy() { if (dataRepeat > 0) // we have still old work to do return true; diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index 3d77e9e8..54615a29 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -280,6 +280,13 @@ void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repea if (byteCount > MAX_PACKET_SIZE) return; // allow for chksum byte checksum = 0; + if(isMainTrack) { + if (rmtMainChannel != NULL) + rmtMainChannel->waitForDataCopy(); + } else { + if (rmtProgChannel != NULL) + rmtProgChannel->waitForDataCopy(); + } for (byte b = 0; b < byteCount; b++) { checksum ^= buffer[b]; pendingPacket[b] = buffer[b]; diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index f47fd82c..52e43b04 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "c389fe9" +#define GITHUB_SHA "master-packetloss-202501161204Z" diff --git a/version.h b/version.h index c4c7ba4a..862f07bb 100644 --- a/version.h +++ b/version.h @@ -3,7 +3,8 @@ #include "StringFormatter.h" -#define VERSION "5.4.0" +#define VERSION "5.4.X" +// 5.4.X - bugfix branch // 5.4.0 - New version on master // 5.2.96 - EXRAIL additions XFWD() and XREV() // 5.2.95 - Release candidate for 5.4