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