| NUC472_NUC442_BSP V3.04.000 The Board Support Package for NUC472/NUC442

sd.h
Go to the documentation of this file.
1/**************************************************************************/
12#include <stdio.h>
13
14#ifndef __SD_H__
15#define __SD_H__
16
30#define SD_CARD 0
31#define SD_ERR_ID 0xFFFF0100
32
33#define SD_TIMEOUT (SD_ERR_ID|0x01)
34#define SD_NO_MEMORY (SD_ERR_ID|0x02)
35
36//-- function return value
37#define Successful 0
38#define Fail 1
39
40//--- define type of SD card or MMC
41#define SD_TYPE_UNKNOWN 0
42#define SD_TYPE_SD_HIGH 1
43#define SD_TYPE_SD_LOW 2
44#define SD_TYPE_MMC 3
45#define SD_TYPE_EMMC 4
46
47/* SD error */
48#define SD_NO_SD_CARD (SD_ERR_ID|0x10)
49#define SD_ERR_DEVICE (SD_ERR_ID|0x11)
50#define SD_INIT_TIMEOUT (SD_ERR_ID|0x12)
51#define SD_SELECT_ERROR (SD_ERR_ID|0x13)
52#define SD_WRITE_PROTECT (SD_ERR_ID|0x14)
53#define SD_INIT_ERROR (SD_ERR_ID|0x15)
54#define SD_CRC7_ERROR (SD_ERR_ID|0x16)
55#define SD_CRC16_ERROR (SD_ERR_ID|0x17)
56#define SD_CRC_ERROR (SD_ERR_ID|0x18)
57#define SD_CMD8_ERROR (SD_ERR_ID|0x19)
58
59#define SD_FREQ 12000
60#define SDHC_FREQ 12000
61
62#define STOR_STRING_LEN 32
63
64#define SD_PORT0 (1 << 0)
65#define SD_PORT1 (1 << 2)
67#define CardDetect_From_GPIO (1 << 8)
68#define CardDetect_From_DAT3 (1 << 9) /* end of group NUC472_442_SD_EXPORTED_CONSTANTS */
71
75 typedef struct SD_info_t
76{
77 uint32_t CardType;
78 uint32_t RCA;
79 uint8_t IsCardInsert;
80} SD_INFO_T;
81
82/* we allocate one of these for every device that we remember */
83 typedef struct disk_data_t
84{
85 struct disk_data_t *next;
87 /* information about the device -- always good */
88 unsigned int totalSectorN;
89 unsigned int diskSize;
90 int sectorSize;
91 char vendor[STOR_STRING_LEN];
92 char product[STOR_STRING_LEN];
93 char serial[STOR_STRING_LEN];
94} DISK_DATA_T;
95 /* end of group NUC472_442_SD_EXPORTED_TYPEDEF */
97
99extern SD_INFO_T SD0;
100extern SD_INFO_T SD1;
102
121#define SD_ENABLE_INT(u32IntMask) (SD->INTEN |= (u32IntMask))
122
134#define SD_DISABLE_INT(u32IntMask) (SD->INTEN &= ~(u32IntMask))
135
150#define SD_GET_INT_FLAG(u32IntMask) ((SD->INTSTS & (u32IntMask))?1:0)
151
152
165#define SD_CLR_INT_FLAG(u32IntMask) (SD->INTSTS = u32IntMask)
166
167
177#define SD_IS_CARD_PRESENT(u32CardNum) ((u32CardNum & (SD_PORT0))?(SD0.IsCardInsert):(SD1.IsCardInsert))
178
187#define SD_GET_CARD_CAPACITY(u32CardNum) ((u32CardNum & (SD_PORT0))?(SD_DiskInfo0.diskSize):(SD_DiskInfo1.diskSize))
188
189
190void SD_Open(uint32_t u32CardDetSrc);
191void SD_Probe(uint32_t u32CardNum);
192uint32_t SD_Read(uint32_t u32CardNum, uint8_t *pu8BufAddr, uint32_t u32StartSec, uint32_t u32SecCount);
193uint32_t SD_Write(uint32_t u32CardNum, uint8_t *pu8BufAddr, uint32_t u32StartSec, uint32_t u32SecCount);
194
195
196 /* end of group NUC472_442_ADC_EXPORTED_FUNCTIONS */
198 /* end of group NUC472_442_ADC_Driver */
200 /* end of group NUC472_442_Device_Driver */
202
203#endif //end of __SD_H__
204/*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
STOR_STRING_LEN
#define STOR_STRING_LEN
Definition: sd.h:62
disk_data_t::diskSize
unsigned int diskSize
Definition: sd.h:89
SD_Read
uint32_t SD_Read(uint32_t u32CardNum, uint8_t *pu8BufAddr, uint32_t u32StartSec, uint32_t u32SecCount)
This function use to read data from SD card.
Definition: sd.c:901
disk_data_t::serial
char serial[STOR_STRING_LEN]
Definition: sd.h:93
disk_data_t::next
struct disk_data_t * next
Definition: sd.h:85
disk_data_t::vendor
char vendor[STOR_STRING_LEN]
Definition: sd.h:91
disk_data_t::product
char product[STOR_STRING_LEN]
Definition: sd.h:92
disk_data_t::totalSectorN
unsigned int totalSectorN
Definition: sd.h:88
SD_Write
uint32_t SD_Write(uint32_t u32CardNum, uint8_t *pu8BufAddr, uint32_t u32StartSec, uint32_t u32SecCount)
This function use to write data to SD card.
Definition: sd.c:1077
disk_data_t::sectorSize
int sectorSize
Definition: sd.h:90
SD_info_t::RCA
uint32_t RCA
Definition: sd.h:78
SD_Open
void SD_Open(uint32_t u32CardDetSrc)
This function use to reset SD function and select card detection source and pin.
Definition: sd.c:764
SD_info_t::IsCardInsert
uint8_t IsCardInsert
Definition: sd.h:79
SD_info_t::CardType
uint32_t CardType
Definition: sd.h:77
SD_Probe
void SD_Probe(uint32_t u32CardNum)
This function use to initial SD card.
Definition: sd.c:837
SD_INFO_T
struct SD_info_t SD_INFO_T
DISK_DATA_T
struct disk_data_t DISK_DATA_T
SD_info_t
Definition: sd.h:76
disk_data_t
Definition: sd.h:84