APM:Libraries
sd.h
Go to the documentation of this file.
1 /*-----------------------------------------------------------------------
2  Low level SD card and DataFlash include file
3 /-----------------------------------------------------------------------*/
4 
5 #ifndef _SD_DEFINED
6 #define _SD_DEFINED
7 
8 #include "../diskio.h"
9 
10 #include <hal.h>
11 #include <timer.h>
12 #include <string.h>
13 
14 #define FAT_SECTOR_SIZE 512
15 
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #include "../integer.h"
22 
23 
24 /*---------------------------------------*/
25 /* Prototypes for disk control functions */
26 /*---------------------------------------*/
27 
28 void sd_timerproc();
29 
32 DRESULT sd_read (uint8_t* buff, uint32_t sector, uint16_t count);
33 DRESULT sd_write (const uint8_t* buff, uint32_t sector, uint16_t count);
34 DRESULT sd_ioctl (uint8_t cmd, void* buff);
35 uint8_t sd_get_type();
36 uint8_t sd_get_state();
37 uint8_t sd_getSectorCount(uint32_t *ptr);
38 
39 
40 /* MMC card type flags (MMC_GET_TYPE) */
41 #define CT_MMC 0x01 /* MMC ver 3 */
42 #define CT_SD1 0x02 /* SD ver 1 */
43 #define CT_SD2 0x04 /* SD ver 2 */
44 #define CT_SDC (CT_SD1|CT_SD2) /* SD */
45 #define CT_BLOCK 0x08 /* Block addressing */
46 
47 
48 #define MMCSD_R1_OUTOFRANGE ((uint32_t)1 << 31) /* Bad argument */
49 #define MMCSD_R1_ADDRESSERROR ((uint32_t)1 << 30) /* Bad address */
50 #define MMCSD_R1_BLOCKLENERROR ((uint32_t)1 << 29) /* Bad block length */
51 #define MMCSD_R1_ERASESEQERROR ((uint32_t)1 << 28) /* Erase cmd error */
52 #define MMCSD_R1_ERASEPARAM ((uint32_t)1 << 27) /* Bad write blocks */
53 #define MMCSD_R1_WPVIOLATION ((uint32_t)1 << 26) /* Erase access failure */
54 #define MMCSD_R1_CARDISLOCKED ((uint32_t)1 << 25) /* Card is locked */
55 #define MMCSD_R1_LOCKUNLOCKFAILED ((uint32_t)1 << 24) /* Password error */
56 #define MMCSD_R1_COMCRCERROR ((uint32_t)1 << 23) /* CRC error */
57 #define MMCSD_R1_ILLEGALCOMMAND ((uint32_t)1 << 22) /* Bad command */
58 #define MMCSD_R1_CARDECCFAILED ((uint32_t)1 << 21) /* Failed to correct data */
59 #define MMCSD_R1_CCERROR ((uint32_t)1 << 20) /* Card controller error */
60 #define MMCSD_R1_ERROR ((uint32_t)1 << 19) /* General error */
61 #define MMCSD_R1_UNDERRUN ((uint32_t)1 << 18) /* Underrun (MMC only) */
62 #define MMCSD_R1_OVERRRUN ((uint32_t)1 << 17) /* Overrun (MMC only) */
63 #define MMCSD_R1_CIDCSDOVERWRITE ((uint32_t)1 << 16) /* CID/CSD error */
64 #define MMCSD_R1_WPERASESKIP ((uint32_t)1 << 15) /* Not all erased */
65 #define MMCSD_R1_CARDECCDISABLED ((uint32_t)1 << 14) /* Internal ECC not used */
66 #define MMCSD_R1_ERASERESET ((uint32_t)1 << 13) /* Reset sequence cleared */
67 #define MMCSD_R1_STATE_SHIFT (9) /* Current card state */
68 #define MMCSD_R1_STATE_MASK ((uint32_t)15 << MMCSD_R1_STATE_SHIFT)
69  /* Card identification mode states */
70 # define MMCSD_R1_STATE_IDLE ((uint32_t)0 << MMCSD_R1_STATE_SHIFT) /* 0=Idle state */
71 # define MMCSD_R1_STATE_READY ((uint32_t)1 << MMCSD_R1_STATE_SHIFT) /* 1=Ready state */
72 # define MMCSD_R1_STATE_IDENT ((uint32_t)2 << MMCSD_R1_STATE_SHIFT) /* 2=Identification state */
73  /* Data transfer states */
74 # define MMCSD_R1_STATE_STBY ((uint32_t)3 << MMCSD_R1_STATE_SHIFT) /* 3=Standby state */
75 # define MMCSD_R1_STATE_TRAN ((uint32_t)4 << MMCSD_R1_STATE_SHIFT) /* 4=Transfer state */
76 # define MMCSD_R1_STATE_DATA ((uint32_t)5 << MMCSD_R1_STATE_SHIFT) /* 5=Sending data state */
77 # define MMCSD_R1_STATE_RCV ((uint32_t)6 << MMCSD_R1_STATE_SHIFT) /* 6=Receiving data state */
78 # define MMCSD_R1_STATE_PRG ((uint32_t)7 << MMCSD_R1_STATE_SHIFT) /* 7=Programming state */
79 # define MMCSD_R1_STATE_DIS ((uint32_t)8 << MMCSD_R1_STATE_SHIFT) /* 8=Disconnect state */
80 #define MMCSD_R1_READYFORDATA ((uint32_t)1 << 8) /* Buffer empty */
81 #define MMCSD_R1_APPCMD ((uint32_t)1 << 5) /* Next CMD is ACMD */
82 #define MMCSD_R1_AKESEQERROR ((uint32_t)1 << 3) /* Authentication error */
83 #define MMCSD_R1_ERRORMASK ((uint32_t)0xfdffe008) /* Error mask */
84 
85 
86 #ifdef __cplusplus
87 }
88 #endif
89 
90 #endif
DRESULT sd_write(const uint8_t *buff, uint32_t sector, uint16_t count)
DRESULT sd_read(uint8_t *buff, uint32_t sector, uint16_t count)
timer interface.
DRESULT sd_ioctl(uint8_t cmd, void *buff)
DSTATUS sd_status()
BYTE DSTATUS
Definition: diskio.h:17
DRESULT
Definition: diskio.h:20
DSTATUS sd_initialize()
void sd_timerproc()
uint8_t sd_get_type()
uint8_t sd_getSectorCount(uint32_t *ptr)
uint8_t sd_get_state()