执行ohci->HcCommandStatus |= OHCI_CS_CLF; //CLF
后,hc处理端点描述符上的TD(传输描述符),但是执行后,TD的HeadP第0位为1,说明处理TD时错误,可能是哪里的无问题呢。代码如下:
pTDout = ohci_create_td(2, 5, 0, 1, (unsigned int)pSetup, 8, 0, 0, 0);
if (!pTDout) {
//unlock_ohci();
return -1;
}
ohci_add_td(pED, pTDout);
// create IN transaction
pTDin = ohci_create_td(3, 5, ED_IN, 1, (unsigned int)pIn, len, 0, 0, 0);
if (!pTDin) {
//unlock_ohci();
return -1;
}
ohci_add_td(pED, pTDin);
//create EMTY transaction
pTDempty = ohci_create_td(2, 5, 0, 1, 0, 0, 0, 0, 0);
if (!pTDempty) {
//unlock_ohci();
return -1;
}
ohci_add_td(pED, pTDempty);
PS_UHP_TD ohci_create_td(unsigned int td_type,
unsigned int del_int,
unsigned int direction,
unsigned int rounding,
unsigned int cbp,
unsigned int buf_len,
unsigned int next_td,
unsigned int cb,
unsigned int arg) {
PS_UHP_TD pTD = NULL;
OHCI_PS_UHP_TD pUTD ;
if (cur_td_num > MAX_TDS) {
OHCI_DBG("UH ERROR: MAX TD\r\n");
return NULL;
}
pTD = (PS_UHP_TD)malloc(sizeof(UHP_TD));
if(!pTD) {
OHCI_DBG("UH ERROR: Not enough memory\r\n");
return NULL;
}
memset(pTD, 0, sizeof(UHP_TD));
pUTD = (OHCI_PS_UHP_TD)aligned_malloc(sizeof(OHCI_S_UHP_TD), 16);
if(!pUTD) {
OHCI_DBG("UH ERROR: Not enough memory\r\n");
return NULL;
}
memset(pUTD, 0, sizeof(OHCI_S_UHP_TD));
pTD->Buf_Len = buf_len;
pTD->CBP = cbp;
pTD->Data_Toggle = td_type;
pTD->DelayInterrupt = del_int;
pTD->Direction = direction;
pTD->NextTD = 0;
pTD->Rounding = rounding;
pTD->TDAddress = (unsigned int) pUTD;
pTD->callback = cb;
pTD->arg = arg;
ll_CreateGenTd(
pTD->TDAddress,
pTD->Data_Toggle,
pTD->DelayInterrupt,
pTD->Direction,
pTD->Rounding,
pTD->CBP,
0,
pTD->Buf_Len);
cur_td_num++;
return pTD;
}
void ohci_add_td(PS_UHP_ED pED, PS_UHP_TD pTD) {
OHCI_PS_UHP_TD psTD;
OHCI_PS_UHP_ED phED;
phED = pED->phED;
if (!phED) return;
if (!pTD) {
OHCI_DBG("UH ERROR: Invalid TD\r\n");
return;
}
if (cur_td_num > MAX_TDS) {
OHCI_DBG("UH ERROR: MAX TD\r\n");
return;
}
if(!phED->HeadP) {
phED->HeadP = (((unsigned int) pTD->TDAddress) & 0xFFFFFFF0);
} else {
psTD = (OHCI_PS_UHP_TD)phED->HeadP;
for (;psTD->NextTD;psTD = (OHCI_PS_UHP_TD)psTD->NextTD);
psTD->NextTD = pTD->TDAddress;
}
phED->TailP = (((unsigned int) pTD->TDAddress) & 0xFFFFFFF0);
} |