/**
*
从控制端点读取数据
* @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;
}
|