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