hal_sdc.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file hal_sdc.h
  15. * @brief SDC Driver macros and structures.
  16. *
  17. * @addtogroup SDC
  18. * @{
  19. */
  20. #ifndef HAL_SDC_H
  21. #define HAL_SDC_H
  22. #if (HAL_USE_SDC == TRUE) || defined(__DOXYGEN__)
  23. /*===========================================================================*/
  24. /* Driver constants. */
  25. /*===========================================================================*/
  26. /**
  27. * @name SD card types
  28. * @{
  29. */
  30. #define SDC_MODE_CARDTYPE_MASK 0xFU
  31. #define SDC_MODE_CARDTYPE_SDV11 0U
  32. #define SDC_MODE_CARDTYPE_SDV20 1U
  33. #define SDC_MODE_CARDTYPE_MMC 2U
  34. #define SDC_MODE_HIGH_CAPACITY 0x10U
  35. /** @} */
  36. /**
  37. * @name SDC bus error conditions
  38. * @{
  39. */
  40. #define SDC_NO_ERROR 0U
  41. #define SDC_CMD_CRC_ERROR 1U
  42. #define SDC_DATA_CRC_ERROR 2U
  43. #define SDC_DATA_TIMEOUT 4U
  44. #define SDC_COMMAND_TIMEOUT 8U
  45. #define SDC_TX_UNDERRUN 16U
  46. #define SDC_RX_OVERRUN 32U
  47. #define SDC_STARTBIT_ERROR 64U
  48. #define SDC_OVERFLOW_ERROR 128U
  49. #define SDC_UNHANDLED_ERROR 0xFFFFFFFFU
  50. /** @} */
  51. /*===========================================================================*/
  52. /* Driver pre-compile time settings. */
  53. /*===========================================================================*/
  54. /**
  55. * @name SDC configuration options
  56. * @{
  57. */
  58. /**
  59. * @brief Number of initialization attempts before rejecting the card.
  60. * @note Attempts are performed at 10mS intervals.
  61. */
  62. #if !defined(SDC_INIT_RETRY) || defined(__DOXYGEN__)
  63. #define SDC_INIT_RETRY 100
  64. #endif
  65. /**
  66. * @brief Include support for MMC cards.
  67. * @note MMC support is not yet implemented so this option must be kept
  68. * at @p FALSE.
  69. */
  70. #if !defined(SDC_MMC_SUPPORT) || defined(__DOXYGEN__)
  71. #define SDC_MMC_SUPPORT FALSE
  72. #endif
  73. /**
  74. * @brief Delays insertions.
  75. * @details If enabled this options inserts delays into the MMC waiting
  76. * routines releasing some extra CPU time for the threads with
  77. * lower priority, this may slow down the driver a bit however.
  78. */
  79. #if !defined(SDC_NICE_WAITING) || defined(__DOXYGEN__)
  80. #define SDC_NICE_WAITING TRUE
  81. #endif
  82. /**
  83. * @brief OCR initialization constant for V20 cards.
  84. */
  85. #if !defined(SDC_INIT_OCR_V20) || defined(__DOXYGEN__)
  86. #define SDC_INIT_OCR_V20 0x50FF8000U
  87. #endif
  88. /**
  89. * @brief OCR initialization constant for non-V20 cards.
  90. */
  91. #if !defined(SDC_INIT_OCR) || defined(__DOXYGEN__)
  92. #define SDC_INIT_OCR 0x80100000U
  93. #endif
  94. /** @} */
  95. /*===========================================================================*/
  96. /* Derived constants and error checks. */
  97. /*===========================================================================*/
  98. /*===========================================================================*/
  99. /* Driver data structures and types. */
  100. /*===========================================================================*/
  101. /**
  102. * @brief Type of SDIO bus mode.
  103. */
  104. typedef enum {
  105. SDC_MODE_1BIT = 0,
  106. SDC_MODE_4BIT,
  107. SDC_MODE_8BIT
  108. } sdcbusmode_t;
  109. /**
  110. * @brief Max supported clock.
  111. */
  112. typedef enum {
  113. SDC_CLK_25MHz = 0,
  114. SDC_CLK_50MHz
  115. } sdcbusclk_t;
  116. #include "hal_sdc_lld.h"
  117. /*===========================================================================*/
  118. /* Driver macros. */
  119. /*===========================================================================*/
  120. /**
  121. * @name Macro Functions
  122. * @{
  123. */
  124. /**
  125. * @brief Returns the card insertion status.
  126. * @note This macro wraps a low level function named
  127. * @p sdc_lld_is_card_inserted(), this function must be
  128. * provided by the application because it is not part of the
  129. * SDC driver.
  130. *
  131. * @param[in] sdcp pointer to the @p SDCDriver object
  132. * @return The card state.
  133. * @retval false card not inserted.
  134. * @retval true card inserted.
  135. *
  136. * @api
  137. */
  138. #define sdcIsCardInserted(sdcp) (sdc_lld_is_card_inserted(sdcp))
  139. /**
  140. * @brief Returns the write protect status.
  141. * @note This macro wraps a low level function named
  142. * @p sdc_lld_is_write_protected(), this function must be
  143. * provided by the application because it is not part of the
  144. * SDC driver.
  145. *
  146. * @param[in] sdcp pointer to the @p SDCDriver object
  147. * @return The card state.
  148. * @retval false not write protected.
  149. * @retval true write protected.
  150. *
  151. * @api
  152. */
  153. #define sdcIsWriteProtected(sdcp) (sdc_lld_is_write_protected(sdcp))
  154. /** @} */
  155. /*===========================================================================*/
  156. /* External declarations. */
  157. /*===========================================================================*/
  158. #ifdef __cplusplus
  159. extern "C" {
  160. #endif
  161. void sdcInit(void);
  162. void sdcObjectInit(SDCDriver *sdcp);
  163. void sdcStart(SDCDriver *sdcp, const SDCConfig *config);
  164. void sdcStop(SDCDriver *sdcp);
  165. bool sdcConnect(SDCDriver *sdcp);
  166. bool sdcDisconnect(SDCDriver *sdcp);
  167. bool sdcRead(SDCDriver *sdcp, uint32_t startblk,
  168. uint8_t *buf, uint32_t n);
  169. bool sdcWrite(SDCDriver *sdcp, uint32_t startblk,
  170. const uint8_t *buf, uint32_t n);
  171. sdcflags_t sdcGetAndClearErrors(SDCDriver *sdcp);
  172. bool sdcSync(SDCDriver *sdcp);
  173. bool sdcGetInfo(SDCDriver *sdcp, BlockDeviceInfo *bdip);
  174. bool sdcErase(SDCDriver *sdcp, uint32_t startblk, uint32_t endblk);
  175. bool _sdc_wait_for_transfer_state(SDCDriver *sdcp);
  176. #ifdef __cplusplus
  177. }
  178. #endif
  179. #endif /* HAL_USE_SDC == TRUE */
  180. #endif /* HAL_SDC_H */
  181. /** @} */