Skip to content

Robustness fixes for netstack #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 30, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions libraries/net/eth/lwip-eth/arch/lpc17_emac.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
*/
#define TXINTGROUP (EMAC_INT_TX_UNDERRUN | EMAC_INT_TX_ERR | EMAC_INT_TX_DONE)

/** \brief Signal used for ethernet ISR to signal packet_rx() thread.
*/
#define RX_SIGNAL 1

#else
#define RXINTGROUP 0
#define TXINTGROUP 0
Expand Down Expand Up @@ -123,7 +127,7 @@ struct lpc_enetdata {
struct pbuf *txb[LPC_NUM_BUFF_TXDESCS]; /**< TX pbuf pointer list, zero-copy mode */
u32_t lpc_last_tx_idx; /**< TX last descriptor index, zero-copy mode */
#if NO_SYS == 0
sys_sem_t RxSem; /**< RX receive thread wakeup semaphore */
sys_thread_t RxThread; /**< RX receive thread data object pointer */
sys_sem_t TxCleanSem; /**< TX cleanup thread wakeup semaphore */
sys_mutex_t TXLockMutex; /**< TX critical section mutex */
sys_sem_t xTXDCountSem; /**< TX free buffer counting semaphore */
Expand Down Expand Up @@ -346,6 +350,7 @@ static struct pbuf *lpc_low_level_input(struct netif *netif)
struct lpc_enetdata *lpc_enetif = netif->state;
struct pbuf *p = NULL;
u32_t idx, length;
u16_t origLength;

#ifdef LOCK_RX_THREAD
#if NO_SYS == 0
Expand Down Expand Up @@ -428,6 +433,7 @@ static struct pbuf *lpc_low_level_input(struct netif *netif)

/* Zero-copy */
p = lpc_enetif->rxb[idx];
origLength = p->len;
p->len = (u16_t) length;

/* Free pbuf from descriptor */
Expand All @@ -440,6 +446,7 @@ static struct pbuf *lpc_low_level_input(struct netif *netif)
LINK_STATS_INC(link.drop);

/* Re-queue the pbuf for receive */
p->len = origLength;
lpc_rxqueue_pbuf(lpc_enetif, p);

LWIP_DEBUGF(UDP_LPC_EMAC | LWIP_DBG_TRACE,
Expand Down Expand Up @@ -780,8 +787,8 @@ void ENET_IRQHandler(void)
ints = LPC_EMAC->IntStatus;

if (ints & RXINTGROUP) {
/* RX group interrupt(s): Give semaphore to wakeup RX receive task.*/
sys_sem_signal(&lpc_enetdata.RxSem);
/* RX group interrupt(s): Give signal to wakeup RX receive task.*/
osSignalSet(lpc_enetdata.RxThread->id, RX_SIGNAL);
}

if (ints & TXINTGROUP) {
Expand All @@ -807,7 +814,7 @@ static void packet_rx(void* pvParameters) {

while (1) {
/* Wait for receive task to wakeup */
sys_arch_sem_wait(&lpc_enetif->RxSem, 0);
osSignalWait(RX_SIGNAL, osWaitForever);

/* Process packets until all empty */
while (LPC_EMAC->RxConsumeIndex != LPC_EMAC->RxProduceIndex)
Expand Down Expand Up @@ -1093,9 +1100,8 @@ err_t lpc_enetif_init(struct netif *netif)
LWIP_ASSERT("TXLockMutex creation error", (err == ERR_OK));

/* Packet receive task */
err = sys_sem_new(&lpc_enetdata.RxSem, 0);
LWIP_ASSERT("RxSem creation error", (err == ERR_OK));
sys_thread_new("receive_thread", packet_rx, netif->state, DEFAULT_THREAD_STACKSIZE, RX_PRIORITY);
lpc_enetdata.RxThread = sys_thread_new("receive_thread", packet_rx, netif->state, DEFAULT_THREAD_STACKSIZE, RX_PRIORITY);
LWIP_ASSERT("RxThread creation error", (lpc_enetdata.RxThread));

/* Transmit cleanup task */
err = sys_sem_new(&lpc_enetdata.TxCleanSem, 0);
Expand Down
2 changes: 2 additions & 0 deletions libraries/net/lwip/lwip/core/pbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,8 @@ pbuf_coalesce(struct pbuf *p, pbuf_layer layer)
}
err = pbuf_copy(q, p);
LWIP_ASSERT("pbuf_copy failed", err == ERR_OK);
/* next line references err variable even if LWIP_ASSERT is ignored. */
(void)err;
pbuf_free(p);
return q;
}
Expand Down
3 changes: 3 additions & 0 deletions libraries/net/lwip/lwip/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#if NO_SYS == 0
#include "cmsis_os.h"

#define SYS_LIGHTWEIGHT_PROT 1

#define LWIP_RAW 0

#define TCPIP_MBOX_SIZE 8
Expand Down Expand Up @@ -99,6 +101,7 @@
#define MEMP_OVERFLOW_CHECK 1
#define MEMP_SANITY_CHECK 1
#else
#define LWIP_NOASSERT 1
#define LWIP_STATS 0
#endif

Expand Down