/* registered target arrival callback from the HIF layer */ HTC_HANDLE HTCCreate(void *hHIF, HTC_INIT_INFO *pInfo) { A_STATUS status = A_OK; HTC_TARGET *target = NULL; do { if ((target = (HTC_TARGET *)A_MALLOC(sizeof(HTC_TARGET))) == NULL) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("HTC : Unable to allocate memory\n")); status = A_ERROR; break; } A_MEMCPY(&target->HTCInitInfo,pInfo,sizeof(HTC_INIT_INFO)); adf_os_mem_zero(target, sizeof(HTC_TARGET)); adf_os_spinlock_init(&target->HTCLock); adf_os_spinlock_init(&target->HTCRxLock); adf_os_spinlock_init(&target->HTCTxLock); /* setup HIF layer callbacks */ adf_os_mem_zero(&htcCallbacks, sizeof(completion_callbacks_t)); htcCallbacks.Context = target; htcCallbacks.rxCompletionHandler = HTCRxCompletionHandler; htcCallbacks.txCompletionHandler = HTCTxCompletionHandler; HIFPostInit(hHIF, target, &htcCallbacks); target->hif_dev = hHIF; adf_os_init_mutex(&target->htc_rdy_mutex); adf_os_mutex_acquire(&target->htc_rdy_mutex); /* Get HIF default pipe for HTC message exchange */ pEndpoint = &target->EndPoint[ENDPOINT0]; HIFGetDefaultPipe(hHIF, &pEndpoint->UL_PipeID, &pEndpoint->DL_PipeID); adf_os_print("[Default Pipe]UL: %x, DL: %x\n", pEndpoint->UL_PipeID, pEndpoint->DL_PipeID); /* TODO : other init */ } while (FALSE); target->host_handle = htcInfo.pContext; /* TODO INTEGRATION supply from host os handle for any os specific calls*/ target->os_handle = NULL; if (A_FAILED(status)) { HTCCleanup(target); target = NULL; } return (HTC_HANDLE)target; }
/* polling routine to wait for a control packet to be received */ A_STATUS HTCWaitRecvCtrlMessage(HTC_TARGET *target) { // int count = HTC_TARGET_MAX_RESPONSE_POLL; AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("+HTCWaitCtrlMessageRecv\n")); /* Wait for BMI request/response transaction to complete */ while (adf_os_mutex_acquire(target->osdev, &target->CtrlResponseValid)) { } LOCK_HTC_RX(target); /* caller will clear this flag */ target->CtrlResponseProcessing = TRUE; UNLOCK_HTC_RX(target); #if 0 while (count > 0) { LOCK_HTC_RX(target); if (target->CtrlResponseValid) { target->CtrlResponseValid = FALSE; /* caller will clear this flag */ target->CtrlResponseProcessing = TRUE; UNLOCK_HTC_RX(target); break; } UNLOCK_HTC_RX(target); count--; A_MSLEEP(HTC_TARGET_RESPONSE_POLL_MS); } if (count <= 0) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("-HTCWaitCtrlMessageRecv: Timeout!\n")); return A_ECOMM; } #endif AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("-HTCWaitCtrlMessageRecv success\n")); return A_OK; }
A_STATUS HTCWaitTarget(HTC_HANDLE HTCHandle) { A_STATUS status = A_OK; HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("HTCWaitTarget - Enter (target:0x%X) \n", (A_UINT32)HTCHandle)); A_STATUS status = A_OK; /* a_status_t wait_status;*/ HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); HIFStart(target->hif_dev); adf_os_print("[%s %d] Starting mutex waiting...\n",adf_os_function, __LINE__); adf_os_mutex_acquire(&target->htc_rdy_mutex); adf_os_print("[%s %d] Finish mutex waiting...\n",adf_os_function, __LINE__); return status; AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("HTCWaitTarget - Exit\n")); return status; }
void HTCRecvInit(HTC_TARGET *target) { /* Initialize CtrlResponseValid to block */ adf_os_init_mutex(&target->CtrlResponseValid); adf_os_mutex_acquire(target->osdev, &target->CtrlResponseValid); }