LOCAL void HTCProcessConfigPipeMsg(HTC_CONTEXT *pHTC, HTC_CONFIG_PIPE_MSG *pMsg) { adf_nbuf_t pBuffer; HTC_CONFIG_PIPE_RESPONSE_MSG *pRspMsg; pBuffer = HTCAllocMsgBuffer(pHTC); /* note : this will be aligned */ pRspMsg = (HTC_CONFIG_PIPE_RESPONSE_MSG *) adf_nbuf_put_tail(pBuffer, sizeof(HTC_CONFIG_PIPE_RESPONSE_MSG)); A_MEMZERO(pRspMsg,sizeof(HTC_CONFIG_PIPE_RESPONSE_MSG)); pRspMsg->MessageID = adf_os_htons(HTC_MSG_CONFIG_PIPE_RESPONSE_ID); /* reflect the service ID for this connect attempt */ pRspMsg->PipeID = pMsg->PipeID; if ( HIF_is_pipe_supported(pHTC->hifHandle, pMsg->PipeID) ) { pRspMsg->Status = 0; } else { pRspMsg->Status = 1; goto config_done; } if ( (pHTC->TotalCreditsAssigned + pMsg->CreditCount) <= pHTC->TotalCredits ) { pHTC->TotalCreditsAssigned += pMsg->CreditCount; } else { pRspMsg->Status = 2; goto config_done; } HIF_config_pipe(pHTC->hifHandle, pMsg->PipeID, pMsg->CreditCount); config_done: /* send out the response message */ HTC_SendMsg(pHTC, ENDPOINT0, pBuffer); }
LOCAL htc_handle_t _HTC_Init(HTC_SETUP_COMPLETE_CB SetupComplete, HTC_CONFIG *pConfig) { HIF_CALLBACK hifCBConfig; HTC_CONTEXT *pHTC; pHTC = (HTC_CONTEXT *)adf_os_mem_alloc(sizeof(HTC_CONTEXT)); adf_os_mem_zero(pHTC, sizeof(HTC_CONTEXT)); pHTC->OSHandle = pConfig->OSHandle; pHTC->PoolHandle = pConfig->PoolHandle; pHTC->hifHandle = pConfig->HIFHandle; hifCBConfig.send_buf_done = A_INDIR(htc._HTC_SendDoneHandler); hifCBConfig.recv_buf = A_INDIR(htc._HTC_MsgRecvHandler); hifCBConfig.context = pHTC; /* initialize hardware layer */ HIF_register_callback(pConfig->HIFHandle, &hifCBConfig); /* see if the host wants us to override the number of ctrl buffers */ pHTC->NumBuffersForCreditRpts = 0; if (0 == pHTC->NumBuffersForCreditRpts) { /* nothing to override, simply set default */ pHTC->NumBuffersForCreditRpts = HTC_DEFAULT_NUM_CTRL_BUFFERS; } pHTC->MaxEpPendingCreditRpts = 0; if (0 == pHTC->MaxEpPendingCreditRpts) { pHTC->MaxEpPendingCreditRpts = HTC_DEFAULT_MAX_EP_PENDING_CREDIT_REPORTS; } /* calculate the total allocation size based on the number of credit report buffers */ pHTC->CtrlBufferAllocSize = MIN_CREDIT_BUFFER_ALLOC_SIZE * pHTC->NumBuffersForCreditRpts; /* we need at least enough buffer space for 1 ctrl message */ pHTC->CtrlBufferAllocSize = A_MAX(pHTC->CtrlBufferAllocSize,MAX_HTC_SETUP_MSG_SIZE); /* save the size of each buffer/credit we will receive */ pHTC->RecvBufferSize = pConfig->CreditSize; //RecvBufferSize; pHTC->TotalCredits = pConfig->CreditNumber; pHTC->TotalCreditsAssigned = 0; /* setup the pseudo service that handles HTC control messages */ pHTC->HTCControlService.ProcessRecvMsg = A_INDIR(htc._HTC_ControlSvcProcessMsg); pHTC->HTCControlService.ProcessSendBufferComplete = A_INDIR(htc._HTC_ControlSvcProcessSendComplete); pHTC->HTCControlService.TrailerSpcCheckLimit = HTC_CTRL_BUFFER_CHECK_SIZE; pHTC->HTCControlService.MaxSvcMsgSize = MAX_HTC_SETUP_MSG_SIZE; pHTC->HTCControlService.ServiceCtx = pHTC; /* automatically register this pseudo service to endpoint 1 */ pHTC->Endpoints[ENDPOINT0].pService = &pHTC->HTCControlService; HIF_get_default_pipe(pHTC->hifHandle, &pHTC->Endpoints[ENDPOINT0].UpLinkPipeID, &pHTC->Endpoints[ENDPOINT0].DownLinkPipeID); /* Initialize control pipe so we could receive the HTC control packets */ // @TODO: msg size! HIF_config_pipe(pHTC->hifHandle, pHTC->Endpoints[ENDPOINT0].UpLinkPipeID, 1); /* set the first free endpoint */ pHTC->CurrentEpIndex = ENDPOINT1; pHTC->SetupCompleteCb = SetupComplete; /* setup buffers for just the setup phase, we only need 1 buffer to handle * setup */ HTC_AssembleBuffers(pHTC, 4, MAX_HTC_SETUP_MSG_SIZE); /* start hardware layer so that we can queue buffers */ HIF_start(pHTC->hifHandle); return pHTC; }
void Magpie_init(void) { A_PRINTF("[+++Magpie_init]\n\r"); A_PRINTF("[+++VBUF_init(%d)]\n\r", MAX_BUF_NUM); VBUF_init(MAX_BUF_NUM); A_PRINTF("[+++VBUF_init(%d)]\n\r", MAX_DESC_NUM); VDESC_init(MAX_DESC_NUM); #if MAGPIE_ENABLE_WLAN == 0 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa hif_handle = HIF_init(0); #if ZM_FM_LOOPBACK == 1 HIF_config_pipe(hif_handle, HIF_USB_PIPE_TX, 5); HIF_config_pipe(hif_handle, HIF_USB_PIPE_COMMAND, 2); #if SYSTEM_MODULE_HP_EP5 HIF_config_pipe(hif_handle, HIF_USB_PIPE_HP_TX, 3); #endif #if SYSTEM_MODULE_HP_EP6 HIF_config_pipe(hif_handle, HIF_USB_PIPE_MP_TX, 3); #endif A_PRINTF("[+++HIF_init(0)]\n\r"); HIF_start(hif_handle); #else /* ZM_FM_LOOPBACK == 0 */ // initialize HTC htcConf.CreditSize = 320; htcConf.CreditNumber = 10; #if 1 htcConf.ControlDownLinkPipeID = HIF_USB_PIPE_INTERRUPT; // Target -> Host htcConf.ControlUpLinkPipeID = HIF_USB_PIPE_COMMAND; // Host -> Target #else htcConf.ControlDownLinkPipeID = HIF_USB_PIPE_RX; htcConf.ControlUpLinkPipeID = HIF_USB_PIPE_TX; #endif htcConf.HIFHandle = hif_handle; htcConf.OSHandle = 0; // not used htcConf.PoolHandle = pool_handle; htc_handle = HTC_init(htc_setup_comp, &htcConf); // Initialize HTC services HTC_Loopback_Init(htc_handle); adf_os_mem_zero(&wmiConfig, sizeof(WMI_SVC_CONFIG)); wmiConfig.HtcHandle = htc_handle; wmiConfig.PoolHandle = pool_handle; wmiConfig.MaxCmdReplyEvts = 1; wmiConfig.MaxEventEvts = 1; wmi_handle = WMI_Init(&wmiConfig); Magpie_Sys_Commands_Tbl.pContext = wmi_handle; WMI_RegisterDispatchTable(Magpie_Sys_Commands_Tbl.pContext, &Magpie_Sys_Commands_Tbl); #endif/* ZM_FM_LOOPBACK == 0 */ #endif /* MAGPIE_ENABLE_WLAN */ }