mmcsd_spi.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /****************************************************************************
  2. * drivers/mmcsd/mmcsd_spi.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. #ifndef __DRIVERS_MMCSD_MMCSD_SPI_H
  21. #define __DRIVERS_MMCSD_MMCSD_SPI_H
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. /****************************************************************************
  27. * Pre-processor Definitions
  28. ****************************************************************************/
  29. /* SPI **********************************************************************/
  30. /* SPI Command Set */
  31. #define CMD0 0x40 /* GO_IDLE_STATE: Resets all cards to idle state */
  32. #define CMD1 0x41 /* SEND_OP_COND: Sends capacity support information */
  33. #define CMD6 0x46 /* SWITCH_FUNC: Checks switchable function */
  34. #define CMD8 0x48 /* SEND_IF_COND: Sends SD Memory Card interface condition */
  35. #define CMD9 0x49 /* SEND_CSD: Asks card to send its card specific data (CSD) */
  36. #define CMD10 0x4a /* SEND_CID: Asks card to send its card identification (CID) */
  37. #define CMD12 0x4c /* STOP_TRANSMISSION: Forces the card to stop transmission */
  38. #define CMD13 0x4d /* SEND_STATUS: Asks card to send its status register */
  39. #define CMD16 0x50 /* SET_BLOCKLEN: Sets a block length (in bytes) */
  40. #define CMD17 0x51 /* READ_SINGLE_BLOCK: Reads a block of the selected size */
  41. #define CMD18 0x52 /* READ_MULTIPLE_BLOCK: Continuously transfers blocks from card to host */
  42. #define CMD20 0x54 /* CMD_WRITEBLOCK: Write block to memory (MMC) */
  43. #define CMD24 0x58 /* WRITE_BLOCK: Writes a block of the selected size */
  44. #define CMD25 0x59 /* WRITE_MULTIPLE_BLOCK: Continuously writes blocks of data */
  45. #define CMD27 0x5b /* PROGRAM_CSD: Set programmable bits of the CSD */
  46. #define CMD28 0x5c /* SET_WRITE_PROT: Sets the write protection bit of group */
  47. #define CMD29 0x5d /* CLR_WRITE_PROT: Clears the write protection bit of group */
  48. #define CMD30 0x5e /* SEND_WRITE_PROT: Asks card to send state of write protection bits */
  49. #define CMD32 0x60 /* ERASE_WR_BLK_START_ADDR: Sets address of first block to erase */
  50. #define CMD33 0x61 /* ERASE_WR_BLK_END_ADDR: Sets address of last block to erase */
  51. #define CMD34 0x62 /* UNTAG_SECTOR: (MMC) */
  52. #define CMD35 0x63 /* TAG_ERASE_GROUP_START: (MMC) */
  53. #define CMD36 0x64 /* TAG_ERASE_GOUPR_END: (MMC) */
  54. #define CMD37 0x65 /* UNTAG_ERASE_GROUP: (MMC) */
  55. #define CMD38 0x66 /* ERASE: Erases all previously selected write blocks */
  56. #define CMD40 0x68 /* CRC_ON_OFF: (MMC) */
  57. #define CMD42 0x6a /* LOCK_UNLOCK: Used to Set/Reset the Password or lock/unlock card */
  58. #define CMD55 0x77 /* APP_CMD: Tells card that the next command is an application specific command */
  59. #define CMD56 0x78 /* GEN_CMD: Used transfer a block to or get block from card */
  60. #define CMD58 0x7a /* READ_OCR :Reads the OCR register of a card */
  61. #define CMD59 0x7b /* CRC_ON_OFF: Turns the CRC option on or off */
  62. #define ACMD13 0x4d /* SD_STATUS: Send the SD Status */
  63. #define ACMD22 0x56 /* SEND_NUM_WR_BLOCKS: Send number of the errorfree blocks */
  64. #define ACMD23 0x57 /* SET_WR_BLK_ERASE_COUNT: Set number blocks to erase before writing */
  65. #define ACMD41 0x69 /* SD_SEND_OP_COND: Sends host capacity support information */
  66. #define ACMD42 0x6a /* SET_CLR_CARD_DETECT: Connect/disconnect pull-up resistor on CS */
  67. #define ACMD51 0x73 /* SEND_SCR: Reads the SD Configuration Register (SCR) */
  68. /* SPI 8-bit R1 response */
  69. #define MMCSD_SPIR1_OK 0x00 /* No error bits set */
  70. #define MMCSD_SPIR1_IDLESTATE 0x01 /* Idle state */
  71. #define MMCSD_SPIR1_ERASERESET 0x02 /* Erase reset */
  72. #define MMCSD_SPIR1_ILLEGALCMD 0x04 /* Illegal command */
  73. #define MMCSD_SPIR1_CRCERROR 0x08 /* Com CRC error */
  74. #define MMCSD_SPIR1_ERASEERROR 0x10 /* Erase sequence error */
  75. #define MMCSD_SPIR1_ADDRERROR 0x20 /* Address error */
  76. #define MMCSD_SPIR1_PARAMERROR 0x40 /* Parameter error */
  77. /* SPI 8-bit R2 response */
  78. #define MMCSD_SPIR2_CARDLOCKED 0x0001 /* Card is locked */
  79. #define MMCSD_SPIR2_WPERASESKIP 0x0002 /* WP erase skip */
  80. #define MMCSD_SPIR2_LOCKFAIL 0x0002 /* Lock/unlock cmd failed */
  81. #define MMCSD_SPIR2_ERROR 0x0004 /* Error */
  82. #define MMCSD_SPIR2_CCERROR 0x0008 /* CC error */
  83. #define MMCSD_SPIR2_CARDECCFAIL 0x0010 /* Card ECC failed */
  84. #define MMCSD_SPIR2_WPVIOLATION 0x0020 /* WP violation */
  85. #define MMCSD_SPIR2_ERASEPARAM 0x0040 /* Erase parameter */
  86. #define MMCSD_SPIR2_OUTOFRANGE 0x0080 /* Out of range */
  87. #define MMCSD_SPIR2_CSDOVERWRITE 0x0080 /* CSD overwrite */
  88. #define MMCSD_SPIR2_IDLESTATE 0x0100 /* In idle state */
  89. #define MMCSD_SPIR2_ERASERESET 0x0200 /* Erase reset */
  90. #define MMCSD_SPIR2_ILLEGALCMD 0x0400 /* Illegal command */
  91. #define MMCSD_SPIR2_CRCERROR 0x0800 /* Com CRC error */
  92. #define MMCSD_SPIR2_ERASEERROR 0x1000 /* Erase sequence error */
  93. #define MMCSD_SPIR2_ADDRERROR 0x2000 /* Address error */
  94. #define MMCSD_SPIR2_PARAMERROR 0x4000 /* Parameter error */
  95. /* Last 4 bytes of the 5 byte R7 response */
  96. #define MMCSD_SPIR7_VERSION_SHIFT (28) /* Bits 28-31: Command version number */
  97. #define MMCSD_SPIR7_VERSION_MASK ((uint32_t)0x0f << MMCSD_SPIR7_VERSION_SHIFT)
  98. #define MMCSD_SPIR7_VOLTAGE_SHIFT (8) /* Bits 8-11: Voltage accepted */
  99. #define MMCSD_SPIR7_VOLTAGE_MASK ((uint32_t)0x0f << MMCSD_SPIR7_VOLTAGE_SHIFT)
  100. #define MMCSD_SPIR7_VOLTAGE_27 ((uint32_t)0x01 << MMCSD_SPIR7_VOLTAGE_SHIFT) /* 2.7-3.6V */
  101. #define MMCSD_SPIR7_ECHO_SHIFT (0) /* Bits 0-7: Echoed check pattern */
  102. #define MMCSD_SPIR7_ECHO_MASK ((uint32_t)0xff << MMCSD_SPIR7_ECHO_SHIFT)
  103. /* Data Response */
  104. #define MMCSD_SPIDR_MASK 0x1f /* Mask for valid data response bits */
  105. #define MMCSD_SPIDR_ACCEPTED 0x05 /* Data accepted */
  106. #define MMCSD_SPIDR_CRCERROR 0x0b /* Data rejected due to CRC error */
  107. #define MMCSD_SPIDR_WRERROR 0x0d /* Data rejected due to write error */
  108. /* Data Tokens */
  109. #define MMCSD_SPIDT_STARTBLKSNGL 0xfe /* First byte of block, single block */
  110. #define MMCSD_SPIDT_STARTBLKMULTI 0xfc /* First byte of block, multi-block */
  111. #define MMCSD_SPIDT_STOPTRANS 0xfd /* Stop transmission */
  112. /* Data error token */
  113. #define MMCSD_SPIDET_UPPER 0xf0 /* The upper four bits are zero */
  114. #define MMCSD_SPIDET_ERROR 0x01 /* Error */
  115. #define MMCSD_SPIDET_CCERROR 0x02 /* CC error */
  116. #define MMCSD_SPIDET_CARDECCFAIL 0x04 /* Card ECC failed */
  117. #define MMCSD_SPIDET_OUTOFRANGE 0x08 /* Out of range */
  118. /* Operating Conditions register */
  119. #define MMCSD_OCR_V27 ((uint32_t)1 << 15) /* Bit 15: 2.7-2.8V */
  120. #define MMCSD_OCR_V28 ((uint32_t)1 << 16) /* Bit 16: 2.8-2.9V */
  121. #define MMCSD_OCR_V29 ((uint32_t)1 << 17) /* Bit 17: 2.9-3.0V */
  122. #define MMCSD_OCR_V30 ((uint32_t)1 << 18) /* Bit 18: 3.0-3.1V */
  123. #define MMCSD_OCR_V31 ((uint32_t)1 << 19) /* Bit 19: 3.1-3.2V */
  124. #define MMCSD_OCR_V32 ((uint32_t)1 << 20) /* Bit 20: 3.2-3.3V */
  125. #define MMCSD_OCR_V33 ((uint32_t)1 << 21) /* Bit 21: 3.3-3.4V */
  126. #define MMCSD_OCR_V34 ((uint32_t)1 << 22) /* Bit 22: 3.4-3.5V */
  127. #define MMCSD_OCR_V35 ((uint32_t)1 << 23) /* Bit 23: 3.5-3.6V */
  128. #define MMCSD_OCR_CCS ((uint32_t)1 << 30) /* Bit 30: Card capacity status */
  129. #define MMCSD_OCR_BUSY ((uint32_t)1 << 31) /* Bit 31: Card powered up status bit */
  130. /****************************************************************************
  131. * Public Types
  132. ****************************************************************************/
  133. /****************************************************************************
  134. * Public Functions Definitions
  135. ****************************************************************************/
  136. #undef EXTERN
  137. #if defined(__cplusplus)
  138. #define EXTERN extern "C"
  139. extern "C"
  140. {
  141. #else
  142. #define EXTERN extern
  143. #endif
  144. #undef EXTERN
  145. #if defined(__cplusplus)
  146. }
  147. #endif
  148. #endif /* __DRIVERS_MMCSD_MMCSD_SPI_H */