#if KIT_FATFS_LOG_EN && KIT_FATFS_EN
TKIT_ErrType t_memory_WriteLog (char * log)
{
TKIT_ErrType err = TKIT_SUCCESS;
FRESULT res;
FIL fdst;
DIR dir;
INT32U bw;
FATFS fs;
INT8U log_path[64];
INT32U Time;
CTKIT_TIME *pTime;
//Mount file system
if( TKIT_SUCCESS==err)
{
res = f_mount(&fs,MEMORY_ROOT,0);
if(res != FR_OK){
err = E_MEM_FATLOGPATH;
}
}
if( TKIT_SUCCESS == err )
{
res = f_opendir(&dir,MEMORY_LOG_PATH);
if(res != FR_OK){
res = f_mkdir(MEMORY_LOG_PATH);
}
if(res != FR_OK){
err = E_MEM_FATMKPATH;
}
}
if( TKIT_SUCCESS == err )
{
std_ToString(log_path,"%s/%s",MEMORY_LOG_PATH,MEMORY_LOG_PATH_SON);
res = f_opendir(&dir,(char*)log_path);
if(res != FR_OK){
res = f_mkdir( (char*) log_path);
}
if(res != FR_OK){
err = E_MEM_FATMKPATH;
}
}
pTime = TKIT_TimeGet();
Time = pTime->Y * 10000 + pTime->M * 100 + pTime->D;
std_ToString(log_path,"%s/%s/%8d.txt",MEMORY_LOG_PATH,MEMORY_LOG_PATH_SON,Time);
if( TKIT_SUCCESS==err)
{
res = f_open(&fdst,(char*)log_path, FA_OPEN_ALWAYS|FA_WRITE);
if(res != FR_OK){
err = E_MEM_FATLOGFILE;
}
}
//дÈëÈÕÖ¾Îı¾Ä©¶Ë
if( TKIT_SUCCESS==err)
{
std_ToString(log_path,"%2d:%2d:%2d ",pTime->h,pTime->m,pTime->s);
f_lseek(&fdst,(fdst).fsize);
res = f_write(&fdst, log_path, std_StrLen((char*)log_path), &bw);
f_lseek(&fdst,(fdst).fsize);
res = f_write(&fdst, log, std_StrLen((char*)log), &bw);
if(res != FR_OK){
err = E_MEM_FATLOGWRITE;
}
f_close(&fdst);// close file
}
//Unmount file system
f_mount(NULL,MEMORY_LOG_PATH,0);
if( TKIT_SUCCESS!=err)
{
cuart_Printf("<SD.Fat.Log> Write log. Error=0x%4x Fat err=%d\r\n",err,res );
}
return err;
}