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