void log_print_(int level, int line, const char *func, const char *file, const char *msg, ...) { char _buffer[MAX_DEBUG_MESSAGE_LENGTH]; static char * levels[] = { "", "LOG ", "DEBUG", "WARN ", "ERROR", "PANIC", }; va_list args; va_start(args, msg); file = file ? strrchr(file,'/') + 1 : ""; int trunc = snprintf(_buffer, arraySize(_buffer), "%010lu:<%s> %s %s(%d):", GetSystem1MsTick(), levels[level], func, file, line); if (debug_output_) { debug_output_(_buffer); if (trunc > arraySize(_buffer)) { debug_output_("..."); } } trunc = vsnprintf(_buffer,arraySize(_buffer), msg, args); if (debug_output_) { debug_output_(_buffer); if (trunc > arraySize(_buffer)) { debug_output_("..."); } debug_output_("\r\n"); } }
/********************************************************************************* *Function : *Description : *Input : *Output : *Return : *author : *date : *Others : **********************************************************************************/ void panic_(ePanicCode code) { __disable_irq(); // Flush any serial message to help the poor bugger debug this; flash_codes_t pcd = flash_codes[code]; uint16_t c; int loops = 2; if (debug_output_)(debug_output_("!")); while(loops) { // preamble KICK_WDT(); // add led indicate #ifdef RELEASE_BUILD if (--loops == 0) NVIC_SystemReset(); #endif } }