apm32e10x_sdio.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. /*!
  2. * @file apm32e10x_sdio.h
  3. *
  4. * @brief This file contains all the functions prototypes for the SDIO firmware library
  5. *
  6. * @version V1.0.2
  7. *
  8. * @date 2022-12-31
  9. *
  10. * @attention
  11. *
  12. * Copyright (C) 2021-2023 Geehy Semiconductor
  13. *
  14. * You may not use this file except in compliance with the
  15. * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
  16. *
  17. * The program is only for reference, which is distributed in the hope
  18. * that it will be useful and instructional for customers to develop
  19. * their software. Unless required by applicable law or agreed to in
  20. * writing, the program is distributed on an "AS IS" BASIS, WITHOUT
  21. * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
  23. * and limitations under the License.
  24. */
  25. /* Define to prevent recursive inclusion */
  26. #ifndef __APM32E10X_SDIO_H
  27. #define __APM32E10X_SDIO_H
  28. /* Includes */
  29. #include "apm32e10x.h"
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /** @addtogroup APM32E10x_StdPeriphDriver
  34. @{
  35. */
  36. /** @addtogroup SDIO_Driver
  37. @{
  38. */
  39. /** @defgroup SDIO_Macros Macros
  40. @{
  41. */
  42. /* ------------ SDIO registers bit address in the alias region ----------- */
  43. #define SDIO_OFFSET (SDIO_BASE - PERIPH_BASE)
  44. /* --- CLKCTRL Register ---*/
  45. /* Alias word address of CLKEN bit */
  46. #define CLKCTRL_OFFSET (SDIO_OFFSET + 0x04)
  47. #define CLKEN_BitNumber 0x08
  48. #define CLKCTRL_CLKEN_BB (PERIPH_BB_BASE + (CLKCTRL_OFFSET * 32) + (CLKEN_BitNumber * 4))
  49. /* --- CMD Register --- */
  50. /* Alias word address of SDIOSC bit */
  51. #define CMD_OFFSET (SDIO_OFFSET + 0x0C)
  52. #define SDIOSC_BitNumber 0x0B
  53. #define CMD_SDIOSC_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (SDIOSC_BitNumber * 4))
  54. /* Alias word address of CMDCPEN bit */
  55. #define CMDCPEN_BitNumber 0x0C
  56. #define CMD_CMDCPEN_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (CMDCPEN_BitNumber * 4))
  57. /* Alias word address of INTEN bit */
  58. #define INTEN_BitNumber 0x0D
  59. #define CMD_INTEN_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (INTEN_BitNumber * 4))
  60. /* Alias word address of ATACMD bit */
  61. #define ATACMD_BitNumber 0x0E
  62. #define CMD_ATACMD_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (ATACMD_BitNumber * 4))
  63. /* --- DCTRL Register --- */
  64. /* Alias word address of DMAEN bit */
  65. #define DCTRL_OFFSET (SDIO_OFFSET + 0x2C)
  66. #define DMAEN_BitNumber 0x03
  67. #define DCTRL_DMAEN_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (DMAEN_BitNumber * 4))
  68. /* Alias word address of RWSTR bit */
  69. #define RWSTR_BitNumber 0x08
  70. #define DCTRL_RWSTR_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (RWSTR_BitNumber * 4))
  71. /* Alias word address of RWSTOP bit */
  72. #define RWSTOP_BitNumber 0x09
  73. #define DCTRL_RWSTOP_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (RWSTOP_BitNumber * 4))
  74. /* Alias word address of RDWAIT bit */
  75. #define RDWAIT_BitNumber 0x0A
  76. #define DCTRL_RDWAIT_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (RDWAIT_BitNumber * 4))
  77. /* Alias word address of SDIOF bit */
  78. #define SDIOF_BitNumber 0x0B
  79. #define DCTRL_SDIOF_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (SDIOF_BitNumber * 4))
  80. /**@} end of group SDIO_Macros */
  81. /** @defgroup SDIO_Enumerations Enumerations
  82. @{
  83. */
  84. /**
  85. * @brief SDIO clock edge
  86. */
  87. typedef enum
  88. {
  89. SDIO_CLOCK_EDGE_RISING = 0x00000000,
  90. SDIO_CLOCK_EDGE_FALLING = 0x00002000
  91. }SDIO_CLOCK_EDGE_T;
  92. /**
  93. * @brief SDIO clock bypass
  94. */
  95. typedef enum
  96. {
  97. SDIO_CLOCK_BYPASS_DISABLE = 0x00000000,
  98. SDIO_CLOCK_BYPASS_ENABLE = 0x00000400
  99. }SDIO_CLOCK_BYPASS_T;
  100. /**
  101. * @brief SDIO clock power save
  102. */
  103. typedef enum
  104. {
  105. SDIO_CLOCK_POWER_SAVE_DISABLE = 0x00000000,
  106. SDIO_CLOCK_POWER_SAVE_ENABLE = 0x00000200
  107. }SDIO_CLOCK_POWER_SAVE_T;
  108. /**
  109. * @brief SDIO bus wide
  110. */
  111. typedef enum
  112. {
  113. SDIO_BUSWIDE_1B = 0x00000000,
  114. SDIO_BUSWIDE_4B = 0x00000800,
  115. SDIO_BUSWIDE_8B = 0x00001000
  116. }SDIO_BUSWIDE_T;
  117. /**
  118. * @brief SDIO hardware flow control
  119. */
  120. typedef enum
  121. {
  122. SDIO_HARDWARE_FLOW_CONTROL_DISABLE = 0x00000000,
  123. SDIO_HARDWARE_FLOW_CONTROL_ENABLE = 0x00004000
  124. }SDIO_HARDWARE_FLOW_CONTROL_T;
  125. /**
  126. * @brief SDIO power state
  127. */
  128. typedef enum
  129. {
  130. SDIO_POWER_STATE_OFF = 0x00000000,
  131. SDIO_POWER_STATE_ON = 0x00000003
  132. }SDIO_POWER_STATE_T;
  133. /**
  134. * @brief SDIO interrupt sources
  135. */
  136. typedef enum
  137. {
  138. SDIO_INT_COMRESP = 0x00000001,
  139. SDIO_INT_DBDR = 0x00000002,
  140. SDIO_INT_CMDRESTO = 0x00000004,
  141. SDIO_INT_DATATO = 0x00000008,
  142. SDIO_INT_TXUDRER = 0x00000010,
  143. SDIO_INT_RXOVRER = 0x00000020,
  144. SDIO_INT_CMDRES = 0x00000040,
  145. SDIO_INT_CMDSENT = 0x00000080,
  146. SDIO_INT_DATAEND = 0x00000100,
  147. SDIO_INT_SBE = 0x00000200,
  148. SDIO_INT_DBCP = 0x00000400,
  149. SDIO_INT_CMDACT = 0x00000800,
  150. SDIO_INT_TXACT = 0x00001000,
  151. SDIO_INT_RXACT = 0x00002000,
  152. SDIO_INT_TXFHF = 0x00004000,
  153. SDIO_INT_RXFHF = 0x00008000,
  154. SDIO_INT_TXFF = 0x00010000,
  155. SDIO_INT_RXFF = 0x00020000,
  156. SDIO_INT_TXFE = 0x00040000,
  157. SDIO_INT_RXFE = 0x00080000,
  158. SDIO_INT_TXDA = 0x00100000,
  159. SDIO_INT_RXDA = 0x00200000,
  160. SDIO_INT_SDIOINT = 0x00400000,
  161. SDIO_INT_ATAEND = 0x00800000
  162. }SDIO_INT_T;
  163. /**
  164. * @brief SDIO response
  165. */
  166. typedef enum
  167. {
  168. SDIO_RESPONSE_NO = 0x00000000,
  169. SDIO_RESPONSE_SHORT = 0x00000040,
  170. SDIO_RESPONSE_LONG = 0x000000C0
  171. }SDIO_RESPONSE_T;
  172. /**
  173. * @brief SDIO wait interrupt state
  174. */
  175. typedef enum
  176. {
  177. SDIO_WAIT_NO = 0x00000000,
  178. SDIO_WAIT_INT = 0x00000100,
  179. SDIO_WAIT_PEND = 0x00000200
  180. }SDIO_WAIT_T;
  181. /**
  182. * @brief SDIO CPSM state
  183. */
  184. typedef enum
  185. {
  186. SDIO_CPSM_DISABLE = 0x00000000,
  187. SDIO_CPSM_ENABLE = 0x00000400
  188. }SDIO_CPSM_T;
  189. /**
  190. * @brief SDIO response registers
  191. */
  192. typedef enum
  193. {
  194. SDIO_RES1 = 0x00000000,
  195. SDIO_RES2 = 0x00000004,
  196. SDIO_RES3 = 0x00000008,
  197. SDIO_RES4 = 0x0000000C
  198. }SDIO_RES_T;
  199. /**
  200. * @brief SDIO data block size
  201. */
  202. typedef enum
  203. {
  204. SDIO_DATA_BLOCKSIZE_1B = 0x00000000,
  205. SDIO_DATA_BLOCKSIZE_2B = 0x00000010,
  206. SDIO_DATA_BLOCKSIZE_4B = 0x00000020,
  207. SDIO_DATA_BLOCKSIZE_8B = 0x00000030,
  208. SDIO_DATA_BLOCKSIZE_16B = 0x00000040,
  209. SDIO_DATA_BLOCKSIZE_32B = 0x00000050,
  210. SDIO_DATA_BLOCKSIZE_64B = 0x00000060,
  211. SDIO_DATA_BLOCKSIZE_128B = 0x00000070,
  212. SDIO_DATA_BLOCKSIZE_256B = 0x00000080,
  213. SDIO_DATA_BLOCKSIZE_512B = 0x00000090,
  214. SDIO_DATA_BLOCKSIZE_1024B = 0x000000A0,
  215. SDIO_DATA_BLOCKSIZE_2048B = 0x000000B0,
  216. SDIO_DATA_BLOCKSIZE_496B = 0x000000C0,
  217. SDIO_DATA_BLOCKSIZE_8192B = 0x000000D0,
  218. SDIO_DATA_BLOCKSIZE_16384B = 0x000000E0
  219. }SDIO_DATA_BLOCKSIZE_T;
  220. /**
  221. * @brief SDIO transfer direction
  222. */
  223. typedef enum
  224. {
  225. SDIO_TRANSFER_DIR_TOCARD = 0x00000000,
  226. SDIO_TRANSFER_DIR_TOSDIO = 0x00000002
  227. }SDIO_TRANSFER_DIR_T;
  228. /**
  229. * @brief SDIO transfer type
  230. */
  231. typedef enum
  232. {
  233. SDIO_TRANSFER_MODE_BLOCK = 0x00000000,
  234. SDIO_TRANSFER_MODE_STREAM = 0x00000004
  235. }SDIO_TRANSFER_MODE_T;
  236. /**
  237. * @brief SDIO DPSM state
  238. */
  239. typedef enum
  240. {
  241. SDIO_DPSM_DISABLE = 0x00000000,
  242. SDIO_DPSM_ENABLE = 0x00000001
  243. }SDIO_DPSM_T;
  244. /**
  245. * @brief SDIO flag
  246. */
  247. typedef enum
  248. {
  249. SDIO_FLAG_COMRESP = 0x00000001,
  250. SDIO_FLAG_DBDR = 0x00000002,
  251. SDIO_FLAG_CMDRESTO = 0x00000004,
  252. SDIO_FLAG_DATATO = 0x00000008,
  253. SDIO_FLAG_TXUDRER = 0x00000010,
  254. SDIO_FLAG_RXOVRER = 0x00000020,
  255. SDIO_FLAG_CMDRES = 0x00000040,
  256. SDIO_FLAG_CMDSENT = 0x00000080,
  257. SDIO_FLAG_DATAEND = 0x00000100,
  258. SDIO_FLAG_SBE = 0x00000200,
  259. SDIO_FLAG_DBCP = 0x00000400,
  260. SDIO_FLAG_CMDACT = 0x00000800,
  261. SDIO_FLAG_TXACT = 0x00001000,
  262. SDIO_FLAG_RXACT = 0x00002000,
  263. SDIO_FLAG_TXFHF = 0x00004000,
  264. SDIO_FLAG_RXFHF = 0x00008000,
  265. SDIO_FLAG_TXFF = 0x00010000,
  266. SDIO_FLAG_RXFF = 0x00020000,
  267. SDIO_FLAG_TXFE = 0x00040000,
  268. SDIO_FLAG_RXFE = 0x00080000,
  269. SDIO_FLAG_TXDA = 0x00100000,
  270. SDIO_FLAG_RXDA = 0x00200000,
  271. SDIO_FLAG_SDIOINT = 0x00400000,
  272. SDIO_FLAG_ATAEND = 0x00800000
  273. }SDIO_FLAG_T;
  274. /**
  275. * @brief SDIO read wait mode
  276. */
  277. typedef enum
  278. {
  279. SDIO_READ_WAIT_MODE_CLK = 0x00000001,
  280. SDIO_READ_WAIT_MODE_DATA2 = 0x00000000
  281. }SDIO_READ_WAIT_MODE_T;
  282. /**@} end of group SDIO_Enumerations */
  283. /** @defgroup SDIO_Structures Structures
  284. @{
  285. */
  286. /**
  287. * @brief SDIO Config structure definition
  288. */
  289. typedef struct
  290. {
  291. SDIO_CLOCK_EDGE_T clockEdge;
  292. SDIO_CLOCK_BYPASS_T clockBypass;
  293. SDIO_CLOCK_POWER_SAVE_T clockPowerSave;
  294. SDIO_BUSWIDE_T busWide;
  295. SDIO_HARDWARE_FLOW_CONTROL_T hardwareFlowControl;
  296. uint8_t clockDiv;
  297. }SDIO_Config_T;
  298. /**
  299. * @brief SDIO CMD Config structure definition
  300. */
  301. typedef struct
  302. {
  303. uint32_t argument;
  304. uint32_t cmdIndex;
  305. SDIO_RESPONSE_T response;
  306. SDIO_WAIT_T wait;
  307. SDIO_CPSM_T CPSM;
  308. }SDIO_CMDConfig_T;
  309. /**
  310. * @brief SDIO Data Config structure definition
  311. */
  312. typedef struct
  313. {
  314. uint32_t dataTimeOut;
  315. uint32_t dataLength;
  316. SDIO_DATA_BLOCKSIZE_T dataBlockSize;
  317. SDIO_TRANSFER_DIR_T transferDir;
  318. SDIO_TRANSFER_MODE_T transferMode;
  319. SDIO_DPSM_T DPSM;
  320. }SDIO_DataConfig_T;
  321. /**@} end of group SDIO_Structures */
  322. /** @defgroup SDIO_Functions Functions
  323. @{
  324. */
  325. /* SDIO reset and configuration */
  326. void SDIO_Reset(void);
  327. void SDIO_Config(SDIO_Config_T* sdioConfig);
  328. void SDIO_ConfigStructInit(SDIO_Config_T* sdioConfig);
  329. void SDIO_EnableClock(void);
  330. void SDIO_DisableClock(void);
  331. void SDIO_ConfigPowerState(SDIO_POWER_STATE_T powerState);
  332. uint32_t SDIO_ReadPowerState(void);
  333. /* DMA */
  334. void SDIO_EnableDMA(void);
  335. void SDIO_DisableDMA(void);
  336. /* Command */
  337. void SDIO_TxCommand(SDIO_CMDConfig_T *cmdConfig);
  338. void SDIO_TxCommandStructInit(SDIO_CMDConfig_T* cmdconfig);
  339. uint8_t SDIO_ReadCommandResponse(void);
  340. uint32_t SDIO_ReadResponse(SDIO_RES_T res);
  341. /* SDIO data configuration */
  342. void SDIO_ConfigData(SDIO_DataConfig_T* dataConfig);
  343. void SDIO_ConfigDataStructInit(SDIO_DataConfig_T* dataConfig);
  344. uint32_t SDIO_ReadDataCounter(void);
  345. void SDIO_WriteData(uint32_t data);
  346. uint32_t SDIO_ReadData(void);
  347. uint32_t SDIO_ReadFIFOCount(void);
  348. /* SDIO mode */
  349. void SDIO_EnableStartReadWait(void);
  350. void SDIO_DisableStartReadWait(void);
  351. void SDIO_EnableStopReadWait(void);
  352. void SDIO_DisableStopReadWait(void);
  353. void SDIO_ConfigSDIOReadWaitMode(SDIO_READ_WAIT_MODE_T readWaitMode);
  354. void SDIO_EnableSDIO(void);
  355. void SDIO_DisableSDIO(void);
  356. void SDIO_EnableTxSDIOSuspend(void);
  357. void SDIO_DisableTxSDIOSuspend(void);
  358. void SDIO_EnableCommandCompletion(void);
  359. void SDIO_DisableCommandCompletion(void);
  360. void SDIO_EnableCEATAInterrupt(void);
  361. void SDIO_DisableCEATAInterrupt(void);
  362. void SDIO_EnableTxCEATA(void);
  363. void SDIO_DisableTxCEATA(void);
  364. /* Interrupt and flags */
  365. void SDIO_EnableInterrupt(uint32_t interrupt);
  366. void SDIO_DisableInterrupt(uint32_t interrupt);
  367. uint8_t SDIO_ReadStatusFlag(SDIO_FLAG_T flag);
  368. void SDIO_ClearStatusFlag(uint32_t flag);
  369. uint8_t SDIO_ReadIntFlag(SDIO_INT_T flag);
  370. void SDIO_ClearIntFlag(uint32_t flag);
  371. /**@} end of group SDIO_Functions*/
  372. /**@} end of group SDIO_Driver*/
  373. /**@} end of group APM32E10x_StdPeriphDriver*/
  374. #ifdef __cplusplus
  375. }
  376. #endif
  377. #endif /* __APM32E10X_SDIO_H */