基于OHCI的USB主机开发 —— OHCI(控制端口读数据)

根据USB的规范,在系统初始化的时候需要从控制端口发送命令,其中有一些命令是包含数据的,对于这些命令,需要调用本函数来完成。函数内主要调用AM9200提供的OHCI接口:AT91F_CreateEd()AT91F_CreateGenTd()来完成EDTD的参数设置:
/**

 从控制端点读取数据

 * @param pSetup Setup包指针,用来设置数据长度和传输方向

 * @param *pData 数据缓冲区指针

 */

short ctrlCmdGet(unsigned int pSetup, unsigned short len, unsigned char *pData)

{

    unsigned char direction;

   

    //初始化控制端点的ED

    AT91F_CreateEd(

       (unsigned int) &controlEd, // ED Address

       64,                           // Max packet

       0,                         // TD format

       0,                         // Skip

       0,                         // Speed

       0x0,                          // Direction

       0,                           // Endpoint

       usbDevInfo.addr,             // Func Address

       (unsigned int) &genTd[3],    // TDQTailPointer

       (unsigned int) &genTd[0],    // TDQHeadPointer

       0,                         // ToggleCarry

       0x0);                        // NextED

   

    direction = TD_IN;

   

    //控制端点的第一个TD,用于发送Setup

    AT91F_CreateGenTd(

       (unsigned int) &genTd[0],    // TD Address

       2,                         // Data Toggle

       TD_DELAY_INT,                 // DelayInterrupt

       TD_SETUP,                     // Direction

       1,                         // Buffer Rounding

       (unsigned int) pSetup,      // Current Buffer Pointer

       (unsigned int) &genTd[1],    // Next TD

       8);                       // Buffer Length

 

    //控制端点的第二个TD,用于接收数据

    AT91F_CreateGenTd(

       (unsigned int) &genTd[1],    // TD Address

       3,                        // Data Toggle

       TD_DELAY_INT,                // DelayInterrupt

       direction,                  // Direction

       1,                        // Buffer Rounding

       (unsigned int) pData,       // Current Buffer Pointer

       (unsigned int) &genTd[2],    // Next TD

       len);                        // Buffer Length

 

    //控制端点的第三个TD,用于得到命令的状态

    AT91F_CreateGenTd(

       (unsigned int) &genTd[2],    // TD Address

       3,                         // Data Toggle

       TD_DELAY_INT,                 // DelayInterrupt

       ~direction,                 // Direction

       1,                         // Buffer Rounding

       0x0,                          // Current Buffer Pointer

       (unsigned int) &genTd[3],   // Next TD

       0x0);                        // Buffer Length

 

    //标志TD队列结束的最后一个TD,设置为空

    AT91F_CreateGenTd(

       (unsigned int) &genTd[3],    // TD Address

       3,                         // Data Toggle

       TD_DELAY_INT,                 // DelayInterrupt

       ~direction,                 // Direction

       1,                         // Buffer Rounding

       0x0,                          // Current Buffer Pointer

       (unsigned int) 0,            // Next TD

       0x0);                        // Buffer Length

   

    //调用底层接口把数据发送出去

    ohciCtrlXfer(&controlEd);

   

    //设置相关信息,以便中断程序中判断命令是否结束

    usbRunCmd(USB_CMD_TYPE_CTRL_READ, 3);

   

    return 0;

}





本文转自 tywali 51CTO博客,原文链接:http://blog.51cto.com/lancelot/247245,如需转载请自行联系原作者
上一篇:带你读《深入理解以太坊》之一:以太坊概述


下一篇:Updating Maven Project". Unsupported IClasspathEntry kind=4错误解