mirror of
https://github.com/pvvx/RTL00_WEB.git
synced 2024-11-22 05:54:19 +00:00
add test SDdir
This commit is contained in:
parent
3a865fb51d
commit
60c064ca19
8 changed files with 370 additions and 25 deletions
|
@ -8,23 +8,34 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h3 style="width:800px; text-align: center;">Read regs U & I INA219</h3>
|
<h3 style="width:800px; text-align: center;">Read regs U & I INA219</h3>
|
||||||
<div id="div_g" style="width:800px; height:400px;"></div>
|
<div id="div_v" style="width:800px; height:400px;"></div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var data = [];
|
var datau = [];
|
||||||
var g = new Dygraph(
|
//var datai = [];
|
||||||
document.getElementById("div_g"),
|
var gu = new Dygraph(
|
||||||
data,
|
document.getElementById("div_v"),
|
||||||
|
datau,
|
||||||
{
|
{
|
||||||
drawPoints: true,
|
labels: ['X', 'I', 'U'],
|
||||||
showRoller: true,
|
// drawPoints: true,
|
||||||
labels: ['X', 'U', 'I']});
|
rollPeriod: 100,
|
||||||
|
// errorBars: true,
|
||||||
|
// showRoller: true,
|
||||||
|
y2label: 'U(mV)',
|
||||||
|
ylabel: 'I(mA)',
|
||||||
|
series : {
|
||||||
|
'U': { axis: 'y2' }
|
||||||
|
}
|
||||||
|
// , axes: { y: {valueRange: [4500, 5500] }, y2: {valueRange: [75, 125] }}
|
||||||
|
});
|
||||||
|
|
||||||
var oldblkid = 0;
|
var oldblkid = 0;
|
||||||
var rdnextflg = false;
|
var rdnextflg = false;
|
||||||
var cur_idx = 0;
|
var cur_idx = 0;
|
||||||
|
var sig = 10;
|
||||||
ws = new WebSocket('ws://rtl871x0/web.cgi');
|
ws = new WebSocket('ws://rtl871x0/web.cgi');
|
||||||
ws.binaryType = 'arraybuffer';
|
ws.binaryType = 'arraybuffer';
|
||||||
ws.onopen = function(){ws.send('ina219')};
|
ws.onopen = function(){ws.send('ina219'); ws.send('pr=0')};
|
||||||
ws.onmessage = function (event) {
|
ws.onmessage = function (event) {
|
||||||
if(event.data instanceof ArrayBuffer) {
|
if(event.data instanceof ArrayBuffer) {
|
||||||
var wordarray = new Int16Array(event.data);
|
var wordarray = new Int16Array(event.data);
|
||||||
|
@ -37,11 +48,11 @@ ws.onmessage = function (event) {
|
||||||
} else rdnextflg = true;
|
} else rdnextflg = true;
|
||||||
oldblkid = blkid + blksz;
|
oldblkid = blkid + blksz;
|
||||||
for (var i=2; i<wordarray.length; i+=2) {
|
for (var i=2; i<wordarray.length; i+=2) {
|
||||||
if(cur_idx > 2000 ) data.shift();
|
if(cur_idx > 10000 ) datau.shift();
|
||||||
data.push([cur_idx, wordarray[i], wordarray[i+1]*50]);
|
datau.push([cur_idx, wordarray[i+1], wordarray[i]*0.5 ]);
|
||||||
cur_idx++;
|
cur_idx++;
|
||||||
}
|
}
|
||||||
g.updateOptions({'file':data});
|
gu.updateOptions({'file':datau});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ws.send("ina219");
|
ws.send("ina219");
|
||||||
|
|
|
@ -8,13 +8,14 @@
|
||||||
#ifdef CONFIG_SDIO_HOST_EN
|
#ifdef CONFIG_SDIO_HOST_EN
|
||||||
#include "sd.h"
|
#include "sd.h"
|
||||||
#include "sdio_host.h"
|
#include "sdio_host.h"
|
||||||
|
#include "semphr.h"
|
||||||
|
|
||||||
#define SIZE_BLOCK_ADMA 512
|
#define SIZE_BLOCK_ADMA 512
|
||||||
|
|
||||||
SemaphoreHandle_t sdWSema;
|
SemaphoreHandle_t sdWSema;
|
||||||
|
|
||||||
void sd_xfer_done_callback(void *obj) {
|
void sd_xfer_done_callback(void *obj) {
|
||||||
RtlUpSema(&sdWSema);
|
rtw_up_sema(&sdWSema);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sd_xfer_err_callback(void *obj) {
|
void sd_xfer_err_callback(void *obj) {
|
||||||
|
@ -35,7 +36,7 @@ SD_RESULT SD_Init() {
|
||||||
else {
|
else {
|
||||||
if (sdio_sd_getProtection() != 0)
|
if (sdio_sd_getProtection() != 0)
|
||||||
result = SD_PROTECTED;
|
result = SD_PROTECTED;
|
||||||
RtlInitSema(&sdWSema, 0);
|
rtw_init_sema(&sdWSema, 0);
|
||||||
sdio_sd_hook_xfer_cmp_cb(sd_xfer_done_callback, 0);
|
sdio_sd_hook_xfer_cmp_cb(sd_xfer_done_callback, 0);
|
||||||
sdio_sd_hook_xfer_err_cb(sd_xfer_err_callback, 0);
|
sdio_sd_hook_xfer_err_cb(sd_xfer_err_callback, 0);
|
||||||
}
|
}
|
||||||
|
@ -45,7 +46,7 @@ SD_RESULT SD_Init() {
|
||||||
//----- SD_DeInit
|
//----- SD_DeInit
|
||||||
SD_RESULT SD_DeInit() {
|
SD_RESULT SD_DeInit() {
|
||||||
sdio_sd_deinit();
|
sdio_sd_deinit();
|
||||||
RtlFreeSema(&sdWSema);
|
rtw_free_sema(&sdWSema);
|
||||||
return SD_OK;
|
return SD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +120,7 @@ SD_RESULT SD_ReadBlocks(u32 sector, u8 *data, u32 count) {
|
||||||
while (sector < end_sector) {
|
while (sector < end_sector) {
|
||||||
rd_count = sdio_read_blocks(sector, buf, 1);
|
rd_count = sdio_read_blocks(sector, buf, 1);
|
||||||
// rtl_printf("rd_counts = %d\n", rd_count);
|
// rtl_printf("rd_counts = %d\n", rd_count);
|
||||||
if (rd_count == 0 && RtlDownSemaWithTimeout(&sdWSema, 1000) != 1) {
|
if (rd_count == 0 && rtw_down_timeout_sema(&sdWSema, 1000) != 1) {
|
||||||
DBG_SDIO_ERR("SD_ReadBlocks timeout\n");
|
DBG_SDIO_ERR("SD_ReadBlocks timeout\n");
|
||||||
return SD_ERROR;
|
return SD_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -133,7 +134,7 @@ SD_RESULT SD_ReadBlocks(u32 sector, u8 *data, u32 count) {
|
||||||
return SD_OK;
|
return SD_OK;
|
||||||
} else {
|
} else {
|
||||||
if (sdio_read_blocks(sector, data, count) == 0) {
|
if (sdio_read_blocks(sector, data, count) == 0) {
|
||||||
if (RtlDownSemaWithTimeout(&sdWSema, 1000) == 1)
|
if (rtw_down_timeout_sema(&sdWSema, 1000) == 1)
|
||||||
return SD_OK;
|
return SD_OK;
|
||||||
DBG_SDIO_ERR("SD_ReadBlocks timeout\n");
|
DBG_SDIO_ERR("SD_ReadBlocks timeout\n");
|
||||||
}
|
}
|
||||||
|
@ -155,7 +156,7 @@ SD_RESULT SD_WriteBlocks(u32 sector, const u8 *data, u32 count) {
|
||||||
while (sector != end_sector) {
|
while (sector != end_sector) {
|
||||||
rtl_memcpy(buf, data, SIZE_BLOCK_ADMA);
|
rtl_memcpy(buf, data, SIZE_BLOCK_ADMA);
|
||||||
wr_count = sdio_write_blocks(sector, buf, 1);
|
wr_count = sdio_write_blocks(sector, buf, 1);
|
||||||
if (wr_count == 0 && RtlDownSemaWithTimeout(&sdWSema, 1000) != 1) {
|
if (wr_count == 0 && rtw_down_timeout_sema(&sdWSema, 1000) != 1) {
|
||||||
DBG_SDIO_ERR("SD_WriteBlocks timeout\n");
|
DBG_SDIO_ERR("SD_WriteBlocks timeout\n");
|
||||||
return SD_ERROR;
|
return SD_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -166,7 +167,7 @@ SD_RESULT SD_WriteBlocks(u32 sector, const u8 *data, u32 count) {
|
||||||
if (wr_count == 0)
|
if (wr_count == 0)
|
||||||
return SD_OK;
|
return SD_OK;
|
||||||
} else if (sdio_write_blocks(sector, data, count) == 0) {
|
} else if (sdio_write_blocks(sector, data, count) == 0) {
|
||||||
if (RtlDownSemaWithTimeout(&sdWSema, 1000) == 1)
|
if (rtw_down_timeout_sema(&sdWSema, 1000) == 1)
|
||||||
return SD_OK;
|
return SD_OK;
|
||||||
DBG_SDIO_ERR("SD_WriteBlocks timeout\n");
|
DBG_SDIO_ERR("SD_WriteBlocks timeout\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ typedef struct{
|
||||||
ll_diskio_drv *drv[_VOLUMES];
|
ll_diskio_drv *drv[_VOLUMES];
|
||||||
unsigned int nbr;
|
unsigned int nbr;
|
||||||
}ff_disk_drv;
|
}ff_disk_drv;
|
||||||
|
|
||||||
extern ff_disk_drv disk;
|
extern ff_disk_drv disk;
|
||||||
|
|
||||||
int FATFS_RegisterDiskDriver(ll_diskio_drv *disk_drv);
|
int FATFS_RegisterDiskDriver(ll_diskio_drv *disk_drv);
|
||||||
|
|
|
@ -39,6 +39,10 @@ else
|
||||||
all: LIBS +=_wlan _platform_new _wps _websocket _xmodem _mdns
|
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
|
||||||
|
LIBS += _sdcard
|
||||||
|
CFLAGS += -DCONFIG_FATFS_EN=1
|
||||||
|
endif
|
||||||
# m c nosys gcc
|
# m c nosys gcc
|
||||||
PATHLIBS = sdk/component/soc/realtek/8195a/misc/bsp/lib/common/gcc
|
PATHLIBS = sdk/component/soc/realtek/8195a/misc/bsp/lib/common/gcc
|
||||||
LDFILE = rlx8195A-symbol-v04-img2.ld
|
LDFILE = rlx8195A-symbol-v04-img2.ld
|
||||||
|
@ -365,6 +369,7 @@ 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
|
||||||
ifdef USE_SDIOH
|
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
|
SRC_C += sdk/component/common/file_system/fatfs/disk_if/src/sdcard.c
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
15
project.mk
15
project.mk
|
@ -1,11 +1,12 @@
|
||||||
#=============================================
|
#=============================================
|
||||||
# SDK CONFIG
|
# SDK CONFIG
|
||||||
#=============================================
|
#=============================================
|
||||||
#WEB_INA219_DRV = 1
|
WEB_INA219_DRV = 1
|
||||||
#WEB_ADC_DRV = 1
|
#WEB_ADC_DRV = 1
|
||||||
|
#WEB_SDCARD = 1
|
||||||
#USE_AT = 1
|
#USE_AT = 1
|
||||||
#USE_FATFS = 1
|
USE_FATFS = 1
|
||||||
#USE_SDIOH = 1
|
USE_SDIOH = 1
|
||||||
#USE_POLARSSL = 1
|
#USE_POLARSSL = 1
|
||||||
#USE_P2P_WPS = 1
|
#USE_P2P_WPS = 1
|
||||||
#USE_GCC_LIB = 1
|
#USE_GCC_LIB = 1
|
||||||
|
@ -34,11 +35,19 @@ ADD_SRC_C += project/src/console/atcmd_user.c
|
||||||
ADD_SRC_C += project/src/console/wifi_console.c
|
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
|
||||||
|
USE_FATFS = 1
|
||||||
|
USE_SDIOH = 1
|
||||||
|
ADD_SRC_C += project/src/console/sd_fat.c
|
||||||
|
endif
|
||||||
|
|
||||||
ifdef WEB_INA219_DRV
|
ifdef WEB_INA219_DRV
|
||||||
ADD_SRC_C += project/src/driver/i2c_drv.c
|
ADD_SRC_C += project/src/driver/i2c_drv.c
|
||||||
ADD_SRC_C += project/src/ina219/ina219drv.c
|
ADD_SRC_C += project/src/ina219/ina219drv.c
|
||||||
CFLAGS += -DWEB_INA219_DRV=1
|
CFLAGS += -DWEB_INA219_DRV=1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef WEB_ADC_DRV
|
ifdef WEB_ADC_DRV
|
||||||
ADD_SRC_C += project/src/driver/adc_drv.c
|
ADD_SRC_C += project/src/driver/adc_drv.c
|
||||||
ADD_SRC_C += project/src/adc_ws/adc_ws.c
|
ADD_SRC_C += project/src/adc_ws/adc_ws.c
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
#define RTL8195A 1
|
#define RTL8195A 1
|
||||||
/* 0 - 166666666 Hz, 1 - 83333333 Hz, 2 - 41666666 Hz, 3 - 20833333 Hz, 4 - 10416666 Hz, 5 - 4000000? Hz,
|
/* 0 - 166666666 Hz, 1 - 83333333 Hz, 2 - 41666666 Hz, 3 - 20833333 Hz, 4 - 10416666 Hz, 5 - 4000000? Hz,
|
||||||
6 - 200000000 Hz, 7 - 10000000 Hz, 8 - 50000000 Hz, 9 - 25000000 Hz, 10 - 12500000 Hz, 11 - 4000000? Hz */
|
6 - 200000000 Hz, 7 - 10000000 Hz, 8 - 50000000 Hz, 9 - 25000000 Hz, 10 - 12500000 Hz, 11 - 4000000? Hz */
|
||||||
#define CONFIG_CPU_CLK 1
|
#define CONFIG_CPU_CLK 0
|
||||||
//166.6MHZ - RUN/IDLE/SLP ~63/21/6.4 mA
|
//166.6MHZ - RUN/IDLE/SLP ~63/21/6.4 mA
|
||||||
//83.3MHZ - RUN/IDLE/SLP ~55/15/6.4 mA
|
//83.3MHZ - RUN/IDLE/SLP ~55/15/6.4 mA
|
||||||
//41.6MHZ - RUN/IDLE ~51/11 mA
|
//41.6MHZ - RUN/IDLE ~51/11 mA
|
||||||
|
|
318
project/src/console/sd_fat.c
Normal file
318
project/src/console/sd_fat.c
Normal file
|
@ -0,0 +1,318 @@
|
||||||
|
/*
|
||||||
|
* sd_fat.c
|
||||||
|
*
|
||||||
|
* Created on: 17 дек. 2016 г.
|
||||||
|
* Author: PVV
|
||||||
|
*/
|
||||||
|
#include "rtl8195a.h"
|
||||||
|
|
||||||
|
#ifdef CONFIG_SDIO_HOST_EN
|
||||||
|
|
||||||
|
#include "rtl8195a_sdio_host.h"
|
||||||
|
#include "hal_sdio_host.h"
|
||||||
|
#include "sd.h"
|
||||||
|
#include "sdio_host.h"
|
||||||
|
#include "pinmap.h"
|
||||||
|
#include "sdcard.h"
|
||||||
|
//#include "ff.h"
|
||||||
|
//#include "fatfs_ext/inc/ff_driver.h"
|
||||||
|
#include "rtl8195a/os.h"
|
||||||
|
#include "at_cmd/log_service.h"
|
||||||
|
|
||||||
|
|
||||||
|
//extern ll_diskio_drv SD_disk_Driver;
|
||||||
|
|
||||||
|
char *logical_drv = "0:/";
|
||||||
|
|
||||||
|
#define START_CHAR_DISK '0'
|
||||||
|
|
||||||
|
typedef struct _msftm_td {
|
||||||
|
unsigned short day :5;
|
||||||
|
unsigned short month :4;
|
||||||
|
unsigned short year :7;
|
||||||
|
} msftm_d;
|
||||||
|
|
||||||
|
typedef struct _msftm_tt {
|
||||||
|
unsigned short sec :5;
|
||||||
|
unsigned short min :6;
|
||||||
|
unsigned short hour :5;
|
||||||
|
} msftm_t;
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
unsigned short w;
|
||||||
|
msftm_d d;
|
||||||
|
} msftm_td;
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
unsigned short w;
|
||||||
|
msftm_t t;
|
||||||
|
} msftm_tt;
|
||||||
|
uint8_t * month[12] = { "Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" , "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
|
||||||
|
/*
|
||||||
|
* MS files times
|
||||||
|
*/
|
||||||
|
int ms_ftime(unsigned short td, unsigned short tt, struct os_tm *tm) {
|
||||||
|
msftm_td d;
|
||||||
|
msftm_tt t;
|
||||||
|
d.w = td;
|
||||||
|
t.w = tt;
|
||||||
|
tm->year = d.d.year + 1980;
|
||||||
|
tm->month = d.d.month;
|
||||||
|
tm->day = d.d.day;
|
||||||
|
tm->hour = t.t.hour;
|
||||||
|
tm->min = t.t.min;
|
||||||
|
tm->sec = t.t.sec << 1;
|
||||||
|
if (tm->month > 11 || tm->hour > 23 || tm->min > 59 || tm->sec > 59) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* MS files attr
|
||||||
|
*/
|
||||||
|
uint8_t * ms_fattr(uint8_t *s, uint8_t attr) {
|
||||||
|
memset(s, '-', 7);
|
||||||
|
if (attr & AM_ARC)
|
||||||
|
s[0] = 'a';
|
||||||
|
if (attr & AM_DIR)
|
||||||
|
s[1] = 'd';
|
||||||
|
if (attr & AM_LFN)
|
||||||
|
s[2] = 'l';
|
||||||
|
if (attr & AM_VOL)
|
||||||
|
s[3] = 'v';
|
||||||
|
if (attr & AM_SYS)
|
||||||
|
s[4] = 's';
|
||||||
|
if (attr & AM_HID)
|
||||||
|
s[5] = 'h';
|
||||||
|
if (attr & AM_RDO)
|
||||||
|
s[6] = 'r';
|
||||||
|
s[7] = 0;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Linux files attr
|
||||||
|
*/
|
||||||
|
uint8_t * ux_fattr(uint8_t *s, uint8_t attr) {
|
||||||
|
memset(s, '-', 10);
|
||||||
|
if (attr & AM_DIR) {
|
||||||
|
s[0] = 'd';
|
||||||
|
// s[3] = 'x';
|
||||||
|
// s[6] = 'x';
|
||||||
|
// s[9] = 'x';
|
||||||
|
}
|
||||||
|
if (!(attr & AM_VOL)) {
|
||||||
|
// {
|
||||||
|
s[1] = 'r';
|
||||||
|
s[4] = 'r';
|
||||||
|
s[7] = 'r';
|
||||||
|
if (!(attr & AM_RDO)) {
|
||||||
|
s[2] = 'w';
|
||||||
|
s[5] = 'w';
|
||||||
|
s[8] = 'w';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if(attr & AM_VOL) s[3] = 'x';
|
||||||
|
if (!(attr & AM_SYS))
|
||||||
|
s[3] = 'x';
|
||||||
|
if (!(attr & AM_HID))
|
||||||
|
s[6] = 'x';
|
||||||
|
if (!(attr & AM_ARC))
|
||||||
|
s[9] = 'x';
|
||||||
|
s[10] = 0;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
FATFS * sd_mount(void) {
|
||||||
|
FATFS * m_fs = NULL;
|
||||||
|
// Инициализация I/O SDIOH
|
||||||
|
if (HalGetChipId() != CHIP_ID_8195AM) {
|
||||||
|
GPIOState[0] &= ~((1 << 8) - 1);
|
||||||
|
HAL_GPIO_PullCtrl(PA_0, PullUp); // D2
|
||||||
|
HAL_GPIO_PullCtrl(PA_1, PullUp); // D3
|
||||||
|
HAL_GPIO_PullCtrl(PA_2, PullUp); // CMD
|
||||||
|
HAL_GPIO_PullCtrl(PA_3, PullNone); // CLK
|
||||||
|
HAL_GPIO_PullCtrl(PA_4, PullUp); // D0
|
||||||
|
HAL_GPIO_PullCtrl(PA_5, PullUp); // D1
|
||||||
|
HAL_GPIO_PullCtrl(PA_6, PullDown); // SD card removed
|
||||||
|
HAL_GPIO_PullCtrl(PA_7, PullDown); // WP enable
|
||||||
|
vTaskDelay(1);
|
||||||
|
};
|
||||||
|
s8 ret = SD_Init();
|
||||||
|
if (ret < SD_NODISK) { // sdio_sd_init();
|
||||||
|
if (sdio_sd_status() >= 0 && sdio_status == SDIO_SD_OK) {
|
||||||
|
sdio_sd_getProtection();
|
||||||
|
#if CONFIG_DEBUG_LOG > 2
|
||||||
|
// чтение информации о SD карте
|
||||||
|
printf("\nSD CSD: ");
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
printf("%02x", SdioHostAdapter.Csd[i]);
|
||||||
|
u32 i = sdio_sd_getCapacity();
|
||||||
|
printf("\nSD Capacity: %d sectors (%d GB | %d MB | %d KB)\n", i,
|
||||||
|
i >> 21, i >> 11, i >> 1);
|
||||||
|
#endif
|
||||||
|
m_fs = (FATFS *) malloc(sizeof(FATFS));
|
||||||
|
if (m_fs != NULL) {
|
||||||
|
memset(m_fs, 0, sizeof(FATFS));
|
||||||
|
int drv_num = FATFS_RegisterDiskDriver(&SD_disk_Driver);
|
||||||
|
if (drv_num >= 0) {
|
||||||
|
*logical_drv = (char) drv_num + START_CHAR_DISK;
|
||||||
|
if (f_mount(m_fs, logical_drv, 1) == FR_OK) {
|
||||||
|
m_fs->drv = (BYTE) drv_num;
|
||||||
|
#if CONFIG_DEBUG_LOG > 3
|
||||||
|
printf("SD disk:%c mounted\n", logical_drv[0], m_fs);
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
#if CONFIG_DEBUG_LOG > 2
|
||||||
|
printf("SD disk mount failed!\n");
|
||||||
|
#endif
|
||||||
|
FATFS_UnRegisterDiskDriver(drv_num);
|
||||||
|
free(m_fs);
|
||||||
|
m_fs = NULL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
#if CONFIG_DEBUG_LOG > 2
|
||||||
|
printf("SD Register Disk Driver failed!\n");
|
||||||
|
#endif
|
||||||
|
free(m_fs);
|
||||||
|
m_fs = NULL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
#if CONFIG_DEBUG_LOG > 2
|
||||||
|
printf("Malloc failed!\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
#if CONFIG_DEBUG_LOG > 2
|
||||||
|
printf("SD Error (%d) get status!\n", sdio_status);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
#if CONFIG_DEBUG_LOG > 2
|
||||||
|
printf("SD Init Error (%d)!\n", ret);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return m_fs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sd_unmount(FATFS *m_fs) {
|
||||||
|
if (m_fs != NULL) {
|
||||||
|
#if CONFIG_DEBUG_LOG > 2
|
||||||
|
printf("unmount (%d)\n", f_mount(NULL, logical_drv, 1));
|
||||||
|
#else
|
||||||
|
f_mount(NULL, logical_drv, 1);
|
||||||
|
#endif
|
||||||
|
FATFS_UnRegisterDiskDriver(m_fs->drv);
|
||||||
|
free(m_fs);
|
||||||
|
}
|
||||||
|
pin_mode(PA_6, PullUp); // SD card removed
|
||||||
|
pin_mode(PA_7, PullUp); // WP enable
|
||||||
|
vTaskDelay(1);
|
||||||
|
SD_DeInit(); // sdio_sd_deinit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test SD */
|
||||||
|
LOCAL void fATHS(int argc, char *argv[]) {
|
||||||
|
// HalPinCtrlRtl8195A(UART0,0,0);
|
||||||
|
// HalPinCtrlRtl8195A(UART1,0,0);
|
||||||
|
#if CONFIG_DEBUG_LOG > 4
|
||||||
|
ConfigDebugErr = -1;
|
||||||
|
ConfigDebugInfo = -1;
|
||||||
|
ConfigDebugWarn = -1;
|
||||||
|
CfgSysDebugErr = -1;
|
||||||
|
CfgSysDebugInfo = -1;
|
||||||
|
CfgSysDebugWarn = -1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEBUG_AT_USER_LEVEL > 3
|
||||||
|
printf("ATHS: dir\n");
|
||||||
|
#endif
|
||||||
|
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;
|
||||||
|
printf("\ndir %s\n", sdir);
|
||||||
|
if (f_opendir(&dir, sdir) == FR_OK) {
|
||||||
|
while (f_readdir(&dir, &fno) == FR_OK && fno.fname[0] != 0) {
|
||||||
|
int srtlen = 0;
|
||||||
|
{
|
||||||
|
u8 buf[12];
|
||||||
|
srtlen += printf(ux_fattr(buf, fno.fattrib));
|
||||||
|
}
|
||||||
|
srtlen += printf(" 0");
|
||||||
|
if (fno.fattrib & AM_VOL)
|
||||||
|
printf(" volume");
|
||||||
|
else if (fno.fattrib & AM_SYS)
|
||||||
|
printf(" system");
|
||||||
|
else
|
||||||
|
printf(" none ");
|
||||||
|
srtlen += 7;
|
||||||
|
if (fno.fattrib & AM_HID)
|
||||||
|
printf(" hidden");
|
||||||
|
else
|
||||||
|
printf(" none ");
|
||||||
|
srtlen += 7;
|
||||||
|
srtlen += printf(" %d", fno.fsize);
|
||||||
|
while (srtlen < 37)
|
||||||
|
srtlen += printf(" ");
|
||||||
|
ms_ftime(fno.fdate, fno.ftime, &tm);
|
||||||
|
srtlen += printf(" %04d-%02d-%02d %02d:%02d:%02d ", tm.year,
|
||||||
|
tm.month, tm.day, tm.hour, tm.min, tm.sec);
|
||||||
|
if (*fno.lfname) {
|
||||||
|
srtlen += printf(fno.lfname);
|
||||||
|
//fnlen = fno.lfsize;
|
||||||
|
} else {
|
||||||
|
srtlen += printf(fno.fname);
|
||||||
|
//fnlen = fno.fsize;
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
};
|
||||||
|
printf("\n");
|
||||||
|
f_closedir(&dir);
|
||||||
|
} else
|
||||||
|
printf("FATFS: Open dir fail!\n");
|
||||||
|
free(pbuf);
|
||||||
|
if(sdir != logical_drv) free(sdir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sd_unmount(fs);
|
||||||
|
|
||||||
|
/*
|
||||||
|
} else
|
||||||
|
printf("FATFS: Malloc fail!\n");
|
||||||
|
f_mount(NULL, logical_drv, 1);
|
||||||
|
} else
|
||||||
|
printf("FATFS mount logical drive fail!\n");
|
||||||
|
FATFS_UnRegisterDiskDriver(drv_num);
|
||||||
|
} else
|
||||||
|
printf("Register disk driver to FATFS fail.\n");
|
||||||
|
free(m_fs);
|
||||||
|
} else
|
||||||
|
printf("FATFS: Malloc fail!\n");
|
||||||
|
} else
|
||||||
|
printf("SD Init fail!\n");
|
||||||
|
pin_mode(PA_6, PullUp); // SD card removed
|
||||||
|
pin_mode(PA_7, PullUp); // WP enable
|
||||||
|
vTaskDelay(5);
|
||||||
|
|
||||||
|
SD_DeInit(); // sdio_sd_deinit();
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MON_RAM_TAB_SECTION COMMAND_TABLE console_commands_spitst[] = {
|
||||||
|
{"ATHS", 0, fATHS, ": SD test"}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CONFIG_SDIO_HOST_EN
|
|
@ -323,7 +323,7 @@ MON_RAM_TAB_SECTION COMMAND_TABLE console_cmd_wifi_api[] = {
|
||||||
{"ATWT", 1, fATWT, "=<tx_power>: WiFi tx power: 0 - 100%, 1 - 75%, 2 - 50%, 3 - 25%, 4 - 12.5%"},
|
{"ATWT", 1, fATWT, "=<tx_power>: WiFi tx power: 0 - 100%, 1 - 75%, 2 - 50%, 3 - 25%, 4 - 12.5%"},
|
||||||
{"ATSF", 0, fATSF, ": Get TSF value"},
|
{"ATSF", 0, fATSF, ": Get TSF value"},
|
||||||
#endif
|
#endif
|
||||||
{"ATWP", 0, fATWP, "=[dtim]: 0 - WiFi ipc/lpc off, 1..10 - on + dtim"},
|
// {"ATWP", 0, fATWP, "=[dtim]: 0 - WiFi ipc/lpc off, 1..10 - on + dtim"},
|
||||||
{"ATSN", 0, fATSN, ": Scan networks"}
|
{"ATSN", 0, fATSN, ": Scan networks"}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue