| M480 BSP V3.05.001 The Board Support Package for M480 Series

sdh.h
Go to the documentation of this file.
1 /**************************************************************************/
9 #include <stdio.h>
10
11 #ifndef __SDH_H__
12 #define __SDH_H__
13
14 #ifdef __cplusplus
15 extern "C"
16 {
17 #endif
18
19
33 #define SDH_ERR_ID 0xFFFF0100ul
35 #define SDH_TIMEOUT (SDH_ERR_ID|0x01ul)
36 #define SDH_NO_MEMORY (SDH_ERR_ID|0x02ul)
38 /*-- function return value */
39 #define Successful 0ul
40 #define Fail 1ul
42 /*--- define type of SD card or MMC */
43 #define SDH_TYPE_UNKNOWN 0ul
44 #define SDH_TYPE_SD_HIGH 1ul
45 #define SDH_TYPE_SD_LOW 2ul
46 #define SDH_TYPE_MMC 3ul
47 #define SDH_TYPE_EMMC 4ul
49 /* SD error */
50 #define SDH_NO_SD_CARD (SDH_ERR_ID|0x10ul)
51 #define SDH_ERR_DEVICE (SDH_ERR_ID|0x11ul)
52 #define SDH_INIT_TIMEOUT (SDH_ERR_ID|0x12ul)
53 #define SDH_SELECT_ERROR (SDH_ERR_ID|0x13ul)
54 #define SDH_WRITE_PROTECT (SDH_ERR_ID|0x14ul)
55 #define SDH_INIT_ERROR (SDH_ERR_ID|0x15ul)
56 #define SDH_CRC7_ERROR (SDH_ERR_ID|0x16ul)
57 #define SDH_CRC16_ERROR (SDH_ERR_ID|0x17ul)
58 #define SDH_CRC_ERROR (SDH_ERR_ID|0x18ul)
59 #define SDH_CMD8_ERROR (SDH_ERR_ID|0x19ul)
61 #define MMC_FREQ 20000ul
62 #define SD_FREQ 25000ul
63 #define SDHC_FREQ 50000ul
65 #define SD_PORT0 (1 << 0)
66 #define SD_PORT1 (1 << 2)
67 #define CardDetect_From_GPIO (1ul << 8)
68 #define CardDetect_From_DAT3 (1ul << 9)
70 /* end of group SDH_EXPORTED_CONSTANTS */
71
75 typedef struct SDH_info_t
76 {
77 unsigned char IsCardInsert;
78 unsigned char R3Flag;
79 unsigned char R7Flag;
80 unsigned char volatile DataReadyFlag;
81 unsigned int CardType;
82 unsigned int RCA;
83 unsigned int totalSectorN;
84 unsigned int diskSize;
85 int sectorSize;
86 unsigned char *dmabuf;
87 } SDH_INFO_T;
89 /* end of group SDH_EXPORTED_TYPEDEF */
90
92 extern SDH_INFO_T SD0, SD1;
111 #define SDH_ENABLE_INT(sdh, u32IntMask) ((sdh)->INTEN |= (u32IntMask))
112
124 #define SDH_DISABLE_INT(sdh, u32IntMask) ((sdh)->INTEN &= ~(u32IntMask))
125
142 #define SDH_GET_INT_FLAG(sdh, u32IntMask) (((sdh)->INTSTS & (u32IntMask))?1:0)
143
144
157 #define SDH_CLR_INT_FLAG(sdh, u32IntMask) ((sdh)->INTSTS = (u32IntMask))
158
159
169 #define SDH_IS_CARD_PRESENT(sdh) (((sdh) == SDH0)? SD0.IsCardInsert : SD1.IsCardInsert)
170
179 #define SDH_GET_CARD_CAPACITY(sdh) (((sdh) == SDH0)? SD0.diskSize : SD1.diskSize)
180
181
182 void SDH_Open(SDH_T *sdh, uint32_t u32CardDetSrc);
183 uint32_t SDH_Probe(SDH_T *sdh);
184 uint32_t SDH_Read(SDH_T *sdh, uint8_t *pu8BufAddr, uint32_t u32StartSec, uint32_t u32SecCount);
185 uint32_t SDH_Write(SDH_T *sdh, uint8_t *pu8BufAddr, uint32_t u32StartSec, uint32_t u32SecCount);
186
187 uint32_t SDH_CardDetection(SDH_T *sdh);
188 void SDH_Open_Disk(SDH_T *sdh, uint32_t u32CardDetSrc);
189 void SDH_Close_Disk(SDH_T *sdh);
190
191 /* end of group SDH_EXPORTED_FUNCTIONS */
193 /* end of group SDH_Driver */
195 /* end of group Standard_Driver */
197
198 #ifdef __cplusplus
199 }
200 #endif
201
202 #endif /* __SDH_H__ */
203 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
SDH_info_t::CardType
unsigned int CardType
Definition: sdh.h:81
SDH_info_t::DataReadyFlag
unsigned char volatile DataReadyFlag
Definition: sdh.h:80
SDH_info_t::totalSectorN
unsigned int totalSectorN
Definition: sdh.h:83
SDH_Read
uint32_t SDH_Read(SDH_T *sdh, uint8_t *pu8BufAddr, uint32_t u32StartSec, uint32_t u32SecCount)
This function use to read data from SD card.
Definition: sdh.c:995
SDH_info_t::dmabuf
unsigned char * dmabuf
Definition: sdh.h:86
SDH_Probe
uint32_t SDH_Probe(SDH_T *sdh)
This function use to initial SD card.
Definition: sdh.c:945
SDH_info_t::RCA
unsigned int RCA
Definition: sdh.h:82
SDH_Open_Disk
void SDH_Open_Disk(SDH_T *sdh, uint32_t u32CardDetSrc)
SDH_Write
uint32_t SDH_Write(SDH_T *sdh, uint8_t *pu8BufAddr, uint32_t u32StartSec, uint32_t u32SecCount)
This function use to write data to SD card.
Definition: sdh.c:1142
SDH_info_t::IsCardInsert
unsigned char IsCardInsert
Definition: sdh.h:77
SDH_info_t
Definition: sdh.h:75
SDH_info_t::diskSize
unsigned int diskSize
Definition: sdh.h:84
SDH_info_t::sectorSize
int sectorSize
Definition: sdh.h:85
SDH_T
Definition: sdh_reg.h:26
SDH_INFO_T
struct SDH_info_t SDH_INFO_T
SDH_info_t::R3Flag
unsigned char R3Flag
Definition: sdh.h:78
SDH_Open
void SDH_Open(SDH_T *sdh, uint32_t u32CardDetSrc)
This function use to reset SD function and select card detection source and pin.
Definition: sdh.c:886
SDH_info_t::R7Flag
unsigned char R7Flag
Definition: sdh.h:79
SDH_CardDetection
uint32_t SDH_CardDetection(SDH_T *sdh)
SDH_Close_Disk
void SDH_Close_Disk(SDH_T *sdh)