您的位置 首页 软件

2440下的USB试验

staticvoid__irqIsrUsbd(void){U8usbdIntpnd,epIntpnd;U8saveIndexReg=rINDEX_REG;保存索引寄存器值(现场保护)usbdInt

static void __irq IsrUsbd(void)

{
U8 usbdIntpnd, epIntpnd;
U8 saveIndexReg = rINDEX_REG; //保存索引寄存器值(现场维护)
usbdIntpnd = rUSB_INT_REG;//保存中止标志寄存器
epIntpnd = rEP_INT_REG;

if(usbdIntpnd&SUSPEND_INT)//总线上超越 3ms 没有活动信号引起中止
{
rUSB_INT_REG = SUSPEND_INT;//铲除中止标志位
}

if(usbdIntpnd&RESUME_INT)
{
rUSB_INT_REG = RESUME_INT; //康复引起的中止
}

if(usbdIntpnd&RESET_INT)//接收到复位信号引起的中止
{
//ResetUsbd();
ReconfigUsbd();//重新配置 USB device
rUSB_INT_REG = RESET_INT; //RESET_INT should be cleared after ResetUsbd().
PrepareEp1Fifo();
}

if(epIntpnd&EP0_INT)//端点 0 中止
{
rEP_INT_REG = EP0_INT;
Ep0Handler();//进入操控传输中止处理程序
}

if(epIntpnd&EP1_INT)
{
rEP_INT_REG=EP1_INT;
Ep1Handler();//进入 Ep1 中止处理程序(BULK IN)
}

if(epIntpnd&EP2_INT)
{
rEP_INT_REG = EP2_INT;
//Ep2Handler();
}

if(epIntpnd&EP3_INT)
{
rEP_INT_REG = EP3_INT;
Ep3Handler();//进入 Ep3 中止处理程序(BULK OUT)
}

if(epIntpnd&EP4_INT)
{
rEP_INT_REG = EP4_INT;
//Ep4Handler();
}

ClearPending(BIT_USBD);//USB 设备中止处理完毕,铲除中止标志位
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 GPH10–>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;//GPG9 input

if(len>0) {

Uart_Printf(“nUSB download finished,press any key to exitn”);

}

return len;

}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qianrushi/ruanjian/258945.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部