原创作品,允许转载,转载时请务必以超链接形式标明文章
原始出处 、作者信息和本声明。否则将追究法律责任。
http://lancelot.blog.51cto.com/393579/253009
通过批量端口向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(
unsignedchar
*pCbw,
unsignedchar
*pData,
unsignedchar
*pCsw)
{
BYTE
toggle;
//
得到批量出端点的下一次发送数据区编号
toggle = usbGetEdToggle(bulkEd[0]);
//
初始化批量出端点
ED
AT91F_CreateEd(
(
unsignedint
) &bulkEd[0],
// ED Address
64 ,
// Max packet
0,
// TD format
0,
// Skip
0,
// Speed
ED_OUT,
// Direction
usbDevInfo.
bulkOutPort
,
// Endpoint
usbDevInfo.
addr
,
// Func Address
(
unsignedint
) &genTd[2],
// TDQTailPointer
(
unsignedint
) &genTd[0],
// TDQHeadPointer
toggle,
// ToggleCarry
(
unsignedint
) &bulkEd[1]);
// NextED
//
设置批量出端点的
TD
//
用于发送
CBW
命令的
TD
AT91F_CreateGenTd(
(
unsignedint
) &genTd[0],
// TD Address
0,
// Data Toggle
TD_DELAY_INT,
// DelayInterrupt
TD_OUT,
// Direction
1,
// Buffer Rounding
(
unsignedint
) pCbw,
// Current Buffer Pointer
(
unsignedint
) &genTd[1],
// Next TD
31);
// Buffer Length
//
用于发送数据的
TD
AT91F_CreateGenTd(
(
unsignedint
) &genTd[1],
// TD Address
0,
// Data Toggle
TD_DELAY_INT,
// DelayInterrupt
TD_OUT,
// Direction
1,
// Buffer Rounding
(
unsignedint
) pData,
// Current Buffer Pointer
(
unsignedint
) &genTd[2],
// Next TD
512);
// Buffer Length
AT91F_CreateGenTd(
(
unsignedint
) &genTd[2],
// TD Address
3,
// Data Toggle
TD_DELAY_INT,
// DelayInterrupt
TD_OUT,
// Direction
1,
// Buffer Rounding
0x0,
// Current Buffer Pointer
(
unsignedint
) 0,
// Next TD
0x0);
// Buffer Length
//
得到批量入端点的下一次发送数据区编号
toggle = usbGetEdToggle(bulkEd[1]);
//
初始化批量入端点
ED
AT91F_CreateEd(
(
unsignedint
) &bulkEd[1],
// ED Address
64 ,
// Max packet
0,
// TD format
0,
// Skip
0,
// Speed
ED_IN,
// Direction
usbDevInfo.
bulkInPort
,
// Endpoint
usbDevInfo.
addr
,
// Func Address
(
unsignedint
) &genTd[4],
// TDQTailPointer
(
unsignedint
) &genTd[3],
// TDQHeadPointer
toggle,
// ToggleCarry
(
unsignedint
) 0);
// NextED
//
用于接收
CSW
的
TD
AT91F_CreateGenTd(
(
unsignedint
) &genTd[3],
// TD Address
0,
// Data Toggle
TD_DELAY_INT,
// DelayInterrupt
TD_IN,
// Direction
1,
// Buffer Rounding
(
unsignedint
) pCsw,
// Current Buffer Pointer
(
unsignedint
) &genTd[4],
// Next TD
13);
// Buffer Length
AT91F_CreateGenTd(
(
unsignedint
) &genTd[4],
// TD Address
3,
// Data Toggle
TD_DELAY_INT,
// DelayInterrupt
TD_IN,
// Direction
1,
// Buffer Rounding
0x0,
// Current Buffer Pointer
(
unsignedint
) 0,
// Next TD
0x0);
// Buffer Length
//
调用底层接口把数据发送出去
ohciBulkXfer(&bulkEd[0]);
usbRunCmd(USB_CMD_TYPE_BULK_WRITE, 3);
return
0;
}
|