]> granicus.if.org Git - esp-idf/commitdiff
lwip/ethernet: fix emac rx buf err
authorLiu Zhi Fu <liuzhifu@espressif.com>
Thu, 20 Jul 2017 10:09:06 +0000 (18:09 +0800)
committerLiu Zhi Fu <liuzhifu@espressif.com>
Tue, 25 Jul 2017 03:19:31 +0000 (11:19 +0800)
1. Lwip not free the ethernet buf in lwip layer
2. Fix emac counter error

components/ethernet/emac_main.c
components/lwip/port/netif/ethernetif.c

index 8c24eb4f97bc268b497c48c505c1c34ebd3f0fd7..391ffcdb43b0dbe346803aa690054443d70ed4ca 100644 (file)
@@ -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");
                     }
index f4bb9241310870bf2fb002f132e03557bc09888a..9189c03a91751d13283363af33181711170b9eaa 100644 (file)
@@ -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;