diff --git a/ChangeLog b/ChangeLog index 7f550033742bacebd7a00fab0a44fad2d71f0395..bb6b359ae2554ec7fef21f86ec3608be060af469 100644 --- a/ChangeLog +++ b/ChangeLog @@ -213,4 +213,6 @@ * Provide support for multiple network devices * Implement socket ioctl() calls to set addresses * Added listen() and accept() + * Added DM90x0 ethernet driver + * ARP timer is now built into the network layer diff --git a/Documentation/NuttX.html b/Documentation/NuttX.html index 3369857b360a8f71aa85bb02e9817b2abdde55d1..0e0535bb00ff766ec5b261150a5e801787d5093e 100644 --- a/Documentation/NuttX.html +++ b/Documentation/NuttX.html @@ -646,6 +646,8 @@ Other memory: * Provide support for multiple network devices * Implement socket ioctl() calls to set addresses * Added listen() and accept() + * Added DM90x0 ethernet driver + * ARP timer is now built into the network layer </pre></ul> <table width ="100%"> diff --git a/arch/arm/src/common/up_initialize.c b/arch/arm/src/common/up_initialize.c index 9fad207e5920374ac65a06f7d0d0f525a7b168fa..b9622d0d0e9533c9dd8ea11a4d0cd043bcdee0b6 100644 --- a/arch/arm/src/common/up_initialize.c +++ b/arch/arm/src/common/up_initialize.c @@ -100,5 +100,9 @@ void up_initialize(void) /* Initialize the serial device driver */ up_serialinit(); + + /* Initialize the netwok */ + + up_netinitialize(); up_ledon(LED_IRQSENABLED); } diff --git a/arch/arm/src/common/up_internal.h b/arch/arm/src/common/up_internal.h index 268dc6f2d6c0eb25930175e662aeab0a1647809a..f75995b005d7a70eebae4f5e8e41bbf2511419e3 100644 --- a/arch/arm/src/common/up_internal.h +++ b/arch/arm/src/common/up_internal.h @@ -157,6 +157,13 @@ extern void up_ledoff(int led); # define up_ledoff(led) #endif +/* Defined in board/up_network.c */ + +#ifdef CONFIG_NET +extern up_netinitialize(void); +#else +# define up_netinitialize() +#endif #endif /* __ASSEMBLY__ */ #endif /* __UP_INTERNAL_H */ diff --git a/arch/sim/src/up_tapdev.c b/arch/sim/src/up_tapdev.c index 3626809e31079e856fbf6fe12412f1f7c97b447c..a649c2490b013a1fcc424518865532bc82366d24 100644 --- a/arch/sim/src/up_tapdev.c +++ b/arch/sim/src/up_tapdev.c @@ -266,7 +266,7 @@ void tapdev_init(void) /* Assign an IPv4 address to the tap device */ - snprintf(buf, sizeof(buf), "ifconfig tap0 inet %d.%d.%d.%d\n", + snprintf(buf, sizeof(buf), "/sbin/ifconfig tap0 inet %d.%d.%d.%d\n", UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3); system(buf); } diff --git a/arch/sim/src/up_uipdriver.c b/arch/sim/src/up_uipdriver.c index 6f465feca3c8ca12d970d5bb4bdb3a9a37d00b62..fbb8550de8dc4f1e241d5d043686a3d3ea5e9867 100644 --- a/arch/sim/src/up_uipdriver.c +++ b/arch/sim/src/up_uipdriver.c @@ -81,7 +81,6 @@ struct timer ****************************************************************************/ static struct timer g_periodic_timer; -static struct timer g_arp_timer; static struct uip_driver_s g_sim_dev; /**************************************************************************** @@ -216,14 +215,6 @@ void uipdriver_loop(void) } } #endif /* CONFIG_NET_UDP */ - - /* Call the ARP timer function every 10 seconds. */ - - if (timer_expired(&g_arp_timer)) - { - timer_reset(&g_arp_timer); - uip_arp_timer(); - } } sched_unlock(); } @@ -233,7 +224,6 @@ int uipdriver_init(void) /* Internal initalization */ timer_set(&g_periodic_timer, 500); - timer_set(&g_arp_timer, 10000 ); tapdev_init(); (void)tapdev_getmacaddr(g_sim_dev.d_mac.addr); diff --git a/configs/ntosd-dm320/include/board.h b/configs/ntosd-dm320/include/board.h index 742b0cdb3e67e057aac84a4bc1faabe958f1f095..646349075200e5db550c7cce1971a51f5af455aa 100644 --- a/configs/ntosd-dm320/include/board.h +++ b/configs/ntosd-dm320/include/board.h @@ -81,6 +81,7 @@ #define GIO_KEY_SCAN3 4 #define GIO_KEY_SCAN4 5 #define GIO_MS_DETECT 5 +#define GIO_DM9000A_INT 6 #define GIO_MMC_DETECT 8 #define GIO_CFC_DETECT 9 #define GIO_VIDEO_IN 10 diff --git a/configs/ntosd-dm320/src/Makefile b/configs/ntosd-dm320/src/Makefile index 158b7f4d4893a265f57fda0269b3b9a077187c74..862f23a667c94ba2692fab307e32d8604919d4ab 100644 --- a/configs/ntosd-dm320/src/Makefile +++ b/configs/ntosd-dm320/src/Makefile @@ -40,7 +40,7 @@ CFLAGS += -I$(TOPDIR)/sched ASRCS = AOBJS = $(ASRCS:.S=$(OBJEXT)) -CSRCS = up_leds.c +CSRCS = up_leds.c up_network.c COBJS = $(CSRCS:.c=$(OBJEXT)) SRCS = $(ASRCS) $(CSRCS) diff --git a/configs/ntosd-dm320/src/up_network.c b/configs/ntosd-dm320/src/up_network.c new file mode 100644 index 0000000000000000000000000000000000000000..5ba9fd3aad2957e2718e71f2e5c9875140934ad1 --- /dev/null +++ b/configs/ntosd-dm320/src/up_network.c @@ -0,0 +1,92 @@ +/**************************************************************************** + * board/up_network.c + * + * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name Gregory Nutt nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#if defined(CONFIG_NET) && defined(CONFIG_NET_DM90x0) + +#include <sys/types.h> +#include <arch/board.h> + +#include "up_internal.h" +#include "chip/dm320_gio.h" + +extern void dm9x_initialize(void); + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_netinitialize + ****************************************************************************/ + +void up_netinitialize(void) +{ + /* CS4 is used for DM9000A Ethernet. Interrupt is provided via GIO6 + * which must be configured to interrupt on the rising edge. Bus + * width is 16-bits. + */ + + /* It is assumed that bootloader has already configured CS4. Here, + * we will only make certain that the GIO is properly configured + */ + + GIO_INPUT(GIO_DM9000A_INT); + GIO_NONINVERTED(GIO_DM9000A_INT); + GIO_INTERRUPT(GIO_DM9000A_INT); + GIO_RISINGEDGE(GIO_DM9000A_INT); + + /* Then initialize the driver */ + + dm9x_initialize(); +} + +#endif /* CONFIG_NET && CONFIG_NET_DM90x0 */ diff --git a/drivers/Makefile b/drivers/Makefile index f992f583740b58802a8438da161bb221308b5fe1..0ebf08d5c68321b0048e4f8220772cf32e0fe5a7 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -37,10 +37,14 @@ MKDEP = $(TOPDIR)/tools/mkdeps.sh -ASRCS = +ifeq ($(CONFIG_NET),y) +include net/Make.defs +endif + +ASRCS = $(NET_ASRCS) AOBJS = $(ASRCS:.S=$(OBJEXT)) -CSRCS = dev_null.c serial.c +CSRCS = dev_null.c serial.c $(NET_CSRCS) COBJS = $(CSRCS:.c=$(OBJEXT)) SRCS = $(ASRCS) $(CSRCS) @@ -48,6 +52,8 @@ OBJS = $(AOBJS) $(COBJS) BIN = libdrivers$(LIBEXT) +VPATH = net + all: $(BIN) $(AOBJS): %$(OBJEXT): %.S @@ -63,7 +69,11 @@ $(BIN): $(OBJS) done ; ) .depend: Makefile $(SRCS) +ifeq ($(CONFIG_NET),y) + $(MKDEP) --dep-path . --dep-path net $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep +else $(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep +endif touch $@ depend: .depend diff --git a/include/net/uip/uip-arch.h b/include/net/uip/uip-arch.h index 42e01cbcd4e5f8583efa5d52f334ae5f90039a2a..2c6720ab431109cc9a8c324f4b35dea77ddfbf99 100644 --- a/include/net/uip/uip-arch.h +++ b/include/net/uip/uip-arch.h @@ -168,6 +168,15 @@ struct uip_driver_s */ uint16 d_sndlen; + + /* Driver callbacks */ + + int (*ifup)(struct uip_driver_s *dev); + int (*ifdown)(struct uip_driver_s *dev); + + /* Drivers may attached device-specific, private information */ + + void *d_private; }; /**************************************************************************** diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 2da8e723ec1d5e1c1f1aed94a9158a1fc1612475..db17b30de36b294a1e0433d63b27341e3fbf93b7 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1,4 +1,4 @@ -/************************************************************ +/**************************************************************************** * arch.h * * Copyright (C) 2007 Gregory Nutt. All rights reserved. @@ -31,37 +31,37 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ #ifndef __ARCH_H #define __ARCH_H -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include <nuttx/config.h> #include <sys/types.h> #include <sched.h> #include <arch/arch.h> -/************************************************************ +/**************************************************************************** * Definitions - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Public Types - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Public Variables - ************************************************************/ + ****************************************************************************/ typedef void (*sig_deliver_t)(_TCB *tcb); -/************************************************************ +/**************************************************************************** * Public Function Prototypes - ************************************************************/ + ****************************************************************************/ #ifdef __cplusplus #define EXTERN extern "C" @@ -70,12 +70,12 @@ extern "C" { #define EXTERN extern #endif -/************************************************************ +/**************************************************************************** * These are standard interfaces that must be exported to the * scheduler from architecture-specific code. - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Name: up_initialize * * Description: @@ -93,11 +93,11 @@ extern "C" { * libraries have been initialized. OS services and driver * services are available. * - ************************************************************/ + ****************************************************************************/ EXTERN void up_initialize(void); -/************************************************************ +/**************************************************************************** * Name: up_idle * * Description: @@ -109,11 +109,11 @@ EXTERN void up_initialize(void); * Processing in this state may be processor-specific. e.g., * this is where power management operations might be performed. * - ************************************************************/ + ****************************************************************************/ EXTERN void up_idle(void); -/************************************************************ +/**************************************************************************** * Name: up_initial_state * * Description: @@ -125,11 +125,11 @@ EXTERN void up_idle(void); * and/or stack so that execution will begin at tcb->start * on the next context switch. * - ************************************************************/ + ****************************************************************************/ EXTERN void up_initial_state(FAR _TCB *tcb); -/************************************************************ +/**************************************************************************** * Name: up_create_stack * * Description: @@ -149,13 +149,13 @@ EXTERN void up_initial_state(FAR _TCB *tcb); * stack_size: The requested stack size. At least this much * must be allocated. * - ************************************************************/ + ****************************************************************************/ #ifndef CONFIG_CUSTOM_STACK EXTERN STATUS up_create_stack(FAR _TCB *tcb, size_t stack_size); #endif -/************************************************************ +/**************************************************************************** * Name: up_use_stack * * Description: @@ -174,26 +174,26 @@ EXTERN STATUS up_create_stack(FAR _TCB *tcb, size_t stack_size); * tcb: The TCB of new task * stack_size: The allocated stack size. * - ************************************************************/ + ****************************************************************************/ #ifndef CONFIG_CUSTOM_STACK EXTERN STATUS up_use_stack(FAR _TCB *tcb, FAR void *stack, size_t stack_size); #endif -/************************************************************ +/**************************************************************************** * Name: up_release_stack * * Description: * A task has been stopped. Free all stack * related resources retained int the defunct TCB. * - ************************************************************/ + ****************************************************************************/ #ifndef CONFIG_CUSTOM_STACK EXTERN void up_release_stack(FAR _TCB *dtcb); #endif -/************************************************************ +/**************************************************************************** * Name: up_unblock_task * * Description: @@ -211,11 +211,11 @@ EXTERN void up_release_stack(FAR _TCB *dtcb); * the ready-to-run list and, if it is the highest priority * ready to run taks, executed. * - ************************************************************/ + ****************************************************************************/ EXTERN void up_unblock_task(FAR _TCB *tcb); -/************************************************************ +/**************************************************************************** * Name: up_block_task * * Description: @@ -237,11 +237,11 @@ EXTERN void up_unblock_task(FAR _TCB *tcb); * task_state: Specifies which waiting task list should be * hold the blocked task TCB. * - ************************************************************/ + ****************************************************************************/ EXTERN void up_block_task(FAR _TCB *tcb, tstate_t task_state); -/************************************************************ +/**************************************************************************** * Name: up_release_pending * * Description: @@ -256,11 +256,11 @@ EXTERN void up_block_task(FAR _TCB *tcb, tstate_t task_state); * logic when pre-emptioni is re-enabled. Interrupts will * always be disabled when this function is called. * - ************************************************************/ + ****************************************************************************/ EXTERN void up_release_pending(void); -/************************************************************ +/**************************************************************************** * Name: up_reprioritize_rtr * * Description: @@ -282,11 +282,11 @@ EXTERN void up_release_pending(void); * tcb: The TCB of the task that has been reprioritized * priority: The new task priority * - ************************************************************/ + ****************************************************************************/ EXTERN void up_reprioritize_rtr(FAR _TCB *tcb, ubyte priority); -/************************************************************ +/**************************************************************************** * Name: _exit * * Description: @@ -298,20 +298,20 @@ EXTERN void up_reprioritize_rtr(FAR _TCB *tcb, ubyte priority); * implementation of this function should diable interrupts * before performing scheduling operations. * - ************************************************************/ + ****************************************************************************/ /* Prototype is in unistd.h */ -/************************************************************ +/**************************************************************************** * Name: up_assert and up_assert_code * * Description: * Assertions may be handled in an architecture-specific * way. * - ************************************************************/ + ****************************************************************************/ /* Prototype is in assert.h */ -/************************************************************ +/**************************************************************************** * Name: up_schedule_sigaction * * Description: @@ -342,13 +342,13 @@ EXTERN void up_reprioritize_rtr(FAR _TCB *tcb, ubyte priority); * currently executing task -- just call the signal * handler now. * - ************************************************************/ + ****************************************************************************/ #ifndef CONFIG_DISABLE_SIGNALS EXTERN void up_schedule_sigaction(FAR _TCB *tcb, sig_deliver_t sigdeliver); #endif -/************************************************************ +/**************************************************************************** * Name: up_allocate_heap * * Description: @@ -357,59 +357,59 @@ EXTERN void up_schedule_sigaction(FAR _TCB *tcb, sig_deliver_t sigdeliver); * are not defined, then this function will be called to * dynamically set aside the heap region. * - ************************************************************/ + ****************************************************************************/ #ifndef CONFIG_HEAP_BASE EXTERN void up_allocate_heap(FAR void **heap_start, size_t *heap_size); #endif -/************************************************************ +/**************************************************************************** * Name: up_interrupt_context * * Description: * Return TRUE is we are currently executing in * the interrupt handler context. * - ************************************************************/ + ****************************************************************************/ EXTERN boolean up_interrupt_context(void); -/************************************************************ +/**************************************************************************** * Name: up_disable_irq * * Description: * Disable the IRQ specified by 'irq' * - ************************************************************/ + ****************************************************************************/ EXTERN void up_disable_irq(int irq); -/************************************************************ +/**************************************************************************** * Name: up_enable_irq * * Description: * Enable the IRQ specified by 'irq' * - ************************************************************/ + ****************************************************************************/ EXTERN void up_enable_irq(int irq); -/************************************************************ +/**************************************************************************** * Name: up_disable_irq * * Description: * Disable the IRQ specified by 'irq' * - ************************************************************/ + ****************************************************************************/ EXTERN void up_disable_irq(int irq); -/************************************************************ +/**************************************************************************** * These are standard interfaces that are exported by the OS * for use by the architecture specific logic - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Name: sched_process_timer * * Description: @@ -419,34 +419,46 @@ EXTERN void up_disable_irq(int irq); * function periodically -- the calling interval must be * MSEC_PER_TICK. * - ************************************************************/ + ****************************************************************************/ EXTERN void sched_process_timer(void); -/************************************************************ +/**************************************************************************** * Name: irq_dispatch * * Description: * This function must be called from the achitecture- - * specific logic in order to dispaly an interrupt to + * specific logic in order to dispatch an interrupt to * the appropriate, registered handling logic. * - ***********************************************************/ + ***************************************************************************/ EXTERN void irq_dispatch(int irq, FAR void *context); -/************************************************************ +/**************************************************************************** + * Name: up_mdelay and up_udelay + * + * Description: + * Some device drivers may require that the plaform-specific logic + * provide these timing loops for short delays. + * + ***************************************************************************/ + +EXTERN void up_mdelay(unsigned int milliseconds); +EXTERN void up_udelay(unsigned int microseconds); + +/**************************************************************************** * Debug interfaces exported by the architecture-specific * logic - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Name: up_putc * * Description: * Output one character on the console * - ************************************************************/ + ****************************************************************************/ # ifdef CONFIG_ARCH_LOWPUTC EXTERN int up_putc(int ch); diff --git a/net/Makefile b/net/Makefile index fa0175409f0ab354ede4c3534522102c2ddd3a68..cf6f35081bae321bbfe9a053659804572305d073 100644 --- a/net/Makefile +++ b/net/Makefile @@ -46,7 +46,7 @@ SOCK_CSRCS = socket.c bind.c connect.c listen.c accept.c send.c sendto.c \ ifeq ($(CONFIG_NET_SOCKOPTS),y) SOCK_CSRCS += setsockopt.c getsockopt.c ifneq ($(CONFIG_DISABLE_CLOCK),y) -SOCK_CSRCS += net-timeo.c net-dsec2timeval.c net-timeval2dsec.c +SOCK_CSRCS += net-timeo.c net-dsec2timeval.c net-timeval2dsec.c net-arptimer.c endif endif diff --git a/net/connect.c b/net/connect.c index 35c3b9e0dde6e71270db3a25ce3f5ce3aba65e9c..c520aaac8798ee8b960cde967181fa1dbea8368e 100644 --- a/net/connect.c +++ b/net/connect.c @@ -355,7 +355,6 @@ static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in /**************************************************************************** * Public Functions ****************************************************************************/ - /**************************************************************************** * Function: connect * diff --git a/net/net-arptimer.c b/net/net-arptimer.c new file mode 100644 index 0000000000000000000000000000000000000000..69d8aebb09db56e1ae1931236cc8c3895ee4050c --- /dev/null +++ b/net/net-arptimer.c @@ -0,0 +1,130 @@ +/**************************************************************************** + * net/net-arptimer.c + * + * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#ifdef CONFIG_NET + +#include <time.h> +#include <wdog.h> + +#include <net/uip/uip-arp.h> + +#include "net-internal.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/* ARP timer interval = 10 seconds. CLK_TCK is the number of clock ticks + * per second + */ + +#define ARPTIMER_WDINTERVAL (10*CLK_TCK) + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static WDOG_ID g_arptimer; /* ARP timer */ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: arptimer_poll + * + * Description: + * Periodic timer handler. Called from the timer interrupt handler. + * + * Parameters: + * argc - The number of available arguments + * arg - The first argument + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static void arptimer_poll(int argc, uint32 arg, ...) +{ + dbg("ARP timer expiration\n"); + + /* Call the ARP timer function every 10 seconds. */ + + uip_arp_timer(); + + /* Setup the watchdog timer again */ + + (void)wd_start(g_arptimer, ARPTIMER_WDINTERVAL, arptimer_poll, 0); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: arptimer_init + * + * Description: + * Initialized the 10 second timer that is need by uIP to age ARP + * associations + * + * Parameters: + * None + * + * Returned Value: + * None + * + * Assumptions: + * Called once at system initialization time + * + ****************************************************************************/ + +void arptimer_init(void) +{ + /* Create and start the ARP timer */ + + g_arptimer = wd_create(); + (void)wd_start(g_arptimer, ARPTIMER_WDINTERVAL, arptimer_poll, 0); +} + +#endif /* CONFIG_NET */ diff --git a/net/net-internal.h b/net/net-internal.h index af587d970b0a35494c22629c846a589d490f2862..2354e54c1198bdbe2a9273d1187d3cdbc50cf4f1 100644 --- a/net/net-internal.h +++ b/net/net-internal.h @@ -176,6 +176,10 @@ EXTERN FAR struct uip_driver_s *netdev_find(const char *ifname); EXTERN int netdev_count(void); #endif +/* net-arptimer.c ************************************************************/ + +EXTERN void arptimer_init(void); + #undef EXTERN #if defined(__cplusplus) } diff --git a/net/net-sockets.c b/net/net-sockets.c index 71641a8fa48172f46525d49618a3ca0c77d33e5b..34a20a05aae4ae48b6faa0fb98fb9f471c338474 100644 --- a/net/net-sockets.c +++ b/net/net-sockets.c @@ -107,6 +107,10 @@ void net_initialize(void) #if CONFIG_NSOCKET_DESCRIPTORS > 0 sem_init(&g_netdev_sem, 0, 1); #endif + + /* Initialize the periodic ARP timer */ + + arptimer_init(); } #if CONFIG_NSOCKET_DESCRIPTORS > 0 diff --git a/net/netdev-ioctl.c b/net/netdev-ioctl.c index 1abc841056c11fe9dd8e661fa2aea41d38630949..5c7b767fdf442bdd6d31488a369a70486b0a37e2 100644 --- a/net/netdev-ioctl.c +++ b/net/netdev-ioctl.c @@ -67,14 +67,14 @@ ****************************************************************************/ /**************************************************************************** - * Name: _get_ipaddr / _set_ipaddr + * Name: ioctl_getipaddr / ioctl_setipaddr * * Description: * Copy IP addresses into and out of device structure * ****************************************************************************/ -static void _get_ipaddr(struct sockaddr *outaddr, uip_ipaddr_t *inaddr) +static void ioctl_getipaddr(struct sockaddr *outaddr, uip_ipaddr_t *inaddr) { #ifdef CONFIG_NET_IPv6 #error " big enough for IPv6 address" @@ -90,7 +90,7 @@ static void _get_ipaddr(struct sockaddr *outaddr, uip_ipaddr_t *inaddr) #endif } -static void _set_ipaddr(uip_ipaddr_t *outaddr, struct sockaddr *inaddr) +static void ioctl_setipaddr(uip_ipaddr_t *outaddr, struct sockaddr *inaddr) { #ifdef CONFIG_NET_IPv6 struct sockaddr_in6 *src = (struct sockaddr_in6 *)inaddr; @@ -101,6 +101,22 @@ static void _set_ipaddr(uip_ipaddr_t *outaddr, struct sockaddr *inaddr) #endif } +static void ioctl_ifup(FAR struct uip_driver_s *dev) +{ + if (dev->ifup) + { + dev->ifup(dev); + } +} + +static void ioctl_ifdown(FAR struct uip_driver_s *dev) +{ + if (dev->ifdown) + { + dev->ifdown(dev); + } +} + /**************************************************************************** * Global Functions ****************************************************************************/ @@ -170,27 +186,29 @@ int netdev_ioctl(int sockfd, int cmd, struct ifreq *req) switch (cmd) { case SIOCGIFADDR: /* Get IP address */ - _get_ipaddr(&req->ifr_addr, &dev->d_ipaddr); + ioctl_getipaddr(&req->ifr_addr, &dev->d_ipaddr); break; case SIOCSIFADDR: /* Set IP address */ - _set_ipaddr(&dev->d_ipaddr, &req->ifr_addr); + ioctl_ifdown(dev); + ioctl_setipaddr(&dev->d_ipaddr, &req->ifr_addr); + ioctl_ifup(dev); break; case SIOCGIFDSTADDR: /* Get P-to-P address */ - _get_ipaddr(&req->ifr_dstaddr, &dev->d_draddr); + ioctl_getipaddr(&req->ifr_dstaddr, &dev->d_draddr); break; case SIOCSIFDSTADDR: /* Set P-to-P address */ - _set_ipaddr(&dev->d_draddr, &req->ifr_dstaddr); + ioctl_setipaddr(&dev->d_draddr, &req->ifr_dstaddr); break; case SIOCGIFNETMASK: /* Get network mask */ - _get_ipaddr(&req->ifr_addr, &dev->d_netmask); + ioctl_getipaddr(&req->ifr_addr, &dev->d_netmask); break; case SIOCSIFNETMASK: /* Set network mask */ - _set_ipaddr(&dev->d_netmask, &req->ifr_addr); + ioctl_setipaddr(&dev->d_netmask, &req->ifr_addr); break; case SIOCGIFMTU: /* Get MTU size */ diff --git a/netutils/Makefile b/netutils/Makefile index 3232dd5f2f473c240c171ce0adb8013360712aec..a975296f9df31b6f987998d54066d761ad35ecbe 100644 --- a/netutils/Makefile +++ b/netutils/Makefile @@ -105,6 +105,6 @@ clean: distclean: clean @rm -f Make.dep .depend @rm -f $(STRNG_CSRCS) $(STRNG_ASRCS) - @rm -f Make.str netutil-strings.h makestrings$(EXEEXT) + @rm -f rm .strings make.str netutil-strings.h makestrings$(EXEEXT) -include Make.dep