1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- /*
- * log.c
- *
- * Created on: Nov 7, 2022
- * Author: tangm
- */
- #include "log.h"
- #include "usart.h"
- #include <stdarg.h>
- #include <stdio.h>
- #include "ucos_ii.h"
- #include "main.h"
- #include "udp_send.h"
- #include "stdlib.h"
- #include "malloc.h"
- static OS_EVENT *logMutex;
- uint8_t perr;
- void LogPrint(logLevel_t logLevel,const char *file, const char *func, const int line, char * fmt, ...)
- {
-
- OSMutexPend(logMutex, 5000, &perr);
- if(perr == OS_ERR_NONE)
- {
- udp_log_start();
- va_list args;
- va_start(args, fmt);
- char buf[LOG_LEN_MAX];
- vsnprintf(buf, sizeof(buf), fmt, args);
- va_end(args);
- char *p=mymalloc(SRAMEX, 1024);
- switch (logLevel)
- {
- #ifdef _LOG_INFO
- case LOG_INFO:
- sprintf(p,"[%s][%s][%s:%4d] %s\r\n", "INFO", file, func, line, buf);
- break;
- #endif
- #ifdef _LOG_DEBUG
- case LOG_DEBUG:
- sprintf(p,"[%s][%s][%s:%4d] %s\r\n", "DEBUG",file, func, line, buf);
- break;
- #endif
- #ifdef _LOG_WARN
- case LOG_WARN:
- sprintf(p,"[%s][%s][%s:%4d] %s\r\n", "WARN", file, func, line, buf);
- break;
- #endif
- case LOG_ERROR:
- sprintf(p,"[%s][%s][%s:%4d] %s\r\n", "ERROR",file, func, line, buf);
- break;
- default:
- break;
- }
- udp_send_printf(p);
- myfree(SRAMEX, p);
- udp_log_close();
- perr = OSMutexPost(logMutex);
- }
- }
- void log_init()
- {
-
- logMutex = OSMutexCreate (0, &perr);//´´½¨Ò»¸ölog»¥³âÁ¿
- OSTimeDly(100);
- }
|