![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Dependencies: PinDetect TextLCD mbed mRotaryEncoder
FATFileSystem/Core/diskio.c@0:afb2650fb49a, 2012-02-13 (annotated)
- Committer:
- cicklaus
- Date:
- Mon Feb 13 02:11:20 2012 +0000
- Revision:
- 0:afb2650fb49a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cicklaus | 0:afb2650fb49a | 1 | /*-----------------------------------------------------------------------*/ |
cicklaus | 0:afb2650fb49a | 2 | /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */ |
cicklaus | 0:afb2650fb49a | 3 | /*-----------------------------------------------------------------------*/ |
cicklaus | 0:afb2650fb49a | 4 | /* This is a stub disk I/O module that acts as front end of the existing */ |
cicklaus | 0:afb2650fb49a | 5 | /* disk I/O modules and attach it to FatFs module with common interface. */ |
cicklaus | 0:afb2650fb49a | 6 | /*-----------------------------------------------------------------------*/ |
cicklaus | 0:afb2650fb49a | 7 | |
cicklaus | 0:afb2650fb49a | 8 | //Modified by Thomas Hamilton, Copyright 2010 |
cicklaus | 0:afb2650fb49a | 9 | |
cicklaus | 0:afb2650fb49a | 10 | #include "diskio.h" |
cicklaus | 0:afb2650fb49a | 11 | |
cicklaus | 0:afb2650fb49a | 12 | DSTATUS disk_initialize(BYTE drv) |
cicklaus | 0:afb2650fb49a | 13 | { |
cicklaus | 0:afb2650fb49a | 14 | if (FATFileSystem::DriveArray[drv]) |
cicklaus | 0:afb2650fb49a | 15 | { |
cicklaus | 0:afb2650fb49a | 16 | return (DSTATUS)FATFileSystem::DriveArray[drv]->disk_initialize(); |
cicklaus | 0:afb2650fb49a | 17 | } |
cicklaus | 0:afb2650fb49a | 18 | else |
cicklaus | 0:afb2650fb49a | 19 | { |
cicklaus | 0:afb2650fb49a | 20 | return STA_NOINIT; |
cicklaus | 0:afb2650fb49a | 21 | } |
cicklaus | 0:afb2650fb49a | 22 | } |
cicklaus | 0:afb2650fb49a | 23 | |
cicklaus | 0:afb2650fb49a | 24 | DSTATUS disk_status(BYTE drv) |
cicklaus | 0:afb2650fb49a | 25 | { |
cicklaus | 0:afb2650fb49a | 26 | if (FATFileSystem::DriveArray[drv]) |
cicklaus | 0:afb2650fb49a | 27 | { |
cicklaus | 0:afb2650fb49a | 28 | return (DSTATUS)FATFileSystem::DriveArray[drv]->disk_status(); |
cicklaus | 0:afb2650fb49a | 29 | } |
cicklaus | 0:afb2650fb49a | 30 | else |
cicklaus | 0:afb2650fb49a | 31 | { |
cicklaus | 0:afb2650fb49a | 32 | return STA_NOINIT; |
cicklaus | 0:afb2650fb49a | 33 | } |
cicklaus | 0:afb2650fb49a | 34 | } |
cicklaus | 0:afb2650fb49a | 35 | |
cicklaus | 0:afb2650fb49a | 36 | DRESULT disk_read(BYTE drv, BYTE* buff, DWORD sector, BYTE count) |
cicklaus | 0:afb2650fb49a | 37 | { |
cicklaus | 0:afb2650fb49a | 38 | if (FATFileSystem::DriveArray[drv]) |
cicklaus | 0:afb2650fb49a | 39 | { |
cicklaus | 0:afb2650fb49a | 40 | return (DRESULT)FATFileSystem::DriveArray[drv]->disk_read((unsigned char*)buff, |
cicklaus | 0:afb2650fb49a | 41 | (unsigned long)sector, (unsigned char)count); |
cicklaus | 0:afb2650fb49a | 42 | } |
cicklaus | 0:afb2650fb49a | 43 | else |
cicklaus | 0:afb2650fb49a | 44 | { |
cicklaus | 0:afb2650fb49a | 45 | return RES_NOTRDY; |
cicklaus | 0:afb2650fb49a | 46 | } |
cicklaus | 0:afb2650fb49a | 47 | } |
cicklaus | 0:afb2650fb49a | 48 | |
cicklaus | 0:afb2650fb49a | 49 | #if _READONLY == 0 |
cicklaus | 0:afb2650fb49a | 50 | DRESULT disk_write(BYTE drv, const BYTE* buff, DWORD sector, BYTE count) |
cicklaus | 0:afb2650fb49a | 51 | { |
cicklaus | 0:afb2650fb49a | 52 | if (FATFileSystem::DriveArray[drv]) |
cicklaus | 0:afb2650fb49a | 53 | { |
cicklaus | 0:afb2650fb49a | 54 | return (DRESULT)FATFileSystem::DriveArray[drv]->disk_write((const unsigned char*)buff, |
cicklaus | 0:afb2650fb49a | 55 | (unsigned long)sector, (unsigned char)count); |
cicklaus | 0:afb2650fb49a | 56 | } |
cicklaus | 0:afb2650fb49a | 57 | else |
cicklaus | 0:afb2650fb49a | 58 | { |
cicklaus | 0:afb2650fb49a | 59 | return RES_NOTRDY; |
cicklaus | 0:afb2650fb49a | 60 | } |
cicklaus | 0:afb2650fb49a | 61 | } |
cicklaus | 0:afb2650fb49a | 62 | #endif |
cicklaus | 0:afb2650fb49a | 63 | |
cicklaus | 0:afb2650fb49a | 64 | DRESULT disk_ioctl(BYTE drv, BYTE ctrl, void* buff) |
cicklaus | 0:afb2650fb49a | 65 | { |
cicklaus | 0:afb2650fb49a | 66 | switch (ctrl) |
cicklaus | 0:afb2650fb49a | 67 | { |
cicklaus | 0:afb2650fb49a | 68 | case CTRL_SYNC: |
cicklaus | 0:afb2650fb49a | 69 | if (FATFileSystem::DriveArray[drv]) |
cicklaus | 0:afb2650fb49a | 70 | { |
cicklaus | 0:afb2650fb49a | 71 | return (DRESULT)FATFileSystem::DriveArray[drv]->disk_sync(); |
cicklaus | 0:afb2650fb49a | 72 | } |
cicklaus | 0:afb2650fb49a | 73 | else |
cicklaus | 0:afb2650fb49a | 74 | { |
cicklaus | 0:afb2650fb49a | 75 | return RES_NOTRDY; |
cicklaus | 0:afb2650fb49a | 76 | } |
cicklaus | 0:afb2650fb49a | 77 | |
cicklaus | 0:afb2650fb49a | 78 | case GET_SECTOR_SIZE: |
cicklaus | 0:afb2650fb49a | 79 | if (FATFileSystem::DriveArray[drv]) |
cicklaus | 0:afb2650fb49a | 80 | { |
cicklaus | 0:afb2650fb49a | 81 | WORD Result = FATFileSystem::DriveArray[drv]->disk_sector_size(); |
cicklaus | 0:afb2650fb49a | 82 | if (Result > 0) |
cicklaus | 0:afb2650fb49a | 83 | { |
cicklaus | 0:afb2650fb49a | 84 | *((WORD*)buff) = Result; |
cicklaus | 0:afb2650fb49a | 85 | return RES_OK; |
cicklaus | 0:afb2650fb49a | 86 | } |
cicklaus | 0:afb2650fb49a | 87 | else |
cicklaus | 0:afb2650fb49a | 88 | { |
cicklaus | 0:afb2650fb49a | 89 | return RES_ERROR; |
cicklaus | 0:afb2650fb49a | 90 | } |
cicklaus | 0:afb2650fb49a | 91 | } |
cicklaus | 0:afb2650fb49a | 92 | else |
cicklaus | 0:afb2650fb49a | 93 | { |
cicklaus | 0:afb2650fb49a | 94 | return RES_NOTRDY; |
cicklaus | 0:afb2650fb49a | 95 | } |
cicklaus | 0:afb2650fb49a | 96 | |
cicklaus | 0:afb2650fb49a | 97 | case GET_SECTOR_COUNT: |
cicklaus | 0:afb2650fb49a | 98 | if (FATFileSystem::DriveArray[drv]) |
cicklaus | 0:afb2650fb49a | 99 | { |
cicklaus | 0:afb2650fb49a | 100 | DWORD Result = FATFileSystem::DriveArray[drv]->disk_sector_count(); |
cicklaus | 0:afb2650fb49a | 101 | if (Result > 0) |
cicklaus | 0:afb2650fb49a | 102 | { |
cicklaus | 0:afb2650fb49a | 103 | *((DWORD*)buff) = Result; |
cicklaus | 0:afb2650fb49a | 104 | return RES_OK; |
cicklaus | 0:afb2650fb49a | 105 | } |
cicklaus | 0:afb2650fb49a | 106 | else |
cicklaus | 0:afb2650fb49a | 107 | { |
cicklaus | 0:afb2650fb49a | 108 | return RES_ERROR; |
cicklaus | 0:afb2650fb49a | 109 | } |
cicklaus | 0:afb2650fb49a | 110 | } |
cicklaus | 0:afb2650fb49a | 111 | else |
cicklaus | 0:afb2650fb49a | 112 | { |
cicklaus | 0:afb2650fb49a | 113 | return RES_NOTRDY; |
cicklaus | 0:afb2650fb49a | 114 | } |
cicklaus | 0:afb2650fb49a | 115 | |
cicklaus | 0:afb2650fb49a | 116 | case GET_BLOCK_SIZE: |
cicklaus | 0:afb2650fb49a | 117 | if (FATFileSystem::DriveArray[drv]) |
cicklaus | 0:afb2650fb49a | 118 | { |
cicklaus | 0:afb2650fb49a | 119 | DWORD Result = FATFileSystem::DriveArray[drv]->disk_block_size(); |
cicklaus | 0:afb2650fb49a | 120 | if (Result > 0) |
cicklaus | 0:afb2650fb49a | 121 | { |
cicklaus | 0:afb2650fb49a | 122 | *((DWORD*)buff) = Result; |
cicklaus | 0:afb2650fb49a | 123 | return RES_OK; |
cicklaus | 0:afb2650fb49a | 124 | } |
cicklaus | 0:afb2650fb49a | 125 | else |
cicklaus | 0:afb2650fb49a | 126 | { |
cicklaus | 0:afb2650fb49a | 127 | return RES_ERROR; |
cicklaus | 0:afb2650fb49a | 128 | } |
cicklaus | 0:afb2650fb49a | 129 | } |
cicklaus | 0:afb2650fb49a | 130 | else |
cicklaus | 0:afb2650fb49a | 131 | { |
cicklaus | 0:afb2650fb49a | 132 | return RES_NOTRDY; |
cicklaus | 0:afb2650fb49a | 133 | } |
cicklaus | 0:afb2650fb49a | 134 | |
cicklaus | 0:afb2650fb49a | 135 | default: |
cicklaus | 0:afb2650fb49a | 136 | return RES_PARERR; |
cicklaus | 0:afb2650fb49a | 137 | } |
cicklaus | 0:afb2650fb49a | 138 | } |