gd32f10x_sdio.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /**
  2. ******************************************************************************
  3. * @brief SDIO header file of the firmware library
  4. ******************************************************************************
  5. */
  6. /* Define to prevent recursive inclusion -------------------------------------*/
  7. #ifndef __GD32F10X_SDIO_H
  8. #define __GD32F10X_SDIO_H
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /* Includes ------------------------------------------------------------------*/
  13. #include "gd32f10x.h"
  14. /** @addtogroup GD32F10x_Firmware
  15. * @{
  16. */
  17. /** @addtogroup SDIO
  18. * @{
  19. */
  20. /** @defgroup SDIO_Exported_Types
  21. * @{
  22. */
  23. typedef struct {
  24. uint32_t SDIO_ClockEdge; /*!< Configure the SDIO Clock edge on which the bit capture is made.
  25. This parameter can be a value of @ref SDIO_Clock_Edge*/
  26. uint32_t SDIO_ClockBypassState; /*!< Configure the SDIO Clock divider bypass mode
  27. This parameter can be a value of @ref SDIO_Clock_Bypass_State */
  28. uint32_t SDIO_ClockPWRSave; /*!< Configure the SDIO Clock output powersave mode when the bus is idle.
  29. This parameter can be a value of @ref SDIO_Clock_Power_Save */
  30. uint32_t SDIO_BusMode; /*!< Configure the SDIO bus mode.
  31. This parameter can be a value of @ref SDIO_Bus_Mode */
  32. uint32_t SDIO_HWFlowCtrlState; /*!< Configure the SDIO hardware flow control is enabled or disabled.
  33. This parameter can be a value of @ref SDIO_HW_Flow_Control_State */
  34. uint8_t SDIO_ClockDiv; /*!< Configure the clock frequency prescaler of the SDIO controller.
  35. This parameter can be a value between 0x00 and 0xFF. */
  36. } SDIO_InitPara;
  37. typedef struct {
  38. uint32_t SDIO_CMDParameter; /*!< Configure the SDIO command parameter which is sent to
  39. a card as part of a command message. */
  40. uint32_t SDIO_CMDIndex; /*!< Configure the SDIO command index. */
  41. uint32_t SDIO_ResponseType; /*!< Configure the SDIO response type.
  42. This parameter can be a value of @ref SDIO_Response_Type */
  43. uint32_t SDIO_WaitINTState; /*!< Configure whether SDIO wait-for-interrupt request is enabled or disabled.
  44. This parameter can be a value of @ref SDIO_Wait_Interrupt_State */
  45. uint32_t SDIO_CSMState; /*!< Configure SDIO Command state machine (CSM) is enabled or disabled.
  46. This parameter can be a value of @ref SDIO_CSM_State */
  47. } SDIO_CmdInitPara;
  48. typedef struct {
  49. uint32_t SDIO_DataTimeOut; /*!< Configure the data timeout period in card bus clock periods. */
  50. uint32_t SDIO_DataLength; /*!< Configure the number of data bytes to be transferred. */
  51. uint32_t SDIO_DataBlockSize; /*!< Configure the data block size for block transfer.
  52. This parameter can be a value of @ref SDIO_Data_Block_Size */
  53. uint32_t SDIO_TransDirection; /*!< Configure the data transfer direction, read or write.
  54. This parameter can be a value of @ref SDIO_Transfer_Direction */
  55. uint32_t SDIO_TransMode; /*!< Configure whether data transfer is in stream or block mode.
  56. This parameter can be a value of @ref SDIO_Transfer_Mode */
  57. uint32_t SDIO_DSMState; /*!< Configure whether SDIO Data state machine (DSM) is enabled or disabled.
  58. This parameter can be a value of @ref SDIO_DSM_State */
  59. } SDIO_DataInitPara;
  60. /**
  61. * @}
  62. */
  63. /** @defgroup SDIO_Exported_Constants
  64. * @{
  65. */
  66. /** @defgroup SDIO_Clock_Edge
  67. * @{
  68. */
  69. #define SDIO_CLOCKEDGE_RISING ((uint32_t)0x00000000)
  70. #define SDIO_CLOCKEDGE_FALLING ((uint32_t)0x00002000)
  71. /**
  72. * @}
  73. */
  74. /** @defgroup SDIO_Clock_Bypass_State
  75. * @{
  76. */
  77. #define SDIO_CLOCKBYPASSSTATE_DISABLE ((uint32_t)0x00000000)
  78. #define SDIO_CLOCKBYPASSSTATE_ENABLE ((uint32_t)0x00000400)
  79. /**
  80. * @}
  81. */
  82. /** @defgroup SDIO_Clock_PWR_Save
  83. * @{
  84. */
  85. #define SDIO_CLOCKPWRSAVE_DISABLE ((uint32_t)0x00000000)
  86. #define SDIO_CLOCKPWRSAVE_ENABLE ((uint32_t)0x00000200)
  87. /**
  88. * @}
  89. */
  90. /** @defgroup SDIO_Bus_Mode
  91. * @{
  92. */
  93. #define SDIO_BUSMODE_1B ((uint32_t)0x00000000)
  94. #define SDIO_BUSMODE_4B ((uint32_t)0x00000800)
  95. #define SDIO_BUSMODE_8B ((uint32_t)0x00001000)
  96. /**
  97. * @}
  98. */
  99. /** @defgroup SDIO_HW_Flow_Control_State
  100. * @{
  101. */
  102. #define SDIO_HWFLOWCTRLSTATE_DISABLE ((uint32_t)0x00000000)
  103. #define SDIO_HWFLOWCTRLSTATE_ENABLE ((uint32_t)0x00004000)
  104. /**
  105. * @}
  106. */
  107. /** @defgroup SDIO_Power_State
  108. * @{
  109. */
  110. #define SDIO_PWRSTATE_OFF ((uint32_t)0x00000000)
  111. #define SDIO_PWRSTATE_ON ((uint32_t)0x00000003)
  112. /**
  113. * @}
  114. */
  115. /** @defgroup SDIO_Interrupt_sources
  116. * @{
  117. */
  118. #define SDIO_INT_CCRCFAIL ((uint32_t)0x00000001)
  119. #define SDIO_INT_DTCRCFAIL ((uint32_t)0x00000002)
  120. #define SDIO_INT_CMDTMOUT ((uint32_t)0x00000004)
  121. #define SDIO_INT_DTTMOUT ((uint32_t)0x00000008)
  122. #define SDIO_INT_TXURE ((uint32_t)0x00000010)
  123. #define SDIO_INT_RXORE ((uint32_t)0x00000020)
  124. #define SDIO_INT_CMDREND ((uint32_t)0x00000040)
  125. #define SDIO_INT_CMDSENT ((uint32_t)0x00000080)
  126. #define SDIO_INT_DTEND ((uint32_t)0x00000100)
  127. #define SDIO_INT_STBITE ((uint32_t)0x00000200)
  128. #define SDIO_INT_DTBLKEND ((uint32_t)0x00000400)
  129. #define SDIO_INT_CMDRUN ((uint32_t)0x00000800)
  130. #define SDIO_INT_TXRUN ((uint32_t)0x00001000)
  131. #define SDIO_INT_RXRUN ((uint32_t)0x00002000)
  132. #define SDIO_INT_TXFIFOHE ((uint32_t)0x00004000)
  133. #define SDIO_INT_RXFIFOHF ((uint32_t)0x00008000)
  134. #define SDIO_INT_TXFIFOF ((uint32_t)0x00010000)
  135. #define SDIO_INT_RXFIFOF ((uint32_t)0x00020000)
  136. #define SDIO_INT_TXFIFOE ((uint32_t)0x00040000)
  137. #define SDIO_INT_RXFIFOE ((uint32_t)0x00080000)
  138. #define SDIO_INT_TXDTVAL ((uint32_t)0x00100000)
  139. #define SDIO_INT_RXDTVAL ((uint32_t)0x00200000)
  140. #define SDIO_INT_SDIOINT ((uint32_t)0x00400000)
  141. #define SDIO_INT_ATAEND ((uint32_t)0x00800000)
  142. /**
  143. * @}
  144. */
  145. /** @defgroup SDIO_Response_Type
  146. * @{
  147. */
  148. #define SDIO_RESPONSETYPE_NO ((uint32_t)0x00000000)
  149. #define SDIO_RESPONSETYPE_SHORT ((uint32_t)0x00000040)
  150. #define SDIO_RESPONSETYPE_LONG ((uint32_t)0x000000C0)
  151. /**
  152. * @}
  153. */
  154. /** @defgroup SDIO_Wait_Interrupt_State
  155. * @{
  156. */
  157. #define SDIO_WAITINTSTATE_NO ((uint32_t)0x00000000)
  158. #define SDIO_WAITINTSTATE_INT ((uint32_t)0x00000100)
  159. #define SDIO_WAITINTSTATE_PEND ((uint32_t)0x00000200)
  160. /**
  161. * @}
  162. */
  163. /** @defgroup SDIO_CSM_State
  164. * @{
  165. */
  166. #define SDIO_CSMSTATE_DISABLE ((uint32_t)0x00000000)
  167. #define SDIO_CSMSTATE_ENABLE ((uint32_t)0x00000400)
  168. /**
  169. * @}
  170. */
  171. /** @defgroup SDIO_Response_Registers
  172. * @{
  173. */
  174. #define SDIO_RESP1 ((uint32_t)0x00000000)
  175. #define SDIO_RESP2 ((uint32_t)0x00000004)
  176. #define SDIO_RESP3 ((uint32_t)0x00000008)
  177. #define SDIO_RESP4 ((uint32_t)0x0000000C)
  178. /**
  179. * @}
  180. */
  181. /** @defgroup SDIO_Data_Block_Size
  182. * @{
  183. */
  184. #define SDIO_DATABLOCKSIZE_1B ((uint32_t)0x00000000)
  185. #define SDIO_DATABLOCKSIZE_2B ((uint32_t)0x00000010)
  186. #define SDIO_DATABLOCKSIZE_4B ((uint32_t)0x00000020)
  187. #define SDIO_DATABLOCKSIZE_8B ((uint32_t)0x00000030)
  188. #define SDIO_DATABLOCKSIZE_16B ((uint32_t)0x00000040)
  189. #define SDIO_DATABLOCKSIZE_32B ((uint32_t)0x00000050)
  190. #define SDIO_DATABLOCKSIZE_64B ((uint32_t)0x00000060)
  191. #define SDIO_DATABLOCKSIZE_128B ((uint32_t)0x00000070)
  192. #define SDIO_DATABLOCKSIZE_256B ((uint32_t)0x00000080)
  193. #define SDIO_DATABLOCKSIZE_512B ((uint32_t)0x00000090)
  194. #define SDIO_DATABLOCKSIZE_1024B ((uint32_t)0x000000A0)
  195. #define SDIO_DATABLOCKSIZE_2048B ((uint32_t)0x000000B0)
  196. #define SDIO_DATABLOCKSIZE_4096B ((uint32_t)0x000000C0)
  197. #define SDIO_DATABLOCKSIZE_8192B ((uint32_t)0x000000D0)
  198. #define SDIO_DATABLOCKSIZE_16384B ((uint32_t)0x000000E0)
  199. /**
  200. * @}
  201. */
  202. /** @defgroup SDIO_Transfer_Direction
  203. * @{
  204. */
  205. #define SDIO_TRANSDIRECTION_TOCARD ((uint32_t)0x00000000)
  206. #define SDIO_TRANSDIRECTION_TOSDIO ((uint32_t)0x00000002)
  207. /**
  208. * @}
  209. */
  210. /** @defgroup SDIO_Transfer_Mode
  211. * @{
  212. */
  213. #define SDIO_TRANSMODE_BLOCK ((uint32_t)0x00000000)
  214. #define SDIO_TRANSMODE_STREAM ((uint32_t)0x00000004)
  215. /**
  216. * @}
  217. */
  218. /** @defgroup SDIO_DSM_State
  219. * @{
  220. */
  221. #define SDIO_DSMSTATE_DISABLE ((uint32_t)0x00000000)
  222. #define SDIO_DSMSTATE_ENABLE ((uint32_t)0x00000001)
  223. /**
  224. * @}
  225. */
  226. /** @defgroup SDIO_Flag
  227. * @{
  228. */
  229. #define SDIO_FLAG_CCRCFAIL ((uint32_t)0x00000001)
  230. #define SDIO_FLAG_DTCRCFAIL ((uint32_t)0x00000002)
  231. #define SDIO_FLAG_CMDTMOUT ((uint32_t)0x00000004)
  232. #define SDIO_FLAG_DTTMOUT ((uint32_t)0x00000008)
  233. #define SDIO_FLAG_TXURE ((uint32_t)0x00000010)
  234. #define SDIO_FLAG_RXORE ((uint32_t)0x00000020)
  235. #define SDIO_FLAG_CMDREND ((uint32_t)0x00000040)
  236. #define SDIO_FLAG_CMDSENT ((uint32_t)0x00000080)
  237. #define SDIO_FLAG_DTEND ((uint32_t)0x00000100)
  238. #define SDIO_FLAG_STBITE ((uint32_t)0x00000200)
  239. #define SDIO_FLAG_DTBLKEND ((uint32_t)0x00000400)
  240. #define SDIO_FLAG_CMDRUN ((uint32_t)0x00000800)
  241. #define SDIO_FLAG_TXRUN ((uint32_t)0x00001000)
  242. #define SDIO_FLAG_RXRUN ((uint32_t)0x00002000)
  243. #define SDIO_FLAG_TXFIFOHE ((uint32_t)0x00004000)
  244. #define SDIO_FLAG_RXFIFOHF ((uint32_t)0x00008000)
  245. #define SDIO_FLAG_TXFIFOF ((uint32_t)0x00010000)
  246. #define SDIO_FLAG_RXFIFOF ((uint32_t)0x00020000)
  247. #define SDIO_FLAG_TXFIFOE ((uint32_t)0x00040000)
  248. #define SDIO_FLAG_RXFIFOE ((uint32_t)0x00080000)
  249. #define SDIO_FLAG_TXDTVAL ((uint32_t)0x00100000)
  250. #define SDIO_FLAG_RXDTVAL ((uint32_t)0x00200000)
  251. #define SDIO_FLAG_SDIOINT ((uint32_t)0x00400000)
  252. #define SDIO_FLAG_ATAEND ((uint32_t)0x00800000)
  253. /**
  254. * @}
  255. */
  256. /** @defgroup SDIO_Read_Wait_Mode
  257. * @{
  258. */
  259. #define SDIO_READWAITMODE_CLK ((uint32_t)0x00000001)
  260. #define SDIO_READWAITMODE_DAT2 ((uint32_t)0x00000000)
  261. /**
  262. * @}
  263. */
  264. /**
  265. * @}
  266. */
  267. /** @defgroup SDIO_Exported_Functions
  268. * @{
  269. */
  270. void SDIO_DeInit(void);
  271. void SDIO_Init(SDIO_InitPara *SDIO_InitParaStruct);
  272. void SDIO_ParaInit(SDIO_InitPara *SDIO_InitParaStruct);
  273. void SDIO_Clock_Enable(TypeState NewState);
  274. void SDIO_SetPWRState(uint32_t SDIO_PWRState);
  275. uint32_t SDIO_GetPWRState(void);
  276. void SDIO_INTConfig(uint32_t SDIO_INT, TypeState NewState);
  277. void SDIO_DMA_Enable(TypeState NewState);
  278. void SDIO_SendCMD(SDIO_CmdInitPara *SDIO_CmdInitParaStruct);
  279. void SDIO_CMDParaInit(SDIO_CmdInitPara *SDIO_CmdInitParaStruct);
  280. uint8_t SDIO_GetCMDResponse(void);
  281. uint32_t SDIO_GetResponse(uint32_t SDIO_RESP);
  282. void SDIO_DataConfig(SDIO_DataInitPara *SDIO_DataInitParaStruct);
  283. void SDIO_DataParaInit(SDIO_DataInitPara *SDIO_DataInitParaStruct);
  284. uint32_t SDIO_GetDataCount(void);
  285. uint32_t SDIO_ReadData(void);
  286. void SDIO_WriteData(uint32_t Data);
  287. uint32_t SDIO_GetFIFOCount(void);
  288. void SDIO_StartSDIOReadWait(TypeState NewState);
  289. void SDIO_StopSDIOReadWait(TypeState NewState);
  290. void SDIO_SetSDIOReadWaitMode(uint32_t SDIO_ReadWaitMode);
  291. void SDIO_SetSDIOOperation(TypeState NewState);
  292. void SDIO_SendSDIOSuspend_Enable(TypeState NewState);
  293. void SDIO_CMDCompletion_Enable(TypeState NewState);
  294. void SDIO_CEATAInt_Enable(TypeState NewState);
  295. void SDIO_SendCEATA_Enable(TypeState NewState);
  296. TypeState SDIO_GetBitState(uint32_t SDIO_FLAG);
  297. void SDIO_ClearBitState(uint32_t SDIO_FLAG);
  298. TypeState SDIO_GetIntBitState(uint32_t SDIO_INT);
  299. void SDIO_ClearIntBitState(uint32_t SDIO_INT);
  300. #ifdef __cplusplus
  301. }
  302. #endif
  303. #endif /* __GD32F10X_SDIO_H */
  304. /**
  305. * @}
  306. */
  307. /**
  308. * @}
  309. */
  310. /**
  311. * @}
  312. */