stevenwin
驱动牛犊
驱动牛犊
  • 注册日期2008-03-29
  • 最后登录2008-07-02
  • 粉丝0
  • 关注0
  • 积分120分
  • 威望13点
  • 贡献值0点
  • 好评度12点
  • 原创分0分
  • 专家分0分
阅读:1498回复:7

ISP1161host问题求助

楼主#
更多 发布于:2008-03-31 16:49
我正在用PHILIPS1161做USB HOST的开发,遇到一问题始终过不去,请大家帮帮忙

void USB_Host_Exception()
{
    uint8 i;
    //uint16 temp;
    uint32 st1,st2,ist;
    uint8 addr;
    
    addr=0;
    
  
    st1= READ_32BIT_REG(HcRhPortStatus1);
    st2= READ_32BIT_REG(HcRhPortStatus2);
    ist=READ_32BIT_REG(HcInterruptStatus);
    
   /* if((st1&0x0200)||(st2&0x0200))
        device_speed=low_speed;
    else
        device_speed=full_speed;*/
        
        device_speed=1;
    
    if((st1&0x00000001)||(st2&0x00000001))//有设备连上,则进行枚举
    {
      
        WRITE_32BIT_REG(HcuPInterrupt,0x04); //Clear EOT interrupt bit
 
        //第一个控制建立数据包Setup
        make_control_ptd((uint16 *)c_ptd,SETUP,1,0,8,0,addr);
        send_control(c_ptd,rb_ptr,0x0680,0x0100,0x0000,0x0012,16);
        
        //IN
        make_control_ptd((uint16 *)c_ptd,IN,1,0,16,1,addr);
        send_control(c_ptd,rb_ptr,0x0000,0x0000,0x0000,0x0000,24);
        
        
        //out空包
        make_control_ptd((uint16 *)c_ptd, OUT, 1, 0, 0,1,addr);
        send_control(c_ptd,rb_ptr,0x0000,0x0000,0x0000,0x0000,8); //发送0长度包来结束传输
      
    }
}

void write_atl(uint16 *a_ptr, uint16 data_size)
{
    uint32 cnt;
    uint16 temp;
 
    WRITE_16BIT_REG(HcTransferCounter,data_size*2);
    
    //debug
   // WRITE_16BIT_REG(HcTransferCounter, 0x0040);
    temp = READ_16BIT_REG(HcTransferCounter);
    
    
    if(temp==0)
        return;
        
        
    //debug
    //读HcBufferStatus Register
    READ_16BIT_REG(HcBufferStatus);//此时bit[2]为0,empty
  
    outw(COMMAND_PORT,HcATLBufferPort|0x80);
  
     //关中断
    interrupt_disable();
    
    
    
    cnt=0;
    do
    {
        outw(DATA_PORT,*(a_ptr+cnt));
        cnt++;
         outw(DATA_PORT,*(a_ptr+cnt));
        cnt++;
      
     }
   // while(cnt<(data_size));
   while(cnt<(data_size/2));

        //开中断
        interrupt_enable();
    
    
     //debug
    //读HcBufferStatus Register
    READ_16BIT_REG(HcBufferStatus);//此时bit[2]为1,full  
    
      //debug
       outw(COMMAND_PORT,HcATLBufferPort);
      for(temp=0;temp<16;temp++){
        
       inw(DATA_PORT);}
 
}


void read_atl(uint16 *a_ptr,  uint16 data_size)
{
    uint32 cnt;
  
    WRITE_16BIT_REG(HcTransferCounter,data_size*2);
    outw(COMMAND_PORT,HcATLBufferPort);
  
    cnt=0;
    do
    {
        *(a_ptr+cnt)=inw(DATA_PORT);
        cnt++;
    }
    while(cnt<(data_size));
  }
    

void make_control_ptd(uint16 *rptr,uint8 type_ptd,uint8 last,uint8 ep,uint32 max,uint8 tog,uint8 addr)
{
    //ptd2send.CompletetionCode=0x0; //设置完成代码 = 0000。 无错误。
    ptd2send.CompletetionCode=0xF;
    
    ptd2send.active_bit=1; //使能主机控制器执行的传输
    ptd2send.toggle=tog;
    
    ptd2send.ActualBytes=0; //设为0。该字段被主机控制器填充,反映了发送或接收的字节数
      
    
    ptd2send.endpoint=ep;
    ptd2send.last_ptd=1;
    ptd2send.speed=device_speed;
    ptd2send.MaxPacketSize=max;
    
   ptd2send.TotalBytes=max;
  
    
    ptd2send.pid_type= type_ptd;
    ptd2send.format=0;
    ptd2send.fm=0;
    ptd2send.FunctionAddress=addr;
    
     //PTD的字节0和1的10位ActualBytes
    //rptr[0]= (ptd2send.CompletetionCode &0x0000)<<12|(ptd2send.active_bit &0x0001)<<11|(ptd2send.toggle &0x0001)<<10 |(ptd2send.ActualBytes &0x03FF);
    rptr[0]= (ptd2send.CompletetionCode &0xFFFF)<<12|(ptd2send.active_bit &0x0001)<<11|(ptd2send.toggle &0x0001)<<10 |(ptd2send.ActualBytes &0x03FF);
     // PTD的字节1和2的10位MaxPacketSize
    rptr[1]= (ptd2send.endpoint &0x000F)<<12|(ptd2send.last_ptd &0x0001)<<11|(ptd2send.speed &0x0001)<<10|(ptd2send.MaxPacketSize&0x03FF);
     // PTD的字节3和4的10位TotalSize
    rptr[2]= (0x0000 &0x000F)<<12|(ptd2send.pid_type &0x0003)<<10|(ptd2send.TotalBytes &0x03FF);
  
    rptr[3]= (ptd2send.fm &0x00FF)<<8|(ptd2send.format &0x0001)<<7|(ptd2send.FunctionAddress &0x007F);
}

void send_control(uint16 *a_ptr,uint16 *r_ptr,uint16 d0,uint16  d1,uint16  d2,uint16 d3,uint32 send_bytes)
{
    uint32 cnt=8;
    uint8 active_bit;
    uint16 send_words;
    uint16 i;
  
    abuf[0]=*(a_ptr+0);
    abuf[1]=*(a_ptr+1);
    abuf[2]=*(a_ptr+2);
    abuf[3]=*(a_ptr+3);
    abuf[4]=d0;
    abuf[5]=d1;
    abuf[6]=d2;
    abuf[7]=d3;
    
  
    send_words=send_bytes/2;
    
    write_atl(abuf,send_words);
    
    do
    {
      
        if(ptd2send.speed==1)// 读16字节
                {read_atl(r_ptr, 16);}  
        else// 读72字节
                {read_atl(r_ptr,72);}
      
        active_bit=(*r_ptr)&(0x0800); // 检查有效位。PTD结束后主机控制器将该位清零。
        active_bit=active_bit>>11;
       // cnt--;
    }
    //while((cnt>2) && (active_bit!=0));
    while(active_bit!=0);
}

现在能看到数据写进ATL缓冲区,再读出来的时候,completion code=00,标识发送无误,但数据包始终没有发送出去?还有一个问题就是,读出的数据的PIDDirection怎么都是01(IN)?
附件中是读ATL缓冲区时在中断中看到的数据(处理器:LPC2200)
stevenwin
驱动牛犊
驱动牛犊
  • 注册日期2008-03-29
  • 最后登录2008-07-02
  • 粉丝0
  • 关注0
  • 积分120分
  • 威望13点
  • 贡献值0点
  • 好评度12点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2008-03-31 20:26
补充一下:
在发出读ATL缓冲区的命令后,存储器中的值变为如上图所示。
数据含义如下:
00 0C  //PTD的第0个字节和第1个字节
40 08  / /PTD的第2个字节和第3个字节
00 04  //PTD的第4个字节和第5个字节
00 00  //PTD的第6个字节和第7个字节
//获取设备描述符的请求数据如下
80 06
00 01
00 00
12 00
stevenwin
驱动牛犊
驱动牛犊
  • 注册日期2008-03-29
  • 最后登录2008-07-02
  • 粉丝0
  • 关注0
  • 积分120分
  • 威望13点
  • 贡献值0点
  • 好评度12点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2008-04-01 14:46
现在数据能正确写进ATL缓冲区,但再次读出来时,Actual Bytes任然等于0
hongfeng_wang
驱动牛犊
驱动牛犊
  • 注册日期2003-02-26
  • 最后登录2009-05-10
  • 粉丝0
  • 关注0
  • 积分6分
  • 威望12点
  • 贡献值0点
  • 好评度6点
  • 原创分0分
  • 专家分0分
地板#
发布于:2008-04-02 02:51
PTD's active=1 means 你的数据根本没发出去。
stevenwin
驱动牛犊
驱动牛犊
  • 注册日期2008-03-29
  • 最后登录2008-07-02
  • 粉丝0
  • 关注0
  • 积分120分
  • 威望13点
  • 贡献值0点
  • 好评度12点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2008-04-02 10:28
hongfeng_wang能帮忙看看是什么原因造成的吗?急啊,先谢谢了!
这里是我的初始化代码:
http://bbs.driverdevelop.com/htm_data/9/0804/110117.html
hongfeng_wang
驱动牛犊
驱动牛犊
  • 注册日期2003-02-26
  • 最后登录2009-05-10
  • 粉丝0
  • 关注0
  • 积分6分
  • 威望12点
  • 贡献值0点
  • 好评度6点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2008-04-05 05:45
I am not familiar with ISP1161, but I am trying to help since I understand how you feel when I was stuck with ISP1761.
I looked at the datasheet. here 's suspicious:

PTD byte 4, should be total bytes to send, but in your readback, it's 0,
check out PTD packet after make_control_ptd() before you send it out.
liudingli
驱动牛犊
驱动牛犊
  • 注册日期2008-04-16
  • 最后登录2008-07-16
  • 粉丝4
  • 关注0
  • 积分213分
  • 威望33点
  • 贡献值2点
  • 好评度29点
  • 原创分0分
  • 专家分0分
6楼#
发布于:2008-04-26 10:29
我们交流交流吧。我也正用ISP1161。QQ38012101
liudingli
驱动牛犊
驱动牛犊
  • 注册日期2008-04-16
  • 最后登录2008-07-16
  • 粉丝4
  • 关注0
  • 积分213分
  • 威望33点
  • 贡献值2点
  • 好评度29点
  • 原创分0分
  • 专家分0分
7楼#
发布于:2008-04-26 10:42
我们交流交流吧。我也正用ISP1161。QQ38012101
游客

返回顶部