]> cloudbase.mooo.com Git - z180-stamp.git/blame - fatfs/src/diskio.c
enum command_ret_t --> typedef
[z180-stamp.git] / fatfs / src / diskio.c
CommitLineData
53668523
L
1/*-----------------------------------------------------------------------*/\r
2/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2013 */\r
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
7/* storage control module to the FatFs module with a defined API. */\r
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
15/* Definitions of physical drive number for each media */\r
16#define ATA 0\r
17#define MMC 1\r
18#define USB 2\r
19\r
20\r
21/*-----------------------------------------------------------------------*/\r
22/* Inidialize a Drive */\r
23/*-----------------------------------------------------------------------*/\r
24\r
25DSTATUS disk_initialize (\r
26 BYTE pdrv /* Physical drive nmuber (0..) */\r
27)\r
28{\r
29 DSTATUS stat;\r
30 int result;\r
31\r
32 switch (pdrv) {\r
33 case ATA :\r
34 result = ATA_disk_initialize();\r
35\r
36 // translate the reslut code here\r
37\r
38 return stat;\r
39\r
40 case MMC :\r
41 result = MMC_disk_initialize();\r
42\r
43 // translate the reslut code here\r
44\r
45 return stat;\r
46\r
47 case USB :\r
48 result = USB_disk_initialize();\r
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
60/* Get Disk Status */\r
61/*-----------------------------------------------------------------------*/\r
62\r
63DSTATUS disk_status (\r
64 BYTE pdrv /* Physical drive nmuber (0..) */\r
65)\r
66{\r
67 DSTATUS stat;\r
68 int result;\r
69\r
70 switch (pdrv) {\r
71 case ATA :\r
72 result = ATA_disk_status();\r
73\r
74 // translate the reslut code here\r
75\r
76 return stat;\r
77\r
78 case MMC :\r
79 result = MMC_disk_status();\r
80\r
81 // translate the reslut code here\r
82\r
83 return stat;\r
84\r
85 case USB :\r
86 result = USB_disk_status();\r
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
101DRESULT disk_read (\r
102 BYTE pdrv, /* Physical drive nmuber (0..) */\r
103 BYTE *buff, /* Data buffer to store read data */\r
104 DWORD sector, /* Sector address (LBA) */\r
105 UINT count /* Number of sectors to read (1..128) */\r
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
139 return RES_PARERR;\r
140}\r
141\r
142\r
143\r
144/*-----------------------------------------------------------------------*/\r
145/* Write Sector(s) */\r
146/*-----------------------------------------------------------------------*/\r
147\r
148#if _USE_WRITE\r
149DRESULT disk_write (\r
150 BYTE pdrv, /* Physical drive nmuber (0..) */\r
151 const BYTE *buff, /* Data to be written */\r
152 DWORD sector, /* Sector address (LBA) */\r
153 UINT count /* Number of sectors to write (1..128) */\r
154)\r
155{\r
156 DRESULT res;\r
157 int result;\r
158\r
159 switch (pdrv) {\r
160 case ATA :\r
161 // translate the arguments here\r
162\r
163 result = ATA_disk_write(buff, sector, count);\r
164\r
165 // translate the reslut code here\r
166\r
167 return res;\r
168\r
169 case MMC :\r
170 // translate the arguments here\r
171\r
172 result = MMC_disk_write(buff, sector, count);\r
173\r
174 // translate the reslut code here\r
175\r
176 return res;\r
177\r
178 case USB :\r
179 // translate the arguments here\r
180\r
181 result = USB_disk_write(buff, sector, count);\r
182\r
183 // translate the reslut code here\r
184\r
185 return res;\r
186 }\r
187 return RES_PARERR;\r
188}\r
189#endif\r
190\r
191\r
192/*-----------------------------------------------------------------------*/\r
193/* Miscellaneous Functions */\r
194/*-----------------------------------------------------------------------*/\r
195\r
196#if _USE_IOCTL\r
197DRESULT disk_ioctl (\r
198 BYTE pdrv, /* Physical drive nmuber (0..) */\r
199 BYTE cmd, /* Control code */\r
200 void *buff /* Buffer to send/receive control data */\r
201)\r
202{\r
203 DRESULT res;\r
204 int result;\r
205\r
206 switch (pdrv) {\r
207 case ATA :\r
208 // pre-process here\r
209\r
210 result = ATA_disk_ioctl(cmd, buff);\r
211\r
212 // post-process here\r
213\r
214 return res;\r
215\r
216 case MMC :\r
217 // pre-process here\r
218\r
219 result = MMC_disk_ioctl(cmd, buff);\r
220\r
221 // post-process here\r
222\r
223 return res;\r
224\r
225 case USB :\r
226 // pre-process here\r
227\r
228 result = USB_disk_ioctl(cmd, buff);\r
229\r
230 // post-process here\r
231\r
232 return res;\r
233 }\r
234 return RES_PARERR;\r
235}\r
236#endif\r