1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-26 17:46:14 +01:00

memory saving

This commit is contained in:
Asbelos 2024-10-27 12:28:59 +00:00
parent 158cb47474
commit f910e75da0
3 changed files with 16 additions and 5 deletions

View File

@ -481,6 +481,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
DCC::writeCVByteMain(p[0], p[1], p[2]); DCC::writeCVByteMain(p[0], p[1], p[2]);
return; return;
#ifdef HAS_ENOUGH_MEMORY
case 'r': // READ CV on MAIN <r CAB CV> Requires Railcom case 'r': // READ CV on MAIN <r CAB CV> Requires Railcom
if (params != 2) if (params != 2)
break; break;
@ -488,6 +489,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
if (!stashCallback(stream, p, ringStream)) break; if (!stashCallback(stream, p, ringStream)) break;
DCC::readCVByteMain(p[0], p[1],callback_r); DCC::readCVByteMain(p[0], p[1],callback_r);
return; return;
#endif
case 'b': // WRITE CV BIT ON MAIN <b CAB CV BIT VALUE> case 'b': // WRITE CV BIT ON MAIN <b CAB CV BIT VALUE>
if (params != 4) if (params != 4)
@ -1129,7 +1131,7 @@ bool DCCEXParser::parseC(Print *stream, int16_t params, int16_t p[]) {
DCC::setGlobalSpeedsteps(128); DCC::setGlobalSpeedsteps(128);
DIAG(F("128 Speedsteps")); DIAG(F("128 Speedsteps"));
return true; return true;
#if defined(HAS_ENOUGH_MEMORY) && !defined(ARDUINO_ARCH_UNO) && !defined(ARDUINO_ARCH_ESP32) #if defined(HAS_ENOUGH_MEMORY)
case "RAILCOM"_hk: case "RAILCOM"_hk:
{ // <C RAILCOM ON|OFF|DEBUG > { // <C RAILCOM ON|OFF|DEBUG >
if (params<2) return false; if (params<2) return false;
@ -1213,11 +1215,11 @@ bool DCCEXParser::parseD(Print *stream, int16_t params, int16_t p[])
Diag::CMD = onOff; Diag::CMD = onOff;
return true; return true;
#ifdef HAS_ENOUGH_MEMORY
case "RAILCOM"_hk: // <D RAILCOM ON/OFF> case "RAILCOM"_hk: // <D RAILCOM ON/OFF>
Diag::RAILCOM = onOff; Diag::RAILCOM = onOff;
return true; return true;
#ifdef HAS_ENOUGH_MEMORY
case "WIFI"_hk: // <D WIFI ON/OFF> case "WIFI"_hk: // <D WIFI ON/OFF>
Diag::WIFI = onOff; Diag::WIFI = onOff;
return true; return true;

View File

@ -74,12 +74,14 @@ void DCCWaveform::loop() {
void DCCWaveform::interruptHandler() { void DCCWaveform::interruptHandler() {
// call the timer edge sensitive actions for progtrack and maintrack // call the timer edge sensitive actions for progtrack and maintrack
// member functions would be cleaner but have more overhead // member functions would be cleaner but have more overhead
#if defined(HAS_ENOUGH_MEMORY)
if (cutoutNextTime) { if (cutoutNextTime) {
cutoutNextTime=false; cutoutNextTime=false;
railcomSampleWindow=false; // about to cutout, stop reading railcom data. railcomSampleWindow=false; // about to cutout, stop reading railcom data.
railcomCutoutCounter++; railcomCutoutCounter++;
DCCTimer::startRailcomTimer(9); DCCTimer::startRailcomTimer(9);
} }
#endif
byte sigMain=signalTransform[mainTrack.state]; byte sigMain=signalTransform[mainTrack.state];
byte sigProg=TrackManager::progTrackSyncMain? sigMain : signalTransform[progTrack.state]; byte sigProg=TrackManager::progTrackSyncMain? sigMain : signalTransform[progTrack.state];
@ -160,6 +162,8 @@ void DCCWaveform::interrupt2() {
reminderWindowOpen=transmitRepeats==0 && remainingPreambles<10 && remainingPreambles>1; reminderWindowOpen=transmitRepeats==0 && remainingPreambles<10 && remainingPreambles>1;
if (remainingPreambles==1) if (remainingPreambles==1)
promotePendingPacket(); promotePendingPacket();
#if defined(HAS_ENOUGH_MEMORY)
else if (isMainTrack && railcomActive) { else if (isMainTrack && railcomActive) {
if (remainingPreambles==(requiredPreambles-1)) { if (remainingPreambles==(requiredPreambles-1)) {
// First look if we need to start a railcom cutout on next interrupt // First look if we need to start a railcom cutout on next interrupt
@ -179,6 +183,7 @@ void DCCWaveform::interrupt2() {
DCCTimer::ackRailcomTimer(); DCCTimer::ackRailcomTimer();
} }
} }
#endif
// Update free memory diagnostic as we don't have anything else to do this time. // Update free memory diagnostic as we don't have anything else to do this time.
// Allow for checkAck and its called functions using 22 bytes more. // Allow for checkAck and its called functions using 22 bytes more.
else DCCTimer::updateMinimumFreeMemoryISR(22); else DCCTimer::updateMinimumFreeMemoryISR(22);

View File

@ -14,11 +14,15 @@ Some CPUs require very specific choice of brake pins etc to match their internal
- Nucleo ... TBA - Nucleo ... TBA
Enabling the Railcom Cutout requires a `<C RAILCOM ON>` command. This can be added to myAutomation using `PARSE("<C RAILCOM ON>")` Enabling the Railcom Cutout requires a `<C RAILCOM ON>` command. This can be added to myAutomation using `PARSE("<C RAILCOM ON>")`
Code to calculate the cutout position and provide synchronization for the sampling is in `DCCWaveform.cpp` (not ESP32)
and in general a global search for "railcom" will show all code changes that have been made to support this.
Code to actually implement the timing of the cutout is hihjly cpu dependent and can be found in gthe various implementations of `DCCTimer.h`. At this time only `DCCTimerAVR.cpp`has implemented this.
Reading Railcom data: Reading Railcom data:
A new HAL handler has been added to process input from a 2-block railcom reader (Refer Henk) which operates as a 2 channel UART accessible over I2C. The reader(s) sit between the CS and the track and collect railcom data from locos during the cutout. A new HAL handler (`IO_I2CRailcom.h`)has been added to process input from a 2-block railcom reader (Refer Henk) which operates as a 2 channel UART accessible over I2C. The reader(s) sit between the CS and the track and collect railcom data from locos during the cutout.
After the cutout the HAL driver reads the UARTs over I2C and passes the raw data to the CS logic for analysis. After the cutout the HAL driver reads the UARTs over I2C and passes the raw data to the CS logic (`Railcom.cpp`)for analysis.
Each 2-block reader is described in myAutomation like `HAL(I2CRailcom,10000,2,0x48)` which will assign 2 channels on i2c address 0x48 with vpin numbers 10000 and 10001. If you only use the first channel in the reader, just asign one pin instead of two. Each 2-block reader is described in myAutomation like `HAL(I2CRailcom,10000,2,0x48)` which will assign 2 channels on i2c address 0x48 with vpin numbers 10000 and 10001. If you only use the first channel in the reader, just asign one pin instead of two.
(Implementation notes.. potentially other readers are possible with suitable HAL drivers. There are however several touch-points with the code DCC Waveform code which helps the HAL driver to understand when the data is safe to sample, and how to interpret responses when the sender is unknown. ) (Implementation notes.. potentially other readers are possible with suitable HAL drivers. There are however several touch-points with the code DCC Waveform code which helps the HAL driver to understand when the data is safe to sample, and how to interpret responses when the sender is unknown. )