Skip to content

Commit

Permalink
Add NeoSerialDebug define
Browse files Browse the repository at this point in the history
  • Loading branch information
Mythologyli committed Apr 19, 2021
1 parent e2c5acb commit 63e8387
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 44 deletions.
40 changes: 20 additions & 20 deletions src/MemoryUsage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,24 @@ void SRamDisplay(void)

available -= data_size + bss_size + heap_size + stack_size;

NeoSerial.print(F("+----------------+ ")); NeoSerial.print((int)&__data_start); NeoSerial.println(" (__data_start)");
NeoSerial.print(F("+ data +")); NeoSerial.println();
NeoSerial.print(F("+ variables + size = ")); NeoSerial.println(data_size);
NeoSerial.print(F("+----------------+ ")); NeoSerial.print((int)&__data_end); NeoSerial.println(" (__data_end / __bss_start)");
NeoSerial.print(F("+ bss +")); NeoSerial.println();
NeoSerial.print(F("+ variables + size = ")); NeoSerial.println(bss_size);
NeoSerial.print(F("+----------------+ ")); NeoSerial.print((int)&__bss_end); NeoSerial.println(" (__bss_end / __heap_start)");
NeoSerial.print(F("+ heap + size = ")); NeoSerial.println(heap_size);
NeoSerial.print(F("+----------------+ ")); NeoSerial.print((int)heap_end); NeoSerial.println(" (__brkval if not 0, or __heap_start)");
NeoSerial.print(F("+ +")); NeoSerial.println();
NeoSerial.print(F("+ +")); NeoSerial.println();
NeoSerial.print(F("+ FREE RAM + size = ")); NeoSerial.println(available);
NeoSerial.print(F("+ +")); NeoSerial.println();
NeoSerial.print(F("+ +")); NeoSerial.println();
NeoSerial.print(F("+----------------+ ")); NeoSerial.print((int)SP); NeoSerial.println(" (SP)");
NeoSerial.print(F("+ stack + size = ")); NeoSerial.println(stack_size);
NeoSerial.print(F("+----------------+ ")); NeoSerial.print((int)RAMEND); NeoSerial.println(" (RAMEND / __stack)");

NeoSerial.println();
NeoSerial.println();
NeoSerialDebug.print(F("+----------------+ ")); NeoSerialDebug.print((int)&__data_start); NeoSerialDebug.println(" (__data_start)");
NeoSerialDebug.print(F("+ data +")); NeoSerialDebug.println();
NeoSerialDebug.print(F("+ variables + size = ")); NeoSerialDebug.println(data_size);
NeoSerialDebug.print(F("+----------------+ ")); NeoSerialDebug.print((int)&__data_end); NeoSerialDebug.println(" (__data_end / __bss_start)");
NeoSerialDebug.print(F("+ bss +")); NeoSerialDebug.println();
NeoSerialDebug.print(F("+ variables + size = ")); NeoSerialDebug.println(bss_size);
NeoSerialDebug.print(F("+----------------+ ")); NeoSerialDebug.print((int)&__bss_end); NeoSerialDebug.println(" (__bss_end / __heap_start)");
NeoSerialDebug.print(F("+ heap + size = ")); NeoSerialDebug.println(heap_size);
NeoSerialDebug.print(F("+----------------+ ")); NeoSerialDebug.print((int)heap_end); NeoSerialDebug.println(" (__brkval if not 0, or __heap_start)");
NeoSerialDebug.print(F("+ +")); NeoSerialDebug.println();
NeoSerialDebug.print(F("+ +")); NeoSerialDebug.println();
NeoSerialDebug.print(F("+ FREE RAM + size = ")); NeoSerialDebug.println(available);
NeoSerialDebug.print(F("+ +")); NeoSerialDebug.println();
NeoSerialDebug.print(F("+ +")); NeoSerialDebug.println();
NeoSerialDebug.print(F("+----------------+ ")); NeoSerialDebug.print((int)SP); NeoSerialDebug.println(" (SP)");
NeoSerialDebug.print(F("+ stack + size = ")); NeoSerialDebug.println(stack_size);
NeoSerialDebug.print(F("+----------------+ ")); NeoSerialDebug.print((int)RAMEND); NeoSerialDebug.println(" (RAMEND / __stack)");

NeoSerialDebug.println();
NeoSerialDebug.println();
}
50 changes: 26 additions & 24 deletions src/MemoryUsage.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <stdint.h>
#include <NeoHWSerial.h>

#define NeoSerialDebug NeoSerial3

/*! \mainpage
A full explanation in french can be read at http://www.locoduino.org/ecrire/?exec=article&action=redirect&type=article&id=149 .
Expand Down Expand Up @@ -119,27 +121,27 @@ extern uint8_t *__bss_end;
// Memory addresses
//

/// Print data start on NeoSerial console.
#define MEMORY_PRINT_START { NeoSerial.print(F("Data start:")); NeoSerial.println((int) &__data_start); }
/// Print data end / heap start on NeoSerial console.
#define MEMORY_PRINT_HEAPSTART { NeoSerial.print(F("Heap start:")); NeoSerial.println((int)&__heap_start); }
/// Print heap end / free ram area on NeoSerial console.
#define MEMORY_PRINT_HEAPEND { NeoSerial.print(F("Heap end:")); NeoSerial.println(__brkval == 0 ? (int)&__heap_start : (int)__brkval); }
/// Print free ram end / stack start on NeoSerial console.
#define MEMORY_PRINT_STACKSTART { NeoSerial.print(F("Stack start:")); NeoSerial.println((int) SP); }
/// Print end of memory on NeoSerial console.
#define MEMORY_PRINT_END { NeoSerial.print(F("Stack end:")); NeoSerial.println((int) RAMEND); }

/// Print heap size on NeoSerial console.
#define MEMORY_PRINT_HEAPSIZE { NeoSerial.print(F("Heap size:")); NeoSerial.println((int) (__brkval == 0 ? (int)&__heap_start : (int)__brkval) - (int)&__heap_start); }
/// Print stack size on NeoSerial console.
#define MEMORY_PRINT_STACKSIZE { NeoSerial.print(F("Stack size:")); NeoSerial.println((int) RAMEND - (int)SP); }
/// Print free ram size on NeoSerial console.
#define MEMORY_PRINT_FREERAM { NeoSerial.print(F("Free ram:")); NeoSerial.println((int) SP - (int) (__brkval == 0 ? (int)&__heap_start : (int)__brkval)); }
/// Print total SRAM size on NeoSerial console.
#define MEMORY_PRINT_TOTALSIZE { NeoSerial.print(F("SRAM size:")); NeoSerial.println((int) RAMEND - (int) &__data_start); }

/// Displays the 'map' of the current state of the Arduino's SRAM memory on the NeoSerial console.
/// Print data start on NeoSerialDebug console.
#define MEMORY_PRINT_START { NeoSerialDebug.print(F("Data start:")); NeoSerialDebug.println((int) &__data_start); }
/// Print data end / heap start on NeoSerialDebug console.
#define MEMORY_PRINT_HEAPSTART { NeoSerialDebug.print(F("Heap start:")); NeoSerialDebug.println((int)&__heap_start); }
/// Print heap end / free ram area on NeoSerialDebug console.
#define MEMORY_PRINT_HEAPEND { NeoSerialDebug.print(F("Heap end:")); NeoSerialDebug.println(__brkval == 0 ? (int)&__heap_start : (int)__brkval); }
/// Print free ram end / stack start on NeoSerialDebug console.
#define MEMORY_PRINT_STACKSTART { NeoSerialDebug.print(F("Stack start:")); NeoSerialDebug.println((int) SP); }
/// Print end of memory on NeoSerialDebug console.
#define MEMORY_PRINT_END { NeoSerialDebug.print(F("Stack end:")); NeoSerialDebug.println((int) RAMEND); }

/// Print heap size on NeoSerialDebug console.
#define MEMORY_PRINT_HEAPSIZE { NeoSerialDebug.print(F("Heap size:")); NeoSerialDebug.println((int) (__brkval == 0 ? (int)&__heap_start : (int)__brkval) - (int)&__heap_start); }
/// Print stack size on NeoSerialDebug console.
#define MEMORY_PRINT_STACKSIZE { NeoSerialDebug.print(F("Stack size:")); NeoSerialDebug.println((int) RAMEND - (int)SP); }
/// Print free ram size on NeoSerialDebug console.
#define MEMORY_PRINT_FREERAM { NeoSerialDebug.print(F("Free ram:")); NeoSerialDebug.println((int) SP - (int) (__brkval == 0 ? (int)&__heap_start : (int)__brkval)); }
/// Print total SRAM size on NeoSerialDebug console.
#define MEMORY_PRINT_TOTALSIZE { NeoSerialDebug.print(F("SRAM size:")); NeoSerialDebug.println((int) RAMEND - (int) &__data_start); }

/// Displays the 'map' of the current state of the Arduino's SRAM memory on the NeoSerialDebug console.
void SRamDisplay(void);

//
Expand All @@ -153,7 +155,7 @@ void SRamDisplay(void);
#define STACK_COMPUTE { mu_stack_size = (RAMEND - SP) > mu_stack_size ? (RAMEND - SP) : mu_stack_size;}

/// Compute the current maximum and show it now with customized text.
#define STACK_PRINT_TEXT(text) { STACK_COMPUTE; NeoSerial.print(text); NeoSerial.println(mu_stack_size); }
#define STACK_PRINT_TEXT(text) { STACK_COMPUTE; NeoSerialDebug.print(text); NeoSerialDebug.println(mu_stack_size); }

/// Compute the current maximum and show it now with default text.
#define STACK_PRINT STACK_PRINT_TEXT(F("Stack Maximum Size (Instrumentation method): "));
Expand All @@ -163,7 +165,7 @@ void SRamDisplay(void);
//

/// Shows the current free SRAM memory with customized text.
#define FREERAM_PRINT_TEXT(text) NeoSerial.print(text); NeoSerial.println(mu_freeRam());
#define FREERAM_PRINT_TEXT(text) NeoSerialDebug.print(text); NeoSerialDebug.println(mu_freeRam());

/// Shows the current free SRAM memory with default text.
#define FREERAM_PRINT FREERAM_PRINT_TEXT(F("Free Ram Size: "));
Expand All @@ -179,7 +181,7 @@ int mu_freeRam(void);
uint16_t mu_StackCount(void);

/// Compute the current maximum and show it now with customized text.
#define STACKPAINT_PRINT_TEXT(text) { NeoSerial.print(text); NeoSerial.println(mu_StackCount()); }
#define STACKPAINT_PRINT_TEXT(text) { NeoSerialDebug.print(text); NeoSerialDebug.println(mu_StackCount()); }

/// Compute the current maximum and show it now with default text.
#define STACKPAINT_PRINT STACKPAINT_PRINT_TEXT(F("Stack Maximum Size (Painting method): "));
Expand Down

0 comments on commit 63e8387

Please sign in to comment.