From 5c97ea92544fd062c8fa05c8e2034a7ca5858d97 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 28 Oct 2016 15:22:08 -0500 Subject: [PATCH] lwip - Change k64f emac layer to drop frames on buffer exhaustion Previously, exhausting hardware buffers would begin blocking the lwip thread. This patch changes the emac layer to simply drop ethernet frames, leaving recovery up to a higher level protocol. This is consistent with the behaviour of the emac layer when unable to allocate dynamic memory. --- .../lwip-eth/arch/TARGET_Freescale/k64f_emac.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/TARGET_Freescale/k64f_emac.c b/features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/TARGET_Freescale/k64f_emac.c index 66a0b587b0..0710450ffc 100644 --- a/features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/TARGET_Freescale/k64f_emac.c +++ b/features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/TARGET_Freescale/k64f_emac.c @@ -522,9 +522,10 @@ static err_t k64f_low_level_output(struct netif *netif, struct pbuf *p) dst += q->len; } - /* Wait until a descriptor is available for the transfer. */ - /* THIS WILL BLOCK UNTIL THERE ARE A DESCRIPTOR AVAILABLE */ - osSemaphoreWait(k64f_enet->xTXDCountSem.id, osWaitForever); + /* Check if a descriptor is available for the transfer. */ + int32_t count = osSemaphoreWait(k64f_enet->xTXDCountSem.id, 0); + if (count < 1) + return ERR_BUF; /* Get exclusive access */ sys_mutex_lock(&k64f_enet->TXLockMutex);