ahmed ahmed
/
samir2_alti_logger
dd
FileSystem/FatFileSystem/diskio.cpp@0:caecb0d1e7d3, 2015-04-08 (annotated)
- Committer:
- pfe
- Date:
- Wed Apr 08 08:27:55 2015 +0000
- Revision:
- 0:caecb0d1e7d3
ddd
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pfe | 0:caecb0d1e7d3 | 1 | /*-----------------------------------------------------------------------*/ |
pfe | 0:caecb0d1e7d3 | 2 | /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */ |
pfe | 0:caecb0d1e7d3 | 3 | /*-----------------------------------------------------------------------*/ |
pfe | 0:caecb0d1e7d3 | 4 | /* This is a stub disk I/O module that acts as front end of the existing */ |
pfe | 0:caecb0d1e7d3 | 5 | /* disk I/O modules and attach it to FatFs module with common interface. */ |
pfe | 0:caecb0d1e7d3 | 6 | /*-----------------------------------------------------------------------*/ |
pfe | 0:caecb0d1e7d3 | 7 | |
pfe | 0:caecb0d1e7d3 | 8 | #include "diskio.h" |
pfe | 0:caecb0d1e7d3 | 9 | #include <stdio.h> |
pfe | 0:caecb0d1e7d3 | 10 | #include <string.h> |
pfe | 0:caecb0d1e7d3 | 11 | #include "FATFileSystem.h" |
pfe | 0:caecb0d1e7d3 | 12 | |
pfe | 0:caecb0d1e7d3 | 13 | #include "mbed.h" |
pfe | 0:caecb0d1e7d3 | 14 | |
pfe | 0:caecb0d1e7d3 | 15 | DSTATUS disk_initialize ( |
pfe | 0:caecb0d1e7d3 | 16 | BYTE drv /* Physical drive nmuber (0..) */ |
pfe | 0:caecb0d1e7d3 | 17 | ) |
pfe | 0:caecb0d1e7d3 | 18 | { |
pfe | 0:caecb0d1e7d3 | 19 | FFSDEBUG("disk_initialize on drv [%d]\n", drv); |
pfe | 0:caecb0d1e7d3 | 20 | return (DSTATUS)FATFileSystem::_ffs[drv]->disk_initialize(); |
pfe | 0:caecb0d1e7d3 | 21 | } |
pfe | 0:caecb0d1e7d3 | 22 | |
pfe | 0:caecb0d1e7d3 | 23 | DSTATUS disk_status ( |
pfe | 0:caecb0d1e7d3 | 24 | BYTE drv /* Physical drive nmuber (0..) */ |
pfe | 0:caecb0d1e7d3 | 25 | ) |
pfe | 0:caecb0d1e7d3 | 26 | { |
pfe | 0:caecb0d1e7d3 | 27 | FFSDEBUG("disk_status on drv [%d]\n", drv); |
pfe | 0:caecb0d1e7d3 | 28 | return (DSTATUS)FATFileSystem::_ffs[drv]->disk_status(); |
pfe | 0:caecb0d1e7d3 | 29 | } |
pfe | 0:caecb0d1e7d3 | 30 | |
pfe | 0:caecb0d1e7d3 | 31 | DRESULT disk_read ( |
pfe | 0:caecb0d1e7d3 | 32 | BYTE drv, /* Physical drive nmuber (0..) */ |
pfe | 0:caecb0d1e7d3 | 33 | BYTE *buff, /* Data buffer to store read data */ |
pfe | 0:caecb0d1e7d3 | 34 | DWORD sector, /* Sector address (LBA) */ |
pfe | 0:caecb0d1e7d3 | 35 | BYTE count /* Number of sectors to read (1..255) */ |
pfe | 0:caecb0d1e7d3 | 36 | ) |
pfe | 0:caecb0d1e7d3 | 37 | { |
pfe | 0:caecb0d1e7d3 | 38 | FFSDEBUG("disk_read(sector %d, count %d) on drv [%d]\n", sector, count, drv); |
pfe | 0:caecb0d1e7d3 | 39 | for(DWORD s=sector; s<sector+count; s++) { |
pfe | 0:caecb0d1e7d3 | 40 | FFSDEBUG(" disk_read(sector %d)\n", s); |
pfe | 0:caecb0d1e7d3 | 41 | int res = FATFileSystem::_ffs[drv]->disk_read((char*)buff, s); |
pfe | 0:caecb0d1e7d3 | 42 | if(res) { |
pfe | 0:caecb0d1e7d3 | 43 | return RES_PARERR; |
pfe | 0:caecb0d1e7d3 | 44 | } |
pfe | 0:caecb0d1e7d3 | 45 | buff += 512; |
pfe | 0:caecb0d1e7d3 | 46 | } |
pfe | 0:caecb0d1e7d3 | 47 | return RES_OK; |
pfe | 0:caecb0d1e7d3 | 48 | } |
pfe | 0:caecb0d1e7d3 | 49 | |
pfe | 0:caecb0d1e7d3 | 50 | #if _READONLY == 0 |
pfe | 0:caecb0d1e7d3 | 51 | DRESULT disk_write ( |
pfe | 0:caecb0d1e7d3 | 52 | BYTE drv, /* Physical drive nmuber (0..) */ |
pfe | 0:caecb0d1e7d3 | 53 | const BYTE *buff, /* Data to be written */ |
pfe | 0:caecb0d1e7d3 | 54 | DWORD sector, /* Sector address (LBA) */ |
pfe | 0:caecb0d1e7d3 | 55 | BYTE count /* Number of sectors to write (1..255) */ |
pfe | 0:caecb0d1e7d3 | 56 | ) |
pfe | 0:caecb0d1e7d3 | 57 | { |
pfe | 0:caecb0d1e7d3 | 58 | FFSDEBUG("disk_write(sector %d, count %d) on drv [%d]\n", sector, count, drv); |
pfe | 0:caecb0d1e7d3 | 59 | for(DWORD s=sector; s<sector+count; s++) { |
pfe | 0:caecb0d1e7d3 | 60 | FFSDEBUG(" disk_write(sector %d)\n", s); |
pfe | 0:caecb0d1e7d3 | 61 | int res = FATFileSystem::_ffs[drv]->disk_write((char*)buff, s); |
pfe | 0:caecb0d1e7d3 | 62 | if(res) { |
pfe | 0:caecb0d1e7d3 | 63 | return RES_PARERR; |
pfe | 0:caecb0d1e7d3 | 64 | } |
pfe | 0:caecb0d1e7d3 | 65 | buff += 512; |
pfe | 0:caecb0d1e7d3 | 66 | } |
pfe | 0:caecb0d1e7d3 | 67 | return RES_OK; |
pfe | 0:caecb0d1e7d3 | 68 | } |
pfe | 0:caecb0d1e7d3 | 69 | #endif /* _READONLY */ |
pfe | 0:caecb0d1e7d3 | 70 | |
pfe | 0:caecb0d1e7d3 | 71 | DRESULT disk_ioctl ( |
pfe | 0:caecb0d1e7d3 | 72 | BYTE drv, /* Physical drive nmuber (0..) */ |
pfe | 0:caecb0d1e7d3 | 73 | BYTE ctrl, /* Control code */ |
pfe | 0:caecb0d1e7d3 | 74 | void *buff /* Buffer to send/receive control data */ |
pfe | 0:caecb0d1e7d3 | 75 | ) |
pfe | 0:caecb0d1e7d3 | 76 | { |
pfe | 0:caecb0d1e7d3 | 77 | FFSDEBUG("disk_ioctl(%d)\n", ctrl); |
pfe | 0:caecb0d1e7d3 | 78 | switch(ctrl) { |
pfe | 0:caecb0d1e7d3 | 79 | case CTRL_SYNC: |
pfe | 0:caecb0d1e7d3 | 80 | if(FATFileSystem::_ffs[drv] == NULL) { |
pfe | 0:caecb0d1e7d3 | 81 | return RES_NOTRDY; |
pfe | 0:caecb0d1e7d3 | 82 | } else if(FATFileSystem::_ffs[drv]->disk_sync()) { |
pfe | 0:caecb0d1e7d3 | 83 | return RES_ERROR; |
pfe | 0:caecb0d1e7d3 | 84 | } |
pfe | 0:caecb0d1e7d3 | 85 | return RES_OK; |
pfe | 0:caecb0d1e7d3 | 86 | case GET_SECTOR_COUNT: |
pfe | 0:caecb0d1e7d3 | 87 | if(FATFileSystem::_ffs[drv] == NULL) { |
pfe | 0:caecb0d1e7d3 | 88 | return RES_NOTRDY; |
pfe | 0:caecb0d1e7d3 | 89 | } else { |
pfe | 0:caecb0d1e7d3 | 90 | int res = FATFileSystem::_ffs[drv]->disk_sectors(); |
pfe | 0:caecb0d1e7d3 | 91 | if(res > 0) { |
pfe | 0:caecb0d1e7d3 | 92 | *((DWORD*)buff) = res; // minimum allowed |
pfe | 0:caecb0d1e7d3 | 93 | return RES_OK; |
pfe | 0:caecb0d1e7d3 | 94 | } else { |
pfe | 0:caecb0d1e7d3 | 95 | return RES_ERROR; |
pfe | 0:caecb0d1e7d3 | 96 | } |
pfe | 0:caecb0d1e7d3 | 97 | } |
pfe | 0:caecb0d1e7d3 | 98 | case GET_BLOCK_SIZE: |
pfe | 0:caecb0d1e7d3 | 99 | *((DWORD*)buff) = 1; // default when not known |
pfe | 0:caecb0d1e7d3 | 100 | return RES_OK; |
pfe | 0:caecb0d1e7d3 | 101 | |
pfe | 0:caecb0d1e7d3 | 102 | } |
pfe | 0:caecb0d1e7d3 | 103 | return RES_PARERR; |
pfe | 0:caecb0d1e7d3 | 104 | } |
pfe | 0:caecb0d1e7d3 | 105 |