6 #ifndef FS_DRIVE_SDIO_HPP_
7 #define FS_DRIVE_SDIO_HPP_
10 #include "RtosInclude.hpp"
12 class FsDriveSdio:
public FsDrive {
13 friend class RtosInterrupt;
43 uint32_t akeSeqError :1;
48 uint32_t readyForData :1;
49 SD_STATE currentState :4;
50 uint32_t eraseReset :1;
51 uint32_t cardEccDisabled :1;
52 uint32_t wpEraseSkip :1;
54 uint32_t csdOverwrite :1;
58 uint32_t cardEccFailed :1;
59 uint32_t illegalCommand :1;
60 uint32_t comCrcError :1;
62 uint32_t lockUnlockFailed :1;
63 uint32_t cardIsLocked :1;
64 uint32_t wpViolation :1;
65 uint32_t eraseParam :1;
66 uint32_t eraseSeqError :1;
67 uint32_t blockLenError :1;
68 uint32_t addressError :1;
69 uint32_t outOfRange :1;
74 const static uint32_t RESP_STATUS_ERROR_BITS = 0xFDFFE008;
82 uint8_t manufacturingDate[2];
83 uint8_t productSerial[4];
84 uint8_t productRevision;
85 uint8_t productName[5];
87 uint8_t manufacturerId;
91 }__attribute__((packed)) REG_CID;
99 uint8_t akeSeqError :1;
104 uint8_t readyForData :1;
105 uint8_t currentState :4;
107 uint8_t illegalCommand :1;
108 uint8_t comCrcError :1;
125 uint32_t fileFormat :2;
126 uint32_t tmpWriteProtect :1;
127 uint32_t permWriteProtect :1;
129 uint32_t fileFormatGrp :1;
131 uint32_t writeBlPartial :1;
132 uint32_t writeBlLen :4;
133 uint32_t r2wFactor :3;
135 uint32_t wpGrpEnable :1;
137 uint32_t wpGrpSize :7;
138 uint32_t sectorSize :7;
139 uint32_t eraseBlkEnable :1;
140 uint32_t cSizeMult :3;
141 uint32_t vddWrCurrMax :3;
142 uint32_t vddWrCurrMin :3;
143 uint32_t vddRdCurrMax :3;
144 uint32_t vddRdCurrMin :3;
147 uint32_t cSizeHi :10;
150 uint32_t readBlkMisalign :1;
151 uint32_t writeBlkMissalign :1;
152 uint32_t readBlPartial :1;
153 uint32_t readBlLen :4;
156 uint32_t tranSpeed :8;
160 uint32_t csdStruct :2;
166 uint32_t fileFormat :2;
167 uint32_t tmpWriteProtect :1;
168 uint32_t permWriteProtect :1;
170 uint32_t fileFormatGrp :1;
172 uint32_t writeBlPartial :1;
173 uint32_t writeBlLen :4;
174 uint32_t r2wFactor :3;
176 uint32_t wpGrpEnable :1;
178 uint32_t wpGrpSize :7;
179 uint32_t sectorSize :7;
180 uint32_t eraseBlkEnable :1;
182 uint32_t cSizeLo :16;
187 uint32_t readBlkMisalign :1;
188 uint32_t writeBlkMissalign :1;
189 uint32_t readBlPartial :1;
190 uint32_t readBlLen :4;
193 uint32_t tranSpeed :8;
197 uint32_t csdStruct :2;
201 }__attribute__((packed)) REG_CSD;
207 uint32_t commandSupportBits :2;
209 uint32_t extendedSecuritySupport :4;
211 uint32_t datBusWidthSupport :4;
212 uint32_t cprmSecuritySuppport :3;
213 uint32_t dataStatusAfterErases :1;
214 uint32_t sdSpecVersion :4;
215 uint32_t scrStructure :4;
220 }__attribute__((packed)) RESP_SCR;
224 const static uint32_t RESP_RCA_STATUS_ERROR_BITS = 0x0000E000;
239 static FsDriveSdio* sInstances[];
245 bool waitInterrupt(uint32_t* status);
246 bool sendCmd(uint32_t arg, uint32_t flags, RESPONSE response = RESP_NONE);
247 bool getState(SD_STATE* state);
248 void dataTransferConfig(uint32_t timer, uint32_t datalen, uint32_t ctrlFlags);
252 virtual bool readBlocks(FsDefs::SECTOR* buffer,
unsigned int blockNumber,
unsigned int blockCount);
253 virtual bool writeBlocks(
const FsDefs::SECTOR* buffer,
unsigned int blockNumber,
unsigned int blockCount);
256 const static uint32_t SDIO_STATIC_FLAGS = ((uint32_t) 0x000005FF);
258 const static uint8_t CMD_GO_IDLE_STATE = ((uint8_t) 0);
259 const static uint8_t CMD_SEND_OP_COND = ((uint8_t) 1);
260 const static uint8_t CMD_ALL_SEND_CID = ((uint8_t) 2);
261 const static uint8_t CMD_SET_REL_ADDR = ((uint8_t) 3);
262 const static uint8_t CMD_SET_DSR = ((uint8_t) 4);
263 const static uint8_t CMD_SDIO_SEN_OP_COND = ((uint8_t) 5);
264 const static uint8_t CMD_HS_SWITCH = ((uint8_t) 6);
265 const static uint8_t CMD_SEL_DESEL_CARD = ((uint8_t) 7);
266 const static uint8_t CMD_HS_SEND_EXT_CSD = ((uint8_t) 8);
267 const static uint8_t CMD_SEND_CSD = ((uint8_t) 9);
268 const static uint8_t CMD_SEND_CID = ((uint8_t) 10);
269 const static uint8_t CMD_READ_DAT_UNTIL_STOP = ((uint8_t) 11);
270 const static uint8_t CMD_STOP_TRANSMISSION = ((uint8_t) 12);
271 const static uint8_t CMD_SEND_STATUS = ((uint8_t) 13);
272 const static uint8_t CMD_HS_BUSTEST_READ = ((uint8_t) 14);
273 const static uint8_t CMD_GO_INACTIVE_STATE = ((uint8_t) 15);
274 const static uint8_t CMD_SET_BLOCKLEN = ((uint8_t) 16);
275 const static uint8_t CMD_READ_SINGLE_BLOCK = ((uint8_t) 17);
276 const static uint8_t CMD_READ_MULT_BLOCK = ((uint8_t) 18);
277 const static uint8_t CMD_HS_BUSTEST_WRITE = ((uint8_t) 19);
278 const static uint8_t CMD_WRITE_DAT_UNTIL_STOP = ((uint8_t) 20);
279 const static uint8_t CMD_SET_BLOCK_COUNT = ((uint8_t) 23);
280 const static uint8_t CMD_WRITE_SINGLE_BLOCK = ((uint8_t) 24);
281 const static uint8_t CMD_WRITE_MULT_BLOCK = ((uint8_t) 25);
282 const static uint8_t CMD_PROG_CID = ((uint8_t) 26);
283 const static uint8_t CMD_PROG_CSD = ((uint8_t) 27);
284 const static uint8_t CMD_SET_WRITE_PROT = ((uint8_t) 28);
285 const static uint8_t CMD_CLR_WRITE_PROT = ((uint8_t) 29);
286 const static uint8_t CMD_SEND_WRITE_PROT = ((uint8_t) 30);
287 const static uint8_t CMD_SD_ERASE_GRP_START = ((uint8_t) 32);
288 const static uint8_t CMD_SD_ERASE_GRP_END = ((uint8_t) 33);
289 const static uint8_t CMD_ERASE_GRP_START = ((uint8_t) 35);
290 const static uint8_t CMD_ERASE_GRP_END = ((uint8_t) 36);
291 const static uint8_t CMD_ERASE = ((uint8_t) 38);
292 const static uint8_t CMD_FAST_IO = ((uint8_t) 39);
293 const static uint8_t CMD_GO_IRQ_STATE = ((uint8_t) 40);
294 const static uint8_t CMD_LOCK_UNLOCK = ((uint8_t) 42);
295 const static uint8_t CMD_APP_CMD = ((uint8_t) 55);
296 const static uint8_t CMD_GEN_CMD = ((uint8_t) 56);
297 const static uint8_t CMD_NO_CMD = ((uint8_t) 64);
298 const static uint8_t CMD_APP_SD_SET_BUSWIDTH = ((uint8_t) 6);
299 const static uint8_t CMD_SD_APP_STAUS = ((uint8_t) 13);
300 const static uint8_t CMD_SD_APP_SEND_NUM_WRITE_BLOCKS = ((uint8_t) 22);
301 const static uint8_t CMD_SD_APP_OP_COND = ((uint8_t) 41);
302 const static uint8_t CMD_SD_APP_SET_CLR_CARD_DETECT = ((uint8_t) 42);
303 const static uint8_t CMD_SD_APP_SEND_SCR = ((uint8_t) 51);
304 const static uint8_t CMD_SDIO_RW_DIRECT = ((uint8_t) 52);
305 const static uint8_t CMD_SDIO_RW_EXTENDED = ((uint8_t) 53);
306 const static uint8_t CMDA_SD_APP_GET_MKB = ((uint8_t) 43);
307 const static uint8_t CMD_SD_APP_GET_MID = ((uint8_t) 44);
308 const static uint8_t CMD_SD_APP_SET_CER_RN1 = ((uint8_t) 45);
309 const static uint8_t CMD_SD_APP_GET_CER_RN2 = ((uint8_t) 46);
310 const static uint8_t CMD_SD_APP_SET_CER_RES2 = ((uint8_t) 47);
311 const static uint8_t CMD_SD_APP_GET_CER_RES1 = ((uint8_t) 48);
312 const static uint8_t CMD_SD_APP_SECURE_READ_MULTIPLE_BLOCK = ((uint8_t) 18);
313 const static uint8_t CMD_SD_APP_SECURE_WRITE_MULTIPLE_BLOCK = ((uint8_t) 25);
314 const static uint8_t CMD_SD_APP_SECURE_ERASE = ((uint8_t) 38);
315 const static uint8_t CMD_SD_APP_CHANGE_SECURE_AREA = ((uint8_t) 49);
316 const static uint8_t CMD_SD_APP_SECURE_WRITE_MKB = ((uint8_t) 48);
318 const static uint32_t SD_R6_GENERAL_UNKNOWN_ERROR = ((uint32_t) 0x00002000);
319 const static uint32_t SD_R6_ILLEGAL_CMD = ((uint32_t) 0x00004000);
320 const static uint32_t SD_R6_COM_CRC_FAILED = ((uint32_t) 0x00008000);
322 const static uint32_t SD_VOLTAGE_WINDOW_SD = ((uint32_t) 0x80100000);
323 const static uint32_t SD_HIGH_CAPACITY = ((uint32_t) 0x40000000);
324 const static uint32_t SD_STD_CAPACITY = ((uint32_t) 0x00000000);
325 const static uint32_t SD_CHECK_PATTERN = ((uint32_t) 0x000001AA);
327 const static uint32_t SD_MAX_VOLT_TRIAL = ((uint32_t) 0x0000FFFF);
328 const static uint32_t SD_ALLZERO = ((uint32_t) 0x00000000);
330 const static uint32_t SD_WIDE_BUS_SUPPORT = ((uint32_t) 0x00040000);
331 const static uint32_t SD_SINGLE_BUS_SUPPORT = ((uint32_t) 0x00010000);
332 const static uint32_t SD_CARD_LOCKED = ((uint32_t) 0x02000000);
334 const static uint32_t SD_DATATIMEOUT = ((uint32_t) 0xFFFFFFFF);
335 const static uint32_t SD_0TO7BITS = ((uint32_t) 0x000000FF);
336 const static uint32_t SD_8TO15BITS = ((uint32_t) 0x0000FF00);
337 const static uint32_t SD_16TO23BITS = ((uint32_t) 0x00FF0000);
338 const static uint32_t SD_24TO31BITS = ((uint32_t) 0xFF000000);
339 const static uint32_t SD_MAX_DATA_LENGTH = ((uint32_t) 0x01FFFFFF);
341 const static uint32_t SD_HALFFIFO = ((uint32_t) 0x00000008);
342 const static uint32_t SD_HALFFIFOBYTES = ((uint32_t) 0x00000020);
344 const static uint32_t SD_CCCC_LOCK_UNLOCK = ((uint32_t) 0x00000080);
345 const static uint32_t SD_CCCC_WRITE_PROT = ((uint32_t) 0x00000040);
346 const static uint32_t SD_CCCC_ERASE = ((uint32_t) 0x00000020);
348 const static uint32_t SDIO_SEND_IF_COND = ((uint32_t) 0x00000008);
350 const static uint32_t SDIO_IT_CCRCFAIL = 0x00000001;
351 const static uint32_t SDIO_IT_DCRCFAIL = 0x00000002;
352 const static uint32_t SDIO_IT_CTIMEOUT = 0x00000004;
353 const static uint32_t SDIO_IT_DTIMEOUT = 0x00000008;
354 const static uint32_t SDIO_IT_TXUNDERR = 0x00000010;
355 const static uint32_t SDIO_IT_RXOVERR = 0x00000020;
356 const static uint32_t SDIO_IT_CMDREND = 0x00000040;
357 const static uint32_t SDIO_IT_CMDSENT = 0x00000080;
358 const static uint32_t SDIO_IT_DATAEND = 0x00000100;
359 const static uint32_t SDIO_IT_STBITERR = 0x00000200;
360 const static uint32_t SDIO_IT_DBCKEND = 0x00000400;
361 const static uint32_t SDIO_IT_CMDACT = 0x00000800;
362 const static uint32_t SDIO_IT_TXACT = 0x00001000;
363 const static uint32_t SDIO_IT_RXACT = 0x00002000;
364 const static uint32_t SDIO_IT_TXFIFOHE = 0x00004000;
365 const static uint32_t SDIO_IT_RXFIFOHF = 0x00008000;
366 const static uint32_t SDIO_IT_TXFIFOF = 0x00010000;
367 const static uint32_t SDIO_IT_RXFIFOF = 0x00020000;
368 const static uint32_t SDIO_IT_TXFIFOE = 0x00040000;
369 const static uint32_t SDIO_IT_RXFIFOE = 0x00080000;
370 const static uint32_t SDIO_IT_TXDAVL = 0x00100000;
371 const static uint32_t SDIO_IT_RXDAVL = 0x00200000;
372 const static uint32_t SDIO_IT_SDIOIT = 0x00400000;
373 const static uint32_t SDIO_IT_CEATAEND = 0x00800000;