Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

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