Motion_EC_Stm32_archived/Middlewares/Log/log.c

56 lines
1.3 KiB
C
Raw Normal View History

2021-01-07 19:01:08 +08:00
/*
* @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"
2021-01-07 19:01:08 +08:00
static bool mutex =false;
2021-01-07 19:01:08 +08:00
void Log(LogLevel_t level,LogPositon_t positon,char *format,...)
{
2021-01-07 19:01:08 +08:00
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("%u | ",osKernelGetTickCount());
va_list args;
va_start( args, format );
print(0, format, args );
printf("\n") ;
2021-01-07 19:01:08 +08:00
mutex = false;
}
}