#include "board_common.h"
|
|
static osMutexId PrintMutex;
|
static int PrintCurLevel = TH_PRINT_CUR;
|
osMutexDef(PrintMutex);
|
|
static void Board_DebugMutexInit(void)
|
{
|
PrintMutex = osMutexCreate(osMutex(PrintMutex));
|
}
|
|
static void Board_DebugMutexDeInit(void)
|
{
|
osMutexDelete(PrintMutex);
|
}
|
|
static void Board_DebugSetLevel(int Level)
|
{
|
PrintCurLevel = Level;
|
}
|
|
static void PrintToConsole(char *Color, char *Module, int Level, char *LevelName, char *FileName, int LineNum, const char *Func, char *Fmt, va_list argp)
|
{
|
osMutexWait(PrintMutex, osWaitForever);
|
if (Level < TH_PRINT_MAX)
|
PRINTF("%s[%s][%s]>%s(%d,%s)>|", Color, Module, LevelName, FileName, LineNum, Func);
|
|
//ÒÔÏ´úÂ룬²Î¿¼Reportº¯Êý¡£
|
int8_t i8Ret;
|
char *Buffer = NULL;
|
uint32_t u8Size = 300;
|
|
//va_list list;
|
Buffer = (char*)pvPortMalloc(u8Size);
|
if(Buffer == NULL)
|
{
|
osMutexRelease(PrintMutex);
|
return;
|
}
|
memset(Buffer, 0x0, u8Size);
|
|
while(1)
|
{
|
i8Ret = TH_VSNPRINTF(Buffer, u8Size, Fmt, argp);
|
if(i8Ret > -1 && i8Ret < u8Size)
|
break;
|
}
|
|
PRINTF("%s", Buffer);
|
|
if (Buffer != NULL)
|
vPortFree(Buffer);
|
Buffer = NULL;
|
|
/* »¹ÔĬÈÏ×ÖÌåÑÕÉ« */
|
if (Level < TH_PRINT_MAX)
|
PRINTF("[%d]%c%c%s", (int32_t)uxTaskGetStackHighWaterMark(NULL), '\r', '\n', COLOR_NORMAL);
|
|
osMutexRelease(PrintMutex);
|
}
|
|
//´úÂëÖеļõ1,¼Ó1,ÊÇ×Ö·û´®µÄ½ØÖ¹·û'\0'
|
void Board_DebugPrintf(char *Color, char *Module, int Level, char *LevelName, char *FileName, int LineNum, const char *Func, char *Fmt, ...)
|
{
|
//ÇëÇó´òÓ¡µÄ¼¶±ð£¬±Èµ±Ç°ÉèÖõļ¶±ðµÍ£¬²»»á±»´òÓ¡
|
if(Level < PrintCurLevel)
|
return;
|
|
va_list argp;
|
va_start(argp, Fmt);
|
PrintToConsole(Color, Module, Level, LevelName, FileName, LineNum, Func, Fmt, argp);
|
va_end(argp);
|
}
|
|
void Board_DebugInit(int Level)
|
{
|
Board_DebugMutexInit();
|
Board_DebugSetLevel(Level);
|
}
|
|
void Board_DebugDeInit(void)
|
{
|
Board_DebugMutexDeInit();
|
}
|
|