/* Transmit cleanup task This task is called when a transmit interrupt occurs and reclaims the pbuf and descriptor used for the packet once the packet has been transferred */ static void vTransmitCleanupTask(void *pvParameters) { struct lpc_enetdata *lpc_netifdata = pvParameters; while (1) { /* Wait for transmit cleanup task to wakeup */ sys_arch_sem_wait(&lpc_netifdata->TxCleanSem, 0); /* Free TX pbufs and descriptors that are done */ lpc_tx_reclaim(lpc_netifdata->netif); } }
/* Transmit cleanup task for FreeRTOS */ STATIC portTASK_FUNCTION(vTransmitCleanupTask, pvParameters) { lpc_enetdata_t *lpc_enetif = pvParameters; s32_t idx; while (1) { /* Wait for transmit cleanup task to wakeup */ sys_arch_sem_wait(&lpc_enetif->tx_clean_sem, 0); /* Error handling for TX underruns. This should never happen unless something is holding the bus or the clocks are going too slow. It can probably be safely removed. */ if (Chip_ENET_GetIntStatus(LPC_ETHERNET) & ENET_INT_TXUNDERRUN) { LINK_STATS_INC(link.err); LINK_STATS_INC(link.drop); #if NO_SYS == 0 /* Get exclusive access */ sys_mutex_lock(&lpc_enetif->tx_lock_mutex); #endif /* Reset the TX side */ Chip_ENET_ResetTXLogic(LPC_ETHERNET); Chip_ENET_ClearIntStatus(LPC_ETHERNET, ENET_INT_TXUNDERRUN); /* De-allocate all queued TX pbufs */ for (idx = 0; idx < LPC_NUM_BUFF_TXDESCS; idx++) { if (lpc_enetif->txb[idx] != NULL) { pbuf_free(lpc_enetif->txb[idx]); lpc_enetif->txb[idx] = NULL; } } #if NO_SYS == 0 /* Restore access */ sys_mutex_unlock(&lpc_enetif->tx_lock_mutex); #endif /* Start TX side again */ lpc_tx_setup(lpc_enetif); } else { /* Free TX buffers that are done sending */ lpc_tx_reclaim(lpc_enetdata.pnetif); } } }
/** \brief Transmit cleanup task * * This task is called when a transmit interrupt occurs and * reclaims the pbuf and descriptor used for the packet once * the packet has been transferred. * * \param[in] pvParameters Not used yet */ static void packet_tx(void* pvParameters) { struct lpc_enetdata *lpc_enetif = pvParameters; s32_t idx; while (1) { /* Wait for transmit cleanup task to wakeup */ sys_arch_sem_wait(&lpc_enetif->TxCleanSem, 0); /* Error handling for TX underruns. This should never happen unless something is holding the bus or the clocks are going too slow. It can probably be safely removed. */ if (LPC_EMAC->IntStatus & EMAC_INT_TX_UNDERRUN) { LINK_STATS_INC(link.err); LINK_STATS_INC(link.drop); #if NO_SYS == 0 /* Get exclusive access */ sys_mutex_lock(&lpc_enetif->TXLockMutex); #endif /* Reset the TX side */ LPC_EMAC->MAC1 |= EMAC_MAC1_RES_TX; LPC_EMAC->IntClear = EMAC_INT_TX_UNDERRUN; /* De-allocate all queued TX pbufs */ for (idx = 0; idx < LPC_NUM_BUFF_TXDESCS; idx++) { if (lpc_enetif->txb[idx] != NULL) { pbuf_free(lpc_enetif->txb[idx]); lpc_enetif->txb[idx] = NULL; } } #if NO_SYS == 0 /* Restore access */ sys_mutex_unlock(&lpc_enetif->TXLockMutex); #endif /* Start TX side again */ lpc_tx_setup(lpc_enetif); } else { /* Free TX buffers that are done sending */ lpc_tx_reclaim(lpc_enetdata.netif); } } }
/** * @brief main routine for example_lwip_tcpecho_sa_18xx43xx * @return Function should not exit. */ int main(void) { uint32_t physts; ip_addr_t ipaddr, netmask, gw; prvSetupHardware(); /* Initialize LWIP */ lwip_init(); LWIP_DEBUGF(LWIP_DBG_ON, ("Starting LWIP TCP echo server...\n")); /* Static IP assignment */ #if LWIP_DHCP IP4_ADDR(&gw, 0, 0, 0, 0); IP4_ADDR(&ipaddr, 0, 0, 0, 0); IP4_ADDR(&netmask, 0, 0, 0, 0); #else IP4_ADDR(&gw, 10, 1, 10, 1); IP4_ADDR(&ipaddr, 10, 1, 10, 234); IP4_ADDR(&netmask, 255, 255, 255, 0); APP_PRINT_IP(&ipaddr); #endif /* Add netif interface for lpc17xx_8x */ netif_add(&lpc_netif, &ipaddr, &netmask, &gw, NULL, lpc_enetif_init, ethernet_input); netif_set_default(&lpc_netif); netif_set_up(&lpc_netif); #if LWIP_DHCP dhcp_start(&lpc_netif); #endif /* Initialize and start application */ echo_init(); /* This could be done in the sysTick ISR, but may stay in IRQ context too long, so do this stuff with a background loop. */ while (1) { /* Handle packets as part of this loop, not in the IRQ handler */ lpc_enetif_input(&lpc_netif); /* lpc_rx_queue will re-qeueu receive buffers. This normally occurs automatically, but in systems were memory is constrained, pbufs may not always be able to get allocated, so this function can be optionally enabled to re-queue receive buffers. */ #if 0 while (lpc_rx_queue(&lpc_netif)) {} #endif /* Free TX buffers that are done sending */ lpc_tx_reclaim(&lpc_netif); /* LWIP timers - ARP, DHCP, TCP, etc. */ sys_check_timeouts(); /* Call the PHY status update state machine once in a while to keep the link status up-to-date */ physts = lpcPHYStsPoll(); /* Only check for connection state when the PHY status has changed */ if (physts & PHY_LINK_CHANGED) { if (physts & PHY_LINK_CONNECTED) { Board_LED_Set(0, true); /* Set interface speed and duplex */ if (physts & PHY_LINK_SPEED100) { Chip_ENET_SetSpeed(LPC_ETHERNET, 1); NETIF_INIT_SNMP(&lpc_netif, snmp_ifType_ethernet_csmacd, 100000000); } else { Chip_ENET_SetSpeed(LPC_ETHERNET, 0); NETIF_INIT_SNMP(&lpc_netif, snmp_ifType_ethernet_csmacd, 10000000); } if (physts & PHY_LINK_FULLDUPLX) { Chip_ENET_SetDuplex(LPC_ETHERNET, true); } else { Chip_ENET_SetDuplex(LPC_ETHERNET, false); } netif_set_link_up(&lpc_netif); } else { Board_LED_Set(0, false); netif_set_link_down(&lpc_netif); } DEBUGOUT("Link connect status: %d\r\n", ((physts & PHY_LINK_CONNECTED) != 0)); } } /* Never returns, for warning only */ return 0; }
/** * @brief main routine for example_lwip_tcpecho_sa_17xx40xx * @return Function should not exit. */ int main(void) { uint32_t physts; ip_addr_t ipaddr, netmask, gw; static int prt_ip = 0; prvSetupHardware(); /* Initialize LWIP */ lwip_init(); ///LWIP_DEBUGF(LWIP_DBG_ON, ("Starting LWIP TCP echo server...\n")); /* Static IP assignment */ IP4_ADDR(&gw, 0, 0, 0, 0); IP4_ADDR(&ipaddr, 0, 0, 0, 0); IP4_ADDR(&netmask, 0, 0, 0, 0); /* Add netif interface for lpc17xx_8x */ netif_add(&lpc_netif, &ipaddr, &netmask, &gw, NULL, lpc_enetif_init, ethernet_input); netif_set_default(&lpc_netif); netif_set_up(&lpc_netif); dhcp_start(&lpc_netif); uint8_t fl = 0 ; while (1) { /* Handle packets as part of this loop, not in the IRQ handler */ lpc_enetif_input(&lpc_netif); /* lpc_rx_queue will re-qeueu receive buffers. This normally occurs automatically, but in systems were memory is constrained, pbufs may not always be able to get allocated, so this function can be optionally enabled to re-queue receive buffers. */ #if 0 while (lpc_rx_queue(&lpc_netif)) {} #endif /* Free TX buffers that are done sending */ lpc_tx_reclaim(&lpc_netif); /* LWIP timers - ARP, DHCP, TCP, etc. */ sys_check_timeouts(); /* Call the PHY status update state machine once in a while to keep the link status up-to-date */ physts = lpcPHYStsPoll(); /* Only check for connection state when the PHY status has changed */ if (physts & PHY_LINK_CHANGED) { if (physts & PHY_LINK_CONNECTED) { prt_ip = 0; /* Set interface speed and duplex */ if (physts & PHY_LINK_SPEED100) { Chip_ENET_Set100Mbps(LPC_ETHERNET); NETIF_INIT_SNMP(&lpc_netif, snmp_ifType_ethernet_csmacd, 100000000); } else { Chip_ENET_Set10Mbps(LPC_ETHERNET); NETIF_INIT_SNMP(&lpc_netif, snmp_ifType_ethernet_csmacd, 10000000); } if (physts & PHY_LINK_FULLDUPLX) { Chip_ENET_SetFullDuplex(LPC_ETHERNET); } else { Chip_ENET_SetHalfDuplex(LPC_ETHERNET); } netif_set_link_up(&lpc_netif); } else { netif_set_link_down(&lpc_netif); } DEBUGOUT("Link connect status: %d\r\n", ((physts & PHY_LINK_CONNECTED) != 0)); } /* Print IP address info */ if (!prt_ip) { if (lpc_netif.ip_addr.addr) { static char tmp_buff[16]; DEBUGOUT("IP_ADDR : %s\r\n", ipaddr_ntoa_r((const ip_addr_t *) &lpc_netif.ip_addr, tmp_buff, 16)); DEBUGOUT("NET_MASK : %s\r\n", ipaddr_ntoa_r((const ip_addr_t *) &lpc_netif.netmask, tmp_buff, 16)); DEBUGOUT("GATEWAY_IP : %s\r\n", ipaddr_ntoa_r((const ip_addr_t *) &lpc_netif.gw, tmp_buff, 16)); prt_ip = 1; mqttAppInit(); mqttAppConnect(); ////// mqttAppDisconnect(); } } if(mqttIsConnected()==1) { mqttAppHandle(); if (fl == 0) { mqttAppSubscribe("lpc/#"); mqttAppSubscribe("lpc/teste"); fl = 1; } } } return 0; }