NetBurner 3.1
sdio.h
1 /*NB_REVISION*/
2 
3 /*NB_COPYRIGHT*/
4 
5 #ifndef _SDIO_H_
6 #define _SDIO_H_
7 
8 /*
9  ******************************************************************************
10  *
11  * Reference
12  * SDIO Simplified Specification, SD Specification, Part E1, Version 2.00
13  * February 8, 2007, Technical Committee, SD Card Association
14  *
15  * Physical Layer Simplified Specification, SD Specification, Part 1,
16  * Version 2.00, September 25, 2006, Technical Committee
17  * SD Card Association
18  *
19  ******************************************************************************
20  */
21 /*
22  ******************************************************************************
23  *
24  * Debugging
25  *
26  * Needs to be uncommented to support these features
27  *
28  ******************************************************************************
29  */
30 /* Library debugging switch */
31 /* #define SDIO_DEBUG ( 1 ) */
32 
33 /*
34  ******************************************************************************
35  *
36  * Runtime Library Definitions
37  *
38  ******************************************************************************
39  */
40 /* Bus type */
41 #define SDIO_SPI_BUS (1)
42 
43 /*
44  ******************************************************************************
45  *
46  * Command and Response Definitions
47  *
48  ******************************************************************************
49  */
50 /* Command size in bytes */
51 #define SDIO_COMMAND_SIZE (6)
52 
53 /* Block size */
54 #define SDIO_BLOCK_SIZE (512)
55 
56 /* Direction */
57 #define SDIO_CARD_TO_HOST (0x0)
58 #define SDIO_HOST_TO_CARD (0x1)
59 
60 /* Command Index */
61 #define SDIO_GO_IDLE (0x00)
62 #define SDIO_IO_SEND_OPERATIONAL_CONDITION (0x05)
63 #define SDIO_IO_RW_DIRECT (0x34)
64 #define SDIO_IO_RW_EXTENDED (0x35)
65 #define SDIO_CRC_ON_OFF (0x3B)
66 
67 /* Read/Write */
68 #define SDIO_READ (0)
69 #define SDIO_WRITE (1)
70 
71 /* Function Number (I/O card dependent) */
72 #define SDIO_FUNCTION_0 (0)
73 #define SDIO_FUNCTION_1 (1)
74 
75 /* Read after write */
76 #define SDIO_READ_OR_WRITE_ONLY (0)
77 #define SDIO_RAW (1)
78 
79 /* Block Mode */
80 #define SDIO_BYTE_MODE (0)
81 #define SDIO_BLOCK_MODE (1)
82 
83 /* OP code */
84 #define SDIO_FIXED_ADDRESS (FALSE)
85 #define SDIO_INCREMENTING_ADDRESS (TRUE)
86 
87 /* Block size */
88 #define SDIO_BLOCK_SIZE_NONE (0)
89 
90 /*
91  ******************************************************************************
92  *
93  * Common I/O Area (CIA) register addresses (Function 0)
94  *
95  ******************************************************************************
96  */
97 /* Card Common Control Registers (CCCR) */
98 #define SDIO_CIA_CCCR_CCCR_SDIO_REVISION (0x00000)
99 #define SDIO_CIA_CCCR_SD_SPEC_REVISION (0x00001)
100 #define SDIO_CIA_CCCR_IO_ENABLE (0x00002)
101 #define SDIO_CIA_CCCR_IO_READY (0x00003)
102 #define SDIO_CIA_CCCR_INTERRUPT_ENABLE (0x00004)
103 #define SDIO_CIA_CCCR_INTERRUPT_PENDING (0x00005)
104 #define SDIO_CIA_CCCR_IO_ABORT (0x00006)
105 #define SDIO_CIA_CCCR_BUS_INTERFACE_CONTROL (0x00007)
106 #define SDIO_CIA_CCCR_CARD_CAPABILITY (0x00008)
107 #define SDIO_CIA_CCCR_COMMON_CIS_POINTER_LSB (0x00009)
108 #define SDIO_CIA_CCCR_COMMON_CIS_POINTER_CSB (0x0000A)
109 #define SDIO_CIA_CCCR_COMMON_CIS_POINTER_MSB (0x0000B)
110 #define SDIO_CIA_CCCR_BUS_SUSPEND (0x0000C)
111 #define SDIO_CIA_CCCR_FUNCTION_SELECT (0x0000D)
112 #define SDIO_CIA_CCCR_EXEC_FLAGS (0x0000E)
113 #define SDIO_CIA_CCCR_READY_FLAGS (0x0000F)
114 #define SDIO_CIA_CCCR_FN0_BLOCK_SIZE_LSB (0x00010)
115 #define SDIO_CIA_CCCR_FN0_BLOCK_SIZE_MSB (0x00011)
116 #define SDIO_CIA_CCCR_POWER_CONTROL (0x00012)
117 
118 /*
119  ******************************************************************************
120  *
121  * Common I/O Area (CIA) register addresses (Function 1)
122  *
123  ******************************************************************************
124  */
125 #define SDIO_CIA_CCCR_FN1_BLOCK_SIZE_LSB (0x00110)
126 #define SDIO_CIA_CCCR_FN1_BLOCK_SIZE_MSB (0x00111)
127 /*
128  ******************************************************************************
129  *
130  * Runtime Library Enumerations and Structures
131  *
132  ******************************************************************************
133  */
134 /*
135  SDIO Bus type
136  Sdio - SD 4-bit mode
137  SdioSpiMode - SPI mode
138 
139  */
140 typedef enum _SdioBusType
141 {
142  Sdio,
143  SdioSpiMode
144 
145 } SdioBusType;
146 
147 /*
148  SDIO Response type
149  R4 - IO_SEND_OP_COND Response
150  R5 - IO_RW_DIRECT Response
151 
152  */
153 typedef enum _SdioResponseType
154 {
155  R4,
156  R5
157 
158 } SdioResponseType;
159 
160 /*
161  Bus token for user
162  butType - Bus type in use for this token
163 
164  *** SPI ***
165  spiSetting - Shared SPI setting
166  spiConnectTimeout - Bus allocation timeout period in ticks
167  spiResponseTimeout - Command response timeout period in ticks
168  idleByteCount - Bytes required to idle bus
169  idleFillValue - Data to transmit that idles the bus
170 
171  *** SDIO Future ***
172 
173  */
174 typedef struct _SdioBusToken
175 {
176  SdioBusType busType;
177  int spiSetting;
178  uint32_t spiConnectTimeout;
179  uint32_t spiResponseTimeout;
180  ssize_t idleByteCount;
181  uint16_t idleFillValue;
182 
183 } __attribute__((packed)) SdioBusToken;
184 
185 /*
186  ******************************************************************************
187  *
188  * Command and Response Structures
189  *
190  ******************************************************************************
191  */
192 /*
193  Start bit, direction and command
194  startBit - Start bit, always 0
195  direction - 0 card to host, 1 host to card
196  index - Command index
197 
198  */
199 typedef struct _CommandIndex
200 {
201  uint8_t startBit : 1;
202  uint8_t direction : 1;
203  uint8_t index : 6;
204 
205 } __attribute__((packed)) CommandIndex;
206 
207 /*
208  CRC and end
209  crc7 - 7 bits of CRC data
210  endBit - End bit, always 1
211 
212  */
213 typedef struct _Crc
214 {
215  uint8_t crc7 : 7;
216  uint8_t endBit : 1;
217 
218 } __attribute__((packed)) Crc;
219 
220 /*
221  Response Flags IAW SD Physical Specification
222  comCrcError - 1 yes else 0
223  illegalCommand - 1 yes else 0
224  ioCurrentState - Current I/O state
225  error - Unknown error
226  rfu - RFU always 0
227  functionNumberError - 1 yes else 0
228  outOfRange - 1 yes else 0
229 
230  */
231 typedef struct _ResponseFlags
232 {
233  uint8_t comCrcError : 1;
234  uint8_t illegalCommand : 1;
235  uint8_t ioCurrentState : 2;
236  uint8_t error : 1;
237  uint8_t rfu : 1;
238  uint8_t functionNumberError : 1;
239  uint8_t outOfRange : 1;
240 
241 } __attribute__((packed)) ResponseFlags;
242 
243 /*
244  Go idle state (CMD0)
245  commandIndex - Start, direction and command index
246  stuff - MBZ
247  crc - CRC and end bit
248 
249  */
250 typedef struct _GoIdleStateCommand_CMD0
251 {
252  CommandIndex commandIndex;
253  uint8_t stuff[4];
254  Crc crc;
255 
256 } __attribute__((packed)) GoIdleStateCommand_CMD0;
257 
258 /*
259  I/O Send Operational Condition
260  crc - CRC and end bit
261  ocr - Operations condition register
262  stuffBits - MBZ
263  commandIndex - Start, direction and command index
264 
265  */
266 typedef struct _IoSendOpCondCommand_CMD5
267 {
268  CommandIndex commandIndex;
269  uint8_t stuffBits;
270  uint8_t ocr[3];
271  Crc crc;
272 
273 } __attribute__((packed)) IoSendOpCondCommand_CMD5;
274 
275 /*
276  CRC toggle command (CMD59)
277  crc - CRC and end bit
278  ocr - Operations condition register
279  stuffBits - MBZ
280  commandIndex - Start, direction and command index
281 
282  */
283 typedef struct _CrcOnOffCommand_CMD59
284 {
285  CommandIndex commandIndex;
286  uint8_t stuffBits;
287  uint8_t ocr[3];
288  Crc crc;
289 
290 } __attribute__((packed)) CrcOnOffCommand_CMD59;
291 
292 /*
293  Modified R1 IAW SD Physical Specification
294  start - Start bit, always 0
295  parameterError - 1 yes else 0
296  rfu - RFU always 0
297  functionNumberError - 1 yes else 0
298  comCrcError - 1 yes else 0
299  illegalCommand - 1 yes else 0
300  rfu_1 - RFU always 0
301  idleState - Idle state, always 1
302  */
303 typedef struct _ModifiedR1
304 {
305  uint8_t startBit : 1;
306  uint8_t parameterError : 1;
307  uint8_t rfu : 1;
308  uint8_t functionNumberError : 1;
309  uint8_t comCrcError : 1;
310  uint8_t illegalCommand : 1;
311  uint8_t rfu_1 : 1;
312  uint8_t idleState : 1;
313 
314 } __attribute__((packed)) ModifiedR1;
315 
316 /*
317  Operate bit, number of I/O functions and memory present
318  operate - 1 card is ready to operate
319  ioFunctions - Number of I/O functions supported
320  memoryPresent - 1 SD memory else 0
321  stuffBits - MBZ
322 
323  */
324 typedef struct _NumberIoFunctions
325 {
326  uint8_t operate : 1;
327  uint8_t ioFunctions : 3;
328  uint8_t memoryPresent : 1;
329  uint8_t stuffBits : 3;
330 
331 } __attribute__((packed)) NumberIoFunctions;
332 
333 /*
334  I/O Send Operational Condition Response in SPI mode (R4)
335  modifiedR1 - Modified R1
336  numberIoFunctions - Number of I/O functions supported
337  ocr - Operations condition register
338 
339  */
340 typedef struct _IoSendOpCondResponseSpiMode_R4
341 {
342  ModifiedR1 modifiedR1;
343  NumberIoFunctions numberIoFunctions;
344  uint8_t ocr[3];
345 
346 } __attribute__((packed)) IoSendOpCondResponseSpiMode_R4;
347 
348 /*
349  I/O Send Operational Condition Response (R4)
350  startBit - Start bit, always 0
351  direction - 0 card to host
352  reserved_02_07 - 1s
353  numberIoFunctions - Number of I/O functions supported
354  ocr - Operations condition register
355  reserved_45_46 - 1S
356  endBit - End bit, always 1
357 
358  */
359 typedef struct _IoSendOpCondResponse_R4
360 {
361  uint8_t startBit : 1;
362  uint8_t direction : 1;
363  uint8_t reserved_02_07 : 6;
364  NumberIoFunctions numberIoFunctions;
365  uint8_t ocr[3];
366  uint8_t reserved_45_46 : 7;
367  uint8_t endBit : 1;
368 
369 } __attribute__((packed)) IoSendOpCondResponse_R4;
370 
371 /*
372  R/W flag, function number and raw flag
373  rwFlag - 0 read, 1 write
374  functionNumber - I/O card area
375  rawFlag - Read after write, 1 yes
376  stuff - MBZ
377  registerAddress_bits_16thru15 - Register address bits 15 and 16
378 
379  */
380 typedef struct _Function
381 {
382  uint8_t rwFlag : 1;
383  uint8_t functionNumber : 3;
384  uint8_t rawFlag : 1;
385  uint8_t stuff : 1;
386  uint8_t registerAddress_bits_16thru15 : 2;
387 
388 } __attribute__((packed)) Function;
389 
390 /*
391  Register address
392  address - Register address bits 0 through 14
393  stuff - MBZ
394 
395  */
396 typedef struct _RegisterAddress
397 {
398  unsigned short address : 15;
399  unsigned short stuff : 1;
400 
401 } __attribute__((packed)) RegisterAddress;
402 
403 /*
404  I/O read/write direct command
405  commandIndex - Start, direction and command index
406  function - R/W flag, function number and raw flag
407  registerAddress - Register address bits 0 through 14
408  dataOrStuff - Write data byte else MBZ
409  stuffBits - MBZ
410 
411  */
412 typedef struct _IoRwDirectCommand_CMD52
413 {
414  CommandIndex commandIndex;
415  Function function;
416  RegisterAddress registerAddress;
417  uint8_t dataOrStuff;
418  Crc crc;
419 
420 } __attribute__((packed)) IoRwDirectCommand_CMD52;
421 
422 /*
423  I/O read/write direct response
424  commandIndex - Start, direction and command index
425  stuff - MBZ
426  responseFlags - Status of SDIO card
427  readOrWriteData - RAW read else ignore
428  data - Read data
429  crc - CRC
430 
431  */
432 typedef struct _IoRwDirectResponse_R5
433 {
434  CommandIndex commandIndex;
435  uint8_t stuff[2];
436  ResponseFlags responseFlags;
437  uint8_t readOrWriteData;
438  uint8_t data;
439  Crc crc;
440 
441 } __attribute__((packed)) IoRwDirectResponse_R5;
442 
443 /*
444  I/O read/write direct response
445  modifiedR1 - Modified R1
446  data - Read data
447 
448  */
449 typedef struct _IoRwDirectResponseSpiMode_R5
450 {
451  ModifiedR1 modifiedR1;
452  uint8_t data;
453 
454 } __attribute__((packed)) IoRwDirectResponseSpiMode_R5;
455 
456 /*
457  R/W flag, function number and raw flag
458  rwFlag - 0 read, 1 write
459  functionNumber - I/O card area
460  blockMode - 1 block mode else bytes
461  opCode - 1 incrementing, 0 fixed location
462  registerAddress_bits_16thru15 - Register address bits 15 and 16
463 
464  */
465 typedef struct _FunctionBlock
466 {
467  uint8_t rwFlag : 1;
468  uint8_t functionNumber : 3;
469  uint8_t blockMode : 1;
470  uint8_t opCode : 1;
471  uint8_t registerAddress_bits_16thru15 : 2;
472 
473 } __attribute__((packed)) FunctionBlock;
474 
475 /*
476  Register extended address
477  address - Register address bits 0 through 14
478  byteCount_bit_8 - Byte or block count msb
479 
480  */
481 typedef struct _RegisterExtended
482 {
483  unsigned short address : 15;
484  unsigned short byteCount_bit_8 : 1;
485 
486 } __attribute__((packed)) RegisterExtended;
487 
488 /*
489  I/O read/write extended command
490  commandIndex - Start, direction and command index
491  functionBlock - R/W flag, function number, block and increment
492  registerExtended - Register address bits 0 through 14, msb block count
493  byteCount - Byte count bits 0 through 7
494  stuffBits - MBZ
495 
496  */
497 typedef struct _IoRwExtendedCommand_CMD53
498 {
499  CommandIndex commandIndex;
500  FunctionBlock functionBlock;
501  RegisterExtended registerExtended;
502  uint8_t byteCount;
503  Crc crc;
504 
505 } __attribute__((packed)) IoRwExtendedCommand_CMD53;
506 
507 /*
508  Register Value ( Host order, Big Endian )
509  wValue 16bit value
510  bValue 8 bit value
511 
512 */
513 
514 #define HIGH_BYTE (0)
515 #define LOW_BYTE (1)
516 
517 typedef union _RegisterValue {
518  uint16_t wValue;
519  uint8_t bValue[2];
520 
521 } __attribute__((packed)) RegisterValue;
522 
523 /*
524  ******************************************************************************
525  *
526  * CIA CCCR Register field structures
527  *
528  ******************************************************************************
529  */
530 /*
531  CCCR/SDIO Revision Register (SDIO_CIA_CCCR_CCCR_SDIO_REVISION)
532  sdio - SDIO revision
533  cccr - CCCR revision
534 
535  */
536 typedef struct _CccrSdioRevision
537 {
538  uint8_t sdio : 4;
539  uint8_t cccr : 4;
540 
541 } __attribute__((packed)) CccrSdioRevision;
542 
543 /*
544  SDIO Specification Revision Register (SDIO_CIA_CCCR_SD_SPEC_REVISION)
545  rfu - Reserved for future use
546  sd - Revision
547 
548  */
549 typedef struct _SdioSpecRevision
550 {
551  uint8_t rfu : 4;
552  uint8_t sd : 4;
553 
554 } __attribute__((packed)) SdioSpecRevision;
555 
556 /*
557  I/O Enable or Ready Register (SDIO_CIA_CCCR_IO_[ENABLE|READY])
558  io7 - Function 7
559  io6 - Function 6
560  io5 - Function 5
561  io4 - Function 4
562  io3 - Function 3
563  io2 - Function 2
564  io1 - Function 1
565  rfu - Reserved for future use
566 
567  */
568 typedef struct _IoFunctions
569 {
570  uint8_t io7 : 1;
571  uint8_t io6 : 1;
572  uint8_t io5 : 1;
573  uint8_t io4 : 1;
574  uint8_t io3 : 1;
575  uint8_t io2 : 1;
576  uint8_t io1 : 1;
577  uint8_t rfu : 1;
578 
579 } __attribute__((packed)) IoFunctions;
580 
581 /*
582  Interrupt Enable or Pending Register
583  (SDIO_CIA_CCCR_INTERRUPT_[ENABLE|PENDING])
584  int7 - Interrupt for function 7
585  int6 - Interrupt for function 6
586  int5 - Interrupt for function 5
587  int4 - Interrupt for function 4
588  int3 - Interrupt for function 3
589  int2 - Interrupt for function 2
590  int1 - Interrupt for function 1
591  ienm - Master enable
592 
593  */
594 typedef struct _IntFunctions
595 {
596  uint8_t int7 : 1;
597  uint8_t int6 : 1;
598  uint8_t int5 : 1;
599  uint8_t int4 : 1;
600  uint8_t int3 : 1;
601  uint8_t int2 : 1;
602  uint8_t int1 : 1;
603  uint8_t ienm : 1;
604 
605 } __attribute__((packed)) IntFunctions;
606 
607 /*
608  Bus Interface Control (SDIO_CIA_CCCR_BUS_INTERFACE_CONTROL)
609  cdDisable - Card detection
610  scsi - Support continuous SPI interrupt
611  ecsi - Enable continuous SPI interrupt
612  width - SDIO data bus width
613 
614  */
615 typedef struct _BusInterfaceControl
616 {
617  uint8_t cdDisable : 1;
618  uint8_t scsi : 1;
619  uint8_t ecsi : 1;
620  uint8_t rfu : 3;
621  uint8_t width : 2;
622 
623 } __attribute__((packed)) BusInterfaceControl;
624 
625 /*
626  Card Capability (SDIO_CIA_CCCR_CARD_CAPABILITY)
627  s4bls - 4-bit support for low speed cards
628  lsc - Low speed card
629  e4mi - Enable inter-block interrupts 4 bit mode
630  s4mi - Supports inter-block interrupts 4 bit mode
631  sbs - Supports suspend/resume
632  srw - Supports read wait
633  smb - Supports multiblock
634  sdc - Supports direct commands
635 
636  */
637 typedef struct _CardCapability
638 {
639  uint8_t s4bls : 1;
640  uint8_t lsc : 1;
641  uint8_t e4mi : 1;
642  uint8_t s4mi : 1;
643  uint8_t sbs : 1;
644  uint8_t srw : 1;
645  uint8_t smb : 1;
646  uint8_t sdc : 1;
647 
648 } __attribute__((packed)) CardCapability;
649 
650 /*
651  Power Control (SDIO_CIA_CCCR_POWER_CONTROL)
652  empc - Enable master power control
653  smpc - Supports master power control
654 
655  */
656 typedef struct _PowerControl
657 {
658  uint8_t rfu : 6;
659  uint8_t empc : 1;
660  uint8_t smpc : 1;
661 
662 } __attribute__((packed)) PowerControl;
663 
664 /*
665  Register settings and transfer byte union
666  <lower case> - Register bits defined as structure
667  content - Transfer byte
668 
669  */
670 typedef union _CccrRegister {
671  CccrSdioRevision cccrSdioRevision;
672  SdioSpecRevision sdioSpecRevision;
673  IoFunctions ioFunctions;
674  IntFunctions intFunctions;
675  BusInterfaceControl busInterfaceControl;
676  CardCapability cardCapability;
677  PowerControl powerControl;
678  uint8_t content;
679 
680 } __attribute__((packed)) CccrRegister;
681 
682 /*
683  ******************************************************************************
684  *
685  * Classes
686  *
687  ******************************************************************************
688  */
689 /*
690  ******************************************************************************
691  *
692  * SDIO Base Class (CMD0)
693  *
694  ******************************************************************************
695  */
696 class SdioCommand
697 {
698  public:
699  /*** Constructor ***/
700  SdioCommand(uint8_t commandIndex);
701 
702  /*** Destructor ***/
703  virtual ~SdioCommand() { return; };
704 
705  /*** Methods ***/
706  /* Reset command */
707  void reset(void);
708 
709  /* Prepare command to send */
710  virtual void prepare(void);
711 
712  /* Generate CRC 7 */
713  uint8_t generateCrc7(void);
714 
715  /* Display using iprintf */
716  virtual void display(void) { return; };
717 
718  /*** Accessors ***/
719  /* Get command data pointer */
720  puint8_t getPtr(void);
721 
722  /* Get response size */
723  uint32_t getSize(void);
724 
725  protected:
726  /* None */
727 
728  private:
729  /*** Methods ***/
730  /* None */
731 
732  /*** Data Members ***/
733  /* Command index */
734  uint8_t __command_index;
735 
736  /* CRC 7 */
737  uint8_t __crc7;
738 
739  /* Command data buffer */
740  uint8_t __commandData[SDIO_COMMAND_SIZE];
741 
742  /* Command 0 pointer */
743  GoIdleStateCommand_CMD0 *__commandPtr;
744 };
745 
746 /*
747  ******************************************************************************
748  *
749  * SDIO I/O Send Operational Condition (CMD5)
750  *
751  ******************************************************************************
752  */
753 class SdioCMD5 : public SdioCommand
754 {
755  public:
756  /*** Constructor ***/
757  SdioCMD5();
758 
759  /*** Destructor ***/
760  ~SdioCMD5() { return; };
761 
762  /*** Methods ***/
763  /* Prepare command to send */
764  void prepare(uint32_t ocr);
765 
766  /*** Accessors ***/
767  /* None */
768 
769  protected:
770  /* None */
771 
772  private:
773  /*** Methods ***/
774  /* Reset command */
775  /* None */
776 
777  /*** Data Members ***/
778  /* Command 5 pointer */
779  IoSendOpCondCommand_CMD5 *__commandPtr;
780 };
781 
782 /*
783  ******************************************************************************
784  *
785  * SDIO I/O Read/Write Direct (CMD52)
786  *
787  ******************************************************************************
788  */
789 class SdioCMD52 : public SdioCommand
790 {
791  public:
792  /*** Constructor ***/
793  SdioCMD52(void);
794 
795  /*** Destructor ***/
796  ~SdioCMD52() { return; };
797 
798  /*** Methods ***/
799  /* Prepare command to send */
800  void prepare(int readWriteFlag, uint8_t function, int rawFlag, uint32_t registerAddress, uint8_t writeData);
801 
802  /* Display using iprintf */
803  void display(void);
804 
805  /*** Accessors ***/
806  /* None */
807 
808  protected:
809  /* None */
810 
811  private:
812  /*** Methods ***/
813  /* Reset command */
814  /* None */
815 
816  /*** Data Members ***/
817  /* Command 52 pointer */
818  IoRwDirectCommand_CMD52 *__commandPtr;
819 };
820 
821 /*
822  ******************************************************************************
823  *
824  * SDIO I/O Read/Write Extended (CMD53)
825  *
826  ******************************************************************************
827  */
828 class SdioCMD53 : public SdioCommand
829 {
830  public:
831  /*** Constructor ***/
832  SdioCMD53(void);
833 
834  /*** Destructor ***/
835  ~SdioCMD53() { return; };
836 
837  /*** Methods ***/
838  /* Prepare command to send */
839  void prepare(int readWriteFlag,
840  uint8_t function,
841  int blockMode,
842  BOOL isIncrementingAddress,
843  uint32_t registerAddress,
844  uint32_t byteCount,
845  uint16_t blockSize);
846 
847  /* Display using iprintf */
848  void display(void);
849 
850  /*** Accessors ***/
851  /* Get object */
852  IoRwExtendedCommand_CMD53 &getCommand(void);
853 
854  protected:
855  /* None */
856 
857  private:
858  /*** Methods ***/
859  /* Reset command */
860  /* None */
861 
862  /*** Data Members ***/
863  /* Command 53 pointer */
864  IoRwExtendedCommand_CMD53 *__commandPtr;
865 };
866 
867 /*
868  ******************************************************************************
869  *
870  * CRC toggle command (CMD59)
871  *
872  ******************************************************************************
873  */
874 class SdioCMD59 : public SdioCommand
875 {
876  public:
877  /*** Constructor ***/
878  SdioCMD59(void);
879 
880  /*** Destructor ***/
881  ~SdioCMD59() { return; };
882 
883  /*** Methods ***/
884  /* Prepare command to send */
885  void prepare(BOOL isOn);
886 
887  /*** Accessors ***/
888  /* None */
889 
890  protected:
891  /* None */
892 
893  private:
894  /*** Methods ***/
895  /* Reset command */
896  /* None */
897 
898  /*** Data Members ***/
899  /* Command 5 pointer */
900  CrcOnOffCommand_CMD59 *__commandPtr;
901 };
902 
903 /*
904  ******************************************************************************
905  *
906  * SDIO Response Base Class
907  *
908  ******************************************************************************
909  */
910 class SdioResponse
911 {
912  public:
913  /*** Constructor ***/
914  SdioResponse(SdioBusType busType, SdioResponseType responseType);
915 
916  /*** Destructor ***/
917  virtual ~SdioResponse() = 0;
918 
919  /*** Methods ***/
920  /* Is response OK */
921  virtual BOOL isOk(void) = 0;
922 
923  /* Display using iprintf */
924  virtual void display(void) = 0;
925 
926  /*** Accessors ***/
927  /* Get response type */
928  SdioResponseType getType(void);
929 
930  /* Get response type */
931  SdioBusType getBusType(void);
932 
933  /* Get remaining response */
934  virtual puint8_t getPtr(void) = 0;
935 
936  /* Get response size */
937  virtual uint32_t getSize(void) = 0;
938 
939  protected:
940  /* None */
941 
942  private:
943  /*** Methods ***/
944  /* Synchronize data */
945  virtual void synchronize(void) = 0;
946 
947  /*** Data Members ***/
948  /* Type */
949  SdioResponseType __type;
950 
951  SdioBusType __busType;
952 };
953 
954 /*
955  ******************************************************************************
956  *
957  * I/O Send Operational Condition response (R4)
958  *
959  ******************************************************************************
960  */
961 class SdioResponseR4 : public SdioResponse
962 {
963  public:
964  /*** Constructor ***/
965  SdioResponseR4(SdioBusType busType);
966 
967  /*** Destructor ***/
968  ~SdioResponseR4();
969 
970  /*** Methods ***/
971  /* Is response OK */
972  BOOL isOk(void);
973 
974  /* Display using iprintf */
975  void display(void);
976 
977  /*** Accessors ***/
978  /* Get response pointer */
979  IoSendOpCondResponse_R4 *getResponsePtr(void);
980 
981  /* Get remaining response */
982  puint8_t getPtr(void);
983 
984  /* Get response size */
985  uint32_t getSize(void);
986 
987  /* Get response pointer */
988  IoSendOpCondResponse_R4 &getResponse(void);
989 
990  /* Get response size */
991  uint32_t getNumberIoFunctions(void);
992 
993  /* Get Operations Condition Register (OCR) */
994  uint32_t getOcr(void);
995 
996  protected:
997  /* None */
998 
999  private:
1000  /*** Methods ***/
1001  /* Synchronize data */
1002  void synchronize(void);
1003 
1004  /*** Data Members ***/
1005  /* Response pointer and size */
1006  puint8_t __responsePtr;
1007  ssize_t __responseSize;
1008 
1009  /* Response */
1010  IoSendOpCondResponse_R4 __response;
1011 
1012  /* Modified R1 (SPI Mode) */
1013  IoSendOpCondResponseSpiMode_R4 __responseSpiMode;
1014 };
1015 
1016 /*
1017  ******************************************************************************
1018  *
1019  * I/O Read/Write Direct response (R5)
1020  *
1021  ******************************************************************************
1022  */
1023 class SdioResponseR5 : public SdioResponse
1024 {
1025  public:
1026  /*** Constructor ***/
1027  SdioResponseR5(SdioBusType busType);
1028 
1029  /*** Destructor ***/
1030  ~SdioResponseR5();
1031 
1032  /*** Methods ***/
1033  /* Is response OK */
1034  BOOL isOk(void);
1035 
1036  /* Is card idle */
1037  BOOL isIdle(void);
1038 
1039  /* Display using iprintf */
1040  void display(void);
1041 
1042  /*** Accessors ***/
1043  /* Get response pointer */
1044  IoRwDirectResponse_R5 *getResponsePtr(void);
1045 
1046  /* Get remaining response */
1047  puint8_t getPtr(void);
1048 
1049  /* Get response size */
1050  uint32_t getSize(void);
1051 
1052  /* Get response reference */
1053  IoRwDirectResponse_R5 &getResponse(void);
1054 
1055  /* Get data byte */
1056  uint8_t getData(void);
1057 
1058  protected:
1059  /* None */
1060 
1061  private:
1062  /*** Methods ***/
1063  /* Synchronize data */
1064  void synchronize(void);
1065 
1066  /*** Data Members ***/
1067  /* Response pointer and size */
1068  puint8_t __responsePtr;
1069  ssize_t __responseSize;
1070 
1071  /* IO_RW_DIRECT Response */
1072  IoRwDirectResponse_R5 __response;
1073 
1074  /* IO_RW_DIRECT Response (SPI Mode) */
1075  IoRwDirectResponseSpiMode_R5 __responseSpiMode;
1076 };
1077 
1078 #endif /* _SDIO_H_ */