基于OHCI的USB主机开发 —— OHCI(批量端口写数据)

通过批量端口向U盘写数据的函数处理与上面类似,只不过ED[0]下面要有2TD,一个是CBW,另一个是DATA。而ED[1]下只有1TD,是CSW

在本函数内只处理Mass Storage协议,不理会UFI协议:
/**

 从批量端点发送数据

 * @param *pCbw CBW数据区指针

 * @param *pData 存放读取结果的数据区指针

 * @param *pCsw CSW数据区指针

 */

short bulkWrite(unsigned char *pCbw, unsigned char *pData, unsigned char *pCsw)

{

    BYTE toggle;

 

    //得到批量出端点的下一次发送数据区编号

    toggle = usbGetEdToggle(bulkEd[0]);

    //初始化批量出端点ED

    AT91F_CreateEd(

       (unsigned int) &bulkEd[0],  // ED Address

       64 ,                        // Max packet

       0,                          // TD format

       0,                          // Skip

       0,                          // Speed

       ED_OUT,                     // Direction

       usbDevInfo.bulkOutPort,     // Endpoint

       usbDevInfo.addr,            // Func Address

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

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

       toggle,                     // ToggleCarry

       (unsigned int) &bulkEd[1]); // NextED

 

    //设置批量出端点的TD

    //用于发送CBW命令的TD

    AT91F_CreateGenTd(

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

       0,                          // Data Toggle

       TD_DELAY_INT,               // DelayInterrupt

       TD_OUT,                     // Direction

       1,                          // Buffer Rounding

       (unsigned int) pCbw,        // Current Buffer Pointer

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

       31);                        // Buffer Length

   

    //用于发送数据的TD

    AT91F_CreateGenTd(

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

       0,                          // Data Toggle

       TD_DELAY_INT,               // DelayInterrupt

       TD_OUT,                     // Direction

       1,                          // Buffer Rounding

       (unsigned int) pData,       // Current Buffer Pointer

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

       512);                       // Buffer Length

   

    AT91F_CreateGenTd(

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

       3,                          // Data Toggle

       TD_DELAY_INT,               // DelayInterrupt

       TD_OUT,                     // Direction

       1,                          // Buffer Rounding

       0x0,                        // Current Buffer Pointer

       (unsigned int) 0,           // Next TD

       0x0);                       // Buffer Length

 

    //得到批量入端点的下一次发送数据区编号

    toggle = usbGetEdToggle(bulkEd[1]);

    //初始化批量入端点ED

    AT91F_CreateEd(

       (unsigned int) &bulkEd[1],  // ED Address

       64 ,                        // Max packet

       0,                          // TD format

       0,                          // Skip

       0,                          // Speed

       ED_IN,                      // Direction

       usbDevInfo.bulkInPort,      // Endpoint

       usbDevInfo.addr,            // Func Address

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

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

       toggle,                     // ToggleCarry

       (unsigned int) 0);          // NextED

 

    //用于接收CSWTD

    AT91F_CreateGenTd(

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

       0,                          // Data Toggle

       TD_DELAY_INT,               // DelayInterrupt

       TD_IN,                      // Direction

       1,                          // Buffer Rounding

       (unsigned int) pCsw,        // Current Buffer Pointer

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

       13);                        // Buffer Length

   

    AT91F_CreateGenTd(

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

       3,                          // Data Toggle

       TD_DELAY_INT,               // DelayInterrupt

       TD_IN,                      // Direction

       1,                          // Buffer Rounding

       0x0,                        // Current Buffer Pointer

       (unsigned int) 0,           // Next TD

       0x0);                       // Buffer Length

   

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

    ohciBulkXfer(&bulkEd[0]);

   

    usbRunCmd(USB_CMD_TYPE_BULK_WRITE, 3);

   

    return 0;

}





本文转自 tywali 51CTO博客,原文链接:http://blog.51cto.com/lancelot/253009,如需转载请自行联系原作者
上一篇:Android开发教程 - 使用Data Binding Android Studio不能正常生成相关类/方法的解决办法


下一篇:《Log4j 2 官方文档》Configuring Filters