gd32f30x_sdio.c 27 KB

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