fsl_sdmmc.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (c) 2015, 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_SDMMC_H_
  31. #define _FSL_SDMMC_H_
  32. #include "fsl_card.h"
  33. /*******************************************************************************
  34. * Definitions
  35. ******************************************************************************/
  36. /*! @brief Reverse byte sequence in uint32_t */
  37. #define SWAP_WORD_BYTE_SEQUENCE(x) (__REV(x))
  38. /*! @brief Reverse byte sequence for each half word in uint32_t */
  39. #define SWAP_HALF_WROD_BYTE_SEQUENCE(x) (__REV16(x))
  40. /*! @brief Maximum loop count to check the card operation voltage range */
  41. #define FSL_SDMMC_MAX_VOLTAGE_RETRIES (1000U)
  42. /*! @brief Maximum loop count to send the cmd */
  43. #define FSL_SDMMC_MAX_CMD_RETRIES (10U)
  44. /*************************************************************************************************
  45. * API
  46. ************************************************************************************************/
  47. #if defined(__cplusplus)
  48. extern "C" {
  49. #endif
  50. /*!
  51. * @brief Selects the card to put it into transfer state.
  52. *
  53. * @param base HOST peripheral base address.
  54. * @param transfer HOST transfer function.
  55. * @param relativeAddress Relative address.
  56. * @param isSelected True to put card into transfer state.
  57. * @retval kStatus_SDMMC_TransferFailed Transfer failed.
  58. * @retval kStatus_Success Operate successfully.
  59. */
  60. status_t SDMMC_SelectCard(HOST_TYPE *base, HOST_TRANSFER_FUNCTION transfer, uint32_t relativeAddress, bool isSelected);
  61. /*!
  62. * @brief Sends an application command.
  63. *
  64. * @param base HOST peripheral base address.
  65. * @param transfer HOST transfer function.
  66. * @param relativeAddress Card relative address.
  67. * @retval kStatus_SDMMC_TransferFailed Transfer failed.
  68. * @retval kStatus_SDMMC_CardNotSupport Card doesn't support.
  69. * @retval kStatus_Success Operate successfully.
  70. */
  71. status_t SDMMC_SendApplicationCommand(HOST_TYPE *base, HOST_TRANSFER_FUNCTION transfer, uint32_t relativeAddress);
  72. /*!
  73. * @brief Sets the block count.
  74. *
  75. * @param base HOST peripheral base address.
  76. * @param transfer HOST transfer function.
  77. * @param blockCount Block count.
  78. * @retval kStatus_SDMMC_TransferFailed Transfer failed.
  79. * @retval kStatus_Success Operate successfully.
  80. */
  81. status_t SDMMC_SetBlockCount(HOST_TYPE *base, HOST_TRANSFER_FUNCTION transfer, uint32_t blockCount);
  82. /*!
  83. * @brief Sets the card to be idle state.
  84. *
  85. * @param base HOST peripheral base address.
  86. * @param transfer HOST transfer function.
  87. * @retval kStatus_SDMMC_TransferFailed Transfer failed.
  88. * @retval kStatus_Success Operate successfully.
  89. */
  90. status_t SDMMC_GoIdle(HOST_TYPE *base, HOST_TRANSFER_FUNCTION transfer);
  91. /*!
  92. * @brief Sets data block size.
  93. *
  94. * @param base HOST peripheral base address.
  95. * @param transfer HOST transfer function.
  96. * @param blockSize Block size.
  97. * @retval kStatus_SDMMC_TransferFailed Transfer failed.
  98. * @retval kStatus_Success Operate successfully.
  99. */
  100. status_t SDMMC_SetBlockSize(HOST_TYPE *base, HOST_TRANSFER_FUNCTION transfer, uint32_t blockSize);
  101. /*!
  102. * @brief Sets card to inactive status
  103. *
  104. * @param base HOST peripheral base address.
  105. * @param transfer HOST transfer function.
  106. * @retval kStatus_SDMMC_TransferFailed Transfer failed.
  107. * @retval kStatus_Success Operate successfully.
  108. */
  109. status_t SDMMC_SetCardInactive(HOST_TYPE *base, HOST_TRANSFER_FUNCTION transfer);
  110. /*!
  111. * @brief provide a simple delay function for sdmmc
  112. *
  113. * @param delay num*10000.
  114. */
  115. void SDMMC_Delay(uint32_t num);
  116. /*!
  117. * @brief provide a voltage switch function for SD/SDIO card
  118. *
  119. * @param base HOST peripheral base address.
  120. * @param transfer HOST transfer function.
  121. */
  122. status_t SDMMC_SwitchVoltage(HOST_TYPE *base, HOST_TRANSFER_FUNCTION transfer);
  123. /*!
  124. * @brief excute tuning
  125. *
  126. * @param base HOST peripheral base address.
  127. * @param tuning cmd
  128. * @param tuning block size
  129. */
  130. status_t SDMMC_ExecuteTuning(HOST_TYPE *base, uint32_t tuningCmd, uint32_t blockSize);
  131. #if defined(__cplusplus)
  132. }
  133. #endif
  134. #endif /* _FSL_SDMMC_H_ */