From ddf21aceb7beda5df26a0ee747ee36237d33d55c Mon Sep 17 00:00:00 2001 From: patacongo Date: Tue, 6 Nov 2007 19:58:14 +0000 Subject: [PATCH] Verified basic client-side network functionality git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@373 42af7a65-404d-4744-a932-0658087f49c3 --- arch/arm/src/common/up_udelay.c | 54 +++++++++++++++------------------ arch/sim/src/up_uipdriver.c | 2 +- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/arch/arm/src/common/up_udelay.c b/arch/arm/src/common/up_udelay.c index f7d10e4590f..40ec3ba75dc 100644 --- a/arch/arm/src/common/up_udelay.c +++ b/arch/arm/src/common/up_udelay.c @@ -44,8 +44,9 @@ * Definitions ****************************************************************************/ -#define CONFIG_BOARD_LOOPSPERUSEC ((CONFIG_BOARD_LOOPSPERMSEC+500)/1000) -#define CONFIG_BOARD_LOOPSPER10USEC ((CONFIG_BOARD_LOOPSPERMSEC+50)/100) +#define CONFIG_BOARD_LOOPSPER100USEC ((CONFIG_BOARD_LOOPSPERMSEC+5)/10) +#define CONFIG_BOARD_LOOPSPER10USEC ((CONFIG_BOARD_LOOPSPERMSEC+50)/100) +#define CONFIG_BOARD_LOOPSPERUSEC ((CONFIG_BOARD_LOOPSPERMSEC+500)/1000) /**************************************************************************** * Private Types @@ -85,48 +86,43 @@ void up_udelay(unsigned int microseconds) { - volatile int i; - volatile int j; - register uint32 loops; + volatile int i; - /* The value of microseconds should be less than 1000. If not, then we - * will perform millescond delays until it is. + /* We'll do this a little at a time because we expect that the + * CONFIG_BOARD_LOOPSPERUSEC is very inaccurate during to truncation in + * the divisions of its calculation. We'll use the largest values that + * we can in order to prevent significant error buildup in the loops. */ while (microseconds > 1000) { - for (j = 0; j < CONFIG_BOARD_LOOPSPERMSEC; j++) + for (i = 0; i < CONFIG_BOARD_LOOPSPERMSEC; i++) { } microseconds -= 1000; } - /* The numerator of the 'loops' below will overflow if CONFIG_BOARD_LOOPSPERMSEC - * is larger than (4*1024*1024*1024 - 500)/999 = 4,299,266.06 - */ - -#if CONFIG_BOARD_LOOPSPERMSEC >= 4299266 - while (microseconds > 500) + while (microseconds > 100) { - for (j = 0; j < ((CONFIG_BOARD_LOOPSPERMSEC+1)/2); j++) + for (i = 0; i < CONFIG_BOARD_LOOPSPER100USEC; i++) { } - microseconds -= 500; + microseconds -= 100; } -#endif - /* The overflow could still occur if CONFIG_BOARD_LOOPSPERMSEC is larger than - * (4*1024*1024*1024 - 500)/499 = 8,607,147.89 - */ - -#if CONFIG_BOARD_LOOPSPERMSEC >= 8607147 -# warning "Overflow in loops calculation is possible" -#endif - - /* Caculate the number of loops need to produce the required usec delay */ - - loops = (CONFIG_BOARD_LOOPSPERMSEC * microseconds + 500) / 1000; - for (j = 0; j < loops; j++) + while (microseconds > 10) { + for (i = 0; i < CONFIG_BOARD_LOOPSPER10USEC; i++) + { + } + microseconds -= 10; + } + + while (microseconds > 0) + { + for (i = 0; i < CONFIG_BOARD_LOOPSPERUSEC; i++) + { + } + microseconds--; } } diff --git a/arch/sim/src/up_uipdriver.c b/arch/sim/src/up_uipdriver.c index 3bd08c0b518..82e740bc03d 100644 --- a/arch/sim/src/up_uipdriver.c +++ b/arch/sim/src/up_uipdriver.c @@ -201,7 +201,7 @@ void uipdriver_loop(void) else if (timer_expired(&g_periodic_timer)) { timer_reset(&g_periodic_timer); - uip_poll(&g_sim_dev, sim_uiptxpoll, UIP_TIMER); + uip_poll(&g_sim_dev, sim_uiptxpoll, UIP_DRV_TIMER); } sched_unlock(); }