fe3eddef9b241b805a2f71ad59bc6bef0bbc3538
[rpi-open-firmware.git] / arm_chainloader / drivers / fatfs / diskio.c
1 /*-----------------------------------------------------------------------*/
2 /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2016 */
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: Header file of existing USB MSD control module */
12 #include "atadrive.h" /* Example: Header file of existing ATA harddisk control module */
13 #include "sdcard.h" /* Example: Header file of existing MMC/SDC contorl module */
14
15 /* Definitions of physical drive number for each drive */
16 #define ATA 0 /* Example: Map ATA harddisk to physical drive 0 */
17 #define MMC 1 /* Example: Map MMC/SD card to physical drive 1 */
18 #define USB 2 /* Example: Map USB MSD to physical drive 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 DRESULT disk_write (
150 BYTE pdrv, /* Physical drive nmuber to identify the drive */
151 const BYTE *buff, /* Data to be written */
152 DWORD sector, /* Sector address in LBA */
153 UINT count /* Number of sectors to write */
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
188 return RES_PARERR;
189 }
190
191
192
193 /*-----------------------------------------------------------------------*/
194 /* Miscellaneous Functions */
195 /*-----------------------------------------------------------------------*/
196
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
209 // Process of the command for the ATA drive
210
211 return res;
212
213 case MMC :
214
215 // Process of the command for the MMC/SD card
216
217 return res;
218
219 case USB :
220
221 // Process of the command the USB drive
222
223 return res;
224 }
225
226 return RES_PARERR;
227 }
228
This page took 0.085866 seconds and 3 git commands to generate.