Motion_EC_Stm32_archived/Middlewares/Log/log.c

56 lines
1.3 KiB
C

/*
* @Description:
* @Date: 2020-12-22 18:27:24
* @LastEditors: CK.Zh
* @LastEditTime: 2021-01-07 17:54:00
* @FilePath: \NaviKit_stm32\Middlewares\Log\log.c
*/
/*
* log.c
*
* Created on: Dec 16, 2020
* Author: bookshiyi
*/
#include "log.h"
static bool mutex =false;
void Log(LogLevel_t level,LogPositon_t positon,char *format,...)
{
if(mutex){
unsigned char time_out = 100;
while(mutex && time_out--){//100ms timout for multi-thread use log function
osDelay(1);
}
}
if(!mutex){
mutex = true;
switch(level){
case trace: { printf("[Trace ] ") ; }break;
case debug: { printf("[Debug ] ") ; }break;
case info: { printf("[Info ] ") ; }break;
case warning:{ printf("[Warning] ") ; }break;
case error: { printf("[Error ] ") ; }break;
case fatal: { printf("[Fatal ] ") ; }break;
default: { printf("[Undefined Level] ") ; }break;
}
switch (positon)
{
case sys:{ printf("SYS: ") ; }break;
case som:{ printf("SOM: ") ; }break;
case pmb:{ printf("PMB: ") ; }break;
default: { printf("Undefined Position: ") ;}break;
}
printf("%8u | ",osKernelGetTickCount());
va_list args;
va_start( args, format );
print(0, format, args );
printf("\n") ;
mutex = false;
}
}