|
最近在学嵌入式,学习USB的代码中有些问题不知道什么意思?
其中“*paddr = (unsigned char *)(addr - 4);”
原文void Usb_Get_Data(unsigned int addr)
{
unsigned short i_st;
unsigned char *paddr = (unsigned char *)(addr - 4);
int length = 0x100000;
int bGetlen = 0;
rNCACHBE0=0x80002000;//设置非CACHE的开始地址0x2000000,结束地址0x8000000
Uart_Printf("Download file from usb......\n");
reconnect_USB();
while(1)
{
i_st = D12_ReadInterruptRegister();//D12_ReadInterruptRegister();
if(i_st != 0)
{
if(i_st & D12_INT_BUSRESET)
{
bus_reset();
bEPPflags.bits.bus_reset = 1;
i_st &= ~D12_INT_BUSRESET;
}
else
{
if(i_st & D12_INT_EOT)
{
dma_eot();
i_st &= ~D12_INT_EOT;
}
if(i_st & D12_INT_SUSPENDCHANGE)
{
bEPPflags.bits.suspend = 1;
i_st &= ~D12_INT_SUSPENDCHANGE;
}
if(i_st & D12_INT_ENDP0IN)
{
ep0_txdone();
i_st &= ~D12_INT_ENDP0IN;
}
if(i_st & D12_INT_ENDP0OUT)
{
ep0_rxdone();
i_st = ~D12_INT_ENDP0OUT;
}
if(i_st & D12_INT_ENDP1IN)
{
ep1_txdone();
i_st &= ~D12_INT_ENDP1IN;
}
if(i_st & D12_INT_ENDP1OUT)
{
{
unsigned char i;
unsigned char len;
D12_ReadLastTransactionStatus(2); /* Clear interrupt flag */
len = D12_ReadEndpoint(2, GenEpBuf, sizeof(GenEpBuf));
if(len != 0)
{
memcpy(paddr, GenEpBuf, len);
paddr += len;
if(bGetlen == 0 && (int)paddr >= (int)addr)
{
length = *((unsigned int *)(addr-4));
Uart_Printf("\r\nDownloading, size = %d(0x%x)... \r\n", length, length);
bGetlen = 1;
}
if((int)paddr >= (int)addr + length)
{
Uart_Printf("Download complete\r\n");
return;
}
Uart_Printf("\rpaddr = 0x%08x, addr = 0x%08x", paddr, addr);
bEPPflags.bits.ep1_rxdone = 1;
}
}
i_st &= ~D12_INT_ENDP1OUT;
}
if(i_st & D12_INT_ENDP2IN)
{
main_txdone();
i_st &= ~D12_INT_ENDP2IN;
}
if(i_st & D12_INT_ENDP2OUT)
{
main_rxdone();
i_st &= ~D12_INT_ENDP2OUT;
}
if(bEPPflags.bits.ep1_rxdone)
{
}
if (bEPPflags.bits.bus_reset) {
DISABLE;
bEPPflags.bits.bus_reset = 0;
ENABLE;
} // if bus reset
if (bEPPflags.bits.suspend) {
DISABLE;
bEPPflags.bits.suspend= 0;
ENABLE;
suspend_change();
} // if suspend change
if (bEPPflags.bits.setup_packet){
DISABLE;
bEPPflags.bits.setup_packet = 0;
ENABLE;
control_handler();
} // if setup_packet
if(bEPPflags.bits.setup_dma) {
DISABLE;
bEPPflags.bits.setup_dma = 0;
ENABLE;
//setup_dma();
} // if setup_dma
}
}
}
}
|
|