📄 sd.lst
字号:
266 1 firstblock=sd_Resp8b(iface);
267 1 while(firstblock==0xff && fb_timeout--);
268 1
269 1 if(cardresp!=0x00 || firstblock!=0xfe){
270 2 sd_Resp8bError(iface,firstblock);
271 2 return(-1);
272 2 }
273 1
274 1 for(i=0;i<512;i++){
275 2 c = if_spiSend(iface,0xff);
276 2 if(i<len)
277 2 buf[i] = c;
278 2 }
279 1
280 1 /* Checksum (2 byte) - ignore for now */
281 1 if_spiSend(iface,0xff);
282 1 if_spiSend(iface,0xff);
283 1
284 1 return(0);
285 1 }
286 /*****************************************************************************/
287
288 /* ****************************************************************************
289 calculates size of card from CSD
290 (extension by Martin Thomas, inspired by code from Holger Klabunde)
291 */
292 esint8 sd_getDriveSize(hwInterface *iface, euint32* drive_size )
293 {
294 1 euint8 cardresp, i, by;
295 1 euint8 iob[16];
296 1 euint16 c_size, c_size_mult, read_bl_len;
297 1
298 1 sd_Command(iface, CMDREADCSD, 0, 0);
299 1
300 1 do {
301 2 cardresp = sd_Resp8b(iface);
302 2 } while ( cardresp != 0xFE );
303 1
304 1 DBG((TXT("CSD:")));
305 1 for( i=0; i<16; i++) {
306 2 iob[i] = sd_Resp8b(iface);
307 2 DBG((TXT(" %02x"), iob[i]));
308 2 }
309 1 DBG((TXT("\n")));
310 1
311 1 if_spiSend(iface,0xff);
312 1 if_spiSend(iface,0xff);
313 1
314 1 c_size = iob[6] & 0x03; // bits 1..0
315 1 c_size <<= 10;
316 1 c_size += (euint16)iob[7]<<2;
317 1 c_size += iob[8]>>6;
318 1
319 1 by= iob[5] & 0x0F;
320 1 read_bl_len = 1;
321 1 read_bl_len <<= by;
322 1
ARM COMPILER V2.42, sd 27/03/06 10:45:52 PAGE 6
323 1 by=iob[9] & 0x03;
324 1 by <<= 1;
325 1 by += iob[10] >> 7;
326 1
327 1 c_size_mult = 1;
328 1 c_size_mult <<= (2+by);
329 1
330 1 *drive_size = (euint32)(c_size+1) * (euint32)c_size_mult * (euint32)read_bl_len;
331 1
332 1 return 0;
333 1 }
ARM COMPILER V2.42, sd 27/03/06 10:45:52 PAGE 7
ASSEMBLY LISTING OF GENERATED OBJECT CODE
*** EXTERNALS:
EXTERN CODE16 (lpc2000_debug_printf?T)
EXTERN CODE16 (if_spiSend?T)
*** PUBLICS:
PUBLIC sd_Init?T
PUBLIC sd_Command?T
PUBLIC sd_Resp8b?T
PUBLIC sd_Resp8bError?T
PUBLIC sd_Resp16b?T
PUBLIC sd_State?T
PUBLIC sd_readSector?T
PUBLIC sd_writeSector?T
PUBLIC sd_getDriveSize?T
*** DATA SEGMENT '?CON?sd':
00000000 ??S_20:
00000000 DB 0x0A,0x00
00000002 ??S_19:
00000002 DB ' %02x',0x00
00000008 ??S_18:
00000008 DB 'CSD:',0x00
0000000D ??S_17:
0000000D DB 'Unknown error: 0x%x (see SanDisk docs '
00000033 DB 'p5-14).',0x0A,0x00
0000003C ??S_16:
0000003C DB 'Out of Range, CSD_Overwrite.',0x0A,0x00
0000005A ??S_15:
0000005A DB 'An invalid selection, sectors for eras'
00000080 DB 'e.',0x0A,0x00
00000084 ??S_14:
00000084 DB 'Write protect violation.',0x0A,0x00
0000009E ??S_13:
0000009E DB 'Card internal ECC was applied, but fai'
000000C4 DB 'led to correct the data.',0x0A,0x00
000000DE ??S_12:
000000DE DB 'Internal card controller error.',0x0A
000000FE DB 0x00
000000FF ??S_11:
000000FF DB 'General / Unknown error -- card broken'
00000125 DB '?.',0x0A,0x00
00000129 ??S_10:
00000129 DB 'WP Erase Skip, Lock/Unlock Cmd Failed.'
0000014F DB 0x0A,0x00
00000151 ??S_9:
00000151 DB 'Card is Locked.',0x0A,0x00
00000162 ??S_8:
00000162 DB 'Unknown error 0x%x (see SanDisk docs p'
00000188 DB '5-13).',0x0A,0x00
00000190 ??S_7:
00000190 DB 'Card is initialising.',0x0A,0x00
000001A7 ??S_6:
000001A7 DB 'Erase reset (see SanDisk docs p5-13).',0x0A
000001CD DB 0x00
000001CE ??S_5:
000001CE DB 'Illegal command.',0x0A,0x00
000001E0 ??S_4:
000001E0 DB 'CRC failed.',0x0A,0x00
000001ED ??S_3:
000001ED DB 'Error during erase sequence.',0x0A,0x00
0000020B ??S_2:
0000020B DB 'Address out of bounds.',0x0A,0x00
00000223 ??S_1:
ARM COMPILER V2.42, sd 27/03/06 10:45:52 PAGE 8
00000223 DB 'Argument out of bounds.',0x0A,0x00
*** CODE SEGMENT '?PR?sd_Init?T?sd':
28: esint8 sd_Init(hwInterface *iface)
00000000 B570 PUSH {R4-R6,LR}
00000002 1C05 MOV R5,R0 ; iface
00000004 ---- Variable 'iface' assigned to Register 'R5' ----
00000004 ---- Variable 'resp' assigned to Register 'R4' ----
29: {
00000004 ; SCOPE-START
34: i=100;
00000004 2664 MOV R6,#0x64
00000006 ---- Variable 'i' assigned to Register 'R6' ----
35: do{
00000006 L_1:
36: sd_Command(iface,0, 0, 0);
00000006 1C28 MOV R0,R5 ; iface
00000008 2300 MOV R3,#0x0
0000000A 1C19 MOV R1,R3
0000000C 1C1A MOV R2,R3
0000000E F7FF BL sd_Command?T ; T=0x0001 (1)
00000010 FFF7 BL sd_Command?T ; T=0x0001 (2)
37: resp=sd_Resp8b(iface);
00000012 1C28 MOV R0,R5 ; iface
00000014 F7FF BL sd_Resp8b?T ; T=0x0001 (1)
00000016 FFF4 BL sd_Resp8b?T ; T=0x0001 (2)
00000018 1C04 MOV R4,R0 ; resp
38: }
0000001A 0600 LSL R0,R0,#0x18 ; resp
0000001C 0E00 LSR R0,R0,#0x18
0000001E 2801 CMP R0,#0x1
00000020 D005 BEQ L_4 ; T=0x0000002E
00000022 1C30 MOV R0,R6 ; i
00000024 3E01 SUB R6,#0x1
00000026 0436 LSL R6,R6,#0x10
00000028 1436 ASR R6,R6,#0x10
0000002A 2800 CMP R0,#0x0 ; i
0000002C D1EB BNE L_1 ; T=0x00000006
0000002E L_4:
41: if(resp!=1){
0000002E 1C20 MOV R0,R4 ; resp
00000030 0600 LSL R0,R0,#0x18 ; resp
00000032 0E00 LSR R0,R0,#0x18
00000034 2801 CMP R0,#0x1
00000036 D00E BEQ L_6 ; T=0x00000056
42: if(resp==0xff){
00000038 1C20 MOV R0,R4 ; resp
0000003A 0600 LSL R0,R0,#0x18 ; resp
0000003C 0E00 LSR R0,R0,#0x18
0000003E 28FF CMP R0,#0xFF
00000040 D101 BNE L_7 ; T=0x00000046
43: return(-1);
00000042 4800 LDR R0,=0xFFFFFFFF
00000044 E035 B L_8 ; T=0x000000B2
44: }
00000046 L_7:
46: sd_Resp8bError(iface,resp);
00000046 1C20 MOV R0,R4 ; resp
00000048 0601 LSL R1,R0,#0x18 ; resp
0000004A 0E09 LSR R1,R1,#0x18
0000004C 1C28 MOV R0,R5 ; iface
0000004E F7FF BL sd_Resp8bError?T ; T=0x0001 (1)
00000050 FFD7 BL sd_Resp8bError?T ; T=0x0001 (2)
47: return(-2);
00000052 4800 LDR R0,=0xFFFFFFFE
00000054 E02D B L_8 ; T=0x000000B2
49: }
ARM COMPILER V2.42, sd 27/03/06 10:45:52 PAGE 9
00000056 L_6:
53: i=32000;
00000056 4800 LDRH R6,=0x7D00
54: do{
00000058 L_10:
55: sd_Command(iface,1, 0, 0);
00000058 1C28 MOV R0,R5 ; iface
0000005A 2101 MOV R1,#0x1
0000005C 2300 MOV R3,#0x0
0000005E 1C1A MOV R2,R3
00000060 F7FF BL sd_Command?T ; T=0x0001 (1)
00000062 FFCE BL sd_Command?T ; T=0x0001 (2)
57: resp=sd_Resp8b(iface);
00000064 1C28 MOV R0,R5 ; iface
00000066 F7FF BL sd_Resp8b?T ; T=0x0001 (1)
00000068 FFCB BL sd_Resp8b?T ; T=0x0001 (2)
0000006A 1C04 MOV R4,R0 ; resp
58: if(resp!=0)
0000006C 0600 LSL R0,R0,#0x18 ; resp
0000006E 0E00 LSR R0,R0,#0x18
00000070 2800 CMP R0,#0x0
00000072 D005 BEQ L_12 ; T=0x00000080
59: sd_Resp8bError(iface,resp);
00000074 1C20 MOV R0,R4 ; resp
00000076 0601 LSL R1,R0,#0x18 ; resp
00000078 0E09 LSR R1,R1,#0x18
0000007A 1C28 MOV R0,R5 ; iface
0000007C F7FF BL sd_Resp8bError?T ; T=0x0001 (1)
0000007E FFC0 BL sd_Resp8bError?T ; T=0x0001 (2)
60: }
00000080 L_12:
00000080 1C20 MOV R0,R4 ; resp
00000082 0600 LSL R0,R0,#0x18 ; resp
00000084 0E00 LSR R0,R0,#0x18
00000086 2801 CMP R0,#0x1
00000088 D105 BNE L_13 ; T=0x00000096
0000008A 1C30 MOV R0,R6 ; i
0000008C 3E01 SUB R6,#0x1
0000008E 0436 LSL R6,R6,#0x10
00000090 1436 ASR R6,R6,#0x10
00000092 2800 CMP R0,#0x0 ; i
00000094 D1E0 BNE L_10 ; T=0x00000058
00000096 L_13:
63: if(resp!=0){
00000096 1C20 MOV R0,R4 ; resp
00000098 0600 LSL R0,R0,#0x18 ; resp
0000009A 0E00 LSR R0,R0,#0x18
0000009C 2800 CMP R0,#0x0
0000009E D007 BEQ L_16 ; T=0x000000B0
64: sd_Resp8bError(iface,resp);
000000A0 1C20 MOV R0,R4 ; resp
000000A2 0601 LSL R1,R0,#0x18 ; resp
000000A4 0E09 LSR R1,R1,#0x18
000000A6 1C28 MOV R0,R5 ; iface
000000A8 F7FF BL sd_Resp8bError?T ; T=0x0001 (1)
000000AA FFAA BL sd_Resp8bError?T ; T=0x0001 (2)
65: return(-3);
000000AC 4800 LDR R0,=0xFFFFFFFD
000000AE E000 B L_8 ; T=0x000000B2
66: }
000000B0 L_16:
68: return(0);
000000B0 2000 MOV R0,#0x0
000000B2 ; SCOPE-END
69: }
000000B2 L_8:
ARM COMPILER V2.42, sd 27/03/06 10:45:52 PAGE 10
000000B2 BC70 POP {R4-R6}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -