通過批量端口向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;
}
本文出自 “rainman” 博客,請務必保留此出處http://lancelot.blog.51cto.com/393579/253009