hal_sdc_lld.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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_lld.h
  15. * @brief PLATFORM SDC subsystem low level driver header.
  16. *
  17. * @addtogroup SDC
  18. * @{
  19. */
  20. #ifndef HAL_SDC_LLD_H
  21. #define HAL_SDC_LLD_H
  22. #if (HAL_USE_SDC == TRUE) || defined(__DOXYGEN__)
  23. /*===========================================================================*/
  24. /* Driver constants. */
  25. /*===========================================================================*/
  26. /*===========================================================================*/
  27. /* Driver pre-compile time settings. */
  28. /*===========================================================================*/
  29. /**
  30. * @name PLATFORM configuration options
  31. * @{
  32. */
  33. /**
  34. * @brief PWMD1 driver enable switch.
  35. * @details If set to @p TRUE the support for PWM1 is included.
  36. * @note The default is @p FALSE.
  37. */
  38. #if !defined(PLATFORM_SDC_USE_SDC1) || defined(__DOXYGEN__)
  39. #define PLATFORM_SDC_USE_SDC1 FALSE
  40. #endif
  41. /** @} */
  42. /*===========================================================================*/
  43. /* Derived constants and error checks. */
  44. /*===========================================================================*/
  45. /*===========================================================================*/
  46. /* Driver data structures and types. */
  47. /*===========================================================================*/
  48. /**
  49. * @brief Type of card flags.
  50. */
  51. typedef uint32_t sdcmode_t;
  52. /**
  53. * @brief SDC Driver condition flags type.
  54. */
  55. typedef uint32_t sdcflags_t;
  56. /**
  57. * @brief Type of a structure representing an SDC driver.
  58. */
  59. typedef struct SDCDriver SDCDriver;
  60. /**
  61. * @brief Driver configuration structure.
  62. * @note It could be empty on some architectures.
  63. */
  64. typedef struct {
  65. /**
  66. * @brief Working area for memory consuming operations.
  67. * @note It is mandatory for detecting MMC cards bigger than 2GB else it
  68. * can be @p NULL.
  69. * @note Memory pointed by this buffer is only used by @p sdcConnect(),
  70. * afterward it can be reused for other purposes.
  71. */
  72. uint8_t *scratchpad;
  73. /**
  74. * @brief Bus width.
  75. */
  76. sdcbusmode_t bus_width;
  77. /* End of the mandatory fields.*/
  78. } SDCConfig;
  79. /**
  80. * @brief @p SDCDriver specific methods.
  81. */
  82. #define _sdc_driver_methods \
  83. _mmcsd_block_device_methods
  84. /**
  85. * @extends MMCSDBlockDeviceVMT
  86. *
  87. * @brief @p SDCDriver virtual methods table.
  88. */
  89. struct SDCDriverVMT {
  90. _sdc_driver_methods
  91. };
  92. /**
  93. * @brief Structure representing an SDC driver.
  94. */
  95. struct SDCDriver {
  96. /**
  97. * @brief Virtual Methods Table.
  98. */
  99. const struct SDCDriverVMT *vmt;
  100. _mmcsd_block_device_data
  101. /**
  102. * @brief Current configuration data.
  103. */
  104. const SDCConfig *config;
  105. /**
  106. * @brief Various flags regarding the mounted card.
  107. */
  108. sdcmode_t cardmode;
  109. /**
  110. * @brief Errors flags.
  111. */
  112. sdcflags_t errors;
  113. /**
  114. * @brief Card RCA.
  115. */
  116. uint32_t rca;
  117. /* End of the mandatory fields.*/
  118. };
  119. /*===========================================================================*/
  120. /* Driver macros. */
  121. /*===========================================================================*/
  122. /*===========================================================================*/
  123. /* External declarations. */
  124. /*===========================================================================*/
  125. #if (PLATFORM_SDC_USE_SDC1 == TRUE) && !defined(__DOXYGEN__)
  126. extern SDCDriver SDCD1;
  127. #endif
  128. #ifdef __cplusplus
  129. extern "C" {
  130. #endif
  131. void sdc_lld_init(void);
  132. void sdc_lld_start(SDCDriver *sdcp);
  133. void sdc_lld_stop(SDCDriver *sdcp);
  134. void sdc_lld_start_clk(SDCDriver *sdcp);
  135. void sdc_lld_set_data_clk(SDCDriver *sdcp, sdcbusclk_t clk);
  136. void sdc_lld_stop_clk(SDCDriver *sdcp);
  137. void sdc_lld_set_bus_mode(SDCDriver *sdcp, sdcbusmode_t mode);
  138. void sdc_lld_send_cmd_none(SDCDriver *sdcp, uint8_t cmd, uint32_t arg);
  139. bool sdc_lld_send_cmd_short(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
  140. uint32_t *resp);
  141. bool sdc_lld_send_cmd_short_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
  142. uint32_t *resp);
  143. bool sdc_lld_send_cmd_long_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
  144. uint32_t *resp);
  145. bool sdc_lld_read_special(SDCDriver *sdcp, uint8_t *buf, size_t bytes,
  146. uint8_t cmd, uint32_t argument);
  147. bool sdc_lld_read(SDCDriver *sdcp, uint32_t startblk,
  148. uint8_t *buf, uint32_t n);
  149. bool sdc_lld_write(SDCDriver *sdcp, uint32_t startblk,
  150. const uint8_t *buf, uint32_t n);
  151. bool sdc_lld_sync(SDCDriver *sdcp);
  152. bool sdc_lld_is_card_inserted(SDCDriver *sdcp);
  153. bool sdc_lld_is_write_protected(SDCDriver *sdcp);
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. #endif /* HAL_USE_SDC == TRUE */
  158. #endif /* HAL_SDC_LLD_H */
  159. /** @} */