Merge branch 'bugfix/tw14130_fix_emac_rx_buf_err' into 'master'

lwip/ethernet: fix emac rx buf err

See merge request !1037
This commit is contained in:
Jiang Jiang Jian 2017-07-25 20:41:22 +08:00
commit f19b08b25a
2 changed files with 16 additions and 5 deletions

View file

@ -449,10 +449,12 @@ static void emac_process_rx_unavail(void)
while (emac_config.cnt_rx < DMA_RX_BUF_NUM) { while (emac_config.cnt_rx < DMA_RX_BUF_NUM) {
emac_config.cnt_rx++;
//copy data to lwip //copy data to lwip
emac_config.emac_tcpip_input((void *)(emac_config.dma_erx[emac_config.dirty_rx].basic.desc2), 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.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) { if (emac_config.cnt_rx > DMA_RX_BUF_NUM) {
ESP_LOGE(TAG, "emac rx unavail buf err !!\n"); 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)) { 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 ) { 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 //copy data to lwip
emac_config.emac_tcpip_input((void *)(emac_config.dma_erx[emac_config.dirty_rx].basic.desc2), 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.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 ) { if (emac_config.cnt_rx > DMA_RX_BUF_NUM ) {
ESP_LOGE(TAG, "emac rx buf err!!\n"); 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) { 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) { while (emac_config.cnt_rx < DMA_RX_BUF_NUM) {
emac_config.cnt_rx++;
//copy data to lwip //copy data to lwip
emac_config.emac_tcpip_input((void *)(emac_config.dma_erx[emac_config.dirty_rx].basic.desc2), 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.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) { if (emac_config.cnt_rx > DMA_RX_BUF_NUM) {
ESP_LOGE(TAG, "emac rx buf err!!!\n"); ESP_LOGE(TAG, "emac rx buf err!!!\n");
} }

View file

@ -147,6 +147,13 @@ ethernet_low_level_output(struct netif *netif, struct pbuf *p)
* the appropriate input function is called. * the appropriate input function is called.
* *
* @param netif the lwip network interface structure for this ethernetif * @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 void
ethernetif_input(struct netif *netif, void *buffer, uint16_t len) 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; struct pbuf *p;
if(buffer== NULL || !netif_is_up(netif)) { if(buffer== NULL || !netif_is_up(netif)) {
#ifndef CONFIG_EMAC_L2_TO_L3_RX_BUF_MODE
if (buffer) { if (buffer) {
esp_eth_free_rx_buf(buffer); esp_eth_free_rx_buf(buffer);
} }
#endif
return; return;
} }
#ifdef CONFIG_EMAC_L2_TO_L3_RX_BUF_MODE #ifdef CONFIG_EMAC_L2_TO_L3_RX_BUF_MODE
p = pbuf_alloc(PBUF_RAW, len, PBUF_RAM); p = pbuf_alloc(PBUF_RAW, len, PBUF_RAM);
if (p == NULL) { if (p == NULL) {
esp_eth_free_rx_buf(buffer);
return; return;
} }
p->l2_owner = NULL; p->l2_owner = NULL;