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