756a45a9b968862cd1d25979721531b68f8f1004
[bertos.git] / bertos / fs / fatfs / src / diskio.c
1 /*-----------------------------------------------------------------------*/
2 /* Low level disk I/O module skeleton for FatFs     (C)ChaN, 2007        */
3 /*-----------------------------------------------------------------------*/
4 /* This is a stub disk I/O module that acts as front end of the existing */
5 /* disk I/O modules and attach it to FatFs module with common interface. */
6 /*-----------------------------------------------------------------------*/
7
8 #include "diskio.h"
9
10 /*-----------------------------------------------------------------------*/
11 /* Correspondence between physical drive number and physical drive.      */
12
13 #define ATA             0
14 #define MMC             1
15 #define USB             2
16
17
18
19 /*-----------------------------------------------------------------------*/
20 /* Inidialize a Drive                                                    */
21
22 DSTATUS disk_initialize (
23         BYTE drv                                /* Physical drive nmuber (0..) */
24 )
25 {
26         DSTATUS stat;
27         int result;
28
29         switch (drv) {
30         case ATA :
31                 result = ATA_disk_initialize();
32                 // translate the reslut code here
33
34                 return stat;
35
36         case MMC :
37                 result = MMC_disk_initialize();
38                 // translate the reslut code here
39
40                 return stat;
41
42         case USB :
43                 result = USB_disk_initialize();
44                 // translate the reslut code here
45
46                 return stat;
47         }
48         return STA_NOINIT;
49 }
50
51
52
53 /*-----------------------------------------------------------------------*/
54 /* Return Disk Status                                                    */
55
56 DSTATUS disk_status (
57         BYTE drv                /* Physical drive nmuber (0..) */
58 )
59 {
60         DSTATUS stat;
61         int result;
62
63         switch (drv) {
64         case ATA :
65                 result = ATA_disk_status();
66                 // translate the reslut code here
67
68                 return stat;
69
70         case MMC :
71                 result = MMC_disk_status();
72                 // translate the reslut code here
73
74                 return stat;
75
76         case USB :
77                 result = USB_disk_status();
78                 // translate the reslut code here
79
80                 return stat;
81         }
82         return STA_NOINIT;
83 }
84
85
86
87 /*-----------------------------------------------------------------------*/
88 /* Read Sector(s)                                                        */
89
90 DRESULT disk_read (
91         BYTE drv,               /* Physical drive nmuber (0..) */
92         BYTE *buff,             /* Data buffer to store read data */
93         DWORD sector,   /* Sector address (LBA) */
94         BYTE count              /* Number of sectors to read (1..255) */
95 )
96 {
97         DRESULT res;
98         int result;
99
100         switch (drv) {
101         case ATA :
102                 result = ATA_disk_read(buff, sector, count);
103                 // translate the reslut code here
104
105                 return res;
106
107         case MMC :
108                 result = MMC_disk_read(buff, sector, count);
109                 // translate the reslut code here
110
111                 return res;
112
113         case USB :
114                 result = USB_disk_read(buff, sector, count);
115                 // translate the reslut code here
116
117                 return res;
118         }
119         return RES_PARERR;
120 }
121
122
123
124 /*-----------------------------------------------------------------------*/
125 /* Write Sector(s)                                                       */
126
127 #if _READONLY == 0
128 DRESULT disk_write (
129         BYTE drv,                       /* Physical drive nmuber (0..) */
130         const BYTE *buff,       /* Data to be written */
131         DWORD sector,           /* Sector address (LBA) */
132         BYTE count                      /* Number of sectors to write (1..255) */
133 )
134 {
135         DRESULT res;
136         int result;
137
138         switch (drv) {
139         case ATA :
140                 result = ATA_disk_write(buff, sector, count);
141                 // translate the reslut code here
142
143                 return res;
144
145         case MMC :
146                 result = MMC_disk_write(buff, sector, count);
147                 // translate the reslut code here
148
149                 return res;
150
151         case USB :
152                 result = USB_disk_write(buff, sector, count);
153                 // translate the reslut code here
154
155                 return res;
156         }
157         return RES_PARERR;
158 }
159 #endif /* _READONLY */
160
161
162
163 /*-----------------------------------------------------------------------*/
164 /* Miscellaneous Functions                                               */
165
166 DRESULT disk_ioctl (
167         BYTE drv,               /* Physical drive nmuber (0..) */
168         BYTE ctrl,              /* Control code */
169         void *buff              /* Buffer to send/receive control data */
170 )
171 {
172         DRESULT res;
173         int result;
174
175         switch (drv) {
176         case ATA :
177                 // pre-process here
178
179                 result = ATA_disk_ioctl(ctrl, buff);
180                 // post-process here
181
182                 return res;
183
184         case MMC :
185                 // pre-process here
186
187                 result = MMC_disk_ioctl(ctrl, buff);
188                 // post-process here
189
190                 return res;
191
192         case USB :
193                 // pre-process here
194
195                 result = USB_disk_ioctl(ctrl, buff);
196                 // post-process here
197
198                 return res;
199         }
200         return RES_PARERR;
201 }
202