diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2011-03-03 14:38:54 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2011-03-03 14:38:54 +0000 |
commit | a8da4176aaf75a753f61b68f1f03ea33b9960af9 (patch) | |
tree | e2224d702b736215ef6765f1b434a36e38c7709a /misc | |
parent | 2010-12-17 Joel Sherrill <joel.sherrill@oarcorp.com> (diff) | |
download | rtems-examples-a8da4176aaf75a753f61b68f1f03ea33b9960af9.tar.bz2 |
2011-03-03 Joel Sherrill <joel.sherrill@oarcorp.com>
PR 1749/bsps
* Makefile: Add new test program for wrapping clock tick.
* nanosecond_tick_wrap/.cvsignore, nanosecond_tick_wrap/Makefile,
nanosecond_tick_wrap/README, nanosecond_tick_wrap/init.c: New files.
Diffstat (limited to 'misc')
-rw-r--r-- | misc/ChangeLog | 7 | ||||
-rw-r--r-- | misc/Makefile | 2 | ||||
-rw-r--r-- | misc/nanosecond_tick_wrap/.cvsignore | 1 | ||||
-rw-r--r-- | misc/nanosecond_tick_wrap/Makefile | 27 | ||||
-rw-r--r-- | misc/nanosecond_tick_wrap/README | 32 | ||||
-rw-r--r-- | misc/nanosecond_tick_wrap/init.c | 73 |
6 files changed, 141 insertions, 1 deletions
diff --git a/misc/ChangeLog b/misc/ChangeLog index 6a69f09..dae7338 100644 --- a/misc/ChangeLog +++ b/misc/ChangeLog @@ -1,3 +1,10 @@ +2011-03-03 Joel Sherrill <joel.sherrill@oarcorp.com> + + PR 1749/bsps + * Makefile: Add new test program for wrapping clock tick. + * nanosecond_tick_wrap/.cvsignore, nanosecond_tick_wrap/Makefile, + nanosecond_tick_wrap/README, nanosecond_tick_wrap/init.c: New files. + 2010-05-05 Joel Sherrill <joel.sherrill@oarcorp.com> * qemu_vfat/Makefile, qemu_vfat/README, qemu_vfat/init.c: Now includes diff --git a/misc/Makefile b/misc/Makefile index cbb25ea..d89656b 100644 --- a/misc/Makefile +++ b/misc/Makefile @@ -6,7 +6,7 @@ include $(RTEMS_MAKEFILE_PATH)/Makefile.inc include $(RTEMS_CUSTOM) include $(RTEMS_ROOT)/make/directory.cfg -SUBDIRS=minimum bspcmdline extract_example +SUBDIRS=minimum bspcmdline extract_example nanosecond_tick_wrap # If the POSIX API isn't enabled, we can't build these ifeq ($(RTEMS_HAS_POSIX_API),yes) diff --git a/misc/nanosecond_tick_wrap/.cvsignore b/misc/nanosecond_tick_wrap/.cvsignore new file mode 100644 index 0000000..fecf58a --- /dev/null +++ b/misc/nanosecond_tick_wrap/.cvsignore @@ -0,0 +1 @@ +o-optimize diff --git a/misc/nanosecond_tick_wrap/Makefile b/misc/nanosecond_tick_wrap/Makefile new file mode 100644 index 0000000..40b3244 --- /dev/null +++ b/misc/nanosecond_tick_wrap/Makefile @@ -0,0 +1,27 @@ +# +# $Id$ +# + +# +# RTEMS_MAKEFILE_PATH is typically set in an environment variable +# + +PGM=${ARCH}/nanoseconds_tick_wrap.exe + +# optional managers required +MANAGERS=all + +# C source names +CSRCS = init.c +COBJS = $(CSRCS:%.c=${ARCH}/%.o) + +include $(RTEMS_MAKEFILE_PATH)/Makefile.inc +include $(RTEMS_CUSTOM) +include $(PROJECT_ROOT)/make/leaf.cfg + +OBJS= $(COBJS) $(CXXOBJS) $(ASOBJS) + +all: ${ARCH} $(PGM) + +$(PGM): $(OBJS) + $(make-exe) diff --git a/misc/nanosecond_tick_wrap/README b/misc/nanosecond_tick_wrap/README new file mode 100644 index 0000000..390d507 --- /dev/null +++ b/misc/nanosecond_tick_wrap/README @@ -0,0 +1,32 @@ +# +# $Id$ +# + +PR 1748 [1] points out a general problem that many BSPs could have in their +nanoseconds since last tick handler. This problem occurs when: + ++ We are in the middle of getting TOD or Update AND ++ Clock tick counter goes to 0 + +Then the nanoseconds since last tick handler needs to account for either +a clock interrupt pending (if the counter resets) or the counter wrapping +below 0. The following illustrates the interrupt pending method: + +iuint32_t bsp_clock_nanoseconds_since_last_tick(void) +{ + uint32_t clicks; + uint32_t usecs; + + clicks = HARDWARE_COUNTER; + + usecs = TO_USECS(clicks); + if ( Is_interrupt_pending( CLOCK_VECTOR ) ) + usecs += rtems_configuration_get_microseconds_per_tick(); + return usecs * 1000; +} + + +References +========== + +[1] https://www.rtems.org/bugzilla/show_bug.cgi?id=1748 diff --git a/misc/nanosecond_tick_wrap/init.c b/misc/nanosecond_tick_wrap/init.c new file mode 100644 index 0000000..1740df2 --- /dev/null +++ b/misc/nanosecond_tick_wrap/init.c @@ -0,0 +1,73 @@ +/* + * COPYRIGHT (c) 1989-2011. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +/* Based upon code in PR1748 */ + +#include <stdio.h> +#include <stdlib.h> + +#include <bsp.h> + +#define LOOPS 1000 +uint32_t uptime_usec[LOOPS]; +struct timespec uptime[LOOPS]; + +rtems_task Init( + rtems_task_argument argument +) +{ + int i; + uint32_t t0=0; + + puts( "\n\n*** Nanosecond Clock Tick Wrap Test ***" ); + for ( i=0; i<LOOPS; i++ ) { + + rtems_clock_get_uptime( &uptime[i] ); + uptime_usec[i] = ((uint32_t)uptime[i].tv_sec * 1000000) + + ((uint32_t)uptime[i].tv_nsec / 1000); + } + + for ( i=0; i<LOOPS; i++ ) { + unsigned t1, usec, msec, sec; + + t1 = uptime_usec[i]; + usec = t1 % 1000; + msec = (t1 / 1000) % 1000; + sec = t1 / 1000000; + + printf( + "TEST:rtems=%u.%09u t=%u.%03u.%03u dt=%u\n", + uptime[i].tv_sec, uptime[i].tv_nsec, sec, msec, usec, (t1-t0) + ); + t0 = t1; + } + + puts( "*** END OF Nanosecond Clock Tick Wrap Test ***" ); + exit(0); +} + +/**************** START OF CONFIGURATION INFORMATION ****************/ + +#define CONFIGURE_INIT + +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER + +#define CONFIGURE_MAXIMUM_TASKS 1 +#define CONFIGURE_MICROSECONDS_PER_TICK \ + (RTEMS_MILLISECONDS_TO_MICROSECONDS(1) / 2) + +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE + +#include <rtems/confdefs.h> + +/**************** END OF CONFIGURATION INFORMATION ****************/ + |