diff --git a/components/ethernet/emac_main.c b/components/ethernet/emac_main.c index 8c24eb4f9..391ffcdb4 100644 --- a/components/ethernet/emac_main.c +++ b/components/ethernet/emac_main.c @@ -449,10 +449,12 @@ static void emac_process_rx_unavail(void) while (emac_config.cnt_rx < DMA_RX_BUF_NUM) { + emac_config.cnt_rx++; + //copy data to lwip emac_config.emac_tcpip_input((void *)(emac_config.dma_erx[emac_config.dirty_rx].basic.desc2), (((emac_config.dma_erx[emac_config.dirty_rx].basic.desc0) >> EMAC_DESC_FRAME_LENGTH_S) & EMAC_DESC_FRAME_LENGTH) , NULL); - emac_config.cnt_rx++; + if (emac_config.cnt_rx > DMA_RX_BUF_NUM) { ESP_LOGE(TAG, "emac rx unavail buf err !!\n"); } @@ -476,12 +478,12 @@ static void emac_process_rx(void) if (((uint32_t) & (emac_config.dma_erx[emac_config.dirty_rx].basic.desc0) != cur_rx_desc)) { while (((uint32_t) & (emac_config.dma_erx[emac_config.dirty_rx].basic.desc0) != cur_rx_desc) && emac_config.cnt_rx < DMA_RX_BUF_NUM ) { + emac_config.cnt_rx++; + //copy data to lwip emac_config.emac_tcpip_input((void *)(emac_config.dma_erx[emac_config.dirty_rx].basic.desc2), (((emac_config.dma_erx[emac_config.dirty_rx].basic.desc0) >> EMAC_DESC_FRAME_LENGTH_S) & EMAC_DESC_FRAME_LENGTH) , NULL); - emac_config.cnt_rx++; - if (emac_config.cnt_rx > DMA_RX_BUF_NUM ) { ESP_LOGE(TAG, "emac rx buf err!!\n"); } @@ -494,10 +496,11 @@ static void emac_process_rx(void) if ((emac_config.dma_erx[emac_config.dirty_rx].basic.desc0 & EMAC_DESC_RX_OWN) == 0) { while (emac_config.cnt_rx < DMA_RX_BUF_NUM) { + emac_config.cnt_rx++; //copy data to lwip emac_config.emac_tcpip_input((void *)(emac_config.dma_erx[emac_config.dirty_rx].basic.desc2), (((emac_config.dma_erx[emac_config.dirty_rx].basic.desc0) >> EMAC_DESC_FRAME_LENGTH_S) & EMAC_DESC_FRAME_LENGTH) , NULL); - emac_config.cnt_rx++; + if (emac_config.cnt_rx > DMA_RX_BUF_NUM) { ESP_LOGE(TAG, "emac rx buf err!!!\n"); } diff --git a/components/lwip/port/netif/ethernetif.c b/components/lwip/port/netif/ethernetif.c index f4bb92413..9189c03a9 100644 --- a/components/lwip/port/netif/ethernetif.c +++ b/components/lwip/port/netif/ethernetif.c @@ -147,6 +147,13 @@ ethernet_low_level_output(struct netif *netif, struct pbuf *p) * the appropriate input function is called. * * @param netif the lwip network interface structure for this ethernetif + * @param buffer the ethernet buffer + * @param len the len of buffer + * + * @note When CONFIG_EMAC_L2_TO_L3_RX_BUF_MODE is enabled, a copy of buffer + * will be made for high layer (LWIP) and ethernet is responsible for + * freeing the buffer. Otherwise, high layer and ethernet share the + * same buffer and high layer is responsible for freeing the buffer. */ void ethernetif_input(struct netif *netif, void *buffer, uint16_t len) @@ -154,16 +161,17 @@ ethernetif_input(struct netif *netif, void *buffer, uint16_t len) struct pbuf *p; if(buffer== NULL || !netif_is_up(netif)) { +#ifndef CONFIG_EMAC_L2_TO_L3_RX_BUF_MODE if (buffer) { esp_eth_free_rx_buf(buffer); } +#endif return; } #ifdef CONFIG_EMAC_L2_TO_L3_RX_BUF_MODE p = pbuf_alloc(PBUF_RAW, len, PBUF_RAM); if (p == NULL) { - esp_eth_free_rx_buf(buffer); return; } p->l2_owner = NULL;