基於OHCI的USB主機 —— 寄存器(傳輸)

啓動控制傳輸

進行控制傳輸以前,須要設置好相應的 ED TD 參數(參見下一章),啓動傳輸時須要設置 OHCI 寄存器中的控制傳輸 ED 頭指針寄存器和控制傳輸的當前 ED 指針寄存器,而後設置控制寄存器容許處理控制傳輸列表,控制狀態寄存器有控制傳輸列表數據須要傳輸,代碼以下:
/**
 * 經過 Control 端口傳輸數據
 * @param *ed 須要進行數據收發的 ED 指針
 * @return 0 - 成功
 */
short ohciCtrlXfer( AT91S_UHP_ED *ed)
{
    // Programming the CHED
    pUhp-> UHP_HcControlHeadED = ( unsigned int ) ed;
 
    // Programming the CCED
    pUhp-> UHP_HcControlCurrentED = ( unsigned int ) ed;
 
    // UHP: UHP is now operational and control list processing is enabled
    pUhp-> UHP_HcControl = 0x90;
   
    // UHP: Notify the Hc that the Control list is filled
    pUhp-> UHP_HcCommandStatus = OHCI_HC_COMMAND_STATUS_CLF;
   
    return 0;
}
 

啓動批量傳輸

啓動批量傳輸的流程與控制傳輸相似,只不過相應寄存器換爲批量傳輸的寄存器了:
/**
 * 經過 Bulk 端口傳輸數據
 * @param *ed 須要進行數據收發的 ED 指針
 * @return 0 - 成功
 */
short ohciBulkXfer( AT91S_UHP_ED *ed)
{
    // 禁止 ED
    pUhp-> UHP_HcControl = 0x180;
    pUhp-> UHP_HcCommandStatus = 0x00;
   
    // Programming the BHED
    pUhp-> UHP_HcBulkHeadED = ( unsigned int ) ed;
 
    // Programming the BCED
    pUhp-> UHP_HcBulkCurrentED = ( unsigned int ) ed;
 
    // UHP: UHP is now operational and control list processing is enabled
    pUhp-> UHP_HcControl = 0x0A0;
   
    // UHP: Notify the Hc that the Bulk list is filled
    pUhp-> UHP_HcCommandStatus = OHCI_HC_COMMAND_STATUS_BLF;
   
    return 0;
}