comparison fatfs/diskio.c @ 49:ace431a0d0f5

Add SDIO code poached from STM. Use FatFS to read from SD card. LFN doesn't work reliably so it's disabled for now.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 03 Apr 2013 23:34:20 +1030
parents
children
comparison
equal deleted inserted replaced
48:2f336d212c74 49:ace431a0d0f5
1 /*-----------------------------------------------------------------------*/
2 /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2013 */
3 /*-----------------------------------------------------------------------*/
4 /* If a working storage control module is available, it should be */
5 /* attached to the FatFs via a glue function rather than modifying it. */
6 /* This is an example of glue functions to attach various exsisting */
7 /* storage control module to the FatFs module with a defined API. */
8 /*-----------------------------------------------------------------------*/
9
10 #include "diskio.h" /* FatFs lower layer API */
11 #include "usbdisk.h" /* Example: USB drive control */
12 #include "atadrive.h" /* Example: ATA drive control */
13 #include "sdcard.h" /* Example: MMC/SDC contorl */
14
15 /* Definitions of physical drive number for each media */
16 #define ATA 0
17 #define MMC 1
18 #define USB 2
19
20
21 /*-----------------------------------------------------------------------*/
22 /* Inidialize a Drive */
23 /*-----------------------------------------------------------------------*/
24
25 DSTATUS disk_initialize (
26 BYTE pdrv /* Physical drive nmuber (0..) */
27 )
28 {
29 DSTATUS stat;
30 int result;
31
32 switch (pdrv) {
33 case ATA :
34 result = ATA_disk_initialize();
35
36 // translate the reslut code here
37
38 return stat;
39
40 case MMC :
41 result = MMC_disk_initialize();
42
43 // translate the reslut code here
44
45 return stat;
46
47 case USB :
48 result = USB_disk_initialize();
49
50 // translate the reslut code here
51
52 return stat;
53 }
54 return STA_NOINIT;
55 }
56
57
58
59 /*-----------------------------------------------------------------------*/
60 /* Get Disk Status */
61 /*-----------------------------------------------------------------------*/
62
63 DSTATUS disk_status (
64 BYTE pdrv /* Physical drive nmuber (0..) */
65 )
66 {
67 DSTATUS stat;
68 int result;
69
70 switch (pdrv) {
71 case ATA :
72 result = ATA_disk_status();
73
74 // translate the reslut code here
75
76 return stat;
77
78 case MMC :
79 result = MMC_disk_status();
80
81 // translate the reslut code here
82
83 return stat;
84
85 case USB :
86 result = USB_disk_status();
87
88 // translate the reslut code here
89
90 return stat;
91 }
92 return STA_NOINIT;
93 }
94
95
96
97 /*-----------------------------------------------------------------------*/
98 /* Read Sector(s) */
99 /*-----------------------------------------------------------------------*/
100
101 DRESULT disk_read (
102 BYTE pdrv, /* Physical drive nmuber (0..) */
103 BYTE *buff, /* Data buffer to store read data */
104 DWORD sector, /* Sector address (LBA) */
105 BYTE count /* Number of sectors to read (1..128) */
106 )
107 {
108 DRESULT res;
109 int result;
110
111 switch (pdrv) {
112 case ATA :
113 // translate the arguments here
114
115 result = ATA_disk_read(buff, sector, count);
116
117 // translate the reslut code here
118
119 return res;
120
121 case MMC :
122 // translate the arguments here
123
124 result = MMC_disk_read(buff, sector, count);
125
126 // translate the reslut code here
127
128 return res;
129
130 case USB :
131 // translate the arguments here
132
133 result = USB_disk_read(buff, sector, count);
134
135 // translate the reslut code here
136
137 return res;
138 }
139 return RES_PARERR;
140 }
141
142
143
144 /*-----------------------------------------------------------------------*/
145 /* Write Sector(s) */
146 /*-----------------------------------------------------------------------*/
147
148 #if _USE_WRITE
149 DRESULT disk_write (
150 BYTE pdrv, /* Physical drive nmuber (0..) */
151 const BYTE *buff, /* Data to be written */
152 DWORD sector, /* Sector address (LBA) */
153 BYTE count /* Number of sectors to write (1..128) */
154 )
155 {
156 DRESULT res;
157 int result;
158
159 switch (pdrv) {
160 case ATA :
161 // translate the arguments here
162
163 result = ATA_disk_write(buff, sector, count);
164
165 // translate the reslut code here
166
167 return res;
168
169 case MMC :
170 // translate the arguments here
171
172 result = MMC_disk_write(buff, sector, count);
173
174 // translate the reslut code here
175
176 return res;
177
178 case USB :
179 // translate the arguments here
180
181 result = USB_disk_write(buff, sector, count);
182
183 // translate the reslut code here
184
185 return res;
186 }
187 return RES_PARERR;
188 }
189 #endif
190
191
192 /*-----------------------------------------------------------------------*/
193 /* Miscellaneous Functions */
194 /*-----------------------------------------------------------------------*/
195
196 #if _USE_IOCTL
197 DRESULT disk_ioctl (
198 BYTE pdrv, /* Physical drive nmuber (0..) */
199 BYTE cmd, /* Control code */
200 void *buff /* Buffer to send/receive control data */
201 )
202 {
203 DRESULT res;
204 int result;
205
206 switch (pdrv) {
207 case ATA :
208 // pre-process here
209
210 result = ATA_disk_ioctl(cmd, buff);
211
212 // post-process here
213
214 return res;
215
216 case MMC :
217 // pre-process here
218
219 result = MMC_disk_ioctl(cmd, buff);
220
221 // post-process here
222
223 return res;
224
225 case USB :
226 // pre-process here
227
228 result = USB_disk_ioctl(cmd, buff);
229
230 // post-process here
231
232 return res;
233 }
234 return RES_PARERR;
235 }
236 #endif