1 /**************************************************************************//**
\r
4 * @brief M2351 SDH driver header file
\r
6 * @copyright (C) 2017 Nuvoton Technology Corp. All rights reserved.
\r
7 *****************************************************************************/
\r
18 /** @addtogroup Standard_Driver Standard Driver
\r
22 /** @addtogroup SDH_Driver SDH Driver
\r
27 /** @addtogroup SDH_EXPORTED_CONSTANTS SDH Exported Constants
\r
31 #define SDH_ERR_ID 0xFFFF0100UL /*!< SDH error ID \hideinitializer */
\r
33 #define SDH_TIMEOUT (SDH_ERR_ID|0x01UL) /*!< Timeout \hideinitializer */
\r
34 #define SDH_NO_MEMORY (SDH_ERR_ID|0x02UL) /*!< OOM \hideinitializer */
\r
36 /* -- function return value */
\r
37 #define Successful 0U /*!< Success \hideinitializer */
\r
38 #define Fail 1U /*!< Failed \hideinitializer */
\r
40 /* --- define type of SD card or MMC */
\r
41 #define SDH_TYPE_UNKNOWN 0UL /*!< Unknown card type \hideinitializer */
\r
42 #define SDH_TYPE_SD_HIGH 1UL /*!< SDHC card \hideinitializer */
\r
43 #define SDH_TYPE_SD_LOW 2UL /*!< SD card \hideinitializer */
\r
44 #define SDH_TYPE_MMC 3UL /*!< MMC card \hideinitializer */
\r
45 #define SDH_TYPE_EMMC 4UL /*!< eMMC card \hideinitializer */
\r
48 #define SDH_NO_SD_CARD (SDH_ERR_ID|0x10UL) /*!< Card removed \hideinitializer */
\r
49 #define SDH_ERR_DEVICE (SDH_ERR_ID|0x11UL) /*!< Device error \hideinitializer */
\r
50 #define SDH_INIT_TIMEOUT (SDH_ERR_ID|0x12UL) /*!< Card init timeout \hideinitializer */
\r
51 #define SDH_SELECT_ERROR (SDH_ERR_ID|0x13UL) /*!< Card select error \hideinitializer */
\r
52 #define SDH_WRITE_PROTECT (SDH_ERR_ID|0x14UL) /*!< Card write protect \hideinitializer */
\r
53 #define SDH_INIT_ERROR (SDH_ERR_ID|0x15UL) /*!< Card init error \hideinitializer */
\r
54 #define SDH_CRC7_ERROR (SDH_ERR_ID|0x16UL) /*!< CRC 7 error \hideinitializer */
\r
55 #define SDH_CRC16_ERROR (SDH_ERR_ID|0x17UL) /*!< CRC 16 error \hideinitializer */
\r
56 #define SDH_CRC_ERROR (SDH_ERR_ID|0x18UL) /*!< CRC error \hideinitializer */
\r
57 #define SDH_CMD8_ERROR (SDH_ERR_ID|0x19UL) /*!< Command 8 error \hideinitializer */
\r
59 #define MMC_FREQ 20000UL /*!< output 20MHz to MMC \hideinitializer */
\r
60 #define SD_FREQ 25000UL /*!< output 25MHz to SD \hideinitializer */
\r
61 #define SDHC_FREQ 50000UL /*!< output 50MHz to SDH \hideinitializer */
\r
63 #define CardDetect_From_GPIO (1UL << 8) /*!< Card detection pin is GPIO \hideinitializer */
\r
64 #define CardDetect_From_DAT3 (1UL << 9) /*!< Card detection pin is DAT3 \hideinitializer */
\r
66 /*@}*/ /* end of group SDH_EXPORTED_CONSTANTS */
\r
68 /** @addtogroup SDH_EXPORTED_TYPEDEF SDH Exported Type Defines
\r
71 typedef struct SDH_info_t
\r
73 unsigned int CardType; /*!< SDHC, SD, or MMC */
\r
74 unsigned int RCA; /*!< Relative card address */
\r
75 unsigned char IsCardInsert; /*!< Card insert state */
\r
76 unsigned int totalSectorN; /*!< Total sector number */
\r
77 unsigned int diskSize; /*!< Disk size in K bytes */
\r
78 int sectorSize; /*!< Sector size in bytes */
\r
79 } SDH_INFO_T; /*!< Structure holds SD card info */
\r
81 /*@}*/ /* end of group SDH_EXPORTED_TYPEDEF */
\r
83 /** @cond HIDDEN_SYMBOLS */
\r
84 extern SDH_INFO_T SD0;
\r
85 /** @endcond HIDDEN_SYMBOLS */
\r
87 /** @addtogroup SDH_EXPORTED_FUNCTIONS SDH Exported Functions
\r
92 * @brief Enable specified interrupt.
\r
94 * @param[in] sdh The pointer of the specified SDH module.
\r
95 * @param[in] u32IntMask Interrupt type mask:
\r
96 * \ref SDH_INTEN_BLKDIEN_Msk / \ref SDH_INTEN_CRCIEN_Msk / \ref SDH_INTEN_CDIEN_Msk /
\r
97 * \ref SDH_INTEN_CDSRC_Msk / \ref SDH_INTEN_RTOIEN_Msk / \ref SDH_INTEN_DITOIEN_Msk /
\r
98 * \ref SDH_INTEN_WKIEN_Msk
\r
103 #define SDH_ENABLE_INT(sdh, u32IntMask) ((sdh)->INTEN |= (u32IntMask))
\r
106 * @brief Disable specified interrupt.
\r
108 * @param[in] sdh The pointer of the specified SDH module.
\r
109 * @param[in] u32IntMask Interrupt type mask:
\r
110 * \ref SDH_INTEN_BLKDIEN_Msk / \ref SDH_INTEN_CRCIEN_Msk / \ref SDH_INTEN_CDIEN_Msk /
\r
111 * \ref SDH_INTEN_RTOIEN_Msk / \ref SDH_INTEN_DITOIEN_Msk / \ref SDH_INTEN_WKIEN_Msk / \ref SDH_INTEN_CDSRC_Msk /
\r
116 #define SDH_DISABLE_INT(sdh, u32IntMask) ((sdh)->INTEN &= ~(u32IntMask))
\r
119 * @brief Get specified interrupt flag/status.
\r
121 * @param[in] sdh The pointer of the specified SDH module.
\r
122 * @param[in] u32IntMask Interrupt type mask:
\r
123 * \ref SDH_INTSTS_BLKDIF_Msk / \ref SDH_INTSTS_CRCIF_Msk / \ref SDH_INTSTS_CRC7_Msk /
\r
124 * \ref SDH_INTSTS_CRC16_Msk / \ref SDH_INTSTS_CRCSTS_Msk / \ref SDH_INTSTS_DAT0STS_Msk /
\r
125 * \ref SDH_INTSTS_CDIF_Msk / \ref SDH_INTSTS_RTOIF_Msk /
\r
126 * \ref SDH_INTSTS_DITOIF_Msk / \ref SDH_INTSTS_CDSTS_Msk /
\r
127 * \ref SDH_INTSTS_DAT1STS_Msk
\r
130 * @return 0 = The specified interrupt is not happened.
\r
131 * 1 = The specified interrupt is happened.
\r
134 #define SDH_GET_INT_FLAG(sdh, u32IntMask) (((sdh)->INTSTS & (u32IntMask))?1:0)
\r
138 * @brief Clear specified interrupt flag/status.
\r
140 * @param[in] sdh The pointer of the specified SDH module.
\r
141 * @param[in] u32IntMask Interrupt type mask:
\r
142 * \ref SDH_INTSTS_BLKDIF_Msk / \ref SDH_INTSTS_CRCIF_Msk / \ref SDH_INTSTS_CDIF_Msk /
\r
143 * \ref SDH_INTSTS_RTOIF_Msk / \ref SDH_INTSTS_DITOIF_Msk
\r
149 #define SDH_CLR_INT_FLAG(sdh, u32IntMask) ((sdh)->INTSTS = (u32IntMask))
\r
153 * @brief Check SD Card inserted or removed.
\r
155 * @param[in] sdh The pointer of the specified SDH module.
\r
157 * @return 1: Card inserted.
\r
161 #define SDH_IS_CARD_PRESENT(sdh) ((((sdh) == SDH0)||((sdh) == SDH0_NS))? SD0.IsCardInsert : 0)
\r
164 * @brief Get SD Card capacity.
\r
166 * @param[in] sdh The pointer of the specified SDH module.
\r
168 * @return SD Card capacity. (unit: KByte)
\r
171 #define SDH_GET_CARD_CAPACITY(sdh) ((((sdh) == SDH0)||((sdh) == SDH0_NS))? SD0.diskSize : 0)
\r
174 void SDH_Open(SDH_T *sdh, uint32_t u32CardDetSrc);
\r
175 uint32_t SDH_Probe(SDH_T *sdh);
\r
176 uint32_t SDH_Read(SDH_T *sdh, uint8_t *pu8BufAddr, uint32_t u32StartSec, uint32_t u32SecCount);
\r
177 uint32_t SDH_Write(SDH_T *sdh, uint8_t *pu8BufAddr, uint32_t u32StartSec, uint32_t u32SecCount);
\r
179 uint32_t SDH_CardDetection(SDH_T *sdh);
\r
180 void SDH_Open_Disk(SDH_T *sdh, uint32_t u32CardDetSrc);
\r
181 void SDH_Close_Disk(SDH_T *sdh);
\r
183 /*@}*/ /* end of group SDH_EXPORTED_FUNCTIONS */
\r
185 /*@}*/ /* end of group SDH_Driver */
\r
187 /*@}*/ /* end of group Standard_Driver */
\r
193 #endif /* end of __SDH_H__ */
\r
194 /*** (C) COPYRIGHT 2017 Nuvoton Technology Corp. ***/
\r