初始提交
This commit is contained in:
281
import/fatfs/src/diskio.c
Normal file
281
import/fatfs/src/diskio.c
Normal file
@@ -0,0 +1,281 @@
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2016 */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* If a working storage control module is available, it should be */
|
||||
/* attached to the FatFs via a glue function rather than modifying it. */
|
||||
/* This is an example of glue functions to attach various exsisting */
|
||||
/* storage control modules to the FatFs module with a defined API. */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#include "diskio.h" /* FatFs lower layer API */
|
||||
|
||||
#include "disk_hw.h" /* FatFs hw disk driver */
|
||||
|
||||
#include "os_types_api.h"
|
||||
#include "disk_hw.h"
|
||||
|
||||
/* Definitions of physical drive number for each drive */
|
||||
#define DEV_NOR_FLASH 0 /* Example: Map Ramdisk to physical drive 0 */
|
||||
#define DEV_NAND_FLASH 1 /* Example: Map MMC/SD card to physical drive 1 */
|
||||
#define DEV_SD_CARD 2 /* Example: Map USB MSD to physical drive 2 */
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Get Drive Status */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DSTATUS disk_status (
|
||||
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||
)
|
||||
{
|
||||
DSTATUS stat = 0;
|
||||
uint8_t result;
|
||||
|
||||
switch (pdrv) {
|
||||
case DEV_NOR_FLASH :
|
||||
result = nor_flash_status();
|
||||
|
||||
// translate the reslut code here
|
||||
if (result) {
|
||||
stat = STA_NODISK;
|
||||
}
|
||||
|
||||
return stat;
|
||||
|
||||
case DEV_NAND_FLASH :
|
||||
result = nand_flash_status();
|
||||
|
||||
// translate the reslut code here
|
||||
if (result) {
|
||||
stat = STA_NODISK;
|
||||
}
|
||||
|
||||
return stat;
|
||||
|
||||
case DEV_SD_CARD :
|
||||
result = sd_card_status();
|
||||
|
||||
// translate the reslut code here
|
||||
if (result) {
|
||||
stat = STA_NODISK;
|
||||
}
|
||||
|
||||
return stat;
|
||||
}
|
||||
return STA_NOINIT;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Inidialize a Drive */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DSTATUS disk_initialize (
|
||||
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||
)
|
||||
{
|
||||
DSTATUS stat = 0;
|
||||
uint8_t result;
|
||||
|
||||
switch (pdrv) {
|
||||
case DEV_NOR_FLASH :
|
||||
result = nor_flash_initialize();
|
||||
|
||||
// translate the reslut code here
|
||||
if (result) {
|
||||
stat = STA_NOINIT;
|
||||
}
|
||||
|
||||
return stat;
|
||||
|
||||
case DEV_NAND_FLASH :
|
||||
result = nand_flash_initialize();
|
||||
|
||||
// translate the reslut code here
|
||||
if (result) {
|
||||
stat = STA_NOINIT;
|
||||
}
|
||||
|
||||
return stat;
|
||||
|
||||
case DEV_SD_CARD :
|
||||
result = sd_card_initialize();
|
||||
|
||||
// translate the reslut code here
|
||||
if (result) {
|
||||
stat = STA_NOINIT;
|
||||
}
|
||||
|
||||
return stat;
|
||||
}
|
||||
return STA_NOINIT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Read Sector(s) */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DRESULT disk_read (
|
||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
BYTE *buff, /* Data buffer to store read data */
|
||||
DWORD sector, /* Start sector in LBA */
|
||||
UINT count /* Number of sectors to read */
|
||||
)
|
||||
{
|
||||
DRESULT res = RES_OK;
|
||||
uint8_t result;
|
||||
|
||||
switch (pdrv) {
|
||||
case DEV_NOR_FLASH :
|
||||
// translate the arguments here
|
||||
|
||||
result = nor_flash_read(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
if (result) {
|
||||
res = RES_PARERR;
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
case DEV_NAND_FLASH :
|
||||
// translate the arguments here
|
||||
|
||||
result = nand_flash_read(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
if (result) {
|
||||
res = RES_PARERR;
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
case DEV_SD_CARD :
|
||||
// translate the arguments here
|
||||
|
||||
result = sd_card_read(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
if (result) {
|
||||
res = RES_PARERR;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Write Sector(s) */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DRESULT disk_write (
|
||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
const BYTE *buff, /* Data to be written */
|
||||
DWORD sector, /* Start sector in LBA */
|
||||
UINT count /* Number of sectors to write */
|
||||
)
|
||||
{
|
||||
DRESULT res = RES_OK;
|
||||
uint8_t result;
|
||||
|
||||
switch (pdrv) {
|
||||
case DEV_NOR_FLASH :
|
||||
// translate the arguments here
|
||||
|
||||
result = nor_flash_write(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
if (result) {
|
||||
res = RES_PARERR;
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
case DEV_NAND_FLASH :
|
||||
// translate the arguments here
|
||||
|
||||
result = nand_flash_write(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
if (result) {
|
||||
res = RES_PARERR;
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
case DEV_SD_CARD :
|
||||
// translate the arguments here
|
||||
|
||||
result = sd_card_write(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
if (result) {
|
||||
res = RES_PARERR;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Miscellaneous Functions */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DRESULT disk_ioctl (
|
||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||
BYTE cmd, /* Control code */
|
||||
void *buff /* Buffer to send/receive control data */
|
||||
)
|
||||
{
|
||||
DRESULT res = RES_OK;
|
||||
int result;
|
||||
|
||||
switch (pdrv) {
|
||||
case DEV_NOR_FLASH :
|
||||
|
||||
// Process of the command for the RAM drive
|
||||
result = nor_flash_ioctl(cmd, buff);
|
||||
if (result) {
|
||||
res = RES_PARERR;
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
case DEV_NAND_FLASH :
|
||||
|
||||
// Process of the command for the MMC/SD card
|
||||
result = nand_flash_ioctl(cmd, buff);
|
||||
if (result) {
|
||||
res = RES_PARERR;
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
case DEV_SD_CARD :
|
||||
|
||||
// Process of the command the USB drive
|
||||
result = sd_card_ioctl(cmd, buff);
|
||||
if (result) {
|
||||
res = RES_PARERR;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
DWORD get_fattime (void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
6533
import/fatfs/src/ff.c
Normal file
6533
import/fatfs/src/ff.c
Normal file
File diff suppressed because it is too large
Load Diff
171
import/fatfs/src/ffsystem.c
Normal file
171
import/fatfs/src/ffsystem.c
Normal file
@@ -0,0 +1,171 @@
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Sample Code of OS Dependent Functions for FatFs */
|
||||
/* (C)ChaN, 2017 */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#include "ff.h"
|
||||
|
||||
|
||||
|
||||
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Allocate a memory block */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
void* ff_memalloc ( /* Returns pointer to the allocated memory block (null on not enough core) */
|
||||
UINT msize /* Number of bytes to allocate */
|
||||
)
|
||||
{
|
||||
return malloc(msize); /* Allocate a new memory block with POSIX API */
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Free a memory block */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
void ff_memfree (
|
||||
void* mblock /* Pointer to the memory block to free (nothing to do for null) */
|
||||
)
|
||||
{
|
||||
free(mblock); /* Free the memory block with POSIX API */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if FF_FS_REENTRANT /* Mutal exclusion */
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Create a Synchronization Object */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called in f_mount() function to create a new
|
||||
/ synchronization object for the volume, such as semaphore and mutex.
|
||||
/ When a 0 is returned, the f_mount() function fails with FR_INT_ERR.
|
||||
*/
|
||||
|
||||
//const osMutexDef_t Mutex[FF_VOLUMES]; /* CMSIS-RTOS */
|
||||
|
||||
|
||||
int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */
|
||||
BYTE vol, /* Corresponding volume (logical drive number) */
|
||||
FF_SYNC_t* sobj /* Pointer to return the created sync object */
|
||||
)
|
||||
{
|
||||
/* Win32 */
|
||||
*sobj = CreateMutex(NULL, FALSE, NULL);
|
||||
return (int)(*sobj != INVALID_HANDLE_VALUE);
|
||||
|
||||
/* uITRON */
|
||||
// T_CSEM csem = {TA_TPRI,1,1};
|
||||
// *sobj = acre_sem(&csem);
|
||||
// return (int)(*sobj > 0);
|
||||
|
||||
/* uC/OS-II */
|
||||
// OS_ERR err;
|
||||
// *sobj = OSMutexCreate(0, &err);
|
||||
// return (int)(err == OS_NO_ERR);
|
||||
|
||||
/* FreeRTOS */
|
||||
// *sobj = xSemaphoreCreateMutex();
|
||||
// return (int)(*sobj != NULL);
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// *sobj = osMutexCreate(Mutex + vol);
|
||||
// return (int)(*sobj != NULL);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Delete a Synchronization Object */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called in f_mount() function to delete a synchronization
|
||||
/ object that created with ff_cre_syncobj() function. When a 0 is returned,
|
||||
/ the f_mount() function fails with FR_INT_ERR.
|
||||
*/
|
||||
|
||||
int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error */
|
||||
FF_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
|
||||
)
|
||||
{
|
||||
/* Win32 */
|
||||
return (int)CloseHandle(sobj);
|
||||
|
||||
/* uITRON */
|
||||
// return (int)(del_sem(sobj) == E_OK);
|
||||
|
||||
/* uC/OS-II */
|
||||
// OS_ERR err;
|
||||
// OSMutexDel(sobj, OS_DEL_ALWAYS, &err);
|
||||
// return (int)(err == OS_NO_ERR);
|
||||
|
||||
/* FreeRTOS */
|
||||
// vSemaphoreDelete(sobj);
|
||||
// return 1;
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// return (int)(osMutexDelete(sobj) == osOK);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Request Grant to Access the Volume */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called on entering file functions to lock the volume.
|
||||
/ When a 0 is returned, the file function fails with FR_TIMEOUT.
|
||||
*/
|
||||
|
||||
int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */
|
||||
FF_SYNC_t sobj /* Sync object to wait */
|
||||
)
|
||||
{
|
||||
/* Win32 */
|
||||
return (int)(WaitForSingleObject(sobj, FF_FS_TIMEOUT) == WAIT_OBJECT_0);
|
||||
|
||||
/* uITRON */
|
||||
// return (int)(wai_sem(sobj) == E_OK);
|
||||
|
||||
/* uC/OS-II */
|
||||
// OS_ERR err;
|
||||
// OSMutexPend(sobj, FF_FS_TIMEOUT, &err));
|
||||
// return (int)(err == OS_NO_ERR);
|
||||
|
||||
/* FreeRTOS */
|
||||
// return (int)(xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE);
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// return (int)(osMutexWait(sobj, FF_FS_TIMEOUT) == osOK);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Release Grant to Access the Volume */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called on leaving file functions to unlock the volume.
|
||||
*/
|
||||
|
||||
void ff_rel_grant (
|
||||
FF_SYNC_t sobj /* Sync object to be signaled */
|
||||
)
|
||||
{
|
||||
/* Win32 */
|
||||
ReleaseMutex(sobj);
|
||||
|
||||
/* uITRON */
|
||||
// sig_sem(sobj);
|
||||
|
||||
/* uC/OS-II */
|
||||
// OSMutexPost(sobj);
|
||||
|
||||
/* FreeRTOS */
|
||||
// xSemaphoreGive(sobj);
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// osMutexRelease(sobj);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
15597
import/fatfs/src/ffunicode.c
Normal file
15597
import/fatfs/src/ffunicode.c
Normal file
File diff suppressed because it is too large
Load Diff
49
import/fatfs/src/hw/fs_nandflash.c
Normal file
49
import/fatfs/src/hw/fs_nandflash.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
|
||||
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
||||
|
||||
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
||||
be copied by any method or incorporated into another program without
|
||||
the express written consent of Aerospace C.Power. This Information or any portion
|
||||
thereof remains the property of Aerospace C.Power. The Information contained herein
|
||||
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
||||
liability for its use in any way and conveys no license or title under
|
||||
any patent or copyright and makes no representation or warranty that this
|
||||
Information is free from patent or copyright infringement.
|
||||
|
||||
****************************************************************************/
|
||||
#include "os_types_api.h"
|
||||
#include "iot_errno_api.h"
|
||||
|
||||
uint8_t nand_flash_status()
|
||||
{
|
||||
uint8_t ret = ERR_FAIL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t nand_flash_initialize()
|
||||
{
|
||||
return ERR_FAIL;
|
||||
}
|
||||
|
||||
uint8_t nand_flash_read(uint8_t *buff, uint32_t sector, uint32_t count)
|
||||
{
|
||||
uint8_t ret = ERR_FAIL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t nand_flash_write(const uint8_t *buff, uint32_t sector, uint32_t count)
|
||||
{
|
||||
uint8_t ret = ERR_FAIL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t nand_flash_ioctl(uint8_t cmd, void *buff)
|
||||
{
|
||||
uint8_t ret = ERR_FAIL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
130
import/fatfs/src/hw/fs_norflash.c
Normal file
130
import/fatfs/src/hw/fs_norflash.c
Normal file
@@ -0,0 +1,130 @@
|
||||
/****************************************************************************
|
||||
|
||||
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
||||
|
||||
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
||||
be copied by any method or incorporated into another program without
|
||||
the express written consent of Aerospace C.Power. This Information or any portion
|
||||
thereof remains the property of Aerospace C.Power. The Information contained herein
|
||||
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
||||
liability for its use in any way and conveys no license or title under
|
||||
any patent or copyright and makes no representation or warranty that this
|
||||
Information is free from patent or copyright infringement.
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
#include "os_types_api.h"
|
||||
#include "iot_errno_api.h"
|
||||
#include "flash.h"
|
||||
#include "diskio.h"
|
||||
|
||||
uint32_t g_fs_size = 0;
|
||||
|
||||
extern void flash_wait_status();
|
||||
uint8_t nor_flash_status()
|
||||
{
|
||||
uint8_t ret = ERR_OK;
|
||||
flash_wait_status();
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t nor_flash_initialize()
|
||||
{
|
||||
uint32_t size = 0;
|
||||
flash_init(1);
|
||||
|
||||
size = flash_get_dev_size();
|
||||
|
||||
if (FLASH_1M == size) {
|
||||
// 1M flash un-support fatfs
|
||||
return ERR_FAIL;
|
||||
} else {
|
||||
g_fs_size = 1;
|
||||
for(uint8_t i = 1; i < size; i++) {
|
||||
g_fs_size *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
uint8_t nor_flash_read(uint8_t *buff, uint32_t sector, uint32_t count)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (g_fs_size < 1) {
|
||||
return ERR_FAIL;
|
||||
}
|
||||
|
||||
offset = g_fs_size * 1024 * 1024 / 2;
|
||||
|
||||
ret = flash_read
|
||||
(buff, offset + sector * 4096, count * 4096, MOD_SFC_READ_QUAD_IO_FAST);
|
||||
if (ret) {
|
||||
ret = ERR_FAIL;
|
||||
} else {
|
||||
ret = ERR_OK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t nor_flash_write(const uint8_t *buff, uint32_t sector, uint32_t count)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (g_fs_size < 1) {
|
||||
return ERR_FAIL;
|
||||
}
|
||||
|
||||
offset = g_fs_size * 1024 * 1024 / 2;
|
||||
flash_write_param_t param = {0};
|
||||
param.read_mode = MOD_SFC_READ_QUAD_IO_FAST;
|
||||
param.write_mode = MOD_SFC_PROG_QUAD;
|
||||
param.is_erase = 1;
|
||||
param.sw_mode = MOD_SW_MODE_DIS;
|
||||
|
||||
ret = flash_write(buff, offset + sector * 4096, count * 4096, ¶m);
|
||||
|
||||
if (ret) {
|
||||
ret = ERR_FAIL;
|
||||
} else {
|
||||
ret = ERR_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t nor_flash_ioctl(uint8_t cmd, void *buff)
|
||||
{
|
||||
uint8_t ret = ERR_OK;
|
||||
uint32_t sector_count = 0;
|
||||
|
||||
if (g_fs_size < 1) {
|
||||
return ERR_FAIL;
|
||||
}
|
||||
|
||||
sector_count = g_fs_size * 1024 * 1024 / 2;
|
||||
sector_count = sector_count / 4096;
|
||||
|
||||
switch(cmd) {
|
||||
case CTRL_SYNC:
|
||||
break;
|
||||
case GET_SECTOR_COUNT:
|
||||
*(uint32_t *)buff = sector_count;
|
||||
break;
|
||||
case GET_SECTOR_SIZE:
|
||||
*(uint16_t *)buff = 4096;
|
||||
break;
|
||||
case GET_BLOCK_SIZE:
|
||||
*(uint32_t *)buff = 8;
|
||||
break;
|
||||
default:
|
||||
ret = ERR_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
99
import/fatfs/src/hw/fs_sdcard.c
Normal file
99
import/fatfs/src/hw/fs_sdcard.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/****************************************************************************
|
||||
|
||||
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
||||
|
||||
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
||||
be copied by any method or incorporated into another program without
|
||||
the express written consent of Aerospace C.Power. This Information or any portion
|
||||
thereof remains the property of Aerospace C.Power. The Information contained herein
|
||||
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
||||
liability for its use in any way and conveys no license or title under
|
||||
any patent or copyright and makes no representation or warranty that this
|
||||
Information is free from patent or copyright infringement.
|
||||
|
||||
****************************************************************************/
|
||||
#include "os_types_api.h"
|
||||
#include "iot_errno_api.h"
|
||||
#include "sd_card.h"
|
||||
#include "iot_spi_api.h"
|
||||
#include "diskio.h"
|
||||
#include "iot_board_api.h"
|
||||
|
||||
uint8_t sd_card_status()
|
||||
{
|
||||
uint8_t buf[16];
|
||||
|
||||
return sd_get_dev_id(buf);
|
||||
}
|
||||
|
||||
uint8_t sd_card_initialize()
|
||||
{
|
||||
#define SD_SPI_PORT DEVICE_SPI2_MASTER
|
||||
sd_spi_info_t info;
|
||||
|
||||
info.dev = SD_SPI_PORT;
|
||||
info.gpio_clk = iot_board_get_gpio(GPIO_SPI_FLASH_CLK);
|
||||
info.gpio_cs = iot_board_get_gpio(GPIO_SPI_FLASH_CS);
|
||||
info.gpio_miso = iot_board_get_gpio(GPIO_SPI_FLASH_MISO);
|
||||
info.gpio_mosi = iot_board_get_gpio(GPIO_SPI_FLASH_MOSI);
|
||||
|
||||
if ((GPIO_NO_VALID == info.gpio_clk) ||
|
||||
(GPIO_NO_VALID == info.gpio_cs) ||
|
||||
(GPIO_NO_VALID == info.gpio_miso) ||
|
||||
(GPIO_NO_VALID == info.gpio_mosi) ) {
|
||||
return RES_ERROR;
|
||||
}
|
||||
|
||||
int ret = sd_init(&info);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t sd_card_read(uint8_t *buff, uint32_t sector, uint32_t count)
|
||||
{
|
||||
int ret = sd_read_disk(buff, sector, count);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t sd_card_write(const uint8_t *buff, uint32_t sector, uint32_t count)
|
||||
{
|
||||
int ret = sd_write_disk((uint8_t *)buff, sector, count);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t sd_card_ioctl(uint8_t cmd, void *buff)
|
||||
{
|
||||
uint8_t ret = RES_OK;
|
||||
|
||||
uint32_t sector_count = sd_get_capacity();
|
||||
|
||||
if (0 == sector_count) {
|
||||
return ERR_FAIL;
|
||||
}
|
||||
|
||||
switch(cmd) {
|
||||
case CTRL_SYNC:
|
||||
if (0 == sd_sync()) {
|
||||
ret = RES_OK;
|
||||
}
|
||||
|
||||
break;
|
||||
case GET_SECTOR_COUNT:
|
||||
*(uint32_t *)buff = sector_count;
|
||||
|
||||
break;
|
||||
case GET_SECTOR_SIZE:
|
||||
*(uint16_t *)buff = 512;
|
||||
|
||||
break;
|
||||
case GET_BLOCK_SIZE:
|
||||
*(uint32_t *)buff = 8;
|
||||
|
||||
break;
|
||||
default:
|
||||
ret = RES_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user