fsl_usdhc.h 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380
  1. /*
  2. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017 NXP
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of the copyright holder nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef _FSL_USDHC_H_
  31. #define _FSL_USDHC_H_
  32. #include "fsl_common.h"
  33. /*!
  34. * @addtogroup usdhc
  35. * @{
  36. */
  37. /******************************************************************************
  38. * Definitions.
  39. *****************************************************************************/
  40. /*! @name Driver version */
  41. /*@{*/
  42. /*! @brief Driver version 2.1.1. */
  43. #define FSL_USDHC_DRIVER_VERSION (MAKE_VERSION(2U, 1U, 1U))
  44. /*@}*/
  45. /*! @brief Maximum block count can be set one time */
  46. #define USDHC_MAX_BLOCK_COUNT (USDHC_BLK_ATT_BLKCNT_MASK >> USDHC_BLK_ATT_BLKCNT_SHIFT)
  47. /*! @brief USDHC status */
  48. enum _usdhc_status
  49. {
  50. kStatus_USDHC_BusyTransferring = MAKE_STATUS(kStatusGroup_USDHC, 0U), /*!< Transfer is on-going */
  51. kStatus_USDHC_PrepareAdmaDescriptorFailed = MAKE_STATUS(kStatusGroup_USDHC, 1U), /*!< Set DMA descriptor failed */
  52. kStatus_USDHC_SendCommandFailed = MAKE_STATUS(kStatusGroup_USDHC, 2U), /*!< Send command failed */
  53. kStatus_USDHC_TransferDataFailed = MAKE_STATUS(kStatusGroup_USDHC, 3U), /*!< Transfer data failed */
  54. kStatus_USDHC_DMADataAddrNotAlign = MAKE_STATUS(kStatusGroup_USDHC, 4U), /*!< data address not align */
  55. kStatus_USDHC_ReTuningRequest = MAKE_STATUS(kStatusGroup_USDHC, 5U), /*!< re-tuning request */
  56. kStatus_USDHC_TuningError = MAKE_STATUS(kStatusGroup_USDHC, 6U), /*!< tuning error */
  57. };
  58. /*! @brief Host controller capabilities flag mask */
  59. enum _usdhc_capability_flag
  60. {
  61. kUSDHC_SupportAdmaFlag = USDHC_HOST_CTRL_CAP_ADMAS_MASK, /*!< Support ADMA */
  62. kUSDHC_SupportHighSpeedFlag = USDHC_HOST_CTRL_CAP_HSS_MASK, /*!< Support high-speed */
  63. kUSDHC_SupportDmaFlag = USDHC_HOST_CTRL_CAP_DMAS_MASK, /*!< Support DMA */
  64. kUSDHC_SupportSuspendResumeFlag = USDHC_HOST_CTRL_CAP_SRS_MASK, /*!< Support suspend/resume */
  65. kUSDHC_SupportV330Flag = USDHC_HOST_CTRL_CAP_VS33_MASK, /*!< Support voltage 3.3V */
  66. kUSDHC_SupportV300Flag = USDHC_HOST_CTRL_CAP_VS30_MASK, /*!< Support voltage 3.0V */
  67. kUSDHC_SupportV180Flag = USDHC_HOST_CTRL_CAP_VS18_MASK, /*!< Support voltage 1.8V */
  68. /* Put additional two flags in HTCAPBLT_MBL's position. */
  69. kUSDHC_Support4BitFlag = (USDHC_HOST_CTRL_CAP_MBL_SHIFT << 0U), /*!< Support 4 bit mode */
  70. kUSDHC_Support8BitFlag = (USDHC_HOST_CTRL_CAP_MBL_SHIFT << 1U), /*!< Support 8 bit mode */
  71. /* sd version 3.0 new feature */
  72. kUSDHC_SupportDDR50Flag = USDHC_HOST_CTRL_CAP_DDR50_SUPPORT_MASK, /*!< support DDR50 mode */
  73. #if defined(FSL_FEATURE_USDHC_HAS_SDR104_MODE) && (!FSL_FEATURE_USDHC_HAS_SDR104_MODE)
  74. kUSDHC_SupportSDR104Flag = 0, /*!< not support SDR104 mode */
  75. #else
  76. kUSDHC_SupportSDR104Flag = USDHC_HOST_CTRL_CAP_SDR104_SUPPORT_MASK, /*!< support SDR104 mode */
  77. #endif
  78. #if defined(FSL_FEATURE_USDHC_HAS_SDR50_MODE) && (!FSL_FEATURE_USDHC_HAS_SDR50_MODE)
  79. kUSDHC_SupportSDR50Flag = 0U, /*!< not support SDR50 mode */
  80. #else
  81. kUSDHC_SupportSDR50Flag = USDHC_HOST_CTRL_CAP_SDR50_SUPPORT_MASK, /*!< support SDR50 mode */
  82. #endif
  83. };
  84. /*! @brief Wakeup event mask */
  85. enum _usdhc_wakeup_event
  86. {
  87. kUSDHC_WakeupEventOnCardInt = USDHC_PROT_CTRL_WECINT_MASK, /*!< Wakeup on card interrupt */
  88. kUSDHC_WakeupEventOnCardInsert = USDHC_PROT_CTRL_WECINS_MASK, /*!< Wakeup on card insertion */
  89. kUSDHC_WakeupEventOnCardRemove = USDHC_PROT_CTRL_WECRM_MASK, /*!< Wakeup on card removal */
  90. kUSDHC_WakeupEventsAll = (kUSDHC_WakeupEventOnCardInt | kUSDHC_WakeupEventOnCardInsert |
  91. kUSDHC_WakeupEventOnCardRemove), /*!< All wakeup events */
  92. };
  93. /*! @brief Reset type mask */
  94. enum _usdhc_reset
  95. {
  96. kUSDHC_ResetAll = USDHC_SYS_CTRL_RSTA_MASK, /*!< Reset all except card detection */
  97. kUSDHC_ResetCommand = USDHC_SYS_CTRL_RSTC_MASK, /*!< Reset command line */
  98. kUSDHC_ResetData = USDHC_SYS_CTRL_RSTD_MASK, /*!< Reset data line */
  99. #if defined(FSL_FEATURE_USDHC_HAS_SDR50_MODE) && (!FSL_FEATURE_USDHC_HAS_SDR50_MODE)
  100. kUSDHC_ResetTuning = 0U, /*!< no reset tuning circuit bit */
  101. #else
  102. kUSDHC_ResetTuning = USDHC_SYS_CTRL_RSTT_MASK, /*!< reset tuning circuit */
  103. #endif
  104. kUSDHC_ResetsAll =
  105. (kUSDHC_ResetAll | kUSDHC_ResetCommand | kUSDHC_ResetData | kUSDHC_ResetTuning), /*!< All reset types */
  106. };
  107. /*! @brief Transfer flag mask */
  108. enum _usdhc_transfer_flag
  109. {
  110. kUSDHC_EnableDmaFlag = USDHC_MIX_CTRL_DMAEN_MASK, /*!< Enable DMA */
  111. kUSDHC_CommandTypeSuspendFlag = (USDHC_CMD_XFR_TYP_CMDTYP(1U)), /*!< Suspend command */
  112. kUSDHC_CommandTypeResumeFlag = (USDHC_CMD_XFR_TYP_CMDTYP(2U)), /*!< Resume command */
  113. kUSDHC_CommandTypeAbortFlag = (USDHC_CMD_XFR_TYP_CMDTYP(3U)), /*!< Abort command */
  114. kUSDHC_EnableBlockCountFlag = USDHC_MIX_CTRL_BCEN_MASK, /*!< Enable block count */
  115. kUSDHC_EnableAutoCommand12Flag = USDHC_MIX_CTRL_AC12EN_MASK, /*!< Enable auto CMD12 */
  116. kUSDHC_DataReadFlag = USDHC_MIX_CTRL_DTDSEL_MASK, /*!< Enable data read */
  117. kUSDHC_MultipleBlockFlag = USDHC_MIX_CTRL_MSBSEL_MASK, /*!< Multiple block data read/write */
  118. kUSDHC_EnableAutoCommand23Flag = USDHC_MIX_CTRL_AC23EN_MASK, /*!< Enable auto CMD23 */
  119. kUSDHC_ResponseLength136Flag = USDHC_CMD_XFR_TYP_RSPTYP(1U), /*!< 136 bit response length */
  120. kUSDHC_ResponseLength48Flag = USDHC_CMD_XFR_TYP_RSPTYP(2U), /*!< 48 bit response length */
  121. kUSDHC_ResponseLength48BusyFlag = USDHC_CMD_XFR_TYP_RSPTYP(3U), /*!< 48 bit response length with busy status */
  122. kUSDHC_EnableCrcCheckFlag = USDHC_CMD_XFR_TYP_CCCEN_MASK, /*!< Enable CRC check */
  123. kUSDHC_EnableIndexCheckFlag = USDHC_CMD_XFR_TYP_CICEN_MASK, /*!< Enable index check */
  124. kUSDHC_DataPresentFlag = USDHC_CMD_XFR_TYP_DPSEL_MASK, /*!< Data present flag */
  125. };
  126. /*! @brief Present status flag mask */
  127. enum _usdhc_present_status_flag
  128. {
  129. kUSDHC_CommandInhibitFlag = USDHC_PRES_STATE_CIHB_MASK, /*!< Command inhibit */
  130. kUSDHC_DataInhibitFlag = USDHC_PRES_STATE_CDIHB_MASK, /*!< Data inhibit */
  131. kUSDHC_DataLineActiveFlag = USDHC_PRES_STATE_DLA_MASK, /*!< Data line active */
  132. kUSDHC_SdClockStableFlag = USDHC_PRES_STATE_SDSTB_MASK, /*!< SD bus clock stable */
  133. kUSDHC_WriteTransferActiveFlag = USDHC_PRES_STATE_WTA_MASK, /*!< Write transfer active */
  134. kUSDHC_ReadTransferActiveFlag = USDHC_PRES_STATE_RTA_MASK, /*!< Read transfer active */
  135. kUSDHC_BufferWriteEnableFlag = USDHC_PRES_STATE_BWEN_MASK, /*!< Buffer write enable */
  136. kUSDHC_BufferReadEnableFlag = USDHC_PRES_STATE_BREN_MASK, /*!< Buffer read enable */
  137. #if defined(FSL_FEATURE_USDHC_HAS_SDR50_MODE) && (!FSL_FEATURE_USDHC_HAS_SDR50_MODE)
  138. kUSDHC_DelaySettingFinishedFlag = 0U, /*!< not support */
  139. kUSDHC_ReTuningRequestFlag = 0U, /*!< not support */
  140. #else
  141. kUSDHC_ReTuningRequestFlag = USDHC_PRES_STATE_RTR_MASK, /*!< re-tuning request flag ,only used for SDR104 mode */
  142. kUSDHC_DelaySettingFinishedFlag = USDHC_PRES_STATE_TSCD_MASK, /*!< delay setting finished flag */
  143. #endif
  144. kUSDHC_CardInsertedFlag = USDHC_PRES_STATE_CINST_MASK, /*!< Card inserted */
  145. kUSDHC_CommandLineLevelFlag = USDHC_PRES_STATE_CLSL_MASK, /*!< Command line signal level */
  146. kUSDHC_Data0LineLevelFlag = (1U << USDHC_PRES_STATE_DLSL_SHIFT), /*!< Data0 line signal level */
  147. kUSDHC_Data1LineLevelFlag = (1U << (USDHC_PRES_STATE_DLSL_SHIFT + 1U)), /*!< Data1 line signal level */
  148. kUSDHC_Data2LineLevelFlag = (1U << (USDHC_PRES_STATE_DLSL_SHIFT + 2U)), /*!< Data2 line signal level */
  149. kUSDHC_Data3LineLevelFlag = (1U << (USDHC_PRES_STATE_DLSL_SHIFT + 3U)), /*!< Data3 line signal level */
  150. kUSDHC_Data4LineLevelFlag = (1U << (USDHC_PRES_STATE_DLSL_SHIFT + 4U)), /*!< Data4 line signal level */
  151. kUSDHC_Data5LineLevelFlag = (1U << (USDHC_PRES_STATE_DLSL_SHIFT + 5U)), /*!< Data5 line signal level */
  152. kUSDHC_Data6LineLevelFlag = (1U << (USDHC_PRES_STATE_DLSL_SHIFT + 6U)), /*!< Data6 line signal level */
  153. kUSDHC_Data7LineLevelFlag = (1U << (USDHC_PRES_STATE_DLSL_SHIFT + 7U)), /*!< Data7 line signal level */
  154. };
  155. /*! @brief Interrupt status flag mask */
  156. enum _usdhc_interrupt_status_flag
  157. {
  158. kUSDHC_CommandCompleteFlag = USDHC_INT_STATUS_CC_MASK, /*!< Command complete */
  159. kUSDHC_DataCompleteFlag = USDHC_INT_STATUS_TC_MASK, /*!< Data complete */
  160. kUSDHC_BlockGapEventFlag = USDHC_INT_STATUS_BGE_MASK, /*!< Block gap event */
  161. kUSDHC_DmaCompleteFlag = USDHC_INT_STATUS_DINT_MASK, /*!< DMA interrupt */
  162. kUSDHC_BufferWriteReadyFlag = USDHC_INT_STATUS_BWR_MASK, /*!< Buffer write ready */
  163. kUSDHC_BufferReadReadyFlag = USDHC_INT_STATUS_BRR_MASK, /*!< Buffer read ready */
  164. kUSDHC_CardInsertionFlag = USDHC_INT_STATUS_CINS_MASK, /*!< Card inserted */
  165. kUSDHC_CardRemovalFlag = USDHC_INT_STATUS_CRM_MASK, /*!< Card removed */
  166. kUSDHC_CardInterruptFlag = USDHC_INT_STATUS_CINT_MASK, /*!< Card interrupt */
  167. #if defined(FSL_FEATURE_USDHC_HAS_SDR50_MODE) && (!FSL_FEATURE_USDHC_HAS_SDR50_MODE)
  168. kUSDHC_ReTuningEventFlag = 0U, /*!< Re-Tuning event,only for SD3.0 SDR104 mode */
  169. kUSDHC_TuningPassFlag = 0U, /*!< SDR104 mode tuning pass flag */
  170. kUSDHC_TuningErrorFlag = 0U, /*!< SDR104 tuning error flag */
  171. #else
  172. kUSDHC_ReTuningEventFlag = USDHC_INT_STATUS_RTE_MASK, /*!< Re-Tuning event,only for SD3.0 SDR104 mode */
  173. kUSDHC_TuningPassFlag = USDHC_INT_STATUS_TP_MASK, /*!< SDR104 mode tuning pass flag */
  174. kUSDHC_TuningErrorFlag = USDHC_INT_STATUS_TNE_MASK, /*!< SDR104 tuning error flag */
  175. #endif
  176. kUSDHC_CommandTimeoutFlag = USDHC_INT_STATUS_CTOE_MASK, /*!< Command timeout error */
  177. kUSDHC_CommandCrcErrorFlag = USDHC_INT_STATUS_CCE_MASK, /*!< Command CRC error */
  178. kUSDHC_CommandEndBitErrorFlag = USDHC_INT_STATUS_CEBE_MASK, /*!< Command end bit error */
  179. kUSDHC_CommandIndexErrorFlag = USDHC_INT_STATUS_CIE_MASK, /*!< Command index error */
  180. kUSDHC_DataTimeoutFlag = USDHC_INT_STATUS_DTOE_MASK, /*!< Data timeout error */
  181. kUSDHC_DataCrcErrorFlag = USDHC_INT_STATUS_DCE_MASK, /*!< Data CRC error */
  182. kUSDHC_DataEndBitErrorFlag = USDHC_INT_STATUS_DEBE_MASK, /*!< Data end bit error */
  183. kUSDHC_AutoCommand12ErrorFlag = USDHC_INT_STATUS_AC12E_MASK, /*!< Auto CMD12 error */
  184. kUSDHC_DmaErrorFlag = USDHC_INT_STATUS_DMAE_MASK, /*!< DMA error */
  185. kUSDHC_CommandErrorFlag = (kUSDHC_CommandTimeoutFlag | kUSDHC_CommandCrcErrorFlag | kUSDHC_CommandEndBitErrorFlag |
  186. kUSDHC_CommandIndexErrorFlag), /*!< Command error */
  187. kUSDHC_DataErrorFlag = (kUSDHC_DataTimeoutFlag | kUSDHC_DataCrcErrorFlag | kUSDHC_DataEndBitErrorFlag |
  188. kUSDHC_AutoCommand12ErrorFlag), /*!< Data error */
  189. kUSDHC_ErrorFlag = (kUSDHC_CommandErrorFlag | kUSDHC_DataErrorFlag | kUSDHC_DmaErrorFlag), /*!< All error */
  190. kUSDHC_DataFlag = (kUSDHC_DataCompleteFlag | kUSDHC_DmaCompleteFlag | kUSDHC_BufferWriteReadyFlag |
  191. kUSDHC_BufferReadReadyFlag | kUSDHC_DataErrorFlag | kUSDHC_DmaErrorFlag), /*!< Data interrupts */
  192. kUSDHC_CommandFlag = (kUSDHC_CommandErrorFlag | kUSDHC_CommandCompleteFlag), /*!< Command interrupts */
  193. kUSDHC_CardDetectFlag = (kUSDHC_CardInsertionFlag | kUSDHC_CardRemovalFlag), /*!< Card detection interrupts */
  194. kUSDHC_SDR104TuningFlag = (kUSDHC_TuningErrorFlag | kUSDHC_TuningPassFlag | kUSDHC_ReTuningEventFlag),
  195. kUSDHC_AllInterruptFlags = (kUSDHC_BlockGapEventFlag | kUSDHC_CardInterruptFlag | kUSDHC_CommandFlag |
  196. kUSDHC_DataFlag | kUSDHC_ErrorFlag | kUSDHC_SDR104TuningFlag), /*!< All flags mask */
  197. };
  198. /*! @brief Auto CMD12 error status flag mask */
  199. enum _usdhc_auto_command12_error_status_flag
  200. {
  201. kUSDHC_AutoCommand12NotExecutedFlag = USDHC_AUTOCMD12_ERR_STATUS_AC12NE_MASK, /*!< Not executed error */
  202. kUSDHC_AutoCommand12TimeoutFlag = USDHC_AUTOCMD12_ERR_STATUS_AC12TOE_MASK, /*!< Timeout error */
  203. kUSDHC_AutoCommand12EndBitErrorFlag = USDHC_AUTOCMD12_ERR_STATUS_AC12EBE_MASK, /*!< End bit error */
  204. kUSDHC_AutoCommand12CrcErrorFlag = USDHC_AUTOCMD12_ERR_STATUS_AC12CE_MASK, /*!< CRC error */
  205. kUSDHC_AutoCommand12IndexErrorFlag = USDHC_AUTOCMD12_ERR_STATUS_AC12IE_MASK, /*!< Index error */
  206. kUSDHC_AutoCommand12NotIssuedFlag = USDHC_AUTOCMD12_ERR_STATUS_CNIBAC12E_MASK, /*!< Not issued error */
  207. };
  208. /*! @brief standard tuning flag */
  209. enum _usdhc_standard_tuning
  210. {
  211. #if defined(FSL_FEATURE_USDHC_HAS_SDR50_MODE) && (!FSL_FEATURE_USDHC_HAS_SDR50_MODE)
  212. kUSDHC_ExecuteTuning = 0U, /*!< not support */
  213. kUSDHC_TuningSampleClockSel = 0U, /*!< not support */
  214. #else
  215. kUSDHC_ExecuteTuning = USDHC_AUTOCMD12_ERR_STATUS_EXECUTE_TUNING_MASK, /*!< used to start tuning procedure */
  216. kUSDHC_TuningSampleClockSel =
  217. USDHC_AUTOCMD12_ERR_STATUS_SMP_CLK_SEL_MASK, /*!< when std_tuning_en bit is set, this bit is used
  218. select sampleing clock */
  219. #endif
  220. };
  221. /*! @brief ADMA error status flag mask */
  222. enum _usdhc_adma_error_status_flag
  223. {
  224. kUSDHC_AdmaLenghMismatchFlag = USDHC_ADMA_ERR_STATUS_ADMALME_MASK, /*!< Length mismatch error */
  225. kUSDHC_AdmaDescriptorErrorFlag = USDHC_ADMA_ERR_STATUS_ADMADCE_MASK, /*!< Descriptor error */
  226. };
  227. /*!
  228. * @brief ADMA error state
  229. *
  230. * This state is the detail state when ADMA error has occurred.
  231. */
  232. typedef enum _usdhc_adma_error_state
  233. {
  234. kUSDHC_AdmaErrorStateStopDma = 0x00U, /*!< Stop DMA */
  235. kUSDHC_AdmaErrorStateFetchDescriptor = 0x01U, /*!< Fetch descriptor */
  236. kUSDHC_AdmaErrorStateChangeAddress = 0x02U, /*!< Change address */
  237. kUSDHC_AdmaErrorStateTransferData = 0x03U, /*!< Transfer data */
  238. } usdhc_adma_error_state_t;
  239. /*! @brief Force event mask */
  240. enum _usdhc_force_event
  241. {
  242. kUSDHC_ForceEventAutoCommand12NotExecuted = USDHC_FORCE_EVENT_FEVTAC12NE_MASK, /*!< Auto CMD12 not executed error */
  243. kUSDHC_ForceEventAutoCommand12Timeout = USDHC_FORCE_EVENT_FEVTAC12TOE_MASK, /*!< Auto CMD12 timeout error */
  244. kUSDHC_ForceEventAutoCommand12CrcError = USDHC_FORCE_EVENT_FEVTAC12CE_MASK, /*!< Auto CMD12 CRC error */
  245. kUSDHC_ForceEventEndBitError = USDHC_FORCE_EVENT_FEVTAC12EBE_MASK, /*!< Auto CMD12 end bit error */
  246. kUSDHC_ForceEventAutoCommand12IndexError = USDHC_FORCE_EVENT_FEVTAC12IE_MASK, /*!< Auto CMD12 index error */
  247. kUSDHC_ForceEventAutoCommand12NotIssued = USDHC_FORCE_EVENT_FEVTCNIBAC12E_MASK, /*!< Auto CMD12 not issued error */
  248. kUSDHC_ForceEventCommandTimeout = USDHC_FORCE_EVENT_FEVTCTOE_MASK, /*!< Command timeout error */
  249. kUSDHC_ForceEventCommandCrcError = USDHC_FORCE_EVENT_FEVTCCE_MASK, /*!< Command CRC error */
  250. kUSDHC_ForceEventCommandEndBitError = USDHC_FORCE_EVENT_FEVTCEBE_MASK, /*!< Command end bit error */
  251. kUSDHC_ForceEventCommandIndexError = USDHC_FORCE_EVENT_FEVTCIE_MASK, /*!< Command index error */
  252. kUSDHC_ForceEventDataTimeout = USDHC_FORCE_EVENT_FEVTDTOE_MASK, /*!< Data timeout error */
  253. kUSDHC_ForceEventDataCrcError = USDHC_FORCE_EVENT_FEVTDCE_MASK, /*!< Data CRC error */
  254. kUSDHC_ForceEventDataEndBitError = USDHC_FORCE_EVENT_FEVTDEBE_MASK, /*!< Data end bit error */
  255. kUSDHC_ForceEventAutoCommand12Error = USDHC_FORCE_EVENT_FEVTAC12E_MASK, /*!< Auto CMD12 error */
  256. kUSDHC_ForceEventCardInt = USDHC_FORCE_EVENT_FEVTCINT_MASK, /*!< Card interrupt */
  257. kUSDHC_ForceEventDmaError = USDHC_FORCE_EVENT_FEVTDMAE_MASK, /*!< Dma error */
  258. #if defined(FSL_FEATURE_USDHC_HAS_SDR50_MODE) && (!FSL_FEATURE_USDHC_HAS_SDR50_MODE)
  259. kUSDHC_ForceEventTuningError = 0U, /*!< not support */
  260. #else
  261. kUSDHC_ForceEventTuningError = USDHC_FORCE_EVENT_FEVTTNE_MASK, /*!< Tuning error */
  262. #endif
  263. kUSDHC_ForceEventsAll =
  264. (kUSDHC_ForceEventAutoCommand12NotExecuted | kUSDHC_ForceEventAutoCommand12Timeout |
  265. kUSDHC_ForceEventAutoCommand12CrcError | kUSDHC_ForceEventEndBitError |
  266. kUSDHC_ForceEventAutoCommand12IndexError | kUSDHC_ForceEventAutoCommand12NotIssued |
  267. kUSDHC_ForceEventCommandTimeout | kUSDHC_ForceEventCommandCrcError | kUSDHC_ForceEventCommandEndBitError |
  268. kUSDHC_ForceEventCommandIndexError | kUSDHC_ForceEventDataTimeout | kUSDHC_ForceEventDataCrcError |
  269. kUSDHC_ForceEventDataEndBitError | kUSDHC_ForceEventAutoCommand12Error | kUSDHC_ForceEventCardInt |
  270. kUSDHC_ForceEventDmaError | kUSDHC_ForceEventTuningError), /*!< All force event flags mask */
  271. };
  272. /*! @brief Data transfer width */
  273. typedef enum _usdhc_data_bus_width
  274. {
  275. kUSDHC_DataBusWidth1Bit = 0U, /*!< 1-bit mode */
  276. kUSDHC_DataBusWidth4Bit = 1U, /*!< 4-bit mode */
  277. kUSDHC_DataBusWidth8Bit = 2U, /*!< 8-bit mode */
  278. } usdhc_data_bus_width_t;
  279. /*! @brief Endian mode */
  280. typedef enum _usdhc_endian_mode
  281. {
  282. kUSDHC_EndianModeBig = 0U, /*!< Big endian mode */
  283. kUSDHC_EndianModeHalfWordBig = 1U, /*!< Half word big endian mode */
  284. kUSDHC_EndianModeLittle = 2U, /*!< Little endian mode */
  285. } usdhc_endian_mode_t;
  286. /*! @brief DMA mode */
  287. typedef enum _usdhc_dma_mode
  288. {
  289. kUSDHC_DmaModeSimple = 0U, /*!< external DMA */
  290. kUSDHC_DmaModeAdma1 = 1U, /*!< ADMA1 is selected */
  291. kUSDHC_DmaModeAdma2 = 2U, /*!< ADMA2 is selected */
  292. kUSDHC_ExternalDMA = 3U, /*!< external dma mode select */
  293. } usdhc_dma_mode_t;
  294. /*! @brief SDIO control flag mask */
  295. enum _usdhc_sdio_control_flag
  296. {
  297. kUSDHC_StopAtBlockGapFlag = USDHC_PROT_CTRL_SABGREQ_MASK, /*!< Stop at block gap */
  298. kUSDHC_ReadWaitControlFlag = USDHC_PROT_CTRL_RWCTL_MASK, /*!< Read wait control */
  299. kUSDHC_InterruptAtBlockGapFlag = USDHC_PROT_CTRL_IABG_MASK, /*!< Interrupt at block gap */
  300. kUSDHC_ReadDoneNo8CLK = USDHC_PROT_CTRL_RD_DONE_NO_8CLK_MASK, /*!< read done without 8 clk for block gap */
  301. kUSDHC_ExactBlockNumberReadFlag = USDHC_PROT_CTRL_NON_EXACT_BLK_RD_MASK, /*!< Exact block number read */
  302. };
  303. /*! @brief MMC card boot mode */
  304. typedef enum _usdhc_boot_mode
  305. {
  306. kUSDHC_BootModeNormal = 0U, /*!< Normal boot */
  307. kUSDHC_BootModeAlternative = 1U, /*!< Alternative boot */
  308. } usdhc_boot_mode_t;
  309. /*! @brief The command type */
  310. typedef enum _usdhc_card_command_type
  311. {
  312. kCARD_CommandTypeNormal = 0U, /*!< Normal command */
  313. kCARD_CommandTypeSuspend = 1U, /*!< Suspend command */
  314. kCARD_CommandTypeResume = 2U, /*!< Resume command */
  315. kCARD_CommandTypeAbort = 3U, /*!< Abort command */
  316. } usdhc_card_command_type_t;
  317. /*!
  318. * @brief The command response type.
  319. *
  320. * Define the command response type from card to host controller.
  321. */
  322. typedef enum _usdhc_card_response_type
  323. {
  324. kCARD_ResponseTypeNone = 0U, /*!< Response type: none */
  325. kCARD_ResponseTypeR1 = 1U, /*!< Response type: R1 */
  326. kCARD_ResponseTypeR1b = 2U, /*!< Response type: R1b */
  327. kCARD_ResponseTypeR2 = 3U, /*!< Response type: R2 */
  328. kCARD_ResponseTypeR3 = 4U, /*!< Response type: R3 */
  329. kCARD_ResponseTypeR4 = 5U, /*!< Response type: R4 */
  330. kCARD_ResponseTypeR5 = 6U, /*!< Response type: R5 */
  331. kCARD_ResponseTypeR5b = 7U, /*!< Response type: R5b */
  332. kCARD_ResponseTypeR6 = 8U, /*!< Response type: R6 */
  333. kCARD_ResponseTypeR7 = 9U, /*!< Response type: R7 */
  334. } usdhc_card_response_type_t;
  335. /*! @brief The alignment size for ADDRESS filed in ADMA1's descriptor */
  336. #define USDHC_ADMA1_ADDRESS_ALIGN (4096U)
  337. /*! @brief The alignment size for LENGTH field in ADMA1's descriptor */
  338. #define USDHC_ADMA1_LENGTH_ALIGN (4096U)
  339. /*! @brief The alignment size for ADDRESS field in ADMA2's descriptor */
  340. #define USDHC_ADMA2_ADDRESS_ALIGN (4U)
  341. /*! @brief The alignment size for LENGTH filed in ADMA2's descriptor */
  342. #define USDHC_ADMA2_LENGTH_ALIGN (4U)
  343. /* ADMA1 descriptor table
  344. * |------------------------|---------|--------------------------|
  345. * | Address/page field |Reserved | Attribute |
  346. * |------------------------|---------|--------------------------|
  347. * |31 12|11 6|05 |04 |03|02 |01 |00 |
  348. * |------------------------|---------|----|----|--|---|---|-----|
  349. * | address or data length | 000000 |Act2|Act1| 0|Int|End|Valid|
  350. * |------------------------|---------|----|----|--|---|---|-----|
  351. *
  352. *
  353. * |------|------|-----------------|-------|-------------|
  354. * | Act2 | Act1 | Comment | 31-28 | 27 - 12 |
  355. * |------|------|-----------------|---------------------|
  356. * | 0 | 0 | No op | Don't care |
  357. * |------|------|-----------------|-------|-------------|
  358. * | 0 | 1 | Set data length | 0000 | Data Length |
  359. * |------|------|-----------------|-------|-------------|
  360. * | 1 | 0 | Transfer data | Data address |
  361. * |------|------|-----------------|---------------------|
  362. * | 1 | 1 | Link descriptor | Descriptor address |
  363. * |------|------|-----------------|---------------------|
  364. */
  365. /*! @brief The bit shift for ADDRESS filed in ADMA1's descriptor */
  366. #define USDHC_ADMA1_DESCRIPTOR_ADDRESS_SHIFT (12U)
  367. /*! @brief The bit mask for ADDRESS field in ADMA1's descriptor */
  368. #define USDHC_ADMA1_DESCRIPTOR_ADDRESS_MASK (0xFFFFFU)
  369. /*! @brief The bit shift for LENGTH filed in ADMA1's descriptor */
  370. #define USDHC_ADMA1_DESCRIPTOR_LENGTH_SHIFT (12U)
  371. /*! @brief The mask for LENGTH field in ADMA1's descriptor */
  372. #define USDHC_ADMA1_DESCRIPTOR_LENGTH_MASK (0xFFFFU)
  373. /*! @brief The maximum value of LENGTH filed in ADMA1's descriptor */
  374. #define USDHC_ADMA1_DESCRIPTOR_MAX_LENGTH_PER_ENTRY (USDHC_ADMA1_DESCRIPTOR_LENGTH_MASK - 3U)
  375. /*! @brief The mask for the control/status field in ADMA1 descriptor */
  376. enum _usdhc_adma1_descriptor_flag
  377. {
  378. kUSDHC_Adma1DescriptorValidFlag = (1U << 0U), /*!< Valid flag */
  379. kUSDHC_Adma1DescriptorEndFlag = (1U << 1U), /*!< End flag */
  380. kUSDHC_Adma1DescriptorInterrupFlag = (1U << 2U), /*!< Interrupt flag */
  381. kUSDHC_Adma1DescriptorActivity1Flag = (1U << 4U), /*!< Activity 1 flag */
  382. kUSDHC_Adma1DescriptorActivity2Flag = (1U << 5U), /*!< Activity 2 flag */
  383. kUSDHC_Adma1DescriptorTypeNop = (kUSDHC_Adma1DescriptorValidFlag), /*!< No operation */
  384. kUSDHC_Adma1DescriptorTypeTransfer =
  385. (kUSDHC_Adma1DescriptorActivity2Flag | kUSDHC_Adma1DescriptorValidFlag), /*!< Transfer data */
  386. kUSDHC_Adma1DescriptorTypeLink = (kUSDHC_Adma1DescriptorActivity1Flag | kUSDHC_Adma1DescriptorActivity2Flag |
  387. kUSDHC_Adma1DescriptorValidFlag), /*!< Link descriptor */
  388. kUSDHC_Adma1DescriptorTypeSetLength =
  389. (kUSDHC_Adma1DescriptorActivity1Flag | kUSDHC_Adma1DescriptorValidFlag), /*!< Set data length */
  390. };
  391. /* ADMA2 descriptor table
  392. * |----------------|---------------|-------------|--------------------------|
  393. * | Address field | Length | Reserved | Attribute |
  394. * |----------------|---------------|-------------|--------------------------|
  395. * |63 32|31 16|15 06|05 |04 |03|02 |01 |00 |
  396. * |----------------|---------------|-------------|----|----|--|---|---|-----|
  397. * | 32-bit address | 16-bit length | 0000000000 |Act2|Act1| 0|Int|End|Valid|
  398. * |----------------|---------------|-------------|----|----|--|---|---|-----|
  399. *
  400. *
  401. * | Act2 | Act1 | Comment | Operation |
  402. * |------|------|-----------------|-------------------------------------------------------------------|
  403. * | 0 | 0 | No op | Don't care |
  404. * |------|------|-----------------|-------------------------------------------------------------------|
  405. * | 0 | 1 | Reserved | Read this line and go to next one |
  406. * |------|------|-----------------|-------------------------------------------------------------------|
  407. * | 1 | 0 | Transfer data | Transfer data with address and length set in this descriptor line |
  408. * |------|------|-----------------|-------------------------------------------------------------------|
  409. * | 1 | 1 | Link descriptor | Link to another descriptor |
  410. * |------|------|-----------------|-------------------------------------------------------------------|
  411. */
  412. /*! @brief The bit shift for LENGTH field in ADMA2's descriptor */
  413. #define USDHC_ADMA2_DESCRIPTOR_LENGTH_SHIFT (16U)
  414. /*! @brief The bit mask for LENGTH field in ADMA2's descriptor */
  415. #define USDHC_ADMA2_DESCRIPTOR_LENGTH_MASK (0xFFFFU)
  416. /*! @brief The maximum value of LENGTH field in ADMA2's descriptor */
  417. #define USDHC_ADMA2_DESCRIPTOR_MAX_LENGTH_PER_ENTRY (USDHC_ADMA2_DESCRIPTOR_LENGTH_MASK - 3U)
  418. /*! @brief ADMA1 descriptor control and status mask */
  419. enum _usdhc_adma2_descriptor_flag
  420. {
  421. kUSDHC_Adma2DescriptorValidFlag = (1U << 0U), /*!< Valid flag */
  422. kUSDHC_Adma2DescriptorEndFlag = (1U << 1U), /*!< End flag */
  423. kUSDHC_Adma2DescriptorInterruptFlag = (1U << 2U), /*!< Interrupt flag */
  424. kUSDHC_Adma2DescriptorActivity1Flag = (1U << 4U), /*!< Activity 1 mask */
  425. kUSDHC_Adma2DescriptorActivity2Flag = (1U << 5U), /*!< Activity 2 mask */
  426. kUSDHC_Adma2DescriptorTypeNop = (kUSDHC_Adma2DescriptorValidFlag), /*!< No operation */
  427. kUSDHC_Adma2DescriptorTypeReserved =
  428. (kUSDHC_Adma2DescriptorActivity1Flag | kUSDHC_Adma2DescriptorValidFlag), /*!< Reserved */
  429. kUSDHC_Adma2DescriptorTypeTransfer =
  430. (kUSDHC_Adma2DescriptorActivity2Flag | kUSDHC_Adma2DescriptorValidFlag), /*!< Transfer type */
  431. kUSDHC_Adma2DescriptorTypeLink = (kUSDHC_Adma2DescriptorActivity1Flag | kUSDHC_Adma2DescriptorActivity2Flag |
  432. kUSDHC_Adma2DescriptorValidFlag), /*!< Link type */
  433. };
  434. /*! @brief dma transfer burst len config. */
  435. typedef enum _usdhc_burst_len
  436. {
  437. kUSDHC_EnBurstLenForINCR = 0x01U, /*!< enable burst len for INCR */
  438. kUSDHC_EnBurstLenForINCR4816 = 0x02U, /*!< enable burst len for INCR4/INCR8/INCR16 */
  439. kUSDHC_EnBurstLenForINCR4816WRAP = 0x04U, /*!< enable burst len for INCR4/8/16 WRAP */
  440. } usdhc_burst_len_t;
  441. /*! @brief Defines the adma1 descriptor structure. */
  442. typedef uint32_t usdhc_adma1_descriptor_t;
  443. /*! @brief Defines the ADMA2 descriptor structure. */
  444. typedef struct _usdhc_adma2_descriptor
  445. {
  446. uint32_t attribute; /*!< The control and status field */
  447. const uint32_t *address; /*!< The address field */
  448. } usdhc_adma2_descriptor_t;
  449. /*!
  450. * @brief USDHC capability information.
  451. *
  452. * Defines a structure to save the capability information of USDHC.
  453. */
  454. typedef struct _usdhc_capability
  455. {
  456. uint32_t sdVersion; /*!< support SD card/sdio version */
  457. uint32_t mmcVersion; /*!< support emmc card version */
  458. uint32_t maxBlockLength; /*!< Maximum block length united as byte */
  459. uint32_t maxBlockCount; /*!< Maximum block count can be set one time */
  460. uint32_t flags; /*!< Capability flags to indicate the support information(_usdhc_capability_flag) */
  461. } usdhc_capability_t;
  462. /*! @brief Data structure to configure the MMC boot feature */
  463. typedef struct _usdhc_boot_config
  464. {
  465. uint32_t ackTimeoutCount; /*!< Timeout value for the boot ACK. The available range is 0 ~ 15. */
  466. usdhc_boot_mode_t bootMode; /*!< Boot mode selection. */
  467. uint32_t blockCount; /*!< Stop at block gap value of automatic mode. Available range is 0 ~ 65535. */
  468. bool enableBootAck; /*!< Enable or disable boot ACK */
  469. bool enableBoot; /*!< Enable or disable fast boot */
  470. bool enableAutoStopAtBlockGap; /*!< Enable or disable auto stop at block gap function in boot period */
  471. } usdhc_boot_config_t;
  472. /*! @brief Data structure to initialize the USDHC */
  473. typedef struct _usdhc_config
  474. {
  475. uint32_t dataTimeout; /*!< Data timeout value */
  476. usdhc_endian_mode_t endianMode; /*!< Endian mode */
  477. uint8_t readWatermarkLevel; /*!< Watermark level for DMA read operation. Available range is 1 ~ 128. */
  478. uint8_t writeWatermarkLevel; /*!< Watermark level for DMA write operation. Available range is 1 ~ 128. */
  479. uint8_t readBurstLen; /*!< Read burst len */
  480. uint8_t writeBurstLen; /*!< Write burst len */
  481. } usdhc_config_t;
  482. /*!
  483. * @brief Card data descriptor
  484. *
  485. * Defines a structure to contain data-related attribute. 'enableIgnoreError' is used for the case that upper card
  486. * driver
  487. * want to ignore the error event to read/write all the data not to stop read/write immediately when error event
  488. * happen for example bus testing procedure for MMC card.
  489. */
  490. typedef struct _usdhc_data
  491. {
  492. bool enableAutoCommand12; /*!< Enable auto CMD12 */
  493. bool enableAutoCommand23; /*!< Enable auto CMD23 */
  494. bool enableIgnoreError; /*!< Enable to ignore error event to read/write all the data */
  495. bool executeTuning; /*!< execute tuning flag */
  496. size_t blockSize; /*!< Block size */
  497. uint32_t blockCount; /*!< Block count */
  498. uint32_t *rxData; /*!< Buffer to save data read */
  499. const uint32_t *txData; /*!< Data buffer to write */
  500. } usdhc_data_t;
  501. /*!
  502. * @brief Card command descriptor
  503. *
  504. * Define card command-related attribute.
  505. */
  506. typedef struct _usdhc_command
  507. {
  508. uint32_t index; /*!< Command index */
  509. uint32_t argument; /*!< Command argument */
  510. usdhc_card_command_type_t type; /*!< Command type */
  511. usdhc_card_response_type_t responseType; /*!< Command response type */
  512. uint32_t response[4U]; /*!< Response for this command */
  513. uint32_t responseErrorFlags; /*!< response error flag, the flag which need to check
  514. the command reponse*/
  515. uint32_t flags; /*!< Cmd flags */
  516. } usdhc_command_t;
  517. /*! @brief ADMA configuration */
  518. typedef struct _usdhc_adma_config
  519. {
  520. usdhc_dma_mode_t dmaMode; /*!< DMA mode */
  521. usdhc_burst_len_t burstLen; /*!< burst len config */
  522. uint32_t *admaTable; /*!< ADMA table address, can't be null if transfer way is ADMA1/ADMA2 */
  523. uint32_t admaTableWords; /*!< ADMA table length united as words, can't be 0 if transfer way is ADMA1/ADMA2 */
  524. } usdhc_adma_config_t;
  525. /*! @brief Transfer state */
  526. typedef struct _usdhc_transfer
  527. {
  528. usdhc_data_t *data; /*!< Data to transfer */
  529. usdhc_command_t *command; /*!< Command to send */
  530. } usdhc_transfer_t;
  531. /*! @brief USDHC handle typedef */
  532. typedef struct _usdhc_handle usdhc_handle_t;
  533. /*! @brief USDHC callback functions. */
  534. typedef struct _usdhc_transfer_callback
  535. {
  536. void (*CardInserted)(void); /*!< Card inserted occurs when DAT3/CD pin is for card detect */
  537. void (*CardRemoved)(void); /*!< Card removed occurs */
  538. void (*SdioInterrupt)(void); /*!< SDIO card interrupt occurs */
  539. void (*SdioBlockGap)(void); /*!< SDIO card stopped at block gap occurs */
  540. void (*TransferComplete)(USDHC_Type *base,
  541. usdhc_handle_t *handle,
  542. status_t status,
  543. void *userData); /*!< Transfer complete callback */
  544. void (*ReTuning)(void); /*!< handle the re-tuning */
  545. } usdhc_transfer_callback_t;
  546. /*!
  547. * @brief USDHC handle
  548. *
  549. * Defines the structure to save the USDHC state information and callback function. The detailed interrupt status when
  550. * sending a command or transfering data can be obtained from the interruptFlags field by using the mask defined in
  551. * usdhc_interrupt_flag_t.
  552. *
  553. * @note All the fields except interruptFlags and transferredWords must be allocated by the user.
  554. */
  555. struct _usdhc_handle
  556. {
  557. /* Transfer parameter */
  558. usdhc_data_t *volatile data; /*!< Data to transfer */
  559. usdhc_command_t *volatile command; /*!< Command to send */
  560. /* Transfer status */
  561. volatile uint32_t interruptFlags; /*!< Interrupt flags of last transaction */
  562. volatile uint32_t transferredWords; /*!< Words transferred by DATAPORT way */
  563. /* Callback functions */
  564. usdhc_transfer_callback_t callback; /*!< Callback function */
  565. void *userData; /*!< Parameter for transfer complete callback */
  566. };
  567. /*! @brief USDHC transfer function. */
  568. typedef status_t (*usdhc_transfer_function_t)(USDHC_Type *base, usdhc_transfer_t *content);
  569. /*! @brief USDHC host descriptor */
  570. typedef struct _usdhc_host
  571. {
  572. USDHC_Type *base; /*!< USDHC peripheral base address */
  573. uint32_t sourceClock_Hz; /*!< USDHC source clock frequency united in Hz */
  574. usdhc_config_t config; /*!< USDHC configuration */
  575. usdhc_capability_t capability; /*!< USDHC capability information */
  576. usdhc_transfer_function_t transfer; /*!< USDHC transfer function */
  577. } usdhc_host_t;
  578. /*************************************************************************************************
  579. * API
  580. ************************************************************************************************/
  581. #if defined(__cplusplus)
  582. extern "C" {
  583. #endif
  584. /*!
  585. * @name Initialization and deinitialization
  586. * @{
  587. */
  588. /*!
  589. * @brief USDHC module initialization function.
  590. *
  591. * Configures the USDHC according to the user configuration.
  592. *
  593. * Example:
  594. @code
  595. usdhc_config_t config;
  596. config.cardDetectDat3 = false;
  597. config.endianMode = kUSDHC_EndianModeLittle;
  598. config.dmaMode = kUSDHC_DmaModeAdma2;
  599. config.readWatermarkLevel = 128U;
  600. config.writeWatermarkLevel = 128U;
  601. USDHC_Init(USDHC, &config);
  602. @endcode
  603. *
  604. * @param base USDHC peripheral base address.
  605. * @param config USDHC configuration information.
  606. * @retval kStatus_Success Operate successfully.
  607. */
  608. void USDHC_Init(USDHC_Type *base, const usdhc_config_t *config);
  609. /*!
  610. * @brief Deinitializes the USDHC.
  611. *
  612. * @param base USDHC peripheral base address.
  613. */
  614. void USDHC_Deinit(USDHC_Type *base);
  615. /*!
  616. * @brief Resets the USDHC.
  617. *
  618. * @param base USDHC peripheral base address.
  619. * @param mask The reset type mask(_usdhc_reset).
  620. * @param timeout Timeout for reset.
  621. * @retval true Reset successfully.
  622. * @retval false Reset failed.
  623. */
  624. bool USDHC_Reset(USDHC_Type *base, uint32_t mask, uint32_t timeout);
  625. /* @} */
  626. /*!
  627. * @name DMA Control
  628. * @{
  629. */
  630. /*!
  631. * @brief Sets the ADMA descriptor table configuration.
  632. *
  633. * @param base USDHC peripheral base address.
  634. * @param adma configuration
  635. * @param data Data descriptor
  636. * @param command flags
  637. * @retval kStatus_OutOfRange ADMA descriptor table length isn't enough to describe data.
  638. * @retval kStatus_Success Operate successfully.
  639. */
  640. status_t USDHC_SetAdmaTableConfig(USDHC_Type *base,
  641. usdhc_adma_config_t *dmaConfig,
  642. usdhc_data_t *dataConfig,
  643. uint32_t flags);
  644. /* @} */
  645. /*!
  646. * @name Interrupts
  647. * @{
  648. */
  649. /*!
  650. * @brief Enables the interrupt status.
  651. *
  652. * @param base USDHC peripheral base address.
  653. * @param mask Interrupt status flags mask(_usdhc_interrupt_status_flag).
  654. */
  655. static inline void USDHC_EnableInterruptStatus(USDHC_Type *base, uint32_t mask)
  656. {
  657. base->INT_STATUS_EN |= mask;
  658. }
  659. /*!
  660. * @brief Disables the interrupt status.
  661. *
  662. * @param base USDHC peripheral base address.
  663. * @param mask The interrupt status flags mask(_usdhc_interrupt_status_flag).
  664. */
  665. static inline void USDHC_DisableInterruptStatus(USDHC_Type *base, uint32_t mask)
  666. {
  667. base->INT_STATUS_EN &= ~mask;
  668. }
  669. /*!
  670. * @brief Enables the interrupt signal corresponding to the interrupt status flag.
  671. *
  672. * @param base USDHC peripheral base address.
  673. * @param mask The interrupt status flags mask(_usdhc_interrupt_status_flag).
  674. */
  675. static inline void USDHC_EnableInterruptSignal(USDHC_Type *base, uint32_t mask)
  676. {
  677. base->INT_SIGNAL_EN |= mask;
  678. }
  679. /*!
  680. * @brief Disables the interrupt signal corresponding to the interrupt status flag.
  681. *
  682. * @param base USDHC peripheral base address.
  683. * @param mask The interrupt status flags mask(_usdhc_interrupt_status_flag).
  684. */
  685. static inline void USDHC_DisableInterruptSignal(USDHC_Type *base, uint32_t mask)
  686. {
  687. base->INT_SIGNAL_EN &= ~mask;
  688. }
  689. /* @} */
  690. /*!
  691. * @name Status
  692. * @{
  693. */
  694. /*!
  695. * @brief Gets the current interrupt status.
  696. *
  697. * @param base USDHC peripheral base address.
  698. * @return Current interrupt status flags mask(_usdhc_interrupt_status_flag).
  699. */
  700. static inline uint32_t USDHC_GetInterruptStatusFlags(USDHC_Type *base)
  701. {
  702. return base->INT_STATUS;
  703. }
  704. /*!
  705. * @brief Clears a specified interrupt status.
  706. * write 1 clears
  707. * @param base USDHC peripheral base address.
  708. * @param mask The interrupt status flags mask(_usdhc_interrupt_status_flag).
  709. */
  710. static inline void USDHC_ClearInterruptStatusFlags(USDHC_Type *base, uint32_t mask)
  711. {
  712. base->INT_STATUS = mask;
  713. }
  714. /*!
  715. * @brief Gets the status of auto command 12 error.
  716. *
  717. * @param base USDHC peripheral base address.
  718. * @return Auto command 12 error status flags mask(_usdhc_auto_command12_error_status_flag).
  719. */
  720. static inline uint32_t USDHC_GetAutoCommand12ErrorStatusFlags(USDHC_Type *base)
  721. {
  722. return base->AUTOCMD12_ERR_STATUS;
  723. }
  724. /*!
  725. * @brief Gets the status of the ADMA error.
  726. *
  727. * @param base USDHC peripheral base address.
  728. * @return ADMA error status flags mask(_usdhc_adma_error_status_flag).
  729. */
  730. static inline uint32_t USDHC_GetAdmaErrorStatusFlags(USDHC_Type *base)
  731. {
  732. return base->ADMA_ERR_STATUS;
  733. }
  734. /*!
  735. * @brief Gets a present status.
  736. *
  737. * This function gets the present USDHC's status except for an interrupt status and an error status.
  738. *
  739. * @param base USDHC peripheral base address.
  740. * @return Present USDHC's status flags mask(_usdhc_present_status_flag).
  741. */
  742. static inline uint32_t USDHC_GetPresentStatusFlags(USDHC_Type *base)
  743. {
  744. return base->PRES_STATE;
  745. }
  746. /* @} */
  747. /*!
  748. * @name Bus Operations
  749. * @{
  750. */
  751. /*!
  752. * @brief Gets the capability information.
  753. *
  754. * @param base USDHC peripheral base address.
  755. * @param capability Structure to save capability information.
  756. */
  757. void USDHC_GetCapability(USDHC_Type *base, usdhc_capability_t *capability);
  758. /*!
  759. * @brief force the card clock on.
  760. *
  761. * @param base USDHC peripheral base address.
  762. * @param enable/disable flag.
  763. */
  764. static inline void USDHC_ForceClockOn(USDHC_Type *base, bool enable)
  765. {
  766. if (enable)
  767. {
  768. base->VEND_SPEC |= USDHC_VEND_SPEC_FRC_SDCLK_ON_MASK;
  769. }
  770. else
  771. {
  772. base->VEND_SPEC &= ~USDHC_VEND_SPEC_FRC_SDCLK_ON_MASK;
  773. }
  774. }
  775. /*!
  776. * @brief Sets the SD bus clock frequency.
  777. *
  778. * @param base USDHC peripheral base address.
  779. * @param srcClock_Hz USDHC source clock frequency united in Hz.
  780. * @param busClock_Hz SD bus clock frequency united in Hz.
  781. *
  782. * @return The nearest frequency of busClock_Hz configured to SD bus.
  783. */
  784. uint32_t USDHC_SetSdClock(USDHC_Type *base, uint32_t srcClock_Hz, uint32_t busClock_Hz);
  785. /*!
  786. * @brief Sends 80 clocks to the card to set it to the active state.
  787. *
  788. * This function must be called each time the card is inserted to ensure that the card can receive the command
  789. * correctly.
  790. *
  791. * @param base USDHC peripheral base address.
  792. * @param timeout Timeout to initialize card.
  793. * @retval true Set card active successfully.
  794. * @retval false Set card active failed.
  795. */
  796. bool USDHC_SetCardActive(USDHC_Type *base, uint32_t timeout);
  797. /*!
  798. * @brief trigger a hardware reset.
  799. *
  800. * @param base USDHC peripheral base address.
  801. * @param 1 or 0 level
  802. */
  803. static inline void USDHC_AssertHardwareReset(USDHC_Type *base, bool high)
  804. {
  805. if (high)
  806. {
  807. base->SYS_CTRL |= USDHC_SYS_CTRL_IPP_RST_N_MASK;
  808. }
  809. else
  810. {
  811. base->SYS_CTRL &= ~USDHC_SYS_CTRL_IPP_RST_N_MASK;
  812. }
  813. }
  814. /*!
  815. * @brief Sets the data transfer width.
  816. *
  817. * @param base USDHC peripheral base address.
  818. * @param width Data transfer width.
  819. */
  820. static inline void USDHC_SetDataBusWidth(USDHC_Type *base, usdhc_data_bus_width_t width)
  821. {
  822. base->PROT_CTRL = ((base->PROT_CTRL & ~USDHC_PROT_CTRL_DTW_MASK) | USDHC_PROT_CTRL_DTW(width));
  823. }
  824. /*!
  825. * @brief Fills the the data port.
  826. *
  827. * This function is used to implement the data transfer by Data Port instead of DMA.
  828. *
  829. * @param base USDHC peripheral base address.
  830. * @param data The data about to be sent.
  831. */
  832. static inline void USDHC_WriteData(USDHC_Type *base, uint32_t data)
  833. {
  834. base->DATA_BUFF_ACC_PORT = data;
  835. }
  836. /*!
  837. * @brief Retrieves the data from the data port.
  838. *
  839. * This function is used to implement the data transfer by Data Port instead of DMA.
  840. *
  841. * @param base USDHC peripheral base address.
  842. * @return The data has been read.
  843. */
  844. static inline uint32_t USDHC_ReadData(USDHC_Type *base)
  845. {
  846. return base->DATA_BUFF_ACC_PORT;
  847. }
  848. /*!
  849. * @brief send command function
  850. *
  851. * @param base USDHC peripheral base address.
  852. * @param command configuration
  853. */
  854. void USDHC_SendCommand(USDHC_Type *base, usdhc_command_t *command);
  855. /*!
  856. * @brief Enables or disables a wakeup event in low-power mode.
  857. *
  858. * @param base USDHC peripheral base address.
  859. * @param mask Wakeup events mask(_usdhc_wakeup_event).
  860. * @param enable True to enable, false to disable.
  861. */
  862. static inline void USDHC_EnableWakeupEvent(USDHC_Type *base, uint32_t mask, bool enable)
  863. {
  864. if (enable)
  865. {
  866. base->PROT_CTRL |= mask;
  867. }
  868. else
  869. {
  870. base->PROT_CTRL &= ~mask;
  871. }
  872. }
  873. /*!
  874. * @brief detect card insert status.
  875. *
  876. * @param base USDHC peripheral base address.
  877. * @param enable/disable flag
  878. */
  879. static inline void USDHC_CardDetectByData3(USDHC_Type *base, bool enable)
  880. {
  881. if (enable)
  882. {
  883. base->PROT_CTRL |= USDHC_PROT_CTRL_D3CD_MASK;
  884. }
  885. else
  886. {
  887. base->PROT_CTRL &= ~USDHC_PROT_CTRL_D3CD_MASK;
  888. }
  889. }
  890. /*!
  891. * @brief detect card insert status.
  892. *
  893. * @param base USDHC peripheral base address.
  894. */
  895. static inline bool USDHC_DetectCardInsert(USDHC_Type *base)
  896. {
  897. return (base->PRES_STATE & kUSDHC_CardInsertedFlag) ? true : false;
  898. }
  899. /*!
  900. * @brief Enables or disables the SDIO card control.
  901. *
  902. * @param base USDHC peripheral base address.
  903. * @param mask SDIO card control flags mask(_usdhc_sdio_control_flag).
  904. * @param enable True to enable, false to disable.
  905. */
  906. static inline void USDHC_EnableSdioControl(USDHC_Type *base, uint32_t mask, bool enable)
  907. {
  908. if (enable)
  909. {
  910. base->PROT_CTRL |= mask;
  911. }
  912. else
  913. {
  914. base->PROT_CTRL &= ~mask;
  915. }
  916. }
  917. /*!
  918. * @brief Restarts a transaction which has stopped at the block GAP for the SDIO card.
  919. *
  920. * @param base USDHC peripheral base address.
  921. */
  922. static inline void USDHC_SetContinueRequest(USDHC_Type *base)
  923. {
  924. base->PROT_CTRL |= USDHC_PROT_CTRL_CREQ_MASK;
  925. }
  926. /*!
  927. * @brief Configures the MMC boot feature.
  928. *
  929. * Example:
  930. @code
  931. usdhc_boot_config_t config;
  932. config.ackTimeoutCount = 4;
  933. config.bootMode = kUSDHC_BootModeNormal;
  934. config.blockCount = 5;
  935. config.enableBootAck = true;
  936. config.enableBoot = true;
  937. config.enableAutoStopAtBlockGap = true;
  938. USDHC_SetMmcBootConfig(USDHC, &config);
  939. @endcode
  940. *
  941. * @param base USDHC peripheral base address.
  942. * @param config The MMC boot configuration information.
  943. */
  944. void USDHC_SetMmcBootConfig(USDHC_Type *base, const usdhc_boot_config_t *config);
  945. /*!
  946. * @brief Forces generating events according to the given mask.
  947. *
  948. * @param base USDHC peripheral base address.
  949. * @param mask The force events mask(_usdhc_force_event).
  950. */
  951. static inline void USDHC_SetForceEvent(USDHC_Type *base, uint32_t mask)
  952. {
  953. base->FORCE_EVENT = mask;
  954. }
  955. /*!
  956. * @brief select the usdhc output voltage
  957. *
  958. * @param base USDHC peripheral base address.
  959. * @param true 1.8V, false 3.0V
  960. */
  961. static inline void UDSHC_SelectVoltage(USDHC_Type *base, bool en18v)
  962. {
  963. if (en18v)
  964. {
  965. base->VEND_SPEC |= USDHC_VEND_SPEC_VSELECT_MASK;
  966. }
  967. else
  968. {
  969. base->VEND_SPEC &= ~USDHC_VEND_SPEC_VSELECT_MASK;
  970. }
  971. }
  972. #if defined(FSL_FEATURE_USDHC_HAS_SDR50_MODE) && (!FSL_FEATURE_USDHC_HAS_SDR50_MODE)
  973. #else
  974. /*!
  975. * @brief check the SDR50 mode request tuning bit
  976. * When this bit set, user should call USDHC_StandardTuning function
  977. * @param base USDHC peripheral base address.
  978. */
  979. static inline bool USDHC_RequestTuningForSDR50(USDHC_Type *base)
  980. {
  981. return base->HOST_CTRL_CAP & USDHC_HOST_CTRL_CAP_USE_TUNING_SDR50_MASK ? true : false;
  982. }
  983. /*!
  984. * @brief check the request re-tuning bit
  985. * When this bit is set, user should do manual tuning or standard tuning function
  986. * @param base USDHC peripheral base address.
  987. */
  988. static inline bool USDHC_RequestReTuning(USDHC_Type *base)
  989. {
  990. return base->PRES_STATE & USDHC_PRES_STATE_RTR_MASK ? true : false;
  991. }
  992. /*!
  993. * @brief the SDR104 mode auto tuning enable and disable
  994. * This function should call after tuning function execute pass, auto tuning will handle
  995. * by hardware
  996. * @param base USDHC peripheral base address.
  997. * @param enable/disable flag
  998. */
  999. static inline void USDHC_EnableAutoTuning(USDHC_Type *base, bool enable)
  1000. {
  1001. if (enable)
  1002. {
  1003. base->MIX_CTRL |= USDHC_MIX_CTRL_AUTO_TUNE_EN_MASK;
  1004. }
  1005. else
  1006. {
  1007. base->MIX_CTRL &= ~USDHC_MIX_CTRL_AUTO_TUNE_EN_MASK;
  1008. }
  1009. }
  1010. /*!
  1011. * @brief the config the re-tuning timer for mode 1 and mode 3
  1012. * This timer is used for standard tuning auto re-tuning,
  1013. * @param base USDHC peripheral base address.
  1014. * @param timer counter value
  1015. */
  1016. static inline void USDHC_SetRetuningTimer(USDHC_Type *base, uint32_t counter)
  1017. {
  1018. base->HOST_CTRL_CAP &= ~USDHC_HOST_CTRL_CAP_TIME_COUNT_RETUNING_MASK;
  1019. base->HOST_CTRL_CAP |= USDHC_HOST_CTRL_CAP_TIME_COUNT_RETUNING(counter);
  1020. }
  1021. /*!
  1022. * @brief the auto tuning enbale for CMD/DATA line
  1023. *
  1024. * @param base USDHC peripheral base address.
  1025. */
  1026. void USDHC_EnableAutoTuningForCmdAndData(USDHC_Type *base);
  1027. /*!
  1028. * @brief manual tuning trigger or abort
  1029. * User should handle the tuning cmd and find the boundary of the delay
  1030. * then calucate a average value which will be config to the CLK_TUNE_CTRL_STATUS
  1031. * This function should called before USDHC_AdjustDelayforSDR104 function
  1032. * @param base USDHC peripheral base address.
  1033. * @param tuning enable flag
  1034. */
  1035. void USDHC_EnableManualTuning(USDHC_Type *base, bool enable);
  1036. /*!
  1037. * @brief the SDR104 mode delay setting adjust
  1038. * This function should called after USDHC_ManualTuningForSDR104
  1039. * @param base USDHC peripheral base address.
  1040. * @param delay setting configuration
  1041. * @retval kStatus_Fail config the delay setting fail
  1042. * @retval kStatus_Success config the delay setting success
  1043. */
  1044. status_t USDHC_AdjustDelayForManualTuning(USDHC_Type *base, uint32_t delay);
  1045. /*!
  1046. * @brief the enable standard tuning function
  1047. * The standard tuning window and tuning counter use the default config
  1048. * tuning cmd is send by the software, user need to check the tuning result
  1049. * can be used for SDR50,SDR104,HS200 mode tuning
  1050. * @param base USDHC peripheral base address.
  1051. * @param tuning start tap
  1052. * @param tuning step
  1053. * @param enable/disable flag
  1054. */
  1055. void USDHC_EnableStandardTuning(USDHC_Type *base, uint32_t tuningStartTap, uint32_t step, bool enable);
  1056. /*!
  1057. * @brief Get execute std tuning status
  1058. *
  1059. * @param base USDHC peripheral base address.
  1060. */
  1061. static inline uint32_t USDHC_GetExecuteStdTuningStatus(USDHC_Type *base)
  1062. {
  1063. return (base->AUTOCMD12_ERR_STATUS & USDHC_AUTOCMD12_ERR_STATUS_EXECUTE_TUNING_MASK);
  1064. }
  1065. /*!
  1066. * @brief check std tuning result
  1067. *
  1068. * @param base USDHC peripheral base address.
  1069. */
  1070. static inline uint32_t USDHC_CheckStdTuningResult(USDHC_Type *base)
  1071. {
  1072. return (base->AUTOCMD12_ERR_STATUS & USDHC_AUTOCMD12_ERR_STATUS_SMP_CLK_SEL_MASK);
  1073. }
  1074. /*!
  1075. * @brief check tuning error
  1076. *
  1077. * @param base USDHC peripheral base address.
  1078. */
  1079. static inline uint32_t USDHC_CheckTuningError(USDHC_Type *base)
  1080. {
  1081. return (base->CLK_TUNE_CTRL_STATUS &
  1082. (USDHC_CLK_TUNE_CTRL_STATUS_NXT_ERR_MASK | USDHC_CLK_TUNE_CTRL_STATUS_PRE_ERR_MASK));
  1083. }
  1084. #endif
  1085. /*!
  1086. * @brief the enable/disable DDR mode
  1087. *
  1088. * @param base USDHC peripheral base address.
  1089. * @param enable/disable flag
  1090. * @param nibble position
  1091. */
  1092. static inline void USDHC_EnableDDRMode(USDHC_Type *base, bool enable, uint32_t nibblePos)
  1093. {
  1094. if (enable)
  1095. {
  1096. base->MIX_CTRL &= ~USDHC_MIX_CTRL_NIBBLE_POS_MASK;
  1097. base->MIX_CTRL |= (USDHC_MIX_CTRL_DDR_EN_MASK | USDHC_MIX_CTRL_NIBBLE_POS(nibblePos));
  1098. }
  1099. else
  1100. {
  1101. base->MIX_CTRL &= ~USDHC_MIX_CTRL_DDR_EN_MASK;
  1102. }
  1103. }
  1104. /*!
  1105. * @brief the enable/disable HS400 mode
  1106. *
  1107. * @param base USDHC peripheral base address.
  1108. * @param enable/disable flag
  1109. */
  1110. #if FSL_FEATURE_USDHC_HAS_HS400_MODE
  1111. static inline void USDHC_EnableHS400Mode(USDHC_Type *base, bool enable)
  1112. {
  1113. if (enable)
  1114. {
  1115. base->MIX_CTRL |= USDHC_MIX_CTRL_HS400_MODE_MASK;
  1116. }
  1117. else
  1118. {
  1119. base->MIX_CTRL &= ~USDHC_MIX_CTRL_HS400_MODE_MASK;
  1120. }
  1121. }
  1122. /*!
  1123. * @brief reset the strobe DLL
  1124. *
  1125. * @param base USDHC peripheral base address.
  1126. */
  1127. static inline void USDHC_ResetStrobeDLL(USDHC_Type *base)
  1128. {
  1129. base->STROBE_DLL_CTRL |= USDHC_STROBE_DLL_CTRL_STROBE_DLL_CTRL_RESET_MASK;
  1130. }
  1131. /*!
  1132. * @brief enable/disable the strobe DLL
  1133. *
  1134. * @param base USDHC peripheral base address.
  1135. * @param enable/disable flag
  1136. */
  1137. static inline void USDHC_EnableStrobeDLL(USDHC_Type *base, bool enable)
  1138. {
  1139. if (enable)
  1140. {
  1141. base->STROBE_DLL_CTRL |= USDHC_STROBE_DLL_CTRL_STROBE_DLL_CTRL_ENABLE_MASK;
  1142. }
  1143. else
  1144. {
  1145. base->STROBE_DLL_CTRL &= ~USDHC_STROBE_DLL_CTRL_STROBE_DLL_CTRL_ENABLE_MASK;
  1146. }
  1147. }
  1148. /*!
  1149. * @brief config the strobe DLL delay target and update interval
  1150. *
  1151. * @param base USDHC peripheral base address.
  1152. * @param delay target
  1153. * @param update interval
  1154. */
  1155. static inline void USDHC_ConfigStrobeDLL(USDHC_Type *base, uint32_t delayTarget, uint32_t updateInterval)
  1156. {
  1157. base->STROBE_DLL_CTRL &= (USDHC_STROBE_DLL_CTRL_STROBE_DLL_CTRL_SLV_UPDATE_INT_MASK |
  1158. USDHC_STROBE_DLL_CTRL_STROBE_DLL_CTRL_SLV_DLY_TARGET_MASK);
  1159. base->STROBE_DLL_CTRL |= USDHC_STROBE_DLL_CTRL_STROBE_DLL_CTRL_SLV_UPDATE_INT(updateInterval) |
  1160. USDHC_STROBE_DLL_CTRL_STROBE_DLL_CTRL_SLV_DLY_TARGET(delayTarget);
  1161. }
  1162. /*!
  1163. * @brief get the strobe DLL status
  1164. *
  1165. * @param base USDHC peripheral base address.
  1166. */
  1167. static inline uint32_t USDHC_GetStrobeDLLStatus(USDHC_Type *base)
  1168. {
  1169. return base->STROBE_DLL_STATUS;
  1170. }
  1171. #endif
  1172. /* @} */
  1173. /*!
  1174. * @name Transactional
  1175. * @{
  1176. */
  1177. /*!
  1178. * @brief Transfers the command/data using a blocking method.
  1179. *
  1180. * This function waits until the command response/data is received or the USDHC encounters an error by polling the
  1181. * status
  1182. * flag.
  1183. * The application must not call this API in multiple threads at the same time. Because of that this API doesn't support
  1184. * the re-entry mechanism.
  1185. *
  1186. * @note There is no need to call the API 'USDHC_TransferCreateHandle' when calling this API.
  1187. *
  1188. * @param base USDHC peripheral base address.
  1189. * @param adma configuration
  1190. * @param transfer Transfer content.
  1191. * @retval kStatus_InvalidArgument Argument is invalid.
  1192. * @retval kStatus_USDHC_PrepareAdmaDescriptorFailed Prepare ADMA descriptor failed.
  1193. * @retval kStatus_USDHC_SendCommandFailed Send command failed.
  1194. * @retval kStatus_USDHC_TransferDataFailed Transfer data failed.
  1195. * @retval kStatus_Success Operate successfully.
  1196. */
  1197. status_t USDHC_TransferBlocking(USDHC_Type *base, usdhc_adma_config_t *dmaConfig, usdhc_transfer_t *transfer);
  1198. /*!
  1199. * @brief Creates the USDHC handle.
  1200. *
  1201. * @param base USDHC peripheral base address.
  1202. * @param handle USDHC handle pointer.
  1203. * @param callback Structure pointer to contain all callback functions.
  1204. * @param userData Callback function parameter.
  1205. */
  1206. void USDHC_TransferCreateHandle(USDHC_Type *base,
  1207. usdhc_handle_t *handle,
  1208. const usdhc_transfer_callback_t *callback,
  1209. void *userData);
  1210. /*!
  1211. * @brief Transfers the command/data using an interrupt and an asynchronous method.
  1212. *
  1213. * This function sends a command and data and returns immediately. It doesn't wait the transfer complete or encounter an
  1214. * error.
  1215. * The application must not call this API in multiple threads at the same time. Because of that this API doesn't support
  1216. * the re-entry mechanism.
  1217. *
  1218. * @note Call the API 'USDHC_TransferCreateHandle' when calling this API.
  1219. *
  1220. * @param base USDHC peripheral base address.
  1221. * @param handle USDHC handle.
  1222. * @param adma configuration.
  1223. * @param transfer Transfer content.
  1224. * @retval kStatus_InvalidArgument Argument is invalid.
  1225. * @retval kStatus_USDHC_BusyTransferring Busy transferring.
  1226. * @retval kStatus_USDHC_PrepareAdmaDescriptorFailed Prepare ADMA descriptor failed.
  1227. * @retval kStatus_Success Operate successfully.
  1228. */
  1229. status_t USDHC_TransferNonBlocking(USDHC_Type *base,
  1230. usdhc_handle_t *handle,
  1231. usdhc_adma_config_t *dmaConfig,
  1232. usdhc_transfer_t *transfer);
  1233. /*!
  1234. * @brief IRQ handler for the USDHC.
  1235. *
  1236. * This function deals with the IRQs on the given host controller.
  1237. *
  1238. * @param base USDHC peripheral base address.
  1239. * @param handle USDHC handle.
  1240. */
  1241. void USDHC_TransferHandleIRQ(USDHC_Type *base, usdhc_handle_t *handle);
  1242. /* @} */
  1243. #if defined(__cplusplus)
  1244. }
  1245. #endif
  1246. /*! @} */
  1247. #endif /* _FSL_USDHC_H_*/