1 /*
2  * Copyright (C) 2015-2017 Alibaba Group Holding Limited
3  */
4 #include <string.h>
5 #include "fatfs_diskio.h"
6 #include "ff.h"
7 
8 #ifdef CONFIG_AOS_FATFS_SUPPORT_USB
9 #include "sd_disk/sd_disk.h"
10 #endif
11 
ff_disk_status(BYTE pdrv)12 DSTATUS ff_disk_status(BYTE pdrv)
13 {
14     switch (pdrv) {
15 #ifdef CONFIG_AOS_FATFS_SUPPORT_MMC
16     case DEV_MMC:
17         return SDMMC_status();
18 #endif
19 
20 #ifdef CONFIG_AOS_FATFS_SUPPORT_USB
21     case DEV_USB:
22         retutn USB_disk_status();
23 #endif
24 
25 #ifdef CONFIG_AOS_FATFS_SUPPORT_RAM
26     case DEV_RAM:
27         return RAM_disk_status();
28 #endif
29 
30     default:
31         break;
32     }
33     return STA_NOINIT;
34 }
35 
ff_disk_initialize(BYTE pdrv)36 DSTATUS ff_disk_initialize(BYTE pdrv)
37 {
38     switch (pdrv) {
39 #ifdef CONFIG_AOS_FATFS_SUPPORT_MMC
40     case DEV_MMC:
41         return SDMMC_initialize();
42 #endif
43 
44 #ifdef CONFIG_AOS_FATFS_SUPPORT_USB
45     case DEV_USB:
46         return USB_disk_initialize();
47 #endif
48 
49 #ifdef CONFIG_AOS_FATFS_SUPPORT_RAM
50     case DEV_RAM:
51         return RAM_disk_initialize();
52 #endif
53     default:
54         break;
55     }
56     return STA_NOINIT;
57 }
58 
ff_disk_read(BYTE pdrv,BYTE * buff,DWORD sector,UINT count)59 DRESULT ff_disk_read(BYTE pdrv, BYTE *buff, DWORD sector, UINT count)
60 {
61     switch (pdrv) {
62 #ifdef CONFIG_AOS_FATFS_SUPPORT_MMC
63     case DEV_MMC:
64         return SDMMC_read(buff, sector, count);
65 #endif
66 
67 #ifdef CONFIG_AOS_FATFS_SUPPORT_USB
68     case DEV_USB:
69         return USB_disk_read(buff, sector, count);
70 #endif
71 
72 #ifdef CONFIG_AOS_FATFS_SUPPORT_RAM
73     case DEV_RAM:
74         return RAM_disk_read(buff, sector, count);
75 #endif
76 
77     default:
78         break;
79     }
80     return RES_PARERR;
81 }
82 
ff_disk_write(BYTE pdrv,const BYTE * buff,DWORD sector,UINT count)83 DRESULT ff_disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count)
84 {
85     switch (pdrv) {
86 #ifdef CONFIG_AOS_FATFS_SUPPORT_MMC
87     case DEV_MMC:
88         return SDMMC_write((BYTE *)buff, sector, count);
89 #endif
90 
91 #ifdef CONFIG_AOS_FATFS_SUPPORT_USB
92     case DEV_USB:
93         return USB_disk_write(buff, sector, count);
94 #endif
95 
96 #ifdef CONFIG_AOS_FATFS_SUPPORT_RAM
97     case DEV_RAM:
98         return RAM_disk_write(buff, sector, count);
99 #endif
100 
101     default:
102         break;
103     }
104     return RES_PARERR;
105 }
106 
ff_disk_ioctl(BYTE pdrv,BYTE cmd,void * buff)107 DRESULT ff_disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
108 {
109     switch (pdrv) {
110 #ifdef CONFIG_AOS_FATFS_SUPPORT_MMC
111     case DEV_MMC:
112         return SDMMC_ioctl(cmd, buff);
113 #endif
114 
115 #ifdef CONFIG_AOS_FATFS_SUPPORT_USB
116     case DEV_USB:
117         return USB_disk_ioctl(cmd, buff);
118 #endif
119 
120 #ifdef CONFIG_AOS_FATFS_SUPPORT_RAM
121     case DEV_RAM:
122         return RAM_disk_ioctl(cmd, buff);
123 #endif
124 
125     default:
126         break;
127     }
128     return RES_PARERR;
129 }
130