149 lines
5.5 KiB
C
149 lines
5.5 KiB
C
|
#include "sysport.h"
|
|||
|
#include <string.h>
|
|||
|
#include "usart.h"
|
|||
|
#include "rtc.h"
|
|||
|
#include "malloc.h"
|
|||
|
|
|||
|
/*********************************************************************************************************************
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD>void *portMalloc(size_t xWantedSize )
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD>pvPortMalloc<EFBFBD><EFBFBD><EFBFBD>з<EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>Ϊ0
|
|||
|
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD>ڷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ռ䲻<EFBFBD>ǿյ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>pvPortMalloc<EFBFBD><EFBFBD>һ<EFBFBD>η<EFBFBD>װ<EFBFBD><EFBFBD>
|
|||
|
*********************************************************************************************************************/
|
|||
|
void *portMalloc(size_t xWantedSize )
|
|||
|
{
|
|||
|
void *p = NULL ;
|
|||
|
// uint8_t fBytes = xWantedSize%4 ;
|
|||
|
// if( fBytes != 0 ) //4<>ֽڶ<D6BD><DAB6>봦<EFBFBD><EBB4A6>
|
|||
|
// {
|
|||
|
// xWantedSize = xWantedSize+(4-fBytes) ;
|
|||
|
// }
|
|||
|
p = MyMalloc(SRAMIN, xWantedSize) ;
|
|||
|
uint8_t usedRate = MyMenPerused(SRAMIN);
|
|||
|
if( usedRate > 75 )
|
|||
|
{
|
|||
|
SysErr("\r\n<EFBFBD><EFBFBD>̬<EFBFBD>ڴ<EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD>ѳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%d%%<25><>\r\n", usedRate) ;
|
|||
|
}
|
|||
|
if( p != NULL )
|
|||
|
{
|
|||
|
memset(p, 0, xWantedSize) ; //ʵ<><CAB5><EFBFBD>з<EFBFBD><D0B7>ִ<EFBFBD><D6B4>ڷ<EFBFBD><DAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4>ռ䲻<D5BC>ǿյ<C7BF><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>pvPortMalloc<6F><63>һ<EFBFBD>η<EFBFBD>װ<EFBFBD><D7B0>
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
SysErr("\r\n<EFBFBD>ڴ<EFBFBD>ռ<EFBFBD>ã<EFBFBD>%d%%--<2D><>̬<EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>̬<EFBFBD>ڴ<EFBFBD><DAB4>ռ䣡", usedRate) ;
|
|||
|
MyMenInit(SRAMIN) ; //<2F><>̬<EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
|||
|
p = MyMalloc(SRAMIN, xWantedSize) ;
|
|||
|
if( p == NULL)
|
|||
|
{
|
|||
|
SysErr("") ; //<2F>ڴ<EFBFBD><DAB4>ٴη<D9B4><CEB7><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>
|
|||
|
SystemSoftReset() ;
|
|||
|
}
|
|||
|
}
|
|||
|
return p ;
|
|||
|
}
|
|||
|
|
|||
|
/*********************************************************************************************************************
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD>void *portFree(void *addr )
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ܣ<EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD>portMalloc<EFBFBD><EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ռ<EFBFBD>
|
|||
|
*********************************************************************************************************************/
|
|||
|
void portFree(void *addr )
|
|||
|
{
|
|||
|
#ifdef FREERTOS_MALLOC
|
|||
|
vPortFree(addr) ;
|
|||
|
#else
|
|||
|
MyFree(SRAMIN, addr);
|
|||
|
#endif
|
|||
|
addr = NULL ;
|
|||
|
}
|
|||
|
|
|||
|
/*********************************************************************************************************************
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD>void AppLogPrintf( char *format, ...)
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ܣ<EFBFBD>USB<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|||
|
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽΪ<EFBFBD><EFBFBD>
|
|||
|
* APP Log:
|
|||
|
* Time:14:40:58 ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>³<EFBFBD><EFBFBD>ɹ<EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>vip_task<EFBFBD><EFBFBD>
|
|||
|
*********************************************************************************************************************/
|
|||
|
void AppLogPrintf( char *format, ...)
|
|||
|
{
|
|||
|
#if(configAPPLOGPRINTF_ENABLE == 1)
|
|||
|
{
|
|||
|
va_list ap; //apָ<70><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ַ
|
|||
|
va_start (ap, format); //<2F><>apָ<70><D6B8>ָ<EFBFBD><D6B8><EFBFBD>ɱ<EFBFBD><C9B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
char *log = portMalloc(LOG_BUF_LEN) ;
|
|||
|
//printf("\r\nAppLog: %s ", &uCalendar.bytes[11]) ;
|
|||
|
//int outLen1 = snprintf(log, LOG_BUF_LEN, "\r\nAppLog: %s ", &uCalendar.bytes[11]);//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
|||
|
int outLen1 = snprintf(log, LOG_BUF_LEN, "LogApp:"); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
|||
|
int outLen2 = vsnprintf((log+outLen1), LOG_BUF_LEN-outLen1, (const char*)format, ap);
|
|||
|
//strcat(log, "\r\n") ;
|
|||
|
if(outLen2 > 0 )
|
|||
|
UARTx_SendData(UART_DEBUG, log, outLen2+outLen1);
|
|||
|
else //vsnprintfִ<66><D6B4>ʧ<EFBFBD><CAA7>
|
|||
|
SysErr("") ;
|
|||
|
va_end(ap) ;
|
|||
|
portFree(log) ;
|
|||
|
}
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
/*********************************************************************************************************************
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD>void DebugLogPrintf( char *format, ...)
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ܣ<EFBFBD>USB<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|||
|
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽΪ<EFBFBD><EFBFBD>
|
|||
|
* DEBUG Log:
|
|||
|
* Time:14:40:58 ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>³<EFBFBD><EFBFBD>ɹ<EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>vip_task<EFBFBD><EFBFBD>
|
|||
|
*********************************************************************************************************************/
|
|||
|
void DebugLogPrintf( char *format, ...)
|
|||
|
{
|
|||
|
#if(configDEBUGLOGPRINTF_ENABLE == 1)
|
|||
|
{
|
|||
|
va_list ap; //apָ<70><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ַ
|
|||
|
va_start (ap, format); //<2F><>apָ<70><D6B8>ָ<EFBFBD><D6B8><EFBFBD>ɱ<EFBFBD><C9B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
char *log = portMalloc(LOG_BUF_LEN) ;
|
|||
|
//printf("\r\nDebugLog: %s ", &uCalendar.bytes[11]) ;
|
|||
|
//int outLen = vsnprintf(log, LOG_BUF_LEN, (const char*)format, ap);
|
|||
|
//int outLen1 = snprintf(log, LOG_BUF_LEN, "\r\nDebLog: %s ", &uCalendar.bytes[11]);
|
|||
|
int outLen1 = snprintf(log, LOG_BUF_LEN, "LogDeb:");
|
|||
|
int outLen2 = vsnprintf((log+outLen1), LOG_BUF_LEN-outLen1, (const char*)format, ap);
|
|||
|
//strcat(log, "\r\n") ;
|
|||
|
if(outLen2 > 0)
|
|||
|
UARTx_SendData(UART_DEBUG, log, outLen2+outLen1);
|
|||
|
else //vsnprintfִ<66><D6B4>ʧ<EFBFBD><CAA7>
|
|||
|
SysErr("") ;
|
|||
|
va_end(ap) ;
|
|||
|
portFree(log) ;
|
|||
|
}
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
/*********************************************************************************************************************
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD>void ErrorLog( char *format, ...)
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ܣ<EFBFBD>UART_DEBUG<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|||
|
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽΪ<EFBFBD><EFBFBD> DEBUG Log: 14:40:20 + log<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*********************************************************************************************************************/
|
|||
|
void ErrorLogPrintf( char *format, ...)
|
|||
|
{
|
|||
|
#if(configERRORLOGPRINTF_ENABLE == 1)
|
|||
|
{
|
|||
|
va_list ap; //apָ<70><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ַ
|
|||
|
va_start (ap, format); //<2F><>apָ<70><D6B8>ָ<EFBFBD><D6B8><EFBFBD>ɱ<EFBFBD><C9B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
char *log = portMalloc(LOG_BUF_LEN) ;
|
|||
|
//printf("\r\nErrLog: %s ", &uCalendar.bytes[11]) ;
|
|||
|
//int outLen = vsnprintf(log, LOG_BUF_LEN, (const char*)format, ap);
|
|||
|
//int outLen1 = snprintf(log, LOG_BUF_LEN, "\r\nErrLog: %s ", &uCalendar.bytes[11]);
|
|||
|
int outLen1 = snprintf(log, LOG_BUF_LEN, "LogErr:");
|
|||
|
int outLen2 = vsnprintf((log+outLen1), LOG_BUF_LEN-outLen1, (const char*)format, ap);
|
|||
|
// strcat(log, "\r\n") ;
|
|||
|
if(outLen2 > 0)
|
|||
|
UARTx_SendData(UART_DEBUG, log, outLen2+outLen1);
|
|||
|
// printf((const char*)log) ;
|
|||
|
else //vsnprintfִ<66><D6B4>ʧ<EFBFBD><CAA7>
|
|||
|
SysErr("") ;
|
|||
|
va_end(ap) ;
|
|||
|
portFree(log) ;
|
|||
|
}
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|