Nano100AN Series BSP  V3.02.002
The Board Support Package for Nano100AN Series
SDCard.h
Go to the documentation of this file.
1 /****************************************************************************/
12 #ifndef __SDCARD_H__
13 #define __SDCARD_H__
14 
15 #include "Nano100Series.h"
16 
17 #ifdef __cplusplus
18 extern "C"
19 {
20 #endif
21 
34 #define DBG_PRINTF(...)
35 //#define DBG_PRINTF printf
37 #define PHYSICAL_BLOCK_SIZE 512
39 // Command table value definitions
40 // Used in the MMC_Command_Exec function to
41 // decode and execute MMC command requests
42 #define EMPTY 0
43 #define YES 1
44 #define NO 0
45 #define CMD 0
46 #define RD 1
47 #define WR 2
48 #define RDB 3
49 #define WDB 4
50 #define R1 0
51 #define R1b 1
52 #define R2 2
53 #define R3 3
54 #define R7 4
56 // Start and stop data tokens for single and multiple
57 // block MMC data operations
58 #define START_SBR 0xFE
59 #define START_MBR 0xFE
60 #define START_SBW 0xFE
61 #define START_MBW 0xFC
62 #define STOP_MBW 0xFD
64 // Mask for data response Token after an MMC write
65 #define DATA_RESP_MASK 0x11
67 // Mask for busy Token in R1b response
68 #define BUSY_BIT 0x80
70 #define BACK_FROM_ERROR { SingleWrite(0xFF); SPI_SET_SS0_HIGH(SPI1); return FALSE;}
72 typedef union // byte-addressable unsigned long
73 {
74  uint32_t l;
75  uint8_t b[4];
76 } UINT32;
77 typedef union // byte-addressable unsigned int
78 {
79  uint16_t i;
80  uint8_t b[2];
81 } UINT16;
82 
83 #define SD_SUCCESS (0)
84 #define SD_FAIL (1)
86 // Command Table Index Constants:
87 // Definitions for each table entry in the command table.
88 // These allow the MMC_Command_Exec function to be called with a
89 // meaningful parameter rather than a number.
90 #define SDv1 1<<1
91 #define SDv2 1<<2
92 #define MMCv3 1<<3
93 #define SDBlock 1<<4
95 #define GO_IDLE_STATE 0
96 #define SEND_OP_COND 1
97 #define SEND_IF_COND 2
98 #define SEND_CSD 3
99 #define SEND_CID 4
100 #define STOP_TRANSMISSION 5
101 #define SEND_STATUS 6
102 #define SET_BLOCKLEN 7
103 #define READ_SINGLE_BLOCK 8
104 #define READ_MULTIPLE_BLOCK 9
105 #define SET_BLOCK_COUNT 10
106 #define WRITE_BLOCK 11
107 #define WRITE_MULTIPLE_BLOCK 12
108 #define PROGRAM_CSD 13
109 #define SET_WRITE_PROT 14
110 #define CLR_WRITE_PROT 15
111 #define SEND_WRITE_PROT 16
112 #define TAG_SECTOR_START 17
113 #define TAG_SECTOR_END 18
114 #define UNTAG_SECTOR 19
115 #define TAG_ERASE_GROUP_START 20
116 #define TAG_ERASE_GROUP_END 21
117 #define UNTAG_ERASE_GROUP 22
118 #define ERASE 23
119 #define LOCK_UNLOCK 24
120 #define APP_CMD 25
121 #define READ_OCR 26
122 #define CRC_ON_OFF 27
123 #define SD_SEND_STATUS 28
124 #define SD_SET_WR_BLK_ERASE_COUNT 29
125 #define SD_SEND_OP_COND 30
126  /* end of group NANO100_SDCARD_EXPORTED_CONSTANTS */
127 
131 // This structure defines entries into the command table;
132 typedef struct
133 {
134  uint8_t command_byte;
135  uint8_t arg_required;
136  uint8_t CRC;
137  uint8_t trans_type;
138  uint8_t response;
139  uint8_t var_length;
140 } COMMAND; /* end of group NANO100_SDCARD_EXPORTED_STRUCTS */
142 
146 uint32_t SDCARD_Open(void);
147 void SDCARD_Close(void);
148 uint32_t SDCARD_GetVersion(void);
149 uint32_t MMC_Command_Exec (uint8_t cmd_loc, uint32_t argument,uint8_t *pchar, uint32_t* response);
150 uint32_t GetLogicSector(void);
151 uint32_t SDCARD_GetCardSize(uint32_t* pu32TotSecCnt);
152 void SpiRead(uint32_t addr, uint32_t size, uint8_t* buffer);
153 void SpiWrite(uint32_t addr, uint32_t size, uint8_t* buffer);
154  /* end of group NANO100_SDCARD_EXPORTED_FUNCTIONS */
156 
157  /* end of group NANO100_SDCARD */
159  /* end of group NANO100_Library */
161 
162 #ifdef __cplusplus
163 }
164 #endif
165 
166 #endif
167 
168 /*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/
169 
170 
171 
void SDCARD_Close(void)
This function is used to close SDCARD.
Definition: SDCard.c:615
Definition: SDCard.h:72
uint32_t SDCARD_Open(void)
This function is used to Open GPIO function and initial SDCARD.
Definition: SDCard.c:584
void SpiRead(uint32_t addr, uint32_t size, uint8_t *buffer)
This function is used to Get data from SD card.
Definition: SDCard.c:652
Nano100 series peripheral access layer header file. This file contains all the peripheral register's ...
uint32_t SDCARD_GetCardSize(uint32_t *pu32TotSecCnt)
This function is used to get card total sector after SDCARD is opened.
Definition: SDCard.c:626
void SpiWrite(uint32_t addr, uint32_t size, uint8_t *buffer)
This function is used to store data into SD card.
Definition: SDCard.c:687
uint32_t SDCARD_GetVersion(void)
uint32_t GetLogicSector(void)
This function is used to get logic sector size.
Definition: SDCard.c:640
uint8_t trans_type
Definition: SDCard.h:137
uint8_t command_byte
Definition: SDCard.h:134
uint8_t arg_required
Definition: SDCard.h:135
uint8_t CRC
Definition: SDCard.h:136
uint16_t i
Definition: SDCard.h:79
uint32_t MMC_Command_Exec(uint8_t nCmd, uint32_t nArg, uint8_t *pchar, uint32_t *response)
This function is used to Send SDCARD CMD and Receive Response.
Definition: SDCard.c:140
uint8_t response
Definition: SDCard.h:138
uint32_t l
Definition: SDCard.h:74
Definition: SDCard.h:77
uint8_t var_length
Definition: SDCard.h:139