📄 main.lss
字号:
1004e6: 7023 strb r3, [r4, #0] 1004e8: 9a01 ldr r2, [sp, #4] 1004ea: 1aab sub r3, r5, r2 1004ec: 429c cmp r4, r3 1004ee: d1f7 bne 1004e0 <rprintf+0x138> 1004f0: e002 b 1004f8 <rprintf+0x150>#endif
while(*ptr) { myputchar(*ptr); ptr++; }
1004f2: ff4bf7ff bl 10038c <myputchar> 1004f6: 3401 add r4, #1 1004f8: 7820 ldrb r0, [r4, #0] 1004fa: 2800 cmp r0, #0 1004fc: d1f9 bne 1004f2 <rprintf+0x14a> 1004fe: e75f b 1003c0 <rprintf+0x18> }
}
}
100500: b006 add sp, #24 100502: bcf0 pop {r4, r5, r6, r7} 100504: bc08 pop {r3} 100506: b004 add sp, #16 100508: 4718 bx r3 10050a: 46c0 nop (mov r8, r8)0010050c <Delays>:extern char card_state; // 0 for no card found, 1 for card found (init successfull)
//---------------------------------------------------------------------
void Delays (unsigned long a) { while (--a!=0); }
10050c: 2300 mov r3, #0 10050e: 3301 add r3, #1 100510: 4283 cmp r3, r0 100512: d1fc bne 10050e <Delays+0x2> 100514: 4770 bx lr ...00100518 <initSPI_port>:
void initSPI_port (void) {
//Card present -> CP - PA15
s_pPio->PIO_ODR = BIT15; //Configure in Input
100518: 4b05 ldr r3, [pc, #20] (100530 <.text+0x530>) 10051a: 681a ldr r2, [r3, #0] 10051c: 2380 mov r3, #128 10051e: 021b lsl r3, r3, #8 100520: 6153 str r3, [r2, #20] s_pPio->PIO_PER = BIT15; //Enable PA15
100522: 6013 str r3, [r2, #0]
//Write protect -> WP - PA16
s_pPio->PIO_ODR = BIT16; //Configure in Input
100524: 2380 mov r3, #128 100526: 025b lsl r3, r3, #9 100528: 6153 str r3, [r2, #20] s_pPio->PIO_PER = BIT16; //Enable PA16
10052a: 6013 str r3, [r2, #0]
}
10052c: 4770 bx lr 10052e: 0000 lsl r0, r0, #0 100530: 0038 lsl r0, r7, #0 100532: 0020 lsl r0, r4, #000100534 <initSPI>:
// setup usart1 in spi mode
void initSPI (void)
{
// Init SPI0
//set functionality to pins:
//port0.12 -> NPCS0
//port0.16 -> MISO
//port0.17 -> MOSI
//port0.18 -> SPCK
s_pPio->PIO_PDR = BIT13 | BIT16 | BIT17 | BIT18;
100534: 4b0e ldr r3, [pc, #56] (100570 <.text+0x570>) 100536: 681a ldr r2, [r3, #0] 100538: 23e4 mov r3, #228 10053a: 02db lsl r3, r3, #11 10053c: 6053 str r3, [r2, #4] s_pPio->PIO_ASR = BIT13 | BIT16 | BIT17 | BIT18;
10053e: 6713 str r3, [r2, #112] s_pPio->PIO_BSR = 0;
100540: 2300 mov r3, #0 100542: 6753 str r3, [r2, #116]
//enable the clock of SPI
s_pPMC->PMC_PCER = 1 << AT91C_ID_SPI0;
100544: 4b0b ldr r3, [pc, #44] (100574 <.text+0x574>) 100546: 681a ldr r2, [r3, #0] 100548: 2310 mov r3, #16 10054a: 6113 str r3, [r2, #16] //l_pPMC->PMC_PCER = 1 << 5;
// Fixed mode
s_pSpi->SPI_CR = 0x81; //SPI Enable, Sowtware reset
10054c: 4b0a ldr r3, [pc, #40] (100578 <.text+0x578>) 10054e: 681a ldr r2, [r3, #0] 100550: 2381 mov r3, #129 100552: 6013 str r3, [r2, #0] s_pSpi->SPI_CR = 0x01; //SPI Enable
100554: 2301 mov r3, #1 100556: 6013 str r3, [r2, #0]
s_pSpi->SPI_MR = 0xD0019; //Master mode, fixed select, disable decoder, FDIV=1 (MCK), PCS=1101
100558: 4b08 ldr r3, [pc, #32] (10057c <.text+0x57c>) 10055a: 6053 str r3, [r2, #4]
//s_pSpi->SPI_CSR[1] = 0x4A02; //8bit, CPOL=0, ClockPhase=1, SCLK = 200kHz
s_pSpi->SPI_CSR[1] = 0x00001F02; //8bit, CPOL=0, ClockPhase=1, SCLK = 48Mhz/32*31 = 48kHz
10055c: 4b08 ldr r3, [pc, #32] (100580 <.text+0x580>) 10055e: 6353 str r3, [r2, #52]
s_pPDC->PDC_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTEN;
100560: 4b08 ldr r3, [pc, #32] (100584 <.text+0x584>) 100562: 4909 ldr r1, [pc, #36] (100588 <.text+0x588>) 100564: 681b ldr r3, [r3, #0] s_pSpi->SPI_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTEN;
100566: 32fc add r2, #252 100568: 6219 str r1, [r3, #32] 10056a: 6251 str r1, [r2, #36]
}
10056c: 4770 bx lr 10056e: 0000 lsl r0, r0, #0 100570: 0038 lsl r0, r7, #0 100572: 0020 lsl r0, r4, #0 100574: 0034 lsl r4, r6, #0 100576: 0020 lsl r0, r4, #0 100578: 003c lsl r4, r7, #0 10057a: 0020 lsl r0, r4, #0 10057c: 0019 lsl r1, r3, #0 10057e: 000d lsl r5, r1, #0 100580: 1f02 sub r2, r0, #4 100582: 0000 lsl r0, r0, #0 100584: 0030 lsl r0, r6, #0 100586: 0020 lsl r0, r4, #0 100588: 0101 lsl r1, r0, #4 ...0010058c <spiSendByte>:
// Initialisieren
char initMMC (void)
{
//raise SS and MOSI for 80 clock cycles
//SendByte(0xff) 10 times with SS high
//RAISE SS
int i;
char response=0x01;
// debug_printf("Start iniMMC......");
initSPI();
//initialization sequence on PowerUp
///CS_HIGH();
for(i=0;i<=9;i++)
spiSendByte(0xff);
///CS_LOW();
//Send Command 0 to put MMC in SPI mode
mmcSendCmd(0x00,0,0x95);
//Now wait for READY RESPONSE
if(mmcGetResponse()!=0x01);
// debug_printf("no responce");
while(response==0x01)
{
// debug_printf("Sending Command 1");
//CS_HIGH();
spiSendByte(0xff);
//CS_LOW();
mmcSendCmd(0x01,0x00,0xff);
response=mmcGetResponse();
}
//CS_HIGH();
spiSendByte(0xff);
// debug_printf("MMC INITIALIZED AND SET TO SPI MODE PROPERLY.");
return MMC_SUCCESS;
}
// Ti added mmc Get Responce
char mmcGetResponse(void)
{
//Response comes 1-8bytes after command
//the first bit will be a 0
//followed by an error code
//data will be 0xff until response
int i=0;
char response;
while(i<=64)
{
response=spiSendByte(0xff);
if(response==0x00)break;
if(response==0x01)break;
i++;
}
return response;
}
char mmcGetXXResponse(const char resp)
{
//Response comes 1-8bytes after command
//the first bit will be a 0
//followed by an error code
//data will be 0xff until response
int i=0;
char response;
while(i<=500)
{
response=spiSendByte(0xff);
if(response==resp)break;
i++;
}
return response;
}
char mmcCheckBusy(void)
{
//Response comes 1-8bytes after command
//the first bit will be a 0
//followed by an error code
//data will be 0xff until response
int i=0;
char response;
char rvalue;
while(i<=64)
{
response=spiSendByte(0xff);
response &= 0x1f;
switch(response)
{
case 0x05: rvalue=MMC_SUCCESS;break;
case 0x0b: return(MMC_CRC_ERROR);
case 0x0d: return(MMC_WRITE_ERROR);
default:
rvalue = MMC_OTHER_ERROR;
break;
}
if(rvalue==MMC_SUCCESS)break;
i++;
}
i=0;
do
{
response=spiSendByte(0xff);
i++;
}while(response==0);
return response;
}
// The card will respond with a standard response token followed by a data
// block suffixed with a 16 bit CRC.
// Ti Modification: long int -> long ; int -> long
char mmcReadBlock(const unsigned long address, const unsigned long count)
{
unsigned long i = 0;
char rvalue = MMC_RESPONSE_ERROR;
// Set the block length to read
if (mmcSetBlockLength (count) == MMC_SUCCESS) // block length could be set
{
//SS = LOW (on)
//CS_LOW ();
// send read command MMC_READ_SINGLE_BLOCK=CMD17
mmcSendCmd (17,address, 0xFF);
// Send 8 Clock pulses of delay, check if the MMC acknowledged the read block command
// it will do this by sending an affirmative response
// in the R1 format (0x00 is no errors)
if (mmcGetResponse() == 0x00)
{
// now look for the data token to signify the start of
// the data
if (mmcGetXXResponse(MMC_START_DATA_BLOCK_TOKEN) == MMC_START_DATA_BLOCK_TOKEN)
{
// clock the actual data transfer and receive the bytes; spi_read automatically finds the Data Block
for (i = 0; i < 512; i++)
mmc_buffer[i] = spiSendByte(0xff); // is executed with card inserted
// get CRC bytes (not really needed by us, but required by MMC)
spiSendByte(0xff);
spiSendByte(0xff);
rvalue = MMC_SUCCESS;
}
else
{
// the data token was never received
rvalue = MMC_DATA_TOKEN_ERROR; // 3
}
}
else
{
// the MMC never acknowledge the read command
rvalue = MMC_RESPONSE_ERROR; // 2
}
}
else
{
rvalue = MMC_BLOCK_SET_ERROR; // 1
}
//CS_HIGH ();
spiSendByte(0xff);
return rvalue;
} // mmc_read_block
//---------------------------------------------------------------------
// Ti Modification: long int -> long
char mmcWriteBlock (const unsigned long address)
{
unsigned long i = 0;
char rvalue = MMC_RESPONSE_ERROR; // MMC_SUCCESS;
//char c = 0x00;
// Set the block length to read
if (mmcSetBlockLength (512) == MMC_SUCCESS) // block length could be set
{
// SS = LOW (on)
//CS_LOW ();
// send write command
mmcSendCmd (24,address, 0xFF);
// check if the MMC acknowledged the write block command
// it will do this by sending an affirmative response
// in the R1 format (0x00 is no errors)
if (mmcGetXXResponse(MMC_R1_RESPONSE) == MMC_R1_RESPONSE)
{
spiSendByte(0xff);
// send the data token to signify the start of the data
spiSendByte(0xfe);
// clock the actual data transfer and transmitt the bytes
for (i = 0; i < 512; i++)
spiSendByte(mmc_buffer[i]); // mmc_buffer[i]; Test: i & 0xff
// put CRC bytes (not really needed by us, but required by MMC)
spiSendByte(0xff);
spiSendByte(0xff);
// read the data response xxx0<status>1 : status 010: Data accected, status 101: Data
// rejected due to a crc error, status 110: Data rejected due to a Write error.
mmcCheckBusy();
}
else
{
// the MMC never acknowledge the write command
rvalue = MMC_RESPONSE_ERROR; // 2
}
}
else
{
rvalue = MMC_BLOCK_SET_ERROR; // 1
}
//give the MMC the required clocks to finish up what ever it needs to do
//for (i = 0; i < 9; ++i)
//spiSendByte(0xff);
//CS_HIGH ();
// Send 8 Clock pulses of delay.
spiSendByte(0xff);
return rvalue;
}// mmc_write_block
//---------------------------------------------------------------------
void mmcSendCmd (const char cmd, unsigned long data, const char crc)
{
char frame[6];
char temp;
int i;
frame[0]=(cmd|0x40);
for(i=3;i>=0;i--){
temp=(char)(data>>(8*i));
frame[4-i]=(temp);
}
frame[5]=(crc);
for(i=0;i<6;i++)
spiSendByte(frame[i]);
}
//--------------- set blocklength 2^n ------------------------------------------------------
// Ti Modification: long int-> long
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -