/* * low_level_input(): Should allocate a pbuf and transfer the bytes of the * incoming packet from the interface into the pbuf. */ static struct pbuf *low_level_input( struct netif *netif ) { struct pbuf *p = NULL, *q; u16_t len = 0; static SemaphoreHandle_t xRxSemaphore = NULL; /* Parameter not used. */ ( void ) netif; if( xRxSemaphore == NULL ) { vSemaphoreCreateBinary( xRxSemaphore ); } /* Access to the emac is guarded using a semaphore. */ if( xSemaphoreTake( xRxSemaphore, netifGUARD_BLOCK_TIME ) ) { /* Obtain the size of the packet. */ len = ulEMACInputLength(); if( len ) { #if ETH_PAD_SIZE len += ETH_PAD_SIZE; /* allow room for Ethernet padding */ #endif /* We allocate a pbuf chain of pbufs from the pool. */ p = pbuf_alloc( PBUF_RAW, len, PBUF_POOL ); if( p != NULL ) { #if ETH_PAD_SIZE pbuf_header( p, -ETH_PAD_SIZE ); /* drop the padding word */ #endif /* Let the driver know we are going to read a new packet. */ vEMACRead( NULL, 0, len ); /* We iterate over the pbuf chain until we have read the entire packet into the pbuf. */ for( q = p; q != NULL; q = q->next ) { /* Read enough bytes to fill this pbuf in the chain. The available data in the pbuf is given by the q->len variable. */ vEMACRead( q->payload, q->len, len ); } #if ETH_PAD_SIZE pbuf_header( p, ETH_PAD_SIZE ); /* reclaim the padding word */ #endif #if LINK_STATS lwip_stats.link.recv++; #endif /* LINK_STATS */ } else { #if LINK_STATS lwip_stats.link.memerr++; lwip_stats.link.drop++; #endif /* LINK_STATS */ } } xSemaphoreGive( xRxSemaphore ); } return p; }
/** * Should allocate a pbuf and transfer the bytes of the incoming * packet from the interface into the pbuf. * * @param netif the lwip network interface structure for this ethernetif * @return a pbuf filled with the received packet (including MAC header) * NULL on memory error */ static struct pbuf * low_level_input(struct netif *netif) { //struct ethernetif *ethernetif = netif->state; /* MakingThings: Initialized p */ struct pbuf *p = NULL; struct pbuf *q; /* MakingThings: Initialized len */ u16_t len = 0; /* MakingThings: Add for FreeRTOS */ static xSemaphoreHandle xRxSemaphore = NULL; /* Parameter not used. */ ( void ) netif; /* MakingThings: Add for FreeRTOS */ if( xRxSemaphore == NULL ) { vSemaphoreCreateBinary( xRxSemaphore ); } /* Access to the emac is guarded using a semaphore. */ if( xSemaphoreTake( xRxSemaphore, netifGUARD_BLOCK_TIME ) ) { /* Obtain the size of the packet. */ len = ulEMACInputLength(); if( len ) { #if ETH_PAD_SIZE len += ETH_PAD_SIZE; /* allow room for Ethernet padding */ #endif /* We allocate a pbuf chain of pbufs from the pool. */ p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); if (p != NULL) { #if ETH_PAD_SIZE pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ #endif /* MakingThings: Added */ /* Let the driver know we are going to read a new packet. */ vEMACRead( NULL, 0, len ); /* We iterate over the pbuf chain until we have read the entire * packet into the pbuf. */ for(q = p; q != NULL; q = q->next) { /* Read enough bytes to fill this pbuf in the chain. The * available data in the pbuf is given by the q->len * variable. */ // read data into(q->payload, q->len); vEMACRead( q->payload, q->len, len ); } // MakingThings: for FreeRTOS - nope // acknowledge that packet has been read(); #if ETH_PAD_SIZE pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ #endif LINK_STATS_INC(link.recv); } else { //drop packet(); LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.drop); } } xSemaphoreGive( xRxSemaphore ); } return p; }