From 1ff410957f91d7fcdffadb0a1479567637d96b3c Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Wed, 15 Jan 2020 14:05:52 +0800 Subject: [PATCH] sim/net: do not do any critical operations in idle Change-Id: Ia9011b62ea61d15bd66aa063e4165d9d3baacb51 Signed-off-by: chao.an --- arch/sim/src/sim/up_netdriver.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/arch/sim/src/sim/up_netdriver.c b/arch/sim/src/sim/up_netdriver.c index 10e2ebe6b52..a974027c603 100644 --- a/arch/sim/src/sim/up_netdriver.c +++ b/arch/sim/src/sim/up_netdriver.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include @@ -84,6 +85,10 @@ struct timer static struct timer g_periodic_timer; +/* Net driver worker */ + +static struct work_s g_network; + /* A single packet buffer is used */ static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE]; @@ -159,11 +164,7 @@ static int sim_txpoll(struct net_driver_s *dev) return 0; } -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void netdriver_loop(void) +static void netdriver_work(FAR void *arg) { FAR struct eth_hdr_s *eth; @@ -328,6 +329,18 @@ void netdriver_loop(void) sched_unlock(); } +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void netdriver_loop(void) +{ + if (work_available(&g_network)) + { + work_queue(LPWORK, &g_network, netdriver_work, NULL, 0); + } +} + int netdriver_ifup(struct net_driver_s *dev) { netdev_ifup(dev->d_ipaddr);