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

Fix a few bugs as a result of latest version

This commit is contained in:
Mike S 2021-03-25 14:02:33 -04:00
parent 8141311e66
commit 8e63c452b2
2 changed files with 59 additions and 17 deletions

View File

@ -52,6 +52,8 @@ const int16_t HASH_KEYWORD_LIMIT = 27413;
const int16_t HASH_KEYWORD_ETHERNET = -30767;
const int16_t HASH_KEYWORD_MAX = 16244;
const int16_t HASH_KEYWORD_MIN = 15978;
const int16_t HASH_KEYWORD_LCN = 15137;
const int16_t HASH_KEYWORD_RESET = 26133;
int16_t DCCEXParser::stashP[MAX_COMMAND_PARAMS];
bool DCCEXParser::stashBusy;
@ -795,7 +797,7 @@ bool DCCEXParser::parseD(Print *stream, int16_t params, int16_t p[])
}
// CALLBACKS must be static
bool DCCEXParser::stashCallback(Print *stream, int p[MAX_COMMAND_PARAMS], RingStream * ringStream)
bool DCCEXParser::stashCallback(Print *stream, int16_t p[MAX_COMMAND_PARAMS], RingStream * ringStream)
{
if (stashBusy )
return false;
@ -820,43 +822,43 @@ void DCCEXParser::commitAsyncReplyStream() {
stashBusy = false;
}
void DCCEXParser::callback_W(int result)
void DCCEXParser::callback_W(int16_t result)
{
StringFormatter::send(getAsyncReplyStream(),
F("<r%d|%d|%d %d>"), stashP[2], stashP[3], stashP[0], result == 1 ? stashP[1] : -1);
commitAsyncReplyStream();
}
void DCCEXParser::callback_B(int result)
void DCCEXParser::callback_B(int16_t result)
{
StringFormatter::send(getAsyncReplyStream(),
F("<r%d|%d|%d %d %d>"), stashP[3], stashP[4], stashP[0], stashP[1], result == 1 ? stashP[2] : -1);
commitAsyncReplyStream();
}
void DCCEXParser::callback_Vbit(int result)
void DCCEXParser::callback_Vbit(int16_t result)
{
StringFormatter::send(getAsyncReplyStream(), F("<v %d %d %d>"), stashP[0], stashP[1], result);
commitAsyncReplyStream();
}
void DCCEXParser::callback_Vbyte(int result)
void DCCEXParser::callback_Vbyte(int16_t result)
{
StringFormatter::send(getAsyncReplyStream(), F("<v %d %d>"), stashP[0], result);
commitAsyncReplyStream();
}
void DCCEXParser::callback_R(int result)
void DCCEXParser::callback_R(int16_t result)
{
StringFormatter::send(getAsyncReplyStream(), F("<r%d|%d|%d %d>"), stashP[1], stashP[2], stashP[0], result);
commitAsyncReplyStream();
}
void DCCEXParser::callback_Rloco(int result)
void DCCEXParser::callback_Rloco(int16_t result)
{
StringFormatter::send(getAsyncReplyStream(), F("<r %d>"), result);
commitAsyncReplyStream();
}
void DCCEXParser::callback_Wloco(int result)
void DCCEXParser::callback_Wloco(int16_t result)
{
if (result==1) result=stashP[0]; // pick up original requested id from command
StringFormatter::send(getAsyncReplyStream(), F("<w %d>"), result);

View File

@ -34,7 +34,7 @@ extern char *__malloc_heap_start;
static volatile int minimum_free_memory = __INT_MAX__;
#if !defined(__IMXRT1062__)
static inline int freeMemory() {
char top;
#if defined(__arm__)
@ -46,6 +46,54 @@ static inline int freeMemory() {
#endif
}
// Return low memory value.
int minimumFreeMemory() {
byte sreg_save = SREG;
noInterrupts(); // Disable interrupts
int retval = minimum_free_memory;
SREG = sreg_save; // Restore interrupt state
return retval;
}
#else
#if defined(ARDUINO_TEENSY40)
static const unsigned DTCM_START = 0x20000000UL;
static const unsigned OCRAM_START = 0x20200000UL;
static const unsigned OCRAM_SIZE = 512;
static const unsigned FLASH_SIZE = 1984;
#elif defined(ARDUINO_TEENSY41)
static const unsigned DTCM_START = 0x20000000UL;
static const unsigned OCRAM_START = 0x20200000UL;
static const unsigned OCRAM_SIZE = 512;
static const unsigned FLASH_SIZE = 7936;
#if TEENSYDUINO>151
extern "C" uint8_t external_psram_size;
#endif
#endif
static inline int freeMemory() {
extern unsigned long _ebss;
extern unsigned long _sdata;
extern unsigned long _estack;
const unsigned DTCM_START = 0x20000000UL;
unsigned dtcm = (unsigned)&_estack - DTCM_START;
unsigned stackinuse = (unsigned) &_estack - (unsigned) __builtin_frame_address(0);
unsigned varsinuse = (unsigned)&_ebss - (unsigned)&_sdata;
unsigned freemem = dtcm - (stackinuse + varsinuse);
return freemem;
}
// Return low memory value.
int minimumFreeMemory() {
//byte sreg_save = SREG;
//noInterrupts(); // Disable interrupts
int retval = minimum_free_memory;
//SREG = sreg_save; // Restore interrupt state
return retval;
}
#endif
// Update low ram level. Allow for extra bytes to be specified
// by estimation or inspection, that may be used by other
// called subroutines. Must be called with interrupts disabled.
@ -61,11 +109,3 @@ void updateMinimumFreeMemory(unsigned char extraBytes) {
if (spare < minimum_free_memory) minimum_free_memory = spare;
}
// Return low memory value.
int minimumFreeMemory() {
byte sreg_save = SREG;
noInterrupts(); // Disable interrupts
int retval = minimum_free_memory;
SREG = sreg_save; // Restore interrupt state
return retval;
}