clean up, replace cprintf by std printf (with _write hook)
This commit is contained in:
1 parent
ebbed82c5a
commit
123c3080c3
7 files changed
+63
-76
No files matched your search
+15
-16
@@ -115,12 +115,11 @@
|
||||
// DEBUG HELPER
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_DEBUG == 2
|
||||
#define malloc_named( name, size ) ({ cprintf("[malloc] %s : %d\r\n", name, size); malloc(size); })
|
||||
#define malloc_named( name, size ) ({ printf("[malloc] %s : %d\r\n", name, size); malloc(size); })
|
||||
#else
|
||||
#define malloc_named( name, size ) malloc ( size )
|
||||
#endif
|
||||
|
||||
int cprintf(const char * format, ...);
|
||||
const char* dbg_err_str(int32_t err_id); // TODO move to other place
|
||||
|
||||
#if CFG_DEBUG
|
||||
@@ -141,38 +140,38 @@ const char* dbg_err_str(int32_t err_id); // TODO move to other place
|
||||
|
||||
#if CFG_DEBUG
|
||||
|
||||
#define PRINT_LOCATION() cprintf("%s: %d:\n", __PRETTY_FUNCTION__, __LINE__)
|
||||
#define PRINT_MESS(x) cprintf("%s: %d: %s \n" , __FUNCTION__, __LINE__, (char*)(x))
|
||||
#define PRTNT_HEAP() if (CFG_DEBUG == 3) cprintf("\n%s: %d: Heap free: %d\n", __FUNCTION__, __LINE__, util_heap_get_free_size())
|
||||
#define PRINT_STR(x) cprintf("%s: %d: " #x " = %s\n" , __FUNCTION__, __LINE__, (char*)(x) )
|
||||
#define PRINT_INT(x) cprintf("%s: %d: " #x " = %ld\n" , __FUNCTION__, __LINE__, (uint32_t) (x) )
|
||||
#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 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_HEX(x) \
|
||||
do {\
|
||||
cprintf("%s: %d: " #x " = 0x", __PRETTY_FUNCTION__, __LINE__);\
|
||||
printf("%s: %d: " #x " = 0x", __PRETTY_FUNCTION__, __LINE__);\
|
||||
char fmt[] = "%00X\n";\
|
||||
fmt[2] += 2*sizeof(x); /* Hex with correct size */\
|
||||
cprintf(fmt, (x) );\
|
||||
printf(fmt, (x) );\
|
||||
}while(0)
|
||||
|
||||
#define PRINT_BUFFER(buf, n) \
|
||||
do {\
|
||||
uint8_t const* p8 = (uint8_t const*) (buf);\
|
||||
cprintf(#buf ": ");\
|
||||
for(uint32_t i=0; i<(n); i++) cprintf("%02x ", p8[i]);\
|
||||
cprintf("\n");\
|
||||
printf(#buf ": ");\
|
||||
for(uint32_t i=0; i<(n); i++) printf("%02x ", p8[i]);\
|
||||
printf("\n");\
|
||||
}while(0)
|
||||
|
||||
#define ADALOG(tag, ...) \
|
||||
do { \
|
||||
if ( tag ) cprintf("[%-6s] ", tag);\
|
||||
cprintf(__VA_ARGS__);\
|
||||
cprintf("\n");\
|
||||
if ( tag ) printf("[%-6s] ", tag);\
|
||||
printf(__VA_ARGS__);\
|
||||
printf("\n");\
|
||||
}while(0)
|
||||
|
||||
#define ADALOG_BUFFER(_tag, _buf, _n) \
|
||||
do {\
|
||||
if ( _tag ) cprintf("%-6s: len = %d\n", _tag, _n);\
|
||||
if ( _tag ) printf("%-6s: len = %d\n", _tag, _n);\
|
||||
dbgDumpMemory(_buf, 1, _n, true);\
|
||||
}while(0)
|
||||
|
||||
|
||||
@@ -125,8 +125,6 @@ bool fal_erase (uint32_t addr)
|
||||
|
||||
static uint32_t fal_program (uint32_t dst, void const * src, uint32_t len)
|
||||
{
|
||||
cprintf("Programming 0x%08X\n", dst);
|
||||
|
||||
// wait for async event if SD is enabled
|
||||
uint8_t sd_en = 0;
|
||||
(void) sd_softdevice_is_enabled(&sd_en);
|
||||
|
||||
+2
-2
@@ -68,8 +68,8 @@ enum
|
||||
#define malloc_type(type) rtos_malloc( sizeof(type) )
|
||||
|
||||
#if 0
|
||||
#define rtos_malloc(_size) ({ cprintf("[malloc] %s:%d : %d bytes\r\n", __PRETTY_FUNCTION__, __LINE__, _size); pvPortMalloc(_size); })
|
||||
#define rtos_free(ptr) ({ cprintf("[free] %s:%d\r\n" ,__PRETTY_FUNCTION__, __LINE__/*malloc_usable_size(ptr)*/); vPortFree(ptr); })
|
||||
#define rtos_malloc(_size) ({ printf("[malloc] %s:%d : %d bytes\r\n", __PRETTY_FUNCTION__, __LINE__, _size); pvPortMalloc(_size); })
|
||||
#define rtos_free(ptr) ({ printf("[free] %s:%d\r\n" ,__PRETTY_FUNCTION__, __LINE__/*malloc_usable_size(ptr)*/); vPortFree(ptr); })
|
||||
#else
|
||||
|
||||
#define rtos_malloc_type(_type) (_type*) rtos_malloc(sizeof(_type))
|
||||
|
||||
@@ -62,21 +62,12 @@ void HardFault_Handler(void)
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
int cprintf(const char * format, ...)
|
||||
// nanolib printf() retarget
|
||||
int _write (int fd, const void *buf, size_t count)
|
||||
{
|
||||
char buf[256];
|
||||
int len;
|
||||
(void) fd;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
|
||||
// SEGGER_SYSVIEW_Print(buf);
|
||||
Serial.write(buf, len);
|
||||
|
||||
va_end(ap);
|
||||
return len;
|
||||
Serial.write( (const uint8_t *) buf, count);
|
||||
}
|
||||
|
||||
int dbgHeapTotal(void)
|
||||
@@ -123,14 +114,14 @@ static void printMemRegion(const char* name, uint32_t top, uint32_t bottom, uint
|
||||
sprintf(buffer, "%lu", top-bottom);
|
||||
}
|
||||
|
||||
cprintf("| %-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)
|
||||
{
|
||||
cprintf(" ______________________________________________\n");
|
||||
cprintf("| Name | Addr 0x2000xxxx | Usage |\n");
|
||||
cprintf("| ---------------------------------------------|\n");
|
||||
printf(" ______________________________________________\n");
|
||||
printf("| Name | Addr 0x2000xxxx | Usage |\n");
|
||||
printf("| ---------------------------------------------|\n");
|
||||
|
||||
// Pritn SRAM used for Stack executed by S132 and ISR
|
||||
printMemRegion("Stack", ((uint32_t) __StackTop), ((uint32_t) __StackLimit), dbgStackUsed() );
|
||||
@@ -144,8 +135,8 @@ void dbgMemInfo(void)
|
||||
// Print SRAM Used by SoftDevice
|
||||
printMemRegion("S132", (uint32_t) __data_start__, 0x20000000, 0);
|
||||
|
||||
cprintf("|______________________________________________|\n");
|
||||
cprintf("\n");
|
||||
printf("|______________________________________________|\n");
|
||||
printf("\n");
|
||||
|
||||
// Print Task list
|
||||
uint32_t tasknum = uxTaskGetNumberOfTasks();
|
||||
@@ -153,20 +144,20 @@ void dbgMemInfo(void)
|
||||
|
||||
vTaskList(buf);
|
||||
|
||||
cprintf("Task State Prio StackLeft Num\n");
|
||||
cprintf("-----------------------------------\n");
|
||||
cprintf(buf);
|
||||
cprintf("\n");
|
||||
printf("Task State Prio StackLeft Num\n");
|
||||
printf("-----------------------------------\n");
|
||||
printf(buf);
|
||||
printf("\n");
|
||||
rtos_free(buf);
|
||||
}
|
||||
|
||||
void dbgPrintVersion(void)
|
||||
{
|
||||
cprintf("\n");
|
||||
cprintf("BSP Library : " ARDUINO_BSP_VERSION "\n");
|
||||
cprintf("Bootloader : %s\n", getBootloaderVersion());
|
||||
cprintf("Serial No : %s\n", getMcuUniqueID());
|
||||
cprintf("\n");
|
||||
printf("\n");
|
||||
printf("BSP Library : " ARDUINO_BSP_VERSION "\n");
|
||||
printf("Bootloader : %s\n", getBootloaderVersion());
|
||||
printf("Serial No : %s\n", getMcuUniqueID());
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
@@ -180,7 +171,7 @@ static void dump_str_line(uint8_t const* buf, uint16_t count)
|
||||
for(int i=0; i<count; i++)
|
||||
{
|
||||
const char ch = buf[i];
|
||||
cprintf("%c", isprint(ch) ? ch : '.');
|
||||
printf("%c", isprint(ch) ? ch : '.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +179,7 @@ void dbgDumpMemory(void const *buf, uint8_t size, uint16_t count, bool printOffs
|
||||
{
|
||||
if ( !buf )
|
||||
{
|
||||
cprintf("NULL\n");
|
||||
printf("NULL\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -208,26 +199,26 @@ void dbgDumpMemory(void const *buf, uint8_t size, uint16_t count, bool printOffs
|
||||
// Print Ascii
|
||||
if ( i != 0 )
|
||||
{
|
||||
cprintf(" | ");
|
||||
printf(" | ");
|
||||
dump_str_line(buf8-16, 16);
|
||||
cprintf("\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
// print offset or absolute address
|
||||
if (printOffset)
|
||||
{
|
||||
cprintf("%03lX: ", 16*i/item_per_line);
|
||||
printf("%03lX: ", 16*i/item_per_line);
|
||||
}else
|
||||
{
|
||||
cprintf("%08lX:", (uint32_t) buf8);
|
||||
printf("%08lX:", (uint32_t) buf8);
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(&value, buf8, size);
|
||||
buf8 += size;
|
||||
|
||||
cprintf(" ");
|
||||
cprintf(format, value);
|
||||
printf(" ");
|
||||
printf(format, value);
|
||||
}
|
||||
|
||||
// fill up last row to 16 for printing ascii
|
||||
@@ -238,16 +229,16 @@ void dbgDumpMemory(void const *buf, uint8_t size, uint16_t count, bool printOffs
|
||||
{
|
||||
for(int i=0; i< 16-remain; i++)
|
||||
{
|
||||
cprintf(" ");
|
||||
for(int j=0; j<2*size; j++) cprintf(" ");
|
||||
printf(" ");
|
||||
for(int j=0; j<2*size; j++) printf(" ");
|
||||
}
|
||||
}
|
||||
|
||||
cprintf(" | ");
|
||||
printf(" | ");
|
||||
dump_str_line(buf8-nback, nback);
|
||||
cprintf("\n");
|
||||
printf("\n");
|
||||
|
||||
cprintf("\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -255,11 +246,11 @@ void dbgDumpMemoryCFormat(const char* str, void const *buf, uint16_t count)
|
||||
{
|
||||
if ( !buf )
|
||||
{
|
||||
cprintf("NULL\n");
|
||||
printf("NULL\n");
|
||||
return;
|
||||
}
|
||||
|
||||
cprintf("%s = \n{\n ", str);
|
||||
printf("%s = \n{\n ", str);
|
||||
|
||||
uint8_t const *buf8 = (uint8_t const *) buf;
|
||||
|
||||
@@ -269,17 +260,17 @@ void dbgDumpMemoryCFormat(const char* str, void const *buf, uint16_t count)
|
||||
|
||||
if ( i%16 == 0 )
|
||||
{
|
||||
if ( i != 0 ) cprintf(",\n ");
|
||||
if ( i != 0 ) printf(",\n ");
|
||||
}else
|
||||
{
|
||||
if ( i != 0 ) cprintf(", ");
|
||||
if ( i != 0 ) printf(", ");
|
||||
}
|
||||
|
||||
cprintf("0x%02lX", *buf8);
|
||||
printf("0x%02lX", *buf8);
|
||||
buf8++;
|
||||
}
|
||||
|
||||
cprintf("\n\};\n");
|
||||
printf("\n\};\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -65,9 +65,9 @@ extern "C"
|
||||
#define VERIFY_MESS(_status, _funcstr) \
|
||||
do { \
|
||||
const char* (*_fstr)(int32_t) = _funcstr;\
|
||||
cprintf("%s: %d: verify failed, error = ", __PRETTY_FUNCTION__, __LINE__);\
|
||||
if (_fstr) cprintf(_fstr(_status)); else cprintf("%d", _status);\
|
||||
cprintf("\n");\
|
||||
printf("%s: %d: verify failed, error = ", __PRETTY_FUNCTION__, __LINE__);\
|
||||
if (_fstr) printf(_fstr(_status)); else printf("%d", _status);\
|
||||
printf("\n");\
|
||||
}while(0)
|
||||
#else
|
||||
#define VERIFY_MESS(_status, _funcstr)
|
||||
|
||||
@@ -255,14 +255,14 @@ void bond_print_list(uint8_t role)
|
||||
char devname[len];
|
||||
file.read(devname, len);
|
||||
|
||||
cprintf(" %s : %s (%d bytes)\n", file.name(), devname, file.size());
|
||||
printf(" %s : %s (%d bytes)\n", file.name(), devname, file.size());
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
cprintf("\n");
|
||||
printf("\n");
|
||||
|
||||
file.close();
|
||||
dir.close();
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
|
||||
#if !defined(LFS_NO_DEBUG) || !defined(LFS_NO_WARN) || !defined(LFS_NO_ERROR)
|
||||
#include <stdio.h>
|
||||
int cprintf (const char * format, ...);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -57,21 +56,21 @@ extern "C"
|
||||
// Logging functions
|
||||
#ifndef LFS_NO_DEBUG
|
||||
#define LFS_DEBUG(fmt, ...) \
|
||||
cprintf("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, ...) \
|
||||
cprintf("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, ...) \
|
||||
cprintf("lfs error:%d: " fmt "\n", __LINE__, __VA_ARGS__)
|
||||
printf("lfs error:%d: " fmt "\n", __LINE__, __VA_ARGS__)
|
||||
#else
|
||||
#define LFS_ERROR(fmt, ...)
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user