From 8e63c452b26ef928301b4de4d01d2bdab4d8df0c Mon Sep 17 00:00:00 2001 From: Mike S Date: Thu, 25 Mar 2021 14:02:33 -0400 Subject: [PATCH] Fix a few bugs as a result of latest version --- DCCEXParser.cpp | 18 ++++++++------- freeMemory.cpp | 58 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 59 insertions(+), 17 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 2b75479..21f273a 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -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(""), 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(""), 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(""), stashP[0], stashP[1], result); commitAsyncReplyStream(); } -void DCCEXParser::callback_Vbyte(int result) +void DCCEXParser::callback_Vbyte(int16_t result) { StringFormatter::send(getAsyncReplyStream(), F(""), stashP[0], result); commitAsyncReplyStream(); } -void DCCEXParser::callback_R(int result) +void DCCEXParser::callback_R(int16_t result) { StringFormatter::send(getAsyncReplyStream(), F(""), 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(""), 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(""), result); diff --git a/freeMemory.cpp b/freeMemory.cpp index f640abe..5514e8d 100644 --- a/freeMemory.cpp +++ b/freeMemory.cpp @@ -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; -}