Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions cores/nRF5/common_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@
//--------------------------------------------------------------------+
const char* dbg_err_str(int32_t err_id); // TODO move to other place

#if __cplusplus
#define PRINTF ::printf
#else
#define PRINTF printf
#endif


#if CFG_DEBUG
#define LOG_LV1(...) ADALOG(__VA_ARGS__)
#define LOG_LV1_BUFFER(...) ADALOG_BUFFER(__VA_ARGS__)
Expand All @@ -134,15 +141,9 @@ const char* dbg_err_str(int32_t err_id); // TODO move to other place

#if CFG_DEBUG

#if __cplusplus
#define PRINTF ::printf
#else
#define PRINTF printf
#endif

#define PRINT_LOCATION() PRINTF("%s: %d:\n", __PRETTY_FUNCTION__, __LINE__)
#define PRINT_MESS(x) PRINTF("%s: %d: %s \n" , __FUNCTION__, __LINE__, (char*)(x))
#define PRTNT_HEAP() if (CFG_DEBUG == 3) PRINTF("\n%s: %d: Heap free: %d\n", __FUNCTION__, __LINE__, util_heap_get_free_size())
#define PRTNT_HEAP() if (CFG_DEBUG >= 3) PRINTF("\n%s: %d: Heap free: %d\n", __FUNCTION__, __LINE__, util_heap_get_free_size())
#define PRINT_STR(x) PRINTF("%s: %d: " #x " = %s\n" , __FUNCTION__, __LINE__, (char*)(x) )
#define PRINT_INT(x) PRINTF("%s: %d: " #x " = %ld\n" , __FUNCTION__, __LINE__, (uint32_t) (x) )
#define PRINT_FLOAT(x) PRINTF("%s: %d: " #x " = %f\n" , __FUNCTION__, __LINE__, (float) (x) )
Expand Down
69 changes: 35 additions & 34 deletions cores/nRF5/utility/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <malloc.h>
#include <Arduino.h>
#include <ctype.h>
#include <common_func.h>

// defined in linker script
extern uint32_t __data_start__[];
Expand Down Expand Up @@ -106,14 +107,14 @@ static void printMemRegion(const char* name, uint32_t top, uint32_t bottom, uint
sprintf(buffer, "%lu", top-bottom);
}

printf("| %-5s| 0x%04X - 0x%04X | %-19s |\n", name, (uint16_t) bottom, (uint16_t) (top-1), buffer);
PRINTF("| %-5s| 0x%04X - 0x%04X | %-19s |\n", name, (uint16_t) bottom, (uint16_t) (top-1), buffer);
}

void dbgMemInfo(void)
{
printf(" ______________________________________________\n");
printf("| Name | Addr 0x2000xxxx | Usage |\n");
printf("| ---------------------------------------------|\n");
PRINTF(" ______________________________________________\n");
PRINTF("| Name | Addr 0x2000xxxx | Usage |\n");
PRINTF("| ---------------------------------------------|\n");

// Pritn SRAM used for Stack executed by Softdevice and ISR
printMemRegion("Stack", ((uint32_t) __StackTop), ((uint32_t) __StackLimit), dbgStackUsed() );
Expand All @@ -127,29 +128,29 @@ void dbgMemInfo(void)
// Print SRAM Used by SoftDevice
printMemRegion("SD", (uint32_t) __data_start__, 0x20000000, 0);

printf("|______________________________________________|\n");
printf("\n");
PRINTF("|______________________________________________|\n");
PRINTF("\n");

// Print Task list
uint32_t tasknum = uxTaskGetNumberOfTasks();
char* buf = (char*) rtos_malloc(tasknum*40); // 40 bytes per task

vTaskList(buf);

printf("Task State Prio StackLeft Num\n");
printf("-----------------------------------\n");
printf(buf);
printf("\n");
PRINTF("Task State Prio StackLeft Num\n");
PRINTF("-----------------------------------\n");
PRINTF(buf);
PRINTF("\n");
rtos_free(buf);
}

void dbgPrintVersion(void)
{
printf("\n");
printf("BSP Library : " ARDUINO_BSP_VERSION "\n");
printf("Bootloader : %s\n", getBootloaderVersion());
printf("Serial No : %s\n", getMcuUniqueID());
printf("\n");
PRINTF("\n");
PRINTF("BSP Library : " ARDUINO_BSP_VERSION "\n");
PRINTF("Bootloader : %s\n", getBootloaderVersion());
PRINTF("Serial No : %s\n", getMcuUniqueID());
PRINTF("\n");
}

/******************************************************************************/
Expand All @@ -163,15 +164,15 @@ static void dump_str_line(uint8_t const* buf, uint16_t count)
for(int i=0; i<count; i++)
{
const char ch = buf[i];
printf("%c", isprint(ch) ? ch : '.');
PRINTF("%c", isprint(ch) ? ch : '.');
}
}

void dbgDumpMemory(void const *buf, uint8_t size, uint16_t count, bool printOffset)
{
if ( !buf || !count )
{
printf("NULL\n");
PRINTF("NULL\n");
return;
}

Expand All @@ -191,26 +192,26 @@ void dbgDumpMemory(void const *buf, uint8_t size, uint16_t count, bool printOffs
// Print Ascii
if ( i != 0 )
{
printf(" | ");
PRINTF(" | ");
dump_str_line(buf8-16, 16);
printf("\n");
PRINTF("\n");
}

// print offset or absolute address
if (printOffset)
{
printf("%03lX: ", 16*i/item_per_line);
PRINTF("%03lX: ", 16*i/item_per_line);
}else
{
printf("%08lX:", (uint32_t) buf8);
PRINTF("%08lX:", (uint32_t) buf8);
}
}

memcpy(&value, buf8, size);
buf8 += size;

printf(" ");
printf(format, value);
PRINTF(" ");
PRINTF(format, value);
}

// fill up last row to 16 for printing ascii
Expand All @@ -221,46 +222,46 @@ void dbgDumpMemory(void const *buf, uint8_t size, uint16_t count, bool printOffs
{
for(int i=0; i< 16-remain; i++)
{
printf(" ");
for(int j=0; j<2*size; j++) printf(" ");
PRINTF(" ");
for(int j=0; j<2*size; j++) PRINTF(" ");
}
}

printf(" | ");
PRINTF(" | ");
dump_str_line(buf8-nback, nback);
printf("\n");
PRINTF("\n");

printf("\n");
PRINTF("\n");
}


void dbgDumpMemoryCFormat(const char* str, void const *buf, uint16_t count)
{
if ( !buf )
{
printf("NULL\n");
PRINTF("NULL\n");
return;
}

printf("%s = \n{\n ", str);
PRINTF("%s = \n{\n ", str);

uint8_t const *buf8 = (uint8_t const *) buf;

for(uint32_t i=0; i<count; i++)
{
if ( i%16 == 0 )
{
if ( i != 0 ) printf(",\n ");
if ( i != 0 ) PRINTF(",\n ");
}else
{
if ( i != 0 ) printf(", ");
if ( i != 0 ) PRINTF(", ");
}

printf("0x%02X", *buf8);
PRINTF("0x%02X", *buf8);
buf8++;
}

printf("\n};\n");
PRINTF("\n};\n");
}


Expand Down
8 changes: 4 additions & 4 deletions cores/nRF5/verify.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ extern "C"
#define VERIFY_MESS(_status, _functstr) VERIFY_MESS_impl(_status, _functstr, __PRETTY_FUNCTION__, __LINE__)
static inline void VERIFY_MESS_impl(int32_t _status, const char* (*_fstr)(int32_t), const char* func_name, int line_number)
{
printf("%s: %d: verify failed, error = ", func_name, line_number);
PRINTF("%s: %d: verify failed, error = ", func_name, line_number);
if (_fstr)
{
printf(_fstr(_status));
PRINTF(_fstr(_status));
}
else
{
printf("%ld", _status);
PRINTF("%ld", _status);
}
printf("\n");
PRINTF("\n");
}
#else
#define VERIFY_MESS(_status, _funcstr)
Expand Down
6 changes: 3 additions & 3 deletions libraries/Adafruit_LittleFS/src/littlefs/lfs_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@ extern "C"
// Logging functions
#ifndef LFS_NO_DEBUG
#define LFS_DEBUG(fmt, ...) \
printf("lfs debug:%d: " fmt "\n", __LINE__, __VA_ARGS__)
PRINTF("lfs debug:%d: " fmt "\n", __LINE__, __VA_ARGS__)
#else
#define LFS_DEBUG(fmt, ...)
#endif

#ifndef LFS_NO_WARN
#define LFS_WARN(fmt, ...) \
printf("lfs warn:%d: " fmt "\n", __LINE__, __VA_ARGS__)
PRINTF("lfs warn:%d: " fmt "\n", __LINE__, __VA_ARGS__)
#else
#define LFS_WARN(fmt, ...)
#endif

#ifndef LFS_NO_ERROR
#define LFS_ERROR(fmt, ...) \
printf("lfs error:%d: " fmt "\n", __LINE__, __VA_ARGS__)
PRINTF("lfs error:%d: " fmt "\n", __LINE__, __VA_ARGS__)
#else
#define LFS_ERROR(fmt, ...)
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ void BLEAdafruitQuaternion::_update_timer(int32_t ms)
#if CFG_DEBUG
static void print_quaternion(float quater[4])
{
Serial.printf("Quaternion: %.04f, %.04f, %.04f, %.04f\n", quater[0], quater[1], quater[2], quater[3]);
// prepare for ability to change output, based on compile-time flags
Print& logger = Serial;
logger.printf("Quaternion: %.04f, %.04f, %.04f, %.04f\n", quater[0], quater[1], quater[2], quater[3]);
}
#endif

Expand Down
16 changes: 9 additions & 7 deletions libraries/Bluefruit52Lib/src/BLEPeriph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,16 @@ void BLEPeriph::_eventHandler(ble_evt_t* evt)
void BLEPeriph::printInfo(void)
{
char const * title_fmt = "%-16s: ";
// prepare for ability to change output, based on compile-time flags
Print& logger = Serial;

Serial.printf(title_fmt, "Conn Intervals");
Serial.printf("min = %.2f ms, ", _ppcp.min_conn_interval*1.25f);
Serial.printf("max = %.2f ms", _ppcp.max_conn_interval*1.25f);
Serial.println();
logger.printf(title_fmt, "Conn Intervals");
logger.printf("min = %.2f ms, ", _ppcp.min_conn_interval*1.25f);
logger.printf("max = %.2f ms", _ppcp.max_conn_interval*1.25f);
logger.println();

Serial.printf(title_fmt, "Conn Timeout");
Serial.printf("%d ms", _ppcp.conn_sup_timeout*10);
Serial.println();
logger.printf(title_fmt, "Conn Timeout");
logger.printf("%d ms", _ppcp.conn_sup_timeout*10);
logger.println();
}

Loading