mmcsd_host.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * File : mmcsd_host.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2011-07-25 weety first version
  13. */
  14. #ifndef __HOST_H__
  15. #define __HOST_H__
  16. #include <rtthread.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. struct rt_mmcsd_io_cfg {
  21. rt_uint32_t clock; /* clock rate */
  22. rt_uint16_t vdd;
  23. /* vdd stores the bit number of the selected voltage range from below. */
  24. rt_uint8_t bus_mode; /* command output mode */
  25. #define MMCSD_BUSMODE_OPENDRAIN 1
  26. #define MMCSD_BUSMODE_PUSHPULL 2
  27. rt_uint8_t chip_select; /* SPI chip select */
  28. #define MMCSD_CS_IGNORE 0
  29. #define MMCSD_CS_HIGH 1
  30. #define MMCSD_CS_LOW 2
  31. rt_uint8_t power_mode; /* power supply mode */
  32. #define MMCSD_POWER_OFF 0
  33. #define MMCSD_POWER_UP 1
  34. #define MMCSD_POWER_ON 2
  35. rt_uint8_t bus_width; /* data bus width */
  36. #define MMCSD_BUS_WIDTH_1 0
  37. #define MMCSD_BUS_WIDTH_4 2
  38. #define MMCSD_BUS_WIDTH_8 3
  39. };
  40. struct rt_mmcsd_host;
  41. struct rt_mmcsd_req;
  42. struct rt_mmcsd_host_ops {
  43. void (*request)(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req);
  44. void (*set_iocfg)(struct rt_mmcsd_host *host, struct rt_mmcsd_io_cfg *io_cfg);
  45. rt_int32_t (*get_card_status)(struct rt_mmcsd_host *host);
  46. };
  47. struct rt_mmcsd_host {
  48. struct rt_mmcsd_card *card;
  49. const struct rt_mmcsd_host_ops *ops;
  50. rt_uint32_t freq_min;
  51. rt_uint32_t freq_max;
  52. struct rt_mmcsd_io_cfg io_cfg;
  53. rt_uint32_t valid_ocr; /* current valid OCR */
  54. #define VDD_165_195 (1 << 7) /* VDD voltage 1.65 - 1.95 */
  55. #define VDD_20_21 (1 << 8) /* VDD voltage 2.0 ~ 2.1 */
  56. #define VDD_21_22 (1 << 9) /* VDD voltage 2.1 ~ 2.2 */
  57. #define VDD_22_23 (1 << 10) /* VDD voltage 2.2 ~ 2.3 */
  58. #define VDD_23_24 (1 << 11) /* VDD voltage 2.3 ~ 2.4 */
  59. #define VDD_24_25 (1 << 12) /* VDD voltage 2.4 ~ 2.5 */
  60. #define VDD_25_26 (1 << 13) /* VDD voltage 2.5 ~ 2.6 */
  61. #define VDD_26_27 (1 << 14) /* VDD voltage 2.6 ~ 2.7 */
  62. #define VDD_27_28 (1 << 15) /* VDD voltage 2.7 ~ 2.8 */
  63. #define VDD_28_29 (1 << 16) /* VDD voltage 2.8 ~ 2.9 */
  64. #define VDD_29_30 (1 << 17) /* VDD voltage 2.9 ~ 3.0 */
  65. #define VDD_30_31 (1 << 18) /* VDD voltage 3.0 ~ 3.1 */
  66. #define VDD_31_32 (1 << 19) /* VDD voltage 3.1 ~ 3.2 */
  67. #define VDD_32_33 (1 << 20) /* VDD voltage 3.2 ~ 3.3 */
  68. #define VDD_33_34 (1 << 21) /* VDD voltage 3.3 ~ 3.4 */
  69. #define VDD_34_35 (1 << 22) /* VDD voltage 3.4 ~ 3.5 */
  70. #define VDD_35_36 (1 << 23) /* VDD voltage 3.5 ~ 3.6 */
  71. rt_uint32_t flags; /* define device capabilities */
  72. #define MMCSD_BUSWIDTH_4 (1 << 0)
  73. #define MMCSD_BUSWIDTH_8 (1 << 1)
  74. #define MMCSD_MUTBLKWRITE (1 << 2)
  75. #define MMCSD_HOST_IS_SPI (1 << 3)
  76. #define controller_is_spi(host) (host->flags & MMCSD_HOST_IS_SPI)
  77. rt_uint32_t spi_use_crc;
  78. struct rt_semaphore bus_lock;
  79. struct rt_semaphore sem_ack;
  80. void *private_data;
  81. };
  82. rt_inline void mmcsd_delay_ms(rt_uint32_t ms)
  83. {
  84. if (ms < 1000 / RT_TICK_PER_SECOND)
  85. {
  86. rt_thread_delay(1);
  87. }
  88. else
  89. {
  90. rt_thread_delay(ms/(1000 / RT_TICK_PER_SECOND));
  91. }
  92. }
  93. #ifdef __cplusplus
  94. }
  95. #endif
  96. #endif