Changeset 501 for trunk/softs
- Timestamp:
- Aug 29, 2013, 11:35:11 AM (11 years ago)
- Location:
- trunk/softs/tsar_boot
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/softs/tsar_boot/include/sdcard.h
r292 r501 23 23 24 24 /** 25 * Capacity of the SDCARD in terms of bytes26 */27 unsigned int capacity;28 29 /**30 25 * Block length of the SDCARD 31 26 */ … … 46 41 */ 47 42 int slave_id; 43 44 /* is the card high capacity ? */ 45 int sdhc; 48 46 }; 49 47 … … 105 103 */ 106 104 void sdcard_dev_lseek(struct sdcard_dev * sdcard, unsigned int pos); 107 108 /**109 * \param sdcard : Pointer to the initialized block device110 *111 * \return block device capacity112 *113 * \brief Get the block device capacity114 *115 * The block device access pointer is relocated in terms of blocks116 */117 unsigned int sdcard_dev_get_capacity(struct sdcard_dev * sdcard);118 105 119 106 /** -
trunk/softs/tsar_boot/src/sdcard.c
r398 r501 8 8 9 9 #include <sdcard.h> 10 #include <boot_tty.h> 10 11 11 12 /** … … 157 158 int sdcard_dev_open(struct sdcard_dev * sdcard, struct spi_dev * spi, int ss) 158 159 { 159 160 unsigned char args[4]; 160 161 unsigned char sdcard_rsp; 161 unsigned int iter ;162 unsigned int iter, ersp; 162 163 163 164 sdcard->spi = spi; 164 165 sdcard->slave_id = ss; 165 166 166 167 /* 167 168 168 * Supply SD card ramp up time (min 74 cycles) 169 */ 169 170 _sdcard_gen_tick(sdcard, 10); 170 171 171 172 173 174 175 172 /* 173 * Assert slave select signal 174 * Send CMD0 (Reset Command) 175 * Deassert slave select signal 176 */ 176 177 _sdcard_enable(sdcard); 177 178 178 179 180 181 179 args[0] = 0; 180 args[1] = 0; 181 args[2] = 0; 182 args[3] = 0; 182 183 sdcard_rsp = _sdcard_send_command(sdcard, 0, SDCARD_CMD, args, 0x4A); 183 184 if ( sdcard_rsp != 0x01 ) 184 185 { 186 boot_puts("card CMD0 failed "); 185 187 return sdcard_rsp; 186 188 } 187 189 188 190 _sdcard_disable(sdcard); 191 /* 192 * send CMD8. If card is pre-v2, It will reply with illegal command. 193 * Otherwise we announce sdhc support. 194 */ 189 195 _sdcard_enable(sdcard); 196 args[0] = 0; 197 args[1] = 0; 198 args[2] = 0x01; 199 args[3] = 0x01; 200 sdcard_rsp = _sdcard_send_command(sdcard, 8, SDCARD_CMD, args, 0x63); 201 if (!SDCARD_CHECK_R1_VALID(sdcard_rsp)) { 202 boot_puts("card CMD8 failed "); 203 return sdcard_rsp; 204 } 205 if (!SDCARD_CHECK_R1_ERROR(sdcard_rsp)) { 206 /* no error, command accepted. get whole reply */ 207 ersp = _sdcard_receive_char(sdcard); 208 ersp = (ersp << 8) | _sdcard_receive_char(sdcard); 209 ersp = (ersp << 8) | _sdcard_receive_char(sdcard); 210 ersp = (ersp << 8) | _sdcard_receive_char(sdcard); 211 if ((ersp & 0xffff) != 0x0101) { 212 /* voltage mismatch */ 213 boot_puts("card CMD8 mismatch: "); 214 boot_putx(ersp); 215 return sdcard_rsp; 216 } 217 boot_puts("v2 or later "); 218 sdcard->sdhc = 1; 219 } else if ((sdcard_rsp & SDCARD_R1_ILLEGAL_CMD) == 0) { 220 /* other error */ 221 boot_puts("card CMD8 error "); 222 return sdcard_rsp; 223 } else { 224 sdcard->sdhc = 0; 225 } 226 _sdcard_disable(sdcard); 227 /* send CMD41, enabling the card */ 228 _sdcard_enable(sdcard); 229 args[0] = sdcard->sdhc ? 0x40: 0; 230 args[1] = 0; 231 args[2] = 0; 232 args[3] = 0; 190 233 191 234 iter = 0; … … 202 245 203 246 _sdcard_disable(sdcard); 204 205 return sdcard_rsp; 247 if (sdcard_rsp) { 248 boot_puts("SD ACMD41 failed "); 249 return sdcard_rsp; 250 } 251 if (sdcard->sdhc != 0) { 252 /* get the card capacity to see if it's really HC */ 253 _sdcard_enable(sdcard); 254 args[0] = sdcard->sdhc ? 0x40: 0; 255 args[1] = 0; 256 args[2] = 0; 257 args[3] = 0; 258 sdcard_rsp = _sdcard_send_command(sdcard, 58, SDCARD_CMD, 259 args, 0x00); 260 if (sdcard_rsp) { 261 boot_puts("SD CMD58 failed "); 262 return sdcard_rsp; 263 } 264 ersp = _sdcard_receive_char(sdcard); 265 ersp = (ersp << 8) | _sdcard_receive_char(sdcard); 266 ersp = (ersp << 8) | _sdcard_receive_char(sdcard); 267 ersp = (ersp << 8) | _sdcard_receive_char(sdcard); 268 if (ersp & 0x40000000) { 269 boot_puts("SDHC "); 270 } else { 271 sdcard->sdhc = 0; 272 } 273 _sdcard_disable(sdcard); 274 } 275 boot_puts("card detected "); 276 return 0; 206 277 } 207 278 … … 235 306 */ 236 307 i = count; 237 while( i++ < ( sdcard->block_length+ 2) ) _sdcard_receive_char(sdcard);308 while( i++ < (512 + 2) ) _sdcard_receive_char(sdcard); 238 309 239 310 _sdcard_disable(sdcard); … … 257 328 } 258 329 259 unsigned int sdcard_dev_get_capacity(struct sdcard_dev * sdcard)260 {261 return sdcard->capacity;262 }263 264 330 int sdcard_dev_set_blocklen(struct sdcard_dev * sdcard, unsigned int len) 265 331 { … … 268 334 register int i; 269 335 336 if (len != 512) 337 return 1; 338 339 if (sdcard->sdhc) { 340 sdcard->block_length = 1; 341 return 0; 342 } 343 270 344 for (i = 0; i < 4; i++) 271 345 args[i] = (len >> (32 - (i+1)*8)) & 0xFF;
Note: See TracChangeset
for help on using the changeset viewer.