在USB设备初始化枚举过程中,需要发送一些设置命令到USB设备上,需要调用本函数来完成。函数的处理跟控制端口读数据差不多,只不过TD的数据传输方向设置不一样:
/**
* 通过控制端口发送设置数据的命令
* @param pSetup Setup包指针
* @param *pData 数据缓冲区指针
*/
short ctrlCmdSet(unsigned int pSetup, unsigned char *pData)
{
//初始化控制端点的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[2], // TDQTailPointer
(unsigned int) &genTd[0], // TDQHeadPointer
0, // ToggleCarry
0x0); // NextED
//控制端点的第一个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
TD_IN, // Direction
1, // Buffer Rounding
(unsigned int) pData, // Current Buffer Pointer
(unsigned int) &genTd[2], // Next TD
0); // Buffer Length
//标志TD队列结束的最后一个TD,设置为空
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
//调用底层接口把数据发送出去
ohciCtrlXfer(&controlEd);
usbRunCmd(USB_CMD_TYPE_CTRL_WRITE, 2);
return 0;
}
|
本文转自 tywali 51CTO博客,原文链接:http://blog.51cto.com/lancelot/247246,如需转载请自行联系原作者