1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-23 12:51:24 +01:00

Make packetPending private and new access routine. Implement schedulePacket without packetPending variable for ESP32

This commit is contained in:
Harald Barth 2022-08-02 01:24:01 +02:00
parent 33c9155f6e
commit b09dba1213
3 changed files with 36 additions and 4 deletions

View File

@ -587,7 +587,7 @@ void DCC::loop() {
void DCC::issueReminders() {
// if the main track transmitter still has a pending packet, skip this time around.
if ( DCCWaveform::mainTrack.packetPending) return;
if ( DCCWaveform::mainTrack.getPacketPending()) return;
// This loop searches for a loco in the speed table starting at nextLoco and cycling back around
for (int reg=0;reg<MAX_LOCOS;reg++) {

View File

@ -191,6 +191,9 @@ void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repea
packetPending = true;
sentResetsSincePacket=0;
}
bool DCCWaveform::getPacketPending() {
return packetPending;
}
#endif
#ifdef ARDUINO_ARCH_ESP32
@ -203,7 +206,6 @@ RMTChannel *DCCWaveform::rmtProgChannel = NULL;
DCCWaveform::DCCWaveform(byte preambleBits, bool isMain) {
isMainTrack = isMain;
packetPending = false;
requiredPreambles = preambleBits;
}
void DCCWaveform::begin() {
@ -224,6 +226,34 @@ void DCCWaveform::begin() {
}
void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repeats) {
if (byteCount > MAX_PACKET_SIZE) return; // allow for chksum
byte checksum = 0;
for (byte b = 0; b < byteCount; b++) {
checksum ^= buffer[b];
pendingPacket[b] = buffer[b];
}
// buffer is MAX_PACKET_SIZE but pendingPacket is one bigger
pendingPacket[byteCount] = checksum;
pendingLength = byteCount + 1;
pendingRepeats = repeats;
sentResetsSincePacket=0;
{
int ret;
do {
if(isMainTrack)
ret = rmtMainChannel->RMTfillData(pendingPacket, pendingLength, pendingRepeats);
else
ret = rmtProgChannel->RMTfillData(pendingPacket, pendingLength, pendingRepeats);
} while(ret > 0);
}
}
bool DCCWaveform::getPacketPending() {
if(isMainTrack)
return rmtMainChannel->busy();
else
return rmtProgChannel->busy();
}
void DCCWaveform::loop() {
}

View File

@ -54,11 +54,13 @@ class DCCWaveform {
static DCCWaveform progTrack;
inline void clearRepeats() { transmitRepeats=0; }
void schedulePacket(const byte buffer[], byte byteCount, byte repeats);
volatile bool packetPending;
volatile byte sentResetsSincePacket;
bool getPacketPending();
private:
#ifndef ARDUINO_ARCH_ESP32
volatile bool packetPending;
#endif
static void interruptHandler();
void interrupt2();