//目前使用0X80200000 到 0X803FFFFF 这一区域 大小0x200000 (2097152u)
#define SDRAM_SAVELOG_ADDRESS 0x80200000
#define SDRAM_SAVELOG_SIZE (1000000u)
#define LOG_SIZE (32u) //理论上最大57723条
定义一些接口和实现方法:
extern void SaveDataLogInit(void);
extern char* GetSaveDataLogAddress(void);
extern char* GetSaveDataLogHandle(void);
unsigned int GetSaveDataLength(void);
extern void SaveDataLog(const char *string);
extern void SaveDataLogPrintf(char* operation, \
char* file_name, \
int operation_result,\
int option);
extern void SaveDataLogPrintfGetF(char* drv, \
int free, \
int operation_result);
//定义一个句柄
char *SaveDataLogHandle;
//初始化内存空间和句柄
void SaveDataLogInit(void)
{
SaveDataLogHandle = (char *)SDRAM_SAVELOG_ADDRESS;
memset(SaveDataLogHandle, 0, SDRAM_SAVELOG_SIZE);
}
//获取内存空间起始地址
char* GetSaveDataLogAddress(void)
{
return (char *)SDRAM_SAVELOG_ADDRESS;
}
//获取当前句柄即当前保存log的起始地址
char* GetSaveDataLogHandle(void)
{
return (char *)SaveDataLogHandle;
}
//获取当前已经保存的数据长度
unsigned int GetSaveDataLength(void)
{
return (((unsigned int)SaveDataLogHandle)-SDRAM_SAVELOG_ADDRESS);
}
//保存当前日志
void SaveDataLog(const char *string)
{
char SaveDataLog[LOG_SIZE]={0};
memset(SaveDataLog,0,LOG_SIZE);
memcpy(SaveDataLogHandle, string, LOG_SIZE);
SaveDataLogHandle+=LOG_SIZE;
}
一些专用的保存
void SaveDataLogPrintfGetF(char* drv, int free, int operation_result)
{
if(SaveDataLogHandle == NULL || (((unsigned int)SaveDataLogHandle) > 0x803FFFFF))
{
return;
}
// 填入时间信息
char time_log[10]={0};
memset(time_log,0,10);
sprintf(time_log,"%02d%02d%02d",HOU, \
MIN, \
SEC);
snprintf(SaveDataLogHandle,LOG_SIZE,"%sf_getfree%s %04d %02d",time_log,drv,free,operation_result);
memcpy(SaveDataLogHandle+LOG_SIZE-2,"\r\n",2);//强制以换行符结束
SaveDataLogHandle+=LOG_SIZE;
}
void SaveDataLogPrintf(char* operation, char* file_name, int operation_result, int option)
{
if(SaveDataLogHandle == NULL || (((unsigned int)SaveDataLogHandle) > 0x803FFFFF))
{
return;
}
// 填入时间信息
char time_log[10]={0};
memset(time_log,0,10);
sprintf(time_log,"%02d%02d%02d",PARAMETER_BPAP_HOU, \
PARAMETER_BPAP_MIN, \
PARAMETER_BPAP_SEC);
snprintf(SaveDataLogHandle,LOG_SIZE,"%s%s%s %02d %04d",time_log,operation,&file_name[3],operation_result,option);
memcpy(SaveDataLogHandle+LOG_SIZE-2,"\r\n",2);//强制以换行符结束
SaveDataLogHandle+=LOG_SIZE;
}
//一些格式化输出标志
#define F_OPEN "f_open"
#define F_WRITE "f_write"
#define F_LSEEK "f_lseek"
#define F_CLOSE "f_close"
#define F_READ "f_read"
#define FILE_TYPE_S "s"
#define FILE_TYPE_M "m"
#define FILE_TYPE_D "d"
#define FILE_TYPE_SPACE " "