msg_t WebThread(void *p) { EvTimer evt1, evt2; EventListener el0, el1, el2; uip_ipaddr_t ipaddr; (void)p; /* * Event sources setup. */ chEvtRegister(macGetReceiveEventSource(ÐD1), &el0, FRAME_RECEIVED_ID); chEvtAddFlags(EVENT_MASK(FRAME_RECEIVED_ID)); /* In case some frames are already buffered */ evtInit(&evt1, MS2ST(500)); evtStart(&evt1); chEvtRegister(&evt1.et_es, &el1, PERIODIC_TIMER_ID); evtInit(&evt2, S2ST(10)); evtStart(&evt2); chEvtRegister(&evt2.et_es, &el2, ARP_TIMER_ID); /* * EMAC driver start. */ macStart(ÐD1, &mac_config); (void)macPollLinkStatus(ÐD1); /* * uIP initialization. */ uip_init(); uip_setethaddr(macaddr); uip_ipaddr(ipaddr, IPADDR0, IPADDR1, IPADDR2, IPADDR3); uip_sethostaddr(ipaddr); httpd_init(); while (TRUE) { chEvtDispatch(evhndl, chEvtWaitOne(ALL_EVENTS)); } return 0; }
/** * @brief LWIP handling thread. * * @param[in] p pointer to a @p lwipthread_opts structure or @p NULL * @return The function does not return. */ msg_t lwip_thread(void *p) { event_timer_t evt; event_listener_t el0, el1; struct ip_addr ip, gateway, netmask; static struct netif thisif; static const MACConfig mac_config = {thisif.hwaddr}; chRegSetThreadName("lwipthread"); /* Initializes the thing.*/ tcpip_init(NULL, NULL); /* TCP/IP parameters, runtime or compile time.*/ if (p) { struct lwipthread_opts *opts = p; unsigned i; for (i = 0; i < 6; i++) thisif.hwaddr[i] = opts->macaddress[i]; ip.addr = opts->address; gateway.addr = opts->gateway; netmask.addr = opts->netmask; } else { thisif.hwaddr[0] = LWIP_ETHADDR_0; thisif.hwaddr[1] = LWIP_ETHADDR_1; thisif.hwaddr[2] = LWIP_ETHADDR_2; thisif.hwaddr[3] = LWIP_ETHADDR_3; thisif.hwaddr[4] = LWIP_ETHADDR_4; thisif.hwaddr[5] = LWIP_ETHADDR_5; LWIP_IPADDR(&ip); LWIP_GATEWAY(&gateway); LWIP_NETMASK(&netmask); } macStart(ÐD1, &mac_config); netif_add(&thisif, &ip, &netmask, &gateway, NULL, ethernetif_init, tcpip_input); netif_set_default(&thisif); netif_set_up(&thisif); /* Setup event sources.*/ evtObjectInit(&evt, LWIP_LINK_POLL_INTERVAL); evtStart(&evt); chEvtRegisterMask(&evt.et_es, &el0, PERIODIC_TIMER_ID); chEvtRegisterMask(macGetReceiveEventSource(ÐD1), &el1, FRAME_RECEIVED_ID); chEvtAddEvents(PERIODIC_TIMER_ID | FRAME_RECEIVED_ID); /* Goes to the final priority after initialization.*/ chThdSetPriority(LWIP_THREAD_PRIORITY); while (TRUE) { eventmask_t mask = chEvtWaitAny(ALL_EVENTS); if (mask & PERIODIC_TIMER_ID) { bool_t current_link_status = macPollLinkStatus(ÐD1); if (current_link_status != netif_is_link_up(&thisif)) { if (current_link_status) tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_up, &thisif, 0); else tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_down, &thisif, 0); } } if (mask & FRAME_RECEIVED_ID) { struct pbuf *p; while ((p = low_level_input(&thisif)) != NULL) { struct eth_hdr *ethhdr = p->payload; switch (htons(ethhdr->type)) { /* IP or ARP packet? */ case ETHTYPE_IP: case ETHTYPE_ARP: #if PPPOE_SUPPORT /* PPPoE packet? */ case ETHTYPE_PPPOEDISC: case ETHTYPE_PPPOE: #endif /* PPPOE_SUPPORT */ /* full packet send to tcpip_thread to process */ if (thisif.input(p, &thisif) == ERR_OK) break; LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); default: pbuf_free(p); } } } } return 0; }
VOS_STATUS vos_start( v_CONTEXT_t vosContext ) { VOS_STATUS vStatus = VOS_STATUS_SUCCESS; tSirRetStatus sirStatus = eSIR_SUCCESS; pVosContextType pVosContext = (pVosContextType)vosContext; tHalMacStartParameters halStartParams; VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO, "%s: Starting Libra SW", __func__); if (gpVosContext != pVosContext) { VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR, "%s: mismatch in context", __func__); return VOS_STATUS_E_FAILURE; } if (( pVosContext->pWDAContext == NULL) || ( pVosContext->pMACContext == NULL) || ( pVosContext->pTLContext == NULL)) { if (pVosContext->pWDAContext == NULL) VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR, "%s: WDA NULL context", __func__); else if (pVosContext->pMACContext == NULL) VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR, "%s: MAC NULL context", __func__); else VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR, "%s: TL NULL context", __func__); return VOS_STATUS_E_FAILURE; } vos_event_reset( &(gpVosContext->wdaCompleteEvent) ); vStatus = WDA_NVDownload_Start(pVosContext); if ( vStatus != VOS_STATUS_SUCCESS ) { VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR, "%s: Failed to start NV Download", __func__); return VOS_STATUS_E_FAILURE; } vStatus = vos_wait_single_event( &(gpVosContext->wdaCompleteEvent), VOS_WDA_TIMEOUT ); if ( vStatus != VOS_STATUS_SUCCESS ) { if ( vStatus == VOS_STATUS_E_TIMEOUT ) { VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR, "%s: Timeout occurred before WDA_NVDownload_start complete", __func__); } else { VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR, "%s: WDA_NVDownload_start reporting other error", __func__); } VOS_ASSERT(0); vos_event_reset( &(gpVosContext->wdaCompleteEvent) ); if (vos_is_logp_in_progress(VOS_MODULE_ID_VOSS, NULL)) { VOS_BUG(0); } WDA_setNeedShutdown(vosContext); return VOS_STATUS_E_FAILURE; } VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO, "%s: WDA_NVDownload_start correctly started", __func__); vStatus = WDA_start(pVosContext); if ( vStatus != VOS_STATUS_SUCCESS ) { VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR, "%s: Failed to start WDA", __func__); return VOS_STATUS_E_FAILURE; } VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO, "%s: WDA correctly started", __func__); vos_mem_zero((v_PVOID_t)&halStartParams, sizeof(tHalMacStartParameters)); sirStatus = macStart(pVosContext->pMACContext,(v_PVOID_t)&halStartParams); if (eSIR_SUCCESS != sirStatus) { VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL, "%s: Failed to start MAC", __func__); goto err_wda_stop; } VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO, "%s: MAC correctly started", __func__); vStatus = sme_Start(pVosContext->pMACContext); if (!VOS_IS_STATUS_SUCCESS(vStatus)) { VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL, "%s: Failed to start SME", __func__); goto err_mac_stop; } VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO, "%s: SME correctly started", __func__); vStatus = WLANTL_Start(pVosContext); if (!VOS_IS_STATUS_SUCCESS(vStatus)) { VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL, "%s: Failed to start TL", __func__); goto err_sme_stop; } VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO, "TL correctly started"); VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO, "%s: VOSS Start is successful!!", __func__); return VOS_STATUS_SUCCESS; err_sme_stop: sme_Stop(pVosContext->pMACContext, HAL_STOP_TYPE_SYS_RESET); err_mac_stop: macStop( pVosContext->pMACContext, HAL_STOP_TYPE_SYS_RESET ); err_wda_stop: vos_event_reset( &(gpVosContext->wdaCompleteEvent) ); vStatus = WDA_stop( pVosContext, HAL_STOP_TYPE_RF_KILL); if (!VOS_IS_STATUS_SUCCESS(vStatus)) { VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR, "%s: Failed to stop WDA", __func__); VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vStatus ) ); WDA_setNeedShutdown(vosContext); } else { vStatus = vos_wait_single_event( &(gpVosContext->wdaCompleteEvent), VOS_WDA_TIMEOUT ); if( vStatus != VOS_STATUS_SUCCESS ) { if( vStatus == VOS_STATUS_E_TIMEOUT ) { VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL, "%s: Timeout occurred before WDA_stop complete", __func__); } else { VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL, "%s: WDA_stop reporting other error", __func__); } VOS_ASSERT( 0 ); WDA_setNeedShutdown(vosContext); } } return VOS_STATUS_E_FAILURE; }