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>
<target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>mingw32-make.exe</buildCommand>
<buildArguments>-s -j 4</buildArguments>
<buildArguments>-s -j 2</buildArguments>
<buildTarget>all</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand>

View file

@ -235,6 +235,7 @@ s8 sdio_sd_init(void) {
}
sdio_status = SDIO_SD_OK;
if (HalSdioHostOp.HalSdioHostChangeSdClock(&SdioHostAdapter,
// SD_CLK_20_8MHZ) != HAL_OK)
SD_CLK_41_6MHZ) != HAL_OK)
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");
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);
rtw_mfree(padma, sizeof(ADMA2_DESC_FMT));
if (sta)

View file

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

View file

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

View file

@ -1,6 +1,7 @@
#ifndef _BITBAND_IO_H_
#define _BITBAND_IO_H_
#include "PinNames.h"
#include "hal_platform.h"
#include "hal_api.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_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_

View file

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

View file

@ -425,14 +425,14 @@ typedef struct _ADMA2_DESC_FMT_
/* 0x0E */
typedef struct _SDIO_HOST_CMD_FMT_
{
u16 RespType:2;
u16 Rsvd0:1;
u16 CmdCrcChkEn:1;
u16 CmdIdxChkEn:1;
u16 DataPresent:1;
u16 CmdType:2;
u16 CmdIdx:6;
u16 Rsvd1:2;
u16 RespType:2; //bit:0..1
u16 Rsvd0:1; //bit:2
u16 CmdCrcChkEn:1; //bit:3
u16 CmdIdxChkEn:1; //bit:4
u16 DataPresent:1; //bit:5
u16 CmdType:2; //bit:6..7
u16 CmdIdx:6; //bit:8..13
u16 Rsvd1:2; //bit:14..15
}SDIO_HOST_CMD_FMT, *PSDIO_HOST_CMD_FMT;
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
endif
ifdef USE_SDIOH
LIBS += _sdcard
LIBS += _sdcard_v2
CFLAGS += -DCONFIG_FATFS_EN=1
endif
# m c nosys gcc
@ -364,16 +364,17 @@ endif
#utilities - FatFS
ifdef USE_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
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/ff.c
SRC_C += sdk/component/common/file_system/fatfs/r0.10c/src/option/ccsbcs.c
endif
ifdef USE_SDIOH
INCLUDES += sdk/component/common/file_system/fatfs/disk_if/inc
SRC_C += sdk/component/common/file_system/fatfs/disk_if/src/sdcard.c
endif
endif
# Reversed SDK component
#ADD_SRC_C += sdk/component/soc/realtek/8195a/cmsis/device/app_start.c

View file

@ -3,7 +3,7 @@
#=============================================
#WEB_INA219_DRV = 1
#WEB_ADC_DRV = 1
#WEB_SDCARD = 1
USE_SDCARD = 1
#USE_AT = 1
#USE_FATFS = 1
#USE_SDIOH = 1
@ -17,6 +17,11 @@ USE_NEWCONSOLE = 1
USE_WIFI_API = 1
endif
ifdef USE_SDCARD
USE_FATFS = 1
USE_SDIOH = 1
endif
#RTOSDIR=freertos_v8.1.2
RTOSDIR=freertos_v9.0.0
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/pwm_tst.c
ifdef WEB_SDCARD
USE_FATFS = 1
USE_SDIOH = 1
ifdef USE_SDCARD
ADD_SRC_C += project/src/console/sd_fat.c
endif

View file

@ -211,6 +211,71 @@ void sd_unmount(FATFS *m_fs) {
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 */
LOCAL void fATHS(int argc, char *argv[]) {
// HalPinCtrlRtl8195A(UART0,0,0);
@ -311,8 +376,9 @@ LOCAL void fATHS(int argc, char *argv[]) {
}
MON_RAM_TAB_SECTION COMMAND_TABLE console_commands_spitst[] = {
{"ATHS", 0, fATHS, ": SD test"}
MON_RAM_TAB_SECTION COMMAND_TABLE console_commands_dscard[] = {
{"ATHS", 0, fATHS, ": SD test"},
{"ATHF", 0, fATHF, ": SD file read"}
};
#endif // CONFIG_SDIO_HOST_EN