]>
Commit | Line | Data |
---|---|---|
1 | /*-----------------------------------------------------------------------*/\r | |
2 | /* Low level disk I/O module SKELETON for FatFs (C)ChaN, 2019 */\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 modules to the FatFs module with a defined API. */\r | |
8 | /*-----------------------------------------------------------------------*/\r | |
9 | \r | |
10 | #include "ff.h" /* Obtains integer types */\r | |
11 | #include "diskio.h" /* Declarations of disk functions */\r | |
12 | \r | |
13 | /* Definitions of physical drive number for each drive */\r | |
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 | |
17 | \r | |
18 | \r | |
19 | /*-----------------------------------------------------------------------*/\r | |
20 | /* Get Drive Status */\r | |
21 | /*-----------------------------------------------------------------------*/\r | |
22 | \r | |
23 | DSTATUS disk_status (\r | |
24 | BYTE pdrv /* Physical drive nmuber to identify the drive */\r | |
25 | )\r | |
26 | {\r | |
27 | DSTATUS stat;\r | |
28 | int result;\r | |
29 | \r | |
30 | switch (pdrv) {\r | |
31 | case DEV_RAM :\r | |
32 | result = RAM_disk_status();\r | |
33 | \r | |
34 | // translate the reslut code here\r | |
35 | \r | |
36 | return stat;\r | |
37 | \r | |
38 | case DEV_MMC :\r | |
39 | result = MMC_disk_status();\r | |
40 | \r | |
41 | // translate the reslut code here\r | |
42 | \r | |
43 | return stat;\r | |
44 | \r | |
45 | case DEV_USB :\r | |
46 | result = USB_disk_status();\r | |
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 | |
58 | /* Inidialize a Drive */\r | |
59 | /*-----------------------------------------------------------------------*/\r | |
60 | \r | |
61 | DSTATUS disk_initialize (\r | |
62 | BYTE pdrv /* Physical drive nmuber to identify the drive */\r | |
63 | )\r | |
64 | {\r | |
65 | DSTATUS stat;\r | |
66 | int result;\r | |
67 | \r | |
68 | switch (pdrv) {\r | |
69 | case DEV_RAM :\r | |
70 | result = RAM_disk_initialize();\r | |
71 | \r | |
72 | // translate the reslut code here\r | |
73 | \r | |
74 | return stat;\r | |
75 | \r | |
76 | case DEV_MMC :\r | |
77 | result = MMC_disk_initialize();\r | |
78 | \r | |
79 | // translate the reslut code here\r | |
80 | \r | |
81 | return stat;\r | |
82 | \r | |
83 | case DEV_USB :\r | |
84 | result = USB_disk_initialize();\r | |
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 | |
100 | BYTE pdrv, /* Physical drive nmuber to identify the drive */\r | |
101 | BYTE *buff, /* Data buffer to store read data */\r | |
102 | LBA_t sector, /* Start sector in LBA */\r | |
103 | UINT count /* Number of sectors to read */\r | |
104 | )\r | |
105 | {\r | |
106 | DRESULT res;\r | |
107 | int result;\r | |
108 | \r | |
109 | switch (pdrv) {\r | |
110 | case DEV_RAM :\r | |
111 | // translate the arguments here\r | |
112 | \r | |
113 | result = RAM_disk_read(buff, sector, count);\r | |
114 | \r | |
115 | // translate the reslut code here\r | |
116 | \r | |
117 | return res;\r | |
118 | \r | |
119 | case DEV_MMC :\r | |
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 | |
128 | case DEV_USB :\r | |
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 | |
137 | \r | |
138 | return RES_PARERR;\r | |
139 | }\r | |
140 | \r | |
141 | \r | |
142 | \r | |
143 | /*-----------------------------------------------------------------------*/\r | |
144 | /* Write Sector(s) */\r | |
145 | /*-----------------------------------------------------------------------*/\r | |
146 | \r | |
147 | #if FF_FS_READONLY == 0\r | |
148 | \r | |
149 | DRESULT disk_write (\r | |
150 | BYTE pdrv, /* Physical drive nmuber to identify the drive */\r | |
151 | const BYTE *buff, /* Data to be written */\r | |
152 | LBA_t sector, /* Start sector in LBA */\r | |
153 | UINT count /* Number of sectors to write */\r | |
154 | )\r | |
155 | {\r | |
156 | DRESULT res;\r | |
157 | int result;\r | |
158 | \r | |
159 | switch (pdrv) {\r | |
160 | case DEV_RAM :\r | |
161 | // translate the arguments here\r | |
162 | \r | |
163 | result = RAM_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 DEV_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 DEV_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 | \r | |
188 | return RES_PARERR;\r | |
189 | }\r | |
190 | \r | |
191 | #endif\r | |
192 | \r | |
193 | \r | |
194 | /*-----------------------------------------------------------------------*/\r | |
195 | /* Miscellaneous Functions */\r | |
196 | /*-----------------------------------------------------------------------*/\r | |
197 | \r | |
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 | |
208 | case DEV_RAM :\r | |
209 | \r | |
210 | // Process of the command for the RAM drive\r | |
211 | \r | |
212 | return res;\r | |
213 | \r | |
214 | case DEV_MMC :\r | |
215 | \r | |
216 | // Process of the command for the MMC/SD card\r | |
217 | \r | |
218 | return res;\r | |
219 | \r | |
220 | case DEV_USB :\r | |
221 | \r | |
222 | // Process of the command the USB drive\r | |
223 | \r | |
224 | return res;\r | |
225 | }\r | |
226 | \r | |
227 | return RES_PARERR;\r | |
228 | }\r | |
229 | \r |