gd32f4xx_sdio.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /*!
  2. \file gd32f4xx_sdio.h
  3. \brief definitions for the SDIO
  4. */
  5. /*
  6. Copyright (C) 2016 GigaDevice
  7. 2016-08-15, V1.0.0, firmware for GD32F4xx
  8. */
  9. #ifndef GD32F4XX_SDIO_H
  10. #define GD32F4XX_SDIO_H
  11. #include "gd32f4xx.h"
  12. /* SDIO definitions */
  13. #define SDIO SDIO_BASE
  14. /* registers definitions */
  15. #define SDIO_PWRCTL REG32(SDIO + 0x00U) /*!< SDIO power control register */
  16. #define SDIO_CLKCTL REG32(SDIO + 0x04U) /*!< SDIO clock control register */
  17. #define SDIO_CMDAGMT REG32(SDIO + 0x08U) /*!< SDIO command argument register */
  18. #define SDIO_CMDCTL REG32(SDIO + 0x0CU) /*!< SDIO command control register */
  19. #define SDIO_RSPCMDIDX REG32(SDIO + 0x10U) /*!< SDIO command index response register */
  20. #define SDIO_RESP0 REG32(SDIO + 0x14U) /*!< SDIO response register 0 */
  21. #define SDIO_RESP1 REG32(SDIO + 0x18U) /*!< SDIO response register 1 */
  22. #define SDIO_RESP2 REG32(SDIO + 0x1CU) /*!< SDIO response register 2 */
  23. #define SDIO_RESP3 REG32(SDIO + 0x20U) /*!< SDIO response register 3 */
  24. #define SDIO_DATATO REG32(SDIO + 0x24U) /*!< SDIO data timeout register */
  25. #define SDIO_DATALEN REG32(SDIO + 0x28U) /*!< SDIO data length register */
  26. #define SDIO_DATACTL REG32(SDIO + 0x2CU) /*!< SDIO data control register */
  27. #define SDIO_DATACNT REG32(SDIO + 0x30U) /*!< SDIO data counter register */
  28. #define SDIO_STAT REG32(SDIO + 0x34U) /*!< SDIO status register */
  29. #define SDIO_INTC REG32(SDIO + 0x38U) /*!< SDIO interrupt clear register */
  30. #define SDIO_INTEN REG32(SDIO + 0x3CU) /*!< SDIO interrupt enable register */
  31. #define SDIO_FIFOCNT REG32(SDIO + 0x48U) /*!< SDIO FIFO counter register */
  32. #define SDIO_FIFO REG32(SDIO + 0x80U) /*!< SDIO FIFO data register */
  33. /* bits definitions */
  34. /* SDIO_PWRCTL */
  35. #define SDIO_PWRCTL_PWRCTL BITS(0,1) /*!< SDIO power control bits */
  36. /* SDIO_CLKCTL */
  37. #define SDIO_CLKCTL_DIV BITS(0,7) /*!< clock division */
  38. #define SDIO_CLKCTL_CLKEN BIT(8) /*!< SDIO_CLK clock output enable bit */
  39. #define SDIO_CLKCTL_CLKPWRSAV BIT(9) /*!< SDIO_CLK clock dynamic switch on/off for power saving */
  40. #define SDIO_CLKCTL_CLKBYP BIT(10) /*!< clock bypass enable bit */
  41. #define SDIO_CLKCTL_BUSMODE BITS(11,12) /*!< SDIO card bus mode control bit */
  42. #define SDIO_CLKCTL_CLKEDGE BIT(13) /*!< SDIO_CLK clock edge selection bit */
  43. #define SDIO_CLKCTL_HWCLKEN BIT(14) /*!< hardware clock control enable bit */
  44. #define SDIO_CLKCTL_DIV8 BIT(31) /*!< MSB of clock division */
  45. /* SDIO_CMDAGMT */
  46. #define SDIO_CMDAGMT_CMDAGMT BITS(0,31) /*!< SDIO card command argument */
  47. /* SDIO_CMDCTL */
  48. #define SDIO_CMDCTL_CMDIDX BITS(0,5) /*!< command index */
  49. #define SDIO_CMDCTL_CMDRESP BITS(6,7) /*!< command response type bits */
  50. #define SDIO_CMDCTL_INTWAIT BIT(8) /*!< interrupt wait instead of timeout */
  51. #define SDIO_CMDCTL_WAITDEND BIT(9) /*!< wait for ends of data transfer */
  52. #define SDIO_CMDCTL_CSMEN BIT(10) /*!< command state machine(CSM) enable bit */
  53. #define SDIO_CMDCTL_SUSPEND BIT(11) /*!< SD I/O suspend command(SD I/O only) */
  54. #define SDIO_CMDCTL_ENCMDC BIT(12) /*!< CMD completion signal enabled (CE-ATA only) */
  55. #define SDIO_CMDCTL_NINTEN BIT(13) /*!< no CE-ATA interrupt (CE-ATA only) */
  56. #define SDIO_CMDCTL_ATAEN BIT(14) /*!< CE-ATA command enable(CE-ATA only) */
  57. /* SDIO_DATATO */
  58. #define SDIO_DATATO_DATATO BITS(0,31) /*!< data timeout period */
  59. /* SDIO_DATALEN */
  60. #define SDIO_DATALEN_DATALEN BITS(0,24) /*!< data transfer length */
  61. /* SDIO_DATACTL */
  62. #define SDIO_DATACTL_DATAEN BIT(0) /*!< data transfer enabled bit */
  63. #define SDIO_DATACTL_DATADIR BIT(1) /*!< data transfer direction */
  64. #define SDIO_DATACTL_TRANSMOD BIT(2) /*!< data transfer mode */
  65. #define SDIO_DATACTL_DMAEN BIT(3) /*!< DMA enable bit */
  66. #define SDIO_DATACTL_BLKSZ BITS(4,7) /*!< data block size */
  67. #define SDIO_DATACTL_RWEN BIT(8) /*!< read wait mode enabled(SD I/O only) */
  68. #define SDIO_DATACTL_RWSTOP BIT(9) /*!< read wait stop(SD I/O only) */
  69. #define SDIO_DATACTL_RWTYPE BIT(10) /*!< read wait type(SD I/O only) */
  70. #define SDIO_DATACTL_IOEN BIT(11) /*!< SD I/O specific function enable(SD I/O only) */
  71. /* SDIO_STAT */
  72. #define SDIO_STAT_CCRCERR BIT(0) /*!< command response received (CRC check failed) */
  73. #define SDIO_STAT_DTCRCERR BIT(1) /*!< data block sent/received (CRC check failed) */
  74. #define SDIO_STAT_CMDTMOUT BIT(2) /*!< command response timeout */
  75. #define SDIO_STAT_DTTMOUT BIT(3) /*!< data timeout */
  76. #define SDIO_STAT_TXURE BIT(4) /*!< transmit FIFO underrun error occurs */
  77. #define SDIO_STAT_RXORE BIT(5) /*!< received FIFO overrun error occurs */
  78. #define SDIO_STAT_CMDRECV BIT(6) /*!< command response received (CRC check passed) */
  79. #define SDIO_STAT_CMDSEND BIT(7) /*!< command sent (no response required) */
  80. #define SDIO_STAT_DTEND BIT(8) /*!< data end (data counter, SDIO_DATACNT, is zero) */
  81. #define SDIO_STAT_STBITE BIT(9) /*!< start bit error in the bus */
  82. #define SDIO_STAT_DTBLKEND BIT(10) /*!< data block sent/received (CRC check passed) */
  83. #define SDIO_STAT_CMDRUN BIT(11) /*!< command transmission in progress */
  84. #define SDIO_STAT_TXRUN BIT(12) /*!< data transmission in progress */
  85. #define SDIO_STAT_RXRUN BIT(13) /*!< data reception in progress */
  86. #define SDIO_STAT_TFH BIT(14) /*!< transmit FIFO is half empty: at least 8 words can be written into the FIFO */
  87. #define SDIO_STAT_RFH BIT(15) /*!< receive FIFO is half full: at least 8 words can be read in the FIFO */
  88. #define SDIO_STAT_TFF BIT(16) /*!< transmit FIFO is full */
  89. #define SDIO_STAT_RFF BIT(17) /*!< receive FIFO is full */
  90. #define SDIO_STAT_TFE BIT(18) /*!< transmit FIFO is empty */
  91. #define SDIO_STAT_RFE BIT(19) /*!< receive FIFO is empty */
  92. #define SDIO_STAT_TXDTVAL BIT(20) /*!< data is valid in transmit FIFO */
  93. #define SDIO_STAT_RXDTVAL BIT(21) /*!< data is valid in receive FIFO */
  94. #define SDIO_STAT_SDIOINT BIT(22) /*!< SD I/O interrupt received */
  95. #define SDIO_STAT_ATAEND BIT(23) /*!< CE-ATA command completion signal received (only for CMD61) */
  96. /* SDIO_INTC */
  97. #define SDIO_INTC_CCRCERRC BIT(0) /*!< CCRCERR flag clear bit */
  98. #define SDIO_INTC_DTCRCERRC BIT(1) /*!< DTCRCERR flag clear bit */
  99. #define SDIO_INTC_CMDTMOUTC BIT(2) /*!< CMDTMOUT flag clear bit */
  100. #define SDIO_INTC_DTTMOUTC BIT(3) /*!< DTTMOUT flag clear bit */
  101. #define SDIO_INTC_TXUREC BIT(4) /*!< TXURE flag clear bit */
  102. #define SDIO_INTC_RXOREC BIT(5) /*!< RXORE flag clear bit */
  103. #define SDIO_INTC_CMDRECVC BIT(6) /*!< CMDRECV flag clear bit */
  104. #define SDIO_INTC_CMDSENDC BIT(7) /*!< CMDSEND flag clear bit */
  105. #define SDIO_INTC_DTENDC BIT(8) /*!< DTEND flag clear bit */
  106. #define SDIO_INTC_STBITEC BIT(9) /*!< STBITE flag clear bit */
  107. #define SDIO_INTC_DTBLKENDC BIT(10) /*!< DTBLKEND flag clear bit */
  108. #define SDIO_INTC_SDIOINTC BIT(22) /*!< SDIOINT flag clear bit */
  109. #define SDIO_INTC_ATAENDC BIT(23) /*!< ATAEND flag clear bit */
  110. /* SDIO_INTEN */
  111. #define SDIO_INTEN_CCRCERRIE BIT(0) /*!< command response CRC fail interrupt enable */
  112. #define SDIO_INTEN_DTCRCERRIE BIT(1) /*!< data CRC fail interrupt enable */
  113. #define SDIO_INTEN_CMDTMOUTIE BIT(2) /*!< command response timeout interrupt enable */
  114. #define SDIO_INTEN_DTTMOUTIE BIT(3) /*!< data timeout interrupt enable */
  115. #define SDIO_INTEN_TXUREIE BIT(4) /*!< transmit FIFO underrun error interrupt enable */
  116. #define SDIO_INTEN_RXOREIE BIT(5) /*!< received FIFO overrun error interrupt enable */
  117. #define SDIO_INTEN_CMDRECVIE BIT(6) /*!< command response received interrupt enable */
  118. #define SDIO_INTEN_CMDSENDIE BIT(7) /*!< command sent interrupt enable */
  119. #define SDIO_INTEN_DTENDIE BIT(8) /*!< data end interrupt enable */
  120. #define SDIO_INTEN_STBITEIE BIT(9) /*!< start bit error interrupt enable */
  121. #define SDIO_INTEN_DTBLKENDIE BIT(10) /*!< data block end interrupt enable */
  122. #define SDIO_INTEN_CMDRUNIE BIT(11) /*!< command transmission interrupt enable */
  123. #define SDIO_INTEN_TXRUNIE BIT(12) /*!< data transmission interrupt enable */
  124. #define SDIO_INTEN_RXRUNIE BIT(13) /*!< data reception interrupt enable */
  125. #define SDIO_INTEN_TFHIE BIT(14) /*!< transmit FIFO half empty interrupt enable */
  126. #define SDIO_INTEN_RFHIE BIT(15) /*!< receive FIFO half full interrupt enable */
  127. #define SDIO_INTEN_TFFIE BIT(16) /*!< transmit FIFO full interrupt enable */
  128. #define SDIO_INTEN_RFFIE BIT(17) /*!< receive FIFO full interrupt enable */
  129. #define SDIO_INTEN_TFEIE BIT(18) /*!< transmit FIFO empty interrupt enable */
  130. #define SDIO_INTEN_RFEIE BIT(19) /*!< receive FIFO empty interrupt enable */
  131. #define SDIO_INTEN_TXDTVALIE BIT(20) /*!< data valid in transmit FIFO interrupt enable */
  132. #define SDIO_INTEN_RXDTVALIE BIT(21) /*!< data valid in receive FIFO interrupt enable */
  133. #define SDIO_INTEN_SDIOINTIE BIT(22) /*!< SD I/O interrupt received interrupt enable */
  134. #define SDIO_INTEN_ATAENDIE BIT(23) /*!< CE-ATA command completion signal received interrupt enable */
  135. /* SDIO_FIFO */
  136. #define SDIO_FIFO_FIFODT BITS(0,31) /*!< receive FIFO data or transmit FIFO data */
  137. /* constants definitions */
  138. /* SDIO flags */
  139. #define SDIO_FLAG_CCRCERR BIT(0) /*!< command response received (CRC check failed) flag */
  140. #define SDIO_FLAG_DTCRCERR BIT(1) /*!< data block sent/received (CRC check failed) flag */
  141. #define SDIO_FLAG_CMDTMOUT BIT(2) /*!< command response timeout flag */
  142. #define SDIO_FLAG_DTTMOUT BIT(3) /*!< data timeout flag */
  143. #define SDIO_FLAG_TXURE BIT(4) /*!< transmit FIFO underrun error occurs flag */
  144. #define SDIO_FLAG_RXORE BIT(5) /*!< received FIFO overrun error occurs flag */
  145. #define SDIO_FLAG_CMDRECV BIT(6) /*!< command response received (CRC check passed) flag */
  146. #define SDIO_FLAG_CMDSEND BIT(7) /*!< command sent (no response required) flag */
  147. #define SDIO_FLAG_DTEND BIT(8) /*!< data end (data counter, SDIO_DATACNT, is zero) flag */
  148. #define SDIO_FLAG_STBITE BIT(9) /*!< start bit error in the bus flag */
  149. #define SDIO_FLAG_DTBLKEND BIT(10) /*!< data block sent/received (CRC check passed) flag */
  150. #define SDIO_FLAG_CMDRUN BIT(11) /*!< command transmission in progress flag */
  151. #define SDIO_FLAG_TXRUN BIT(12) /*!< data transmission in progress flag */
  152. #define SDIO_FLAG_RXRUN BIT(13) /*!< data reception in progress flag */
  153. #define SDIO_FLAG_TFH BIT(14) /*!< transmit FIFO is half empty flag: at least 8 words can be written into the FIFO */
  154. #define SDIO_FLAG_RFH BIT(15) /*!< receive FIFO is half full flag: at least 8 words can be read in the FIFO */
  155. #define SDIO_FLAG_TFF BIT(16) /*!< transmit FIFO is full flag */
  156. #define SDIO_FLAG_RFF BIT(17) /*!< receive FIFO is full flag */
  157. #define SDIO_FLAG_TFE BIT(18) /*!< transmit FIFO is empty flag */
  158. #define SDIO_FLAG_RFE BIT(19) /*!< receive FIFO is empty flag */
  159. #define SDIO_FLAG_TXDTVAL BIT(20) /*!< data is valid in transmit FIFO flag */
  160. #define SDIO_FLAG_RXDTVAL BIT(21) /*!< data is valid in receive FIFO flag */
  161. #define SDIO_FLAG_SDIOINT BIT(22) /*!< SD I/O interrupt received flag */
  162. #define SDIO_FLAG_ATAEND BIT(23) /*!< CE-ATA command completion signal received (only for CMD61) flag */
  163. /* SDIO interrupt flags */
  164. #define SDIO_INT_CCRCERR BIT(0) /*!< SDIO CCRCERR interrupt */
  165. #define SDIO_INT_DTCRCERR BIT(1) /*!< SDIO DTCRCERR interrupt */
  166. #define SDIO_INT_CMDTMOUT BIT(2) /*!< SDIO CMDTMOUT interrupt */
  167. #define SDIO_INT_DTTMOUT BIT(3) /*!< SDIO DTTMOUT interrupt */
  168. #define SDIO_INT_TXURE BIT(4) /*!< SDIO TXURE interrupt */
  169. #define SDIO_INT_RXORE BIT(5) /*!< SDIO RXORE interrupt */
  170. #define SDIO_INT_CMDRECV BIT(6) /*!< SDIO CMDRECV interrupt */
  171. #define SDIO_INT_CMDSEND BIT(7) /*!< SDIO CMDSEND interrupt */
  172. #define SDIO_INT_DTEND BIT(8) /*!< SDIO DTEND interrupt */
  173. #define SDIO_INT_STBITE BIT(9) /*!< SDIO STBITE interrupt */
  174. #define SDIO_INT_DTBLKEND BIT(10) /*!< SDIO DTBLKEND interrupt */
  175. #define SDIO_INT_CMDRUN BIT(11) /*!< SDIO CMDRUN interrupt */
  176. #define SDIO_INT_TXRUN BIT(12) /*!< SDIO TXRUN interrupt */
  177. #define SDIO_INT_RXRUN BIT(13) /*!< SDIO RXRUN interrupt */
  178. #define SDIO_INT_TFH BIT(14) /*!< SDIO TFH interrupt */
  179. #define SDIO_INT_RFH BIT(15) /*!< SDIO RFH interrupt */
  180. #define SDIO_INT_TFF BIT(16) /*!< SDIO TFF interrupt */
  181. #define SDIO_INT_RFF BIT(17) /*!< SDIO RFF interrupt */
  182. #define SDIO_INT_TFE BIT(18) /*!< SDIO TFE interrupt */
  183. #define SDIO_INT_RFE BIT(19) /*!< SDIO RFE interrupt */
  184. #define SDIO_INT_TXDTVAL BIT(20) /*!< SDIO TXDTVAL interrupt */
  185. #define SDIO_INT_RXDTVAL BIT(21) /*!< SDIO RXDTVAL interrupt */
  186. #define SDIO_INT_SDIOINT BIT(22) /*!< SDIO SDIOINT interrupt */
  187. #define SDIO_INT_ATAEND BIT(23) /*!< SDIO ATAEND interrupt */
  188. /* SDIO power control */
  189. #define PWRCTL_PWRCTL(regval) (BITS(0,1) & ((uint32_t)(regval) << 0))
  190. #define SDIO_POWER_OFF PWRCTL_PWRCTL(0) /*!< SDIO power off */
  191. #define SDIO_POWER_ON PWRCTL_PWRCTL(3) /*!< SDIO power on */
  192. /* SDIO card bus mode control */
  193. #define CLKCTL_BUSMODE(regval) (BITS(11,12) & ((uint32_t)(regval) << 11))
  194. #define SDIO_BUSMODE_1BIT CLKCTL_BUSMODE(0) /*!< 1-bit SDIO card bus mode */
  195. #define SDIO_BUSMODE_4BIT CLKCTL_BUSMODE(1) /*!< 4-bit SDIO card bus mode */
  196. #define SDIO_BUSMODE_8BIT CLKCTL_BUSMODE(2) /*!< 8-bit SDIO card bus mode */
  197. /* SDIO_CLK clock edge selection */
  198. #define SDIO_SDIOCLKEDGE_RISING (uint32_t)0x00000000U /*!< select the rising edge of the SDIOCLK to generate SDIO_CLK */
  199. #define SDIO_SDIOCLKEDGE_FALLING SDIO_CLKCTL_CLKEDGE /*!< select the falling edge of the SDIOCLK to generate SDIO_CLK */
  200. /* clock bypass enable or disable */
  201. #define SDIO_CLOCKBYPASS_DISABLE (uint32_t)0x00000000U /*!< no bypass */
  202. #define SDIO_CLOCKBYPASS_ENABLE SDIO_CLKCTL_CLKBYP /*!< clock bypass */
  203. /* SDIO_CLK clock dynamic switch on/off for power saving */
  204. #define SDIO_CLOCKPWRSAVE_DISABLE (uint32_t)0x00000000U /*!< SDIO_CLK clock is always on */
  205. #define SDIO_CLOCKPWRSAVE_ENABLE SDIO_CLKCTL_CLKPWRSAV /*!< SDIO_CLK closed when bus is idle */
  206. /* SDIO command response type */
  207. #define CMDCTL_CMDRESP(regval) (BITS(6,7) & ((uint32_t)(regval) << 6))
  208. #define SDIO_RESPONSETYPE_NO CMDCTL_CMDRESP(0) /*!< no response */
  209. #define SDIO_RESPONSETYPE_SHORT CMDCTL_CMDRESP(1) /*!< short response */
  210. #define SDIO_RESPONSETYPE_LONG CMDCTL_CMDRESP(3) /*!< long response */
  211. /* command state machine wait type */
  212. #define SDIO_WAITTYPE_NO (uint32_t)0x00000000U /*!< not wait interrupt */
  213. #define SDIO_WAITTYPE_INTERRUPT SDIO_CMDCTL_INTWAIT /*!< wait interrupt */
  214. #define SDIO_WAITTYPE_DATAEND SDIO_CMDCTL_WAITDEND /*!< wait the end of data transfer */
  215. #define SDIO_RESPONSE0 (uint32_t)0x00000000U /*!< card response[31:0]/card response[127:96] */
  216. #define SDIO_RESPONSE1 (uint32_t)0x00000001U /*!< card response[95:64] */
  217. #define SDIO_RESPONSE2 (uint32_t)0x00000002U /*!< card response[63:32] */
  218. #define SDIO_RESPONSE3 (uint32_t)0x00000003U /*!< card response[31:1], plus bit 0 */
  219. /* SDIO data block size */
  220. #define DATACTL_BLKSZ(regval) (BITS(4,7) & ((uint32_t)(regval) << 4))
  221. #define SDIO_DATABLOCKSIZE_1BYTE DATACTL_BLKSZ(0) /*!< block size = 1 byte */
  222. #define SDIO_DATABLOCKSIZE_2BYTES DATACTL_BLKSZ(1) /*!< block size = 2 bytes */
  223. #define SDIO_DATABLOCKSIZE_4BYTES DATACTL_BLKSZ(2) /*!< block size = 4 bytes */
  224. #define SDIO_DATABLOCKSIZE_8BYTES DATACTL_BLKSZ(3) /*!< block size = 8 bytes */
  225. #define SDIO_DATABLOCKSIZE_16BYTES DATACTL_BLKSZ(4) /*!< block size = 16 bytes */
  226. #define SDIO_DATABLOCKSIZE_32BYTES DATACTL_BLKSZ(5) /*!< block size = 32 bytes */
  227. #define SDIO_DATABLOCKSIZE_64BYTES DATACTL_BLKSZ(6) /*!< block size = 64 bytes */
  228. #define SDIO_DATABLOCKSIZE_128BYTES DATACTL_BLKSZ(7) /*!< block size = 128 bytes */
  229. #define SDIO_DATABLOCKSIZE_256BYTES DATACTL_BLKSZ(8) /*!< block size = 256 bytes */
  230. #define SDIO_DATABLOCKSIZE_512BYTES DATACTL_BLKSZ(9) /*!< block size = 512 bytes */
  231. #define SDIO_DATABLOCKSIZE_1024BYTES DATACTL_BLKSZ(10) /*!< block size = 1024 bytes */
  232. #define SDIO_DATABLOCKSIZE_2048BYTES DATACTL_BLKSZ(11) /*!< block size = 2048 bytes */
  233. #define SDIO_DATABLOCKSIZE_4096BYTES DATACTL_BLKSZ(12) /*!< block size = 4096 bytes */
  234. #define SDIO_DATABLOCKSIZE_8192BYTES DATACTL_BLKSZ(13) /*!< block size = 8192 bytes */
  235. #define SDIO_DATABLOCKSIZE_16384BYTES DATACTL_BLKSZ(14) /*!< block size = 16384 bytes */
  236. /* SDIO data transfer mode */
  237. #define SDIO_TRANSMODE_BLOCK (uint32_t)0x00000000U /*!< block transfer */
  238. #define SDIO_TRANSMODE_STREAM SDIO_DATACTL_TRANSMOD /*!< stream transfer or SDIO multibyte transfer */
  239. /* SDIO data transfer direction */
  240. #define SDIO_TRANSDIRECTION_TOCARD (uint32_t)0x00000000U /*!< write data to card */
  241. #define SDIO_TRANSDIRECTION_TOSDIO SDIO_DATACTL_DATADIR /*!< read data from card */
  242. /* SDIO read wait type */
  243. #define SDIO_READWAITTYPE_DAT2 (uint32_t)0x00000000U /*!< read wait control using SDIO_DAT[2] */
  244. #define SDIO_READWAITTYPE_CLK SDIO_DATACTL_RWTYPE /*!< read wait control by stopping SDIO_CLK */
  245. /* function declarations */
  246. /* deinitialize the SDIO */
  247. void sdio_deinit(void);
  248. /* configure the SDIO clock */
  249. void sdio_clock_config(uint32_t clock_edge, uint32_t clock_bypass, uint32_t clock_powersave, uint16_t clock_division);
  250. /* enable hardware clock control */
  251. void sdio_hardware_clock_enable(void);
  252. /* disable hardware clock control */
  253. void sdio_hardware_clock_disable(void);
  254. /* set different SDIO card bus mode */
  255. void sdio_bus_mode_set(uint32_t bus_mode);
  256. /* set the SDIO power state */
  257. void sdio_power_state_set(uint32_t power_state);
  258. /* get the SDIO power state */
  259. uint32_t sdio_power_state_get(void);
  260. /* enable SDIO_CLK clock output */
  261. void sdio_clock_enable(void);
  262. /* disable SDIO_CLK clock output */
  263. void sdio_clock_disable(void);
  264. /* configure the command index, argument, response type, wait type and CSM to send command */
  265. /* configure the command and response */
  266. void sdio_command_response_config(uint32_t cmd_index, uint32_t cmd_argument, uint32_t response_type);
  267. /* set the command state machine wait type */
  268. void sdio_wait_type_set(uint32_t wait_type);
  269. /* enable the CSM(command state machine) */
  270. void sdio_csm_enable(void);
  271. /* disable the CSM(command state machine) */
  272. void sdio_csm_disable(void);
  273. /* get the last response command index */
  274. uint8_t sdio_command_index_get(void);
  275. /* get the response for the last received command */
  276. uint32_t sdio_response_get(uint32_t sdio_responsex);
  277. /* configure the data timeout, length, block size, transfer mode, direction and DSM for data transfer */
  278. /* configure the data timeout, data length and data block size */
  279. void sdio_data_config(uint32_t data_timeout, uint32_t data_length, uint32_t data_blocksize);
  280. /* configure the data transfer mode and direction */
  281. void sdio_data_transfer_config(uint32_t transfer_mode, uint32_t transfer_direction);
  282. /* enable the DSM(data state machine) for data transfer */
  283. void sdio_dsm_enable(void);
  284. /* disable the DSM(data state machine) */
  285. void sdio_dsm_disable(void);
  286. /* write data(one word) to the transmit FIFO */
  287. void sdio_data_write(uint32_t data);
  288. /* read data(one word) from the receive FIFO */
  289. uint32_t sdio_data_read(void);
  290. /* get the number of remaining data bytes to be transferred to card */
  291. uint32_t sdio_data_counter_get(void);
  292. /* get the number of words remaining to be written or read from FIFO */
  293. uint32_t sdio_fifo_counter_get(void);
  294. /* enable the DMA request for SDIO */
  295. void sdio_dma_enable(void);
  296. /* disable the DMA request for SDIO */
  297. void sdio_dma_disable(void);
  298. /* get the flags state of SDIO */
  299. FlagStatus sdio_flag_get(uint32_t flag);
  300. /* clear the pending flags of SDIO */
  301. void sdio_flag_clear(uint32_t flag);
  302. /* enable the SDIO interrupt */
  303. void sdio_interrupt_enable(uint32_t int_flag);
  304. /* disable the SDIO interrupt */
  305. void sdio_interrupt_disable(uint32_t int_flag);
  306. /* get the interrupt flags state of SDIO */
  307. FlagStatus sdio_interrupt_flag_get(uint32_t int_flag);
  308. /* clear the interrupt pending flags of SDIO */
  309. void sdio_interrupt_flag_clear(uint32_t int_flag);
  310. /* enable the read wait mode(SD I/O only) */
  311. void sdio_readwait_enable(void);
  312. /* disable the read wait mode(SD I/O only) */
  313. void sdio_readwait_disable(void);
  314. /* enable the function that stop the read wait process(SD I/O only) */
  315. void sdio_stop_readwait_enable(void);
  316. /* disable the function that stop the read wait process(SD I/O only) */
  317. void sdio_stop_readwait_disable(void);
  318. /* set the read wait type(SD I/O only) */
  319. void sdio_readwait_type_set(uint32_t readwait_type);
  320. /* enable the SD I/O mode specific operation(SD I/O only) */
  321. void sdio_operation_enable(void);
  322. /* disable the SD I/O mode specific operation(SD I/O only) */
  323. void sdio_operation_disable(void);
  324. /* enable the SD I/O suspend operation(SD I/O only) */
  325. void sdio_suspend_enable(void);
  326. /* disable the SD I/O suspend operation(SD I/O only) */
  327. void sdio_suspend_disable(void);
  328. /* enable the CE-ATA command(CE-ATA only) */
  329. void sdio_ceata_command_enable(void);
  330. /* disable the CE-ATA command(CE-ATA only) */
  331. void sdio_ceata_command_disable(void);
  332. /* enable the CE-ATA interrupt(CE-ATA only) */
  333. void sdio_ceata_interrupt_enable(void);
  334. /* disable the CE-ATA interrupt(CE-ATA only) */
  335. void sdio_ceata_interrupt_disable(void);
  336. /* enable the CE-ATA command completion signal(CE-ATA only) */
  337. void sdio_ceata_command_completion_enable(void);
  338. /* disable the CE-ATA command completion signal(CE-ATA only) */
  339. void sdio_ceata_command_completion_disable(void);
  340. #endif /* GD32F4XX_SDIO_H */