2016-07-26 07:20:54 +08:00
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/* 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. */
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/*----------------------------------------------------------------------------/
|
|
|
|
/ FatFs - Generic FAT file system module R0.12a /
|
|
|
|
/-----------------------------------------------------------------------------/
|
|
|
|
/
|
|
|
|
/ Copyright (C) 2016, ChaN, all right reserved.
|
|
|
|
/
|
|
|
|
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
|
|
|
/ source and binary forms, with or without modification, are permitted provided
|
|
|
|
/ that the following condition is met:
|
|
|
|
|
|
|
|
/ 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
/ this condition and the following disclaimer.
|
|
|
|
/
|
|
|
|
/ This software is provided by the copyright holder and contributors "AS IS"
|
|
|
|
/ and any warranties related to this software are DISCLAIMED.
|
|
|
|
/ The copyright owner or contributors be NOT LIABLE for any damages caused
|
|
|
|
/ by use of this software.
|
|
|
|
/----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include <diskio.h> /* FatFs lower layer API */
|
2016-11-02 10:24:25 +08:00
|
|
|
#include <ffconf.h>
|
|
|
|
#include <disk_access.h>
|
2016-07-26 07:20:54 +08:00
|
|
|
|
2018-05-04 21:47:58 +08:00
|
|
|
static const char* const pdrv_str[] = {_VOLUME_STRS};
|
|
|
|
|
2016-07-26 07:20:54 +08:00
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/* Get Drive Status */
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
2016-08-17 05:41:44 +08:00
|
|
|
DSTATUS disk_status(BYTE pdrv)
|
2016-07-26 07:20:54 +08:00
|
|
|
{
|
2018-05-04 21:47:58 +08:00
|
|
|
__ASSERT(pdrv < ARRAY_SIZE(pdrv_str), "pdrv out-of-range\n");
|
|
|
|
|
|
|
|
if (disk_access_status(pdrv_str[pdrv]) != 0) {
|
2016-11-02 10:24:25 +08:00
|
|
|
return STA_NOINIT;
|
|
|
|
} else {
|
|
|
|
return RES_OK;
|
|
|
|
}
|
2016-07-26 07:20:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
2018-05-04 21:47:58 +08:00
|
|
|
/* Initialize a Drive */
|
2016-07-26 07:20:54 +08:00
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
2016-08-17 05:41:44 +08:00
|
|
|
DSTATUS disk_initialize(BYTE pdrv)
|
2016-07-26 07:20:54 +08:00
|
|
|
{
|
2018-05-04 21:47:58 +08:00
|
|
|
__ASSERT(pdrv < ARRAY_SIZE(pdrv_str), "pdrv out-of-range\n");
|
|
|
|
|
|
|
|
if (disk_access_init(pdrv_str[pdrv]) != 0) {
|
2016-11-02 10:24:25 +08:00
|
|
|
return STA_NOINIT;
|
|
|
|
} else {
|
|
|
|
return RES_OK;
|
|
|
|
}
|
2016-07-26 07:20:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/* Read Sector(s) */
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
2016-08-17 05:41:44 +08:00
|
|
|
DRESULT disk_read(BYTE pdrv, BYTE *buff, DWORD sector, UINT count)
|
2016-07-26 07:20:54 +08:00
|
|
|
{
|
2018-05-04 21:47:58 +08:00
|
|
|
__ASSERT(pdrv < ARRAY_SIZE(pdrv_str), "pdrv out-of-range\n");
|
|
|
|
|
|
|
|
if (disk_access_read(pdrv_str[pdrv], buff, sector, count) != 0) {
|
2016-11-02 10:24:25 +08:00
|
|
|
return RES_ERROR;
|
|
|
|
} else {
|
|
|
|
return RES_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-26 07:20:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/* Write Sector(s) */
|
|
|
|
/*-----------------------------------------------------------------------*/
|
2016-08-17 05:41:44 +08:00
|
|
|
DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count)
|
2016-07-26 07:20:54 +08:00
|
|
|
{
|
2018-05-04 21:47:58 +08:00
|
|
|
__ASSERT(pdrv < ARRAY_SIZE(pdrv_str), "pdrv out-of-range\n");
|
|
|
|
|
|
|
|
if(disk_access_write(pdrv_str[pdrv], buff, sector, count) != 0) {
|
2016-11-02 10:24:25 +08:00
|
|
|
return RES_ERROR;
|
|
|
|
} else {
|
|
|
|
return RES_OK;
|
|
|
|
}
|
2016-07-26 07:20:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/* Miscellaneous Functions */
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
2016-08-17 05:41:44 +08:00
|
|
|
DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
|
2016-07-26 07:20:54 +08:00
|
|
|
{
|
2016-11-02 10:24:25 +08:00
|
|
|
int ret = RES_OK;
|
|
|
|
|
2018-05-04 21:47:58 +08:00
|
|
|
__ASSERT(pdrv < ARRAY_SIZE(pdrv_str), "pdrv out-of-range\n");
|
|
|
|
|
2016-11-02 10:24:25 +08:00
|
|
|
switch (cmd) {
|
|
|
|
case CTRL_SYNC:
|
2018-05-04 21:47:58 +08:00
|
|
|
if(disk_access_ioctl(pdrv_str[pdrv],
|
|
|
|
DISK_IOCTL_CTRL_SYNC, buff) != 0) {
|
2016-11-02 10:24:25 +08:00
|
|
|
ret = RES_ERROR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GET_SECTOR_COUNT:
|
2018-05-04 21:47:58 +08:00
|
|
|
if (disk_access_ioctl(pdrv_str[pdrv],
|
|
|
|
DISK_IOCTL_GET_SECTOR_COUNT, buff) != 0) {
|
2016-11-02 10:24:25 +08:00
|
|
|
ret = RES_ERROR;
|
2018-01-01 01:15:16 +08:00
|
|
|
}
|
2016-11-02 10:24:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GET_BLOCK_SIZE:
|
2018-05-04 21:47:58 +08:00
|
|
|
if (disk_access_ioctl(pdrv_str[pdrv],
|
|
|
|
DISK_IOCTL_GET_ERASE_BLOCK_SZ, buff) != 0) {
|
2016-11-02 10:24:25 +08:00
|
|
|
ret = RES_ERROR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = RES_PARERR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
2016-07-26 07:20:54 +08:00
|
|
|
}
|