]>
Commit | Line | Data |
---|---|---|
53668523 | 1 | /*-----------------------------------------------------------------------*/\r |
5630b930 | 2 | /* Low level disk I/O module SKELETON for FatFs (C)ChaN, 2019 */\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 | |
5630b930 L |
10 | #include "ff.h" /* Obtains integer types */\r |
11 | #include "diskio.h" /* Declarations of disk functions */\r | |
53668523 | 12 | \r |
7b78a5a2 | 13 | /* Definitions of physical drive number for each drive */\r |
70702af1 L |
14 | #define DEV_RAM 0 /* Example: Map Ramdisk to physical drive 0 */\r |
15 | #define DEV_MMC 1 /* Example: Map MMC/SD card to physical drive 1 */\r | |
16 | #define DEV_USB 2 /* Example: Map USB MSD to physical drive 2 */\r | |
53668523 L |
17 | \r |
18 | \r | |
19 | /*-----------------------------------------------------------------------*/\r | |
7b78a5a2 | 20 | /* Get Drive Status */\r |
53668523 L |
21 | /*-----------------------------------------------------------------------*/\r |
22 | \r | |
7b78a5a2 L |
23 | DSTATUS disk_status (\r |
24 | BYTE pdrv /* Physical drive nmuber to identify the drive */\r | |
53668523 L |
25 | )\r |
26 | {\r | |
27 | DSTATUS stat;\r | |
28 | int result;\r | |
29 | \r | |
30 | switch (pdrv) {\r | |
70702af1 L |
31 | case DEV_RAM :\r |
32 | result = RAM_disk_status();\r | |
53668523 L |
33 | \r |
34 | // translate the reslut code here\r | |
35 | \r | |
36 | return stat;\r | |
37 | \r | |
70702af1 | 38 | case DEV_MMC :\r |
7b78a5a2 | 39 | result = MMC_disk_status();\r |
53668523 L |
40 | \r |
41 | // translate the reslut code here\r | |
42 | \r | |
43 | return stat;\r | |
44 | \r | |
70702af1 | 45 | case DEV_USB :\r |
7b78a5a2 | 46 | result = USB_disk_status();\r |
53668523 L |
47 | \r |
48 | // translate the reslut code here\r | |
49 | \r | |
50 | return stat;\r | |
51 | }\r | |
52 | return STA_NOINIT;\r | |
53 | }\r | |
54 | \r | |
55 | \r | |
56 | \r | |
57 | /*-----------------------------------------------------------------------*/\r | |
7b78a5a2 | 58 | /* Inidialize a Drive */\r |
53668523 L |
59 | /*-----------------------------------------------------------------------*/\r |
60 | \r | |
7b78a5a2 L |
61 | DSTATUS disk_initialize (\r |
62 | BYTE pdrv /* Physical drive nmuber to identify the drive */\r | |
53668523 L |
63 | )\r |
64 | {\r | |
65 | DSTATUS stat;\r | |
66 | int result;\r | |
67 | \r | |
68 | switch (pdrv) {\r | |
70702af1 L |
69 | case DEV_RAM :\r |
70 | result = RAM_disk_initialize();\r | |
53668523 L |
71 | \r |
72 | // translate the reslut code here\r | |
73 | \r | |
74 | return stat;\r | |
75 | \r | |
70702af1 | 76 | case DEV_MMC :\r |
7b78a5a2 | 77 | result = MMC_disk_initialize();\r |
53668523 L |
78 | \r |
79 | // translate the reslut code here\r | |
80 | \r | |
81 | return stat;\r | |
82 | \r | |
70702af1 | 83 | case DEV_USB :\r |
7b78a5a2 | 84 | result = USB_disk_initialize();\r |
53668523 L |
85 | \r |
86 | // translate the reslut code here\r | |
87 | \r | |
88 | return stat;\r | |
89 | }\r | |
90 | return STA_NOINIT;\r | |
91 | }\r | |
92 | \r | |
93 | \r | |
94 | \r | |
95 | /*-----------------------------------------------------------------------*/\r | |
96 | /* Read Sector(s) */\r | |
97 | /*-----------------------------------------------------------------------*/\r | |
98 | \r | |
99 | DRESULT disk_read (\r | |
7b78a5a2 | 100 | BYTE pdrv, /* Physical drive nmuber to identify the drive */\r |
53668523 | 101 | BYTE *buff, /* Data buffer to store read data */\r |
5630b930 | 102 | LBA_t sector, /* Start sector in LBA */\r |
7b78a5a2 | 103 | UINT count /* Number of sectors to read */\r |
53668523 L |
104 | )\r |
105 | {\r | |
106 | DRESULT res;\r | |
107 | int result;\r | |
108 | \r | |
109 | switch (pdrv) {\r | |
70702af1 | 110 | case DEV_RAM :\r |
53668523 L |
111 | // translate the arguments here\r |
112 | \r | |
70702af1 | 113 | result = RAM_disk_read(buff, sector, count);\r |
53668523 L |
114 | \r |
115 | // translate the reslut code here\r | |
116 | \r | |
117 | return res;\r | |
118 | \r | |
70702af1 | 119 | case DEV_MMC :\r |
53668523 L |
120 | // translate the arguments here\r |
121 | \r | |
122 | result = MMC_disk_read(buff, sector, count);\r | |
123 | \r | |
124 | // translate the reslut code here\r | |
125 | \r | |
126 | return res;\r | |
127 | \r | |
70702af1 | 128 | case DEV_USB :\r |
53668523 L |
129 | // translate the arguments here\r |
130 | \r | |
131 | result = USB_disk_read(buff, sector, count);\r | |
132 | \r | |
133 | // translate the reslut code here\r | |
134 | \r | |
135 | return res;\r | |
136 | }\r | |
7b78a5a2 | 137 | \r |
53668523 L |
138 | return RES_PARERR;\r |
139 | }\r | |
140 | \r | |
141 | \r | |
142 | \r | |
143 | /*-----------------------------------------------------------------------*/\r | |
144 | /* Write Sector(s) */\r | |
145 | /*-----------------------------------------------------------------------*/\r | |
146 | \r | |
5630b930 L |
147 | #if FF_FS_READONLY == 0\r |
148 | \r | |
53668523 | 149 | DRESULT disk_write (\r |
7b78a5a2 | 150 | BYTE pdrv, /* Physical drive nmuber to identify the drive */\r |
53668523 | 151 | const BYTE *buff, /* Data to be written */\r |
5630b930 | 152 | LBA_t sector, /* Start sector in LBA */\r |
7b78a5a2 | 153 | UINT count /* Number of sectors to write */\r |
53668523 L |
154 | )\r |
155 | {\r | |
156 | DRESULT res;\r | |
157 | int result;\r | |
158 | \r | |
159 | switch (pdrv) {\r | |
70702af1 | 160 | case DEV_RAM :\r |
53668523 L |
161 | // translate the arguments here\r |
162 | \r | |
70702af1 | 163 | result = RAM_disk_write(buff, sector, count);\r |
53668523 L |
164 | \r |
165 | // translate the reslut code here\r | |
166 | \r | |
167 | return res;\r | |
168 | \r | |
70702af1 | 169 | case DEV_MMC :\r |
53668523 L |
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 | |
70702af1 | 178 | case DEV_USB :\r |
53668523 L |
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 | |
7b78a5a2 | 187 | \r |
53668523 L |
188 | return RES_PARERR;\r |
189 | }\r | |
70702af1 | 190 | \r |
5630b930 | 191 | #endif\r |
53668523 L |
192 | \r |
193 | \r | |
194 | /*-----------------------------------------------------------------------*/\r | |
195 | /* Miscellaneous Functions */\r | |
196 | /*-----------------------------------------------------------------------*/\r | |
197 | \r | |
53668523 L |
198 | DRESULT disk_ioctl (\r |
199 | BYTE pdrv, /* Physical drive nmuber (0..) */\r | |
200 | BYTE cmd, /* Control code */\r | |
201 | void *buff /* Buffer to send/receive control data */\r | |
202 | )\r | |
203 | {\r | |
204 | DRESULT res;\r | |
205 | int result;\r | |
206 | \r | |
207 | switch (pdrv) {\r | |
70702af1 | 208 | case DEV_RAM :\r |
53668523 | 209 | \r |
70702af1 | 210 | // Process of the command for the RAM drive\r |
53668523 L |
211 | \r |
212 | return res;\r | |
213 | \r | |
70702af1 | 214 | case DEV_MMC :\r |
53668523 | 215 | \r |
7b78a5a2 | 216 | // Process of the command for the MMC/SD card\r |
53668523 L |
217 | \r |
218 | return res;\r | |
219 | \r | |
70702af1 | 220 | case DEV_USB :\r |
53668523 | 221 | \r |
7b78a5a2 | 222 | // Process of the command the USB drive\r |
53668523 L |
223 | \r |
224 | return res;\r | |
225 | }\r | |
7b78a5a2 | 226 | \r |
53668523 L |
227 | return RES_PARERR;\r |
228 | }\r | |
70702af1 | 229 | \r |