This commit is contained in:
pvvx 2017-07-11 14:51:06 +03:00
parent a82acd811f
commit 6386e78c5b
13 changed files with 596 additions and 513 deletions

View file

@ -644,7 +644,7 @@
<buildTargets> <buildTargets>
<target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> <target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>mingw32-make.exe</buildCommand> <buildCommand>mingw32-make.exe</buildCommand>
<buildArguments>-s -j 4</buildArguments> <buildArguments>-s -j 2</buildArguments>
<buildTarget>all</buildTarget> <buildTarget>all</buildTarget>
<stopOnError>true</stopOnError> <stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand> <useDefaultCommand>false</useDefaultCommand>

View file

@ -235,6 +235,7 @@ s8 sdio_sd_init(void) {
} }
sdio_status = SDIO_SD_OK; sdio_status = SDIO_SD_OK;
if (HalSdioHostOp.HalSdioHostChangeSdClock(&SdioHostAdapter, if (HalSdioHostOp.HalSdioHostChangeSdClock(&SdioHostAdapter,
// SD_CLK_20_8MHZ) != HAL_OK)
SD_CLK_41_6MHZ) != HAL_OK) SD_CLK_41_6MHZ) != HAL_OK)
DBG_SDIO_INFO("SD card does not support high speed.\n"); DBG_SDIO_INFO("SD card does not support high speed.\n");
} }
@ -259,7 +260,7 @@ s8 sdio_sd_setClock(SD_CLK_FREQUENCY SDCLK) {
DBG_SDIO_ERR("Malloc ADMA2 table fail.\n"); DBG_SDIO_ERR("Malloc ADMA2 table fail.\n");
return -1; return -1;
} }
DBG_SDIO_INFO("SD card set CLK %d Hz\n", PLATFORM_CLOCK/(4<<(SD_CLK_41_6MHZ-SDCLK))); DBG_SDIO_INFO("SD card set CLK %d Hz\n", PLATFORM_CLOCK/(2 << (SD_CLK_41_6MHZ - SDCLK)));
sta = HalSdioHostOp.HalSdioHostChangeSdClock(&SdioHostAdapter, SDCLK); sta = HalSdioHostOp.HalSdioHostChangeSdClock(&SdioHostAdapter, SDCLK);
rtw_mfree(padma, sizeof(ADMA2_DESC_FMT)); rtw_mfree(padma, sizeof(ADMA2_DESC_FMT));
if (sta) if (sta)

View file

@ -1,6 +1,6 @@
#ifndef _SDCARD_H_ #ifndef _SDCARD_H_
#define _SDCARD_H_ #define _SDCARD_H_
#include "fatfs_ext/inc/ff_driver.h" #include "ff_driver.h"
extern ll_diskio_drv SD_disk_Driver; extern ll_diskio_drv SD_disk_Driver;
#endif #endif

View file

@ -1,7 +1,7 @@
#ifndef _USBDISK_H_ #ifndef _USBDISK_H_
#define _USBDISK_H_ #define _USBDISK_H_
#include "fatfs_ext/inc/ff_driver.h" #include "ff_driver.h"
extern ll_diskio_drv USB_disk_Driver; extern ll_diskio_drv USB_disk_Driver;
#endif #endif

View file

@ -1,6 +1,7 @@
#ifndef _BITBAND_IO_H_ #ifndef _BITBAND_IO_H_
#define _BITBAND_IO_H_ #define _BITBAND_IO_H_
#include "PinNames.h"
#include "hal_platform.h" #include "hal_platform.h"
#include "hal_api.h" #include "hal_api.h"
#include "hal_gpio.h" #include "hal_gpio.h"
@ -143,4 +144,10 @@
#define BITBAND_K5 ucBITBAND_PERI(GPIO_REG_BASE+GPIO_PORTC_DR,25) //Port = 2, bit = 25, K5 #define BITBAND_K5 ucBITBAND_PERI(GPIO_REG_BASE+GPIO_PORTC_DR,25) //Port = 2, bit = 25, K5
#define BITBAND_K6 ucBITBAND_PERI(GPIO_REG_BASE+GPIO_PORTC_DR,26) //Port = 2, bit = 26, K6 #define BITBAND_K6 ucBITBAND_PERI(GPIO_REG_BASE+GPIO_PORTC_DR,26) //Port = 2, bit = 26, K6
volatile uint8_t * BitBandAddr(void *addr, uint8_t bit);
volatile uint8_t * BitBandPeriAddr(void *addr, uint8_t bit);
volatile uint8_t * GetOutPinBitBandAddr(PinName pin);
volatile uint8_t * GetInPinBitBandAddr(PinName pin);
volatile uint8_t * HardSetPin(PinName pin, HAL_GPIO_PIN_MODE pmode, uint8_t val);
#endif // _BITBAND_IO_H_ #endif // _BITBAND_IO_H_

View file

@ -46,24 +46,24 @@ typedef enum _SDIO_XFER_TYPE_{
}SDIO_XFER_TYPE; }SDIO_XFER_TYPE;
typedef struct _HAL_SDIO_HOST_ADAPTER_{ typedef struct _HAL_SDIO_HOST_ADAPTER_{
IRQ_HANDLE IrqHandle; //+0..6(u32) Irq Handler IRQ_HANDLE IrqHandle; //+0..
ADMA2_DESC_FMT *AdmaDescTbl; //+7(u32) ADMA2_DESC_FMT *AdmaDescTbl; //+16
u32 Response[4]; //+8..11(u32) u32 Response[4]; //+20,24,28,32
u32 CardOCR; //+12 u32 CardOCR; //+36
u32 CardStatus; //+13 u32 CardStatus; //+40
u32 IsWriteProtect; //+14 u32 IsWriteProtect; //+44
u8 SdStatus[SD_STATUS_LEN]; //+15.. u8 SdStatus[SD_STATUS_LEN]; //+48..
u8 Csd[CSD_REG_LEN]; //+31 u8 Csd[CSD_REG_LEN]; //+112..
volatile u8 CmdCompleteFlg; //+128(u8) volatile u8 CmdCompleteFlg; //+128
volatile u8 XferCompleteFlg; //+129(u8) volatile u8 XferCompleteFlg; //+129
volatile u8 ErrIntFlg; volatile u8 ErrIntFlg; //+130
volatile u8 CardCurState; volatile u8 CardCurState; //+131
u8 IsSdhc; u8 IsSdhc; //+132
u8 CurrSdClk; //+133? u8 CurrSdClk; //+133
u16 RCA; u16 RCA; //+134
u16 SdSpecVer; u16 SdSpecVer; //+136
SDIO_ERR_TYPE errType; SDIO_ERR_TYPE errType; //+140
SDIO_XFER_TYPE XferType; SDIO_XFER_TYPE XferType; //+144
VOID (*XferCompCallback)(VOID *pAdapter); VOID (*XferCompCallback)(VOID *pAdapter);
VOID *XferCompCbPara; VOID *XferCompCbPara;
VOID (*ErrorCallback)(VOID *pAdapter); VOID (*ErrorCallback)(VOID *pAdapter);

View file

@ -425,14 +425,14 @@ typedef struct _ADMA2_DESC_FMT_
/* 0x0E */ /* 0x0E */
typedef struct _SDIO_HOST_CMD_FMT_ typedef struct _SDIO_HOST_CMD_FMT_
{ {
u16 RespType:2; u16 RespType:2; //bit:0..1
u16 Rsvd0:1; u16 Rsvd0:1; //bit:2
u16 CmdCrcChkEn:1; u16 CmdCrcChkEn:1; //bit:3
u16 CmdIdxChkEn:1; u16 CmdIdxChkEn:1; //bit:4
u16 DataPresent:1; u16 DataPresent:1; //bit:5
u16 CmdType:2; u16 CmdType:2; //bit:6..7
u16 CmdIdx:6; u16 CmdIdx:6; //bit:8..13
u16 Rsvd1:2; u16 Rsvd1:2; //bit:14..15
}SDIO_HOST_CMD_FMT, *PSDIO_HOST_CMD_FMT; }SDIO_HOST_CMD_FMT, *PSDIO_HOST_CMD_FMT;
typedef struct _SDIO_HOST_CMD_ typedef struct _SDIO_HOST_CMD_

View file

@ -40,7 +40,7 @@ all: LIBS +=_wlan _platform_new _wps _websocket _xmodem _mdns
mp: LIBS +=_wlan_mp _platform_new _wps _websocket _xmodem _mdns mp: LIBS +=_wlan_mp _platform_new _wps _websocket _xmodem _mdns
endif endif
ifdef USE_SDIOH ifdef USE_SDIOH
LIBS += _sdcard LIBS += _sdcard_v2
CFLAGS += -DCONFIG_FATFS_EN=1 CFLAGS += -DCONFIG_FATFS_EN=1
endif endif
# m c nosys gcc # m c nosys gcc
@ -364,16 +364,17 @@ endif
#utilities - FatFS #utilities - FatFS
ifdef USE_FATFS ifdef USE_FATFS
INCLUDES += sdk/component/common/file_system/fatfs INCLUDES += sdk/component/common/file_system/fatfs
INCLUDES += sdk/component/common/file_system/fatfs/fatfs_ext/inc
INCLUDES += sdk/component/common/file_system/fatfs/r0.10c/include INCLUDES += sdk/component/common/file_system/fatfs/r0.10c/include
SRC_C += sdk/component/common/file_system/fatfs/fatfs_ext/src/ff_driver.c SRC_C += sdk/component/common/file_system/fatfs/fatfs_ext/src/ff_driver.c
SRC_C += sdk/component/common/file_system/fatfs/r0.10c/src/diskio.c SRC_C += sdk/component/common/file_system/fatfs/r0.10c/src/diskio.c
SRC_C += sdk/component/common/file_system/fatfs/r0.10c/src/ff.c SRC_C += sdk/component/common/file_system/fatfs/r0.10c/src/ff.c
SRC_C += sdk/component/common/file_system/fatfs/r0.10c/src/option/ccsbcs.c SRC_C += sdk/component/common/file_system/fatfs/r0.10c/src/option/ccsbcs.c
endif
ifdef USE_SDIOH ifdef USE_SDIOH
INCLUDES += sdk/component/common/file_system/fatfs/disk_if/inc INCLUDES += sdk/component/common/file_system/fatfs/disk_if/inc
SRC_C += sdk/component/common/file_system/fatfs/disk_if/src/sdcard.c SRC_C += sdk/component/common/file_system/fatfs/disk_if/src/sdcard.c
endif endif
endif
# Reversed SDK component # Reversed SDK component
#ADD_SRC_C += sdk/component/soc/realtek/8195a/cmsis/device/app_start.c #ADD_SRC_C += sdk/component/soc/realtek/8195a/cmsis/device/app_start.c

View file

@ -3,7 +3,7 @@
#============================================= #=============================================
#WEB_INA219_DRV = 1 #WEB_INA219_DRV = 1
#WEB_ADC_DRV = 1 #WEB_ADC_DRV = 1
#WEB_SDCARD = 1 USE_SDCARD = 1
#USE_AT = 1 #USE_AT = 1
#USE_FATFS = 1 #USE_FATFS = 1
#USE_SDIOH = 1 #USE_SDIOH = 1
@ -17,6 +17,11 @@ USE_NEWCONSOLE = 1
USE_WIFI_API = 1 USE_WIFI_API = 1
endif endif
ifdef USE_SDCARD
USE_FATFS = 1
USE_SDIOH = 1
endif
#RTOSDIR=freertos_v8.1.2 #RTOSDIR=freertos_v8.1.2
RTOSDIR=freertos_v9.0.0 RTOSDIR=freertos_v9.0.0
LWIPDIR=lwip_v1.4.1 LWIPDIR=lwip_v1.4.1
@ -36,9 +41,7 @@ ADD_SRC_C += project/src/console/wifi_console.c
ADD_SRC_C += project/src/console/wlan_tst.c ADD_SRC_C += project/src/console/wlan_tst.c
#ADD_SRC_C += project/src/console/pwm_tst.c #ADD_SRC_C += project/src/console/pwm_tst.c
ifdef WEB_SDCARD ifdef USE_SDCARD
USE_FATFS = 1
USE_SDIOH = 1
ADD_SRC_C += project/src/console/sd_fat.c ADD_SRC_C += project/src/console/sd_fat.c
endif endif

View file

@ -211,6 +211,71 @@ void sd_unmount(FATFS *m_fs) {
SD_DeInit(); // sdio_sd_deinit(); SD_DeInit(); // sdio_sd_deinit();
} }
void read_file_test(char* file_name) {
FIL *f = malloc(sizeof(FIL));
if (f_open(f, file_name, FA_READ) == FR_OK) {
char * buf = malloc(2048);
unsigned int bytesread =0;
unsigned int totalread=0;
do {
if (f_read(f, buf, 2048, &bytesread) != FR_OK) {
totalread += bytesread;
printf("Read error!");
break;
}
totalread += bytesread;
}
while (bytesread !=0);
free(buf);
f_close(f);
} else {
printf("No open file!");
}
free(f);
}
LOCAL void fATHF(int argc, char *argv[]) {
uint8 buf[512];
FATFS * fs = sd_mount();
if (fs != NULL) {
u8 * pbuf = (u8 *) malloc(512); // char *lfn = malloc (_MAX_LFN + 1);
if (pbuf != NULL) {
DIR dir;
FILINFO fno;
struct os_tm tm;
fno.lfname = (TCHAR*) pbuf;
fno.lfsize = 512;
u8 * sdir;
if(argc > 1
&& argv[1] != NULL
&& (sdir = (u8 *) malloc(strlen(argv[1]) + 4)) != NULL )
strcpy(strcpy(sdir, logical_drv) + 3, argv[1]);
else sdir = logical_drv;
if (f_opendir(&dir, sdir) == FR_OK) {
while (f_readdir(&dir, &fno) == FR_OK && fno.fname[0] != 0) {
if ((fno.fattrib & AM_VOL)==0 && fno.fsize > 0) {
if (*fno.lfname) {
strcpy(strcpy(buf, logical_drv) + 3, fno.lfname);
} else {
strcpy(strcpy(buf, logical_drv) + 3, fno.fname);
}
TickType_t t1 = xTaskGetTickCount();
read_file_test(buf);
t1 = xTaskGetTickCount() - t1;
if(t1 == 0) t1 = 1;
printf("%u kbytes/sec\t%s\n", t1, buf);
}
}
} else
printf("FATFS: Open dir fail!\n");
free(pbuf);
if(sdir != logical_drv) free(sdir);
}
}
sd_unmount(fs);
}
/* Test SD */ /* Test SD */
LOCAL void fATHS(int argc, char *argv[]) { LOCAL void fATHS(int argc, char *argv[]) {
// HalPinCtrlRtl8195A(UART0,0,0); // HalPinCtrlRtl8195A(UART0,0,0);
@ -311,8 +376,9 @@ LOCAL void fATHS(int argc, char *argv[]) {
} }
MON_RAM_TAB_SECTION COMMAND_TABLE console_commands_spitst[] = { MON_RAM_TAB_SECTION COMMAND_TABLE console_commands_dscard[] = {
{"ATHS", 0, fATHS, ": SD test"} {"ATHS", 0, fATHS, ": SD test"},
{"ATHF", 0, fATHF, ": SD file read"}
}; };
#endif // CONFIG_SDIO_HOST_EN #endif // CONFIG_SDIO_HOST_EN