gd32f10x_sdio.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. /*!
  2. \file gd32f10x_sdio.c
  3. \brief SDIO driver
  4. \version 2014-12-26, V1.0.0, firmware for GD32F10x
  5. \version 2017-06-20, V2.0.0, firmware for GD32F10x
  6. \version 2018-07-31, V2.1.0, firmware for GD32F10x
  7. \version 2020-09-30, V2.2.0, firmware for GD32F10x
  8. */
  9. /*
  10. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  11. Redistribution and use in source and binary forms, with or without modification,
  12. are permitted provided that the following conditions are met:
  13. 1. Redistributions of source code must retain the above copyright notice, this
  14. list of conditions and the following disclaimer.
  15. 2. Redistributions in binary form must reproduce the above copyright notice,
  16. this list of conditions and the following disclaimer in the documentation
  17. and/or other materials provided with the distribution.
  18. 3. Neither the name of the copyright holder nor the names of its contributors
  19. may be used to endorse or promote products derived from this software without
  20. specific prior written permission.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  23. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  25. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  30. OF SUCH DAMAGE.
  31. */
  32. #include "gd32f10x_sdio.h"
  33. #define DEFAULT_RESET_VALUE 0x00000000U
  34. /*!
  35. \brief deinitialize the SDIO
  36. \param[in] none
  37. \param[out] none
  38. \retval none
  39. */
  40. void sdio_deinit(void)
  41. {
  42. SDIO_PWRCTL = DEFAULT_RESET_VALUE;
  43. SDIO_CLKCTL = DEFAULT_RESET_VALUE;
  44. SDIO_CMDAGMT = DEFAULT_RESET_VALUE;
  45. SDIO_CMDCTL = DEFAULT_RESET_VALUE;
  46. SDIO_DATATO = DEFAULT_RESET_VALUE;
  47. SDIO_DATALEN = DEFAULT_RESET_VALUE;
  48. SDIO_DATACTL = DEFAULT_RESET_VALUE;
  49. SDIO_INTC = DEFAULT_RESET_VALUE;
  50. SDIO_INTEN = DEFAULT_RESET_VALUE;
  51. }
  52. /*!
  53. \brief configure the SDIO clock
  54. \param[in] clock_edge: SDIO_CLK clock edge
  55. only one parameter can be selected which is shown as below:
  56. \arg SDIO_SDIOCLKEDGE_RISING: select the rising edge of the SDIOCLK to generate SDIO_CLK
  57. \arg SDIO_SDIOCLKEDGE_FALLING: select the falling edge of the SDIOCLK to generate SDIO_CLK
  58. \param[in] clock_bypass: clock bypass
  59. only one parameter can be selected which is shown as below:
  60. \arg SDIO_CLOCKBYPASS_ENABLE: clock bypass
  61. \arg SDIO_CLOCKBYPASS_DISABLE: no bypass
  62. \param[in] clock_powersave: SDIO_CLK clock dynamic switch on/off for power saving
  63. only one parameter can be selected which is shown as below:
  64. \arg SDIO_CLOCKPWRSAVE_ENABLE: SDIO_CLK closed when bus is idle
  65. \arg SDIO_CLOCKPWRSAVE_DISABLE: SDIO_CLK clock is always on
  66. \param[in] clock_division: clock division, less than 256
  67. \param[out] none
  68. \retval none
  69. */
  70. void sdio_clock_config(uint32_t clock_edge, uint32_t clock_bypass, uint32_t clock_powersave, uint16_t clock_division)
  71. {
  72. uint32_t clock_config = 0U;
  73. clock_config = SDIO_CLKCTL;
  74. /* reset the CLKEDGE, CLKBYP, CLKPWRSAV, DIV */
  75. clock_config &= ~(SDIO_CLKCTL_CLKEDGE | SDIO_CLKCTL_CLKBYP | SDIO_CLKCTL_CLKPWRSAV | SDIO_CLKCTL_DIV);
  76. /* configure the SDIO_CLKCTL according to the parameters */
  77. clock_config |= (clock_edge | clock_bypass | clock_powersave | clock_division);
  78. SDIO_CLKCTL = clock_config;
  79. }
  80. /*!
  81. \brief enable hardware clock control
  82. \param[in] none
  83. \param[out] none
  84. \retval none
  85. */
  86. void sdio_hardware_clock_enable(void)
  87. {
  88. SDIO_CLKCTL |= SDIO_CLKCTL_HWCLKEN;
  89. }
  90. /*!
  91. \brief disable hardware clock control
  92. \param[in] none
  93. \param[out] none
  94. \retval none
  95. */
  96. void sdio_hardware_clock_disable(void)
  97. {
  98. SDIO_CLKCTL &= ~SDIO_CLKCTL_HWCLKEN;
  99. }
  100. /*!
  101. \brief set different SDIO card bus mode
  102. \param[in] bus_mode: SDIO card bus mode
  103. only one parameter can be selected which is shown as below:
  104. \arg SDIO_BUSMODE_1BIT: 1-bit SDIO card bus mode
  105. \arg SDIO_BUSMODE_4BIT: 4-bit SDIO card bus mode
  106. \arg SDIO_BUSMODE_8BIT: 8-bit SDIO card bus mode
  107. \param[out] none
  108. \retval none
  109. */
  110. void sdio_bus_mode_set(uint32_t bus_mode)
  111. {
  112. /* reset the SDIO card bus mode bits and set according to bus_mode */
  113. SDIO_CLKCTL &= ~SDIO_CLKCTL_BUSMODE;
  114. SDIO_CLKCTL |= bus_mode;
  115. }
  116. /*!
  117. \brief set the SDIO power state
  118. \param[in] power_state: SDIO power state
  119. only one parameter can be selected which is shown as below:
  120. \arg SDIO_POWER_ON: SDIO power on
  121. \arg SDIO_POWER_OFF: SDIO power off
  122. \param[out] none
  123. \retval none
  124. */
  125. void sdio_power_state_set(uint32_t power_state)
  126. {
  127. SDIO_PWRCTL = power_state;
  128. }
  129. /*!
  130. \brief get the SDIO power state
  131. \param[in] none
  132. \param[out] none
  133. \retval SDIO power state
  134. only one parameter can be selected which is shown as below:
  135. \arg SDIO_POWER_ON: SDIO power on
  136. \arg SDIO_POWER_OFF: SDIO power off
  137. */
  138. uint32_t sdio_power_state_get(void)
  139. {
  140. return SDIO_PWRCTL;
  141. }
  142. /*!
  143. \brief enable SDIO_CLK clock output
  144. \param[in] none
  145. \param[out] none
  146. \retval none
  147. */
  148. void sdio_clock_enable(void)
  149. {
  150. SDIO_CLKCTL |= SDIO_CLKCTL_CLKEN;
  151. }
  152. /*!
  153. \brief disable SDIO_CLK clock output
  154. \param[in] none
  155. \param[out] none
  156. \retval none
  157. */
  158. void sdio_clock_disable(void)
  159. {
  160. SDIO_CLKCTL &= ~SDIO_CLKCTL_CLKEN;
  161. }
  162. /*!
  163. \brief configure the command and response
  164. \param[in] cmd_index: command index, refer to the related specifications
  165. \param[in] cmd_argument: command argument, refer to the related specifications
  166. \param[in] response_type: response type
  167. only one parameter can be selected which is shown as below:
  168. \arg SDIO_RESPONSETYPE_NO: no response
  169. \arg SDIO_RESPONSETYPE_SHORT: short response
  170. \arg SDIO_RESPONSETYPE_LONG: long response
  171. \param[out] none
  172. \retval none
  173. */
  174. void sdio_command_response_config(uint32_t cmd_index, uint32_t cmd_argument, uint32_t response_type)
  175. {
  176. uint32_t cmd_config = 0U;
  177. /* reset the command index, command argument and response type */
  178. SDIO_CMDAGMT &= ~SDIO_CMDAGMT_CMDAGMT;
  179. SDIO_CMDAGMT = cmd_argument;
  180. cmd_config = SDIO_CMDCTL;
  181. cmd_config &= ~(SDIO_CMDCTL_CMDIDX | SDIO_CMDCTL_CMDRESP);
  182. /* configure SDIO_CMDCTL and SDIO_CMDAGMT according to the parameters */
  183. cmd_config |= (cmd_index | response_type);
  184. SDIO_CMDCTL = cmd_config;
  185. }
  186. /*!
  187. \brief set the command state machine wait type
  188. \param[in] wait_type: wait type
  189. only one parameter can be selected which is shown as below:
  190. \arg SDIO_WAITTYPE_NO: not wait interrupt
  191. \arg SDIO_WAITTYPE_INTERRUPT: wait interrupt
  192. \arg SDIO_WAITTYPE_DATAEND: wait the end of data transfer
  193. \param[out] none
  194. \retval none
  195. */
  196. void sdio_wait_type_set(uint32_t wait_type)
  197. {
  198. /* reset INTWAIT and WAITDEND */
  199. SDIO_CMDCTL &= ~(SDIO_CMDCTL_INTWAIT | SDIO_CMDCTL_WAITDEND);
  200. /* set the wait type according to wait_type */
  201. SDIO_CMDCTL |= wait_type;
  202. }
  203. /*!
  204. \brief enable the CSM(command state machine)
  205. \param[in] none
  206. \param[out] none
  207. \retval none
  208. */
  209. void sdio_csm_enable(void)
  210. {
  211. SDIO_CMDCTL |= SDIO_CMDCTL_CSMEN;
  212. }
  213. /*!
  214. \brief disable the CSM(command state machine)
  215. \param[in] none
  216. \param[out] none
  217. \retval none
  218. */
  219. void sdio_csm_disable(void)
  220. {
  221. SDIO_CMDCTL &= ~SDIO_CMDCTL_CSMEN;
  222. }
  223. /*!
  224. \brief get the last response command index
  225. \param[in] none
  226. \param[out] none
  227. \retval last response command index
  228. */
  229. uint8_t sdio_command_index_get(void)
  230. {
  231. return (uint8_t)SDIO_RSPCMDIDX;
  232. }
  233. /*!
  234. \brief get the response for the last received command
  235. \param[in] responsex: SDIO response
  236. only one parameter can be selected which is shown as below:
  237. \arg SDIO_RESPONSE0: card response[31:0]/card response[127:96]
  238. \arg SDIO_RESPONSE1: card response[95:64]
  239. \arg SDIO_RESPONSE2: card response[63:32]
  240. \arg SDIO_RESPONSE3: card response[31:1], plus bit 0
  241. \param[out] none
  242. \retval response for the last received command
  243. */
  244. uint32_t sdio_response_get(uint32_t responsex)
  245. {
  246. uint32_t resp_content = 0U;
  247. switch(responsex){
  248. case SDIO_RESPONSE0:
  249. resp_content = SDIO_RESP0;
  250. break;
  251. case SDIO_RESPONSE1:
  252. resp_content = SDIO_RESP1;
  253. break;
  254. case SDIO_RESPONSE2:
  255. resp_content = SDIO_RESP2;
  256. break;
  257. case SDIO_RESPONSE3:
  258. resp_content = SDIO_RESP3;
  259. break;
  260. default:
  261. break;
  262. }
  263. return resp_content;
  264. }
  265. /*!
  266. \brief configure the data timeout, data length and data block size
  267. \param[in] data_timeout: data timeout period in card bus clock periods
  268. \param[in] data_length: number of data bytes to be transferred
  269. \param[in] data_blocksize: size of data block for block transfer
  270. only one parameter can be selected which is shown as below:
  271. \arg SDIO_DATABLOCKSIZE_1BYTE: block size = 1 byte
  272. \arg SDIO_DATABLOCKSIZE_2BYTES: block size = 2 bytes
  273. \arg SDIO_DATABLOCKSIZE_4BYTES: block size = 4 bytes
  274. \arg SDIO_DATABLOCKSIZE_8BYTES: block size = 8 bytes
  275. \arg SDIO_DATABLOCKSIZE_16BYTES: block size = 16 bytes
  276. \arg SDIO_DATABLOCKSIZE_32BYTES: block size = 32 bytes
  277. \arg SDIO_DATABLOCKSIZE_64BYTES: block size = 64 bytes
  278. \arg SDIO_DATABLOCKSIZE_128BYTES: block size = 128 bytes
  279. \arg SDIO_DATABLOCKSIZE_256BYTES: block size = 256 bytes
  280. \arg SDIO_DATABLOCKSIZE_512BYTES: block size = 512 bytes
  281. \arg SDIO_DATABLOCKSIZE_1024BYTES: block size = 1024 bytes
  282. \arg SDIO_DATABLOCKSIZE_2048BYTES: block size = 2048 bytes
  283. \arg SDIO_DATABLOCKSIZE_4096BYTES: block size = 4096 bytes
  284. \arg SDIO_DATABLOCKSIZE_8192BYTES: block size = 8192 bytes
  285. \arg SDIO_DATABLOCKSIZE_16384BYTES: block size = 16384 bytes
  286. \param[out] none
  287. \retval none
  288. */
  289. void sdio_data_config(uint32_t data_timeout, uint32_t data_length, uint32_t data_blocksize)
  290. {
  291. /* reset data timeout, data length and data block size */
  292. SDIO_DATATO &= ~SDIO_DATATO_DATATO;
  293. SDIO_DATALEN &= ~SDIO_DATALEN_DATALEN;
  294. SDIO_DATACTL &= ~SDIO_DATACTL_BLKSZ;
  295. /* configure the related parameters of data */
  296. SDIO_DATATO = data_timeout;
  297. SDIO_DATALEN = data_length;
  298. SDIO_DATACTL |= data_blocksize;
  299. }
  300. /*!
  301. \brief configure the data transfer mode and direction
  302. \param[in] transfer_mode: mode of data transfer
  303. only one parameter can be selected which is shown as below:
  304. \arg SDIO_TRANSMODE_BLOCK: block transfer
  305. \arg SDIO_TRANSMODE_STREAM: stream transfer or SDIO multibyte transfer
  306. \param[in] transfer_direction: data transfer direction, read or write
  307. only one parameter can be selected which is shown as below:
  308. \arg SDIO_TRANSDIRECTION_TOCARD: write data to card
  309. \arg SDIO_TRANSDIRECTION_TOSDIO: read data from card
  310. \param[out] none
  311. \retval none
  312. */
  313. void sdio_data_transfer_config(uint32_t transfer_mode, uint32_t transfer_direction)
  314. {
  315. uint32_t data_trans = 0U;
  316. /* reset the data transfer mode, transfer direction and set according to the parameters */
  317. data_trans = SDIO_DATACTL;
  318. data_trans &= ~(SDIO_DATACTL_TRANSMOD | SDIO_DATACTL_DATADIR);
  319. data_trans |= (transfer_mode | transfer_direction);
  320. SDIO_DATACTL = data_trans;
  321. }
  322. /*!
  323. \brief enable the DSM(data state machine) for data transfer
  324. \param[in] none
  325. \param[out] none
  326. \retval none
  327. */
  328. void sdio_dsm_enable(void)
  329. {
  330. SDIO_DATACTL |= SDIO_DATACTL_DATAEN;
  331. }
  332. /*!
  333. \brief disable the DSM(data state machine)
  334. \param[in] none
  335. \param[out] none
  336. \retval none
  337. */
  338. void sdio_dsm_disable(void)
  339. {
  340. SDIO_DATACTL &= ~SDIO_DATACTL_DATAEN;
  341. }
  342. /*!
  343. \brief write data(one word) to the transmit FIFO
  344. \param[in] data: 32-bit data write to card
  345. \param[out] none
  346. \retval none
  347. */
  348. void sdio_data_write(uint32_t data)
  349. {
  350. SDIO_FIFO = data;
  351. }
  352. /*!
  353. \brief read data(one word) from the receive FIFO
  354. \param[in] none
  355. \param[out] none
  356. \retval received data
  357. */
  358. uint32_t sdio_data_read(void)
  359. {
  360. return SDIO_FIFO;
  361. }
  362. /*!
  363. \brief get the number of remaining data bytes to be transferred to card
  364. \param[in] none
  365. \param[out] none
  366. \retval number of remaining data bytes to be transferred
  367. */
  368. uint32_t sdio_data_counter_get(void)
  369. {
  370. return SDIO_DATACNT;
  371. }
  372. /*!
  373. \brief get the number of words remaining to be written or read from FIFO
  374. \param[in] none
  375. \param[out] none
  376. \retval remaining number of words
  377. */
  378. uint32_t sdio_fifo_counter_get(void)
  379. {
  380. return SDIO_FIFOCNT;
  381. }
  382. /*!
  383. \brief enable the DMA request for SDIO
  384. \param[in] none
  385. \param[out] none
  386. \retval none
  387. */
  388. void sdio_dma_enable(void)
  389. {
  390. SDIO_DATACTL |= SDIO_DATACTL_DMAEN;
  391. }
  392. /*!
  393. \brief disable the DMA request for SDIO
  394. \param[in] none
  395. \param[out] none
  396. \retval none
  397. */
  398. void sdio_dma_disable(void)
  399. {
  400. SDIO_DATACTL &= ~SDIO_DATACTL_DMAEN;
  401. }
  402. /*!
  403. \brief get the flags state of SDIO
  404. \param[in] flag: flags state of SDIO
  405. one or more parameters can be selected which are shown as below:
  406. \arg SDIO_FLAG_CCRCERR: command response received (CRC check failed) flag
  407. \arg SDIO_FLAG_DTCRCERR: data block sent/received (CRC check failed) flag
  408. \arg SDIO_FLAG_CMDTMOUT: command response timeout flag
  409. \arg SDIO_FLAG_DTTMOUT: data timeout flag
  410. \arg SDIO_FLAG_TXURE: transmit FIFO underrun error occurs flag
  411. \arg SDIO_FLAG_RXORE: received FIFO overrun error occurs flag
  412. \arg SDIO_FLAG_CMDRECV: command response received (CRC check passed) flag
  413. \arg SDIO_FLAG_CMDSEND: command sent (no response required) flag
  414. \arg SDIO_FLAG_DTEND: data end (data counter, SDIO_DATACNT, is zero) flag
  415. \arg SDIO_FLAG_STBITE: start bit error in the bus flag
  416. \arg SDIO_FLAG_DTBLKEND: data block sent/received (CRC check passed) flag
  417. \arg SDIO_FLAG_CMDRUN: command transmission in progress flag
  418. \arg SDIO_FLAG_TXRUN: data transmission in progress flag
  419. \arg SDIO_FLAG_RXRUN: data reception in progress flag
  420. \arg SDIO_FLAG_TFH: transmit FIFO is half empty flag: at least 8 words can be written into the FIFO
  421. \arg SDIO_FLAG_RFH: receive FIFO is half full flag: at least 8 words can be read in the FIFO
  422. \arg SDIO_FLAG_TFF: transmit FIFO is full flag
  423. \arg SDIO_FLAG_RFF: receive FIFO is full flag
  424. \arg SDIO_FLAG_TFE: transmit FIFO is empty flag
  425. \arg SDIO_FLAG_RFE: receive FIFO is empty flag
  426. \arg SDIO_FLAG_TXDTVAL: data is valid in transmit FIFO flag
  427. \arg SDIO_FLAG_RXDTVAL: data is valid in receive FIFO flag
  428. \arg SDIO_FLAG_SDIOINT: SD I/O interrupt received flag
  429. \arg SDIO_FLAG_ATAEND: CE-ATA command completion signal received (only for CMD61) flag
  430. \param[out] none
  431. \retval FlagStatus: SET or RESET
  432. */
  433. FlagStatus sdio_flag_get(uint32_t flag)
  434. {
  435. FlagStatus temp_flag = RESET;
  436. if(RESET != (SDIO_STAT & flag)){
  437. temp_flag = SET;
  438. }
  439. return temp_flag;
  440. }
  441. /*!
  442. \brief clear the pending flags of SDIO
  443. \param[in] flag: flags state of SDIO
  444. one or more parameters can be selected which are shown as below:
  445. \arg SDIO_FLAG_CCRCERR: command response received (CRC check failed) flag
  446. \arg SDIO_FLAG_DTCRCERR: data block sent/received (CRC check failed) flag
  447. \arg SDIO_FLAG_CMDTMOUT: command response timeout flag
  448. \arg SDIO_FLAG_DTTMOUT: data timeout flag
  449. \arg SDIO_FLAG_TXURE: transmit FIFO underrun error occurs flag
  450. \arg SDIO_FLAG_RXORE: received FIFO overrun error occurs flag
  451. \arg SDIO_FLAG_CMDRECV: command response received (CRC check passed) flag
  452. \arg SDIO_FLAG_CMDSEND: command sent (no response required) flag
  453. \arg SDIO_FLAG_DTEND: data end (data counter, SDIO_DATACNT, is zero) flag
  454. \arg SDIO_FLAG_STBITE: start bit error in the bus flag
  455. \arg SDIO_FLAG_DTBLKEND: data block sent/received (CRC check passed) flag
  456. \arg SDIO_FLAG_SDIOINT: SD I/O interrupt received flag
  457. \arg SDIO_FLAG_ATAEND: CE-ATA command completion signal received (only for CMD61) flag
  458. \param[out] none
  459. \retval none
  460. */
  461. void sdio_flag_clear(uint32_t flag)
  462. {
  463. SDIO_INTC = flag;
  464. }
  465. /*!
  466. \brief enable the SDIO interrupt
  467. \param[in] int_flag: interrupt flags state of SDIO
  468. one or more parameters can be selected which are shown as below:
  469. \arg SDIO_INT_CCRCERR: SDIO CCRCERR interrupt
  470. \arg SDIO_INT_DTCRCERR: SDIO DTCRCERR interrupt
  471. \arg SDIO_INT_CMDTMOUT: SDIO CMDTMOUT interrupt
  472. \arg SDIO_INT_DTTMOUT: SDIO DTTMOUT interrupt
  473. \arg SDIO_INT_TXURE: SDIO TXURE interrupt
  474. \arg SDIO_INT_RXORE: SDIO RXORE interrupt
  475. \arg SDIO_INT_CMDRECV: SDIO CMDRECV interrupt
  476. \arg SDIO_INT_CMDSEND: SDIO CMDSEND interrupt
  477. \arg SDIO_INT_DTEND: SDIO DTEND interrupt
  478. \arg SDIO_INT_STBITE: SDIO STBITE interrupt
  479. \arg SDIO_INT_DTBLKEND: SDIO DTBLKEND interrupt
  480. \arg SDIO_INT_CMDRUN: SDIO CMDRUN interrupt
  481. \arg SDIO_INT_TXRUN: SDIO TXRUN interrupt
  482. \arg SDIO_INT_RXRUN: SDIO RXRUN interrupt
  483. \arg SDIO_INT_TFH: SDIO TFH interrupt
  484. \arg SDIO_INT_RFH: SDIO RFH interrupt
  485. \arg SDIO_INT_TFF: SDIO TFF interrupt
  486. \arg SDIO_INT_RFF: SDIO RFF interrupt
  487. \arg SDIO_INT_TFE: SDIO TFE interrupt
  488. \arg SDIO_INT_RFE: SDIO RFE interrupt
  489. \arg SDIO_INT_TXDTVAL: SDIO TXDTVAL interrupt
  490. \arg SDIO_INT_RXDTVAL: SDIO RXDTVAL interrupt
  491. \arg SDIO_INT_SDIOINT: SDIO SDIOINT interrupt
  492. \arg SDIO_INT_ATAEND: SDIO ATAEND interrupt
  493. \param[out] none
  494. \retval none
  495. */
  496. void sdio_interrupt_enable(uint32_t int_flag)
  497. {
  498. SDIO_INTEN |= int_flag;
  499. }
  500. /*!
  501. \brief disable the SDIO interrupt
  502. \param[in] int_flag: interrupt flags state of SDIO
  503. one or more parameters can be selected which are shown as below:
  504. \arg SDIO_INT_CCRCERR: SDIO CCRCERR interrupt
  505. \arg SDIO_INT_DTCRCERR: SDIO DTCRCERR interrupt
  506. \arg SDIO_INT_CMDTMOUT: SDIO CMDTMOUT interrupt
  507. \arg SDIO_INT_DTTMOUT: SDIO DTTMOUT interrupt
  508. \arg SDIO_INT_TXURE: SDIO TXURE interrupt
  509. \arg SDIO_INT_RXORE: SDIO RXORE interrupt
  510. \arg SDIO_INT_CMDRECV: SDIO CMDRECV interrupt
  511. \arg SDIO_INT_CMDSEND: SDIO CMDSEND interrupt
  512. \arg SDIO_INT_DTEND: SDIO DTEND interrupt
  513. \arg SDIO_INT_STBITE: SDIO STBITE interrupt
  514. \arg SDIO_INT_DTBLKEND: SDIO DTBLKEND interrupt
  515. \arg SDIO_INT_CMDRUN: SDIO CMDRUN interrupt
  516. \arg SDIO_INT_TXRUN: SDIO TXRUN interrupt
  517. \arg SDIO_INT_RXRUN: SDIO RXRUN interrupt
  518. \arg SDIO_INT_TFH: SDIO TFH interrupt
  519. \arg SDIO_INT_RFH: SDIO RFH interrupt
  520. \arg SDIO_INT_TFF: SDIO TFF interrupt
  521. \arg SDIO_INT_RFF: SDIO RFF interrupt
  522. \arg SDIO_INT_TFE: SDIO TFE interrupt
  523. \arg SDIO_INT_RFE: SDIO RFE interrupt
  524. \arg SDIO_INT_TXDTVAL: SDIO TXDTVAL interrupt
  525. \arg SDIO_INT_RXDTVAL: SDIO RXDTVAL interrupt
  526. \arg SDIO_INT_SDIOINT: SDIO SDIOINT interrupt
  527. \arg SDIO_INT_ATAEND: SDIO ATAEND interrupt
  528. \param[out] none
  529. \retval none
  530. */
  531. void sdio_interrupt_disable(uint32_t int_flag)
  532. {
  533. SDIO_INTEN &= ~int_flag;
  534. }
  535. /*!
  536. \brief get the interrupt flags state of SDIO
  537. \param[in] int_flag: interrupt flags state of SDIO
  538. one or more parameters can be selected which are shown as below:
  539. \arg SDIO_INT_FLAG_CCRCERR: SDIO CCRCERR interrupt flag
  540. \arg SDIO_INT_FLAG_DTCRCERR: SDIO DTCRCERR interrupt flag
  541. \arg SDIO_INT_FLAG_CMDTMOUT: SDIO CMDTMOUT interrupt flag
  542. \arg SDIO_INT_FLAG_DTTMOUT: SDIO DTTMOUT interrupt flag
  543. \arg SDIO_INT_FLAG_TXURE: SDIO TXURE interrupt flag
  544. \arg SDIO_INT_FLAG_RXORE: SDIO RXORE interrupt flag
  545. \arg SDIO_INT_FLAG_CMDRECV: SDIO CMDRECV interrupt flag
  546. \arg SDIO_INT_FLAG_CMDSEND: SDIO CMDSEND interrupt flag
  547. \arg SDIO_INT_FLAG_DTEND: SDIO DTEND interrupt flag
  548. \arg SDIO_INT_FLAG_STBITE: SDIO STBITE interrupt flag
  549. \arg SDIO_INT_FLAG_DTBLKEND: SDIO DTBLKEND interrupt flag
  550. \arg SDIO_INT_FLAG_CMDRUN: SDIO CMDRUN interrupt flag
  551. \arg SDIO_INT_FLAG_TXRUN: SDIO TXRUN interrupt flag
  552. \arg SDIO_INT_FLAG_RXRUN: SDIO RXRUN interrupt flag
  553. \arg SDIO_INT_FLAG_TFH: SDIO TFH interrupt flag
  554. \arg SDIO_INT_FLAG_RFH: SDIO RFH interrupt flag
  555. \arg SDIO_INT_FLAG_TFF: SDIO TFF interrupt flag
  556. \arg SDIO_INT_FLAG_RFF: SDIO RFF interrupt flag
  557. \arg SDIO_INT_FLAG_TFE: SDIO TFE interrupt flag
  558. \arg SDIO_INT_FLAG_RFE: SDIO RFE interrupt flag
  559. \arg SDIO_INT_FLAG_TXDTVAL: SDIO TXDTVAL interrupt flag
  560. \arg SDIO_INT_FLAG_RXDTVAL: SDIO RXDTVAL interrupt flag
  561. \arg SDIO_INT_FLAG_SDIOINT: SDIO SDIOINT interrupt flag
  562. \arg SDIO_INT_FLAG_ATAEND: SDIO ATAEND interrupt flag
  563. \param[out] none
  564. \retval FlagStatus: SET or RESET
  565. */
  566. FlagStatus sdio_interrupt_flag_get(uint32_t int_flag)
  567. {
  568. if(RESET != (SDIO_STAT & int_flag)){
  569. return SET;
  570. }
  571. return RESET;
  572. }
  573. /*!
  574. \brief clear the interrupt pending flags of SDIO
  575. \param[in] int_flag: interrupt flags state of SDIO
  576. one or more parameters can be selected which are shown as below:
  577. \arg SDIO_INT_FLAG_CCRCERR: command response received (CRC check failed) flag
  578. \arg SDIO_INT_FLAG_DTCRCERR: data block sent/received (CRC check failed) flag
  579. \arg SDIO_INT_FLAG_CMDTMOUT: command response timeout flag
  580. \arg SDIO_INT_FLAG_DTTMOUT: data timeout flag
  581. \arg SDIO_INT_FLAG_TXURE: transmit FIFO underrun error occurs flag
  582. \arg SDIO_INT_FLAG_RXORE: received FIFO overrun error occurs flag
  583. \arg SDIO_INT_FLAG_CMDRECV: command response received (CRC check passed) flag
  584. \arg SDIO_INT_FLAG_CMDSEND: command sent (no response required) flag
  585. \arg SDIO_INT_FLAG_DTEND: data end (data counter, SDIO_DATACNT, is zero) flag
  586. \arg SDIO_INT_FLAG_STBITE: start bit error in the bus flag
  587. \arg SDIO_INT_FLAG_DTBLKEND: data block sent/received (CRC check passed) flag
  588. \arg SDIO_INT_FLAG_SDIOINT: SD I/O interrupt received flag
  589. \arg SDIO_INT_FLAG_ATAEND: CE-ATA command completion signal received (only for CMD61) flag
  590. \param[out] none
  591. \retval none
  592. */
  593. void sdio_interrupt_flag_clear(uint32_t int_flag)
  594. {
  595. SDIO_INTC = int_flag;
  596. }
  597. /*!
  598. \brief enable the read wait mode(SD I/O only)
  599. \param[in] none
  600. \param[out] none
  601. \retval none
  602. */
  603. void sdio_readwait_enable(void)
  604. {
  605. SDIO_DATACTL |= SDIO_DATACTL_RWEN;
  606. }
  607. /*!
  608. \brief disable the read wait mode(SD I/O only)
  609. \param[in] none
  610. \param[out] none
  611. \retval none
  612. */
  613. void sdio_readwait_disable(void)
  614. {
  615. SDIO_DATACTL &= ~SDIO_DATACTL_RWEN;
  616. }
  617. /*!
  618. \brief enable the function that stop the read wait process(SD I/O only)
  619. \param[in] none
  620. \param[out] none
  621. \retval none
  622. */
  623. void sdio_stop_readwait_enable(void)
  624. {
  625. SDIO_DATACTL |= SDIO_DATACTL_RWSTOP;
  626. }
  627. /*!
  628. \brief disable the function that stop the read wait process(SD I/O only)
  629. \param[in] none
  630. \param[out] none
  631. \retval none
  632. */
  633. void sdio_stop_readwait_disable(void)
  634. {
  635. SDIO_DATACTL &= ~SDIO_DATACTL_RWSTOP;
  636. }
  637. /*!
  638. \brief set the read wait type(SD I/O only)
  639. \param[in] readwait_type: SD I/O read wait type
  640. only one parameter can be selected which is shown as below:
  641. \arg SDIO_READWAITTYPE_CLK: read wait control by stopping SDIO_CLK
  642. \arg SDIO_READWAITTYPE_DAT2: read wait control using SDIO_DAT[2]
  643. \param[out] none
  644. \retval none
  645. */
  646. void sdio_readwait_type_set(uint32_t readwait_type)
  647. {
  648. if(SDIO_READWAITTYPE_CLK == readwait_type){
  649. SDIO_DATACTL |= SDIO_DATACTL_RWTYPE;
  650. }else{
  651. SDIO_DATACTL &= ~SDIO_DATACTL_RWTYPE;
  652. }
  653. }
  654. /*!
  655. \brief enable the SD I/O mode specific operation(SD I/O only)
  656. \param[in] none
  657. \param[out] none
  658. \retval none
  659. */
  660. void sdio_operation_enable(void)
  661. {
  662. SDIO_DATACTL |= SDIO_DATACTL_IOEN;
  663. }
  664. /*!
  665. \brief disable the SD I/O mode specific operation(SD I/O only)
  666. \param[in] none
  667. \param[out] none
  668. \retval none
  669. */
  670. void sdio_operation_disable(void)
  671. {
  672. SDIO_DATACTL &= ~SDIO_DATACTL_IOEN;
  673. }
  674. /*!
  675. \brief enable the SD I/O suspend operation(SD I/O only)
  676. \param[in] none
  677. \param[out] none
  678. \retval none
  679. */
  680. void sdio_suspend_enable(void)
  681. {
  682. SDIO_CMDCTL |= SDIO_CMDCTL_SUSPEND;
  683. }
  684. /*!
  685. \brief disable the SD I/O suspend operation(SD I/O only)
  686. \param[in] none
  687. \param[out] none
  688. \retval none
  689. */
  690. void sdio_suspend_disable(void)
  691. {
  692. SDIO_CMDCTL &= ~SDIO_CMDCTL_SUSPEND;
  693. }
  694. /*!
  695. \brief enable the CE-ATA command(CE-ATA only)
  696. \param[in] none
  697. \param[out] none
  698. \retval none
  699. */
  700. void sdio_ceata_command_enable(void)
  701. {
  702. SDIO_CMDCTL |= SDIO_CMDCTL_ATAEN;
  703. }
  704. /*!
  705. \brief disable the CE-ATA command(CE-ATA only)
  706. \param[in] none
  707. \param[out] none
  708. \retval none
  709. */
  710. void sdio_ceata_command_disable(void)
  711. {
  712. SDIO_CMDCTL &= ~SDIO_CMDCTL_ATAEN;
  713. }
  714. /*!
  715. \brief enable the CE-ATA interrupt(CE-ATA only)
  716. \param[in] none
  717. \param[out] none
  718. \retval none
  719. */
  720. void sdio_ceata_interrupt_enable(void)
  721. {
  722. SDIO_CMDCTL &= ~SDIO_CMDCTL_NINTEN;
  723. }
  724. /*!
  725. \brief disable the CE-ATA interrupt(CE-ATA only)
  726. \param[in] none
  727. \param[out] none
  728. \retval none
  729. */
  730. void sdio_ceata_interrupt_disable(void)
  731. {
  732. SDIO_CMDCTL |= SDIO_CMDCTL_NINTEN;
  733. }
  734. /*!
  735. \brief enable the CE-ATA command completion signal(CE-ATA only)
  736. \param[in] none
  737. \param[out] none
  738. \retval none
  739. */
  740. void sdio_ceata_command_completion_enable(void)
  741. {
  742. SDIO_CMDCTL |= SDIO_CMDCTL_ENCMDC;
  743. }
  744. /*!
  745. \brief disable the CE-ATA command completion signal(CE-ATA only)
  746. \param[in] none
  747. \param[out] none
  748. \retval none
  749. */
  750. void sdio_ceata_command_completion_disable(void)
  751. {
  752. SDIO_CMDCTL &= ~SDIO_CMDCTL_ENCMDC;
  753. }