📄 sdmmc.s
字号:
cpi R24,100
ldi R30,0
cpc R25,R30
brlo L89
.dbline 393
; {
; Read_Byte_MMC(); //此处会产生死等待
; }
;
; //Send Start Byte to MMC/SD-Card
; Write_Byte_MMC(0xFE);
ldi R16,254
xcall _Write_Byte_MMC
.dbline 396
;
; //Now send real data Bolck (512Bytes) to MMC/SD-Card
; for (i=0;i<512;i++)
clr R10
clr R11
xjmp L96
L93:
.dbline 397
.dbline 398
ldd R30,y+22
ldd R31,y+23
ld R16,Z+
std y+23,R31
std y+22,R30
xcall _Write_Byte_MMC
.dbline 399
L94:
.dbline 396
movw R24,R10
adiw R24,1
movw R10,R24
L96:
.dbline 396
movw R24,R10
cpi R24,0
ldi R30,2
cpc R25,R30
brlo L93
.dbline 402
; {
; Write_Byte_MMC(*Buffer++); //send 512 bytes to Card
; }
;
; //CRC-Byte
; Write_Byte_MMC(0xFF); //Dummy CRC
ldi R16,255
xcall _Write_Byte_MMC
.dbline 403
; Write_Byte_MMC(0xFF); //CRC Code
ldi R16,255
xcall _Write_Byte_MMC
.dbline 406
;
;
; tmp=Read_Byte_MMC(); // read response
xcall _Read_Byte_MMC
mov R12,R16
.dbline 407
; if((tmp & 0x1F)!=0x05) // data block accepted ?
mov R24,R12
andi R24,31
cpi R24,5
breq L100
.dbline 408
; {
.dbline 409
; MMC_Disable();
sbi 0x18,4
.dbline 409
.dbline 411
; #if !(HW_SPI_Mode)
; SPCR=spimode;
ldd R0,y+6
out 0xd,R0
.dbline 412
; SPSR=spispeeddub;
ldd R0,y+7
out 0xe,R0
.dbline 414
; #endif
; return(FALSE); //Error!
clr R16
xjmp L79
L99:
.dbline 417
.dbline 417
L100:
.dbline 417
; }
; //Wait till MMC/SD-Card is not busy
; while (Read_Byte_MMC()!=0xff){};
xcall _Read_Byte_MMC
cpi R16,255
brne L99
.dbline 417
.dbline 420
;
; //set MMC_Chip_Select to high (MMC/SD-Card Invalid)
; MMC_Disable();
sbi 0x18,4
.dbline 420
.dbline 422
; #if !(HW_SPI_Mode)
; SPCR=spimode;
ldd R0,y+6
out 0xd,R0
.dbline 423
; SPSR=spispeeddub;
ldd R0,y+7
out 0xe,R0
.dbline 425
; #endif
; return(TRUE);
ldi R16,1
.dbline -2
L79:
adiw R28,8
xcall pop_gset5
adiw R28,4
.dbline 0 ; func end
ret
.dbsym l spispeeddub 7 c
.dbsym l spimode 6 c
.dbsym l CMD 0 A[6:6]c
.dbsym r retry 14 c
.dbsym r tmp 12 c
.dbsym r i 10 i
.dbsym l Buffer 22 pc
.dbsym l addr 18 l
.dbend
.dbfunc e MMC_Read_Block _MMC_Read_Block fc
; spispeeddub -> R20
; spimode -> R22
; temp -> R12
; retry -> R10
; i -> R12,R13
; Bytes -> R14,R15
; Buffer -> y+12
; CMD -> y+10
.even
_MMC_Read_Block::
xcall push_arg4
xcall push_gset5
ldd R14,y+14
ldd R15,y+15
.dbline -1
.dbline 433
; }
;
; //****************************************************************************
; //Routine for reading data Registers of MMC/SD-Card
; //Return 0 if no Error.
; uint8 MMC_Read_Block(uint8 *CMD,uint8 *Buffer,uint16 Bytes)
; //****************************************************************************
; {
.dbline 438
; uint16 i;
; uint8 retry,temp;
; #if !(HW_SPI_Mode)
; uint8 spimode,spispeeddub;
; spimode=SPCR;
in R22,0xd
.dbline 439
; spispeeddub=SPSR;
in R20,0xe
.dbline 440
; SPCR&=~(1<<SPIE);
cbi 0xd,7
.dbline 443
; #endif
; //Send Command CMD to MMC/SD-Card
; retry=0;
clr R10
L103:
.dbline 445
; do
; { //Retry 100 times to send command.
.dbline 446
; temp=Write_Command_MMC(CMD);
ldd R16,y+10
ldd R17,y+11
xcall _Write_Command_MMC
mov R12,R16
.dbline 447
; retry++;
inc R10
.dbline 448
; if(retry==100)
mov R24,R10
cpi R24,100
brne L106
.dbline 449
; {
.dbline 451
; #if !(HW_SPI_Mode)
; SPCR=spimode;
out 0xd,R22
.dbline 452
; SPSR=spispeeddub;
out 0xe,R20
.dbline 454
; #endif
; return(READ_BLOCK_ERROR); //block read Error!
ldi R16,4
xjmp L102
L106:
.dbline 456
; }
; }
L104:
.dbline 457
; while(temp!=0);
tst R12
brne L103
L108:
.dbline 460
.dbline 460
L109:
.dbline 460
;
; //Read Start Byte form MMC/SD-Card (FEh/Start Byte)
; while (Read_Byte_MMC() != 0xfe){};
xcall _Read_Byte_MMC
cpi R16,254
brne L108
.dbline 460
.dbline 463
;
; //Write blocks(normal 512Bytes) to MMC/SD-Card
; for (i=0;i<Bytes;i++)
clr R12
clr R13
xjmp L114
L111:
.dbline 464
.dbline 465
xcall _Read_Byte_MMC
mov R2,R16
ldd R30,y+12
ldd R31,y+13
st Z+,R2
std y+13,R31
std y+12,R30
.dbline 466
L112:
.dbline 463
movw R24,R12
adiw R24,1
movw R12,R24
L114:
.dbline 463
cp R12,R14
cpc R13,R15
brlo L111
.dbline 469
; {
; *Buffer++ = Read_Byte_MMC();
; }
;
; //CRC-Byte
; Read_Byte_MMC();//CRC - Byte
xcall _Read_Byte_MMC
.dbline 470
; Read_Byte_MMC();//CRC - Byte
xcall _Read_Byte_MMC
.dbline 473
;
; //set MMC_Chip_Select to high (MMC/SD-Card invalid)
; MMC_Disable();
sbi 0x18,4
.dbline 473
.dbline 475
; #if !(HW_SPI_Mode)
; SPCR=spimode;
out 0xd,R22
.dbline 476
; SPSR=spispeeddub;
out 0xe,R20
.dbline 478
; #endif
; return(0);
clr R16
.dbline -2
L102:
xcall pop_gset5
adiw R28,4
.dbline 0 ; func end
ret
.dbsym r spispeeddub 20 c
.dbsym r spimode 22 c
.dbsym r temp 12 c
.dbsym r retry 10 c
.dbsym r i 12 i
.dbsym r Bytes 14 i
.dbsym l Buffer 12 pc
.dbsym l CMD 10 pc
.dbend
.area lit(rom, con, rel)
L116:
.byte 'Q,0
.byte 0,0
.byte 0,255
.area text(rom, con, rel)
.dbfile D:\桌面\mp3\sdmmc\sdmmc.c
.dbfunc e MMC_Read_Sector _MMC_Read_Sector fc
; temp -> <dead>
; CMD -> y+2
; Buffer -> y+16
; addr -> y+12
.even
_MMC_Read_Sector::
xcall push_arg4
xcall push_gset2
sbiw R28,8
.dbline -1
.dbline 487
; }
;
;
; //****************************************************************************
; //Routine for reading Blocks(512Byte) from MMC/SD-Card
; //Return 0 if no Error.
; uint8 MMC_Read_Sector(uint32 addr,uint8 *Buffer)
; //****************************************************************************
; {
.dbline 489
; //Command 16 is reading Blocks from MMC/SD-Card
; uint8 CMD[] = {0x51,0x00,0x00,0x00,0x00,0xFF};
ldi R24,<L116
ldi R25,>L116
movw R30,R28
adiw R30,2
ldi R16,6
ldi R17,0
st -y,R31
st -y,R30
st -y,R25
st -y,R24
xcall asgncblk
.dbline 494
; uint8 temp;
;
; //#asm("cli"); //clear all interrupt.
; //Address conversation(logic block address-->byte address)
; addr = addr << 9; //addr = addr * 512
ldi R24,9
ldi R25,0
movw R30,R28
ldd R2,z+12
ldd R3,z+13
ldd R4,z+14
ldd R5,z+15
st -y,R24
movw R16,R2
movw R18,R4
xcall lsl32
movw R30,R28
std z+12,R16
std z+13,R17
std z+14,R18
std z+15,R19
.dbline 496
;
; CMD[1] = ((addr & 0xFF000000) >>24 );
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,255
movw R30,R28
ldd R2,z+12
ldd R3,z+13
ldd R4,z+14
ldd R5,z+15
and R2,R20
and R3,R21
and R4,R22
and R5,R23
ldi R24,24
ldi R25,0
st -y,R24
movw R16,R2
movw R18,R4
xcall lsr32
std y+3,R16
.dbline 497
; CMD[2] = ((addr & 0x00FF0000) >>16 );
ldi R20,0
ldi R21,0
ldi R22,255
ldi R23,0
movw R30,R28
ldd R2,z+12
ldd R3,z+13
ldd R4,z+14
ldd R5,z+15
and R2,R20
and R3,R21
and R4,R22
and R5,R23
movw R2,R4
clr R4
clr R5
std y+4,R2
.dbline 498
; CMD[3] = ((addr & 0x0000FF00) >>8 );
ldi R20,0
ldi R21,255
ldi R22,0
ldi R23,0
movw R30,R28
ldd R2,z+12
ldd R3,z+13
ldd R4,z+14
ldd R5,z+15
and R2,R20
and R3,R21
and R4,R22
and R5,R23
ldi R24,8
ldi R25,0
st -y,R24
movw R16,R2
movw R18,R4
xcall lsr32
std y+5,R16
.dbline 500
;
; if (MMC_Read_Block(CMD,Buffer,512)==READ_BLOCK_ERROR)
ldi R24,512
ldi R25,2
std y+1,R25
std y+0,R24
ldd R18,y+16
ldd R19,y+17
movw R16,R28
subi R16,254 ; offset = 2
sbci R17,255
xcall _MMC_Read_Block
cpi R16,4
brne L120
.dbline 501
; {
.dbline 502
; return FALSE;
clr R16
xjmp L115
L120:
.dbline 505
; }
; else
; {
.dbline 506
; return TRUE;
ldi R16,1
.dbline -2
L115:
adiw R28,8
xcall pop_gset2
adiw R28,4
.dbline 0 ; func end
ret
.dbsym l temp 3 c
.dbsym l CMD 2 A[6:6]c
.dbsym l Buffer 16 pc
.dbsym l addr 12 l
.dbend
.area lit(rom, con, rel)
L123:
.byte 'J,0
.byte 0,0
.byte 0,255
.area text(rom, con, rel)
.dbfile D:\桌面\mp3\sdmmc\sdmmc.c
.dbfunc e Read_CID_MMC _Read_CID_MMC fc
; temp -> R20
; CMD -> y+2
; Buffer -> R20,R21
.even
_Read_CID_MMC::
xcall push_gset1
movw R20,R16
sbiw R28,8
.dbline -1
.dbline 515
; }
; }
;
; //***************************************************************************
; //Routine for reading CID Registers from MMC/SD-Card (16Bytes)
; //Return 0 if no Error.
; uint8 Read_CID_MMC(uint8 *Buffer)
; //***************************************************************************
; {
.dbline 517
; //Command for reading CID Registers
; uint8 CMD[] = {0x4A,0x00,0x00,0x00,0x00,0xFF};
ldi R24,<L123
ldi R25,>L123
movw R30,R28
adiw R30,2
ldi R16,6
ldi R17,0
st -y,R31
st -y,R30
st -y,R25
st -y,R24
xcall asgncblk
.dbline 519
; uint8 temp;
; temp=MMC_Read_Block(CMD,Buffer,16); //read 16 bytes
ldi R24,16
ldi R25,0
std y+1,R25
std y+0,R24
movw R18,R20
movw R16,R28
subi R16,254 ; offset = 2
sbci R17,255
xcall _MMC_Read_Block
mov R20,R16
.dbline 520
; return(temp);
.dbline -2
L122:
adiw R28,8
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r temp 20 c
.dbsym l CMD 2 A[6:6]c
.dbsym r Buffer 20 pc
.dbend
.area lit(rom, con, rel)
L125:
.byte 'I,0
.byte 0,0
.byte 0,255
.area text(rom, con, rel)
.dbfile D:\桌面\mp3\sdmmc\sdmmc.c
.dbfunc e Read_CSD_MMC _Read_CSD_MMC fc
; temp -> R20
; CMD -> y+2
; Buffer -> R20,R21
.even
_Read_CSD_MMC::
xcall push_gset1
movw R20,R16
sbiw R28,8
.dbline -1
.dbline 528
; }
;
; //***************************************************************************
; //Routine for reading CSD Registers from MMC/SD-Card (16Bytes)
; //Return 0 if no Error.
; uint8 Read_CSD_MMC(uint8 *Buffer)
; //***************************************************************************
; {
.dbline 530
; //Command for reading CSD Registers
; uint8 CMD[] = {0x49,0x00,0x00,0x00,0x00,0xFF};
ldi R24,<L125
ldi R25,>L125
movw R30,R28
adiw R30,2
ldi R16,6
ldi R17,0
st -y,R31
st -y,R30
st -y,R25
st -y,R24
xcall asgncblk
.dbline 532
; uint8 temp;
; temp=MMC_Read_Block(CMD,Buffer,16); //read 16 bytes
ldi R24,16
ldi R25,0
std y+1,R25
std y+0,R24
movw R18,R20
movw R16,R28
subi R16,254 ; offset = 2
sbci R17,255
xcall _MMC_Read_Block
mov R20,R16
.dbline 534
;
; return(temp);
.dbline -2
L124:
adiw R28,8
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r temp 20 c
.dbsym l CMD 2 A[6:6]c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -