nu_sdh.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /****************************************************************************//**
  2. * @file nu_sdh.h
  3. * @brief SDH driver header file
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. * @copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
  7. *****************************************************************************/
  8. #ifndef __NU_SDH_H__
  9. #define __NU_SDH_H__
  10. #if defined ( __CC_ARM )
  11. #pragma anon_unions
  12. #endif
  13. #ifdef __cplusplus
  14. extern "C"
  15. {
  16. #endif
  17. /** @addtogroup Standard_Driver Standard Driver
  18. @{
  19. */
  20. /** @addtogroup SDH_Driver SDH Driver
  21. @{
  22. */
  23. /** @addtogroup SDH_EXPORTED_CONSTANTS SDH Exported Constants
  24. @{
  25. */
  26. #define SDH_POWER_ON 0x01
  27. #define SDH_POWER_180 0x0A
  28. #define SDH_POWER_300 0x0C
  29. #define SDH_POWER_330 0x0E
  30. #define SDH_RESET_ALL 0x01
  31. #define SDH_RESET_CMD 0x02
  32. #define SDH_RESET_DATA 0x04
  33. #define SDH_CMD_RESP_MASK 0x03
  34. #define SDH_CMD_CRC 0x08
  35. #define SDH_CMD_INDEX 0x10
  36. #define SDH_CMD_DATA 0x20
  37. #define SDH_CMD_ABORTCMD 0xC0
  38. #define SDH_CMD_RESP_NONE 0x00
  39. #define SDH_CMD_RESP_LONG 0x01
  40. #define SDH_CMD_RESP_SHORT 0x02
  41. #define SDH_CMD_RESP_SHORT_BUSY 0x03
  42. /* MMC command */
  43. #define MMC_CMD_STOP_TRANSMISSION 12
  44. /* MMC response */
  45. #define MMC_RSP_PRESENT (1 << 0)
  46. #define MMC_RSP_136 (1 << 1) /* 136 bit response */
  47. #define MMC_RSP_CRC (1 << 2) /* expect valid crc */
  48. #define MMC_RSP_BUSY (1 << 3) /* card may send busy */
  49. #define MMC_RSP_OPCODE (1 << 4) /* response contains opcode */
  50. #define MMC_RSP_NONE (0)
  51. #define MMC_RSP_R1 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
  52. #define MMC_RSP_R1b (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE|MMC_RSP_BUSY)
  53. #define MMC_RSP_R2 (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC)
  54. #define MMC_RSP_R3 (MMC_RSP_PRESENT)
  55. #define MMC_RSP_R4 (MMC_RSP_PRESENT)
  56. #define MMC_RSP_R5 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
  57. #define MMC_RSP_R6 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
  58. #define MMC_RSP_R7 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
  59. #define MMC_DATA_READ 1
  60. #define MMC_DATA_WRITE 2
  61. #define SDH_BLOCK_SIZE 512ul
  62. struct mmc_cmd
  63. {
  64. unsigned short cmdidx;
  65. unsigned int resp_type;
  66. unsigned int cmdarg;
  67. unsigned int response[4];
  68. };
  69. struct mmc_data
  70. {
  71. union
  72. {
  73. char *dest;
  74. const char *src; /* src buffers don't get written to */
  75. };
  76. unsigned int flags;
  77. unsigned int blocks;
  78. unsigned int blocksize;
  79. };
  80. #define SDH_ISCARDINSERTED(SDH) (SDH->S_PSTATE.CARD_INSERTED && SDH->S_PSTATE.CARD_STABLE)
  81. /*@}*/ /* end of group SDH_EXPORTED_CONSTANTS */
  82. /** @addtogroup SDH_EXPORTED_FUNCTIONS SDH Exported Functions
  83. @{
  84. */
  85. void SDH_DumpReg(SDH_T *sdh);
  86. void SDH_Reset(SDH_T *sdh, uint8_t u8Mask);
  87. int SDH_SetBusWidth(SDH_T *sdh, uint32_t u32BusWidth);
  88. uint32_t SDH_SetClock(SDH_T *sdh, uint32_t u32SrcFreqInHz, uint32_t u32ExceptedFreqInHz);
  89. int SD_GetBusStatus(SDH_T *sdh, uint32_t cmdidx);
  90. void SDH_SetPower(SDH_T *sdh, uint32_t u32OnOff);
  91. /*@}*/ /* end of group SDH_EXPORTED_FUNCTIONS */
  92. /*@}*/ /* end of group SDH_Driver */
  93. /*@}*/ /* end of group Standard_Driver */
  94. #ifdef __cplusplus
  95. }
  96. #endif
  97. #if defined ( __CC_ARM )
  98. #pragma no_anon_unions
  99. #endif
  100. #endif