1 ////////////////////////////////////////////////////////////////////////////////
2 /// @file     hal_gpio.h
3 /// @author   AE TEAM
4 /// @brief    THIS FILE CONTAINS ALL THE FUNCTIONS PROTOTYPES FOR THE GPIO
5 ///           FIRMWARE LIBRARY.
6 ////////////////////////////////////////////////////////////////////////////////
7 /// @attention
8 ///
9 /// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
10 /// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
11 /// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
12 /// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
13 /// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
14 /// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
15 ///
16 /// <H2><CENTER>&COPY; COPYRIGHT MINDMOTION </CENTER></H2>
17 ////////////////////////////////////////////////////////////////////////////////
18 
19 // Define to prevent recursive inclusion
20 #ifndef __HAL_SDIO_H
21 #define __HAL_SDIO_H
22 
23 // Files includes
24 #include "mm32_reg.h"
25 
26 
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 ////////////////////////////////////////////////////////////////////////////////
32 /// @addtogroup MM32_Hardware_Abstract_Layer
33 /// @{
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// @defgroup GPIO_HAL
37 /// @brief GPIO HAL modules
38 /// @{
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// @defgroup GPIO_Exported_Types
42 /// @{
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// @brief  Output Maximum frequency selection
46 ////////////////////////////////////////////////////////////////////////////////
47 #define SDIO_FLAG_CCRCFAIL                  ((u32)0x00000001)
48 #define SDIO_FLAG_DCRCFAIL                  ((u32)0x00000002)
49 #define SDIO_FLAG_CTIMEOUT                  ((u32)0x00000004)
50 #define SDIO_FLAG_DTIMEOUT                  ((u32)0x00000008)
51 #define SDIO_FLAG_TXUNDERR                  ((u32)0x00000010)
52 #define SDIO_FLAG_RXOVERR                   ((u32)0x00000020)
53 #define SDIO_FLAG_CMDREND                   ((u32)0x00000040)
54 #define SDIO_FLAG_CMDSENT                   ((u32)0x00000080)
55 #define SDIO_FLAG_DATAEND                   ((u32)0x00000100)
56 #define SDIO_FLAG_STBITERR                  ((u32)0x00000200)
57 #define SDIO_FLAG_DBCKEND                   ((u32)0x00000400)
58 #define SDIO_FLAG_CMDACT                    ((u32)0x00000800)
59 #define SDIO_FLAG_TXACT                     ((u32)0x00001000)
60 #define SDIO_FLAG_RXACT                     ((u32)0x00002000)
61 #define SDIO_FLAG_TXFIFOHE                  ((u32)0x00004000)
62 #define SDIO_FLAG_RXFIFOHF                  ((u32)0x00008000)
63 #define SDIO_FLAG_TXFIFOF                   ((u32)0x00010000)
64 #define SDIO_FLAG_RXFIFOF                   ((u32)0x00020000)
65 #define SDIO_FLAG_TXFIFOE                   ((u32)0x00040000)
66 #define SDIO_FLAG_RXFIFOE                   ((u32)0x00080000)
67 #define SDIO_FLAG_TXDAVL                    ((u32)0x00100000)
68 #define SDIO_FLAG_RXDAVL                    ((u32)0x00200000)
69 #define SDIO_FLAG_SDIOIT                    ((u32)0x00400000)
70 #define SDIO_FLAG_CEATAEND                  ((u32)0x00800000)
71 
72 
73 
74 ////////////////////////////////////////////////////////////////////////////////////////////////////
75 //SDIO working mode define ,SDIO working mode definition, set through the SD_SetDevice Mode function.
76 #define SD_POLLING_MODE     0                                                                      /// Query mode. In this mode, it is recommended to increase the setting of SDIO_TRANSFER_CLK_DIV if there are problems with reading and writing.
77 #define SD_DMA_MODE         1                                                                      /// In DMA mode, it is recommended to increase the setting of SDIO_TRANSFER_CLK_DIV if there are problems with reading and writing.
78 
79 ////////////////////////////////////////////////////////////////////////////////
80 /// @brief  SDIO Various error enumeration definitions
81 ////////////////////////////////////////////////////////////////////////////////
82 
83 typedef enum {
84     SD_CMD_CRC_FAIL = 1,                                                                    ///< Command response received (but CRC check failed)
85     SD_DATA_CRC_FAIL,                                                                       ///< Data bock sent/received (CRC check Failed)
86     SD_CMD_RSP_TIMEOUT,                                                                     ///< Command response timeout
87     SD_DATA_TIMEOUT,                                                                        ///< Data time out
88     SD_TX_UNDERRUN,                                                                         ///< Transmit FIFO under-run
89     SD_RX_OVERRUN,                                                                          ///< Receive FIFO over-run
90     SD_START_BIT_ERR,                                                                       ///< Start bit not detected on all data signals in widE bus mode
91     SD_CMD_OUT_OF_RANGE,                                                                    ///< CMD's argument was out of range.
92     SD_ADDR_MISALIGNED,                                                                     ///< Misaligned address
93     SD_BLOCK_LEN_ERR,                                                                       ///< Transferred block length is not allowed for the card or the number of transferred bytes does not match the block length
94     SD_ERASE_SEQ_ERR,                                                                       ///< An error in the sequence of erase command occurs.
95     SD_BAD_ERASE_PARAM,                                                                     ///< An Invalid selection for erase groups
96     SD_WRITE_PROT_VIOLATION,                                                                ///< Attempt to program a write protect block
97     SD_LOCK_UNLOCK_FAILED,                                                                  ///< Sequence or password error has been detected in unlock command or if there was an attempt to access a locked card
98     SD_COM_CRC_FAILED,                                                                      ///< CRC check of the previous command failed
99     SD_ILLEGAL_CMD,                                                                         ///< Command is not legal for the card state
100     SD_CARD_ECC_FAILED,                                                                     ///< Card internal ECC was applied but failed to correct the data
101     SD_CC_ERROR,                                                                            ///< Internal card controller error
102     SD_GENERAL_UNKNOWN_ERROR,                                                               ///< General or Unknown error
103     SD_STREAM_READ_UNDERRUN,                                                                ///< The card could not sustain data transfer in stream read operation.
104     SD_STREAM_WRITE_OVERRUN,                                                                ///< The card could not sustain data programming in stream mode
105     SD_CID_CSD_OVERWRITE,                                                                   ///< CID/CSD overwrite error
106     SD_WP_ERASE_SKIP,                                                                       ///< only partial address space was erased
107     SD_CARD_ECC_DISABLED,                                                                   ///< Command has been executed without using internal ECC
108     SD_ERASE_RESET,                                                                         ///< Erase sequence was cleared before executing because an out of erase sequence command was received
109     SD_AKE_SEQ_ERROR,                                                                       ///< Error in sequence of authentication.
110     SD_INVALID_VOLTRANGE,                                                                   ///< SD invalid voltage range,
111     SD_ADDR_OUT_OF_RANGE,                                                                   ///< SD addresses are out of range,
112     SD_SWITCH_ERROR,                                                                        ///< SD switch error,
113     SD_SDIO_DISABLED,                                                                       ///< SD SDIO disability,
114     SD_SDIO_FUNCTION_BUSY,                                                                  ///< SD SDIO function busy,
115     SD_SDIO_FUNCTION_FAILED,                                                                ///< SD SDIO failed,
116     SD_SDIO_UNKNOWN_FUNCTION,                                                               ///< SDIO unknown function,
117     SD_INTERNAL_ERROR,                                                                      ///< SD internal error,
118     SD_NOT_CONFIGURED,                                                                      ///< SD is not configured,
119     SD_REQUEST_PENDING,                                                                     ///< The SD request waits,
120     SD_REQUEST_NOT_APPLICABLE,                                                              ///< The SD requirement does not apply,
121     SD_INVALID_PARAMETER,                                                                   ///< Invalid SD parameter,
122     SD_UNSUPPORTED_FEATURE,                                                                 ///< Features not supported by SD,
123     SD_UNSUPPORTED_HW,                                                                      ///< HW not supported by SD,
124     SD_ERROR,                                                                               ///< SD error
125     SD_OK = 0                                                                               ///< SD OK
126 } SD_Error;
127 ////////////////////////////////////////////////////////////////////////////////
128 /// @brief  SD card CSD register data
129 ////////////////////////////////////////////////////////////////////////////////
130 typedef struct {
131     u8  CSDStruct;                                                                                ///< CSD structure
132     u8  SysSpecVersion;                                                                           ///< System specification version
133     u8  Reserved1;                                                                                ///< Reserved
134     u8  TAAC;                                                                                     ///< Data read access-time 1
135     u8  NSAC;                                                                                     ///< Data read access-time 2 in CLK cycles
136     u8  MaxBusClkFrec;                                                                            ///< Max. bus clock frequency
137     u16 CardComdClasses;                                                                          ///< Card command classes
138     u8  RdBlockLen;                                                                               ///< Max. read data block length
139     u8  PartBlockRead;                                                                            ///< Partial blocks for read allowed
140     u8  WrBlockMisalign;                                                                          ///< Write block misalignment
141     u8  RdBlockMisalign;                                                                          ///< Read block misalignment
142     u8  DSRImpl;                                                                                  ///< DSR implemented
143     u8  Reserved2;                                                                                ///< Reserved
144     u32 DeviceSize;                                                                               ///< Device Size
145     u8  MaxRdCurrentVDDMin;                                                                       ///< Max. read current @ VDD min
146     u8  MaxRdCurrentVDDMax;                                                                       ///< Max. read current @ VDD max
147     u8  MaxWrCurrentVDDMin;                                                                       ///< Max. write current @ VDD min
148     u8  MaxWrCurrentVDDMax;                                                                       ///< Max. write current @ VDD max
149     u8  DeviceSizeMul;                                                                            ///< Device size multiplier
150     u8  EraseGrSize;                                                                              ///< Erase group size
151     u8  EraseGrMul;                                                                               ///< Erase group size multiplier
152     u8  WrProtectGrSize;                                                                          ///< Write protect group size
153     u8  WrProtectGrEnable;                                                                        ///< Write protect group enable
154     u8  ManDeflECC;                                                                               ///< Manufacturer default ECC
155     u8  WrSpeedFact;                                                                              ///< Write speed factor
156     u8  MaxWrBlockLen;                                                                            ///< Max. write data block length
157     u8  WriteBlockPaPartial;                                                                      ///< Partial blocks for write allowed
158     u8  Reserved3;                                                                                ///< Reserded
159     u8  ContentProtectAppli;                                                                      ///< Content protection application
160     u8  FileFormatGrouop;                                                                         ///< File format group
161     u8  CopyFlag;                                                                                 ///< Copy flag (OTP)
162     u8  PermWrProtect;                                                                            ///< Permanent write protection
163     u8  TempWrProtect;                                                                            ///< Temporary write protection
164     u8  FileFormat;                                                                               ///< File Format
165     u8  ECC;                                                                                      ///< ECC code
166     u8  CSD_CRC;                                                                                  ///< CSD CRC
167     u8  Reserved4;                                                                                ///< always 1
168 } SD_CSD;
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 /// @brief  SD card CID register data
172 ////////////////////////////////////////////////////////////////////////////////
173 typedef struct {
174     u8  ManufacturerID;                                                                           ///< ManufacturerID
175     u16 OEM_AppliID;                                                                              ///< OEM/Application ID
176     u32 ProdName1;                                                                                ///< Product Name part1
177     u8  ProdName2;                                                                                ///< Product Name part2
178     u8  ProdRev;                                                                                  ///< Product Revision
179     u32 ProdSN;                                                                                   ///< Product Serial Number
180     u8  Reserved1;                                                                                ///< Reserved1
181     u16 ManufactDate;                                                                             ///< Manufacturing Date
182     u8  CID_CRC;                                                                                  ///< CID CRC
183     u8  Reserved2;                                                                                ///< always 1
184 } SD_CID;
185 ////////////////////////////////////////////////////////////////////////////////
186 /// @brief  SD state
187 ////////////////////////////////////////////////////////////////////////////////
188 typedef enum {
189     SD_CARD_READY                  = ((u32)0x00000001),
190     SD_CARD_IDENTIFICATION         = ((u32)0x00000002),
191     SD_CARD_STANDBY                = ((u32)0x00000003),
192     SD_CARD_TRANSFER               = ((u32)0x00000004),
193     SD_CARD_SENDING                = ((u32)0x00000005),
194     SD_CARD_RECEIVING              = ((u32)0x00000006),
195     SD_CARD_PROGRAMMING            = ((u32)0x00000007),
196     SD_CARD_DISCONNECTED           = ((u32)0x00000008),
197     SD_CARD_ERROR                  = ((u32)0x000000FF)
198 } SDCardState;
199 
200 ////////////////////////////////////////////////////////////////////////////////
201 /// @brief  SD message ,include CSD,CID data
202 ////////////////////////////////////////////////////////////////////////////////
203 typedef struct {
204     SD_CSD SD_csd;
205     SD_CID SD_cid;
206     long long CardCapacity;
207     u32 CardBlockSize;
208     u16 RCA;
209     u8 CardType;
210 } SD_CardInfo;
211 ////////////////////////////////////////////////////////////////////////////////
212 /// @brief  SDIO init
213 ////////////////////////////////////////////////////////////////////////////////
214 typedef struct {
215     u8 SDIO_MDEN;
216     u8 SDIO_DATWT;
217     u8 SDIO_SelPTSM;
218     u8 SDIO_CLKSP;
219     u8 SDIO_OUTM;
220     u8 SDIO_SelSM;
221     u8 SDIO_OPMSel;
222 } SDIO_InitTypeDef;
223 
224 typedef struct {
225     u32 SDIO_Argument;  ///Specifies the SDIO command argument which is sent
226     ///to a card as part of a command message. If a command
227     ///contains an argument, it must be loaded into this register
228     ///before writing the command to the command register
229 
230     u32 SDIO_CmdIndex;  ///Specifies the SDIO command index. It must be lower than 0x40.
231 
232     u32 SDIO_Response;  ///Specifies the SDIO response type.
233     ///This parameter can be a value of @ref SDIO_Response_Type
234 
235     u32 SDIO_Wait;      ///Specifies whether SDIO wait-for-interrupt request is enabled or disabled.
236     ///This parameter can be a value of @ref SDIO_Wait_Interrupt_State
237 
238 ///    u32 SDIO_CPSM;      ///Specifies whether SDIO Command path state machine (CPSM)
239     ///is enabled or disabled.
240     ///This parameter can be a value of @ref SDIO_CPSM_State
241 } SDIO_CmdInitTypeDef;
242 typedef struct {
243     u32 SDIO_DataTimeOut;   // < Specifies the data timeout period in card bus clock periods.
244     //
245     u32 SDIO_DataLength;    // < Specifies the number of data bytes to be transferred.
246     //
247     u32 SDIO_DataBlockSize; // < Specifies the data block size for block transfer.
248     // This parameter can be a value of @ref SDIO_Data_Block_Size
249     //
250     u32 SDIO_TransferDir;   // < Specifies the data transfer direction, whether the transfer
251     // is a read or write.
252     // This parameter can be a value of @ref SDIO_Transfer_Direction
253     //
254 //    u32 SDIO_TransferMode;  // < Specifies whether data transfer is in stream or block mode.
255 //                                 // This parameter can be a value of @ref SDIO_Transfer_Type
256 //                                 //
257 //    u32 SDIO_DPSM;          // < Specifies whether SDIO Data path state machine (DPSM)
258 //                                 //    is enabled or disabled.
259 //                                 //    This parameter can be a value of @ref SDIO_DPSM_State
260 } SDIO_DataInitTypeDef;
261 
262 
263 
264 extern SD_CardInfo SDCardInfo;
265 ////////////////////////////////////////////////////////////////////////////////
266 /// @defgroup SDIO ָinstruction set
267 /// @{
268 #define SD_CMD_GO_IDLE_STATE                       ((u8)0)
269 #define SD_CMD_SEND_OP_COND                        ((u8)1)
270 #define SD_CMD_ALL_SEND_CID                        ((u8)2)
271 #define SD_CMD_SET_REL_ADDR                        ((u8)3)
272 #define SD_CMD_SET_DSR                             ((u8)4)
273 #define SD_CMD_SDIO_SEN_OP_COND                    ((u8)5)
274 #define SD_CMD_HS_SWITCH                           ((u8)6)
275 #define SD_CMD_SEL_DESEL_CARD                      ((u8)7)
276 #define SD_CMD_HS_SEND_EXT_CSD                     ((u8)8)
277 #define SD_CMD_SEND_CSD                            ((u8)9)
278 #define SD_CMD_SEND_CID                            ((u8)10)
279 #define SD_CMD_READ_DAT_UNTIL_STOP                 ((u8)11)
280 #define SD_CMD_STOP_TRANSMISSION                   ((u8)12)
281 #define SD_CMD_SEND_STATUS                         ((u8)13)
282 #define SD_CMD_HS_BUSTEST_READ                     ((u8)14)
283 #define SD_CMD_GO_INACTIVE_STATE                   ((u8)15)
284 #define SD_CMD_SET_BLOCKLEN                        ((u8)16)
285 #define SD_CMD_READ_SINGLE_BLOCK                   ((u8)17)
286 #define SD_CMD_READ_MULT_BLOCK                     ((u8)18)
287 #define SD_CMD_HS_BUSTEST_WRITE                    ((u8)19)
288 #define SD_CMD_WRITE_DAT_UNTIL_STOP                ((u8)20)
289 #define SD_CMD_SET_BLOCK_COUNT                     ((u8)23)
290 #define SD_CMD_WRITE_SINGLE_BLOCK                  ((u8)24)
291 #define SD_CMD_WRITE_MULT_BLOCK                    ((u8)25)
292 #define SD_CMD_PROG_CID                            ((u8)26)
293 #define SD_CMD_PROG_CSD                            ((u8)27)
294 #define SD_CMD_SET_WRITE_PROT                      ((u8)28)
295 #define SD_CMD_CLR_WRITE_PROT                      ((u8)29)
296 #define SD_CMD_SEND_WRITE_PROT                     ((u8)30)
297 #define SD_CMD_SD_ERASE_GRP_START                  ((u8)32)
298 #define SD_CMD_SD_ERASE_GRP_END                    ((u8)33)
299 #define SD_CMD_ERASE_GRP_START                     ((u8)35)
300 #define SD_CMD_ERASE_GRP_END                       ((u8)36)
301 #define SD_CMD_ERASE                               ((u8)38)
302 #define SD_CMD_FAST_IO                             ((u8)39)
303 #define SD_CMD_GO_IRQ_STATE                        ((u8)40)
304 #define SD_CMD_LOCK_UNLOCK                         ((u8)42)
305 #define SD_CMD_APP_CMD                             ((u8)55)
306 #define SD_CMD_GEN_CMD                             ((u8)56)
307 #define SD_CMD_NO_CMD                              ((u8)64)
308 /// @}
309 
310 ////////////////////////////////////////////////////////////////////////////////
311 /// @defgroup Following commands are SD Card Specific commands.
312 /// @{
313 #define SD_CMD_APP_SD_SET_BUSWIDTH                 ((u8)6)
314 #define SD_CMD_SD_APP_STAUS                        ((u8)13)
315 #define SD_CMD_SD_APP_SEND_NUM_WRITE_BLOCKS        ((u8)22)
316 #define SD_CMD_SD_APP_OP_COND                      ((u8)41)
317 #define SD_CMD_SD_APP_SET_CLR_CARD_DETECT          ((u8)42)
318 #define SD_CMD_SD_APP_SEND_SCR                     ((u8)51)
319 #define SD_CMD_SDIO_RW_DIRECT                      ((u8)52)
320 #define SD_CMD_SDIO_RW_EXTENDED                    ((u8)53)
321 
322 #define SD_CMD_SD_APP_GET_MKB                      ((u8)43)
323 #define SD_CMD_SD_APP_GET_MID                      ((u8)44)
324 #define SD_CMD_SD_APP_SET_CER_RN1                  ((u8)45)
325 #define SD_CMD_SD_APP_GET_CER_RN2                  ((u8)46)
326 #define SD_CMD_SD_APP_SET_CER_RES2                 ((u8)47)
327 #define SD_CMD_SD_APP_GET_CER_RES1                 ((u8)48)
328 #define SD_CMD_SD_APP_SECURE_READ_MULTIPLE_BLOCK   ((u8)18)
329 #define SD_CMD_SD_APP_SECURE_WRITE_MULTIPLE_BLOCK  ((u8)25)
330 #define SD_CMD_SD_APP_SECURE_ERASE                 ((u8)38)
331 #define SD_CMD_SD_APP_CHANGE_SECURE_AREA           ((u8)49)
332 #define SD_CMD_SD_APP_SECURE_WRITE_MKB             ((u8)48)
333 /// @}
334 ////////////////////////////////////////////////////////////////////////////////
335 /// @defgroup SD support define.
336 /// @{
337 #define SDIO_STD_CAPACITY_SD_CARD_V1_1             ((u32)0x00000000)
338 #define SDIO_STD_CAPACITY_SD_CARD_V2_0             ((u32)0x00000001)
339 #define SDIO_HIGH_CAPACITY_SD_CARD                 ((u32)0x00000002)
340 #define SDIO_MULTIMEDIA_CARD                       ((u32)0x00000003)
341 #define SDIO_SECURE_DIGITAL_IO_CARD                ((u32)0x00000004)
342 #define SDIO_HIGH_SPEED_MULTIMEDIA_CARD            ((u32)0x00000005)
343 #define SDIO_SECURE_DIGITAL_IO_COMBO_CARD          ((u32)0x00000006)
344 #define SDIO_HIGH_CAPACITY_MMC_CARD                ((u32)0x00000007)
345 /// @}
346 
347 #ifndef NULL
348 #define NULL 0
349 #endif
350 #define SDIO_STATIC_FLAGS               ((u32)0x000005FF)
351 #define SDIO_CMD0TIMEOUT                ((u32)0x00010000)
352 #define SDIO_DATATIMEOUT                ((u32)0xFFFFFFFF)
353 #define SDIO_FIFO_Address               ((u32)0x40018080)
354 
355 ////////////////////////////////////////////////////////////////////////////////
356 /// @defgroup Mask for errors Card Status R1 (OCR Register)
357 /// @{
358 #define SD_OCR_ADDR_OUT_OF_RANGE        ((u32)0x80000000)
359 #define SD_OCR_ADDR_MISALIGNED          ((u32)0x40000000)
360 #define SD_OCR_BLOCK_LEN_ERR            ((u32)0x20000000)
361 #define SD_OCR_ERASE_SEQ_ERR            ((u32)0x10000000)
362 #define SD_OCR_BAD_ERASE_PARAM          ((u32)0x08000000)
363 #define SD_OCR_WRITE_PROT_VIOLATION     ((u32)0x04000000)
364 #define SD_OCR_LOCK_UNLOCK_FAILED       ((u32)0x01000000)
365 #define SD_OCR_COM_CRC_FAILED           ((u32)0x00800000)
366 #define SD_OCR_ILLEGAL_CMD              ((u32)0x00400000)
367 #define SD_OCR_CARD_ECC_FAILED          ((u32)0x00200000)
368 #define SD_OCR_CC_ERROR                 ((u32)0x00100000)
369 #define SD_OCR_GENERAL_UNKNOWN_ERROR    ((u32)0x00080000)
370 #define SD_OCR_STREAM_READ_UNDERRUN     ((u32)0x00040000)
371 #define SD_OCR_STREAM_WRITE_OVERRUN     ((u32)0x00020000)
372 #define SD_OCR_CID_CSD_OVERWRIETE       ((u32)0x00010000)
373 #define SD_OCR_WP_ERASE_SKIP            ((u32)0x00008000)
374 #define SD_OCR_CARD_ECC_DISABLED        ((u32)0x00004000)
375 #define SD_OCR_ERASE_RESET              ((u32)0x00002000)
376 #define SD_OCR_AKE_SEQ_ERROR            ((u32)0x00000008)
377 #define SD_OCR_ERRORBITS                ((u32)0xFDFFE008)
378 /// @}
379 ////////////////////////////////////////////////////////////////////////////////
380 /// @defgroup Masks for R6 Response
381 /// @{
382 #define SD_R6_GENERAL_UNKNOWN_ERROR     ((u32)0x00002000)
383 #define SD_R6_ILLEGAL_CMD               ((u32)0x00004000)
384 #define SD_R6_COM_CRC_FAILED            ((u32)0x00008000)
385 /// @}
386 #define SD_VOLTAGE_WINDOW_SD            ((u32)0x80100000)
387 #define SD_HIGH_CAPACITY                ((u32)0x40000000)
388 #define SD_STD_CAPACITY                 ((u32)0x00000000)
389 #define SD_CHECK_PATTERN                ((u32)0x000001AA)
390 #define SD_VOLTAGE_WINDOW_MMC           ((u32)0x80FF8000)
391 
392 #define SD_MAX_VOLT_TRIAL               ((u32)0x0000FFFF)
393 #define SD_ALLZERO                      ((u32)0x00000000)
394 
395 #define SD_WIDE_BUS_SUPPORT             ((u32)0x00040000)
396 #define SD_SINGLE_BUS_SUPPORT           ((u32)0x00010000)
397 #define SD_CARD_LOCKED                  ((u32)0x02000000)
398 #define SD_CARD_PROGRAMMING             ((u32)0x00000007)
399 #define SD_CARD_RECEIVING               ((u32)0x00000006)
400 #define SD_DATATIMEOUT                  ((u32)0xFFFFFFFF)
401 #define SD_0TO7BITS                     ((u32)0x000000FF)
402 #define SD_8TO15BITS                    ((u32)0x0000FF00)
403 #define SD_16TO23BITS                   ((u32)0x00FF0000)
404 #define SD_24TO31BITS                   ((u32)0xFF000000)
405 #define SD_MAX_DATA_LENGTH              ((u32)0x01FFFFFF)
406 
407 #define SD_HALFFIFO                     ((u32)0x00000008)
408 #define SD_HALFFIFOBYTES                ((u32)0x00000020)
409 
410 #define SD_CCCC_LOCK_UNLOCK             ((u32)0x00000080)
411 #define SD_CCCC_WRITE_PROT              ((u32)0x00000040)
412 #define SD_CCCC_ERASE                   ((u32)0x00000020)
413 
414 
415 #define SDIO_SEND_IF_COND               ((u32)0x00000008)
416 
417 #define SDIO_Response_No                    ((u32)0x00)
418 #define SDIO_Response_Short                 ((u32)0x01)
419 #define SDIO_Response_Long                  ((u32)0x03)
420 
421 #define SDIO_DataBlockSize_1b               ((u32)0x00000000)
422 #define SDIO_DataBlockSize_2b               ((u32)0x00000001)
423 #define SDIO_DataBlockSize_4b               ((u32)0x00000002)
424 #define SDIO_DataBlockSize_8b               ((u32)0x00000003)
425 #define SDIO_DataBlockSize_16b              ((u32)0x00000004)
426 #define SDIO_DataBlockSize_32b              ((u32)0x00000005)
427 #define SDIO_DataBlockSize_64b              ((u32)0x00000006)
428 #define SDIO_DataBlockSize_128b             ((u32)0x00000007)
429 #define SDIO_DataBlockSize_256b             ((u32)0x00000008)
430 #define SDIO_DataBlockSize_512b             ((u32)0x00000009)
431 #define SDIO_DataBlockSize_1024b            ((u32)0x0000000A)
432 #define SDIO_DataBlockSize_2048b            ((u32)0x0000000B)
433 #define SDIO_DataBlockSize_4096b            ((u32)0x0000000C)
434 #define SDIO_DataBlockSize_8192b            ((u32)0x0000000D)
435 #define SDIO_DataBlockSize_16384b           ((u32)0x0000000E)
436 //Define the data block length when the block data transfer mode is selected:
437 //0000: (0 decimal) lock length  = 2^0 = 1 byte
438 //0001: (1 decimal) lock length  = 2^1 = 2 bytes
439 //0010: (2 decimal) lock length  = 2^2 = 4 bytes
440 //0011: (3 decimal) lock length  = 2^3 = 8 bytes
441 //0100: (4 decimal) lock length  = 2^4 = 16 bytes
442 //0101: (5 decimal) lock length  = 2^5 = 32 bytes
443 //0110: (6 decimal) lock length  = 2^6 = 64 bytes
444 //0111: (7 decimal) lock length  = 2^7 = 128 bytes
445 //1000: (8 decimal) lock length  = 2^8 = 256 bytes
446 //1001: (9 decimal) lock length  = 2^9 = 512 bytes
447 //1010: (10 decimal) lock length = 2^10 = 1024 bytes
448 //1011: (11 decimal) lock length = 2^11 = 2048 bytes
449 //1100: (12 decimal) lock length = 2^12 = 4096 bytes
450 //1101: (13 decimal) lock length = 2^13 = 8192 bytes
451 //1110: (14 decimal) lock length = 2^14 = 16384 bytes
452 //1111: (15 decimal) reserved
453 
454 
455 #define SDIO_TransferDir_ToCard             ((u32)0x00000000)
456 #define SDIO_TransferDir_ToSDIO             ((u32)0x00000002)
457 
458 #define SDIO_Wait_No                        ((u32)0x00000000) // SDIO No Wait, TimeOut is enabled
459 #define SDIO_Wait_IT                        ((u32)0x00000100) //SDIO Wait Interrupt Request
460 #define SDIO_Wait_Pend                      ((u32)0x00000200) // SDIO Wait End of transfer
461 
462 ////////////////////////////////////////////////////////////////////////////////
463 /// @defgroup I2C_Exported_Functions
464 /// @{
465 void SDIO_DeInit(void);
466 void SDIO_StructInit(SDIO_InitTypeDef* SDIO_InitStruct);
467 void SDIO_ClockSet(u32 value);
468 void SDIO_Init(SDIO_InitTypeDef* SDIO_InitStruct);
469 void SDIO_ITConfig(u32 SDIO_IT, FunctionalState state);
470 void SDIO_CRCConfig(u32 SDIO_CRC, FunctionalState state);
471 void SDIO_Clock_Set(u8 clkdiv);
472 void SDIO_Send_Cmd(u8 cmdindex, u8 waitrsp, u32 arg);
473 SD_Error SD_PowerOFF(void);
474 SD_Error CmdError(void);
475 SD_Error CmdResp2Error(void);
476 SD_Error CmdResp3Error(void);
477 SD_Error CmdResp6Error(u8 cmd, u16* prca);
478 SD_Error CmdResp7Error(void);
479 SD_Error CmdResp1Error(u8 cmd);
480 void SDIO_Send_Data_Cfg(u32 datatimeout, u32 datalen, u8 blksize, u8 dir);
481 void SDIO_ClearITPendingBit(u32 SDIO_IT);
482 FlagStatus SDIO_GetFlagStatus(u32 SDIO_FLAG);
483 u32 SDIO_GetTimeOutCounter(void);
484 u32 SDIO_ReadData(void);
485 void SDIO_WriteData(u32 tempbuff);
486 void SDIO_DMACmd(FunctionalState state);
487 /// @}
488 
489 
490 #ifdef __cplusplus
491 }
492 #endif
493 
494 
495 /// @}
496 
497 /// @}
498 
499 /// @}
500 
501 ////////////////////////////////////////////////////////////////////////////////
502 #endif
503 ////////////////////////////////////////////////////////////////////////////////
504