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