📄 sd_mem.h
字号:
#define SD_R3_RESERVED_LENGTH1 6 /* bits */
#define SD_R3_REG_LENGTH 32 /* bits */
#define SD_R3_RESERVED_LENGTH2 7 /* bits */
#define SD_R3_START_BIT 0x0
#define SD_R3_END_BIT 0x1
#define SD_R3_CARD_XMIT_BIT 0x0
/* Response, R6 format (RCA register)..
* [start[47]|xmit[46]|index[45:40]|RCA[39:24]|stat[23:8]|crc[7:1]|end[0]]
*/
#define SD_R6_LENGTH 48 /* bits */
#define SD_R6_INDEX_LENGTH 6 /* bits */
#define SD_R6_RCA_LENGTH 16 /* bits */
#define SD_R6_STATUS_LENGTH 16 /* bits */
#define SD_R6_CRC_LENGTH 7 /* bits */
#define SD_R6_START_BIT 0x0
#define SD_R6_END_BIT 0x1
#define SD_R6_CARD_XMIT_BIT 0x0
/**************************************************************************
* SD structures
**************************************************************************/
typedef struct { /* ref. p.49-52..SD Physical Layer */
unsigned out_of_range :1;
unsigned addr_error :1;
unsigned block_len_error :1;
unsigned erase_seq_error :1;
unsigned erase_param :1;
unsigned wp_violation :1;
unsigned card_locked :1;
unsigned lock_failed :1;
unsigned com_crc_error :1;
unsigned illegal_cmd :1;
unsigned ecc_failed :1;
unsigned cc_error :1;
unsigned error :1;
unsigned reserved_18_17 :2;
unsigned cid_csd_overwr :1;
unsigned wp_erase_skip :1;
unsigned ecc_disable :1;
unsigned erase_reset :1;
unsigned current_state :4;
unsigned ready_for_data :1;
unsigned reserved_7_6 :2;
unsigned app_cmd :1;
unsigned reserved_4 :1;
unsigned ake_seq_error :1;
unsigned reserved_2_0 :3;
} SD_CARD_STATUS;
typedef struct { /* ref. p.52-53..SD Physical Layer */
unsigned dat_bus_width :2;
unsigned secured_mode :1;
unsigned reserved_508_496 :13;
unsigned sd_card_type :16;
unsigned protected_size :32;
#if 0 /* only 64 of 512 bits used */
unsigned reserved_447_312 :136; /* illustrative..not for compile! */
unsigned reserved_311_0 :312; /* illustrative..not for compile! */
#endif
} SD_STATUS;
typedef struct { /* ref. p.61..SD Physical Layer */
unsigned card_ready :1;
unsigned reserved_30_24 :7;
unsigned vdd35_36 :1;
unsigned vdd34_35 :1;
unsigned vdd33_34 :1;
unsigned vdd32_33 :1;
unsigned vdd31_32 :1;
unsigned vdd30_31 :1;
unsigned vdd29_30 :1;
unsigned vdd28_29 :1;
unsigned vdd27_28 :1;
unsigned vdd26_27 :1;
unsigned vdd25_26 :1;
unsigned vdd24_25 :1;
unsigned vdd23_24 :1;
unsigned vdd22_23 :1;
unsigned vdd21_22 :1;
unsigned vdd20_21 :1;
unsigned vdd19_20 :1;
unsigned vdd18_19 :1;
unsigned vdd17_18 :1;
unsigned vdd16_17 :1;
unsigned reserved_3_0 :4;
} SD_OCR;
typedef struct { /* ref. p.62-63..SD Physical Layer */
unsigned mid :8;
unsigned oid_15_8 :8; /* oid[1] ascii..2B */
unsigned oid_7_0 :8; /* oid[0] ascii */
unsigned pnm_39_32 :8; /* pnm[4] ascii..5B */
unsigned pnm_31_24 :8; /* pnm[3] ascii */
unsigned pnm_23_16 :8; /* pnm[2] ascii */
unsigned pnm_15_8 :8; /* pnm[1] ascii */
unsigned pnm_7_0 :8; /* pnm[0] ascii */
unsigned prv :8; /* BCD */
unsigned psn_31_8 :24; /* psn crossed DW boundary */
unsigned psn_7_0 :8; /* psn crossed DW boundary */
unsigned reserved_23_20 :4;
unsigned mdt :12;/* [y[11:4] | m[3:0]]..y: 0->2000; m: 1->January */
unsigned crc :7;
unsigned reserved_0 :1;
} SD_CID;
typedef struct { /* ref. p.63-71..SD Physical Layer */
unsigned version :2;
unsigned reserved_125_119 :7;
unsigned taac_value :4; /* ref. p.65 */
unsigned taac_unit :3; /* ref. p.65 */
unsigned nsac :8; /* N*100 clock cycles */
unsigned reserved_103 :1;
unsigned tran_spd_value :4; /* ref. p.65 */
unsigned tran_spd_unit :3; /* ref. p.65 */
unsigned ccc :12; /* supported command classes */
unsigned rd_blk_len :4;
unsigned rd_blk_len_partial :1;
unsigned wr_blk_misalign :1;
unsigned rd_blk_misalign :1;
unsigned dsr_imp :1;
unsigned reserved_75_74 :2;
unsigned c_size_11_2 :10; /* c_size crossed DW boundary */
unsigned c_size_1_0 :2; /* c_size crossed DW boundary */
unsigned vdd_r_curr_min :3;
unsigned vdd_r_curr_max :3;
unsigned vdd_w_curr_min :3;
unsigned vdd_w_curr_max :3;
unsigned c_size_mult :3;
unsigned erase_blk_en :1;
unsigned sector_size :7;
unsigned wp_grp_size :7;
unsigned wp_grp_enable :1;
unsigned reserved_30_29 :2;
unsigned r2w_factor :3;
unsigned wr_blk_len :4;
unsigned wr_blk_partial :1;
unsigned reserved_20_16 :5;
unsigned file_format_grp :1;
unsigned copy :1;
unsigned perm_wr_protect :1;
unsigned tmp_wr_protect :1;
unsigned file_format :2;
unsigned reserved_9_8 :2;
unsigned crc :7;
unsigned reserved_0 :1;
} SD_CSD;
typedef struct { /* ref. p.72-73..SD Physical Layer */
unsigned scr_struct :4;
unsigned sd_spec :4;
unsigned dat_stat_aft_erase :1;
unsigned sd_security :3;
unsigned sd_bus_widths :4;
unsigned reserved_47_32 :16;
#if 0 /* use 32 of 64 bits */
unsigned reserved_31_0 :32;
#endif
} SD_SCR;
typedef struct {
unsigned com_state :4; /* value <= 0xf */
unsigned response_recv :1;
unsigned response_expected :3;
unsigned cmd :8;
unsigned cur_blk_size :4; /* size = 2^value (bytes) */
unsigned data_width :1; /* 0:1bit, 1:4bits*/
unsigned use_data :2; /* 1:write, 2:read, 0:no data */
unsigned cmd_sent :1; /* 1:cmd completed */
unsigned retry_cnt :8;
uint wait_nclk;
uint arg;
uint data_cnt;
uint data_len; /* length to be xmited in bytes */
uint *rd_dest_ptr;
int *wr_src_ptr;
int result; /* 0: success, -1: failed */
#if SD_CHECK_RECV_CRC
uint crc7_err_cnt;
uint crc16_err_cnt;
#endif
} SD_XMIT_STATUS;
typedef struct {
uchar cmd;
uint arg;
} SD_CMD_Q;
typedef struct {
uchar type;
uchar inserted;
uint n_wr_max; /* min: 2 clk cycles */
uint n_ac_max; /* min: 2 clk cycles */
uint capacity; /* in Bytes */
} SD_CINFO;
/**************************************************************************
* Public SD variables
**************************************************************************/
EXPORT SD_CINFO SD_card_info;
EXPORT SD_XMIT_STATUS SD_xmit_info;
/**************************************************************************
* Public SD functions
**************************************************************************/
EXPORT void SD_service(void);
EXPORT int SD_identify_device(void);
EXPORT void SD_init(void);
EXPORT void SD_enable_io(int);
EXPORT void SD_reset(void);
EXPORT int SD_set_bus_width(int);
EXPORT int SD_read_blk(int, int, uint *, int);
EXPORT int SD_read_nblk(int, int, uint *, int);
EXPORT int SD_send_cmd(int, uint, int);
EXPORT int SD_send_acmd(int, uint, int);
EXPORT int SD_clk_restricted_cmd(int, uint);
EXPORT int SD_get_next_cmd(void);
EXPORT unsigned int SD_boot_setup(void);
EXPORT int SD_read_sector_lba(short *, int, int, int);
#endif /* _SD_MEM_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -