📄 mmc.lst
字号:
258
259 //****************************************************************************
260 //Routine for writing a Block(512Byte) to MMC/SD-Card
261 //Return 0 if sector writing is completed.
\ In segment CODE, align 4, keep-with-next
262 unsigned char MMC_write_sector(unsigned long addr,unsigned char *Buffer)
263 //****************************************************************************
264 {
\ MMC_write_sector:
\ 00000000 F0B5 PUSH {R4-R7,LR}
\ 00000002 83B0 SUB SP,#+0xC
\ 00000004 041C MOV R4,R0
\ 00000006 0D1C MOV R5,R1
265 unsigned char tmp,retry;
266 unsigned int i;
267 // Command 24 is a 写数据块命令.
268 // 根据协议,命令共6字节,首字节为:开始位+传输位+命令编号,接下来四个字节为命令参数(此为地址)
269 // 最后一字节为 7bit CRC + 1bit停止位
270 unsigned char CMD[] = {0x58,0x00,0x00,0x00,0x00,0xFF}; // 0x58 =1011000
\ 00000008 01A8 ADD R0,SP,#+0x4
\ 0000000A 3249 LDR R1,??MMC_write_sector_0 ;; `?<Constant {88, 0, 0, 0, 0, 255}>`
\ 0000000C 0A68 LDR R2,[R1, #0]
\ 0000000E 0260 STR R2,[R0, #0]
\ 00000010 4A68 LDR R2,[R1, #+0x4]
\ 00000012 4260 STR R2,[R0, #+0x4]
271 //24 =11000
272 AT91F_PIO_GetInterruptStatus(AT91C_BASE_PIOA); //clear all interrupt.
\ 00000014 .... LDR R0,??DataTable22 ;; 0xfffff400
\ 00000016 ........ _BLF AT91F_PIO_GetInterruptStatus,AT91F_PIO_GetInterruptStatus??rT
273 addr = addr << 9; //addr = addr * 512
\ 0000001A 6402 LSL R4,R4,#+0x9
274
275 CMD[1] = ((addr & 0xFF000000) >>24 ); // [25~32]
\ 0000001C 01A8 ADD R0,SP,#+0x4
\ 0000001E 211C MOV R1,R4
\ 00000020 090E LSR R1,R1,#+0x18
\ 00000022 4170 STRB R1,[R0, #+0x1]
276 CMD[2] = ((addr & 0x00FF0000) >>16 );
\ 00000024 01A8 ADD R0,SP,#+0x4
\ 00000026 211C MOV R1,R4
\ 00000028 090C LSR R1,R1,#+0x10
\ 0000002A 8170 STRB R1,[R0, #+0x2]
277 CMD[3] = ((addr & 0x0000FF00) >>8 ) ;
\ 0000002C 01A8 ADD R0,SP,#+0x4
\ 0000002E 211C MOV R1,R4
\ 00000030 090A LSR R1,R1,#+0x8
\ 00000032 C170 STRB R1,[R0, #+0x3]
278
279 //Send Command CMD24 to MMC/SD-Card (Write 1 Block/512 Bytes)
280 retry=0;
\ 00000034 0020 MOV R0,#+0
\ 00000036 061C MOV R6,R0
281 do
282 { //Retry 100 times to send command.
283 tmp=Write_Command_MMC(CMD);
\ ??MMC_write_sector_1:
\ 00000038 01A8 ADD R0,SP,#+0x4
\ 0000003A ........ BL Write_Command_MMC
\ 0000003E 6946 MOV R1,SP
\ 00000040 0870 STRB R0,[R1, #+0]
284 retry++;
\ 00000042 761C ADD R6,#+0x1
285 if(retry==100)
\ 00000044 3606 LSL R6,R6,#+0x18 ;; ZeroExt R6,R6,#+0x18,#+0x18
\ 00000046 360E LSR R6,R6,#+0x18
\ 00000048 642E CMP R6,#+0x64
\ 0000004A 02D1 BNE ??MMC_write_sector_2
286 {
287 return(tmp); //send commamd Error!
\ 0000004C 6846 MOV R0,SP
\ 0000004E 0078 LDRB R0,[R0, #+0]
\ 00000050 3BE0 B ??MMC_write_sector_3
288 }
289 }
290 while(tmp!=0);
\ ??MMC_write_sector_2:
\ 00000052 6846 MOV R0,SP
\ 00000054 0078 LDRB R0,[R0, #+0]
\ 00000056 0028 CMP R0,#+0
\ 00000058 EED1 BNE ??MMC_write_sector_1
291
292 //Before writing,send 100 clock to MMC/SD-Card
293 for (i=0;i<100;i++)
\ 0000005A 0020 MOV R0,#+0
\ 0000005C 071C MOV R7,R0
\ ??MMC_write_sector_4:
\ 0000005E 642F CMP R7,#+0x64
\ 00000060 03D2 BCS ??MMC_write_sector_5
294 {
295 Read_Byte_MMC();
\ 00000062 ........ BL Read_Byte_MMC
296 }
\ 00000066 7F1C ADD R7,#+0x1
\ 00000068 F9E7 B ??MMC_write_sector_4
297
298 //Send Start Byte to MMC/SD-Card
299 Write_Byte_MMC(0xFE);
\ ??MMC_write_sector_5:
\ 0000006A FE20 MOV R0,#+0xFE
\ 0000006C ........ BL Write_Byte_MMC
300
301 //Now send real data Bolck (512Bytes) to MMC/SD-Card
302 for (i=0;i<512;i++)
\ 00000070 0020 MOV R0,#+0
\ 00000072 071C MOV R7,R0
\ ??MMC_write_sector_6:
\ 00000074 8020 MOV R0,#+0x80
\ 00000076 8000 LSL R0,R0,#+0x2 ;; #+0x200
\ 00000078 8742 CMP R7,R0
\ 0000007A 05D2 BCS ??MMC_write_sector_7
303 {
304 Write_Byte_MMC(*Buffer++); //send 512 bytes to Card
\ 0000007C 2878 LDRB R0,[R5, #+0]
\ 0000007E ........ BL Write_Byte_MMC
\ 00000082 6D1C ADD R5,#+0x1
305 }
\ 00000084 7F1C ADD R7,#+0x1
\ 00000086 F5E7 B ??MMC_write_sector_6
306
307 //CRC-Byte
308 Write_Byte_MMC(0xFF); //Dummy CRC
\ ??MMC_write_sector_7:
\ 00000088 FF20 MOV R0,#+0xFF
\ 0000008A ........ BL Write_Byte_MMC
309 Write_Byte_MMC(0xFF); //CRC Code
\ 0000008E FF20 MOV R0,#+0xFF
\ 00000090 ........ BL Write_Byte_MMC
310
311
312 tmp=Read_Byte_MMC(); // read response
\ 00000094 ........ BL Read_Byte_MMC
\ 00000098 6946 MOV R1,SP
\ 0000009A 0870 STRB R0,[R1, #+0]
313 if((tmp & 0x1F)!=0x05) // data block accepted ? 检测后8位,
\ 0000009C 6846 MOV R0,SP
\ 0000009E 0078 LDRB R0,[R0, #+0]
\ 000000A0 C006 LSL R0,R0,#+0x1B ;; ZeroExt R0,R0,#+0x1B,#+0x1B
\ 000000A2 C00E LSR R0,R0,#+0x1B
\ 000000A4 0528 CMP R0,#+0x5
\ 000000A6 06D0 BEQ ??MMC_write_sector_8
314 {
315 AT91F_PIO_SetOutput(AT91C_BASE_PIOA,MMC_Chip_Select) ;
\ 000000A8 8021 MOV R1,#+0x80
\ 000000AA 8901 LSL R1,R1,#+0x6 ;; #+0x2000
\ 000000AC .... LDR R0,??DataTable22 ;; 0xfffff400
\ 000000AE ........ _BLF AT91F_PIO_SetOutput,AT91F_PIO_SetOutput??rT
316 return(WRITE_BLOCK_ERROR); //Error!
\ 000000B2 0320 MOV R0,#+0x3
\ 000000B4 09E0 B ??MMC_write_sector_3
317 }
318 //Wait till MMC/SD-Card is not busy
319 while (Read_Byte_MMC()!=0xff){}; //等待命令结束 最后一位为 1
\ ??MMC_write_sector_8:
\ 000000B6 ........ BL Read_Byte_MMC
\ 000000BA FF28 CMP R0,#+0xFF
\ 000000BC FBD1 BNE ??MMC_write_sector_8
320
321 //set MMC_Chip_Select to high (MMC/SD-Card Invalid)
322 AT91F_PIO_SetOutput(AT91C_BASE_PIOA,MMC_Chip_Select) ;
\ 000000BE 8021 MOV R1,#+0x80
\ 000000C0 8901 LSL R1,R1,#+0x6 ;; #+0x2000
\ 000000C2 .... LDR R0,??DataTable22 ;; 0xfffff400
\ 000000C4 ........ _BLF AT91F_PIO_SetOutput,AT91F_PIO_SetOutput??rT
323 return(0);
\ 000000C8 0020 MOV R0,#+0
\ ??MMC_write_sector_3:
\ 000000CA 03B0 ADD SP,#+0xC
\ 000000CC F0BC POP {R4-R7}
\ 000000CE 02BC POP {R1}
\ 000000D0 0847 BX R1 ;; return
\ 000000D2 C046 NOP
\ ??MMC_write_sector_0:
\ 000000D4 ........ DC32 `?<Constant {88, 0, 0, 0, 0, 255}>`
324 }
325
326 //****************************************************************************
327 //Routine for reading data Registers of MMC/SD-Card
328 //Return 0 if no Error.
\ In segment CODE, align 4, keep-with-next
329 unsigned char MMC_Read_Block(unsigned char *CMD,unsigned char *Buffer,unsigned int Bytes)
330 //****************************************************************************
331 {
\ MMC_Read_Block:
\ 00000000 F5B5 PUSH {R0,R2,R4-R7,LR}
\ 00000002 0C1C MOV R4,R1
332 unsigned int i; unsigned retry,temp;
333
334 //Send Command CMD to MMC/SD-Card
335 retry=0;
\ 00000004 0020 MOV R0,#+0
\ 00000006 061C MOV R6,R0
336 do
337 { //Retry 100 times to send command.
338 temp=Write_Command_MMC(CMD); //检测后7比特 ,
\ ??MMC_Read_Block_0:
\ 00000008 0098 LDR R0,[SP, #+0]
\ 0000000A ........ BL Write_Command_MMC
\ 0000000E 071C MOV R7,R0
339 retry++;
\ 00000010 761C ADD R6,#+0x1
340 if(retry==100)
\ 00000012 642E CMP R6,#+0x64
\ 00000014 01D1 BNE ??MMC_Read_Block_1
341 {
342 return(READ_BLOCK_ERROR); //block write Error!
\ 00000016 0420 MOV R0,#+0x4
\ 00000018 1AE0 B ??MMC_Read_Block_2
343 }
344 }
345 while(temp!=0);
\ ??MMC_Read_Block_1:
\ 0000001A 002F CMP R7,#+0
\ 0000001C F4D1 BNE ??MMC_Read_Block_0
346
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -