2351 lines
58 KiB
C
2351 lines
58 KiB
C
/*------------------------------------------------------------
|
|
(C) Copyright [2006-2008] Marvell International Ltd.
|
|
All Rights Reserved
|
|
------------------------------------------------------------*/
|
|
|
|
/*--------------------------------------------------------------------------------------------------------------------
|
|
INTEL CONFIDENTIAL
|
|
Copyright 2006 Intel Corporation All Rights Reserved.
|
|
The source code contained or described herein and all documents related to the source code ("Material") are owned
|
|
by Intel Corporation or its suppliers or licensors. Title to the Material remains with Intel Corporation or
|
|
its suppliers and licensors. The Material contains trade secrets and proprietary and confidential information of
|
|
Intel or its suppliers and licensors. The Material is protected by worldwide copyright and trade secret laws and
|
|
treaty provisions. No part of the Material may be used, copied, reproduced, modified, published, uploaded, posted,
|
|
transmitted, distributed, or disclosed in any way without Intel's prior express written permission.
|
|
|
|
No license under any patent, copyright, trade secret or other intellectual property right is granted to or
|
|
conferred upon you by disclosure or delivery of the Materials, either expressly, by implication, inducement,
|
|
estoppel or otherwise. Any license under such intellectual property rights must be express and approved by
|
|
Intel in writing.
|
|
-------------------------------------------------------------------------------------------------------------------*/
|
|
|
|
/******************************************************************************
|
|
* MODULE IMPLEMENTATION FILE
|
|
*******************************************************************************
|
|
* Title: CrossPlatformSW *
|
|
* Filename: crossPlatformSW.c
|
|
*
|
|
* Target, platform: Common Platform, SW platform
|
|
*
|
|
* Authors:
|
|
*
|
|
* Description:
|
|
*
|
|
* Last Updated:
|
|
*
|
|
* Notes:
|
|
******************************************************************************/
|
|
|
|
/*----------- Local include files --------------------------------------------*/
|
|
#include "stdlib.h"
|
|
#include "global_types.h"
|
|
#include "diag_API.h"
|
|
|
|
#if (defined FEATURE_ACNVM) && !defined(CRANE_MCU_DONGLE)
|
|
#if (defined FLAVOR_APP)
|
|
#include "nvm_server.h"
|
|
#endif
|
|
#if (defined FLAVOR_COM)
|
|
#include "nvmClient.h"
|
|
#endif
|
|
#endif
|
|
|
|
#ifdef RTC_TUNNEL_ENABLE
|
|
#include "rtct_shared.h"
|
|
#endif
|
|
|
|
#include "bsp.h"
|
|
#ifndef CRANE_MCU_DONGLE
|
|
#include "FDI2FS_API.h"
|
|
#endif
|
|
#include "fat32_utils.h"
|
|
#include "crossPlatformSW.h"
|
|
#include "FDI_ERR.h"
|
|
#include "FDI_EXT.h"
|
|
#include "FDI_FILE.h"
|
|
|
|
#ifdef LFS_FILE_SYS
|
|
#include "fattypes.h"
|
|
#include "lfs_api.h"
|
|
#endif
|
|
//#include "ff.h"
|
|
|
|
#include "simPin.h"
|
|
#if defined(FOTA_RS_FEATURE) || defined(FOTA_GS_FEATURE)
|
|
#include "stdlib_util.h"
|
|
#endif
|
|
#include "UART.h"
|
|
#include "MRD.h"
|
|
|
|
extern BOOL is_ram_fs;
|
|
extern void DbgPrintf(char* fmt, ...);
|
|
extern int eeSDDump_status_get(void);
|
|
|
|
#ifdef NEZHA3_1826
|
|
extern void SetAXISD(unsigned char set_flag);
|
|
extern unsigned char Is_Nezha3Stepping_FromZ3(void);
|
|
#endif
|
|
|
|
extern void qspi_printf(char* fmt, ...);
|
|
extern unsigned int spi_nor_do_read(unsigned int addr, unsigned int buf_addr, unsigned int size, BOOL flashType);
|
|
extern int spi_nor_do_erase_4k(unsigned int addr, unsigned int size, BOOL flashType);
|
|
extern unsigned int spi_nor_do_write(unsigned int addr, unsigned int buf_addr,unsigned int size, BOOL flashType);
|
|
|
|
|
|
#ifdef DM_RF_ADC_SUPPORT
|
|
#define MAX_DEVID_SIZE 512
|
|
#define MAX_SECURE_SIZE 2048
|
|
#define MAX_ADC_Data_LEN 10
|
|
#define MAX_ADC_GROUP_CNT 10
|
|
#define ITEM_ADC_SIZE (MAX_ADC_Data_LEN*2*MAX_ADC_GROUP_CNT*(TEMP_TYPE_MAX-1)+8+8) //416 bytes
|
|
UINT32 DevIDFlag=0;
|
|
typedef struct
|
|
{
|
|
UINT32 head;
|
|
UINT32 cnt_RtnAdcTemp[TEMP_TYPE_MAX-1]; //8 bytes
|
|
UINT8 item_RtnAdcTemp[ITEM_ADC_SIZE]; //416 bytes, include vbat adc data in low/high temerature
|
|
UINT8 resv[4096-8-104-216-MAX_SECURE_SIZE-4-MAX_DEVID_SIZE-4-216-ITEM_ADC_SIZE-4*(TEMP_TYPE_MAX-1)]; //560 bytes
|
|
UINT32 cnt_adc_rtp;
|
|
UINT8 item_adc_rtp[212]; //length must be the same as item_adc
|
|
UINT32 cnt_devid;
|
|
UINT8 item_devid[MAX_DEVID_SIZE]; //512 bytes
|
|
UINT32 cnt_secu;
|
|
UINT8 item_secu[MAX_SECURE_SIZE]; //2048 bytes
|
|
UINT32 cnt_adc;
|
|
UINT8 item_adc[212];
|
|
UINT32 cnt_wcard;
|
|
UINT8 item_wcard[100];
|
|
UINT32 tail;
|
|
|
|
}mrd_extra_sector_t;
|
|
|
|
|
|
|
|
extern UINT32 WCardFlag;
|
|
extern UINT8 WCardBuf[100];
|
|
extern UINT32 ADCFlag[];
|
|
extern UINT32 ADCFlag2;
|
|
extern MRDADCInfoS ADCInfoData[];
|
|
extern MRDADCInfoS2 ADCInfoData2;
|
|
extern UINT32 SecuFlag;
|
|
|
|
UINT32 flush_erase_write_time=4000;
|
|
//UINT32 nvm_tfs_write_buf_cmp[4096/4];
|
|
UINT32 *nvm_tfs_write_buf_cmp = NULL;
|
|
|
|
|
|
|
|
|
|
//UINT32 mrd_extra_info_write(UINT32 time)
|
|
extern UINT32 factory_flash_type;
|
|
|
|
|
|
BOOL mrd_extra_info_update_flag[2] = {TRUE,TRUE};
|
|
UINT32 mrd_extra_info_write(void)
|
|
{
|
|
|
|
UINT32 mrd_flash_addr = GetMRDFlashAddress();
|
|
#ifndef MRD_FACTORY_MIN_SIZE
|
|
UINT32 mrd_bak_flash_addr = GetMRDBakFlashAddress();
|
|
#endif
|
|
UINT32 addr;
|
|
mrd_extra_sector_t *p_mrd_extra_sector;
|
|
|
|
UINT32 mrd_extra_offset = MRD_IMAGE_TOTAL_SIZE;
|
|
UINT32 mrd_extra_size = FLASH_SECTOR_SIZE;
|
|
int i=0,j=0;
|
|
ADC_TEMP_t tempID=0;
|
|
|
|
//if((WCardFlag==0)&&(SecuFlag==0)&&(ADCFlag[ADC_VBAT]==0)&&(ADCFlag[ADC_RTP]==0)&&(DevIDFlag==0)&&(ADCFlag2==0))
|
|
if((ADCFlag[ADC_VBAT]==0)&&(ADCFlag[ADC_RTP]==0)&&(ADCFlag2==0))
|
|
return 0;
|
|
|
|
if ((nvm_tfs_write_buf_cmp = calloc(4096, 1)) == NULL) {
|
|
utlError(132,"mrd_extra_info_write: fail to calloc(%d, %d) failed\n", 4096, 1);
|
|
return NULL;
|
|
}
|
|
|
|
p_mrd_extra_sector=(mrd_extra_sector_t *)nvm_tfs_write_buf_cmp;
|
|
|
|
|
|
addr=mrd_flash_addr+mrd_extra_offset;
|
|
spi_nor_do_read(addr,(unsigned int)nvm_tfs_write_buf_cmp, mrd_extra_size, factory_flash_type);
|
|
|
|
|
|
CPUartLogPrintf("%s: mrd adc head=0x%x, tail=0x%x",__FUNCTION__,p_mrd_extra_sector->head,p_mrd_extra_sector->tail);
|
|
|
|
if((ADCFlag[ADC_VBAT]==1))
|
|
{
|
|
p_mrd_extra_sector->cnt_adc=0;
|
|
for(i=0;i<MAX_ADC_GROUP_CNT;i++)
|
|
{
|
|
for(j=0;j<MAX_ADC_Data_LEN*2;j++)
|
|
{
|
|
if((((UINT8 *)&ADCInfoData[ADC_VBAT].info.value[i])[j])!=0)
|
|
{
|
|
p_mrd_extra_sector->cnt_adc++;
|
|
CPUartLogPrintf("adc: %d %d cnt=%d\r\n",i,j,p_mrd_extra_sector->cnt_adc);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// p_mrd_extra_sector->cnt_adc++;
|
|
memcpy(p_mrd_extra_sector->item_adc, &ADCInfoData[ADC_VBAT], sizeof(p_mrd_extra_sector->item_adc));
|
|
}
|
|
if((ADCFlag[ADC_RTP]==1))
|
|
{
|
|
p_mrd_extra_sector->cnt_adc_rtp=0;
|
|
for(i=0;i<MAX_ADC_GROUP_CNT;i++)
|
|
{
|
|
for(j=0;j<MAX_ADC_Data_LEN*2;j++)
|
|
{
|
|
if((((UINT8 *)&ADCInfoData[ADC_RTP].info.value[i])[j])!=0)
|
|
{
|
|
p_mrd_extra_sector->cnt_adc_rtp++;
|
|
CPUartLogPrintf("rtp adc: %d %d %d\r\n",i,j,p_mrd_extra_sector->cnt_adc);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// p_mrd_extra_sector->cnt_adc++;
|
|
memcpy(p_mrd_extra_sector->item_adc_rtp, &ADCInfoData[ADC_RTP], sizeof(p_mrd_extra_sector->item_adc_rtp));
|
|
}
|
|
if((ADCFlag2==1))
|
|
{
|
|
memset(p_mrd_extra_sector->cnt_RtnAdcTemp, 0, (TEMP_TYPE_MAX-1)*4);
|
|
for(tempID=0; tempID<(TEMP_TYPE_MAX-1); tempID++)
|
|
{
|
|
for(i=0;i<MAX_ADC_GROUP_CNT;i++)
|
|
{
|
|
for(j=0;j<MAX_ADC_Data_LEN*2;j++)
|
|
{
|
|
if((((UINT8 *)&ADCInfoData2.info.value[tempID][i])[j])!=0)
|
|
{
|
|
p_mrd_extra_sector->cnt_RtnAdcTemp[tempID]++;
|
|
// uart_printf("value[%d][%d]: %d %d\r\n",tempID, i,j,p_mrd_extra_sector->cnt_RtnAdcTemp[tempID]);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
CPUartLogPrintf("cnt: value[%d][%d]:%d %d\r\n",tempID,i,j, p_mrd_extra_sector->cnt_RtnAdcTemp[tempID]);
|
|
}
|
|
|
|
memcpy(p_mrd_extra_sector->item_RtnAdcTemp, &ADCInfoData2, sizeof(p_mrd_extra_sector->item_RtnAdcTemp));
|
|
}
|
|
|
|
spi_nor_do_erase_4k(addr, mrd_extra_size, factory_flash_type);
|
|
spi_nor_do_write(addr, (unsigned int)nvm_tfs_write_buf_cmp, mrd_extra_size, factory_flash_type);
|
|
|
|
#ifndef MRD_FACTORY_MIN_SIZE
|
|
addr=mrd_bak_flash_addr+mrd_extra_offset;
|
|
|
|
spi_nor_do_erase_4k(addr, mrd_extra_size, factory_flash_type);
|
|
spi_nor_do_write(addr, (unsigned int)nvm_tfs_write_buf_cmp, mrd_extra_size, factory_flash_type);
|
|
#endif
|
|
|
|
ADCFlag[ADC_VBAT]=0;
|
|
ADCFlag[ADC_RTP]=0;
|
|
ADCFlag2=0;
|
|
|
|
if(nvm_tfs_write_buf_cmp != NULL)
|
|
{
|
|
free(nvm_tfs_write_buf_cmp);
|
|
nvm_tfs_write_buf_cmp = NULL;
|
|
}
|
|
|
|
CPUartLogPrintf("%s: end",__FUNCTION__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
void mrd_extra_info_init(void)
|
|
{
|
|
UINT32 mrd_flash_addr = GetMRDFlashAddress();
|
|
#ifndef MRD_FACTORY_MIN_SIZE
|
|
UINT32 mrd_bak_flash_addr = GetMRDBakFlashAddress();
|
|
#endif
|
|
UINT32 addr;
|
|
|
|
UINT32 mrd_extra_offset = MRD_IMAGE_TOTAL_SIZE;
|
|
UINT32 mrd_extra_size = FLASH_SECTOR_SIZE;
|
|
|
|
|
|
mrd_extra_sector_t *p_mrd_extra_sector = NULL ;
|
|
mrd_extra_sector_t *p_mrd_extra_sector_bak = NULL ;
|
|
UINT32 a_ok=0;
|
|
UINT32 b_ok=0;
|
|
UINT32 adc_ok=1;
|
|
ADC_TEMP_t tempID=0;
|
|
|
|
|
|
UINT8 *p_buf = NULL ;
|
|
UINT8 *p_buf_bak = NULL ;
|
|
UINT8 adcFirstInitFlag=0;
|
|
|
|
CPUartLogPrintf("%s: enter", __FUNCTION__);
|
|
|
|
p_buf=(UINT8*)malloc(mrd_extra_size);
|
|
if(p_buf == NULL)
|
|
{
|
|
CPUartLogPrintf("mrd_extra_info_init: p_buf malloc error");
|
|
return;
|
|
}
|
|
|
|
#ifndef MRD_FACTORY_MIN_SIZE
|
|
p_buf_bak=(UINT8*)malloc(mrd_extra_size);
|
|
if(p_buf_bak == NULL)
|
|
{
|
|
CPUartLogPrintf("mrd_extra_info_init: p_buf_bak malloc error");
|
|
free(p_buf);
|
|
p_buf = NULL;
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
addr=mrd_flash_addr+mrd_extra_offset;
|
|
spi_nor_do_read(addr,(unsigned int)p_buf, mrd_extra_size, factory_flash_type);
|
|
p_mrd_extra_sector=(mrd_extra_sector_t*)p_buf;
|
|
|
|
if((p_mrd_extra_sector->head==0x12345678)&&(p_mrd_extra_sector->tail==0x87654321))
|
|
a_ok=1;
|
|
|
|
#ifndef MRD_FACTORY_MIN_SIZE
|
|
addr=mrd_bak_flash_addr+mrd_extra_offset;
|
|
spi_nor_do_read(addr, (unsigned int)p_buf_bak, mrd_extra_size, factory_flash_type);
|
|
p_mrd_extra_sector_bak=(mrd_extra_sector_t*)p_buf_bak;
|
|
|
|
if((p_mrd_extra_sector_bak->head==0x12345678)&&(p_mrd_extra_sector_bak->tail==0x87654321))
|
|
b_ok=1;
|
|
#endif
|
|
|
|
RTI_LOG("a_ok=%d, b_ok=%d\r\n",a_ok,b_ok);
|
|
|
|
if((a_ok==0)
|
|
#ifndef MRD_FACTORY_MIN_SIZE
|
|
&&(b_ok==0)
|
|
#endif
|
|
)
|
|
{
|
|
|
|
RTI_LOG("%s, do first init\r\n",__func__);
|
|
memset(p_buf, 0xFF, mrd_extra_size);
|
|
p_mrd_extra_sector->head=0x12345678;
|
|
p_mrd_extra_sector->cnt_devid=0;
|
|
p_mrd_extra_sector->cnt_secu=0;
|
|
p_mrd_extra_sector->cnt_adc_rtp=0; //added
|
|
p_mrd_extra_sector->cnt_adc=0;
|
|
memset(p_mrd_extra_sector->cnt_RtnAdcTemp, 0, (TEMP_TYPE_MAX-1)*4);
|
|
p_mrd_extra_sector->cnt_wcard=0;
|
|
memset(p_mrd_extra_sector->item_wcard, 0, sizeof(p_mrd_extra_sector->item_wcard));
|
|
memset(p_mrd_extra_sector->item_adc_rtp, 0, sizeof(p_mrd_extra_sector->item_adc_rtp));//added
|
|
memset(p_mrd_extra_sector->item_adc, 0, sizeof(p_mrd_extra_sector->item_adc));
|
|
memset(p_mrd_extra_sector->item_RtnAdcTemp, 0, sizeof(p_mrd_extra_sector->item_RtnAdcTemp));
|
|
memset(p_mrd_extra_sector->item_secu, 0, sizeof(p_mrd_extra_sector->item_secu));
|
|
memset(p_mrd_extra_sector->item_devid, 0, sizeof(p_mrd_extra_sector->item_devid));
|
|
p_mrd_extra_sector->tail=0x87654321;
|
|
|
|
addr=mrd_flash_addr+mrd_extra_offset;
|
|
spi_nor_do_erase_4k(addr, mrd_extra_size, factory_flash_type);
|
|
spi_nor_do_write(addr, (unsigned int)p_buf, mrd_extra_size, factory_flash_type);
|
|
|
|
#ifndef MRD_FACTORY_MIN_SIZE
|
|
addr=mrd_bak_flash_addr+mrd_extra_offset;
|
|
spi_nor_do_erase_4k(addr, mrd_extra_size, factory_flash_type);
|
|
spi_nor_do_write(addr, (unsigned int)p_buf, mrd_extra_size, factory_flash_type);
|
|
#endif
|
|
|
|
}
|
|
#ifndef MRD_FACTORY_MIN_SIZE
|
|
else if((a_ok==1)&&(b_ok==0))
|
|
{
|
|
addr=mrd_bak_flash_addr+mrd_extra_offset;
|
|
spi_nor_do_erase_4k(addr, mrd_extra_size, factory_flash_type);
|
|
spi_nor_do_write(addr, (unsigned int)p_buf, mrd_extra_size, factory_flash_type);
|
|
}
|
|
else if((a_ok==0)&&(b_ok==1))
|
|
{
|
|
addr=mrd_flash_addr+mrd_extra_offset;
|
|
spi_nor_do_erase_4k(addr, mrd_extra_size, factory_flash_type);
|
|
spi_nor_do_write(addr, (unsigned int)p_buf_bak, mrd_extra_size, factory_flash_type);
|
|
}
|
|
#endif
|
|
else if((a_ok==1)
|
|
#ifndef MRD_FACTORY_MIN_SIZE
|
|
&&(b_ok==1)
|
|
#endif
|
|
)
|
|
{
|
|
if(p_mrd_extra_sector->cnt_adc==0xFFFFFFFF)
|
|
{
|
|
CPUartLogPrintf("First MRD vbat adc init\r\n");
|
|
p_mrd_extra_sector->cnt_adc=0;
|
|
memset(p_mrd_extra_sector->item_adc, 0, sizeof(p_mrd_extra_sector->item_adc));
|
|
adcFirstInitFlag=1;
|
|
}
|
|
if(p_mrd_extra_sector->cnt_adc_rtp==0xFFFFFFFF)
|
|
{
|
|
CPUartLogPrintf("First MRD rtp adc init\r\n");
|
|
p_mrd_extra_sector->cnt_adc_rtp=0;
|
|
memset(p_mrd_extra_sector->item_adc_rtp, 0, sizeof(p_mrd_extra_sector->item_adc_rtp));
|
|
adcFirstInitFlag=1;
|
|
}
|
|
if((p_mrd_extra_sector->cnt_RtnAdcTemp[0]==0xFFFFFFFF)&&(p_mrd_extra_sector->cnt_RtnAdcTemp[1]==0xFFFFFFFF))
|
|
{
|
|
CPUartLogPrintf("First MRD adcTemp init\r\n");
|
|
memset(p_mrd_extra_sector->cnt_RtnAdcTemp, 0, (TEMP_TYPE_MAX-1)*4);
|
|
memset(p_mrd_extra_sector->item_RtnAdcTemp, 0, sizeof(p_mrd_extra_sector->item_RtnAdcTemp));
|
|
adcFirstInitFlag=1;
|
|
}
|
|
if(adcFirstInitFlag==1)
|
|
{
|
|
addr=mrd_flash_addr+mrd_extra_offset;
|
|
spi_nor_do_erase_4k(addr, mrd_extra_size, factory_flash_type);
|
|
spi_nor_do_write(addr, (unsigned int)p_buf, mrd_extra_size, factory_flash_type);
|
|
|
|
#ifndef MRD_FACTORY_MIN_SIZE
|
|
addr=mrd_bak_flash_addr+mrd_extra_offset;
|
|
spi_nor_do_erase_4k(addr, mrd_extra_size, factory_flash_type);
|
|
spi_nor_do_write(addr, (unsigned int)p_buf, mrd_extra_size, factory_flash_type);
|
|
#endif
|
|
}
|
|
|
|
#ifndef MRD_FACTORY_MIN_SIZE
|
|
for(tempID=0; tempID<(TEMP_TYPE_MAX-1); tempID++)
|
|
if(p_mrd_extra_sector->cnt_RtnAdcTemp[tempID]>p_mrd_extra_sector_bak->cnt_RtnAdcTemp[tempID])
|
|
adc_ok=0;
|
|
if((p_mrd_extra_sector->cnt_wcard>p_mrd_extra_sector_bak->cnt_wcard)||(adc_ok==0)||(p_mrd_extra_sector->cnt_adc>p_mrd_extra_sector_bak->cnt_adc)||(p_mrd_extra_sector->cnt_secu>p_mrd_extra_sector_bak->cnt_secu)
|
|
||(p_mrd_extra_sector->cnt_devid>p_mrd_extra_sector_bak->cnt_devid)||(p_mrd_extra_sector->cnt_adc_rtp > p_mrd_extra_sector_bak->cnt_adc_rtp))
|
|
{
|
|
RTI_LOG("Copy to Main from Bak\r\n");
|
|
addr=mrd_bak_flash_addr+mrd_extra_offset;
|
|
spi_nor_do_erase_4k(addr, mrd_extra_size, factory_flash_type);
|
|
spi_nor_do_write(addr, (unsigned int)p_buf, mrd_extra_size, factory_flash_type);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
if(p_buf != NULL)
|
|
{
|
|
free(p_buf);
|
|
p_buf = NULL;
|
|
}
|
|
|
|
#ifndef MRD_FACTORY_MIN_SIZE
|
|
if(p_buf_bak != NULL)
|
|
{
|
|
free(p_buf_bak);
|
|
p_buf_bak = NULL;
|
|
}
|
|
#endif
|
|
|
|
CPUartLogPrintf("%s: leave",__FUNCTION__);
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
|
|
void mrd_extra_info_get(void)
|
|
{
|
|
|
|
UINT32 mrd_flash_addr = GetMRDFlashAddress();
|
|
UINT32 addr;
|
|
|
|
// CPUartLogPrintf("%s: enter,type=%d", __FUNCTION__,type);
|
|
|
|
|
|
mrd_extra_sector_t *p_mrd_extra_sector;
|
|
|
|
UINT32 mrd_extra_offset = MRD_IMAGE_TOTAL_SIZE;
|
|
UINT32 mrd_extra_size = FLASH_SECTOR_SIZE;
|
|
|
|
UINT8 *p_buf;
|
|
|
|
p_buf=(UINT8*)malloc(mrd_extra_size);
|
|
if(p_buf == NULL)
|
|
{
|
|
//ASSERT(0);
|
|
CPUartLogPrintf("%s: malloc error", __FUNCTION__);
|
|
return;
|
|
}
|
|
|
|
p_mrd_extra_sector=(mrd_extra_sector_t *)p_buf;
|
|
|
|
addr=mrd_flash_addr+mrd_extra_offset;
|
|
|
|
if(ADCFlag[ADC_VBAT]==0)
|
|
{
|
|
spi_nor_do_read(addr, (unsigned int)p_buf, mrd_extra_size, factory_flash_type);
|
|
memcpy(&ADCInfoData[ADC_VBAT], p_mrd_extra_sector->item_adc, sizeof(p_mrd_extra_sector->item_adc));
|
|
}
|
|
if(ADCFlag[ADC_RTP]==0)
|
|
{
|
|
spi_nor_do_read(addr, (unsigned int)p_buf, mrd_extra_size, factory_flash_type);
|
|
memcpy(&ADCInfoData[ADC_RTP], p_mrd_extra_sector->item_adc_rtp, sizeof(p_mrd_extra_sector->item_adc_rtp));
|
|
}
|
|
if(ADCFlag2==0)
|
|
{
|
|
spi_nor_do_read(addr, (unsigned int)p_buf, mrd_extra_size, factory_flash_type);
|
|
|
|
memcpy(&ADCInfoData2, p_mrd_extra_sector->item_RtnAdcTemp, sizeof(p_mrd_extra_sector->item_RtnAdcTemp));
|
|
}
|
|
|
|
if(p_buf != NULL)
|
|
{
|
|
free(p_buf);
|
|
p_buf = NULL;
|
|
}
|
|
|
|
|
|
}
|
|
#endif
|
|
|
|
//#define ENABLE_SERVER_EEH_DUMP_TASK 1
|
|
|
|
|
|
typedef enum
|
|
{
|
|
RFS_FS_MODE,
|
|
RAM_FS_MODE,
|
|
SVR_FS_MODE,
|
|
FAT_FS_MODE,
|
|
TFS_FS_MODE
|
|
}FS_MODE_t;
|
|
|
|
|
|
FS_MODE_t fs_mode=SVR_FS_MODE;
|
|
|
|
FS_MODE_t get_fs_mode(void)
|
|
{
|
|
return fs_mode;
|
|
}
|
|
|
|
unsigned int fs_mode_is_fat(void)
|
|
{
|
|
if(fs_mode==FAT_FS_MODE)
|
|
return 1;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
|
|
unsigned int fs_mode_is_tfs(void)
|
|
{
|
|
|
|
if(fs_mode==TFS_FS_MODE)
|
|
return 1;
|
|
else
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
unsigned int fs_mode_is_ramfs(void)
|
|
{
|
|
|
|
if(fs_mode==RAM_FS_MODE)
|
|
return 1;
|
|
else
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
void set_fs_mode(FS_MODE_t mode)
|
|
{
|
|
DbgPrintf("set_fs_mode %d\r\n",mode);
|
|
fs_mode=mode;
|
|
}
|
|
|
|
void nvm_axi_lock(void)
|
|
{
|
|
#ifdef NEZHA3_1826
|
|
if(Is_Nezha3Stepping_FromZ3() && (get_fs_mode()==SVR_FS_MODE))
|
|
SetAXISD(0);
|
|
#endif
|
|
}
|
|
|
|
void nvm_axi_un_lock(void)
|
|
{
|
|
#ifdef NEZHA3_1826
|
|
if(Is_Nezha3Stepping_FromZ3() && (get_fs_mode()==SVR_FS_MODE))
|
|
SetAXISD(1);
|
|
#endif
|
|
}
|
|
|
|
|
|
|
|
FILE_ID FDI_fopen(const char *filename_ptr, const char *mode)
|
|
{
|
|
|
|
FILE_ID stream = 0;
|
|
|
|
int ret;
|
|
UINT32 fd;
|
|
|
|
#ifdef FDI_TEST
|
|
uart_printf("FDI_fopen %d, %s,%s\r\n",get_fs_mode(), filename_ptr, mode);
|
|
#endif
|
|
nvm_axi_lock();
|
|
|
|
if(get_fs_mode()==FAT_FS_MODE)
|
|
{
|
|
stream = FDI_fopen_fatsys(filename_ptr, mode);
|
|
}
|
|
#ifndef CRANE_MCU_DONGLE
|
|
else if(get_fs_mode()==SVR_FS_MODE)
|
|
{
|
|
stream = FDI_fopen_2chip(filename_ptr, mode);
|
|
}
|
|
else if(get_fs_mode()==RAM_FS_MODE)
|
|
{
|
|
stream = FDI_fopen_2chip(filename_ptr, mode);
|
|
}
|
|
else if(get_fs_mode()==RFS_FS_MODE)
|
|
{
|
|
stream = FDI_fopen_2chip(filename_ptr, mode);
|
|
}
|
|
else if(get_fs_mode()==TFS_FS_MODE)
|
|
{
|
|
ret = nvm_tfs_fopen(filename_ptr, mode, &fd);
|
|
if(ret==0)
|
|
stream=fd;
|
|
}
|
|
#endif
|
|
|
|
#ifdef FDI_TEST
|
|
uart_printf("FDI_fopen %s,%s=0x%x\r\n",filename_ptr, mode, stream);
|
|
#endif
|
|
|
|
nvm_axi_un_lock();
|
|
|
|
|
|
return stream;
|
|
}
|
|
|
|
|
|
int FDI_fclose(FILE_ID stream)
|
|
{
|
|
/*Fixed coverity[uninit_use]*/
|
|
int ret = 0;
|
|
|
|
#ifdef FDI_TEST
|
|
uart_printf("FDI_fclose 0x%x\r\n",stream);
|
|
#endif
|
|
nvm_axi_lock();
|
|
|
|
if(get_fs_mode()==FAT_FS_MODE)
|
|
{
|
|
ret = FDI_fclose_fatsys(stream);
|
|
}
|
|
#ifndef CRANE_MCU_DONGLE
|
|
else if(get_fs_mode()==SVR_FS_MODE)
|
|
{
|
|
ret = FDI_fclose_2chip(stream);
|
|
}
|
|
else if(get_fs_mode()==RAM_FS_MODE)
|
|
{
|
|
ret = FDI_fclose_2chip(stream);
|
|
}
|
|
else if(get_fs_mode()==RFS_FS_MODE)
|
|
{
|
|
ret = FDI_fclose_2chip(stream);
|
|
}
|
|
else if(get_fs_mode()==TFS_FS_MODE)
|
|
{
|
|
ret = nvm_tfs_fclose(stream);
|
|
}
|
|
#endif
|
|
|
|
nvm_axi_un_lock();
|
|
|
|
#ifndef CRANE_MCU_DONGLE
|
|
if(get_fs_mode()==TFS_FS_MODE)
|
|
RamBlockSyncCheckTrigger();
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
size_t FDI_fread(void *buffer_ptr, size_t element_size, size_t count, FILE_ID stream)
|
|
{
|
|
|
|
/*Fixed coverity[uninit_use]*/
|
|
size_t ret = 0;
|
|
#ifdef FDI_TEST
|
|
uart_printf("FDI_fread 0x%x\r\n",stream);
|
|
#endif
|
|
nvm_axi_lock();
|
|
|
|
if(get_fs_mode()==FAT_FS_MODE)
|
|
{
|
|
ret = FDI_fread_fatsys(buffer_ptr, element_size, count, stream);
|
|
}
|
|
#ifndef CRANE_MCU_DONGLE
|
|
else if(get_fs_mode()==SVR_FS_MODE)
|
|
{
|
|
ret = FDI_fread_2chip(buffer_ptr, element_size, count, stream);
|
|
}
|
|
else if(get_fs_mode()==RAM_FS_MODE)
|
|
{
|
|
ret = FDI_fread_2chip(buffer_ptr, element_size, count, stream);
|
|
}
|
|
else if(get_fs_mode()==RFS_FS_MODE)
|
|
{
|
|
ret = FDI_fread_2chip(buffer_ptr, element_size, count, stream);
|
|
}
|
|
else if(get_fs_mode()==TFS_FS_MODE)
|
|
{
|
|
ret = nvm_tfs_fread(buffer_ptr, element_size, count, stream);
|
|
}
|
|
#endif
|
|
|
|
nvm_axi_un_lock();
|
|
|
|
return ret;
|
|
}
|
|
|
|
|
|
size_t FDI_fwrite(const void *buffer_ptr,size_t element_size,size_t count,FILE_ID stream)
|
|
{
|
|
|
|
/*Fixed coverity[uninit_use]*/
|
|
size_t ret=0;
|
|
|
|
#ifdef FDI_TEST
|
|
uart_printf("FDI_fwrite 0x%x\r\n",stream);
|
|
#endif
|
|
nvm_axi_lock();
|
|
|
|
if(get_fs_mode()==FAT_FS_MODE)
|
|
{
|
|
ret = FDI_fwrite_fatsys(buffer_ptr, element_size, count, stream);
|
|
}
|
|
#ifndef CRANE_MCU_DONGLE
|
|
else if(get_fs_mode()==SVR_FS_MODE)
|
|
{
|
|
ret = FDI_fwrite_2chip(buffer_ptr, element_size, count, stream);
|
|
}
|
|
else if(get_fs_mode()==RAM_FS_MODE)
|
|
{
|
|
ret = FDI_fwrite_2chip(buffer_ptr, element_size, count, stream);
|
|
}
|
|
else if(get_fs_mode()==RFS_FS_MODE)
|
|
{
|
|
ret = FDI_fwrite_2chip(buffer_ptr, element_size, count, stream);
|
|
}
|
|
else if(get_fs_mode()==TFS_FS_MODE)
|
|
{
|
|
ret = nvm_tfs_fwrite(buffer_ptr, element_size, count, stream);
|
|
}
|
|
#endif
|
|
|
|
nvm_axi_un_lock();
|
|
|
|
return ret;
|
|
}
|
|
|
|
|
|
|
|
|
|
int FDI_fseek(FILE_ID stream, long offset, int wherefrom)
|
|
{
|
|
|
|
/*Fixed coverity[uninit_use]*/
|
|
int ret = 0;
|
|
|
|
|
|
if(offset<0)
|
|
{
|
|
qspi_printf("Doesn't support fseek minus\r\n");
|
|
ASSERT(0);
|
|
}
|
|
|
|
|
|
#ifdef FDI_TEST
|
|
uart_printf("FDI_fseek 0x%x\r\n",stream);
|
|
#endif
|
|
nvm_axi_lock();
|
|
|
|
if(get_fs_mode()==FAT_FS_MODE)
|
|
{
|
|
ret = FDI_fseek_fatsys(stream, offset, wherefrom);
|
|
}
|
|
#ifndef CRANE_MCU_DONGLE
|
|
else if(get_fs_mode()==SVR_FS_MODE)
|
|
{
|
|
ret = FDI_fseek_2chip(stream, offset, wherefrom);
|
|
}
|
|
else if(get_fs_mode()==RAM_FS_MODE)
|
|
{
|
|
ret = FDI_fseek_2chip(stream, offset, wherefrom);
|
|
}
|
|
else if(get_fs_mode()==RFS_FS_MODE)
|
|
{
|
|
ret = FDI_fseek_2chip(stream, offset, wherefrom);
|
|
}
|
|
else if(get_fs_mode()==TFS_FS_MODE)
|
|
{
|
|
ret = nvm_tfs_fseek(stream, offset, wherefrom);
|
|
}
|
|
#endif
|
|
|
|
nvm_axi_un_lock();
|
|
|
|
return ret;
|
|
}
|
|
|
|
|
|
int FDI_ftell(FILE_ID stream)
|
|
{
|
|
int ret = 0;
|
|
|
|
nvm_axi_lock();
|
|
|
|
if(get_fs_mode()==FAT_FS_MODE)
|
|
{
|
|
ret = FDI_ftell_fatsys(stream);
|
|
}
|
|
#ifndef CRANE_MCU_DONGLE
|
|
else if(get_fs_mode()==TFS_FS_MODE)
|
|
{
|
|
ret = nvm_tfs_ftell(stream);
|
|
}
|
|
#endif
|
|
|
|
nvm_axi_un_lock();
|
|
|
|
return ret;
|
|
}
|
|
|
|
|
|
unsigned int FDI_GetFileSize(int fd)
|
|
{
|
|
unsigned int ret = 0;
|
|
|
|
FILE_ID stream;
|
|
|
|
stream=(FILE_ID)fd;
|
|
|
|
#ifdef FDI_TEST
|
|
uart_printf("FDI_GetFileSize 0x%x\r\n",fd);
|
|
#endif
|
|
nvm_axi_lock();
|
|
|
|
if(get_fs_mode()==FAT_FS_MODE)
|
|
{
|
|
ret = FDI_fsize_fatsys(stream);
|
|
}
|
|
#ifndef CRANE_MCU_DONGLE
|
|
else if(get_fs_mode()==RAM_FS_MODE)
|
|
{
|
|
ret = FDI_fsize_2chip(stream);
|
|
}
|
|
else if(get_fs_mode()==TFS_FS_MODE)
|
|
{
|
|
ret = nvm_tfs_get_file_size(stream);
|
|
}
|
|
#endif
|
|
|
|
|
|
nvm_axi_un_lock();
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int FDI_remove(const char *filename_ptr)
|
|
{
|
|
/*Fixed coverity[uninit_use]*/
|
|
int ret = 0;
|
|
|
|
#ifdef FDI_TEST
|
|
uart_printf("FDI_remove %s\r\n",filename_ptr);
|
|
#endif
|
|
nvm_axi_lock();
|
|
|
|
if(get_fs_mode()==FAT_FS_MODE)
|
|
{
|
|
ret = FDI_remove_fatsys(filename_ptr);
|
|
}
|
|
#ifndef CRANE_MCU_DONGLE
|
|
else if(get_fs_mode()==SVR_FS_MODE)
|
|
{
|
|
ret = FDI_remove_2chip(filename_ptr);
|
|
}
|
|
else if(get_fs_mode()==RAM_FS_MODE)
|
|
{
|
|
ret = FDI_remove_2chip(filename_ptr);
|
|
}
|
|
else if(get_fs_mode()==RFS_FS_MODE)
|
|
{
|
|
ret = FDI_remove_2chip(filename_ptr);
|
|
}
|
|
else if(get_fs_mode()==TFS_FS_MODE)
|
|
{
|
|
ret = nvm_tfs_remove(filename_ptr);
|
|
}
|
|
#endif
|
|
|
|
nvm_axi_un_lock();
|
|
|
|
return ret;
|
|
}
|
|
|
|
int FDI_findfirst(const char *filename_ptr, FILE_INFO *fileinfo_ptr)
|
|
{
|
|
/*Fixed coverity[uninit_use]*/
|
|
int ret = 0;
|
|
|
|
#ifdef FDI_TEST
|
|
uart_printf("FDI_findfirst %s\r\n",filename_ptr);
|
|
#endif
|
|
nvm_axi_lock();
|
|
|
|
if(get_fs_mode()==FAT_FS_MODE)
|
|
{
|
|
ret = FDI_findfirst_fatsys(filename_ptr, fileinfo_ptr);
|
|
}
|
|
#ifndef CRANE_MCU_DONGLE
|
|
else if(get_fs_mode()==SVR_FS_MODE)
|
|
{
|
|
ret = FDI_findfirst_2chip(filename_ptr, fileinfo_ptr);
|
|
}
|
|
else if(get_fs_mode()==RAM_FS_MODE)
|
|
{
|
|
ret = FDI_findfirst_2chip(filename_ptr, fileinfo_ptr);
|
|
}
|
|
else if(get_fs_mode()==RFS_FS_MODE)
|
|
{
|
|
ret = FDI_findfirst_2chip(filename_ptr, fileinfo_ptr);
|
|
}
|
|
else if(get_fs_mode()==TFS_FS_MODE)
|
|
{
|
|
ret = nvm_tfs_findfirst(filename_ptr, fileinfo_ptr);
|
|
}
|
|
#endif
|
|
|
|
nvm_axi_un_lock();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
int FDI_findnext( FILE_INFO *fileinfo_ptr)
|
|
{
|
|
/*Fixed coverity[uninit_use]*/
|
|
int ret = 0;
|
|
|
|
#ifdef FDI_TEST
|
|
uart_printf("FDI_findnext\r\n");
|
|
#endif
|
|
nvm_axi_lock();
|
|
|
|
if(get_fs_mode()==FAT_FS_MODE)
|
|
{
|
|
ret = FDI_findnext_fatsys(fileinfo_ptr);
|
|
}
|
|
#ifndef CRANE_MCU_DONGLE
|
|
else if(get_fs_mode()==SVR_FS_MODE)
|
|
{
|
|
ret = FDI_findnext_2chip(fileinfo_ptr);
|
|
}
|
|
else if(get_fs_mode()==RAM_FS_MODE)
|
|
{
|
|
ret = FDI_findnext_2chip(fileinfo_ptr);
|
|
}
|
|
else if(get_fs_mode()==RFS_FS_MODE)
|
|
{
|
|
ret = FDI_findnext_2chip(fileinfo_ptr);
|
|
}
|
|
else if(get_fs_mode()==TFS_FS_MODE)
|
|
{
|
|
ret = nvm_tfs_findnext(fileinfo_ptr);
|
|
}
|
|
#endif
|
|
|
|
nvm_axi_un_lock();
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
int FDI_rename(const FDI_TCHAR *oldname_ptr, const FDI_TCHAR *newname_ptr)
|
|
{
|
|
/*Fixed coverity[uninit_use]*/
|
|
int ret = 0;
|
|
|
|
nvm_axi_lock();
|
|
|
|
if(get_fs_mode()==FAT_FS_MODE)
|
|
{
|
|
ret = FDI_rename_fatsys(oldname_ptr, newname_ptr);
|
|
}
|
|
#ifndef CRANE_MCU_DONGLE
|
|
else if(get_fs_mode()==SVR_FS_MODE)
|
|
{
|
|
ret = FDI_rename_2chip(oldname_ptr, newname_ptr);
|
|
}
|
|
else if(get_fs_mode()==RAM_FS_MODE)
|
|
{
|
|
ret = FDI_rename_2chip(oldname_ptr, newname_ptr);
|
|
}
|
|
else if(get_fs_mode()==RFS_FS_MODE)
|
|
{
|
|
ret = FDI_rename_2chip(oldname_ptr, newname_ptr);
|
|
}
|
|
else if(get_fs_mode()==TFS_FS_MODE)
|
|
{
|
|
ret = nvm_tfs_rename(oldname_ptr, newname_ptr);
|
|
}
|
|
#endif
|
|
|
|
nvm_axi_un_lock();
|
|
|
|
|
|
return ret;
|
|
}
|
|
|
|
BOOL FDI_IsFormatted(void)
|
|
{
|
|
/*Todo: implementation*/
|
|
return TRUE;
|
|
}
|
|
ERR_CODE FDI_Format(void)
|
|
{
|
|
|
|
/*Fixed coverity[uninit_use]*/
|
|
ERR_CODE ret = ERR_NONE;
|
|
|
|
nvm_axi_lock();
|
|
|
|
if(get_fs_mode()==FAT_FS_MODE)
|
|
{
|
|
ret = FDI_Format_fatsys();
|
|
}
|
|
#ifndef CRANE_MCU_DONGLE
|
|
else if(get_fs_mode()==SVR_FS_MODE)
|
|
{
|
|
ret = FDI_Format_2chip();
|
|
}
|
|
else if(get_fs_mode()==RAM_FS_MODE)
|
|
{
|
|
ret = FDI_Format_2chip();
|
|
}
|
|
else if(get_fs_mode()==RFS_FS_MODE)
|
|
{
|
|
ret = FDI_Format_2chip();
|
|
}
|
|
else if(get_fs_mode()==TFS_FS_MODE)
|
|
{
|
|
qspi_printf("don't support format\r\n");
|
|
}
|
|
#endif
|
|
|
|
nvm_axi_un_lock();
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
int FDI_stat(const char * filename_ptr, int *mode_ptr)
|
|
{
|
|
|
|
/*Fixed coverity[uninit_use]*/
|
|
int ret = 0;
|
|
|
|
nvm_axi_lock();
|
|
|
|
if(get_fs_mode()==FAT_FS_MODE)
|
|
{
|
|
ret = FDI_stat_fatsys(filename_ptr, mode_ptr);
|
|
}
|
|
#ifndef CRANE_MCU_DONGLE
|
|
else if(get_fs_mode()==SVR_FS_MODE)
|
|
{
|
|
ret = FDI_stat_2chip(filename_ptr, mode_ptr);
|
|
}
|
|
else if(get_fs_mode()==RAM_FS_MODE)
|
|
{
|
|
ret = FDI_stat_2chip(filename_ptr, mode_ptr);
|
|
}
|
|
else if(get_fs_mode()==RFS_FS_MODE)
|
|
{
|
|
ret = FDI_stat_2chip(filename_ptr, mode_ptr);
|
|
}
|
|
else if(get_fs_mode()==TFS_FS_MODE)
|
|
{
|
|
*mode_ptr=0;
|
|
}
|
|
#endif
|
|
|
|
nvm_axi_un_lock();
|
|
|
|
|
|
return ret;
|
|
}
|
|
|
|
int FDI_chmod(const char *filname_ptr, int access_ptr)
|
|
{
|
|
|
|
/*Fixed coverity[uninit_use]*/
|
|
int ret = 0;
|
|
|
|
nvm_axi_lock();
|
|
|
|
if(get_fs_mode()==FAT_FS_MODE)
|
|
{
|
|
ret = FDI_chmod_fatsys(filname_ptr, access_ptr);
|
|
}
|
|
#ifndef CRANE_MCU_DONGLE
|
|
else if(get_fs_mode()==SVR_FS_MODE)
|
|
{
|
|
ret = FDI_chmod_2chip(filname_ptr, access_ptr);
|
|
}
|
|
else if(get_fs_mode()==RAM_FS_MODE)
|
|
{
|
|
ret = FDI_chmod_2chip(filname_ptr, access_ptr);
|
|
}
|
|
else if(get_fs_mode()==RFS_FS_MODE)
|
|
{
|
|
ret = FDI_chmod_2chip(filname_ptr, access_ptr);
|
|
}
|
|
else if(get_fs_mode()==TFS_FS_MODE)
|
|
{
|
|
qspi_printf("don't support FDI_chmod\r\n");
|
|
}
|
|
#endif
|
|
|
|
nvm_axi_un_lock();
|
|
|
|
|
|
return ret;
|
|
}
|
|
|
|
ERR_CODE FDI_ferror(FILE_ID stream)
|
|
{
|
|
|
|
/*Fixed coverity[uninit_use]*/
|
|
ERR_CODE ret = ERR_NONE;
|
|
|
|
nvm_axi_lock();
|
|
|
|
if(get_fs_mode()==FAT_FS_MODE)
|
|
{
|
|
ret = FDI_ferror_fatsys(stream);
|
|
}
|
|
#ifndef CRANE_MCU_DONGLE
|
|
else if(get_fs_mode()==SVR_FS_MODE)
|
|
{
|
|
ret = FDI_ferror_2chip(stream);
|
|
}
|
|
else if(get_fs_mode()==RAM_FS_MODE)
|
|
{
|
|
ret = FDI_ferror_2chip(stream);
|
|
}
|
|
else if(get_fs_mode()==RFS_FS_MODE)
|
|
{
|
|
ret = FDI_ferror_2chip(stream);
|
|
}
|
|
else if(get_fs_mode()==TFS_FS_MODE)
|
|
{
|
|
ret=nvm_tfs_ferror(stream);
|
|
}
|
|
#endif
|
|
|
|
nvm_axi_un_lock();
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
int FDI_eof(FILE_ID stream)
|
|
{
|
|
/*Fixed coverity[uninit_use]*/
|
|
int ret = 0;
|
|
|
|
|
|
nvm_axi_lock();
|
|
|
|
if(get_fs_mode()==FAT_FS_MODE)
|
|
{
|
|
ret = FDI_feof_fatsys(stream);
|
|
}
|
|
#ifndef CRANE_MCU_DONGLE
|
|
else if(get_fs_mode()==RAM_FS_MODE)
|
|
{
|
|
ret = FDI_feof_2chip(stream);
|
|
}
|
|
else if(get_fs_mode()==TFS_FS_MODE)
|
|
{
|
|
ret = nvm_tfs_feof(stream);
|
|
}
|
|
#endif
|
|
|
|
nvm_axi_un_lock();
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
unsigned int FDI_GetFreeSpaceSize(void)
|
|
{
|
|
UINT32 size = 0;
|
|
|
|
if(get_fs_mode()==FAT_FS_MODE)
|
|
{
|
|
size = FDI_GetFreeSpaceSize_fatsys();
|
|
}
|
|
#ifndef CRANE_MCU_DONGLE
|
|
else if(get_fs_mode()==TFS_FS_MODE)
|
|
{
|
|
size=nvm_tfs_get_free_size();
|
|
}
|
|
#endif
|
|
|
|
return size;
|
|
}
|
|
unsigned int FDI_GetUsedSpaceSize(void)
|
|
{
|
|
UINT32 size = 0;
|
|
|
|
if(get_fs_mode()==FAT_FS_MODE)
|
|
{
|
|
size = FDI_GetUsedSpaceSize_fatsys();
|
|
}
|
|
#ifndef CRANE_MCU_DONGLE
|
|
else if(get_fs_mode()==TFS_FS_MODE)
|
|
{
|
|
size = nvm_tfs_get_used_size();
|
|
|
|
}
|
|
#endif
|
|
|
|
return size;
|
|
}
|
|
|
|
void enable_nvm_flush(void)
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
void disable_nvm_flush(void)
|
|
{
|
|
return;
|
|
}
|
|
|
|
#if defined(FOTA_RS_FEATURE) || defined(FOTA_GS_FEATURE)
|
|
void nvm_flush_ps_idle_cnf(BOOL flag)
|
|
{
|
|
return;
|
|
}
|
|
|
|
void nvm_flush_ps_resume_ind(void)
|
|
{
|
|
return;
|
|
}
|
|
|
|
void RamBlockSyncOpWriteTrigger(UINT32 type, UINT32 current, UINT32 len)
|
|
{
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
|
|
int sdcard_fatfs_mount_status_g = 0;
|
|
UINT32 sdcard_ee_dump_folder_index = 0;
|
|
|
|
//TRUE:auto delete sdl log
|
|
BOOL sdlAutoDelete = FALSE;
|
|
|
|
|
|
#ifndef CRANE_SD_NOT_SUPPORT
|
|
//static DWORD fat_buff_temp[FF_MAX_SS];
|
|
FATFS fatfs_fs[3];//fatfs_fs[0]:D/d fatfs_fs[1]:E/e, fatfs_fs[2]:M/m
|
|
BOOL FAT_IsFormatted(char *vol)
|
|
{
|
|
/*Todo: implementation*/
|
|
FATFS *fs = NULL;
|
|
FRESULT res;
|
|
BOOL ret = TRUE;
|
|
|
|
if((strcmp(vol,"D:")==0)||(strcmp(vol,"d:")==0)){
|
|
if (sdcard_fatfs_mount_status_g == 1)
|
|
return TRUE;
|
|
fs=&fatfs_fs[0];
|
|
}
|
|
else if((strcmp(vol,"E:")==0)||(strcmp(vol,"e:")==0))
|
|
fs=&fatfs_fs[1];
|
|
else
|
|
{
|
|
uart_printf("Bad vol format!\r\n");
|
|
ret=FALSE;
|
|
}
|
|
|
|
res = f_mount(fs, vol, 1);
|
|
#ifdef FAT_TEST
|
|
fatal_printf("fatfs mount err:%d\n", res);
|
|
#endif
|
|
if(res != FR_OK) {
|
|
ret = FALSE;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
ERR_CODE FAT_Format(char *vol)
|
|
{
|
|
FATFS *fs;
|
|
FRESULT res;
|
|
void *fat_buff_temp = malloc(FF_MAX_SS * sizeof(DWORD));
|
|
if(fat_buff_temp == NULL)
|
|
return ERR_SYSTEM;
|
|
res = f_mkfs(vol, FM_ANY, 0, fat_buff_temp, FF_MAX_SS * sizeof(DWORD));
|
|
#ifdef FAT_TEST
|
|
uart_printf("fatfs format :%d\r\n", res);
|
|
#endif
|
|
free(fat_buff_temp);
|
|
if (res != FR_OK)
|
|
return ERR_SYSTEM;
|
|
|
|
if((strcmp(vol,"D:")==0)||(strcmp(vol,"d:")==0))
|
|
fs=&fatfs_fs[0];
|
|
else if((strcmp(vol,"E:")==0)||(strcmp(vol,"e:")==0))
|
|
fs=&fatfs_fs[1];
|
|
else
|
|
{
|
|
uart_printf("Bad vol format!\r\n");
|
|
return ERR_SYSTEM;
|
|
}
|
|
|
|
res = f_mount(fs,vol, 1);
|
|
#ifdef FAT_TEST
|
|
uart_printf("fatfs mount:%d\n", res);
|
|
#endif
|
|
if(res != FR_OK)
|
|
return ERR_SYSTEM;
|
|
return ERR_NONE;
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned int FAT_fopen(const char *filename_ptr, const char *mode)
|
|
{
|
|
|
|
#ifdef FAT_TEST
|
|
uart_printf("FAT_fopen %s,mode=%s\r\n",filename_ptr,mode);
|
|
#endif
|
|
|
|
unsigned int stream = 0;
|
|
FIL *handle;
|
|
if (eeSDDump_status_get() == 1)
|
|
{
|
|
//handle = &ee_sd_dump_fil;
|
|
handle = (FIL *)ff_dump_malloc(sizeof(FIL));
|
|
}
|
|
else
|
|
handle = (FIL *)malloc(sizeof(FIL));
|
|
UINT oflag = 0;
|
|
FRESULT res;
|
|
if (handle == NULL)
|
|
return 0;
|
|
if(strlen(mode)<1 || strlen(mode)>5){
|
|
if (eeSDDump_status_get() == 0)
|
|
free(handle);
|
|
else
|
|
ff_dump_free(handle);
|
|
return 0;
|
|
}
|
|
// Next flags set according to first case of table 9 of FDI_6.0_UG.pdf
|
|
oflag = 0;
|
|
int i = 0;
|
|
for(i = 0; i < strlen(mode); i++) {
|
|
switch (mode[i]){
|
|
case 'r' :
|
|
case 'R':
|
|
oflag |= FA_READ;
|
|
break;
|
|
case 'w':
|
|
case 'W':
|
|
oflag |= FA_WRITE;
|
|
break;
|
|
case 'c':
|
|
case 'C':
|
|
oflag |= FA_CREATE_ALWAYS;
|
|
break;
|
|
case 'x':
|
|
case 'X':
|
|
oflag |= FA_CREATE_NEW;
|
|
break;
|
|
case 'b':
|
|
case 'B':
|
|
//oflag &=(~WK_FILE_MODE_TEXT);
|
|
break;
|
|
case 't':
|
|
case 'T':
|
|
break;
|
|
case 'a':
|
|
case 'A':
|
|
oflag |= (FA_OPEN_APPEND|FA_WRITE);
|
|
break;
|
|
case '+':
|
|
oflag |= (FA_WRITE|FA_READ);
|
|
break;
|
|
default:
|
|
if (eeSDDump_status_get() == 0){
|
|
free(handle);
|
|
}
|
|
else {
|
|
ff_dump_free(handle);
|
|
}
|
|
uart_printf("FAT32 mode err\n");
|
|
return 0;
|
|
}
|
|
}
|
|
res = f_open(handle, filename_ptr, oflag);
|
|
//#ifdef FAT_TEST
|
|
uart_printf("%s:f_open res=%d, handle:%x,%s\r\n",filename_ptr,res, handle,mode);
|
|
//#endif
|
|
if (res != FR_OK) {
|
|
if (eeSDDump_status_get() == 0){
|
|
free(handle);
|
|
}
|
|
else {
|
|
ff_dump_free(handle);
|
|
}
|
|
uart_printf("fatfs open err:%d\n", res);
|
|
return 0;
|
|
}
|
|
ffst_open_status((unsigned int)handle);
|
|
return (unsigned int)handle;
|
|
}
|
|
|
|
|
|
int FAT_fclose(unsigned int stream)
|
|
{
|
|
FRESULT res;
|
|
//#ifdef FAT_TEST
|
|
uart_printf("FAT_fclose :%x\r\n", stream);
|
|
//#endif
|
|
|
|
if (stream == 0)
|
|
return -1;
|
|
res = f_close((FIL*)stream);
|
|
ffst_close_status(stream);
|
|
if (eeSDDump_status_get() == 0)
|
|
free((void *)stream);
|
|
else
|
|
ff_dump_free((void *)stream);
|
|
if (res != FR_OK) {
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t FAT_fread(void *buffer_ptr, size_t element_size, size_t count, unsigned int stream)
|
|
{
|
|
unsigned int ret = 0;
|
|
FRESULT res;
|
|
ffst_read_start_status(stream);
|
|
res = f_read((FIL*)stream, buffer_ptr, count * element_size, &ret);
|
|
ffst_read_end_status(stream);
|
|
//uart_printf("FAT_read :%d , %d :%d\n", res,ret, count * element_size);
|
|
if (res != FR_OK)
|
|
return 0;
|
|
return ret/element_size;
|
|
}
|
|
|
|
size_t FAT_fwrite(const void *buffer_ptr,size_t element_size,size_t count,unsigned int stream)
|
|
{
|
|
unsigned int ret = 0;
|
|
FRESULT res;
|
|
//uart_printf("FAT_fwrite stream %x\r\n",stream);
|
|
static unsigned int flush_t1 = 0;
|
|
ffst_write_start_status(stream);
|
|
res = f_write((FIL*)stream, buffer_ptr, count * element_size, &ret);
|
|
if (flush_t1 != 0 && ((OSAGetTicks() - flush_t1) > 200*2))
|
|
f_sync((FIL*)stream);
|
|
flush_t1 = OSAGetTicks();
|
|
ffst_write_end_status(stream);
|
|
if (res != FR_OK){
|
|
uart_printf("%s:%d\r\n", __func__, res);
|
|
return 0;
|
|
}
|
|
// uart_printf("FAT_fwrite return 0x%x,stream %x\r\n",ret/element_size,stream);
|
|
return ret/element_size;
|
|
}
|
|
|
|
|
|
|
|
//#define FS_SEEK_BEGIN 0
|
|
//#define FS_SEEK_CURREN 1
|
|
//#define FS_SEEK_END 2
|
|
|
|
int FAT_fseek(unsigned int stream, long offset, int wherefrom)
|
|
{
|
|
|
|
int ret = 0;
|
|
FRESULT res;
|
|
FSIZE_t ofs;
|
|
if (wherefrom == FS_SEEK_CURREN) {
|
|
ofs = f_tell((FIL *)stream) + offset;
|
|
}
|
|
else if (wherefrom == FS_SEEK_END) {
|
|
ofs = f_size((FIL *)stream) + offset;
|
|
}
|
|
else
|
|
ofs = offset;
|
|
|
|
res = f_lseek((FIL*)stream, ofs);
|
|
#ifdef FAT_TEST
|
|
uart_printf("f_seek res=%d\r\n",res);
|
|
#endif
|
|
if (res != FR_OK)
|
|
return -1;
|
|
f_sync((FIL*)stream);
|
|
return ofs;
|
|
}
|
|
|
|
int FAT_remove(const char *filename_ptr)
|
|
{
|
|
FRESULT res;
|
|
ffst_remove_start_status((char *)filename_ptr);
|
|
res = f_unlink(filename_ptr);
|
|
ffst_remove_end_status((char *)filename_ptr);
|
|
if (res != FR_OK)
|
|
return -1;
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
output : 0 find err
|
|
other find success
|
|
*/
|
|
#define MAX_FATFS_FILE_LENGTH 260
|
|
char CurrentDir_global[MAX_FATFS_FILE_LENGTH]="D:/";
|
|
|
|
int FAT_SetCurrentDir(char *dir_name)
|
|
{
|
|
FRESULT res; //
|
|
char driv[3];
|
|
memcpy(driv, dir_name, 2);
|
|
driv[2] = '\0';
|
|
res = f_chdrive(driv);
|
|
if (res != FR_OK)
|
|
{
|
|
uart_printf("f_chdrive failed,res=%d\r\n",res);
|
|
return -1;
|
|
}
|
|
res = f_chdir(dir_name);
|
|
if (res == FR_OK)
|
|
{
|
|
memset(CurrentDir_global,0,MAX_FATFS_FILE_LENGTH);
|
|
// memcpy(CurrentDir_global,dir_name,MAX_FATFS_FILE_LENGTH);
|
|
strcpy(CurrentDir_global,dir_name);
|
|
// uart_printf("CurrentDir_global=%s\r\n",CurrentDir_global);
|
|
return 0;
|
|
}
|
|
#ifdef FAT_TEST
|
|
uart_printf("f_chdir failed,res=%d\r\n",res);
|
|
#endif
|
|
return -1;
|
|
}
|
|
int FAT_SetCurrentDir_t(char *dir_name)
|
|
{
|
|
FRESULT res; //
|
|
char driv[3];
|
|
memcpy(driv, dir_name, 2);
|
|
driv[2] = '\0';
|
|
res = f_chdrive(driv);
|
|
if (res != FR_OK)
|
|
{
|
|
uart_printf("f_chdrive failed,res=%d\r\n",res);
|
|
return -1;
|
|
}
|
|
res = f_chdir(dir_name);
|
|
if (res == FR_OK)
|
|
return 0;
|
|
#ifdef FAT_TEST
|
|
uart_printf("f_chdir failed,res=%d\r\n",res);
|
|
#endif
|
|
return -1;
|
|
}
|
|
int FAT_GetCurrentDir(char *dir_name, unsigned int max_len)/*the full path*/
|
|
{
|
|
FRESULT res = f_getcwd(dir_name, max_len);
|
|
if (res == FR_OK)
|
|
{
|
|
//uart_printf("FAT_GetCurrentDir success %s\r\n",dir_name);
|
|
return 0;
|
|
}
|
|
//uart_printf("FAT_GetCurrentDir failed\r\n");
|
|
return -1;
|
|
}
|
|
|
|
|
|
unsigned int FAT_findfirst(const char *filename_ptr, LPFAT32FILEINFO fileinfo_ptr)
|
|
{
|
|
#ifdef FAT_TEST
|
|
uart_printf("FAT_findfirst %s\r\n",filename_ptr);
|
|
#endif
|
|
int ret,sd_status;
|
|
DIR *dj;
|
|
char *path,*filename_t;
|
|
|
|
sd_status=eeSDDump_status_get();
|
|
if (sd_status== 1)
|
|
//dj = fat_find_djbuf;
|
|
dj = (DIR *)ff_dump_malloc(sizeof(DIR)+4+4);
|
|
else
|
|
dj = (DIR *)malloc(sizeof(DIR)+4+4);
|
|
if (dj == NULL)
|
|
return 0;
|
|
|
|
if (sd_status== 1){
|
|
//path=fat_find_pathbuf;
|
|
path = ff_dump_malloc(MAX_FATFS_FILE_LENGTH);
|
|
if (path == NULL) {
|
|
ff_dump_free(dj);
|
|
return 0;
|
|
}
|
|
}
|
|
else {
|
|
path=(char *)malloc(MAX_FATFS_FILE_LENGTH);
|
|
if (path == NULL) {
|
|
free(dj);
|
|
return 0;
|
|
}
|
|
}
|
|
if (sd_status== 1){
|
|
//filename_t=fat_find_filename;
|
|
filename_t = ff_dump_malloc(MAX_FATFS_FILE_LENGTH);
|
|
if (filename_t == NULL) {
|
|
ff_dump_free(dj);
|
|
ff_dump_free(path);
|
|
return 0;
|
|
}
|
|
}
|
|
else {
|
|
filename_t=(char *)malloc(MAX_FATFS_FILE_LENGTH);
|
|
if (filename_t == NULL) {
|
|
free(dj);
|
|
free(path);
|
|
return 0;
|
|
}
|
|
}
|
|
memset(path,0,MAX_FATFS_FILE_LENGTH);
|
|
memset(filename_t,0,MAX_FATFS_FILE_LENGTH);
|
|
memcpy(filename_t,filename_ptr,strlen(filename_ptr));
|
|
filename_t[strlen(filename_ptr)]='\0';
|
|
|
|
*(unsigned int *)(((char *)dj)+sizeof(DIR)) = (unsigned int)path;
|
|
*(unsigned int *)(((char *)dj)+sizeof(DIR)+4) = (unsigned int)filename_t;
|
|
FILINFO file_info;
|
|
FRESULT res;
|
|
memset(dj, 0, sizeof(DIR));
|
|
const char *p = filename_t + strlen(filename_ptr);
|
|
while(p > filename_t)
|
|
{
|
|
if (*p == '\\'||*p=='/')
|
|
break;
|
|
p--;
|
|
}
|
|
if(p - filename_t + 1 > MAX_FATFS_FILE_LENGTH)
|
|
{
|
|
if (sd_status== 0)
|
|
{
|
|
free(dj);
|
|
free(path);
|
|
free(filename_t);
|
|
}
|
|
else {
|
|
ff_dump_free(dj);
|
|
ff_dump_free(path);
|
|
ff_dump_free(filename_t);
|
|
}
|
|
return 0;
|
|
}
|
|
memcpy(path, filename_t, p - filename_t);
|
|
|
|
path[p - filename_t] = '\0';
|
|
p++;
|
|
#ifdef FAT_TEST
|
|
uart_printf("path:%s, file:%s\n", path, p);
|
|
#endif
|
|
|
|
ret=FAT_SetCurrentDir_t("D:/");
|
|
// int* buf = (int *)malloc(256);
|
|
// memset((void *)buf,0,256);
|
|
// FAT_GetCurrentDir((char *)buf, 256);
|
|
res = f_findfirst(dj, &file_info, path, p); //path D:\a P:f1.txt
|
|
// uart_printf("f_findfirst res=%d,fname[0]=%c\r\n",res,file_info.fname[0]);
|
|
// uart_printf("dj->pat: %s, %x\r\n",dj->pat,dj->pat);
|
|
FAT_SetCurrentDir_t(CurrentDir_global);
|
|
// memset((void *)buf,0,256);
|
|
// FAT_GetCurrentDir(buf, 256);
|
|
// free(buf);
|
|
if (res == FR_OK&&file_info.fname[0]){
|
|
fileinfo_ptr->info.m_tModify.m_nYear = (file_info.fdate >> 9) + 1980;
|
|
fileinfo_ptr->info.m_tModify.m_nMonth = (file_info.fdate >> 5) & 0xf;
|
|
fileinfo_ptr->info.m_tModify.m_nDate = file_info.fdate & 0x1f;
|
|
fileinfo_ptr->info.m_tModify.m_nHour = file_info.ftime >> 11;
|
|
fileinfo_ptr->info.m_tModify.m_nMinute = (file_info.ftime >> 5) & 0x3f;
|
|
fileinfo_ptr->info.m_tModify.m_nSecond = (file_info.ftime & 0x1f) * 2;
|
|
memcpy(fileinfo_ptr->info.m_lpszFullName, file_info.fname, strlen(file_info.fname)+1);
|
|
//memcpy(fileinfo_ptr->info.m_lpszFullName,path,strlen(path));memcpy(fileinfo_ptr->info.m_lpszFullName+strlen(path),file_info.fname, strlen(file_info.fname)+1);
|
|
fileinfo_ptr->info.m_nAttr = file_info.fattrib;
|
|
fileinfo_ptr->info.m_nFileSize = file_info.fsize;
|
|
return (unsigned int)dj;
|
|
}
|
|
if (sd_status== 0)
|
|
{
|
|
free(dj);
|
|
free(path);
|
|
free(filename_t);
|
|
}
|
|
else {
|
|
ff_dump_free(dj);
|
|
ff_dump_free(path);
|
|
ff_dump_free(filename_t);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
ouput: 0 find ok
|
|
-1 didn't find
|
|
*/
|
|
|
|
int FAT_findnext(unsigned int handle, LPFAT32FILEINFO fileinfo_ptr)
|
|
{
|
|
#ifdef FAT_TEST
|
|
uart_printf("FAT_findnext %x\r\n",handle);
|
|
#endif
|
|
FRESULT res;
|
|
FILINFO file_info;
|
|
// int* buf = (int *)malloc(256);
|
|
FAT_SetCurrentDir_t("D:/");
|
|
// FAT_GetCurrentDir(buf, 256);
|
|
res = f_findnext((DIR*)handle, &file_info);
|
|
FAT_SetCurrentDir_t(CurrentDir_global);
|
|
// FAT_GetCurrentDir(buf, 256);
|
|
// free(buf);
|
|
if (res == FR_OK && file_info.fname[0]) {
|
|
fileinfo_ptr->info.m_tModify.m_nYear = (file_info.fdate >> 9) + 1980;
|
|
fileinfo_ptr->info.m_tModify.m_nMonth = (file_info.fdate >> 5) & 0xf;
|
|
fileinfo_ptr->info.m_tModify.m_nDate = file_info.fdate & 0x1f;
|
|
fileinfo_ptr->info.m_tModify.m_nHour = file_info.ftime >> 11;
|
|
fileinfo_ptr->info.m_tModify.m_nMinute = (file_info.ftime >> 5) & 0x3f;
|
|
fileinfo_ptr->info.m_tModify.m_nSecond = (file_info.ftime & 0x1f) * 2;
|
|
memcpy(fileinfo_ptr->info.m_lpszFullName, file_info.fname, strlen(file_info.fname)+1);
|
|
fileinfo_ptr->info.m_nAttr = file_info.fattrib;
|
|
fileinfo_ptr->info.m_nFileSize = file_info.fsize;
|
|
|
|
return 0;
|
|
}
|
|
return -1;
|
|
}
|
|
BOOL FAT_findfileclose(unsigned int handle){
|
|
int ret;
|
|
unsigned int *temp=NULL;
|
|
|
|
ret=f_closedir((DIR*)handle);
|
|
// uart_printf("f_closedir,ret=%d\r\n",ret);
|
|
if (handle == NULL)
|
|
return FALSE;
|
|
temp=(unsigned int *)(((char *)handle)+sizeof(DIR));
|
|
if (eeSDDump_status_get()== 0)
|
|
{
|
|
if (*temp!=NULL)
|
|
free((void *)(*temp));
|
|
if(*(temp+1)!=NULL)
|
|
free((void *)(*(temp+1)));
|
|
free((void *)handle);
|
|
}
|
|
else
|
|
{
|
|
if (*temp!=NULL)
|
|
ff_dump_free((void *)(*temp));
|
|
if(*(temp+1)!=NULL)
|
|
ff_dump_free((void *)(*(temp+1)));
|
|
ff_dump_free((void *)handle);
|
|
/*
|
|
ff_dump_free(*(unsigned int *)(((char *)handle)+sizeof(DIR)));
|
|
ff_dump_free(*(unsigned int *)(((char *)handle)+sizeof(DIR)+4));
|
|
ff_dump_free(handle);
|
|
*/
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
/*
|
|
ouput: 0 ok
|
|
-1 err
|
|
*/
|
|
int FAT_rename(const char *oldname_ptr, const char *newname_ptr)
|
|
{
|
|
FRESULT res;
|
|
res = f_rename(oldname_ptr, newname_ptr);
|
|
if (res == FR_OK)
|
|
return 0;
|
|
return -1;
|
|
}
|
|
|
|
/*
|
|
ouput: 0 file is end
|
|
-1 file is not end
|
|
*/
|
|
|
|
int FAT_eof(unsigned int stream)
|
|
{
|
|
int ret;
|
|
ret = f_eof((FIL *)stream);
|
|
if (ret == 0)
|
|
return -1;
|
|
return 0;
|
|
}
|
|
|
|
|
|
unsigned int FAT_GetFileSize(unsigned int stream)
|
|
{
|
|
//FSFILEINFO info;
|
|
ASSERT(stream != NULL);
|
|
return f_size((FIL *)stream);
|
|
}
|
|
|
|
int FAT_GetFSInfo(char *pszDevName, FS_INFO* psFSInfo)
|
|
{
|
|
FRESULT res;
|
|
FATFS *fs;
|
|
DWORD clust;
|
|
long long sect_free, sect_total;
|
|
res = f_getfree(pszDevName, &clust, &fs);
|
|
if (res != FR_OK)
|
|
return -1;
|
|
sect_total = (fs->n_fatent -2 ) * fs->csize;
|
|
sect_free = clust * fs->csize;
|
|
psFSInfo->iToTalSize = sect_total * 512;
|
|
psFSInfo->iUsedSize = psFSInfo->iToTalSize - sect_free * 512;
|
|
return 0;
|
|
}
|
|
|
|
//Those three funcs are dir operation
|
|
int FAT_MakeDir(char *dir_name, unsigned int mode)
|
|
{
|
|
FRESULT res = f_mkdir(dir_name);
|
|
if (res == FR_OK)
|
|
return 0;
|
|
return -1;
|
|
}
|
|
|
|
int FAT_MakeDir_M(char *dir_name, unsigned int mode)
|
|
{
|
|
FRESULT res = f_mkdir(dir_name);
|
|
return res;
|
|
}
|
|
|
|
/* 删除文件夹内所有的文件和文件夹*/
|
|
FRESULT FS_RemoveIntFile(char *path)
|
|
{
|
|
UINT i, j;
|
|
FRESULT res;
|
|
DIR *dir;
|
|
FILINFO *fno;
|
|
char *tmp_path = (char *)malloc(255);
|
|
|
|
dir=(DIR *)malloc(sizeof(DIR));
|
|
if(!dir)
|
|
{
|
|
free(tmp_path);
|
|
return FR_NOT_ENOUGH_CORE;
|
|
}
|
|
fno=(FILINFO *)malloc(sizeof(FILINFO));
|
|
if(!fno)
|
|
{
|
|
free(dir);
|
|
free(tmp_path);
|
|
return FR_NOT_ENOUGH_CORE;
|
|
}
|
|
|
|
memset(tmp_path,0,sizeof(tmp_path));
|
|
strcpy(tmp_path, path);
|
|
res = f_opendir(dir, tmp_path);
|
|
if (res == FR_OK)
|
|
{
|
|
for (i = 0; tmp_path[i]; i++) ;
|
|
tmp_path[i++]='/';
|
|
for (;;)
|
|
{
|
|
res = f_readdir(dir, fno);
|
|
if (res != FR_OK || !fno->fname[0]) break;
|
|
if (fno->fname[0] == '.') {
|
|
//fatal_printf("Name:%s\n", fno->fname);
|
|
if(strlen(fno->fname)>=2){
|
|
if(fno->fname[1] == '.')
|
|
continue;
|
|
}
|
|
else {
|
|
continue;
|
|
}
|
|
}
|
|
j = 0;
|
|
do
|
|
tmp_path[i+j] = fno->fname[j];
|
|
while (fno->fname[j++]);
|
|
if (fno->fattrib & AM_DIR)
|
|
{
|
|
// uart_printf("AM_DIR: %s\r\n",path);
|
|
res = FS_RemoveIntFile(tmp_path);
|
|
if (res != FR_OK) break;
|
|
}
|
|
f_chmod(tmp_path,0, AM_RDO);
|
|
res = f_unlink(tmp_path);
|
|
// uart_printf("res=%d\r\n",res);
|
|
if ((res != FR_OK) && (res != FR_DENIED)) break;
|
|
}
|
|
tmp_path[--i] = '\0';
|
|
}
|
|
free(tmp_path);
|
|
free(dir);
|
|
free(fno);
|
|
return res;
|
|
}
|
|
|
|
|
|
/* 删除此文件夹及内部的文件及文件夹*/
|
|
int FAT_RemoveDir(char *dir_name)
|
|
{
|
|
int res;
|
|
char *dir_name_t;
|
|
|
|
dir_name_t=(char *)malloc(strlen(dir_name)+1);
|
|
if(dir_name_t == NULL)
|
|
return -1;
|
|
strcpy(dir_name_t,dir_name);
|
|
f_chmod(dir_name, 0, AM_RDO);
|
|
res = FS_RemoveIntFile(dir_name_t);
|
|
free(dir_name_t);
|
|
|
|
#ifdef FAT_TEST
|
|
uart_printf("removeInt res=%d\r\n",res);
|
|
#endif
|
|
if (res == FR_OK)
|
|
{
|
|
res = f_unlink(dir_name);
|
|
}
|
|
else if (FR_NO_PATH == res)
|
|
{
|
|
res = f_unlink(dir_name);
|
|
}
|
|
if (res == FR_OK)
|
|
return 0;
|
|
return -1;
|
|
|
|
}
|
|
|
|
UINT32 FAT_Getfree(char *path)
|
|
{
|
|
DWORD clust;
|
|
FATFS *fs;
|
|
FRESULT res;
|
|
UINT32 FreeMB = 0;
|
|
long long sect_free = 0;
|
|
res = f_getfree(path, &clust, &fs);
|
|
if (res != FR_OK){
|
|
RTI_LOG("%s res:%d", __FUNCTION__, (int)res);
|
|
return 0;
|
|
}
|
|
|
|
sect_free = clust * fs->csize;
|
|
FreeMB = (sect_free * 512)/0x100000;
|
|
|
|
//ffprintf("driver %s have free size %lu\r\n", path, FreeMB);
|
|
return FreeMB;
|
|
}
|
|
|
|
|
|
/*1 mounted, 0 not yet */
|
|
int FAT_fmount(FATFS* fs, /* Pointer to the filesystem object (NULL:unmount)*/
|
|
const TCHAR* path, /* Logical drive number to be mounted/unmounted */
|
|
BYTE opt /* Mode option 0:Do not mount (delayed mount), 1:Mount immediately */
|
|
){
|
|
char *p = DUMP_VOL;
|
|
FRESULT res = f_mount(fs,path, opt);
|
|
if (res == FR_OK){
|
|
if (*path == *p)
|
|
sdcard_fatfs_mount_status_g = 1;
|
|
return 0;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
#if 0
|
|
void fat32_read_write_test(void)
|
|
{
|
|
int ret;
|
|
#if 0
|
|
ERR_CODE co = FAT_Format("D:");
|
|
if (co != ERR_NONE) {
|
|
fatal_printf("fat32 format err:%d \n", co);
|
|
return;
|
|
}
|
|
#endif
|
|
int* xx_buf = (int *)malloc(1024);
|
|
FRESULT res;// = f_mount(&fs_g,"D:", 1);
|
|
char *str = (char*)malloc(200);
|
|
//ret = FAT_fmount(&fs_g,"D:", 1);
|
|
fatal_printf("fatfs buf %x\n", xx_buf);
|
|
//if(res != FR_OK)
|
|
//return;
|
|
|
|
uart_printf("Sd card is formatted\n");
|
|
//sprintf(str, "%s\\%s", DUMP_VOL,"C");
|
|
ret = FAT_MakeDir("D:\\c", NULL);
|
|
fatal_printf("%s\\C create :%d\n", DUMP_VOL, ret);
|
|
//sprintf(str, "%s\\%s", DUMP_VOL, "c");
|
|
ret = FAT_SetCurrentDir("D:\\c");
|
|
fatal_printf("%s\\c set current dir :%d\n", DUMP_VOL, ret);
|
|
res = f_chdrive("D:");
|
|
fatal_printf("D:\\c set current drive :%d\n", res);
|
|
ret = FAT_GetCurrentDir((char *)xx_buf, 256);
|
|
fatal_printf("get current dir :%d :%s\n", ret, xx_buf);
|
|
sprintf(str, "%s\\", DUMP_VOL);
|
|
ret = FAT_SetCurrentDir(str);
|
|
fatal_printf("%s\\ set current dir :%d\n",DUMP_VOL, ret);
|
|
ret = FAT_GetCurrentDir((char *)xx_buf, 256);
|
|
fatal_printf("get current dir :%d :%s\n", ret, xx_buf);
|
|
sprintf(str, "%s\\%s", DUMP_VOL, "C");
|
|
ret = FAT_RemoveDir(str);
|
|
fatal_printf("%s\\C remove :%d\n",DUMP_VOL, ret);
|
|
|
|
FS_INFO info;
|
|
ret = FAT_GetFSInfo(DUMP_VOL, &info);
|
|
fatal_printf("GetFSInfo ret:%d total:%llu free:%llu\n", ret, info.iToTalSize, info.iUsedSize);
|
|
FAT32FILEINFO fileinfo_ptr;
|
|
unsigned int handle;
|
|
sprintf(str, "%s\\%s", DUMP_VOL, "log1.txt");
|
|
handle = FAT_fopen(str, "wbc");
|
|
fatal_printf("open log1.txt mode:wbc handle:%x\n", handle);
|
|
FAT_fwrite("123456", 1, 6, handle);
|
|
fatal_printf("write log1.txt handle:%x\n", handle);
|
|
ret = FAT_GetFileSize(handle);
|
|
if (ret != 6) {
|
|
fatal_printf("log1.txt GetFileSize err :%u\n", ret);
|
|
return;
|
|
}
|
|
fatal_printf("log1.txt file size is :%u\n", ret);
|
|
|
|
FAT_fclose(handle);
|
|
#if 1
|
|
FAT32FILEINFO *fileinfo_ptr2 = (FAT32FILEINFO *)malloc(sizeof(FAT32FILEINFO));
|
|
unsigned int handle2;
|
|
handle = FAT_findfirst("D:\\*", &fileinfo_ptr);
|
|
if (handle == 0) {
|
|
uart_printf("find out file log*.txt err\n");
|
|
return;
|
|
}
|
|
uart_printf(">>findout :%s size:%u %u:%u:%u-%u:%u:%u\n", fileinfo_ptr.info.m_lpszFullName,fileinfo_ptr.info.m_nFileSize,
|
|
fileinfo_ptr.info.m_tModify.m_nYear,fileinfo_ptr.info.m_tModify.m_nMonth,fileinfo_ptr.info.m_tModify.m_nDate,
|
|
fileinfo_ptr.info.m_tModify.m_nHour,fileinfo_ptr.info.m_tModify.m_nMinute,fileinfo_ptr.info.m_tModify.m_nSecond);
|
|
while(1) {
|
|
ret = FAT_findnext(handle, &fileinfo_ptr);
|
|
if (ret == 0) {
|
|
uart_printf(">>findout :%s size:%u %u:%u:%u-%u:%u:%u\n", fileinfo_ptr.info.m_lpszFullName,fileinfo_ptr.info.m_nFileSize,
|
|
fileinfo_ptr.info.m_tModify.m_nYear,fileinfo_ptr.info.m_tModify.m_nMonth,fileinfo_ptr.info.m_tModify.m_nDate,
|
|
fileinfo_ptr.info.m_tModify.m_nHour,fileinfo_ptr.info.m_tModify.m_nMinute,fileinfo_ptr.info.m_tModify.m_nSecond);
|
|
if(fileinfo_ptr.info.m_nAttr == AM_DIR) {
|
|
sprintf(str, "%s\\%s\\*",DUMP_VOL ,(char *)fileinfo_ptr.info.m_lpszFullName);
|
|
uart_printf("Sub find :%s", str);
|
|
handle2 = FAT_findfirst(str, fileinfo_ptr2);
|
|
if (handle != 0) {
|
|
uart_printf("find out %s\n", fileinfo_ptr2->info.m_lpszFullName);
|
|
FAT_findfileclose(handle2);
|
|
}
|
|
}
|
|
|
|
}
|
|
else break;
|
|
}
|
|
FAT_findfileclose(handle);
|
|
uart_printf("find end000\n");
|
|
#endif
|
|
ASSERT(1==0);
|
|
sprintf(str, "%s\\%s", DUMP_VOL, "log1.txt");
|
|
handle = FAT_fopen(str, "ab");
|
|
fatal_printf("open log1.txt mode:ab handle:%x\n", handle);
|
|
FAT_fwrite("123456", 1, 6, handle);
|
|
ret = FAT_GetFileSize(handle);
|
|
if (ret == 12) {
|
|
fatal_printf("log1file size is :%u\n", ret);
|
|
}
|
|
else {
|
|
fatal_printf("log1file size err :%u\n", ret);
|
|
}
|
|
FAT_fclose(handle);
|
|
sprintf(str, "%s\\%s", DUMP_VOL, "log1.txt");
|
|
handle = FAT_fopen(str, "wb");
|
|
uart_printf("open log1.txt :%x\n", handle);
|
|
ret = FAT_GetFileSize(handle);
|
|
uart_printf("log1file size is :%u\n", ret);
|
|
FAT_fclose(handle);
|
|
sprintf(str, "%s\\%s", DUMP_VOL, "log2.txt");
|
|
handle = FAT_fopen(str, "rb");
|
|
uart_printf("open log2.txt :%x\n", handle);
|
|
ret = FAT_GetFileSize(handle);
|
|
uart_printf("log2file size is :%u\n", ret);
|
|
FAT_fclose(handle);
|
|
sprintf(str, "%s\\%s", DUMP_VOL, "log3.txt");
|
|
handle = FAT_fopen(str, "rwc");
|
|
uart_printf("open log3.txt :%x\n", handle);
|
|
ret = FAT_GetFileSize(handle);
|
|
uart_printf("log3file size is :%u\n", ret);
|
|
FAT_fclose(handle);
|
|
sprintf(str, "%s\\%s", DUMP_VOL, "log4.txt");
|
|
handle = FAT_fopen(str, "rwb");
|
|
uart_printf("open log4.txt :%x\n", handle);
|
|
ret = FAT_GetFileSize(handle);
|
|
uart_printf("log4file size is :%u\n", ret);
|
|
FAT_fclose(handle);
|
|
sprintf(str, "%s\\%s", DUMP_VOL, "log*.txt");
|
|
handle = FAT_findfirst(str, &fileinfo_ptr);
|
|
if (handle == 0) {
|
|
uart_printf("find out file log*.txt err\n");
|
|
return;
|
|
}
|
|
uart_printf(">>findout :%s size:%u %u:%u:%u-%u:%u:%u\n", fileinfo_ptr.info.m_lpszFullName,fileinfo_ptr.info.m_nFileSize,
|
|
fileinfo_ptr.info.m_tModify.m_nYear,fileinfo_ptr.info.m_tModify.m_nMonth,fileinfo_ptr.info.m_tModify.m_nDate,
|
|
fileinfo_ptr.info.m_tModify.m_nHour,fileinfo_ptr.info.m_tModify.m_nMinute,fileinfo_ptr.info.m_tModify.m_nSecond);
|
|
while(1) {
|
|
ret = FAT_findnext(handle, &fileinfo_ptr);
|
|
if (ret == 0) {
|
|
uart_printf(">>findout :%s size:%u %u:%u:%u-%u:%u:%u\n", fileinfo_ptr.info.m_lpszFullName,fileinfo_ptr.info.m_nFileSize,
|
|
fileinfo_ptr.info.m_tModify.m_nYear,fileinfo_ptr.info.m_tModify.m_nMonth,fileinfo_ptr.info.m_tModify.m_nDate,
|
|
fileinfo_ptr.info.m_tModify.m_nHour,fileinfo_ptr.info.m_tModify.m_nMinute,fileinfo_ptr.info.m_tModify.m_nSecond);
|
|
|
|
}
|
|
else break;
|
|
}
|
|
FAT_findfileclose(handle);
|
|
uart_printf("find end\n");
|
|
//create dir and file
|
|
sprintf(str, "%s\\%s", DUMP_VOL, "B");
|
|
f_mkdir(str);
|
|
sprintf(str, "%s\\%s", DUMP_VOL, "B\\loga1.txt");
|
|
handle = FAT_fopen(str, "wbc");
|
|
FAT_fclose(handle);
|
|
sprintf(str, "%s\\%s", DUMP_VOL, "B\\loga*");
|
|
handle = FAT_findfirst(str, &fileinfo_ptr);
|
|
if (handle == 0) {
|
|
uart_printf("find out file err\n");
|
|
return;
|
|
}
|
|
uart_printf(">>findout :%s size:%u %u:%u:%u-%u:%u:%u\n", fileinfo_ptr.info.m_lpszFullName,fileinfo_ptr.info.m_nFileSize,
|
|
fileinfo_ptr.info.m_tModify.m_nYear,fileinfo_ptr.info.m_tModify.m_nMonth,fileinfo_ptr.info.m_tModify.m_nDate,
|
|
fileinfo_ptr.info.m_tModify.m_nHour,fileinfo_ptr.info.m_tModify.m_nMinute,fileinfo_ptr.info.m_tModify.m_nSecond);
|
|
|
|
while(1) {
|
|
ret = FAT_findnext(handle, &fileinfo_ptr);
|
|
if (ret == 0) {
|
|
uart_printf(">>findout :%s size:%u %u:%u:%u-%u:%u:%u\n", fileinfo_ptr.info.m_lpszFullName,fileinfo_ptr.info.m_nFileSize,
|
|
fileinfo_ptr.info.m_tModify.m_nYear,fileinfo_ptr.info.m_tModify.m_nMonth,fileinfo_ptr.info.m_tModify.m_nDate,
|
|
fileinfo_ptr.info.m_tModify.m_nHour,fileinfo_ptr.info.m_tModify.m_nMinute,fileinfo_ptr.info.m_tModify.m_nSecond);
|
|
|
|
}
|
|
else break;
|
|
}
|
|
FAT_findfileclose(handle);
|
|
uart_printf("find end2\n");
|
|
sprintf(str, "%s\\%s", DUMP_VOL, "log10.txt");
|
|
unsigned int file = FAT_fopen(str, "rwbc");
|
|
if (file == 0){
|
|
uart_printf("open file err\n");
|
|
return;
|
|
}
|
|
uart_printf("open file ok :0x%x\n", file);
|
|
int i = 0;
|
|
|
|
ASSERT(xx_buf != NULL);
|
|
for(i = 0; i< 256; i++) {
|
|
xx_buf[i] = i;
|
|
}
|
|
ret = FAT_fwrite(xx_buf,1 ,1024,file);
|
|
if (ret != 1024) {
|
|
uart_printf("file write err\n");
|
|
}
|
|
uart_printf("write file ok\n");
|
|
ret = FAT_fseek(file, 512, 0);
|
|
uart_printf("seek file :%d\n", ret);
|
|
ret = FAT_fread(xx_buf, 1, 512, file);
|
|
if(ret != 512) {
|
|
uart_printf("file read err :%d\n", ret);
|
|
return;
|
|
}
|
|
for(i = 0; i < 128; i++) {
|
|
if (xx_buf[i] != (i + 128)) {
|
|
uart_printf("file read err%d:%d\n", i, xx_buf[i]);
|
|
return;
|
|
}
|
|
}
|
|
uart_printf("read file ok\n");
|
|
ret = FAT_fseek(file, 0,FS_SEEK_END);
|
|
uart_printf("FAT_fseek end :%d\n", ret);
|
|
FAT_fclose(file);
|
|
//before rename, must close the file
|
|
sprintf(str, "%s\\%s", DUMP_VOL, "log10.txt");
|
|
sprintf((char *)xx_buf, "%s\\%s", DUMP_VOL, "log11.txt");
|
|
ret = FAT_rename(str, (const char *)xx_buf);
|
|
if (ret != 0) {
|
|
uart_printf("rename err:%d\n", ret);
|
|
return;
|
|
}
|
|
uart_printf("rename ok\n");
|
|
sprintf(str, "%s\\%s", DUMP_VOL, "*");
|
|
handle = FAT_findfirst(str, &fileinfo_ptr);
|
|
if (handle == 0) {
|
|
uart_printf("find out file err\n");
|
|
return;
|
|
}
|
|
uart_printf(">>findout :%s size:%u %u:%u:%u-%u:%u:%u\n", fileinfo_ptr.info.m_lpszFullName,fileinfo_ptr.info.m_nFileSize,
|
|
fileinfo_ptr.info.m_tModify.m_nYear,fileinfo_ptr.info.m_tModify.m_nMonth,fileinfo_ptr.info.m_tModify.m_nDate,
|
|
fileinfo_ptr.info.m_tModify.m_nHour,fileinfo_ptr.info.m_tModify.m_nMinute,fileinfo_ptr.info.m_tModify.m_nSecond);
|
|
|
|
while(1) {
|
|
ret = FAT_findnext(handle, &fileinfo_ptr);
|
|
if (ret == 0) {
|
|
uart_printf(">>findout2 :%s size:%u %u:%u:%u-%u:%u:%u\n", fileinfo_ptr.info.m_lpszFullName,fileinfo_ptr.info.m_nFileSize,
|
|
fileinfo_ptr.info.m_tModify.m_nYear,fileinfo_ptr.info.m_tModify.m_nMonth,fileinfo_ptr.info.m_tModify.m_nDate,
|
|
fileinfo_ptr.info.m_tModify.m_nHour,fileinfo_ptr.info.m_tModify.m_nMinute,fileinfo_ptr.info.m_tModify.m_nSecond);
|
|
|
|
}
|
|
else break;
|
|
}
|
|
uart_printf("find end5\n");
|
|
FAT_findfileclose(handle);
|
|
sprintf(str, "%s\\%s", DUMP_VOL, "log11.txt");
|
|
ret = FAT_remove(str);
|
|
uart_printf("remove %d\n", ret);
|
|
sprintf(str, "%s\\%s", DUMP_VOL, "*");
|
|
handle = FAT_findfirst(str, &fileinfo_ptr);
|
|
if (handle == 0) {
|
|
uart_printf("find out file err\n");
|
|
return;
|
|
}
|
|
uart_printf(">>findout :%s size:%u %u:%u:%u-%u:%u:%u\n", fileinfo_ptr.info.m_lpszFullName,fileinfo_ptr.info.m_nFileSize,
|
|
fileinfo_ptr.info.m_tModify.m_nYear,fileinfo_ptr.info.m_tModify.m_nMonth,fileinfo_ptr.info.m_tModify.m_nDate,
|
|
fileinfo_ptr.info.m_tModify.m_nHour,fileinfo_ptr.info.m_tModify.m_nMinute,fileinfo_ptr.info.m_tModify.m_nSecond);
|
|
|
|
while(1) {
|
|
ret = FAT_findnext(handle, &fileinfo_ptr);
|
|
if (ret == 0) {
|
|
uart_printf(">>findout2 :%s size:%u %u:%u:%u-%u:%u:%u\n", fileinfo_ptr.info.m_lpszFullName,fileinfo_ptr.info.m_nFileSize,
|
|
fileinfo_ptr.info.m_tModify.m_nYear,fileinfo_ptr.info.m_tModify.m_nMonth,fileinfo_ptr.info.m_tModify.m_nDate,
|
|
fileinfo_ptr.info.m_tModify.m_nHour,fileinfo_ptr.info.m_tModify.m_nMinute,fileinfo_ptr.info.m_tModify.m_nSecond);
|
|
|
|
}
|
|
else break;
|
|
}
|
|
uart_printf("find end6\n");
|
|
FAT_findfileclose(handle);
|
|
|
|
}
|
|
#endif
|
|
#endif
|
|
/*----------- Local defines --------------------------------------------------*/
|
|
|
|
/*----------- Local macro definitions ----------------------------------------*/
|
|
|
|
/*----------- Local type definitions -----------------------------------------*/
|
|
|
|
/*----------- Local constant definitions -------------------------------------*/
|
|
|
|
/*----------- Local variable definitions -------------------------------------*/
|
|
|
|
/*----------- Global variable definition -------------------------------------*/
|
|
|
|
|
|
|
|
/*----------- Global constant definitions ------------------------------------*/
|
|
|
|
/*----------- Local function definition -------------------------------------*/
|
|
|
|
/*******************************************************************************
|
|
* Function: swPlatformPhase1init
|
|
********************************************************************************
|
|
* Description:
|
|
*
|
|
* Parameters:
|
|
*
|
|
* Return value:
|
|
*
|
|
* Notes:
|
|
*******************************************************************************/
|
|
void crossPlatformSWPhase1Init(void)
|
|
{
|
|
return;
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* Function: swPlatformPhase2init
|
|
********************************************************************************
|
|
* Description:
|
|
*
|
|
* Parameters:
|
|
*
|
|
* Return value:
|
|
*
|
|
* Notes:
|
|
*******************************************************************************/
|
|
void crossPlatformSWPhase2Init(void)
|
|
{
|
|
return;
|
|
} /* End of swPlatformPhase2init */
|
|
|
|
|
|
/*******************************************************************************
|
|
* Function: swPlatformPhase3init
|
|
********************************************************************************
|
|
|
|
* Description:
|
|
*
|
|
* Parameters:
|
|
*
|
|
* Return value:
|
|
*
|
|
* Notes:
|
|
*******************************************************************************/
|
|
|
|
void crossPlatformSWPhase3Init(void)
|
|
{
|
|
return;
|
|
}
|
|
|
|
#if (defined FLAVOR_COM)
|
|
void crossPlatformSWPhaseAfterAllNvmInit(void)
|
|
{
|
|
|
|
}
|
|
#endif
|