aboutsummaryrefslogtreecommitdiff
path: root/sd.h
blob: 0a00addb8417f9d59a180f7247b5695d6a3f514a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdint.h>

#include "sd_config.h"

#define SD_GO_IDLE_STATE 0
#define SD_SEND_OP_COND 1
#define SD_OP_COND_SDC 0xe9
#define SD_SEND_IF_COND 8
#define SD_SEND_CSD 9      
#define SD_SEND_CID 10
#define SD_STOP_TRANSMISSION 12
#define SD_SEND_STATUS 13

#define SD_SET_BLOCKLEN 16
#define SD_READ_SINGLE_BLOCK 17
#define SD_READ_MULTIPLE_BLOCK 18

#define SD_WRITE_BLOCK 24
#define SD_WRITE_MULTIPLE_BLOCK 25
#define SD_PROGRAM_CSD 27

#define SD_SET_WRITE_PROT 28
#define SD_CLR_WRITE_PROT 29
#define SD_SEND_WRITE_PROT 30

#define SD_ERASE_WR_BLK_START 32
#define SD_ERASE_WR_BLK_END 33
#define SD_ERASE 38

#define SD_APP_CMD 55 
#define SD_GEN_CMD 56

#define SD_READ_OCR 58
#define SD_CRC_ON_OFF 59 

#define SD_SD_STATUS 13
#define SD_SEND_NUM_WR_BLOCKS 22
#define SD_SET_WR_BLK_ERASE_COUNT 23
#define SD_SD_APP_OP_COND 41
#define SD_SET_CLR_CARD_DETECT 42
#define SD_SEND_SCR 51

#define SD_IN_IDLE_STATE 0x01
#define SD_ERASE_RESET 0x02
#define SD_ILLEGAL_COMMAND 0x04
#define SD_CRC_ERROR 0x08
#define SD_ERASE_ERROR 0x10
#define SD_ADDRESS_ERROR 0x20
#define SD_PARAM_ERROR 0x40

#define SD_SELECT() (SD_CHIP_SELECT = 0)
#define SD_DESELECT() (SD_CHIP_SELECT = 1)

uint8_t sd_send_command(uint8_t cmd, uint32_t data);
void sd_wait(void);
char sd_init(void);