通过批量端口向
U
盘写数据的函数处理与上面类似,只不过
ED[0]
下面要有
2
个
TD
,一个是
CBW
,另一个是
DATA
。而
ED[1]
下只有
1
个
TD
,是
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
//
用于接收
CSW
的
TD
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,如需转载请自行联系原作者