From dea24c503a073a2200d27e039c9a15c428d96d7a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 3 Feb 2016 12:12:41 -0600 Subject: [PATCH] Networking: Remove the HSEC argument from devif_timer. --- ChangeLog | 6 ++- arch | 2 +- drivers/net/cs89x0.c | 3 +- drivers/net/dm90x0.c | 3 +- drivers/net/e1000.c | 3 +- drivers/net/enc28j60.c | 3 +- drivers/net/encx24j600.c | 3 +- drivers/net/ftmac100.c | 3 +- drivers/net/loopback.c | 3 +- drivers/net/skeleton.c | 3 +- drivers/net/slip.c | 2 +- drivers/net/tun.c | 3 +- drivers/net/vnet.c | 3 +- include/nuttx/clock.h | 20 ++++++-- include/nuttx/net/netdev.h | 5 +- net/arp/arp_poll.c | 8 ---- net/devif/devif.h | 5 ++ net/devif/devif_initialize.c | 13 ++---- net/devif/devif_poll.c | 73 ++++++++++++++++++++++-------- net/neighbor/neighbor.h | 30 ++---------- net/neighbor/neighbor_initialize.c | 33 +------------- net/neighbor/neighbor_periodic.c | 53 ++++++++-------------- net/net_initialize.c | 8 +--- 23 files changed, 123 insertions(+), 165 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7712850411..a74d8a4917 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11444,4 +11444,8 @@ these are MCU-specific interfaces used only be MCU-specific code. The the correct naming is xyz_i2cbus_initialize and xzy_i2cbus_uninitialize where xzy is the MCU mnemonic (2016-02-02). - + * Networking drivers that support CONFIG_NET_NOINTS: Fix a race condition + that can cause the TX poll timer to stop running. From Manuel Stuhn + (2016-02-03). + * All Network drivers: Remove the hsec parameter from devif_timer(). + We can get better timing accuracy without it (2016-02-03). diff --git a/arch b/arch index be6af64502..757fb2224a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit be6af64502d5520799fcba3ed20b6fff13f88ca0 +Subproject commit 757fb2224ae99916b8b46695a007a6be06f33dfb diff --git a/drivers/net/cs89x0.c b/drivers/net/cs89x0.c index 5adbe42135..f27c0a077d 100644 --- a/drivers/net/cs89x0.c +++ b/drivers/net/cs89x0.c @@ -76,7 +76,6 @@ /* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define CS89x0_WDDELAY (1*CLK_TCK) -#define CS89x0_POLLHSEC (1*2) /* TX timeout = 1 minute */ @@ -790,7 +789,7 @@ static void cs89x0_polltimer(int argc, uint32_t arg, ...) /* If so, update TCP timing states and poll uIP for new XMIT data */ - (void)devif_timer(&cs89x0->cs_dev, cs89x0_txpoll, CS89x0_POLLHSEC); + (void)devif_timer(&cs89x0->cs_dev, cs89x0_txpoll); /* Setup the watchdog poll timer again */ diff --git a/drivers/net/dm90x0.c b/drivers/net/dm90x0.c index e810c6b672..37e49d3bae 100644 --- a/drivers/net/dm90x0.c +++ b/drivers/net/dm90x0.c @@ -266,7 +266,6 @@ /* TX poll deley = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define DM6X_WDDELAY (1*CLK_TCK) -#define DM6X_POLLHSEC (1*2) /* TX timeout = 1 minute */ @@ -1266,7 +1265,7 @@ static void dm9x_polltimer(int argc, uint32_t arg, ...) { /* If so, update TCP timing states and poll uIP for new XMIT data */ - (void)devif_timer(&dm9x->dm_dev, dm9x_txpoll, DM6X_POLLHSEC); + (void)devif_timer(&dm9x->dm_dev, dm9x_txpoll); } /* Setup the watchdog poll timer again */ diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c index cbed8d5656..cdc8f236e0 100644 --- a/drivers/net/e1000.c +++ b/drivers/net/e1000.c @@ -78,7 +78,6 @@ /* TX poll deley = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define E1000_WDDELAY (1*CLK_TCK) -#define E1000_POLLHSEC (1*2) /* TX timeout = 1 minute */ @@ -770,7 +769,7 @@ static void e1000_polltimer(int argc, uint32_t arg, ...) * we will missing TCP time state updates? */ - (void)devif_timer(&e1000->netdev, e1000_txpoll, E1000_POLLHSEC); + (void)devif_timer(&e1000->netdev, e1000_txpoll); /* Setup the watchdog poll timer again */ diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c index db3bbb2de5..e1665ea86b 100644 --- a/drivers/net/enc28j60.c +++ b/drivers/net/enc28j60.c @@ -144,7 +144,6 @@ /* TX poll deley = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define ENC_WDDELAY (1*CLK_TCK) -#define ENC_POLLHSEC (1*2) /* TX timeout = 1 minute */ @@ -1990,7 +1989,7 @@ static void enc_pollworker(FAR void *arg) * in progress, we will missing TCP time state updates? */ - (void)devif_timer(&priv->dev, enc_txpoll, ENC_POLLHSEC); + (void)devif_timer(&priv->dev, enc_txpoll); } /* Release lock on the SPI bus and uIP */ diff --git a/drivers/net/encx24j600.c b/drivers/net/encx24j600.c index d5846c752b..baa18cc438 100644 --- a/drivers/net/encx24j600.c +++ b/drivers/net/encx24j600.c @@ -149,7 +149,6 @@ /* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define ENC_WDDELAY (1*CLK_TCK) -#define ENC_POLLHSEC (1*2) /* TX timeout = 1 minute */ @@ -2156,7 +2155,7 @@ static void enc_pollworker(FAR void *arg) * in progress, we will missing TCP time state updates? */ - (void)devif_timer(&priv->dev, enc_txpoll, ENC_POLLHSEC); + (void)devif_timer(&priv->dev, enc_txpoll); } /* Release lock on the SPI bus and uIP */ diff --git a/drivers/net/ftmac100.c b/drivers/net/ftmac100.c index 9e2ada57ff..6a9f53ed13 100644 --- a/drivers/net/ftmac100.c +++ b/drivers/net/ftmac100.c @@ -91,7 +91,6 @@ /* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define FTMAC100_WDDELAY (1*CLK_TCK) -#define FTMAC100_POLLHSEC (1*2) /* TX timeout = 1 minute */ @@ -1200,7 +1199,7 @@ static inline void ftmac100_poll_process(FAR struct ftmac100_driver_s *priv) * we will missing TCP time state updates? */ - (void)devif_timer(&priv->ft_dev, ftmac100_txpoll, FTMAC100_POLLHSEC); + (void)devif_timer(&priv->ft_dev, ftmac100_txpoll); /* Setup the watchdog poll timer again */ diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 7bb99c1744..3b750b8051 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -78,7 +78,6 @@ /* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define LO_WDDELAY (1*CLK_TCK) -#define LO_POLLHSEC (1*2) /* This is a helper pointer for accessing the contents of the Ethernet header */ @@ -242,7 +241,7 @@ static void lo_poll_work(FAR void *arg) state = net_lock(); priv->lo_txdone = false; - (void)devif_timer(&priv->lo_dev, lo_txpoll, LO_POLLHSEC); + (void)devif_timer(&priv->lo_dev, lo_txpoll); /* Was something received and looped back? */ diff --git a/drivers/net/skeleton.c b/drivers/net/skeleton.c index 516b6f0e8c..ef6f2bf595 100644 --- a/drivers/net/skeleton.c +++ b/drivers/net/skeleton.c @@ -86,7 +86,6 @@ /* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define skeleton_WDDELAY (1*CLK_TCK) -#define skeleton_POLLHSEC (1*2) /* TX timeout = 1 minute */ @@ -746,7 +745,7 @@ static inline void skel_poll_process(FAR struct skel_driver_s *priv) * progress, we will missing TCP time state updates? */ - (void)devif_timer(&priv->sk_dev, skel_txpoll, skeleton_POLLHSEC); + (void)devif_timer(&priv->sk_dev, skel_txpoll); /* Setup the watchdog poll timer again */ diff --git a/drivers/net/slip.c b/drivers/net/slip.c index d1ecef3aca..c02ebb0e93 100644 --- a/drivers/net/slip.c +++ b/drivers/net/slip.c @@ -490,7 +490,7 @@ static void slip_txtask(int argc, FAR char *argv[]) { /* Yes, perform the timer poll */ - (void)devif_timer(&priv->dev, slip_txpoll, hsec); + (void)devif_timer(&priv->dev, slip_txpoll); msec_start += hsec * (MSEC_PER_SEC / 2); } else diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 97a4fd7d26..1221b56ad8 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -96,7 +96,6 @@ */ #define TUN_WDDELAY (1*CLK_TCK) -#define TUN_POLLHSEC (1*2) /**************************************************************************** * Private Types @@ -533,7 +532,7 @@ static void tun_poll_process(FAR struct tun_device_s *priv) /* If so, poll uIP for new XMIT data. */ priv->dev.d_buf = priv->read_buf; - (void)devif_timer(&priv->dev, tun_txpoll, TUN_POLLHSEC); + (void)devif_timer(&priv->dev, tun_txpoll); } /* Setup the watchdog poll timer again */ diff --git a/drivers/net/vnet.c b/drivers/net/vnet.c index d8849d8194..e57b654a9d 100644 --- a/drivers/net/vnet.c +++ b/drivers/net/vnet.c @@ -81,7 +81,6 @@ /* TX poll deley = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define VNET_WDDELAY (1*CLK_TCK) -#define VNET_POLLHSEC (1*2) /* TX timeout = 1 minute */ @@ -518,7 +517,7 @@ static void vnet_polltimer(int argc, uint32_t arg, ...) * progress, we will missing TCP time state updates? */ - (void)devif_timer(&vnet->sk_dev, vnet_txpoll, VNET_POLLHSEC); + (void)devif_timer(&vnet->sk_dev, vnet_txpoll); /* Setup the watchdog poll timer again */ diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h index 501545fac9..c0fcc35b75 100644 --- a/include/nuttx/clock.h +++ b/include/nuttx/clock.h @@ -99,16 +99,25 @@ /* Timing constants *********************************************************/ -#define NSEC_PER_SEC 1000000000L +#define NSEC_PER_SEC 1000000000L /* Seconds */ #define USEC_PER_SEC 1000000L #define MSEC_PER_SEC 1000L #define DSEC_PER_SEC 10L -#define NSEC_PER_DSEC 100000000L +#define HSEC_PER_SEC 2L + +#define NSEC_PER_HSEC 500000000L /* Half seconds */ +#define USEC_PER_HSEC 500000L +#define MSEC_PER_HSEC 500L +#define DSEC_PER_HSEC 5L + +#define NSEC_PER_DSEC 100000000L /* Deciseconds */ #define USEC_PER_DSEC 100000L #define MSEC_PER_DSEC 100L -#define NSEC_PER_MSEC 1000000L + +#define NSEC_PER_MSEC 1000000L /* Milliseconds */ #define USEC_PER_MSEC 1000L -#define NSEC_PER_USEC 1000L + +#define NSEC_PER_USEC 1000L /* Microseconds */ /* If CONFIG_SCHED_TICKLESS is not defined, then the interrupt interval of * the system timer is given by USEC_PER_TICK. This is the expected number @@ -136,6 +145,7 @@ */ #define TICK_PER_DSEC (USEC_PER_DSEC / USEC_PER_TICK) /* Truncates! */ +#define TICK_PER_HSEC (USEC_PER_HSEC / USEC_PER_TICK) /* Truncates! */ #define TICK_PER_SEC (USEC_PER_SEC / USEC_PER_TICK) /* Truncates! */ #define TICK_PER_MSEC (USEC_PER_MSEC / USEC_PER_TICK) /* Truncates! */ #define MSEC_PER_TICK (USEC_PER_TICK / USEC_PER_MSEC) /* Truncates! */ @@ -151,6 +161,7 @@ #endif #define DSEC2TICK(dsec) MSEC2TICK((dsec) * MSEC_PER_DSEC) /* Rounds */ +#define HSEC2TICK(dsec) MSEC2TICK((dsec) * MSEC_PER_HSEC) /* Rounds */ #define SEC2TICK(sec) MSEC2TICK((sec) * MSEC_PER_SEC) /* Rounds */ #define TICK2NSEC(tick) ((tick) * NSEC_PER_TICK) /* Exact */ @@ -163,6 +174,7 @@ #endif #define TICK2DSEC(tick) (((tick)+(TICK_PER_DSEC/2))/TICK_PER_DSEC) /* Rounds */ +#define TICK2HSEC(tick) (((tick)+(TICK_PER_HSEC/2))/TICK_PER_HSEC) /* Rounds */ #define TICK2SEC(tick) (((tick)+(TICK_PER_SEC/2))/TICK_PER_SEC) /* Rounds */ /**************************************************************************** diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index 3182e7f80b..de6e997faf 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -2,7 +2,7 @@ * include/nuttx/net/netdev.h * Defines architecture-specific device driver interfaces to the uIP network. * - * Copyright (C) 2007, 2009, 2011-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Derived largely from portions of uIP with has a similar BSD-styple license: @@ -475,8 +475,7 @@ int ipv6_input(FAR struct net_driver_s *dev); ****************************************************************************/ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback); -int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback, - int hsec); +int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback); /**************************************************************************** * Name: neighbor_out diff --git a/net/arp/arp_poll.c b/net/arp/arp_poll.c index 85cc2b38c0..424d0fe2e7 100644 --- a/net/arp/arp_poll.c +++ b/net/arp/arp_poll.c @@ -48,14 +48,6 @@ #ifdef CONFIG_NET_ARP_SEND -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/devif/devif.h b/net/devif/devif.h index a7c26d3437..58f7fffa9d 100644 --- a/net/devif/devif.h +++ b/net/devif/devif.h @@ -51,6 +51,7 @@ #include #include +#include #include /**************************************************************************** @@ -256,6 +257,10 @@ extern uint16_t g_ipid; extern uint8_t g_reassembly_timer; #endif +/* Time of last poll */ + +extern systime_t g_polltime; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/net/devif/devif_initialize.c b/net/devif/devif_initialize.c index 606a22f9b7..4142019e2c 100644 --- a/net/devif/devif_initialize.c +++ b/net/devif/devif_initialize.c @@ -46,6 +46,7 @@ #include +#include #include #include @@ -139,14 +140,6 @@ const struct ether_addr g_ipv6_ethallrouters = /* All link local routers */ #endif /* CONFIG_NET_ICMPv6_AUTOCONF || CONFIG_NET_ICMPv6_ROUTER */ #endif /* CONFIG_NET_IPv4 */ -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -167,6 +160,10 @@ const struct ether_addr g_ipv6_ethallrouters = /* All link local routers */ void devif_initialize(void) { + /* Initialize the time of the last timer poll */ + + g_polltime = clock_systimer(); + /* Initialize callback support */ devif_callback_init(); diff --git a/net/devif/devif_poll.c b/net/devif/devif_poll.c index 67f7e05c02..32a2eb51ab 100644 --- a/net/devif/devif_poll.c +++ b/net/devif/devif_poll.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/devif/devif_poll.c * - * Copyright (C) 2007-2010, 2012, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2010, 2012, 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -42,6 +42,7 @@ #include +#include #include #include @@ -56,9 +57,13 @@ #include "igmp/igmp.h" /**************************************************************************** - * Private Data + * Public Data ****************************************************************************/ +/* Time of last poll */ + +systime_t g_polltime; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -258,22 +263,30 @@ static inline int devif_poll_tcp_connections(FAR struct net_driver_s *dev, #ifdef CONFIG_NET_TCP static inline int devif_poll_tcp_timer(FAR struct net_driver_s *dev, - devif_poll_callback_t callback, int hsec) + devif_poll_callback_t callback, + int hsec) { FAR struct tcp_conn_s *conn = NULL; int bstop = 0; - /* Traverse all of the active TCP connections and perform the poll action */ + /* Don't do anything is less a half second has elapsed */ - while (!bstop && (conn = tcp_nextconn(conn))) + if (hsec > 0) { - /* Perform the TCP timer poll */ + /* Traverse all of the active TCP connections and perform the poll + * action. + */ - tcp_timer(dev, conn, hsec); + while (!bstop && (conn = tcp_nextconn(conn))) + { + /* Perform the TCP timer poll */ - /* Call back into the driver */ + tcp_timer(dev, conn, hsec); - bstop = callback(dev); + /* Call back into the driver */ + + bstop = callback(dev); + } } return bstop; @@ -414,26 +427,46 @@ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback) * ****************************************************************************/ -int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback, - int hsec) +int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback) { + systime_t now; + systime_t elpased; int bstop = false; + int hsec; - /* Increment the timer used by the IP reassembly logic */ + /* Get the elapsed time since the last poll in units of half seconds + * (truncating). + */ + + now = clock_systimer(); + hsec = (now - g_polltime) / TICK_PER_HSEC; + + /* Update the time only when more than one half second elapses */ + + if (hsec > 0) + { + /* Save the current time */ + + g_polltime = now; + + /* Perform periodic activitives that depend on hsec > 0 */ #if defined(CONFIG_NET_TCP_REASSEMBLY) && defined(CONFIG_NET_IPv4) - if (g_reassembly_timer != 0 && - g_reassembly_timer < CONFIG_NET_TCP_REASS_MAXAGE) - { - g_reassembly_timer += hsec; - } + /* Increment the timer used by the IP reassembly logic */ + + if (g_reassembly_timer != 0 && + g_reassembly_timer < CONFIG_NET_TCP_REASS_MAXAGE) + { + g_reassembly_timer += hsec; + } #endif #ifdef CONFIG_NET_IPv6 - /* Perform ageing on the entries in the Neighbor Table */ + /* Perform aging on the entries in the Neighbor Table */ - neighbor_periodic(); + neighbor_periodic(hsec); #endif + } /* Traverse all of the active packet connections and perform the poll * action. @@ -467,6 +500,8 @@ int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback, { /* Traverse all of the active TCP connections and perform the * timer action. + * + * NOTE: devif_poll_tcp_timer will handle the case where hsec <= 0. */ bstop = devif_poll_tcp_timer(dev, callback, hsec); diff --git a/net/neighbor/neighbor.h b/net/neighbor/neighbor.h index d6330f16a9..a8317f6d36 100644 --- a/net/neighbor/neighbor.h +++ b/net/neighbor/neighbor.h @@ -99,16 +99,12 @@ struct neighbor_entry extern struct neighbor_entry g_neighbors[CONFIG_NET_IPv6_NCONF_ENTRIES]; -/* This is the time, in clock ticks, of the last poll */ - -extern systime_t g_neighbor_polltime; - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ /**************************************************************************** - * Name: neighbor_setup + * Name: neighbor_initialize * * Description: * Initialize Neighbor table data structures. This function is called @@ -124,26 +120,6 @@ extern systime_t g_neighbor_polltime; * ****************************************************************************/ -void neighbor_setup(void); - -/**************************************************************************** - * Name: neighbor_initialize - * - * Description: - * Initialize Neighbor ageing. This function is called from the OS - * initialization logic at power-up reset AFTER initialization of hardware - * facilities such as timers and interrupts. This logic completes the - * initialization started by neighbor_setup. - * - * - * Input Parameters: - * None - * - * Returned Value: - * None - * - ****************************************************************************/ - void neighbor_initialize(void); /**************************************************************************** @@ -226,14 +202,14 @@ void neighbor_update(const net_ipv6addr_t ipaddr); * entries in the Neighbor Table * * Input Parameters: - * None + * hsec - Elapsed time in half seconds since the last check * * Returned Value: * None * ****************************************************************************/ -void neighbor_periodic(void); +void neighbor_periodic(int hsec); #endif /* CONFIG_NET_IPv6 */ #endif /* __NET_NEIGHBOR_NEIGHBOR_H */ diff --git a/net/neighbor/neighbor_initialize.c b/net/neighbor/neighbor_initialize.c index 124e0f9a89..d25fb782f3 100644 --- a/net/neighbor/neighbor_initialize.c +++ b/net/neighbor/neighbor_initialize.c @@ -56,16 +56,12 @@ struct neighbor_entry g_neighbors[CONFIG_NET_IPv6_NCONF_ENTRIES]; -/* This is the time, in clock ticks, of the last poll */ - -systime_t g_neighbor_polltime; - /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: neighbor_setup + * Name: neighbor_initialize * * Description: * Initialize Neighbor table data structures. This function is called @@ -81,7 +77,7 @@ systime_t g_neighbor_polltime; * ****************************************************************************/ -void neighbor_setup(void) +void neighbor_initialize(void) { int i; @@ -90,28 +86,3 @@ void neighbor_setup(void) g_neighbors[i].ne_time = NEIGHBOR_MAXTIME; } } - -/**************************************************************************** - * Name: neighbor_initialize - * - * Description: - * Initialize Neighbor ageing. This function is called from the OS - * initialization logic at power-up reset AFTER initialization of hardware - * facilities such as timers and interrupts. This logic completes the - * initialization started by neighbor_setup. - * - * - * Input Parameters: - * None - * - * Returned Value: - * None - * - ****************************************************************************/ - -void neighbor_initialize(void) -{ - /* Initialize the time of the last poll */ - - g_neighbor_polltime = clock_systimer(); -} diff --git a/net/neighbor/neighbor_periodic.c b/net/neighbor/neighbor_periodic.c index c242b099d2..2ca0a5b3ca 100644 --- a/net/neighbor/neighbor_periodic.c +++ b/net/neighbor/neighbor_periodic.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/neighbor/neighbor_periodic.c * - * Copyright (C) 2007-2009, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * A leverage of logic from uIP which also has a BSD style license @@ -42,18 +42,9 @@ ****************************************************************************/ #include -#include #include "neighbor/neighbor.h" -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -#define USEC_PER_HSEC 500000 -#define TICK_PER_HSEC (USEC_PER_HSEC / USEC_PER_TICK) /* Truncates! */ -#define TICK2HSEC(tick) (((tick)+(TICK_PER_HSEC/2))/TICK_PER_HSEC) /* Rounds */ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -66,42 +57,34 @@ * entries in the Neighbor Table * * Input Parameters: - * None + * hsec - Elapsed time in half seconds since the last check * * Returned Value: * None * ****************************************************************************/ -void neighbor_periodic(void) +void neighbor_periodic(int hsec) { - systime_t now; - systime_t ticks; - uint32_t hsecs; int i; - /* Get the elapsed time in units of half seconds */ + /* Only perform the aging when more than a half second has elapsed */ - now = clock_systimer(); - ticks = now - g_neighbor_polltime; - hsecs = (uint32_t)TICK2HSEC(ticks); - - /* Reset the time of the last poll */ - - g_neighbor_polltime = now; - - /* Add the elapsed half seconds from each activate entry in the - * Neighbor table. - */ - - for (i = 0; i < CONFIG_NET_IPv6_NCONF_ENTRIES; ++i) + if (hsec > 0) { - uint32_t newtime = g_neighbors[i].ne_time + hsecs; - if (newtime > NEIGHBOR_MAXTIME) - { - newtime = NEIGHBOR_MAXTIME; - } + /* Add the elapsed half seconds from each activate entry in the + * Neighbor table. + */ - g_neighbors[i].ne_time = newtime; + for (i = 0; i < CONFIG_NET_IPv6_NCONF_ENTRIES; ++i) + { + uint32_t newtime = g_neighbors[i].ne_time + hsec; + if (newtime > NEIGHBOR_MAXTIME) + { + newtime = NEIGHBOR_MAXTIME; + } + + g_neighbors[i].ne_time = newtime; + } } } diff --git a/net/net_initialize.c b/net/net_initialize.c index 99090c650a..6de3a97c10 100644 --- a/net/net_initialize.c +++ b/net/net_initialize.c @@ -118,7 +118,7 @@ void net_setup(void) #ifdef CONFIG_NET_IPv6 /* Initialize the Neighbor Table data structures */ - neighbor_setup(); + neighbor_initialize(); #endif #ifdef CONFIG_NET_IOB @@ -197,12 +197,6 @@ void net_setup(void) void net_initialize(void) { -#ifdef CONFIG_NET_IPv6 - /* Configure Neighbor Table ageing */ - - neighbor_initialize(); -#endif - /* Initialize the periodic ARP timer */ arp_timer_initialize();