The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 145:64910690c574 1 /*
AnnaBridge 145:64910690c574 2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
AnnaBridge 145:64910690c574 3 * All rights reserved.
AnnaBridge 145:64910690c574 4 *
AnnaBridge 145:64910690c574 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 145:64910690c574 6 * are permitted provided that the following conditions are met:
AnnaBridge 145:64910690c574 7 *
AnnaBridge 145:64910690c574 8 * o Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 145:64910690c574 9 * of conditions and the following disclaimer.
AnnaBridge 145:64910690c574 10 *
AnnaBridge 145:64910690c574 11 * o Redistributions in binary form must reproduce the above copyright notice, this
AnnaBridge 145:64910690c574 12 * list of conditions and the following disclaimer in the documentation and/or
AnnaBridge 145:64910690c574 13 * other materials provided with the distribution.
AnnaBridge 145:64910690c574 14 *
AnnaBridge 145:64910690c574 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
AnnaBridge 145:64910690c574 16 * contributors may be used to endorse or promote products derived from this
AnnaBridge 145:64910690c574 17 * software without specific prior written permission.
AnnaBridge 145:64910690c574 18 *
AnnaBridge 145:64910690c574 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 145:64910690c574 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 145:64910690c574 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 145:64910690c574 22 * DISCLAIMED. IN NO EVENT SL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 145:64910690c574 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 145:64910690c574 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 145:64910690c574 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 145:64910690c574 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 145:64910690c574 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 145:64910690c574 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 145:64910690c574 29 */
AnnaBridge 145:64910690c574 30 #ifndef _FSL_SDHC_H_
AnnaBridge 145:64910690c574 31 #define _FSL_SDHC_H_
AnnaBridge 145:64910690c574 32
AnnaBridge 145:64910690c574 33 #include "fsl_common.h"
AnnaBridge 145:64910690c574 34
AnnaBridge 145:64910690c574 35 /*!
AnnaBridge 145:64910690c574 36 * @addtogroup sdhc
AnnaBridge 145:64910690c574 37 * @{
AnnaBridge 145:64910690c574 38 */
AnnaBridge 145:64910690c574 39
AnnaBridge 145:64910690c574 40 /******************************************************************************
AnnaBridge 145:64910690c574 41 * Definitions.
AnnaBridge 145:64910690c574 42 *****************************************************************************/
AnnaBridge 145:64910690c574 43
AnnaBridge 145:64910690c574 44 /*! @name Driver version */
AnnaBridge 145:64910690c574 45 /*@{*/
AnnaBridge 145:64910690c574 46 /*! @brief Driver version 2.1.2. */
AnnaBridge 145:64910690c574 47 #define FSL_SDHC_DRIVER_VERSION (MAKE_VERSION(2U, 1U, 2U))
AnnaBridge 145:64910690c574 48 /*@}*/
AnnaBridge 145:64910690c574 49
AnnaBridge 145:64910690c574 50 /*! @brief Maximum block count can be set one time */
AnnaBridge 145:64910690c574 51 #define SDHC_MAX_BLOCK_COUNT (SDHC_BLKATTR_BLKCNT_MASK >> SDHC_BLKATTR_BLKCNT_SHIFT)
AnnaBridge 145:64910690c574 52
AnnaBridge 145:64910690c574 53 /*! @brief SDHC status */
AnnaBridge 145:64910690c574 54 enum _sdhc_status
AnnaBridge 145:64910690c574 55 {
AnnaBridge 145:64910690c574 56 kStatus_SDHC_BusyTransferring = MAKE_STATUS(kStatusGroup_SDHC, 0U), /*!< Transfer is on-going */
AnnaBridge 145:64910690c574 57 kStatus_SDHC_PrepareAdmaDescriptorFailed = MAKE_STATUS(kStatusGroup_SDHC, 1U), /*!< Set DMA descriptor failed */
AnnaBridge 145:64910690c574 58 kStatus_SDHC_SendCommandFailed = MAKE_STATUS(kStatusGroup_SDHC, 2U), /*!< Send command failed */
AnnaBridge 145:64910690c574 59 kStatus_SDHC_TransferDataFailed = MAKE_STATUS(kStatusGroup_SDHC, 3U), /*!< Transfer data failed */
AnnaBridge 145:64910690c574 60 };
AnnaBridge 145:64910690c574 61
AnnaBridge 145:64910690c574 62 /*! @brief Host controller capabilities flag mask */
AnnaBridge 145:64910690c574 63 enum _sdhc_capability_flag
AnnaBridge 145:64910690c574 64 {
AnnaBridge 145:64910690c574 65 kSDHC_SupportAdmaFlag = SDHC_HTCAPBLT_ADMAS_MASK, /*!< Support ADMA */
AnnaBridge 145:64910690c574 66 kSDHC_SupportHighSpeedFlag = SDHC_HTCAPBLT_HSS_MASK, /*!< Support high-speed */
AnnaBridge 145:64910690c574 67 kSDHC_SupportDmaFlag = SDHC_HTCAPBLT_DMAS_MASK, /*!< Support DMA */
AnnaBridge 145:64910690c574 68 kSDHC_SupportSuspendResumeFlag = SDHC_HTCAPBLT_SRS_MASK, /*!< Support suspend/resume */
AnnaBridge 145:64910690c574 69 kSDHC_SupportV330Flag = SDHC_HTCAPBLT_VS33_MASK, /*!< Support voltage 3.3V */
AnnaBridge 145:64910690c574 70 #if defined FSL_FEATURE_SDHC_HAS_V300_SUPPORT && FSL_FEATURE_SDHC_HAS_V300_SUPPORT
AnnaBridge 145:64910690c574 71 kSDHC_SupportV300Flag = SDHC_HTCAPBLT_VS30_MASK, /*!< Support voltage 3.0V */
AnnaBridge 145:64910690c574 72 #endif
AnnaBridge 145:64910690c574 73 #if defined FSL_FEATURE_SDHC_HAS_V180_SUPPORT && FSL_FEATURE_SDHC_HAS_V180_SUPPORT
AnnaBridge 145:64910690c574 74 kSDHC_SupportV180Flag = SDHC_HTCAPBLT_VS18_MASK, /*!< Support voltage 1.8V */
AnnaBridge 145:64910690c574 75 #endif
AnnaBridge 145:64910690c574 76 /* Put additional two flags in HTCAPBLT_MBL's position. */
AnnaBridge 145:64910690c574 77 kSDHC_Support4BitFlag = (SDHC_HTCAPBLT_MBL_SHIFT << 0U), /*!< Support 4 bit mode */
AnnaBridge 145:64910690c574 78 kSDHC_Support8BitFlag = (SDHC_HTCAPBLT_MBL_SHIFT << 1U), /*!< Support 8 bit mode */
AnnaBridge 145:64910690c574 79 };
AnnaBridge 145:64910690c574 80
AnnaBridge 145:64910690c574 81 /*! @brief Wakeup event mask */
AnnaBridge 145:64910690c574 82 enum _sdhc_wakeup_event
AnnaBridge 145:64910690c574 83 {
AnnaBridge 145:64910690c574 84 kSDHC_WakeupEventOnCardInt = SDHC_PROCTL_WECINT_MASK, /*!< Wakeup on card interrupt */
AnnaBridge 145:64910690c574 85 kSDHC_WakeupEventOnCardInsert = SDHC_PROCTL_WECINS_MASK, /*!< Wakeup on card insertion */
AnnaBridge 145:64910690c574 86 kSDHC_WakeupEventOnCardRemove = SDHC_PROCTL_WECRM_MASK, /*!< Wakeup on card removal */
AnnaBridge 145:64910690c574 87
AnnaBridge 145:64910690c574 88 kSDHC_WakeupEventsAll = (kSDHC_WakeupEventOnCardInt | kSDHC_WakeupEventOnCardInsert |
AnnaBridge 145:64910690c574 89 kSDHC_WakeupEventOnCardRemove), /*!< All wakeup events */
AnnaBridge 145:64910690c574 90 };
AnnaBridge 145:64910690c574 91
AnnaBridge 145:64910690c574 92 /*! @brief Reset type mask */
AnnaBridge 145:64910690c574 93 enum _sdhc_reset
AnnaBridge 145:64910690c574 94 {
AnnaBridge 145:64910690c574 95 kSDHC_ResetAll = SDHC_SYSCTL_RSTA_MASK, /*!< Reset all except card detection */
AnnaBridge 145:64910690c574 96 kSDHC_ResetCommand = SDHC_SYSCTL_RSTC_MASK, /*!< Reset command line */
AnnaBridge 145:64910690c574 97 kSDHC_ResetData = SDHC_SYSCTL_RSTD_MASK, /*!< Reset data line */
AnnaBridge 145:64910690c574 98
AnnaBridge 145:64910690c574 99 kSDHC_ResetsAll = (kSDHC_ResetAll | kSDHC_ResetCommand | kSDHC_ResetData), /*!< All reset types */
AnnaBridge 145:64910690c574 100 };
AnnaBridge 145:64910690c574 101
AnnaBridge 145:64910690c574 102 /*! @brief Transfer flag mask */
AnnaBridge 145:64910690c574 103 enum _sdhc_transfer_flag
AnnaBridge 145:64910690c574 104 {
AnnaBridge 145:64910690c574 105 kSDHC_EnableDmaFlag = SDHC_XFERTYP_DMAEN_MASK, /*!< Enable DMA */
AnnaBridge 145:64910690c574 106
AnnaBridge 145:64910690c574 107 kSDHC_CommandTypeSuspendFlag = (SDHC_XFERTYP_CMDTYP(1U)), /*!< Suspend command */
AnnaBridge 145:64910690c574 108 kSDHC_CommandTypeResumeFlag = (SDHC_XFERTYP_CMDTYP(2U)), /*!< Resume command */
AnnaBridge 145:64910690c574 109 kSDHC_CommandTypeAbortFlag = (SDHC_XFERTYP_CMDTYP(3U)), /*!< Abort command */
AnnaBridge 145:64910690c574 110
AnnaBridge 145:64910690c574 111 kSDHC_EnableBlockCountFlag = SDHC_XFERTYP_BCEN_MASK, /*!< Enable block count */
AnnaBridge 145:64910690c574 112 kSDHC_EnableAutoCommand12Flag = SDHC_XFERTYP_AC12EN_MASK, /*!< Enable auto CMD12 */
AnnaBridge 145:64910690c574 113 kSDHC_DataReadFlag = SDHC_XFERTYP_DTDSEL_MASK, /*!< Enable data read */
AnnaBridge 145:64910690c574 114 kSDHC_MultipleBlockFlag = SDHC_XFERTYP_MSBSEL_MASK, /*!< Multiple block data read/write */
AnnaBridge 145:64910690c574 115
AnnaBridge 145:64910690c574 116 kSDHC_ResponseLength136Flag = SDHC_XFERTYP_RSPTYP(1U), /*!< 136 bit response length */
AnnaBridge 145:64910690c574 117 kSDHC_ResponseLength48Flag = SDHC_XFERTYP_RSPTYP(2U), /*!< 48 bit response length */
AnnaBridge 145:64910690c574 118 kSDHC_ResponseLength48BusyFlag = SDHC_XFERTYP_RSPTYP(3U), /*!< 48 bit response length with busy status */
AnnaBridge 145:64910690c574 119
AnnaBridge 145:64910690c574 120 kSDHC_EnableCrcCheckFlag = SDHC_XFERTYP_CCCEN_MASK, /*!< Enable CRC check */
AnnaBridge 145:64910690c574 121 kSDHC_EnableIndexCheckFlag = SDHC_XFERTYP_CICEN_MASK, /*!< Enable index check */
AnnaBridge 145:64910690c574 122 kSDHC_DataPresentFlag = SDHC_XFERTYP_DPSEL_MASK, /*!< Data present flag */
AnnaBridge 145:64910690c574 123 };
AnnaBridge 145:64910690c574 124
AnnaBridge 145:64910690c574 125 /*! @brief Present status flag mask */
AnnaBridge 145:64910690c574 126 enum _sdhc_present_status_flag
AnnaBridge 145:64910690c574 127 {
AnnaBridge 145:64910690c574 128 kSDHC_CommandInhibitFlag = SDHC_PRSSTAT_CIHB_MASK, /*!< Command inhibit */
AnnaBridge 145:64910690c574 129 kSDHC_DataInhibitFlag = SDHC_PRSSTAT_CDIHB_MASK, /*!< Data inhibit */
AnnaBridge 145:64910690c574 130 kSDHC_DataLineActiveFlag = SDHC_PRSSTAT_DLA_MASK, /*!< Data line active */
AnnaBridge 145:64910690c574 131 kSDHC_SdClockStableFlag = SDHC_PRSSTAT_SDSTB_MASK, /*!< SD bus clock stable */
AnnaBridge 145:64910690c574 132 kSDHC_WriteTransferActiveFlag = SDHC_PRSSTAT_WTA_MASK, /*!< Write transfer active */
AnnaBridge 145:64910690c574 133 kSDHC_ReadTransferActiveFlag = SDHC_PRSSTAT_RTA_MASK, /*!< Read transfer active */
AnnaBridge 145:64910690c574 134 kSDHC_BufferWriteEnableFlag = SDHC_PRSSTAT_BWEN_MASK, /*!< Buffer write enable */
AnnaBridge 145:64910690c574 135 kSDHC_BufferReadEnableFlag = SDHC_PRSSTAT_BREN_MASK, /*!< Buffer read enable */
AnnaBridge 145:64910690c574 136 kSDHC_CardInsertedFlag = SDHC_PRSSTAT_CINS_MASK, /*!< Card inserted */
AnnaBridge 145:64910690c574 137 kSDHC_CommandLineLevelFlag = SDHC_PRSSTAT_CLSL_MASK, /*!< Command line signal level */
AnnaBridge 145:64910690c574 138 kSDHC_Data0LineLevelFlag = (1U << 24U), /*!< Data0 line signal level */
AnnaBridge 145:64910690c574 139 kSDHC_Data1LineLevelFlag = (1U << 25U), /*!< Data1 line signal level */
AnnaBridge 145:64910690c574 140 kSDHC_Data2LineLevelFlag = (1U << 26U), /*!< Data2 line signal level */
AnnaBridge 145:64910690c574 141 kSDHC_Data3LineLevelFlag = (1U << 27U), /*!< Data3 line signal level */
AnnaBridge 145:64910690c574 142 kSDHC_Data4LineLevelFlag = (1U << 28U), /*!< Data4 line signal level */
AnnaBridge 145:64910690c574 143 kSDHC_Data5LineLevelFlag = (1U << 29U), /*!< Data5 line signal level */
AnnaBridge 145:64910690c574 144 kSDHC_Data6LineLevelFlag = (1U << 30U), /*!< Data6 line signal level */
AnnaBridge 145:64910690c574 145 kSDHC_Data7LineLevelFlag = (1U << 31U), /*!< Data7 line signal level */
AnnaBridge 145:64910690c574 146 };
AnnaBridge 145:64910690c574 147
AnnaBridge 145:64910690c574 148 /*! @brief Interrupt status flag mask */
AnnaBridge 145:64910690c574 149 enum _sdhc_interrupt_status_flag
AnnaBridge 145:64910690c574 150 {
AnnaBridge 145:64910690c574 151 kSDHC_CommandCompleteFlag = SDHC_IRQSTAT_CC_MASK, /*!< Command complete */
AnnaBridge 145:64910690c574 152 kSDHC_DataCompleteFlag = SDHC_IRQSTAT_TC_MASK, /*!< Data complete */
AnnaBridge 145:64910690c574 153 kSDHC_BlockGapEventFlag = SDHC_IRQSTAT_BGE_MASK, /*!< Block gap event */
AnnaBridge 145:64910690c574 154 kSDHC_DmaCompleteFlag = SDHC_IRQSTAT_DINT_MASK, /*!< DMA interrupt */
AnnaBridge 145:64910690c574 155 kSDHC_BufferWriteReadyFlag = SDHC_IRQSTAT_BWR_MASK, /*!< Buffer write ready */
AnnaBridge 145:64910690c574 156 kSDHC_BufferReadReadyFlag = SDHC_IRQSTAT_BRR_MASK, /*!< Buffer read ready */
AnnaBridge 145:64910690c574 157 kSDHC_CardInsertionFlag = SDHC_IRQSTAT_CINS_MASK, /*!< Card inserted */
AnnaBridge 145:64910690c574 158 kSDHC_CardRemovalFlag = SDHC_IRQSTAT_CRM_MASK, /*!< Card removed */
AnnaBridge 145:64910690c574 159 kSDHC_CardInterruptFlag = SDHC_IRQSTAT_CINT_MASK, /*!< Card interrupt */
AnnaBridge 145:64910690c574 160 kSDHC_CommandTimeoutFlag = SDHC_IRQSTAT_CTOE_MASK, /*!< Command timeout error */
AnnaBridge 145:64910690c574 161 kSDHC_CommandCrcErrorFlag = SDHC_IRQSTAT_CCE_MASK, /*!< Command CRC error */
AnnaBridge 145:64910690c574 162 kSDHC_CommandEndBitErrorFlag = SDHC_IRQSTAT_CEBE_MASK, /*!< Command end bit error */
AnnaBridge 145:64910690c574 163 kSDHC_CommandIndexErrorFlag = SDHC_IRQSTAT_CIE_MASK, /*!< Command index error */
AnnaBridge 145:64910690c574 164 kSDHC_DataTimeoutFlag = SDHC_IRQSTAT_DTOE_MASK, /*!< Data timeout error */
AnnaBridge 145:64910690c574 165 kSDHC_DataCrcErrorFlag = SDHC_IRQSTAT_DCE_MASK, /*!< Data CRC error */
AnnaBridge 145:64910690c574 166 kSDHC_DataEndBitErrorFlag = SDHC_IRQSTAT_DEBE_MASK, /*!< Data end bit error */
AnnaBridge 145:64910690c574 167 kSDHC_AutoCommand12ErrorFlag = SDHC_IRQSTAT_AC12E_MASK, /*!< Auto CMD12 error */
AnnaBridge 145:64910690c574 168 kSDHC_DmaErrorFlag = SDHC_IRQSTAT_DMAE_MASK, /*!< DMA error */
AnnaBridge 145:64910690c574 169
AnnaBridge 145:64910690c574 170 kSDHC_CommandErrorFlag = (kSDHC_CommandTimeoutFlag | kSDHC_CommandCrcErrorFlag | kSDHC_CommandEndBitErrorFlag |
AnnaBridge 145:64910690c574 171 kSDHC_CommandIndexErrorFlag), /*!< Command error */
AnnaBridge 145:64910690c574 172 kSDHC_DataErrorFlag = (kSDHC_DataTimeoutFlag | kSDHC_DataCrcErrorFlag | kSDHC_DataEndBitErrorFlag |
AnnaBridge 145:64910690c574 173 kSDHC_AutoCommand12ErrorFlag), /*!< Data error */
AnnaBridge 145:64910690c574 174 kSDHC_ErrorFlag = (kSDHC_CommandErrorFlag | kSDHC_DataErrorFlag | kSDHC_DmaErrorFlag), /*!< All error */
AnnaBridge 145:64910690c574 175 kSDHC_DataFlag = (kSDHC_DataCompleteFlag | kSDHC_DmaCompleteFlag | kSDHC_BufferWriteReadyFlag |
AnnaBridge 145:64910690c574 176 kSDHC_BufferReadReadyFlag | kSDHC_DataErrorFlag | kSDHC_DmaErrorFlag), /*!< Data interrupts */
AnnaBridge 145:64910690c574 177 kSDHC_CommandFlag = (kSDHC_CommandErrorFlag | kSDHC_CommandCompleteFlag), /*!< Command interrupts */
AnnaBridge 145:64910690c574 178 kSDHC_CardDetectFlag = (kSDHC_CardInsertionFlag | kSDHC_CardRemovalFlag), /*!< Card detection interrupts */
AnnaBridge 145:64910690c574 179
AnnaBridge 145:64910690c574 180 kSDHC_AllInterruptFlags = (kSDHC_BlockGapEventFlag | kSDHC_CardInterruptFlag | kSDHC_CommandFlag | kSDHC_DataFlag |
AnnaBridge 145:64910690c574 181 kSDHC_ErrorFlag), /*!< All flags mask */
AnnaBridge 145:64910690c574 182 };
AnnaBridge 145:64910690c574 183
AnnaBridge 145:64910690c574 184 /*! @brief Auto CMD12 error status flag mask */
AnnaBridge 145:64910690c574 185 enum _sdhc_auto_command12_error_status_flag
AnnaBridge 145:64910690c574 186 {
AnnaBridge 145:64910690c574 187 kSDHC_AutoCommand12NotExecutedFlag = SDHC_AC12ERR_AC12NE_MASK, /*!< Not executed error */
AnnaBridge 145:64910690c574 188 kSDHC_AutoCommand12TimeoutFlag = SDHC_AC12ERR_AC12TOE_MASK, /*!< Timeout error */
AnnaBridge 145:64910690c574 189 kSDHC_AutoCommand12EndBitErrorFlag = SDHC_AC12ERR_AC12EBE_MASK, /*!< End bit error */
AnnaBridge 145:64910690c574 190 kSDHC_AutoCommand12CrcErrorFlag = SDHC_AC12ERR_AC12CE_MASK, /*!< CRC error */
AnnaBridge 145:64910690c574 191 kSDHC_AutoCommand12IndexErrorFlag = SDHC_AC12ERR_AC12IE_MASK, /*!< Index error */
AnnaBridge 145:64910690c574 192 kSDHC_AutoCommand12NotIssuedFlag = SDHC_AC12ERR_CNIBAC12E_MASK, /*!< Not issued error */
AnnaBridge 145:64910690c574 193 };
AnnaBridge 145:64910690c574 194
AnnaBridge 145:64910690c574 195 /*! @brief ADMA error status flag mask */
AnnaBridge 145:64910690c574 196 enum _sdhc_adma_error_status_flag
AnnaBridge 145:64910690c574 197 {
AnnaBridge 145:64910690c574 198 kSDHC_AdmaLenghMismatchFlag = SDHC_ADMAES_ADMALME_MASK, /*!< Length mismatch error */
AnnaBridge 145:64910690c574 199 kSDHC_AdmaDescriptorErrorFlag = SDHC_ADMAES_ADMADCE_MASK, /*!< Descriptor error */
AnnaBridge 145:64910690c574 200 };
AnnaBridge 145:64910690c574 201
AnnaBridge 145:64910690c574 202 /*!
AnnaBridge 145:64910690c574 203 * @brief ADMA error state
AnnaBridge 145:64910690c574 204 *
AnnaBridge 145:64910690c574 205 * This state is the detail state when ADMA error has occurred.
AnnaBridge 145:64910690c574 206 */
AnnaBridge 145:64910690c574 207 typedef enum _sdhc_adma_error_state
AnnaBridge 145:64910690c574 208 {
AnnaBridge 145:64910690c574 209 kSDHC_AdmaErrorStateStopDma = 0x00U, /*!< Stop DMA */
AnnaBridge 145:64910690c574 210 kSDHC_AdmaErrorStateFetchDescriptor = 0x01U, /*!< Fetch descriptor */
AnnaBridge 145:64910690c574 211 kSDHC_AdmaErrorStateChangeAddress = 0x02U, /*!< Change address */
AnnaBridge 145:64910690c574 212 kSDHC_AdmaErrorStateTransferData = 0x03U, /*!< Transfer data */
AnnaBridge 145:64910690c574 213 } sdhc_adma_error_state_t;
AnnaBridge 145:64910690c574 214
AnnaBridge 145:64910690c574 215 /*! @brief Force event mask */
AnnaBridge 145:64910690c574 216 enum _sdhc_force_event
AnnaBridge 145:64910690c574 217 {
AnnaBridge 145:64910690c574 218 kSDHC_ForceEventAutoCommand12NotExecuted = SDHC_FEVT_AC12NE_MASK, /*!< Auto CMD12 not executed error */
AnnaBridge 145:64910690c574 219 kSDHC_ForceEventAutoCommand12Timeout = SDHC_FEVT_AC12TOE_MASK, /*!< Auto CMD12 timeout error */
AnnaBridge 145:64910690c574 220 kSDHC_ForceEventAutoCommand12CrcError = SDHC_FEVT_AC12CE_MASK, /*!< Auto CMD12 CRC error */
AnnaBridge 145:64910690c574 221 kSDHC_ForceEventEndBitError = SDHC_FEVT_AC12EBE_MASK, /*!< Auto CMD12 end bit error */
AnnaBridge 145:64910690c574 222 kSDHC_ForceEventAutoCommand12IndexError = SDHC_FEVT_AC12IE_MASK, /*!< Auto CMD12 index error */
AnnaBridge 145:64910690c574 223 kSDHC_ForceEventAutoCommand12NotIssued = SDHC_FEVT_CNIBAC12E_MASK, /*!< Auto CMD12 not issued error */
AnnaBridge 145:64910690c574 224 kSDHC_ForceEventCommandTimeout = SDHC_FEVT_CTOE_MASK, /*!< Command timeout error */
AnnaBridge 145:64910690c574 225 kSDHC_ForceEventCommandCrcError = SDHC_FEVT_CCE_MASK, /*!< Command CRC error */
AnnaBridge 145:64910690c574 226 kSDHC_ForceEventCommandEndBitError = SDHC_FEVT_CEBE_MASK, /*!< Command end bit error */
AnnaBridge 145:64910690c574 227 kSDHC_ForceEventCommandIndexError = SDHC_FEVT_CIE_MASK, /*!< Command index error */
AnnaBridge 145:64910690c574 228 kSDHC_ForceEventDataTimeout = SDHC_FEVT_DTOE_MASK, /*!< Data timeout error */
AnnaBridge 145:64910690c574 229 kSDHC_ForceEventDataCrcError = SDHC_FEVT_DCE_MASK, /*!< Data CRC error */
AnnaBridge 145:64910690c574 230 kSDHC_ForceEventDataEndBitError = SDHC_FEVT_DEBE_MASK, /*!< Data end bit error */
AnnaBridge 145:64910690c574 231 kSDHC_ForceEventAutoCommand12Error = SDHC_FEVT_AC12E_MASK, /*!< Auto CMD12 error */
AnnaBridge 145:64910690c574 232 kSDHC_ForceEventCardInt = SDHC_FEVT_CINT_MASK, /*!< Card interrupt */
AnnaBridge 145:64910690c574 233 kSDHC_ForceEventDmaError = SDHC_FEVT_DMAE_MASK, /*!< Dma error */
AnnaBridge 145:64910690c574 234
AnnaBridge 145:64910690c574 235 kSDHC_ForceEventsAll =
AnnaBridge 145:64910690c574 236 (kSDHC_ForceEventAutoCommand12NotExecuted | kSDHC_ForceEventAutoCommand12Timeout |
AnnaBridge 145:64910690c574 237 kSDHC_ForceEventAutoCommand12CrcError | kSDHC_ForceEventEndBitError | kSDHC_ForceEventAutoCommand12IndexError |
AnnaBridge 145:64910690c574 238 kSDHC_ForceEventAutoCommand12NotIssued | kSDHC_ForceEventCommandTimeout | kSDHC_ForceEventCommandCrcError |
AnnaBridge 145:64910690c574 239 kSDHC_ForceEventCommandEndBitError | kSDHC_ForceEventCommandIndexError | kSDHC_ForceEventDataTimeout |
AnnaBridge 145:64910690c574 240 kSDHC_ForceEventDataCrcError | kSDHC_ForceEventDataEndBitError | kSDHC_ForceEventAutoCommand12Error |
AnnaBridge 145:64910690c574 241 kSDHC_ForceEventCardInt | kSDHC_ForceEventDmaError), /*!< All force event flags mask */
AnnaBridge 145:64910690c574 242 };
AnnaBridge 145:64910690c574 243
AnnaBridge 145:64910690c574 244 /*! @brief Data transfer width */
AnnaBridge 145:64910690c574 245 typedef enum _sdhc_data_bus_width
AnnaBridge 145:64910690c574 246 {
AnnaBridge 145:64910690c574 247 kSDHC_DataBusWidth1Bit = 0U, /*!< 1-bit mode */
AnnaBridge 145:64910690c574 248 kSDHC_DataBusWidth4Bit = 1U, /*!< 4-bit mode */
AnnaBridge 145:64910690c574 249 kSDHC_DataBusWidth8Bit = 2U, /*!< 8-bit mode */
AnnaBridge 145:64910690c574 250 } sdhc_data_bus_width_t;
AnnaBridge 145:64910690c574 251
AnnaBridge 145:64910690c574 252 /*! @brief Endian mode */
AnnaBridge 145:64910690c574 253 typedef enum _sdhc_endian_mode
AnnaBridge 145:64910690c574 254 {
AnnaBridge 145:64910690c574 255 kSDHC_EndianModeBig = 0U, /*!< Big endian mode */
AnnaBridge 145:64910690c574 256 kSDHC_EndianModeHalfWordBig = 1U, /*!< Half word big endian mode */
AnnaBridge 145:64910690c574 257 kSDHC_EndianModeLittle = 2U, /*!< Little endian mode */
AnnaBridge 145:64910690c574 258 } sdhc_endian_mode_t;
AnnaBridge 145:64910690c574 259
AnnaBridge 145:64910690c574 260 /*! @brief DMA mode */
AnnaBridge 145:64910690c574 261 typedef enum _sdhc_dma_mode
AnnaBridge 145:64910690c574 262 {
AnnaBridge 145:64910690c574 263 kSDHC_DmaModeNo = 0U, /*!< No DMA */
AnnaBridge 145:64910690c574 264 kSDHC_DmaModeAdma1 = 1U, /*!< ADMA1 is selected */
AnnaBridge 145:64910690c574 265 kSDHC_DmaModeAdma2 = 2U, /*!< ADMA2 is selected */
AnnaBridge 145:64910690c574 266 } sdhc_dma_mode_t;
AnnaBridge 145:64910690c574 267
AnnaBridge 145:64910690c574 268 /*! @brief SDIO control flag mask */
AnnaBridge 145:64910690c574 269 enum _sdhc_sdio_control_flag
AnnaBridge 145:64910690c574 270 {
AnnaBridge 145:64910690c574 271 kSDHC_StopAtBlockGapFlag = 0x01, /*!< Stop at block gap */
AnnaBridge 145:64910690c574 272 kSDHC_ReadWaitControlFlag = 0x02, /*!< Read wait control */
AnnaBridge 145:64910690c574 273 kSDHC_InterruptAtBlockGapFlag = 0x04, /*!< Interrupt at block gap */
AnnaBridge 145:64910690c574 274 kSDHC_ExactBlockNumberReadFlag = 0x08, /*!< Exact block number read */
AnnaBridge 145:64910690c574 275 };
AnnaBridge 145:64910690c574 276
AnnaBridge 145:64910690c574 277 /*! @brief MMC card boot mode */
AnnaBridge 145:64910690c574 278 typedef enum _sdhc_boot_mode
AnnaBridge 145:64910690c574 279 {
AnnaBridge 145:64910690c574 280 kSDHC_BootModeNormal = 0U, /*!< Normal boot */
AnnaBridge 145:64910690c574 281 kSDHC_BootModeAlternative = 1U, /*!< Alternative boot */
AnnaBridge 145:64910690c574 282 } sdhc_boot_mode_t;
AnnaBridge 145:64910690c574 283
AnnaBridge 145:64910690c574 284 /*! @brief The command type */
AnnaBridge 145:64910690c574 285 typedef enum _sdhc_command_type
AnnaBridge 145:64910690c574 286 {
AnnaBridge 145:64910690c574 287 kSDHC_CommandTypeNormal = 0U, /*!< Normal command */
AnnaBridge 145:64910690c574 288 kSDHC_CommandTypeSuspend = 1U, /*!< Suspend command */
AnnaBridge 145:64910690c574 289 kSDHC_CommandTypeResume = 2U, /*!< Resume command */
AnnaBridge 145:64910690c574 290 kSDHC_CommandTypeAbort = 3U, /*!< Abort command */
AnnaBridge 145:64910690c574 291 } sdhc_command_type_t;
AnnaBridge 145:64910690c574 292
AnnaBridge 145:64910690c574 293 /*!
AnnaBridge 145:64910690c574 294 * @brief The command response type.
AnnaBridge 145:64910690c574 295 *
AnnaBridge 145:64910690c574 296 * Define the command response type from card to host controller.
AnnaBridge 145:64910690c574 297 */
AnnaBridge 145:64910690c574 298 typedef enum _sdhc_response_type
AnnaBridge 145:64910690c574 299 {
AnnaBridge 145:64910690c574 300 kSDHC_ResponseTypeNone = 0U, /*!< Response type: none */
AnnaBridge 145:64910690c574 301 kSDHC_ResponseTypeR1 = 1U, /*!< Response type: R1 */
AnnaBridge 145:64910690c574 302 kSDHC_ResponseTypeR1b = 2U, /*!< Response type: R1b */
AnnaBridge 145:64910690c574 303 kSDHC_ResponseTypeR2 = 3U, /*!< Response type: R2 */
AnnaBridge 145:64910690c574 304 kSDHC_ResponseTypeR3 = 4U, /*!< Response type: R3 */
AnnaBridge 145:64910690c574 305 kSDHC_ResponseTypeR4 = 5U, /*!< Response type: R4 */
AnnaBridge 145:64910690c574 306 kSDHC_ResponseTypeR5 = 6U, /*!< Response type: R5 */
AnnaBridge 145:64910690c574 307 kSDHC_ResponseTypeR5b = 7U, /*!< Response type: R5b */
AnnaBridge 145:64910690c574 308 kSDHC_ResponseTypeR6 = 8U, /*!< Response type: R6 */
AnnaBridge 145:64910690c574 309 kSDHC_ResponseTypeR7 = 9U, /*!< Response type: R7 */
AnnaBridge 145:64910690c574 310 } sdhc_response_type_t;
AnnaBridge 145:64910690c574 311
AnnaBridge 145:64910690c574 312 /*! @brief The alignment size for ADDRESS filed in ADMA1's descriptor */
AnnaBridge 145:64910690c574 313 #define SDHC_ADMA1_ADDRESS_ALIGN (4096U)
AnnaBridge 145:64910690c574 314 /*! @brief The alignment size for LENGTH field in ADMA1's descriptor */
AnnaBridge 145:64910690c574 315 #define SDHC_ADMA1_LENGTH_ALIGN (4096U)
AnnaBridge 145:64910690c574 316 /*! @brief The alignment size for ADDRESS field in ADMA2's descriptor */
AnnaBridge 145:64910690c574 317 #define SDHC_ADMA2_ADDRESS_ALIGN (4U)
AnnaBridge 145:64910690c574 318 /*! @brief The alignment size for LENGTH filed in ADMA2's descriptor */
AnnaBridge 145:64910690c574 319 #define SDHC_ADMA2_LENGTH_ALIGN (4U)
AnnaBridge 145:64910690c574 320
AnnaBridge 145:64910690c574 321 /* ADMA1 descriptor table
AnnaBridge 145:64910690c574 322 * |------------------------|---------|--------------------------|
AnnaBridge 145:64910690c574 323 * | Address/page field |Reserved | Attribute |
AnnaBridge 145:64910690c574 324 * |------------------------|---------|--------------------------|
AnnaBridge 145:64910690c574 325 * |31 12|11 6|05 |04 |03|02 |01 |00 |
AnnaBridge 145:64910690c574 326 * |------------------------|---------|----|----|--|---|---|-----|
AnnaBridge 145:64910690c574 327 * | address or data length | 000000 |Act2|Act1| 0|Int|End|Valid|
AnnaBridge 145:64910690c574 328 * |------------------------|---------|----|----|--|---|---|-----|
AnnaBridge 145:64910690c574 329 *
AnnaBridge 145:64910690c574 330 *
AnnaBridge 145:64910690c574 331 * |------|------|-----------------|-------|-------------|
AnnaBridge 145:64910690c574 332 * | Act2 | Act1 | Comment | 31-28 | 27 - 12 |
AnnaBridge 145:64910690c574 333 * |------|------|-----------------|---------------------|
AnnaBridge 145:64910690c574 334 * | 0 | 0 | No op | Don't care |
AnnaBridge 145:64910690c574 335 * |------|------|-----------------|-------|-------------|
AnnaBridge 145:64910690c574 336 * | 0 | 1 | Set data length | 0000 | Data Length |
AnnaBridge 145:64910690c574 337 * |------|------|-----------------|-------|-------------|
AnnaBridge 145:64910690c574 338 * | 1 | 0 | Transfer data | Data address |
AnnaBridge 145:64910690c574 339 * |------|------|-----------------|---------------------|
AnnaBridge 145:64910690c574 340 * | 1 | 1 | Link descriptor | Descriptor address |
AnnaBridge 145:64910690c574 341 * |------|------|-----------------|---------------------|
AnnaBridge 145:64910690c574 342 */
AnnaBridge 145:64910690c574 343 /*! @brief The bit shift for ADDRESS filed in ADMA1's descriptor */
AnnaBridge 145:64910690c574 344 #define SDHC_ADMA1_DESCRIPTOR_ADDRESS_SHIFT (12U)
AnnaBridge 145:64910690c574 345 /*! @brief The bit mask for ADDRESS field in ADMA1's descriptor */
AnnaBridge 145:64910690c574 346 #define SDHC_ADMA1_DESCRIPTOR_ADDRESS_MASK (0xFFFFFU)
AnnaBridge 145:64910690c574 347 /*! @brief The bit shift for LENGTH filed in ADMA1's descriptor */
AnnaBridge 145:64910690c574 348 #define SDHC_ADMA1_DESCRIPTOR_LENGTH_SHIFT (12U)
AnnaBridge 145:64910690c574 349 /*! @brief The mask for LENGTH field in ADMA1's descriptor */
AnnaBridge 145:64910690c574 350 #define SDHC_ADMA1_DESCRIPTOR_LENGTH_MASK (0xFFFFU)
AnnaBridge 145:64910690c574 351 /*! @brief The maximum value of LENGTH filed in ADMA1's descriptor */
AnnaBridge 145:64910690c574 352 #define SDHC_ADMA1_DESCRIPTOR_MAX_LENGTH_PER_ENTRY (SDHC_ADMA1_DESCRIPTOR_LENGTH_MASK + 1U)
AnnaBridge 145:64910690c574 353
AnnaBridge 145:64910690c574 354 /*! @brief The mask for the control/status field in ADMA1 descriptor */
AnnaBridge 145:64910690c574 355 enum _sdhc_adma1_descriptor_flag
AnnaBridge 145:64910690c574 356 {
AnnaBridge 145:64910690c574 357 kSDHC_Adma1DescriptorValidFlag = (1U << 0U), /*!< Valid flag */
AnnaBridge 145:64910690c574 358 kSDHC_Adma1DescriptorEndFlag = (1U << 1U), /*!< End flag */
AnnaBridge 145:64910690c574 359 kSDHC_Adma1DescriptorInterrupFlag = (1U << 2U), /*!< Interrupt flag */
AnnaBridge 145:64910690c574 360 kSDHC_Adma1DescriptorActivity1Flag = (1U << 4U), /*!< Activity 1 flag */
AnnaBridge 145:64910690c574 361 kSDHC_Adma1DescriptorActivity2Flag = (1U << 5U), /*!< Activity 2 flag */
AnnaBridge 145:64910690c574 362 kSDHC_Adma1DescriptorTypeNop = (kSDHC_Adma1DescriptorValidFlag), /*!< No operation */
AnnaBridge 145:64910690c574 363 kSDHC_Adma1DescriptorTypeTransfer =
AnnaBridge 145:64910690c574 364 (kSDHC_Adma1DescriptorActivity2Flag | kSDHC_Adma1DescriptorValidFlag), /*!< Transfer data */
AnnaBridge 145:64910690c574 365 kSDHC_Adma1DescriptorTypeLink = (kSDHC_Adma1DescriptorActivity1Flag | kSDHC_Adma1DescriptorActivity2Flag |
AnnaBridge 145:64910690c574 366 kSDHC_Adma1DescriptorValidFlag), /*!< Link descriptor */
AnnaBridge 145:64910690c574 367 kSDHC_Adma1DescriptorTypeSetLength =
AnnaBridge 145:64910690c574 368 (kSDHC_Adma1DescriptorActivity1Flag | kSDHC_Adma1DescriptorValidFlag), /*!< Set data length */
AnnaBridge 145:64910690c574 369 };
AnnaBridge 145:64910690c574 370
AnnaBridge 145:64910690c574 371 /* ADMA2 descriptor table
AnnaBridge 145:64910690c574 372 * |----------------|---------------|-------------|--------------------------|
AnnaBridge 145:64910690c574 373 * | Address field | Length | Reserved | Attribute |
AnnaBridge 145:64910690c574 374 * |----------------|---------------|-------------|--------------------------|
AnnaBridge 145:64910690c574 375 * |63 32|31 16|15 06|05 |04 |03|02 |01 |00 |
AnnaBridge 145:64910690c574 376 * |----------------|---------------|-------------|----|----|--|---|---|-----|
AnnaBridge 145:64910690c574 377 * | 32-bit address | 16-bit length | 0000000000 |Act2|Act1| 0|Int|End|Valid|
AnnaBridge 145:64910690c574 378 * |----------------|---------------|-------------|----|----|--|---|---|-----|
AnnaBridge 145:64910690c574 379 *
AnnaBridge 145:64910690c574 380 *
AnnaBridge 145:64910690c574 381 * | Act2 | Act1 | Comment | Operation |
AnnaBridge 145:64910690c574 382 * |------|------|-----------------|-------------------------------------------------------------------|
AnnaBridge 145:64910690c574 383 * | 0 | 0 | No op | Don't care |
AnnaBridge 145:64910690c574 384 * |------|------|-----------------|-------------------------------------------------------------------|
AnnaBridge 145:64910690c574 385 * | 0 | 1 | Reserved | Read this line and go to next one |
AnnaBridge 145:64910690c574 386 * |------|------|-----------------|-------------------------------------------------------------------|
AnnaBridge 145:64910690c574 387 * | 1 | 0 | Transfer data | Transfer data with address and length set in this descriptor line |
AnnaBridge 145:64910690c574 388 * |------|------|-----------------|-------------------------------------------------------------------|
AnnaBridge 145:64910690c574 389 * | 1 | 1 | Link descriptor | Link to another descriptor |
AnnaBridge 145:64910690c574 390 * |------|------|-----------------|-------------------------------------------------------------------|
AnnaBridge 145:64910690c574 391 */
AnnaBridge 145:64910690c574 392 /*! @brief The bit shift for LENGTH field in ADMA2's descriptor */
AnnaBridge 145:64910690c574 393 #define SDHC_ADMA2_DESCRIPTOR_LENGTH_SHIFT (16U)
AnnaBridge 145:64910690c574 394 /*! @brief The bit mask for LENGTH field in ADMA2's descriptor */
AnnaBridge 145:64910690c574 395 #define SDHC_ADMA2_DESCRIPTOR_LENGTH_MASK (0xFFFFU)
AnnaBridge 145:64910690c574 396 /*! @brief The maximum value of LENGTH field in ADMA2's descriptor */
AnnaBridge 145:64910690c574 397 #define SDHC_ADMA2_DESCRIPTOR_MAX_LENGTH_PER_ENTRY (SDHC_ADMA2_DESCRIPTOR_LENGTH_MASK)
AnnaBridge 145:64910690c574 398
AnnaBridge 145:64910690c574 399 /*! @brief ADMA1 descriptor control and status mask */
AnnaBridge 145:64910690c574 400 enum _sdhc_adma2_descriptor_flag
AnnaBridge 145:64910690c574 401 {
AnnaBridge 145:64910690c574 402 kSDHC_Adma2DescriptorValidFlag = (1U << 0U), /*!< Valid flag */
AnnaBridge 145:64910690c574 403 kSDHC_Adma2DescriptorEndFlag = (1U << 1U), /*!< End flag */
AnnaBridge 145:64910690c574 404 kSDHC_Adma2DescriptorInterruptFlag = (1U << 2U), /*!< Interrupt flag */
AnnaBridge 145:64910690c574 405 kSDHC_Adma2DescriptorActivity1Flag = (1U << 4U), /*!< Activity 1 mask */
AnnaBridge 145:64910690c574 406 kSDHC_Adma2DescriptorActivity2Flag = (1U << 5U), /*!< Activity 2 mask */
AnnaBridge 145:64910690c574 407
AnnaBridge 145:64910690c574 408 kSDHC_Adma2DescriptorTypeNop = (kSDHC_Adma2DescriptorValidFlag), /*!< No operation */
AnnaBridge 145:64910690c574 409 kSDHC_Adma2DescriptorTypeReserved =
AnnaBridge 145:64910690c574 410 (kSDHC_Adma2DescriptorActivity1Flag | kSDHC_Adma2DescriptorValidFlag), /*!< Reserved */
AnnaBridge 145:64910690c574 411 kSDHC_Adma2DescriptorTypeTransfer =
AnnaBridge 145:64910690c574 412 (kSDHC_Adma2DescriptorActivity2Flag | kSDHC_Adma2DescriptorValidFlag), /*!< Transfer type */
AnnaBridge 145:64910690c574 413 kSDHC_Adma2DescriptorTypeLink = (kSDHC_Adma2DescriptorActivity1Flag | kSDHC_Adma2DescriptorActivity2Flag |
AnnaBridge 145:64910690c574 414 kSDHC_Adma2DescriptorValidFlag), /*!< Link type */
AnnaBridge 145:64910690c574 415 };
AnnaBridge 145:64910690c574 416
AnnaBridge 145:64910690c574 417 /*! @brief Defines the adma1 descriptor structure. */
AnnaBridge 145:64910690c574 418 typedef uint32_t sdhc_adma1_descriptor_t;
AnnaBridge 145:64910690c574 419
AnnaBridge 145:64910690c574 420 /*! @brief Defines the ADMA2 descriptor structure. */
AnnaBridge 145:64910690c574 421 typedef struct _sdhc_adma2_descriptor
AnnaBridge 145:64910690c574 422 {
AnnaBridge 145:64910690c574 423 uint32_t attribute; /*!< The control and status field */
AnnaBridge 145:64910690c574 424 const uint32_t *address; /*!< The address field */
AnnaBridge 145:64910690c574 425 } sdhc_adma2_descriptor_t;
AnnaBridge 145:64910690c574 426
AnnaBridge 145:64910690c574 427 /*!
AnnaBridge 145:64910690c574 428 * @brief SDHC capability information.
AnnaBridge 145:64910690c574 429 *
AnnaBridge 145:64910690c574 430 * Defines a structure to save the capability information of SDHC.
AnnaBridge 145:64910690c574 431 */
AnnaBridge 145:64910690c574 432 typedef struct _sdhc_capability
AnnaBridge 145:64910690c574 433 {
AnnaBridge 145:64910690c574 434 uint32_t specVersion; /*!< Specification version */
AnnaBridge 145:64910690c574 435 uint32_t vendorVersion; /*!< Vendor version */
AnnaBridge 145:64910690c574 436 uint32_t maxBlockLength; /*!< Maximum block length united as byte */
AnnaBridge 145:64910690c574 437 uint32_t maxBlockCount; /*!< Maximum block count can be set one time */
AnnaBridge 145:64910690c574 438 uint32_t flags; /*!< Capability flags to indicate the support information(_sdhc_capability_flag) */
AnnaBridge 145:64910690c574 439 } sdhc_capability_t;
AnnaBridge 145:64910690c574 440
AnnaBridge 145:64910690c574 441 /*! @brief Card transfer configuration.
AnnaBridge 145:64910690c574 442 *
AnnaBridge 145:64910690c574 443 * Define structure to configure the transfer-related command index/argument/flags and data block
AnnaBridge 145:64910690c574 444 * size/data block numbers. This structure needs to be filled each time a command is sent to the card.
AnnaBridge 145:64910690c574 445 */
AnnaBridge 145:64910690c574 446 typedef struct _sdhc_transfer_config
AnnaBridge 145:64910690c574 447 {
AnnaBridge 145:64910690c574 448 size_t dataBlockSize; /*!< Data block size */
AnnaBridge 145:64910690c574 449 uint32_t dataBlockCount; /*!< Data block count */
AnnaBridge 145:64910690c574 450 uint32_t commandArgument; /*!< Command argument */
AnnaBridge 145:64910690c574 451 uint32_t commandIndex; /*!< Command index */
AnnaBridge 145:64910690c574 452 uint32_t flags; /*!< Transfer flags(_sdhc_transfer_flag) */
AnnaBridge 145:64910690c574 453 } sdhc_transfer_config_t;
AnnaBridge 145:64910690c574 454
AnnaBridge 145:64910690c574 455 /*! @brief Data structure to configure the MMC boot feature */
AnnaBridge 145:64910690c574 456 typedef struct _sdhc_boot_config
AnnaBridge 145:64910690c574 457 {
AnnaBridge 145:64910690c574 458 uint32_t ackTimeoutCount; /*!< Timeout value for the boot ACK. The available range is 0 ~ 15. */
AnnaBridge 145:64910690c574 459 sdhc_boot_mode_t bootMode; /*!< Boot mode selection. */
AnnaBridge 145:64910690c574 460 uint32_t blockCount; /*!< Stop at block gap value of automatic mode. Available range is 0 ~ 65535. */
AnnaBridge 145:64910690c574 461 bool enableBootAck; /*!< Enable or disable boot ACK */
AnnaBridge 145:64910690c574 462 bool enableBoot; /*!< Enable or disable fast boot */
AnnaBridge 145:64910690c574 463 bool enableAutoStopAtBlockGap; /*!< Enable or disable auto stop at block gap function in boot period */
AnnaBridge 145:64910690c574 464 } sdhc_boot_config_t;
AnnaBridge 145:64910690c574 465
AnnaBridge 145:64910690c574 466 /*! @brief Data structure to initialize the SDHC */
AnnaBridge 145:64910690c574 467 typedef struct _sdhc_config
AnnaBridge 145:64910690c574 468 {
AnnaBridge 145:64910690c574 469 bool cardDetectDat3; /*!< Enable DAT3 as card detection pin */
AnnaBridge 145:64910690c574 470 sdhc_endian_mode_t endianMode; /*!< Endian mode */
AnnaBridge 145:64910690c574 471 sdhc_dma_mode_t dmaMode; /*!< DMA mode */
AnnaBridge 145:64910690c574 472 uint32_t readWatermarkLevel; /*!< Watermark level for DMA read operation. Available range is 1 ~ 128. */
AnnaBridge 145:64910690c574 473 uint32_t writeWatermarkLevel; /*!< Watermark level for DMA write operation. Available range is 1 ~ 128. */
AnnaBridge 145:64910690c574 474 } sdhc_config_t;
AnnaBridge 145:64910690c574 475
AnnaBridge 145:64910690c574 476 /*!
AnnaBridge 145:64910690c574 477 * @brief Card data descriptor
AnnaBridge 145:64910690c574 478 *
AnnaBridge 145:64910690c574 479 * Defines a structure to contain data-related attribute. 'enableIgnoreError' is used for the case that upper card
AnnaBridge 145:64910690c574 480 * driver
AnnaBridge 145:64910690c574 481 * want to ignore the error event to read/write all the data not to stop read/write immediately when error event
AnnaBridge 145:64910690c574 482 * happen for example bus testing procedure for MMC card.
AnnaBridge 145:64910690c574 483 */
AnnaBridge 145:64910690c574 484 typedef struct _sdhc_data
AnnaBridge 145:64910690c574 485 {
AnnaBridge 145:64910690c574 486 bool enableAutoCommand12; /*!< Enable auto CMD12 */
AnnaBridge 145:64910690c574 487 bool enableIgnoreError; /*!< Enable to ignore error event to read/write all the data */
AnnaBridge 145:64910690c574 488 size_t blockSize; /*!< Block size */
AnnaBridge 145:64910690c574 489 uint32_t blockCount; /*!< Block count */
AnnaBridge 145:64910690c574 490 uint32_t *rxData; /*!< Buffer to save data read */
AnnaBridge 145:64910690c574 491 const uint32_t *txData; /*!< Data buffer to write */
AnnaBridge 145:64910690c574 492 } sdhc_data_t;
AnnaBridge 145:64910690c574 493
AnnaBridge 145:64910690c574 494 /*!
AnnaBridge 145:64910690c574 495 * @brief Card command descriptor
AnnaBridge 145:64910690c574 496 *
AnnaBridge 145:64910690c574 497 * Define card command-related attribute.
AnnaBridge 145:64910690c574 498 */
AnnaBridge 145:64910690c574 499 typedef struct _sdhc_command
AnnaBridge 145:64910690c574 500 {
AnnaBridge 145:64910690c574 501 uint32_t index; /*!< Command index */
AnnaBridge 145:64910690c574 502 uint32_t argument; /*!< Command argument */
AnnaBridge 145:64910690c574 503 sdhc_command_type_t type; /*!< Command type */
AnnaBridge 145:64910690c574 504 sdhc_response_type_t responseType; /*!< Command response type */
AnnaBridge 145:64910690c574 505 uint32_t response[4U]; /*!< Response for this command */
AnnaBridge 145:64910690c574 506 } sdhc_command_t;
AnnaBridge 145:64910690c574 507
AnnaBridge 145:64910690c574 508 /*! @brief Transfer state */
AnnaBridge 145:64910690c574 509 typedef struct _sdhc_transfer
AnnaBridge 145:64910690c574 510 {
AnnaBridge 145:64910690c574 511 sdhc_data_t *data; /*!< Data to transfer */
AnnaBridge 145:64910690c574 512 sdhc_command_t *command; /*!< Command to send */
AnnaBridge 145:64910690c574 513 } sdhc_transfer_t;
AnnaBridge 145:64910690c574 514
AnnaBridge 145:64910690c574 515 /*! @brief SDHC handle typedef */
AnnaBridge 145:64910690c574 516 typedef struct _sdhc_handle sdhc_handle_t;
AnnaBridge 145:64910690c574 517
AnnaBridge 145:64910690c574 518 /*! @brief SDHC callback functions. */
AnnaBridge 145:64910690c574 519 typedef struct _sdhc_transfer_callback
AnnaBridge 145:64910690c574 520 {
AnnaBridge 145:64910690c574 521 void (*CardInserted)(void); /*!< Card inserted occurs when DAT3/CD pin is for card detect */
AnnaBridge 145:64910690c574 522 void (*CardRemoved)(void); /*!< Card removed occurs */
AnnaBridge 145:64910690c574 523 void (*SdioInterrupt)(void); /*!< SDIO card interrupt occurs */
AnnaBridge 145:64910690c574 524 void (*SdioBlockGap)(void); /*!< SDIO card stopped at block gap occurs */
AnnaBridge 145:64910690c574 525 void (*TransferComplete)(SDHC_Type *base,
AnnaBridge 145:64910690c574 526 sdhc_handle_t *handle,
AnnaBridge 145:64910690c574 527 status_t status,
AnnaBridge 145:64910690c574 528 void *userData); /*!< Transfer complete callback */
AnnaBridge 145:64910690c574 529 } sdhc_transfer_callback_t;
AnnaBridge 145:64910690c574 530
AnnaBridge 145:64910690c574 531 /*!
AnnaBridge 145:64910690c574 532 * @brief SDHC handle
AnnaBridge 145:64910690c574 533 *
AnnaBridge 145:64910690c574 534 * Defines the structure to save the SDHC state information and callback function. The detailed interrupt status when
AnnaBridge 145:64910690c574 535 * sending a command or transfering data can be obtained from the interruptFlags field by using the mask defined in
AnnaBridge 145:64910690c574 536 * sdhc_interrupt_flag_t.
AnnaBridge 145:64910690c574 537 *
AnnaBridge 145:64910690c574 538 * @note All the fields except interruptFlags and transferredWords must be allocated by the user.
AnnaBridge 145:64910690c574 539 */
AnnaBridge 145:64910690c574 540 struct _sdhc_handle
AnnaBridge 145:64910690c574 541 {
AnnaBridge 145:64910690c574 542 /* Transfer parameter */
AnnaBridge 145:64910690c574 543 sdhc_data_t *volatile data; /*!< Data to transfer */
AnnaBridge 145:64910690c574 544 sdhc_command_t *volatile command; /*!< Command to send */
AnnaBridge 145:64910690c574 545
AnnaBridge 145:64910690c574 546 /* Transfer status */
AnnaBridge 145:64910690c574 547 volatile uint32_t interruptFlags; /*!< Interrupt flags of last transaction */
AnnaBridge 145:64910690c574 548 volatile uint32_t transferredWords; /*!< Words transferred by DATAPORT way */
AnnaBridge 145:64910690c574 549
AnnaBridge 145:64910690c574 550 /* Callback functions */
AnnaBridge 145:64910690c574 551 sdhc_transfer_callback_t callback; /*!< Callback function */
AnnaBridge 145:64910690c574 552 void *userData; /*!< Parameter for transfer complete callback */
AnnaBridge 145:64910690c574 553 };
AnnaBridge 145:64910690c574 554
AnnaBridge 145:64910690c574 555 /*! @brief SDHC transfer function. */
AnnaBridge 145:64910690c574 556 typedef status_t (*sdhc_transfer_function_t)(SDHC_Type *base, sdhc_transfer_t *content);
AnnaBridge 145:64910690c574 557
AnnaBridge 145:64910690c574 558 /*! @brief SDHC host descriptor */
AnnaBridge 145:64910690c574 559 typedef struct _sdhc_host
AnnaBridge 145:64910690c574 560 {
AnnaBridge 145:64910690c574 561 SDHC_Type *base; /*!< SDHC peripheral base address */
AnnaBridge 145:64910690c574 562 uint32_t sourceClock_Hz; /*!< SDHC source clock frequency united in Hz */
AnnaBridge 145:64910690c574 563 sdhc_config_t config; /*!< SDHC configuration */
AnnaBridge 145:64910690c574 564 sdhc_capability_t capability; /*!< SDHC capability information */
AnnaBridge 145:64910690c574 565 sdhc_transfer_function_t transfer; /*!< SDHC transfer function */
AnnaBridge 145:64910690c574 566 } sdhc_host_t;
AnnaBridge 145:64910690c574 567
AnnaBridge 145:64910690c574 568 /*************************************************************************************************
AnnaBridge 145:64910690c574 569 * API
AnnaBridge 145:64910690c574 570 ************************************************************************************************/
AnnaBridge 145:64910690c574 571 #if defined(__cplusplus)
AnnaBridge 145:64910690c574 572 extern "C" {
AnnaBridge 145:64910690c574 573 #endif
AnnaBridge 145:64910690c574 574
AnnaBridge 145:64910690c574 575 /*!
AnnaBridge 145:64910690c574 576 * @name Initialization and deinitialization
AnnaBridge 145:64910690c574 577 * @{
AnnaBridge 145:64910690c574 578 */
AnnaBridge 145:64910690c574 579
AnnaBridge 145:64910690c574 580 /*!
AnnaBridge 145:64910690c574 581 * @brief SDHC module initialization function.
AnnaBridge 145:64910690c574 582 *
AnnaBridge 145:64910690c574 583 * Configures the SDHC according to the user configuration.
AnnaBridge 145:64910690c574 584 *
AnnaBridge 145:64910690c574 585 * Example:
AnnaBridge 145:64910690c574 586 @code
AnnaBridge 145:64910690c574 587 sdhc_config_t config;
AnnaBridge 145:64910690c574 588 config.cardDetectDat3 = false;
AnnaBridge 145:64910690c574 589 config.endianMode = kSDHC_EndianModeLittle;
AnnaBridge 145:64910690c574 590 config.dmaMode = kSDHC_DmaModeAdma2;
AnnaBridge 145:64910690c574 591 config.readWatermarkLevel = 128U;
AnnaBridge 145:64910690c574 592 config.writeWatermarkLevel = 128U;
AnnaBridge 145:64910690c574 593 SDHC_Init(SDHC, &config);
AnnaBridge 145:64910690c574 594 @endcode
AnnaBridge 145:64910690c574 595 *
AnnaBridge 145:64910690c574 596 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 597 * @param config SDHC configuration information.
AnnaBridge 145:64910690c574 598 * @retval kStatus_Success Operate successfully.
AnnaBridge 145:64910690c574 599 */
AnnaBridge 145:64910690c574 600 void SDHC_Init(SDHC_Type *base, const sdhc_config_t *config);
AnnaBridge 145:64910690c574 601
AnnaBridge 145:64910690c574 602 /*!
AnnaBridge 145:64910690c574 603 * @brief Deinitializes the SDHC.
AnnaBridge 145:64910690c574 604 *
AnnaBridge 145:64910690c574 605 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 606 */
AnnaBridge 145:64910690c574 607 void SDHC_Deinit(SDHC_Type *base);
AnnaBridge 145:64910690c574 608
AnnaBridge 145:64910690c574 609 /*!
AnnaBridge 145:64910690c574 610 * @brief Resets the SDHC.
AnnaBridge 145:64910690c574 611 *
AnnaBridge 145:64910690c574 612 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 613 * @param mask The reset type mask(_sdhc_reset).
AnnaBridge 145:64910690c574 614 * @param timeout Timeout for reset.
AnnaBridge 145:64910690c574 615 * @retval true Reset successfully.
AnnaBridge 145:64910690c574 616 * @retval false Reset failed.
AnnaBridge 145:64910690c574 617 */
AnnaBridge 145:64910690c574 618 bool SDHC_Reset(SDHC_Type *base, uint32_t mask, uint32_t timeout);
AnnaBridge 145:64910690c574 619
AnnaBridge 145:64910690c574 620 /* @} */
AnnaBridge 145:64910690c574 621
AnnaBridge 145:64910690c574 622 /*!
AnnaBridge 145:64910690c574 623 * @name DMA Control
AnnaBridge 145:64910690c574 624 * @{
AnnaBridge 145:64910690c574 625 */
AnnaBridge 145:64910690c574 626
AnnaBridge 145:64910690c574 627 /*!
AnnaBridge 145:64910690c574 628 * @brief Sets the ADMA descriptor table configuration.
AnnaBridge 145:64910690c574 629 *
AnnaBridge 145:64910690c574 630 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 631 * @param dmaMode DMA mode.
AnnaBridge 145:64910690c574 632 * @param table ADMA table address.
AnnaBridge 145:64910690c574 633 * @param tableWords ADMA table buffer length united as Words.
AnnaBridge 145:64910690c574 634 * @param data Data buffer address.
AnnaBridge 145:64910690c574 635 * @param dataBytes Data length united as bytes.
AnnaBridge 145:64910690c574 636 * @retval kStatus_OutOfRange ADMA descriptor table length isn't enough to describe data.
AnnaBridge 145:64910690c574 637 * @retval kStatus_Success Operate successfully.
AnnaBridge 145:64910690c574 638 */
AnnaBridge 145:64910690c574 639 status_t SDHC_SetAdmaTableConfig(SDHC_Type *base,
AnnaBridge 145:64910690c574 640 sdhc_dma_mode_t dmaMode,
AnnaBridge 145:64910690c574 641 uint32_t *table,
AnnaBridge 145:64910690c574 642 uint32_t tableWords,
AnnaBridge 145:64910690c574 643 const uint32_t *data,
AnnaBridge 145:64910690c574 644 uint32_t dataBytes);
AnnaBridge 145:64910690c574 645
AnnaBridge 145:64910690c574 646 /* @} */
AnnaBridge 145:64910690c574 647
AnnaBridge 145:64910690c574 648 /*!
AnnaBridge 145:64910690c574 649 * @name Interrupts
AnnaBridge 145:64910690c574 650 * @{
AnnaBridge 145:64910690c574 651 */
AnnaBridge 145:64910690c574 652
AnnaBridge 145:64910690c574 653 /*!
AnnaBridge 145:64910690c574 654 * @brief Enables the interrupt status.
AnnaBridge 145:64910690c574 655 *
AnnaBridge 145:64910690c574 656 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 657 * @param mask Interrupt status flags mask(_sdhc_interrupt_status_flag).
AnnaBridge 145:64910690c574 658 */
AnnaBridge 145:64910690c574 659 static inline void SDHC_EnableInterruptStatus(SDHC_Type *base, uint32_t mask)
AnnaBridge 145:64910690c574 660 {
AnnaBridge 145:64910690c574 661 base->IRQSTATEN |= mask;
AnnaBridge 145:64910690c574 662 }
AnnaBridge 145:64910690c574 663
AnnaBridge 145:64910690c574 664 /*!
AnnaBridge 145:64910690c574 665 * @brief Disables the interrupt status.
AnnaBridge 145:64910690c574 666 *
AnnaBridge 145:64910690c574 667 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 668 * @param mask The interrupt status flags mask(_sdhc_interrupt_status_flag).
AnnaBridge 145:64910690c574 669 */
AnnaBridge 145:64910690c574 670 static inline void SDHC_DisableInterruptStatus(SDHC_Type *base, uint32_t mask)
AnnaBridge 145:64910690c574 671 {
AnnaBridge 145:64910690c574 672 base->IRQSTATEN &= ~mask;
AnnaBridge 145:64910690c574 673 }
AnnaBridge 145:64910690c574 674
AnnaBridge 145:64910690c574 675 /*!
AnnaBridge 145:64910690c574 676 * @brief Enables the interrupt signal corresponding to the interrupt status flag.
AnnaBridge 145:64910690c574 677 *
AnnaBridge 145:64910690c574 678 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 679 * @param mask The interrupt status flags mask(_sdhc_interrupt_status_flag).
AnnaBridge 145:64910690c574 680 */
AnnaBridge 145:64910690c574 681 static inline void SDHC_EnableInterruptSignal(SDHC_Type *base, uint32_t mask)
AnnaBridge 145:64910690c574 682 {
AnnaBridge 145:64910690c574 683 base->IRQSIGEN |= mask;
AnnaBridge 145:64910690c574 684 }
AnnaBridge 145:64910690c574 685
AnnaBridge 145:64910690c574 686 /*!
AnnaBridge 145:64910690c574 687 * @brief Disables the interrupt signal corresponding to the interrupt status flag.
AnnaBridge 145:64910690c574 688 *
AnnaBridge 145:64910690c574 689 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 690 * @param mask The interrupt status flags mask(_sdhc_interrupt_status_flag).
AnnaBridge 145:64910690c574 691 */
AnnaBridge 145:64910690c574 692 static inline void SDHC_DisableInterruptSignal(SDHC_Type *base, uint32_t mask)
AnnaBridge 145:64910690c574 693 {
AnnaBridge 145:64910690c574 694 base->IRQSIGEN &= ~mask;
AnnaBridge 145:64910690c574 695 }
AnnaBridge 145:64910690c574 696
AnnaBridge 145:64910690c574 697 /* @} */
AnnaBridge 145:64910690c574 698
AnnaBridge 145:64910690c574 699 /*!
AnnaBridge 145:64910690c574 700 * @name Status
AnnaBridge 145:64910690c574 701 * @{
AnnaBridge 145:64910690c574 702 */
AnnaBridge 145:64910690c574 703
AnnaBridge 145:64910690c574 704 /*!
AnnaBridge 145:64910690c574 705 * @brief Gets the current interrupt status.
AnnaBridge 145:64910690c574 706 *
AnnaBridge 145:64910690c574 707 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 708 * @return Current interrupt status flags mask(_sdhc_interrupt_status_flag).
AnnaBridge 145:64910690c574 709 */
AnnaBridge 145:64910690c574 710 static inline uint32_t SDHC_GetInterruptStatusFlags(SDHC_Type *base)
AnnaBridge 145:64910690c574 711 {
AnnaBridge 145:64910690c574 712 return base->IRQSTAT;
AnnaBridge 145:64910690c574 713 }
AnnaBridge 145:64910690c574 714
AnnaBridge 145:64910690c574 715 /*!
AnnaBridge 145:64910690c574 716 * @brief Clears a specified interrupt status.
AnnaBridge 145:64910690c574 717 *
AnnaBridge 145:64910690c574 718 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 719 * @param mask The interrupt status flags mask(_sdhc_interrupt_status_flag).
AnnaBridge 145:64910690c574 720 */
AnnaBridge 145:64910690c574 721 static inline void SDHC_ClearInterruptStatusFlags(SDHC_Type *base, uint32_t mask)
AnnaBridge 145:64910690c574 722 {
AnnaBridge 145:64910690c574 723 base->IRQSTAT = mask;
AnnaBridge 145:64910690c574 724 }
AnnaBridge 145:64910690c574 725
AnnaBridge 145:64910690c574 726 /*!
AnnaBridge 145:64910690c574 727 * @brief Gets the status of auto command 12 error.
AnnaBridge 145:64910690c574 728 *
AnnaBridge 145:64910690c574 729 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 730 * @return Auto command 12 error status flags mask(_sdhc_auto_command12_error_status_flag).
AnnaBridge 145:64910690c574 731 */
AnnaBridge 145:64910690c574 732 static inline uint32_t SDHC_GetAutoCommand12ErrorStatusFlags(SDHC_Type *base)
AnnaBridge 145:64910690c574 733 {
AnnaBridge 145:64910690c574 734 return base->AC12ERR;
AnnaBridge 145:64910690c574 735 }
AnnaBridge 145:64910690c574 736
AnnaBridge 145:64910690c574 737 /*!
AnnaBridge 145:64910690c574 738 * @brief Gets the status of the ADMA error.
AnnaBridge 145:64910690c574 739 *
AnnaBridge 145:64910690c574 740 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 741 * @return ADMA error status flags mask(_sdhc_adma_error_status_flag).
AnnaBridge 145:64910690c574 742 */
AnnaBridge 145:64910690c574 743 static inline uint32_t SDHC_GetAdmaErrorStatusFlags(SDHC_Type *base)
AnnaBridge 145:64910690c574 744 {
AnnaBridge 145:64910690c574 745 return base->ADMAES;
AnnaBridge 145:64910690c574 746 }
AnnaBridge 145:64910690c574 747
AnnaBridge 145:64910690c574 748 /*!
AnnaBridge 145:64910690c574 749 * @brief Gets a present status.
AnnaBridge 145:64910690c574 750 *
AnnaBridge 145:64910690c574 751 * This function gets the present SDHC's status except for an interrupt status and an error status.
AnnaBridge 145:64910690c574 752 *
AnnaBridge 145:64910690c574 753 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 754 * @return Present SDHC's status flags mask(_sdhc_present_status_flag).
AnnaBridge 145:64910690c574 755 */
AnnaBridge 145:64910690c574 756 static inline uint32_t SDHC_GetPresentStatusFlags(SDHC_Type *base)
AnnaBridge 145:64910690c574 757 {
AnnaBridge 145:64910690c574 758 return base->PRSSTAT;
AnnaBridge 145:64910690c574 759 }
AnnaBridge 145:64910690c574 760
AnnaBridge 145:64910690c574 761 /* @} */
AnnaBridge 145:64910690c574 762
AnnaBridge 145:64910690c574 763 /*!
AnnaBridge 145:64910690c574 764 * @name Bus Operations
AnnaBridge 145:64910690c574 765 * @{
AnnaBridge 145:64910690c574 766 */
AnnaBridge 145:64910690c574 767
AnnaBridge 145:64910690c574 768 /*!
AnnaBridge 145:64910690c574 769 * @brief Gets the capability information.
AnnaBridge 145:64910690c574 770 *
AnnaBridge 145:64910690c574 771 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 772 * @param capability Structure to save capability information.
AnnaBridge 145:64910690c574 773 */
AnnaBridge 145:64910690c574 774 void SDHC_GetCapability(SDHC_Type *base, sdhc_capability_t *capability);
AnnaBridge 145:64910690c574 775
AnnaBridge 145:64910690c574 776 /*!
AnnaBridge 145:64910690c574 777 * @brief Enables or disables the SD bus clock.
AnnaBridge 145:64910690c574 778 *
AnnaBridge 145:64910690c574 779 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 780 * @param enable True to enable, false to disable.
AnnaBridge 145:64910690c574 781 */
AnnaBridge 145:64910690c574 782 static inline void SDHC_EnableSdClock(SDHC_Type *base, bool enable)
AnnaBridge 145:64910690c574 783 {
AnnaBridge 145:64910690c574 784 if (enable)
AnnaBridge 145:64910690c574 785 {
AnnaBridge 145:64910690c574 786 base->SYSCTL |= SDHC_SYSCTL_SDCLKEN_MASK;
AnnaBridge 145:64910690c574 787 }
AnnaBridge 145:64910690c574 788 else
AnnaBridge 145:64910690c574 789 {
AnnaBridge 145:64910690c574 790 base->SYSCTL &= ~SDHC_SYSCTL_SDCLKEN_MASK;
AnnaBridge 145:64910690c574 791 }
AnnaBridge 145:64910690c574 792 }
AnnaBridge 145:64910690c574 793
AnnaBridge 145:64910690c574 794 /*!
AnnaBridge 145:64910690c574 795 * @brief Sets the SD bus clock frequency.
AnnaBridge 145:64910690c574 796 *
AnnaBridge 145:64910690c574 797 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 798 * @param srcClock_Hz SDHC source clock frequency united in Hz.
AnnaBridge 145:64910690c574 799 * @param busClock_Hz SD bus clock frequency united in Hz.
AnnaBridge 145:64910690c574 800 *
AnnaBridge 145:64910690c574 801 * @return The nearest frequency of busClock_Hz configured to SD bus.
AnnaBridge 145:64910690c574 802 */
AnnaBridge 145:64910690c574 803 uint32_t SDHC_SetSdClock(SDHC_Type *base, uint32_t srcClock_Hz, uint32_t busClock_Hz);
AnnaBridge 145:64910690c574 804
AnnaBridge 145:64910690c574 805 /*!
AnnaBridge 145:64910690c574 806 * @brief Sends 80 clocks to the card to set it to the active state.
AnnaBridge 145:64910690c574 807 *
AnnaBridge 145:64910690c574 808 * This function must be called each time the card is inserted to ensure that the card can receive the command
AnnaBridge 145:64910690c574 809 * correctly.
AnnaBridge 145:64910690c574 810 *
AnnaBridge 145:64910690c574 811 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 812 * @param timeout Timeout to initialize card.
AnnaBridge 145:64910690c574 813 * @retval true Set card active successfully.
AnnaBridge 145:64910690c574 814 * @retval false Set card active failed.
AnnaBridge 145:64910690c574 815 */
AnnaBridge 145:64910690c574 816 bool SDHC_SetCardActive(SDHC_Type *base, uint32_t timeout);
AnnaBridge 145:64910690c574 817
AnnaBridge 145:64910690c574 818 /*!
AnnaBridge 145:64910690c574 819 * @brief Sets the data transfer width.
AnnaBridge 145:64910690c574 820 *
AnnaBridge 145:64910690c574 821 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 822 * @param width Data transfer width.
AnnaBridge 145:64910690c574 823 */
AnnaBridge 145:64910690c574 824 static inline void SDHC_SetDataBusWidth(SDHC_Type *base, sdhc_data_bus_width_t width)
AnnaBridge 145:64910690c574 825 {
AnnaBridge 145:64910690c574 826 base->PROCTL = ((base->PROCTL & ~SDHC_PROCTL_DTW_MASK) | SDHC_PROCTL_DTW(width));
AnnaBridge 145:64910690c574 827 }
AnnaBridge 145:64910690c574 828
AnnaBridge 145:64910690c574 829 /*!
AnnaBridge 145:64910690c574 830 * @brief Sets the card transfer-related configuration.
AnnaBridge 145:64910690c574 831 *
AnnaBridge 145:64910690c574 832 * This function fills the card transfer-related command argument/transfer flag/data size. The command and data are sent
AnnaBridge 145:64910690c574 833 by
AnnaBridge 145:64910690c574 834 * SDHC after calling this function.
AnnaBridge 145:64910690c574 835 *
AnnaBridge 145:64910690c574 836 * Example:
AnnaBridge 145:64910690c574 837 @code
AnnaBridge 145:64910690c574 838 sdhc_transfer_config_t transferConfig;
AnnaBridge 145:64910690c574 839 transferConfig.dataBlockSize = 512U;
AnnaBridge 145:64910690c574 840 transferConfig.dataBlockCount = 2U;
AnnaBridge 145:64910690c574 841 transferConfig.commandArgument = 0x01AAU;
AnnaBridge 145:64910690c574 842 transferConfig.commandIndex = 8U;
AnnaBridge 145:64910690c574 843 transferConfig.flags |= (kSDHC_EnableDmaFlag | kSDHC_EnableAutoCommand12Flag | kSDHC_MultipleBlockFlag);
AnnaBridge 145:64910690c574 844 SDHC_SetTransferConfig(SDHC, &transferConfig);
AnnaBridge 145:64910690c574 845 @endcode
AnnaBridge 145:64910690c574 846 *
AnnaBridge 145:64910690c574 847 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 848 * @param config Command configuration structure.
AnnaBridge 145:64910690c574 849 */
AnnaBridge 145:64910690c574 850 void SDHC_SetTransferConfig(SDHC_Type *base, const sdhc_transfer_config_t *config);
AnnaBridge 145:64910690c574 851
AnnaBridge 145:64910690c574 852 /*!
AnnaBridge 145:64910690c574 853 * @brief Gets the command response.
AnnaBridge 145:64910690c574 854 *
AnnaBridge 145:64910690c574 855 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 856 * @param index The index of response register, range from 0 to 3.
AnnaBridge 145:64910690c574 857 * @return Response register transfer.
AnnaBridge 145:64910690c574 858 */
AnnaBridge 145:64910690c574 859 static inline uint32_t SDHC_GetCommandResponse(SDHC_Type *base, uint32_t index)
AnnaBridge 145:64910690c574 860 {
AnnaBridge 145:64910690c574 861 assert(index < 4U);
AnnaBridge 145:64910690c574 862
AnnaBridge 145:64910690c574 863 return base->CMDRSP[index];
AnnaBridge 145:64910690c574 864 }
AnnaBridge 145:64910690c574 865
AnnaBridge 145:64910690c574 866 /*!
AnnaBridge 145:64910690c574 867 * @brief Fills the the data port.
AnnaBridge 145:64910690c574 868 *
AnnaBridge 145:64910690c574 869 * This function is used to implement the data transfer by Data Port instead of DMA.
AnnaBridge 145:64910690c574 870 *
AnnaBridge 145:64910690c574 871 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 872 * @param data The data about to be sent.
AnnaBridge 145:64910690c574 873 */
AnnaBridge 145:64910690c574 874 static inline void SDHC_WriteData(SDHC_Type *base, uint32_t data)
AnnaBridge 145:64910690c574 875 {
AnnaBridge 145:64910690c574 876 base->DATPORT = data;
AnnaBridge 145:64910690c574 877 }
AnnaBridge 145:64910690c574 878
AnnaBridge 145:64910690c574 879 /*!
AnnaBridge 145:64910690c574 880 * @brief Retrieves the data from the data port.
AnnaBridge 145:64910690c574 881 *
AnnaBridge 145:64910690c574 882 * This function is used to implement the data transfer by Data Port instead of DMA.
AnnaBridge 145:64910690c574 883 *
AnnaBridge 145:64910690c574 884 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 885 * @return The data has been read.
AnnaBridge 145:64910690c574 886 */
AnnaBridge 145:64910690c574 887 static inline uint32_t SDHC_ReadData(SDHC_Type *base)
AnnaBridge 145:64910690c574 888 {
AnnaBridge 145:64910690c574 889 return base->DATPORT;
AnnaBridge 145:64910690c574 890 }
AnnaBridge 145:64910690c574 891
AnnaBridge 145:64910690c574 892 /*!
AnnaBridge 145:64910690c574 893 * @brief Enables or disables a wakeup event in low-power mode.
AnnaBridge 145:64910690c574 894 *
AnnaBridge 145:64910690c574 895 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 896 * @param mask Wakeup events mask(_sdhc_wakeup_event).
AnnaBridge 145:64910690c574 897 * @param enable True to enable, false to disable.
AnnaBridge 145:64910690c574 898 */
AnnaBridge 145:64910690c574 899 static inline void SDHC_EnableWakeupEvent(SDHC_Type *base, uint32_t mask, bool enable)
AnnaBridge 145:64910690c574 900 {
AnnaBridge 145:64910690c574 901 if (enable)
AnnaBridge 145:64910690c574 902 {
AnnaBridge 145:64910690c574 903 base->PROCTL |= mask;
AnnaBridge 145:64910690c574 904 }
AnnaBridge 145:64910690c574 905 else
AnnaBridge 145:64910690c574 906 {
AnnaBridge 145:64910690c574 907 base->PROCTL &= ~mask;
AnnaBridge 145:64910690c574 908 }
AnnaBridge 145:64910690c574 909 }
AnnaBridge 145:64910690c574 910
AnnaBridge 145:64910690c574 911 /*!
AnnaBridge 145:64910690c574 912 * @brief Enables or disables the card detection level for testing.
AnnaBridge 145:64910690c574 913 *
AnnaBridge 145:64910690c574 914 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 915 * @param enable True to enable, false to disable.
AnnaBridge 145:64910690c574 916 */
AnnaBridge 145:64910690c574 917 static inline void SDHC_EnableCardDetectTest(SDHC_Type *base, bool enable)
AnnaBridge 145:64910690c574 918 {
AnnaBridge 145:64910690c574 919 if (enable)
AnnaBridge 145:64910690c574 920 {
AnnaBridge 145:64910690c574 921 base->PROCTL |= SDHC_PROCTL_CDSS_MASK;
AnnaBridge 145:64910690c574 922 }
AnnaBridge 145:64910690c574 923 else
AnnaBridge 145:64910690c574 924 {
AnnaBridge 145:64910690c574 925 base->PROCTL &= ~SDHC_PROCTL_CDSS_MASK;
AnnaBridge 145:64910690c574 926 }
AnnaBridge 145:64910690c574 927 }
AnnaBridge 145:64910690c574 928
AnnaBridge 145:64910690c574 929 /*!
AnnaBridge 145:64910690c574 930 * @brief Sets the card detection test level.
AnnaBridge 145:64910690c574 931 *
AnnaBridge 145:64910690c574 932 * This function sets the card detection test level to indicate whether the card is inserted into the SDHC when DAT[3]/
AnnaBridge 145:64910690c574 933 * CD pin is selected as a card detection pin. This function can also assert the pin logic when DAT[3]/CD pin is
AnnaBridge 145:64910690c574 934 * selected
AnnaBridge 145:64910690c574 935 * as the card detection pin.
AnnaBridge 145:64910690c574 936 *
AnnaBridge 145:64910690c574 937 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 938 * @param high True to set the card detect level to high.
AnnaBridge 145:64910690c574 939 */
AnnaBridge 145:64910690c574 940 static inline void SDHC_SetCardDetectTestLevel(SDHC_Type *base, bool high)
AnnaBridge 145:64910690c574 941 {
AnnaBridge 145:64910690c574 942 if (high)
AnnaBridge 145:64910690c574 943 {
AnnaBridge 145:64910690c574 944 base->PROCTL |= SDHC_PROCTL_CDTL_MASK;
AnnaBridge 145:64910690c574 945 }
AnnaBridge 145:64910690c574 946 else
AnnaBridge 145:64910690c574 947 {
AnnaBridge 145:64910690c574 948 base->PROCTL &= ~SDHC_PROCTL_CDTL_MASK;
AnnaBridge 145:64910690c574 949 }
AnnaBridge 145:64910690c574 950 }
AnnaBridge 145:64910690c574 951
AnnaBridge 145:64910690c574 952 /*!
AnnaBridge 145:64910690c574 953 * @brief Enables or disables the SDIO card control.
AnnaBridge 145:64910690c574 954 *
AnnaBridge 145:64910690c574 955 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 956 * @param mask SDIO card control flags mask(_sdhc_sdio_control_flag).
AnnaBridge 145:64910690c574 957 * @param enable True to enable, false to disable.
AnnaBridge 145:64910690c574 958 */
AnnaBridge 145:64910690c574 959 void SDHC_EnableSdioControl(SDHC_Type *base, uint32_t mask, bool enable);
AnnaBridge 145:64910690c574 960
AnnaBridge 145:64910690c574 961 /*!
AnnaBridge 145:64910690c574 962 * @brief Restarts a transaction which has stopped at the block GAP for the SDIO card.
AnnaBridge 145:64910690c574 963 *
AnnaBridge 145:64910690c574 964 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 965 */
AnnaBridge 145:64910690c574 966 static inline void SDHC_SetContinueRequest(SDHC_Type *base)
AnnaBridge 145:64910690c574 967 {
AnnaBridge 145:64910690c574 968 base->PROCTL |= SDHC_PROCTL_CREQ_MASK;
AnnaBridge 145:64910690c574 969 }
AnnaBridge 145:64910690c574 970
AnnaBridge 145:64910690c574 971 /*!
AnnaBridge 145:64910690c574 972 * @brief Configures the MMC boot feature.
AnnaBridge 145:64910690c574 973 *
AnnaBridge 145:64910690c574 974 * Example:
AnnaBridge 145:64910690c574 975 @code
AnnaBridge 145:64910690c574 976 sdhc_boot_config_t config;
AnnaBridge 145:64910690c574 977 config.ackTimeoutCount = 4;
AnnaBridge 145:64910690c574 978 config.bootMode = kSDHC_BootModeNormal;
AnnaBridge 145:64910690c574 979 config.blockCount = 5;
AnnaBridge 145:64910690c574 980 config.enableBootAck = true;
AnnaBridge 145:64910690c574 981 config.enableBoot = true;
AnnaBridge 145:64910690c574 982 config.enableAutoStopAtBlockGap = true;
AnnaBridge 145:64910690c574 983 SDHC_SetMmcBootConfig(SDHC, &config);
AnnaBridge 145:64910690c574 984 @endcode
AnnaBridge 145:64910690c574 985 *
AnnaBridge 145:64910690c574 986 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 987 * @param config The MMC boot configuration information.
AnnaBridge 145:64910690c574 988 */
AnnaBridge 145:64910690c574 989 void SDHC_SetMmcBootConfig(SDHC_Type *base, const sdhc_boot_config_t *config);
AnnaBridge 145:64910690c574 990
AnnaBridge 145:64910690c574 991 /*!
AnnaBridge 145:64910690c574 992 * @brief Forces generating events according to the given mask.
AnnaBridge 145:64910690c574 993 *
AnnaBridge 145:64910690c574 994 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 995 * @param mask The force events mask(_sdhc_force_event).
AnnaBridge 145:64910690c574 996 */
AnnaBridge 145:64910690c574 997 static inline void SDHC_SetForceEvent(SDHC_Type *base, uint32_t mask)
AnnaBridge 145:64910690c574 998 {
AnnaBridge 145:64910690c574 999 base->FEVT = mask;
AnnaBridge 145:64910690c574 1000 }
AnnaBridge 145:64910690c574 1001
AnnaBridge 145:64910690c574 1002 /* @} */
AnnaBridge 145:64910690c574 1003
AnnaBridge 145:64910690c574 1004 /*!
AnnaBridge 145:64910690c574 1005 * @name Transactional
AnnaBridge 145:64910690c574 1006 * @{
AnnaBridge 145:64910690c574 1007 */
AnnaBridge 145:64910690c574 1008
AnnaBridge 145:64910690c574 1009 /*!
AnnaBridge 145:64910690c574 1010 * @brief Transfers the command/data using a blocking method.
AnnaBridge 145:64910690c574 1011 *
AnnaBridge 145:64910690c574 1012 * This function waits until the command response/data is received or the SDHC encounters an error by polling the status
AnnaBridge 145:64910690c574 1013 * flag.
AnnaBridge 145:64910690c574 1014 * The application must not call this API in multiple threads at the same time. Because of that this API doesn't support
AnnaBridge 145:64910690c574 1015 * the re-entry mechanism.
AnnaBridge 145:64910690c574 1016 *
AnnaBridge 145:64910690c574 1017 * @note There is no need to call the API 'SDHC_TransferCreateHandle' when calling this API.
AnnaBridge 145:64910690c574 1018 *
AnnaBridge 145:64910690c574 1019 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 1020 * @param admaTable ADMA table address, can't be null if transfer way is ADMA1/ADMA2.
AnnaBridge 145:64910690c574 1021 * @param admaTableWords ADMA table length united as words, can't be 0 if transfer way is ADMA1/ADMA2.
AnnaBridge 145:64910690c574 1022 * @param transfer Transfer content.
AnnaBridge 145:64910690c574 1023 * @retval kStatus_InvalidArgument Argument is invalid.
AnnaBridge 145:64910690c574 1024 * @retval kStatus_SDHC_PrepareAdmaDescriptorFailed Prepare ADMA descriptor failed.
AnnaBridge 145:64910690c574 1025 * @retval kStatus_SDHC_SendCommandFailed Send command failed.
AnnaBridge 145:64910690c574 1026 * @retval kStatus_SDHC_TransferDataFailed Transfer data failed.
AnnaBridge 145:64910690c574 1027 * @retval kStatus_Success Operate successfully.
AnnaBridge 145:64910690c574 1028 */
AnnaBridge 145:64910690c574 1029 status_t SDHC_TransferBlocking(SDHC_Type *base,
AnnaBridge 145:64910690c574 1030 uint32_t *admaTable,
AnnaBridge 145:64910690c574 1031 uint32_t admaTableWords,
AnnaBridge 145:64910690c574 1032 sdhc_transfer_t *transfer);
AnnaBridge 145:64910690c574 1033
AnnaBridge 145:64910690c574 1034 /*!
AnnaBridge 145:64910690c574 1035 * @brief Creates the SDHC handle.
AnnaBridge 145:64910690c574 1036 *
AnnaBridge 145:64910690c574 1037 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 1038 * @param handle SDHC handle pointer.
AnnaBridge 145:64910690c574 1039 * @param callback Structure pointer to contain all callback functions.
AnnaBridge 145:64910690c574 1040 * @param userData Callback function parameter.
AnnaBridge 145:64910690c574 1041 */
AnnaBridge 145:64910690c574 1042 void SDHC_TransferCreateHandle(SDHC_Type *base,
AnnaBridge 145:64910690c574 1043 sdhc_handle_t *handle,
AnnaBridge 145:64910690c574 1044 const sdhc_transfer_callback_t *callback,
AnnaBridge 145:64910690c574 1045 void *userData);
AnnaBridge 145:64910690c574 1046
AnnaBridge 145:64910690c574 1047 /*!
AnnaBridge 145:64910690c574 1048 * @brief Transfers the command/data using an interrupt and an asynchronous method.
AnnaBridge 145:64910690c574 1049 *
AnnaBridge 145:64910690c574 1050 * This function sends a command and data and returns immediately. It doesn't wait the transfer complete or encounter an
AnnaBridge 145:64910690c574 1051 * error.
AnnaBridge 145:64910690c574 1052 * The application must not call this API in multiple threads at the same time. Because of that this API doesn't support
AnnaBridge 145:64910690c574 1053 * the re-entry mechanism.
AnnaBridge 145:64910690c574 1054 *
AnnaBridge 145:64910690c574 1055 * @note Call the API 'SDHC_TransferCreateHandle' when calling this API.
AnnaBridge 145:64910690c574 1056 *
AnnaBridge 145:64910690c574 1057 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 1058 * @param handle SDHC handle.
AnnaBridge 145:64910690c574 1059 * @param admaTable ADMA table address, can't be null if transfer way is ADMA1/ADMA2.
AnnaBridge 145:64910690c574 1060 * @param admaTableWords ADMA table length united as words, can't be 0 if transfer way is ADMA1/ADMA2.
AnnaBridge 145:64910690c574 1061 * @param transfer Transfer content.
AnnaBridge 145:64910690c574 1062 * @retval kStatus_InvalidArgument Argument is invalid.
AnnaBridge 145:64910690c574 1063 * @retval kStatus_SDHC_BusyTransferring Busy transferring.
AnnaBridge 145:64910690c574 1064 * @retval kStatus_SDHC_PrepareAdmaDescriptorFailed Prepare ADMA descriptor failed.
AnnaBridge 145:64910690c574 1065 * @retval kStatus_Success Operate successfully.
AnnaBridge 145:64910690c574 1066 */
AnnaBridge 145:64910690c574 1067 status_t SDHC_TransferNonBlocking(
AnnaBridge 145:64910690c574 1068 SDHC_Type *base, sdhc_handle_t *handle, uint32_t *admaTable, uint32_t admaTableWords, sdhc_transfer_t *transfer);
AnnaBridge 145:64910690c574 1069
AnnaBridge 145:64910690c574 1070 /*!
AnnaBridge 145:64910690c574 1071 * @brief IRQ handler for the SDHC.
AnnaBridge 145:64910690c574 1072 *
AnnaBridge 145:64910690c574 1073 * This function deals with the IRQs on the given host controller.
AnnaBridge 145:64910690c574 1074 *
AnnaBridge 145:64910690c574 1075 * @param base SDHC peripheral base address.
AnnaBridge 145:64910690c574 1076 * @param handle SDHC handle.
AnnaBridge 145:64910690c574 1077 */
AnnaBridge 145:64910690c574 1078 void SDHC_TransferHandleIRQ(SDHC_Type *base, sdhc_handle_t *handle);
AnnaBridge 145:64910690c574 1079
AnnaBridge 145:64910690c574 1080 /* @} */
AnnaBridge 145:64910690c574 1081
AnnaBridge 145:64910690c574 1082 #if defined(__cplusplus)
AnnaBridge 145:64910690c574 1083 }
AnnaBridge 145:64910690c574 1084 #endif
AnnaBridge 145:64910690c574 1085 /*! @} */
AnnaBridge 145:64910690c574 1086
AnnaBridge 145:64910690c574 1087 #endif /* _FSL_SDHC_H_*/