From 5cfdb282640f66a4c1c819c4af9e6cde8af8a1e1 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 1 Sep 2018 00:17:36 +0700 Subject: [PATCH] fix deubg.cpp issue #176 --- cores/nRF5/debug.cpp | 160 ++++++++++++++++++++++++++++++------------- 1 file changed, 114 insertions(+), 46 deletions(-) diff --git a/cores/nRF5/debug.cpp b/cores/nRF5/debug.cpp index ff6b2915..0bda5609 100644 --- a/cores/nRF5/debug.cpp +++ b/cores/nRF5/debug.cpp @@ -1,13 +1,13 @@ /**************************************************************************/ /*! @file debug.cpp - @author hathach + @author hathach (tinyusb.org) @section LICENSE Software License Agreement (BSD License) - Copyright (c) 2017, Adafruit Industries (adafruit.com) + Copyright (c) 2018, Adafruit Industries (adafruit.com) All rights reserved. Redistribution and use in source and binary forms, with or without @@ -38,6 +38,7 @@ #include #include #include +#include // defined in linker script extern uint32_t __data_start__[]; @@ -54,30 +55,30 @@ extern uint32_t __StackLimit[]; extern "C" { - int cprintf(const char * format, ...) - { - char buf[256]; - int len; - va_list ap; - va_start(ap, format); +int cprintf(const char * format, ...) +{ + char buf[256]; + int len; - len = vsnprintf(buf, 256, format, ap); - Serial.write(buf, len); + va_list ap; + va_start(ap, format); - va_end(ap); - return len; - } + len = vsnprintf(buf, 256, format, ap); + Serial.write(buf, len); - void vApplicationMallocFailedHook(void) - { - Serial.println("Failed to Malloc"); - } + va_end(ap); + return len; +} - void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ) - { - Serial.printf("%s Stack Overflow !!!", pcTaskName); - } +void vApplicationMallocFailedHook(void) +{ + cprintf("Failed to Malloc"); +} + +void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ) +{ + cprintf("%s Stack Overflow !!!", pcTaskName); } int dbgHeapTotal(void) @@ -124,14 +125,14 @@ static void printMemRegion(const char* name, uint32_t top, uint32_t bottom, uint sprintf(buffer, "%lu", top-bottom); } - Serial.printf("| %-5s| 0x%04X - 0x%04X | %-19s |\n", name, (uint16_t) bottom, (uint16_t) (top-1), buffer); + cprintf("| %-5s| 0x%04X - 0x%04X | %-19s |\n", name, (uint16_t) bottom, (uint16_t) (top-1), buffer); } void dbgMemInfo(void) { - Serial.println(" ______________________________________________"); - Serial.println("| Name | Addr 0x2000xxxx | Usage |"); - Serial.println("| ---------------------------------------------|"); + cprintf(" ______________________________________________\n"); + cprintf("| Name | Addr 0x2000xxxx | Usage |\n"); + cprintf("| ---------------------------------------------|\n"); // Pritn SRAM used for Stack executed by S132 and ISR printMemRegion("Stack", ((uint32_t) __StackTop), ((uint32_t) __StackLimit), dbgStackUsed() ); @@ -145,8 +146,8 @@ void dbgMemInfo(void) // Print SRAM Used by SoftDevice printMemRegion("S132", (uint32_t) __data_start__, 0x20000000, 0); - Serial.printf("|______________________________________________|\n"); - Serial.println(); + cprintf("|______________________________________________|\n"); + cprintf("\n"); // Print Task list uint32_t tasknum = uxTaskGetNumberOfTasks(); @@ -154,9 +155,10 @@ void dbgMemInfo(void) vTaskList(buf); - Serial.println("Task State Prio StackLeft Num"); - Serial.println("-----------------------------------"); - Serial.println(buf); + cprintf("Task State Prio StackLeft Num\n"); + cprintf("-----------------------------------\n"); + cprintf(buf); + cprintf("\n"); rtos_free(buf); } @@ -174,50 +176,116 @@ void dbgPrintVersion(void) @brief Helper function to display memory contents in a friendly format */ /******************************************************************************/ +static void dump_str_line(uint8_t const* buf, uint16_t count) +{ + // each line is 16 bytes + for(int i=0; i UINT8_MAX ) offset_fmt_size *= 2; - if ( count*size > UINT16_MAX ) offset_fmt_size *= 2; - char format[] = "%02lX"; + char format[] = "%00lX"; + format[2] += 2*size; - char offset_fmt[] = "%00lX: "; - offset_fmt[2] += offset_fmt_size; - - const uint8_t item_per_line = 16 / size; + const uint8_t item_per_line = 16 / size; for(int i=0; i