1 | /*-----------------------------------------------------------------------*/
|
2 | /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 */
|
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 "diskio.h" /* FatFs lower layer API */
|
11 | #include "flash.h" /* Example: Header file of existing USB MSD control module */
|
12 |
|
13 |
|
14 | /* Definitions of physical drive number for each drive */
|
15 | #define ATA 0 /* Example: Map ATA harddisk to physical drive 0 */
|
16 | #define MMC 1 /* Example: Map MMC/SD card to physical drive 1 */
|
17 | #define USB 2 /* Example: Map USB MSD to physical drive 2 */
|
18 |
|
19 |
|
20 | /*-----------------------------------------------------------------------*/
|
21 | /* Get Drive Status */
|
22 | /*-----------------------------------------------------------------------*/
|
23 |
|
24 | DSTATUS disk_status (
|
25 | BYTE pdrv /* Physical drive nmuber to identify the drive */
|
26 | )
|
27 | {
|
28 | //DSTATUS stat;
|
29 |
|
30 | if(readStatus() & WIP_MASK) return RES_NOTRDY;
|
31 | else return RES_OK;
|
32 |
|
33 |
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 | /*-----------------------------------------------------------------------*/
|
39 | /* Inidialize a Drive */
|
40 | /*-----------------------------------------------------------------------*/
|
41 |
|
42 | DSTATUS disk_initialize (
|
43 | BYTE pdrv /* Physical drive nmuber to identify the drive */
|
44 | )
|
45 | {
|
46 | //DSTATUS stat;
|
47 |
|
48 | init_flash();
|
49 | return RES_OK;
|
50 |
|
51 | //return STA_NOINIT;
|
52 | }
|
53 |
|
54 |
|
55 |
|
56 | /*-----------------------------------------------------------------------*/
|
57 | /* Read Sector(s) */
|
58 | /*-----------------------------------------------------------------------*/
|
59 |
|
60 | DRESULT disk_read (
|
61 | BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
62 | BYTE *buff, /* Data buffer to store read data */
|
63 | DWORD sector, /* Sector address in LBA */
|
64 | UINT count /* Number of sectors to read */
|
65 | )
|
66 | {
|
67 |
|
68 | uint32_t Address = 0;
|
69 | //Sektoren addresse,
|
70 | //Sektor wurde mit 512 Byte definiert.
|
71 |
|
72 | Address = ((sector + 1) * 512) - 512;
|
73 |
|
74 | if(count == 1)
|
75 | {
|
76 | pageRead(buff,Address,256);
|
77 | buff += 256;
|
78 |
|
79 | pageRead(buff,Address+256,256);
|
80 |
|
81 | }
|
82 | else
|
83 | {
|
84 | do
|
85 | {
|
86 | //Start Addresse berechnen
|
87 | Address = ((sector + 1) * 512) - 512;
|
88 |
|
89 | pageRead(buff,Address,512);
|
90 |
|
91 | buff+=512;
|
92 | sector++;
|
93 | }while(count--);
|
94 | }
|
95 | return RES_OK;
|
96 |
|
97 | //return RES_PARERR;
|
98 | }
|
99 |
|
100 |
|
101 |
|
102 | /*-----------------------------------------------------------------------*/
|
103 | /* Write Sector(s) */
|
104 | /*-----------------------------------------------------------------------*/
|
105 |
|
106 | #if _USE_WRITE
|
107 | DRESULT disk_write (
|
108 | BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
109 | const BYTE *buff, /* Data to be written */
|
110 | DWORD sector, /* Sector address in LBA */
|
111 | UINT count /* Number of sectors to write */
|
112 | )
|
113 | {
|
114 |
|
115 |
|
116 |
|
117 | uint32_t Address = 0;
|
118 |
|
119 | //Sektoren addresse,
|
120 | //Sektor wurde mit 512 Byte definiert.
|
121 |
|
122 | //Startaddresse berechnen
|
123 |
|
124 |
|
125 | Address = ((sector + 1) * 512) - 512;
|
126 |
|
127 | if(count == 1)
|
128 | {
|
129 | pageWrite(buff,Address,256);
|
130 | buff += 256;
|
131 |
|
132 | pageWrite(buff,Address+256,256);
|
133 | }
|
134 | else
|
135 | {
|
136 | do
|
137 | {
|
138 | //Start Addresse berechnen
|
139 | Address = ((sector + 1) * 512) - 512;
|
140 |
|
141 | pageWrite(buff,Address,256);
|
142 | buff += 256;
|
143 |
|
144 | pageWrite(buff,Address+256,256);
|
145 |
|
146 | buff+=256;
|
147 | sector++;
|
148 | }while(count--);
|
149 | }
|
150 |
|
151 |
|
152 |
|
153 | while(readStatus() & WIP_MASK);
|
154 | return RES_OK;
|
155 |
|
156 | }
|
157 | #endif
|
158 |
|
159 |
|
160 | /*-----------------------------------------------------------------------*/
|
161 | /* Miscellaneous Functions */
|
162 | /*-----------------------------------------------------------------------*/
|
163 |
|
164 | #if _USE_IOCTL
|
165 | DRESULT disk_ioctl (
|
166 | BYTE pdrv, /* Physical drive nmuber (0..) */
|
167 | BYTE cmd, /* Control code */
|
168 | void *buff /* Buffer to send/receive control data */
|
169 | )
|
170 | {
|
171 |
|
172 |
|
173 | if( cmd == GET_SECTOR_COUNT )
|
174 | {
|
175 | *(DWORD*)buff = 2048;
|
176 | }
|
177 |
|
178 | if( cmd == GET_SECTOR_SIZE )
|
179 | {
|
180 | *(DWORD*)buff = 512;
|
181 | }
|
182 |
|
183 | if( cmd == GET_BLOCK_SIZE )
|
184 | {
|
185 | *(DWORD*)buff = 1;
|
186 | }
|
187 |
|
188 | return RES_OK;
|
189 |
|
190 | //return RES_PARERR;
|
191 | }
|
192 | #endif
|