gd32f4xx_sdio.c 27 KB

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