2440下的USB实验
{
U8 usbdIntpnd, epIntpnd;
U8 saveIndexReg = rINDEX_REG;
usbdIntpnd = rUSB_INT_REG;
epIntpnd = rEP_INT_REG;
if(usbdIntpnd&SUSPEND_INT)
{
rUSB_INT_REG = SUSPEND_INT;//清除中断标志位
}
if(usbdIntpnd&RESUME_INT)
{
rUSB_INT_REG = RESUME_INT; //恢复引起的中断
}
if(usbdIntpnd&RESET_INT)
{
//ResetUsbd();
ReconfigUsbd();
rUSB_INT_REG = RESET_INT;
PrepareEp1Fifo();
}
if(epIntpnd&EP0_INT)
{
rEP_INT_REG = EP0_INT;
Ep0Handler();
}
if(epIntpnd&EP1_INT)
{
rEP_INT_REG=EP1_INT;
Ep1Handler();
}
if(epIntpnd&EP2_INT)
{
rEP_INT_REG = EP2_INT;
//Ep2Handler();
}
if(epIntpnd&EP3_INT)
{
rEP_INT_REG = EP3_INT;
Ep3Handler();
}
if(epIntpnd&EP4_INT)
{
rEP_INT_REG = EP4_INT;
//Ep4Handler();
}
ClearPending(BIT_USBD);
rINDEX_REG = saveIndexReg;
}
6.2 端点 1 的数据传输程序
void Ep1Handler(void)
{
U8 in_csr1;
rINDEX_REG = 1;
in_csr1 = rIN_CSR1_REG;
//I think that EPI_SENT_STALL will not be set to 1.
if(in_csr1 & EPI_SENT_STALL) //USB 已经发布了一个 STALL 握手信号,由此引起该中断
{
CLR_EP1_SENT_STALL();//清除 SENT_STALL 位,STALL 状态结束
return;
}
//IN_PKT_READY is cleared
//The data transfered was ep1Buf[] which was already configured transferIndex++;
if(UsbState==0x01234567)
PrepareEp1Fifo();//准备好发送的数据,把 IN_PKT_READY 置位
//IN_PKT_READY is set
//This packit will be used for next IN packit.
return;
}
6.3 USB Device 初始化函数
void UsbdInit(U8 fun)
{
isUsbdSetConfiguration = 0;
//Mdiv=40,Pdiv=4,Sdiv=1
//Upll = (m * Fin) / (p * 2**s)
//m = (Mdiv + 8), p = (Pdiv + 2), s = Sdiv
//Upll=48MHz
rUPLLCON = (40<12) | (4<4) | 1;
//初始化描述符 InitDescriptorTable(fun); ReconfigUsbd();
UsbState = 0;
}
6.4 USB 下载函数
static int BoardUsbDownload(U32 addr, U32 run)
{
U8 fun;
int len;
//GPH9-->output
rGPHCON = rGPHCON&~(0xf<18)|(0x5<18);
//GPG9-->input
rGPGCON &= 0xfff3ffff;
fun = 1;
//USB Device 初始化 UsbdInit(fun); Delay(100);
//GPG9-->output rGPGCON |= 0x00040000;
//GPG9 ouput 1
rGPGDAT |= 0x0200;
//中断服务程序
pISR_USBD =(unsigned)IsrUsbd; ClearPending(BIT_USBD); EnableIrq(BIT_USBD);
len = WaitDownload(addr); DisableIrq(BIT_USBD);
rGPGCON &= 0xfff3ffff;
if(len>0) {
Uart_Printf("nUSB download finished,press any key to exitn");
}
return len;
}
2440USB实 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)