publication inutile mais obligée

Committer:
adrevong
Date:
Tue Jan 28 11:14:21 2020 +0000
Revision:
0:8b2a15992487

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
adrevong 0:8b2a15992487 1 /*-----------------------------------------------------------------------*/
adrevong 0:8b2a15992487 2 /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 */
adrevong 0:8b2a15992487 3 /*-----------------------------------------------------------------------*/
adrevong 0:8b2a15992487 4 /* If a working storage control module is available, it should be */
adrevong 0:8b2a15992487 5 /* attached to the FatFs via a glue function rather than modifying it. */
adrevong 0:8b2a15992487 6 /* This is an example of glue functions to attach various exsisting */
adrevong 0:8b2a15992487 7 /* storage control modules to the FatFs module with a defined API. */
adrevong 0:8b2a15992487 8 /*-----------------------------------------------------------------------*/
adrevong 0:8b2a15992487 9
adrevong 0:8b2a15992487 10 #include "diskio.h"
adrevong 0:8b2a15992487 11 #include "mbed_debug.h"
adrevong 0:8b2a15992487 12 #include "FATFileSystem.h"
adrevong 0:8b2a15992487 13
adrevong 0:8b2a15992487 14 using namespace mbed;
adrevong 0:8b2a15992487 15
adrevong 0:8b2a15992487 16 /*-----------------------------------------------------------------------*/
adrevong 0:8b2a15992487 17 /* Get Drive Status */
adrevong 0:8b2a15992487 18 /*-----------------------------------------------------------------------*/
adrevong 0:8b2a15992487 19
adrevong 0:8b2a15992487 20 DSTATUS disk_status (
adrevong 0:8b2a15992487 21 BYTE pdrv /* Physical drive nmuber to identify the drive */
adrevong 0:8b2a15992487 22 )
adrevong 0:8b2a15992487 23 {
adrevong 0:8b2a15992487 24 debug_if(FFS_DBG, "disk_status on pdrv [%d]\n", pdrv);
adrevong 0:8b2a15992487 25 return (DSTATUS)FATFileSystem::_ffs[pdrv]->disk_status();
adrevong 0:8b2a15992487 26 }
adrevong 0:8b2a15992487 27
adrevong 0:8b2a15992487 28 /*-----------------------------------------------------------------------*/
adrevong 0:8b2a15992487 29 /* Inidialize a Drive */
adrevong 0:8b2a15992487 30 /*-----------------------------------------------------------------------*/
adrevong 0:8b2a15992487 31
adrevong 0:8b2a15992487 32 DSTATUS disk_initialize (
adrevong 0:8b2a15992487 33 BYTE pdrv /* Physical drive nmuber to identify the drive */
adrevong 0:8b2a15992487 34 )
adrevong 0:8b2a15992487 35 {
adrevong 0:8b2a15992487 36 debug_if(FFS_DBG, "disk_initialize on pdrv [%d]\n", pdrv);
adrevong 0:8b2a15992487 37 return (DSTATUS)FATFileSystem::_ffs[pdrv]->disk_initialize();
adrevong 0:8b2a15992487 38 }
adrevong 0:8b2a15992487 39
adrevong 0:8b2a15992487 40 /*-----------------------------------------------------------------------*/
adrevong 0:8b2a15992487 41 /* Read Sector(s) */
adrevong 0:8b2a15992487 42 /*-----------------------------------------------------------------------*/
adrevong 0:8b2a15992487 43
adrevong 0:8b2a15992487 44 DRESULT disk_read (
adrevong 0:8b2a15992487 45 BYTE pdrv, /* Physical drive nmuber to identify the drive */
adrevong 0:8b2a15992487 46 BYTE* buff, /* Data buffer to store read data */
adrevong 0:8b2a15992487 47 DWORD sector, /* Sector address in LBA */
adrevong 0:8b2a15992487 48 UINT count /* Number of sectors to read */
adrevong 0:8b2a15992487 49 )
adrevong 0:8b2a15992487 50 {
adrevong 0:8b2a15992487 51 debug_if(FFS_DBG, "disk_read(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv);
adrevong 0:8b2a15992487 52 if (FATFileSystem::_ffs[pdrv]->disk_read((uint8_t*)buff, sector, count))
adrevong 0:8b2a15992487 53 return RES_PARERR;
adrevong 0:8b2a15992487 54 else
adrevong 0:8b2a15992487 55 return RES_OK;
adrevong 0:8b2a15992487 56 }
adrevong 0:8b2a15992487 57
adrevong 0:8b2a15992487 58 /*-----------------------------------------------------------------------*/
adrevong 0:8b2a15992487 59 /* Write Sector(s) */
adrevong 0:8b2a15992487 60 /*-----------------------------------------------------------------------*/
adrevong 0:8b2a15992487 61
adrevong 0:8b2a15992487 62 #if _USE_WRITE
adrevong 0:8b2a15992487 63 DRESULT disk_write (
adrevong 0:8b2a15992487 64 BYTE pdrv, /* Physical drive nmuber to identify the drive */
adrevong 0:8b2a15992487 65 const BYTE* buff, /* Data to be written */
adrevong 0:8b2a15992487 66 DWORD sector, /* Sector address in LBA */
adrevong 0:8b2a15992487 67 UINT count /* Number of sectors to write */
adrevong 0:8b2a15992487 68 )
adrevong 0:8b2a15992487 69 {
adrevong 0:8b2a15992487 70 debug_if(FFS_DBG, "disk_write(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv);
adrevong 0:8b2a15992487 71 if (FATFileSystem::_ffs[pdrv]->disk_write((uint8_t*)buff, sector, count))
adrevong 0:8b2a15992487 72 return RES_PARERR;
adrevong 0:8b2a15992487 73 else
adrevong 0:8b2a15992487 74 return RES_OK;
adrevong 0:8b2a15992487 75 }
adrevong 0:8b2a15992487 76 #endif
adrevong 0:8b2a15992487 77
adrevong 0:8b2a15992487 78 /*-----------------------------------------------------------------------*/
adrevong 0:8b2a15992487 79 /* Miscellaneous Functions */
adrevong 0:8b2a15992487 80 /*-----------------------------------------------------------------------*/
adrevong 0:8b2a15992487 81
adrevong 0:8b2a15992487 82 #if _USE_IOCTL
adrevong 0:8b2a15992487 83 DRESULT disk_ioctl (
adrevong 0:8b2a15992487 84 BYTE pdrv, /* Physical drive nmuber (0..) */
adrevong 0:8b2a15992487 85 BYTE cmd, /* Control code */
adrevong 0:8b2a15992487 86 void* buff /* Buffer to send/receive control data */
adrevong 0:8b2a15992487 87 )
adrevong 0:8b2a15992487 88 {
adrevong 0:8b2a15992487 89 debug_if(FFS_DBG, "disk_ioctl(%d)\n", cmd);
adrevong 0:8b2a15992487 90 switch(cmd) {
adrevong 0:8b2a15992487 91 case CTRL_SYNC:
adrevong 0:8b2a15992487 92 if(FATFileSystem::_ffs[pdrv] == NULL) {
adrevong 0:8b2a15992487 93 return RES_NOTRDY;
adrevong 0:8b2a15992487 94 } else if(FATFileSystem::_ffs[pdrv]->disk_sync()) {
adrevong 0:8b2a15992487 95 return RES_ERROR;
adrevong 0:8b2a15992487 96 }
adrevong 0:8b2a15992487 97 return RES_OK;
adrevong 0:8b2a15992487 98 case GET_SECTOR_COUNT:
adrevong 0:8b2a15992487 99 if(FATFileSystem::_ffs[pdrv] == NULL) {
adrevong 0:8b2a15992487 100 return RES_NOTRDY;
adrevong 0:8b2a15992487 101 } else {
adrevong 0:8b2a15992487 102 DWORD res = FATFileSystem::_ffs[pdrv]->disk_sectors();
adrevong 0:8b2a15992487 103 if(res > 0) {
adrevong 0:8b2a15992487 104 *((DWORD*)buff) = res; // minimum allowed
adrevong 0:8b2a15992487 105 return RES_OK;
adrevong 0:8b2a15992487 106 } else {
adrevong 0:8b2a15992487 107 return RES_ERROR;
adrevong 0:8b2a15992487 108 }
adrevong 0:8b2a15992487 109 }
adrevong 0:8b2a15992487 110 case GET_BLOCK_SIZE:
adrevong 0:8b2a15992487 111 *((DWORD*)buff) = 1; // default when not known
adrevong 0:8b2a15992487 112 return RES_OK;
adrevong 0:8b2a15992487 113
adrevong 0:8b2a15992487 114 }
adrevong 0:8b2a15992487 115 return RES_PARERR;
adrevong 0:8b2a15992487 116 }
adrevong 0:8b2a15992487 117 #endif