| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef SdInfo_h |
| 21 |
#define SdInfo_h |
| 22 |
#include <stdint.h> |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
uint8_t const CMD0 = 0X00; |
| 37 |
|
| 38 |
uint8_t const CMD8 = 0X08; |
| 39 |
|
| 40 |
uint8_t const CMD9 = 0X09; |
| 41 |
|
| 42 |
uint8_t const CMD10 = 0X0A; |
| 43 |
|
| 44 |
uint8_t const CMD13 = 0X0D; |
| 45 |
|
| 46 |
uint8_t const CMD17 = 0X11; |
| 47 |
|
| 48 |
uint8_t const CMD24 = 0X18; |
| 49 |
|
| 50 |
uint8_t const CMD25 = 0X19; |
| 51 |
|
| 52 |
uint8_t const CMD32 = 0X20; |
| 53 |
|
| 54 |
|
| 55 |
uint8_t const CMD33 = 0X21; |
| 56 |
|
| 57 |
uint8_t const CMD38 = 0X26; |
| 58 |
|
| 59 |
uint8_t const CMD55 = 0X37; |
| 60 |
|
| 61 |
uint8_t const CMD58 = 0X3A; |
| 62 |
|
| 63 |
|
| 64 |
uint8_t const ACMD23 = 0X17; |
| 65 |
|
| 66 |
|
| 67 |
uint8_t const ACMD41 = 0X29; |
| 68 |
|
| 69 |
|
| 70 |
uint8_t const R1_READY_STATE = 0X00; |
| 71 |
|
| 72 |
uint8_t const R1_IDLE_STATE = 0X01; |
| 73 |
|
| 74 |
uint8_t const R1_ILLEGAL_COMMAND = 0X04; |
| 75 |
|
| 76 |
uint8_t const DATA_START_BLOCK = 0XFE; |
| 77 |
|
| 78 |
uint8_t const STOP_TRAN_TOKEN = 0XFD; |
| 79 |
|
| 80 |
uint8_t const WRITE_MULTIPLE_TOKEN = 0XFC; |
| 81 |
|
| 82 |
uint8_t const DATA_RES_MASK = 0X1F; |
| 83 |
|
| 84 |
uint8_t const DATA_RES_ACCEPTED = 0X05; |
| 85 |
|
| 86 |
typedef struct CID { |
| 87 |
|
| 88 |
uint8_t mid; |
| 89 |
|
| 90 |
char oid[2]; |
| 91 |
|
| 92 |
char pnm[5]; |
| 93 |
|
| 94 |
unsigned prv_m : 4; |
| 95 |
unsigned prv_n : 4; |
| 96 |
|
| 97 |
uint32_t psn; |
| 98 |
|
| 99 |
unsigned mdt_year_high : 4; |
| 100 |
unsigned reserved : 4; |
| 101 |
|
| 102 |
unsigned mdt_month : 4; |
| 103 |
unsigned mdt_year_low :4; |
| 104 |
|
| 105 |
unsigned always1 : 1; |
| 106 |
unsigned crc : 7; |
| 107 |
}cid_t; |
| 108 |
|
| 109 |
|
| 110 |
typedef struct CSDV1 { |
| 111 |
|
| 112 |
unsigned reserved1 : 6; |
| 113 |
unsigned csd_ver : 2; |
| 114 |
|
| 115 |
uint8_t taac; |
| 116 |
|
| 117 |
uint8_t nsac; |
| 118 |
|
| 119 |
uint8_t tran_speed; |
| 120 |
|
| 121 |
uint8_t ccc_high; |
| 122 |
|
| 123 |
unsigned read_bl_len : 4; |
| 124 |
unsigned ccc_low : 4; |
| 125 |
|
| 126 |
unsigned c_size_high : 2; |
| 127 |
unsigned reserved2 : 2; |
| 128 |
unsigned dsr_imp : 1; |
| 129 |
unsigned read_blk_misalign :1; |
| 130 |
unsigned write_blk_misalign : 1; |
| 131 |
unsigned read_bl_partial : 1; |
| 132 |
|
| 133 |
uint8_t c_size_mid; |
| 134 |
|
| 135 |
unsigned vdd_r_curr_max : 3; |
| 136 |
unsigned vdd_r_curr_min : 3; |
| 137 |
unsigned c_size_low :2; |
| 138 |
|
| 139 |
unsigned c_size_mult_high : 2; |
| 140 |
unsigned vdd_w_cur_max : 3; |
| 141 |
unsigned vdd_w_curr_min : 3; |
| 142 |
|
| 143 |
unsigned sector_size_high : 6; |
| 144 |
unsigned erase_blk_en : 1; |
| 145 |
unsigned c_size_mult_low : 1; |
| 146 |
|
| 147 |
unsigned wp_grp_size : 7; |
| 148 |
unsigned sector_size_low : 1; |
| 149 |
|
| 150 |
unsigned write_bl_len_high : 2; |
| 151 |
unsigned r2w_factor : 3; |
| 152 |
unsigned reserved3 : 2; |
| 153 |
unsigned wp_grp_enable : 1; |
| 154 |
|
| 155 |
unsigned reserved4 : 5; |
| 156 |
unsigned write_partial : 1; |
| 157 |
unsigned write_bl_len_low : 2; |
| 158 |
|
| 159 |
unsigned reserved5: 2; |
| 160 |
unsigned file_format : 2; |
| 161 |
unsigned tmp_write_protect : 1; |
| 162 |
unsigned perm_write_protect : 1; |
| 163 |
unsigned copy : 1; |
| 164 |
unsigned file_format_grp : 1; |
| 165 |
|
| 166 |
unsigned always1 : 1; |
| 167 |
unsigned crc : 7; |
| 168 |
}csd1_t; |
| 169 |
|
| 170 |
|
| 171 |
typedef struct CSDV2 { |
| 172 |
|
| 173 |
unsigned reserved1 : 6; |
| 174 |
unsigned csd_ver : 2; |
| 175 |
|
| 176 |
uint8_t taac; |
| 177 |
|
| 178 |
uint8_t nsac; |
| 179 |
|
| 180 |
uint8_t tran_speed; |
| 181 |
|
| 182 |
uint8_t ccc_high; |
| 183 |
|
| 184 |
unsigned read_bl_len : 4; |
| 185 |
unsigned ccc_low : 4; |
| 186 |
|
| 187 |
unsigned reserved2 : 4; |
| 188 |
unsigned dsr_imp : 1; |
| 189 |
unsigned read_blk_misalign :1; |
| 190 |
unsigned write_blk_misalign : 1; |
| 191 |
unsigned read_bl_partial : 1; |
| 192 |
|
| 193 |
unsigned reserved3 : 2; |
| 194 |
unsigned c_size_high : 6; |
| 195 |
|
| 196 |
uint8_t c_size_mid; |
| 197 |
|
| 198 |
uint8_t c_size_low; |
| 199 |
|
| 200 |
unsigned sector_size_high : 6; |
| 201 |
unsigned erase_blk_en : 1; |
| 202 |
unsigned reserved4 : 1; |
| 203 |
|
| 204 |
unsigned wp_grp_size : 7; |
| 205 |
unsigned sector_size_low : 1; |
| 206 |
|
| 207 |
unsigned write_bl_len_high : 2; |
| 208 |
unsigned r2w_factor : 3; |
| 209 |
unsigned reserved5 : 2; |
| 210 |
unsigned wp_grp_enable : 1; |
| 211 |
|
| 212 |
unsigned reserved6 : 5; |
| 213 |
unsigned write_partial : 1; |
| 214 |
unsigned write_bl_len_low : 2; |
| 215 |
|
| 216 |
unsigned reserved7: 2; |
| 217 |
unsigned file_format : 2; |
| 218 |
unsigned tmp_write_protect : 1; |
| 219 |
unsigned perm_write_protect : 1; |
| 220 |
unsigned copy : 1; |
| 221 |
unsigned file_format_grp : 1; |
| 222 |
|
| 223 |
unsigned always1 : 1; |
| 224 |
unsigned crc : 7; |
| 225 |
}csd2_t; |
| 226 |
|
| 227 |
|
| 228 |
union csd_t { |
| 229 |
csd1_t v1; |
| 230 |
csd2_t v2; |
| 231 |
}; |
| 232 |
#endif |