diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-11-06 19:58:14 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-11-06 19:58:14 +0000 |
commit | 7a21220ebd5cef442fb059c90e18ff90232d8dc9 (patch) | |
tree | 38277e8efa923112be23e9a0554313c0927f02e2 /nuttx/arch/arm/src/common/up_udelay.c | |
parent | 4fc87116d818f5285403dbb37d2aa60d33e4203a (diff) | |
download | px4-nuttx-7a21220ebd5cef442fb059c90e18ff90232d8dc9.tar.gz px4-nuttx-7a21220ebd5cef442fb059c90e18ff90232d8dc9.tar.bz2 px4-nuttx-7a21220ebd5cef442fb059c90e18ff90232d8dc9.zip |
Verified basic client-side network functionalitynuttx-3.0
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@373 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/arch/arm/src/common/up_udelay.c')
-rw-r--r-- | nuttx/arch/arm/src/common/up_udelay.c | 52 |
1 files changed, 24 insertions, 28 deletions
diff --git a/nuttx/arch/arm/src/common/up_udelay.c b/nuttx/arch/arm/src/common/up_udelay.c index f7d10e459..40ec3ba75 100644 --- a/nuttx/arch/arm/src/common/up_udelay.c +++ b/nuttx/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 */ + while (microseconds > 10) + { + for (i = 0; i < CONFIG_BOARD_LOOPSPER10USEC; i++) + { + } + microseconds -= 10; + } - loops = (CONFIG_BOARD_LOOPSPERMSEC * microseconds + 500) / 1000; - for (j = 0; j < loops; j++) + while (microseconds > 0) { + for (i = 0; i < CONFIG_BOARD_LOOPSPERUSEC; i++) + { + } + microseconds--; } } |