[PATCH] score: Add CPU counter support
Sebastian Huber
sebastian.huber at embedded-brains.de
Tue Feb 11 16:41:56 UTC 2014
Add a CPU counter interface to allow access to a free-running counter.
It is useful to measure short time intervals. This can be used for
example to enable profiling of critical low-level functions.
Add two busy wait functions rtems_delay_cpu_counter_ticks() and
rtems_delay_nanoseconds() implemented via the CPU counter.
---
c/src/lib/libbsp/arm/csb336/Makefile.am | 2 +
c/src/lib/libbsp/arm/csb337/Makefile.am | 2 +
c/src/lib/libbsp/arm/edb7312/Makefile.am | 2 +
c/src/lib/libbsp/arm/gba/Makefile.am | 2 +
c/src/lib/libbsp/arm/gdbarmsim/Makefile.am | 2 +
c/src/lib/libbsp/arm/gp32/Makefile.am | 2 +
c/src/lib/libbsp/arm/gumstix/Makefile.am | 2 +
c/src/lib/libbsp/arm/lm3s69xx/Makefile.am | 2 +
c/src/lib/libbsp/arm/lpc24xx/Makefile.am | 1 +
c/src/lib/libbsp/arm/lpc24xx/misc/system-clocks.c | 11 ++-
c/src/lib/libbsp/arm/lpc32xx/Makefile.am | 1 +
c/src/lib/libbsp/arm/lpc32xx/startup/bspstart.c | 13 ++-
c/src/lib/libbsp/arm/nds/Makefile.am | 2 +
c/src/lib/libbsp/arm/raspberrypi/Makefile.am | 2 +
c/src/lib/libbsp/arm/realview-pbx-a9/Makefile.am | 1 +
c/src/lib/libbsp/arm/rtl22xx/Makefile.am | 2 +
.../libbsp/arm/shared/arm-a9mpcore-clock-config.c | 11 ++
c/src/lib/libbsp/arm/smdk2410/Makefile.am | 2 +
c/src/lib/libbsp/arm/stm32f4/Makefile.am | 2 +
c/src/lib/libbsp/arm/xilinx-zynq/Makefile.am | 1 +
.../lib/libbsp/powerpc/beatnik/startup/bspstart.c | 4 +
c/src/lib/libbsp/powerpc/ep1a/startup/bspstart.c | 4 +
.../lib/libbsp/powerpc/gen5200/startup/bspstart.c | 2 +
.../lib/libbsp/powerpc/gen83xx/startup/bspstart.c | 3 +
.../libbsp/powerpc/haleakala/startup/bspstart.c | 3 +
c/src/lib/libbsp/powerpc/mbx8xx/startup/bspstart.c | 2 +
.../libbsp/powerpc/mpc55xxevb/startup/bspstart.c | 2 +
.../libbsp/powerpc/mpc8260ads/startup/bspstart.c | 2 +
.../lib/libbsp/powerpc/mvme3100/startup/bspstart.c | 4 +
.../lib/libbsp/powerpc/mvme5500/startup/bspstart.c | 4 +
c/src/lib/libbsp/powerpc/psim/startup/bspstart.c | 2 +
.../lib/libbsp/powerpc/qemuppc/startup/bspstart.c | 3 +
c/src/lib/libbsp/powerpc/qoriq/startup/bspstart.c | 2 +
.../libbsp/powerpc/score603e/startup/bspstart.c | 2 +
c/src/lib/libbsp/powerpc/shared/startup/bspstart.c | 4 +
c/src/lib/libbsp/powerpc/ss555/startup/bspstart.c | 2 +
.../lib/libbsp/powerpc/t32mppc/startup/bspstart.c | 3 +
c/src/lib/libbsp/powerpc/tqm8xx/startup/bspstart.c | 2 +
c/src/lib/libbsp/powerpc/virtex/startup/bspstart.c | 4 +
.../lib/libbsp/powerpc/virtex4/startup/bspstart.c | 2 +
.../lib/libbsp/powerpc/virtex5/startup/bspstart.c | 4 +
c/src/lib/libbsp/shared/cpucounterget.c | 27 ++++
c/src/lib/libbsp/shared/cpucountersubtract.c | 23 ++++
c/src/lib/libbsp/sparc/erc32/Makefile.am | 1 +
c/src/lib/libbsp/sparc/leon2/Makefile.am | 1 +
c/src/lib/libbsp/sparc/leon3/Makefile.am | 1 +
c/src/lib/libbsp/sparc/leon3/include/bsp.h | 4 +
c/src/lib/libbsp/sparc/leon3/include/leon.h | 2 +
c/src/lib/libbsp/sparc/leon3/startup/bspstart.c | 1 +
c/src/lib/libbsp/sparc/leon3/startup/cpucounter.c | 63 +++++++++
cpukit/sapi/Makefile.am | 4 +
cpukit/sapi/include/rtems/cpucounter.h | 140 ++++++++++++++++++++
cpukit/sapi/preinstall.am | 4 +
cpukit/sapi/src/cpucounterconverter.c | 39 ++++++
cpukit/sapi/src/delaycpu.c | 35 +++++
cpukit/sapi/src/delaynano.c | 26 ++++
cpukit/score/cpu/arm/rtems/score/cpu.h | 9 ++
cpukit/score/cpu/avr/Makefile.am | 1 +
cpukit/score/cpu/avr/rtems/score/cpu.h | 12 ++
cpukit/score/cpu/bfin/Makefile.am | 1 +
cpukit/score/cpu/bfin/rtems/score/cpu.h | 12 ++
cpukit/score/cpu/h8300/Makefile.am | 1 +
cpukit/score/cpu/h8300/rtems/score/cpu.h | 12 ++
cpukit/score/cpu/i386/Makefile.am | 1 +
cpukit/score/cpu/i386/rtems/score/cpu.h | 12 ++
cpukit/score/cpu/lm32/Makefile.am | 1 +
cpukit/score/cpu/lm32/rtems/score/cpu.h | 12 ++
cpukit/score/cpu/m32c/Makefile.am | 1 +
cpukit/score/cpu/m32c/rtems/score/cpu.h | 12 ++
cpukit/score/cpu/m32r/Makefile.am | 1 +
cpukit/score/cpu/m32r/rtems/score/cpu.h | 12 ++
cpukit/score/cpu/m68k/Makefile.am | 1 +
cpukit/score/cpu/m68k/rtems/score/cpu.h | 12 ++
cpukit/score/cpu/mips/Makefile.am | 1 +
cpukit/score/cpu/mips/rtems/score/cpu.h | 11 ++
cpukit/score/cpu/moxie/Makefile.am | 1 +
cpukit/score/cpu/moxie/rtems/score/cpu.h | 12 ++
cpukit/score/cpu/nios2/Makefile.am | 1 +
cpukit/score/cpu/nios2/rtems/score/cpu.h | 12 ++
cpukit/score/cpu/no_cpu/Makefile.am | 1 +
cpukit/score/cpu/no_cpu/cpucounterget.c | 27 ++++
cpukit/score/cpu/no_cpu/rtems/score/cpu.h | 31 +++++
cpukit/score/cpu/powerpc/rtems/score/cpu.h | 24 ++++
cpukit/score/cpu/sh/Makefile.am | 1 +
cpukit/score/cpu/sh/rtems/score/cpu.h | 12 ++
cpukit/score/cpu/sparc/rtems/score/cpu.h | 12 ++
cpukit/score/cpu/sparc64/Makefile.am | 1 +
cpukit/score/cpu/sparc64/rtems/score/cpu.h | 12 ++
cpukit/score/cpu/v850/Makefile.am | 1 +
cpukit/score/cpu/v850/rtems/score/cpu.h | 12 ++
doc/cpu_supplement/general.t | 19 +++
testsuites/sptests/Makefile.am | 1 +
testsuites/sptests/configure.ac | 1 +
testsuites/sptests/spcpucounter01/Makefile.am | 19 +++
testsuites/sptests/spcpucounter01/init.c | 112 ++++++++++++++++
.../sptests/spcpucounter01/spcpucounter01.doc | 16 +++
.../sptests/spcpucounter01/spcpucounter01.scn | 15 ++
97 files changed, 959 insertions(+), 5 deletions(-)
create mode 100644 c/src/lib/libbsp/shared/cpucounterget.c
create mode 100644 c/src/lib/libbsp/shared/cpucountersubtract.c
create mode 100644 c/src/lib/libbsp/sparc/leon3/startup/cpucounter.c
create mode 100644 cpukit/sapi/include/rtems/cpucounter.h
create mode 100644 cpukit/sapi/src/cpucounterconverter.c
create mode 100644 cpukit/sapi/src/delaycpu.c
create mode 100644 cpukit/sapi/src/delaynano.c
create mode 100644 cpukit/score/cpu/no_cpu/cpucounterget.c
create mode 100644 testsuites/sptests/spcpucounter01/Makefile.am
create mode 100644 testsuites/sptests/spcpucounter01/init.c
create mode 100644 testsuites/sptests/spcpucounter01/spcpucounter01.doc
create mode 100644 testsuites/sptests/spcpucounter01/spcpucounter01.scn
diff --git a/c/src/lib/libbsp/arm/csb336/Makefile.am b/c/src/lib/libbsp/arm/csb336/Makefile.am
index b21206b..f0bd7eb 100644
--- a/c/src/lib/libbsp/arm/csb336/Makefile.am
+++ b/c/src/lib/libbsp/arm/csb336/Makefile.am
@@ -33,6 +33,8 @@ libbsp_a_SOURCES += ../../shared/bsplibc.c ../../shared/bsppost.c \
../../shared/bsppredriverhook.c startup/bspstart.c ../../shared/bspclean.c \
../../shared/bspreset.c startup/memmap.c ../../shared/bootcard.c \
../../shared/sbrk.c ../../shared/gnatinstallhandler.c
+libbsp_a_SOURCES += ../../shared/cpucounterget.c
+libbsp_a_SOURCES += ../../shared/cpucountersubtract.c
# console
libbsp_a_SOURCES += console/uart.c
# abort
diff --git a/c/src/lib/libbsp/arm/csb337/Makefile.am b/c/src/lib/libbsp/arm/csb337/Makefile.am
index 5eafd49..da80ae0 100644
--- a/c/src/lib/libbsp/arm/csb337/Makefile.am
+++ b/c/src/lib/libbsp/arm/csb337/Makefile.am
@@ -56,6 +56,8 @@ libbsp_a_SOURCES = ../../shared/bsplibc.c ../../shared/bsppost.c \
../../shared/bspclean.c startup/bspreset.c \
startup/memmap.c ../../shared/bootcard.c ../../shared/sbrk.c \
../../shared/gnatinstallhandler.c
+libbsp_a_SOURCES += ../../shared/cpucounterget.c
+libbsp_a_SOURCES += ../../shared/cpucountersubtract.c
# console
libbsp_a_SOURCES += ../../shared/console.c console/uarts.c \
../../shared/console_select.c ../../shared/console_control.c \
diff --git a/c/src/lib/libbsp/arm/edb7312/Makefile.am b/c/src/lib/libbsp/arm/edb7312/Makefile.am
index 236a992..88e674c 100644
--- a/c/src/lib/libbsp/arm/edb7312/Makefile.am
+++ b/c/src/lib/libbsp/arm/edb7312/Makefile.am
@@ -35,6 +35,8 @@ libbsp_a_SOURCES += ../../shared/bsppost.c ../../shared/bsplibc.c \
../../shared/bsppredriverhook.c startup/bspstart.c \
../../shared/bspclean.c ../../shared/bootcard.c ../../shared/sbrk.c \
startup/bspreset.c ../../shared/gnatinstallhandler.c
+libbsp_a_SOURCES += ../../shared/cpucounterget.c
+libbsp_a_SOURCES += ../../shared/cpucountersubtract.c
# clock
libbsp_a_SOURCES += clock/clockdrv.c
diff --git a/c/src/lib/libbsp/arm/gba/Makefile.am b/c/src/lib/libbsp/arm/gba/Makefile.am
index 1b271bc..71e7a1e 100644
--- a/c/src/lib/libbsp/arm/gba/Makefile.am
+++ b/c/src/lib/libbsp/arm/gba/Makefile.am
@@ -38,6 +38,8 @@ libbsp_a_SOURCES += ../../shared/bsplibc.c ../../shared/bsppost.c \
startup/bspreset.c ../../shared/bootcard.c ../../shared/sbrk.c \
../../shared/gnatinstallhandler.c \
startup/bspstart.c
+libbsp_a_SOURCES += ../../shared/cpucounterget.c
+libbsp_a_SOURCES += ../../shared/cpucountersubtract.c
# clock
libbsp_a_SOURCES += clock/clockdrv.c
libbsp_a_SOURCES += ../../shared/clockdrv_shell.h
diff --git a/c/src/lib/libbsp/arm/gdbarmsim/Makefile.am b/c/src/lib/libbsp/arm/gdbarmsim/Makefile.am
index f03a257..8a7e4e7 100644
--- a/c/src/lib/libbsp/arm/gdbarmsim/Makefile.am
+++ b/c/src/lib/libbsp/arm/gdbarmsim/Makefile.am
@@ -33,6 +33,8 @@ libbsp_a_SOURCES += ../../shared/bsplibc.c ../../shared/bsppost.c \
../../shared/bsppredriverhook.c ../../shared/bspstart.c \
../../shared/bspclean.c startup/bspreset.c ../../shared/bootcard.c \
../../shared/sbrk.c ../../shared/gnatinstallhandler.c startup/syscalls.c
+libbsp_a_SOURCES += ../../shared/cpucounterget.c
+libbsp_a_SOURCES += ../../shared/cpucountersubtract.c
# console
libbsp_a_SOURCES += ../../shared/console-polled.c console/console-io.c
# clock
diff --git a/c/src/lib/libbsp/arm/gp32/Makefile.am b/c/src/lib/libbsp/arm/gp32/Makefile.am
index 92dfc72..db9c445 100644
--- a/c/src/lib/libbsp/arm/gp32/Makefile.am
+++ b/c/src/lib/libbsp/arm/gp32/Makefile.am
@@ -34,6 +34,8 @@ libbsp_a_SOURCES += ../../shared/bsplibc.c ../../shared/bsppost.c \
../../shared/bspclean.c startup/bspreset.c \
startup/memmap.c ../../shared/bootcard.c ../../shared/sbrk.c \
../../shared/gnatinstallhandler.c
+libbsp_a_SOURCES += ../../shared/cpucounterget.c
+libbsp_a_SOURCES += ../../shared/cpucountersubtract.c
# console
libbsp_a_SOURCES += console/uart.c ../../shared/console.c \
../../shared/console_select.c ../../shared/console_control.c \
diff --git a/c/src/lib/libbsp/arm/gumstix/Makefile.am b/c/src/lib/libbsp/arm/gumstix/Makefile.am
index 6372caf..6d408eb 100644
--- a/c/src/lib/libbsp/arm/gumstix/Makefile.am
+++ b/c/src/lib/libbsp/arm/gumstix/Makefile.am
@@ -33,6 +33,8 @@ libbsp_a_SOURCES += ../../shared/bsplibc.c ../../shared/bsppost.c \
../../shared/bootcard.c ../../shared/sbrk.c \
../../shared/gnatinstallhandler.c ../../shared/bsppretaskinghook.c \
../../shared/bspclean.c startup/bspstart.c startup/bspreset.c startup/memmap.c
+libbsp_a_SOURCES += ../../shared/cpucounterget.c
+libbsp_a_SOURCES += ../../shared/cpucountersubtract.c
#console
libbsp_a_SOURCES += console/uarts.c ../../shared/console.c \
diff --git a/c/src/lib/libbsp/arm/lm3s69xx/Makefile.am b/c/src/lib/libbsp/arm/lm3s69xx/Makefile.am
index 589112a..fc76999 100644
--- a/c/src/lib/libbsp/arm/lm3s69xx/Makefile.am
+++ b/c/src/lib/libbsp/arm/lm3s69xx/Makefile.am
@@ -68,6 +68,8 @@ libbsp_a_SOURCES += ../../shared/bsplibc.c
libbsp_a_SOURCES += ../../shared/bsppost.c
libbsp_a_SOURCES += ../../shared/bsppredriverhook.c
libbsp_a_SOURCES += ../../shared/bsppretaskinghook.c
+libbsp_a_SOURCES += ../../shared/cpucounterget.c
+libbsp_a_SOURCES += ../../shared/cpucountersubtract.c
libbsp_a_SOURCES += ../../shared/gnatinstallhandler.c
libbsp_a_SOURCES += ../../shared/sbrk.c
libbsp_a_SOURCES += ../../shared/src/stackalloc.c
diff --git a/c/src/lib/libbsp/arm/lpc24xx/Makefile.am b/c/src/lib/libbsp/arm/lpc24xx/Makefile.am
index 28ef708..134bdb8 100644
--- a/c/src/lib/libbsp/arm/lpc24xx/Makefile.am
+++ b/c/src/lib/libbsp/arm/lpc24xx/Makefile.am
@@ -101,6 +101,7 @@ libbsp_a_SOURCES += ../../shared/bootcard.c \
../../shared/sbrk.c \
../../shared/src/stackalloc.c \
../../shared/src/uart-output-char.c
+libbsp_a_SOURCES += ../../shared/cpucountersubtract.c
# Startup
libbsp_a_SOURCES += ../shared/startup/bsp-start-memcpy.S
diff --git a/c/src/lib/libbsp/arm/lpc24xx/misc/system-clocks.c b/c/src/lib/libbsp/arm/lpc24xx/misc/system-clocks.c
index fcd56ea..087da34 100644
--- a/c/src/lib/libbsp/arm/lpc24xx/misc/system-clocks.c
+++ b/c/src/lib/libbsp/arm/lpc24xx/misc/system-clocks.c
@@ -7,7 +7,7 @@
*/
/*
- * Copyright (c) 2008-2012 embedded brains GmbH. All rights reserved.
+ * Copyright (c) 2008-2014 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Obere Lagerstr. 30
@@ -20,6 +20,8 @@
* http://www.rtems.com/license/LICENSE.
*/
+#include <rtems/cpucounter.h>
+
#include <bsp.h>
#include <bsp/lpc24xx.h>
#include <bsp/system-clocks.h>
@@ -59,6 +61,13 @@ void lpc24xx_timer_initialize(void)
/* Start timer */
T1TCR = TCR_EN;
+
+ rtems_cpu_counter_initialize_converter(LPC24XX_PCLK);
+}
+
+CPU_counter _CPU_counter_Get(void)
+{
+ return lpc24xx_timer();
}
void lpc24xx_micro_seconds_delay(unsigned us)
diff --git a/c/src/lib/libbsp/arm/lpc32xx/Makefile.am b/c/src/lib/libbsp/arm/lpc32xx/Makefile.am
index 1489efc..e447257 100644
--- a/c/src/lib/libbsp/arm/lpc32xx/Makefile.am
+++ b/c/src/lib/libbsp/arm/lpc32xx/Makefile.am
@@ -88,6 +88,7 @@ libbsp_a_SOURCES += ../../shared/bsplibc.c
libbsp_a_SOURCES += ../../shared/bsppost.c
libbsp_a_SOURCES += ../../shared/bsppredriverhook.c
libbsp_a_SOURCES += ../../shared/bsppretaskinghook.c
+libbsp_a_SOURCES += ../../shared/cpucountersubtract.c
libbsp_a_SOURCES += ../../shared/gnatinstallhandler.c
libbsp_a_SOURCES += ../../shared/sbrk.c
libbsp_a_SOURCES += ../../shared/src/stackalloc.c
diff --git a/c/src/lib/libbsp/arm/lpc32xx/startup/bspstart.c b/c/src/lib/libbsp/arm/lpc32xx/startup/bspstart.c
index 2a8bcc7..45fe250 100644
--- a/c/src/lib/libbsp/arm/lpc32xx/startup/bspstart.c
+++ b/c/src/lib/libbsp/arm/lpc32xx/startup/bspstart.c
@@ -7,7 +7,7 @@
*/
/*
- * Copyright (c) 2009-2012 embedded brains GmbH. All rights reserved.
+ * Copyright (c) 2009-2014 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Obere Lagerstr. 30
@@ -20,14 +20,19 @@
* http://www.rtems.com/license/LICENSE.
*/
+#include <rtems/cpucounter.h>
+
#include <bsp.h>
#include <bsp/bootcard.h>
#include <bsp/irq-generic.h>
-#include <bsp/irq.h>
-#include <bsp/linker-symbols.h>
-#include <bsp/lpc32xx.h>
+
+CPU_counter _CPU_counter_Get(void)
+{
+ return lpc32xx_timer();
+}
void bsp_start(void)
{
+ rtems_cpu_counter_initialize_converter(LPC32XX_PERIPH_CLK);
bsp_interrupt_initialize();
}
diff --git a/c/src/lib/libbsp/arm/nds/Makefile.am b/c/src/lib/libbsp/arm/nds/Makefile.am
index 2776974..4e57392 100644
--- a/c/src/lib/libbsp/arm/nds/Makefile.am
+++ b/c/src/lib/libbsp/arm/nds/Makefile.am
@@ -35,6 +35,8 @@ startup_rel_SOURCES = ../../shared/bsplibc.c ../../shared/bsppost.c \
startup/bspstart.c ../../shared/bspclean.c startup/bspreset.c \
../../shared/bspgetworkarea.c ../../shared/bsppredriverhook.c \
../../shared/bsppretaskinghook.c ../../shared/bootcard.c
+libbsp_a_SOURCES += ../../shared/cpucounterget.c
+libbsp_a_SOURCES += ../../shared/cpucountersubtract.c
startup_rel_CPPFLAGS = $(AM_CPPFLAGS) -DARM9 -I$(srcdir)/libnds/include
startup_rel_LDFLAGS = $(RTEMS_RELLDFLAGS)
diff --git a/c/src/lib/libbsp/arm/raspberrypi/Makefile.am b/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
index a06979a..8aacb47 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
+++ b/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
@@ -80,6 +80,8 @@ libbsp_a_SOURCES += ../../shared/bsplibc.c
libbsp_a_SOURCES += ../../shared/bsppost.c
libbsp_a_SOURCES += ../../shared/bsppredriverhook.c
libbsp_a_SOURCES += ../../shared/bsppretaskinghook.c
+libbsp_a_SOURCES += ../../shared/cpucounterget.c
+libbsp_a_SOURCES += ../../shared/cpucountersubtract.c
libbsp_a_SOURCES += ../../shared/gnatinstallhandler.c
libbsp_a_SOURCES += ../../shared/sbrk.c
libbsp_a_SOURCES += ../../shared/src/stackalloc.c
diff --git a/c/src/lib/libbsp/arm/realview-pbx-a9/Makefile.am b/c/src/lib/libbsp/arm/realview-pbx-a9/Makefile.am
index d5c3957..19dac65 100644
--- a/c/src/lib/libbsp/arm/realview-pbx-a9/Makefile.am
+++ b/c/src/lib/libbsp/arm/realview-pbx-a9/Makefile.am
@@ -84,6 +84,7 @@ libbsp_a_SOURCES += ../../shared/bsplibc.c
libbsp_a_SOURCES += ../../shared/bsppost.c
libbsp_a_SOURCES += ../../shared/bsppredriverhook.c
libbsp_a_SOURCES += ../../shared/bsppretaskinghook.c
+libbsp_a_SOURCES += ../../shared/cpucountersubtract.c
libbsp_a_SOURCES += ../../shared/gnatinstallhandler.c
libbsp_a_SOURCES += ../../shared/sbrk.c
libbsp_a_SOURCES += ../../shared/timerstub.c
diff --git a/c/src/lib/libbsp/arm/rtl22xx/Makefile.am b/c/src/lib/libbsp/arm/rtl22xx/Makefile.am
index 31fd115..d9fca1c 100644
--- a/c/src/lib/libbsp/arm/rtl22xx/Makefile.am
+++ b/c/src/lib/libbsp/arm/rtl22xx/Makefile.am
@@ -36,6 +36,8 @@ libbsp_a_SOURCES += ../../shared/bsplibc.c ../../shared/bsppost.c \
../../shared/bspclean.c startup/bspreset.c \
../../shared/bootcard.c ../../shared/sbrk.c \
../../shared/gnatinstallhandler.c
+libbsp_a_SOURCES += ../../shared/cpucounterget.c
+libbsp_a_SOURCES += ../../shared/cpucountersubtract.c
# console
libbsp_a_SOURCES += ../../shared/console.c \
../../shared/console_select.c ../../shared/console_control.c \
diff --git a/c/src/lib/libbsp/arm/shared/arm-a9mpcore-clock-config.c b/c/src/lib/libbsp/arm/shared/arm-a9mpcore-clock-config.c
index 6f9990c..0cf839d 100644
--- a/c/src/lib/libbsp/arm/shared/arm-a9mpcore-clock-config.c
+++ b/c/src/lib/libbsp/arm/shared/arm-a9mpcore-clock-config.c
@@ -12,6 +12,8 @@
* http://www.rtems.com/license/LICENSE.
*/
+#include <rtems/cpucounter.h>
+
#include <bsp.h>
#include <bsp/irq.h>
#include <bsp/arm-a9mpcore-regs.h>
@@ -94,6 +96,15 @@ static void a9mpcore_clock_initialize(void)
| A9MPCORE_GT_CTRL_IRQ_EN
| A9MPCORE_GT_CTRL_COMP_EN
| A9MPCORE_GT_CTRL_TMR_EN;
+
+ rtems_cpu_counter_initialize_converter((uint32_t) periphclk);
+}
+
+CPU_counter _CPU_counter_Get(void)
+{
+ volatile a9mpcore_gt *gt = A9MPCORE_GT;
+
+ return gt->cntrlower;
}
static void a9mpcore_clock_cleanup(void)
diff --git a/c/src/lib/libbsp/arm/smdk2410/Makefile.am b/c/src/lib/libbsp/arm/smdk2410/Makefile.am
index e5dee1a..55c1bb7 100644
--- a/c/src/lib/libbsp/arm/smdk2410/Makefile.am
+++ b/c/src/lib/libbsp/arm/smdk2410/Makefile.am
@@ -34,6 +34,8 @@ libbsp_a_SOURCES += ../../shared/bsplibc.c ../../shared/bsppost.c \
../../shared/bsppretaskinghook.c \
../../shared/bsppredriverhook.c ../../shared/bspgetworkarea.c \
../../shared/gnatinstallhandler.c
+libbsp_a_SOURCES += ../../shared/cpucounterget.c
+libbsp_a_SOURCES += ../../shared/cpucountersubtract.c
# console
libbsp_a_SOURCES += ../gp32/console/uart.c ../../shared/console.c \
../../shared/console_select.c \
diff --git a/c/src/lib/libbsp/arm/stm32f4/Makefile.am b/c/src/lib/libbsp/arm/stm32f4/Makefile.am
index 8bdaa5e..401b23f 100644
--- a/c/src/lib/libbsp/arm/stm32f4/Makefile.am
+++ b/c/src/lib/libbsp/arm/stm32f4/Makefile.am
@@ -76,6 +76,8 @@ libbsp_a_SOURCES += ../../shared/bsplibc.c
libbsp_a_SOURCES += ../../shared/bsppost.c
libbsp_a_SOURCES += ../../shared/bsppredriverhook.c
libbsp_a_SOURCES += ../../shared/bsppretaskinghook.c
+libbsp_a_SOURCES += ../../shared/cpucounterget.c
+libbsp_a_SOURCES += ../../shared/cpucountersubtract.c
libbsp_a_SOURCES += ../../shared/gnatinstallhandler.c
libbsp_a_SOURCES += ../../shared/sbrk.c
libbsp_a_SOURCES += ../../shared/src/stackalloc.c
diff --git a/c/src/lib/libbsp/arm/xilinx-zynq/Makefile.am b/c/src/lib/libbsp/arm/xilinx-zynq/Makefile.am
index fd5d47a..098e347 100644
--- a/c/src/lib/libbsp/arm/xilinx-zynq/Makefile.am
+++ b/c/src/lib/libbsp/arm/xilinx-zynq/Makefile.am
@@ -78,6 +78,7 @@ libbsp_a_SOURCES += ../../shared/bsplibc.c
libbsp_a_SOURCES += ../../shared/bsppost.c
libbsp_a_SOURCES += ../../shared/bsppredriverhook.c
libbsp_a_SOURCES += ../../shared/bsppretaskinghook.c
+libbsp_a_SOURCES += ../../shared/cpucountersubtract.c
libbsp_a_SOURCES += ../../shared/gnatinstallhandler.c
libbsp_a_SOURCES += ../../shared/sbrk.c
libbsp_a_SOURCES += ../../shared/timerstub.c
diff --git a/c/src/lib/libbsp/powerpc/beatnik/startup/bspstart.c b/c/src/lib/libbsp/powerpc/beatnik/startup/bspstart.c
index 9b5c7a7..04a8c85 100644
--- a/c/src/lib/libbsp/powerpc/beatnik/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/beatnik/startup/bspstart.c
@@ -31,6 +31,7 @@
#include <rtems/libio.h>
#include <rtems/libcsupport.h>
#include <rtems/bspIo.h>
+#include <rtems/cpucounter.h>
#include <rtems/powerpc/powerpc.h>
/*#include <bsp/consoleIo.h>*/
#include <libcpu/spr.h> /* registers.h is included here */
@@ -337,6 +338,9 @@ void bsp_start( void )
*/
bsp_clicks_per_usec = BSP_bus_frequency/(BSP_time_base_divisor * 1000);
+ rtems_cpu_counter_initialize_converter(
+ BSP_bus_frequency / (BSP_time_base_divisor / 1000)
+ );
#ifdef SHOW_MORE_INIT_SETTINGS
printk(
diff --git a/c/src/lib/libbsp/powerpc/ep1a/startup/bspstart.c b/c/src/lib/libbsp/powerpc/ep1a/startup/bspstart.c
index a766579..a5ec7da 100644
--- a/c/src/lib/libbsp/powerpc/ep1a/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/ep1a/startup/bspstart.c
@@ -27,6 +27,7 @@
#include <libcpu/cpuIdent.h>
#include <bsp/vectors.h>
#include <rtems/powerpc/powerpc.h>
+#include <rtems/cpucounter.h>
extern unsigned long __bss_start[], __SBSS_START__[], __SBSS_END__[];
extern unsigned long __SBSS2_START__[], __SBSS2_END__[];
@@ -300,6 +301,9 @@ void bsp_start( void )
Read_ep1a_config_registers( myCpu );
bsp_clicks_per_usec = BSP_processor_frequency/(BSP_time_base_divisor * 1000);
+ rtems_cpu_counter_initialize_converter(
+ BSP_processor_frequency / (BSP_time_base_divisor / 1000)
+ );
ShowBATS();
#if 0 /* XXX - Add back in cache enable when we get this up and running!! */
diff --git a/c/src/lib/libbsp/powerpc/gen5200/startup/bspstart.c b/c/src/lib/libbsp/powerpc/gen5200/startup/bspstart.c
index 821b633..47206f0 100644
--- a/c/src/lib/libbsp/powerpc/gen5200/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/gen5200/startup/bspstart.c
@@ -95,6 +95,7 @@
/***********************************************************************/
#include <rtems.h>
+#include <rtems/cpucounter.h>
#include <libcpu/powerpc-utility.h>
@@ -164,6 +165,7 @@ void bsp_start(void)
bsp_time_base_frequency = XLB_CLOCK / 4;
bsp_clicks_per_usec = (XLB_CLOCK/4000000);
+ rtems_cpu_counter_initialize_converter(bsp_time_base_frequency);
/* Initialize exception handler */
ppc_exc_cache_wb_check = 0;
diff --git a/c/src/lib/libbsp/powerpc/gen83xx/startup/bspstart.c b/c/src/lib/libbsp/powerpc/gen83xx/startup/bspstart.c
index c3e87b4..a1d1e6b 100644
--- a/c/src/lib/libbsp/powerpc/gen83xx/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/gen83xx/startup/bspstart.c
@@ -19,6 +19,8 @@
* http://www.rtems.com/license/LICENSE.
*/
+#include <rtems/cpucounter.h>
+
#include <libchip/serial.h>
#include <libcpu/powerpc-utility.h>
@@ -117,6 +119,7 @@ void bsp_start( void)
#endif /* HAS_UBOOT */
bsp_time_base_frequency = BSP_bus_frequency / 4;
bsp_clicks_per_usec = bsp_time_base_frequency / 1000000;
+ rtems_cpu_counter_initialize_converter(bsp_time_base_frequency);
/* Initialize some console parameters */
for (i = 0; i < Console_Configuration_Count; ++i) {
diff --git a/c/src/lib/libbsp/powerpc/haleakala/startup/bspstart.c b/c/src/lib/libbsp/powerpc/haleakala/startup/bspstart.c
index 078a469..a8e9b49 100644
--- a/c/src/lib/libbsp/powerpc/haleakala/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/haleakala/startup/bspstart.c
@@ -59,6 +59,8 @@
#include <string.h>
#include <fcntl.h>
+#include <rtems/cpucounter.h>
+
#include <bsp.h>
#include <bsp/uart.h>
#include <bsp/irq.h>
@@ -194,6 +196,7 @@ void bsp_start( void )
/* Set globals visible to clock.c */
/* timebase register ticks/microsecond = CPU Clk in MHz */
bsp_clicks_per_usec = 400;
+ rtems_cpu_counter_initialize_converter(bsp_clicks_per_usec * 1000000);
bsp_timer_internal_clock = TRUE;
bsp_timer_average_overhead = 2;
diff --git a/c/src/lib/libbsp/powerpc/mbx8xx/startup/bspstart.c b/c/src/lib/libbsp/powerpc/mbx8xx/startup/bspstart.c
index 09d4fab..3524ca7 100644
--- a/c/src/lib/libbsp/powerpc/mbx8xx/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/mbx8xx/startup/bspstart.c
@@ -19,6 +19,7 @@
#include <bsp.h>
#include <bsp/irq.h>
#include <rtems/bspIo.h>
+#include <rtems/cpucounter.h>
#include <libcpu/cpuIdent.h>
#include <libcpu/spr.h>
#include <rtems/powerpc/powerpc.h>
@@ -142,6 +143,7 @@ void bsp_start(void)
#else
bsp_clicks_per_usec = 1; /* for 4MHz extclk */
#endif
+ rtems_cpu_counter_initialize_converter(bsp_clicks_per_usec * 1000000);
bsp_serial_per_sec = 10000000;
bsp_serial_external_clock = true;
diff --git a/c/src/lib/libbsp/powerpc/mpc55xxevb/startup/bspstart.c b/c/src/lib/libbsp/powerpc/mpc55xxevb/startup/bspstart.c
index 2d7debe..c1cd1e5 100644
--- a/c/src/lib/libbsp/powerpc/mpc55xxevb/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/mpc55xxevb/startup/bspstart.c
@@ -29,6 +29,7 @@
#include <rtems.h>
#include <rtems/config.h>
+#include <rtems/cpucounter.h>
#include <libcpu/powerpc-utility.h>
#include <bsp/vectors.h>
@@ -103,6 +104,7 @@ void bsp_start(void)
/* Time reference value */
bsp_clicks_per_usec = bsp_clock_speed / 1000000;
+ rtems_cpu_counter_initialize_converter(bsp_clock_speed);
/* Initialize exceptions */
ppc_exc_initialize_with_vector_base(
diff --git a/c/src/lib/libbsp/powerpc/mpc8260ads/startup/bspstart.c b/c/src/lib/libbsp/powerpc/mpc8260ads/startup/bspstart.c
index d736f24..c41e457 100644
--- a/c/src/lib/libbsp/powerpc/mpc8260ads/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/mpc8260ads/startup/bspstart.c
@@ -44,6 +44,7 @@
#include <rtems/powerpc/powerpc.h>
#include <rtems/bspIo.h>
+#include <rtems/cpucounter.h>
#include <bsp/irq.h>
#include <libcpu/cpuIdent.h>
#include <libcpu/spr.h>
@@ -208,6 +209,7 @@ void bsp_start(void)
bsp_timer_average_overhead = 3;
bsp_timer_least_valid = 3;
bsp_clock_speed = 40000000;
+ rtems_cpu_counter_initialize_converter(bsp_clock_speed);
#ifdef REV_0_2
/* set up some board specific registers */
diff --git a/c/src/lib/libbsp/powerpc/mvme3100/startup/bspstart.c b/c/src/lib/libbsp/powerpc/mvme3100/startup/bspstart.c
index 9830b6c..0cef04a 100644
--- a/c/src/lib/libbsp/powerpc/mvme3100/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/mvme3100/startup/bspstart.c
@@ -23,6 +23,7 @@
#include <rtems.h>
#include <bsp.h>
#include <rtems/bspIo.h>
+#include <rtems/cpucounter.h>
#include <libcpu/spr.h>
#include <libcpu/io.h>
#include <libcpu/e500_mmu.h>
@@ -384,6 +385,9 @@ VpdBufRec vpdData [] = {
_BSP_clear_hostbridge_errors(0 /* enableMCP */, 0/*quiet*/);
bsp_clicks_per_usec = BSP_bus_frequency/(BSP_time_base_divisor * 1000);
+ rtems_cpu_counter_initialize_converter(
+ BSP_bus_frequency / (BSP_time_base_divisor / 1000)
+ );
/*
* Initalize RTEMS IRQ system
diff --git a/c/src/lib/libbsp/powerpc/mvme5500/startup/bspstart.c b/c/src/lib/libbsp/powerpc/mvme5500/startup/bspstart.c
index 1ea4c67..abb2ac7 100644
--- a/c/src/lib/libbsp/powerpc/mvme5500/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/mvme5500/startup/bspstart.c
@@ -40,6 +40,7 @@
#include <bsp/bspException.h>
#include <rtems/bspIo.h>
+#include <rtems/cpucounter.h>
#include <rtems/sptables.h>
/*
@@ -287,6 +288,9 @@ void bsp_start( void )
/* P94 : 7455 TB/DECR is clocked by the system bus clock frequency */
bsp_clicks_per_usec = BSP_bus_frequency/(BSP_time_base_divisor * 1000);
+ rtems_cpu_counter_initialize_converter(
+ BSP_bus_frequency / (BSP_time_base_divisor / 1000)
+ );
/*
* Initalize RTEMS IRQ system
diff --git a/c/src/lib/libbsp/powerpc/psim/startup/bspstart.c b/c/src/lib/libbsp/powerpc/psim/startup/bspstart.c
index 90e9bff..5bb3b19 100644
--- a/c/src/lib/libbsp/powerpc/psim/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/psim/startup/bspstart.c
@@ -20,6 +20,7 @@
#include <bsp/bootcard.h>
#include <bsp/linker-symbols.h>
#include <rtems/bspIo.h>
+#include <rtems/cpucounter.h>
#include <rtems/powerpc/powerpc.h>
#include <libcpu/cpuIdent.h>
@@ -92,6 +93,7 @@ void bsp_start( void )
BSP_bus_frequency = (unsigned int)PSIM_INSTRUCTIONS_PER_MICROSECOND;
bsp_clicks_per_usec = BSP_bus_frequency;
BSP_time_base_divisor = 1;
+ rtems_cpu_counter_initialize_converter(BSP_bus_frequency);
/*
* Initialize default raw exception handlers.
diff --git a/c/src/lib/libbsp/powerpc/qemuppc/startup/bspstart.c b/c/src/lib/libbsp/powerpc/qemuppc/startup/bspstart.c
index 4a0a66f..d57d94b 100644
--- a/c/src/lib/libbsp/powerpc/qemuppc/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/qemuppc/startup/bspstart.c
@@ -15,6 +15,8 @@
#include <string.h>
#include <fcntl.h>
+#include <rtems/cpucounter.h>
+
#include <libcpu/bat.h>
#include <libcpu/spr.h>
#include <libcpu/powerpc-utility.h>
@@ -79,6 +81,7 @@ void bsp_start( void )
BSP_bus_frequency = 20;
bsp_time_base_frequency = 20000000;
bsp_clicks_per_usec = BSP_bus_frequency;
+ rtems_cpu_counter_initialize_converter(bsp_time_base_frequency);
/*
* Initialize the interrupt related settings.
diff --git a/c/src/lib/libbsp/powerpc/qoriq/startup/bspstart.c b/c/src/lib/libbsp/powerpc/qoriq/startup/bspstart.c
index c6f6dd9..0545fdb 100644
--- a/c/src/lib/libbsp/powerpc/qoriq/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/qoriq/startup/bspstart.c
@@ -22,6 +22,7 @@
#include <rtems.h>
#include <rtems/config.h>
+#include <rtems/cpucounter.h>
#include <libchip/serial.h>
@@ -89,6 +90,7 @@ void bsp_start(void)
BSP_bus_frequency = bsp_uboot_board_info.bi_busfreq;
bsp_clicks_per_usec = bsp_uboot_board_info.bi_busfreq / 8000000;
#endif /* HAS_UBOOT */
+ rtems_cpu_counter_initialize_converter(BSP_bus_frequency / 8);
/* Initialize some console parameters */
for (i = 0; i < Console_Configuration_Count; ++i) {
diff --git a/c/src/lib/libbsp/powerpc/score603e/startup/bspstart.c b/c/src/lib/libbsp/powerpc/score603e/startup/bspstart.c
index 8739efb..490dbdb 100644
--- a/c/src/lib/libbsp/powerpc/score603e/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/score603e/startup/bspstart.c
@@ -19,6 +19,7 @@
#include <rtems/libio.h>
#include <rtems/libcsupport.h>
#include <rtems/bspIo.h>
+#include <rtems/cpucounter.h>
#include <libcpu/cpuIdent.h>
#include <bsp/irq.h>
@@ -210,6 +211,7 @@ void bsp_start( void )
printk("bsp_start: set clicks poer usec\n");
#endif
bsp_clicks_per_usec = 66 / 4;
+ rtems_cpu_counter_initialize_converter(bsp_clicks_per_usec * 1000000);
#if BSP_DATA_CACHE_ENABLED
#if DEBUG
diff --git a/c/src/lib/libbsp/powerpc/shared/startup/bspstart.c b/c/src/lib/libbsp/powerpc/shared/startup/bspstart.c
index a59c7eb..1907a8d 100644
--- a/c/src/lib/libbsp/powerpc/shared/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/shared/startup/bspstart.c
@@ -19,6 +19,7 @@
#include <bsp.h>
#include <rtems/bspIo.h>
+#include <rtems/cpucounter.h>
#include <bsp/consoleIo.h>
#include <libcpu/spr.h>
#include <bsp/residual.h>
@@ -342,6 +343,9 @@ void bsp_start( void )
* initialize the device driver parameters
*/
bsp_clicks_per_usec = BSP_bus_frequency/(BSP_time_base_divisor * 1000);
+ rtems_cpu_counter_initialize_converter(
+ BSP_bus_frequency / (BSP_time_base_divisor / 1000)
+ );
/*
* Initalize RTEMS IRQ system
diff --git a/c/src/lib/libbsp/powerpc/ss555/startup/bspstart.c b/c/src/lib/libbsp/powerpc/ss555/startup/bspstart.c
index 46e3412..6991a08 100644
--- a/c/src/lib/libbsp/powerpc/ss555/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/ss555/startup/bspstart.c
@@ -24,6 +24,7 @@
#warning The interrupt disable mask is now stored in SPRG0, please verify that this is compatible to this BSP (see also bootcard.c).
#include <rtems/bspIo.h>
+#include <rtems/cpucounter.h>
#include <rtems/powerpc/powerpc.h>
#include <libcpu/cpuIdent.h>
@@ -108,6 +109,7 @@ void bsp_start(void)
bsp_clock_speed = BSP_CLOCK_HZ; /* for SCI baud rate generator */
bsp_timer_least_valid = 0;
bsp_timer_average_overhead = 0;
+ rtems_cpu_counter_initialize_converter(BSP_CRYSTAL_HZ / 4);
/*
* Initalize RTEMS IRQ system
diff --git a/c/src/lib/libbsp/powerpc/t32mppc/startup/bspstart.c b/c/src/lib/libbsp/powerpc/t32mppc/startup/bspstart.c
index b91ff43..7b9a6b2 100644
--- a/c/src/lib/libbsp/powerpc/t32mppc/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/t32mppc/startup/bspstart.c
@@ -13,6 +13,7 @@
*/
#include <rtems/config.h>
+#include <rtems/cpucounter.h>
#include <bsp.h>
#include <bsp/vectors.h>
@@ -63,6 +64,8 @@ void bsp_start(void)
get_ppc_cpu_type();
get_ppc_cpu_revision();
+ rtems_cpu_counter_initialize_converter(bsp_time_base_frequency);
+
/* Initialize exception handler */
ppc_exc_initialize_with_vector_base(
PPC_INTERRUPT_DISABLE_MASK_DEFAULT,
diff --git a/c/src/lib/libbsp/powerpc/tqm8xx/startup/bspstart.c b/c/src/lib/libbsp/powerpc/tqm8xx/startup/bspstart.c
index fca3531..ae40090 100644
--- a/c/src/lib/libbsp/powerpc/tqm8xx/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/tqm8xx/startup/bspstart.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <rtems.h>
+#include <rtems/cpucounter.h>
#include <libcpu/powerpc-utility.h>
@@ -179,6 +180,7 @@ void bsp_start( void)
bsp_clicks_per_usec = bsp_time_base_frequency / 1000000;
bsp_timer_least_valid = 3;
bsp_timer_average_overhead = 3;
+ rtems_cpu_counter_initialize_converter(bsp_time_base_frequency);
/* Initialize exception handler */
ppc_exc_initialize(
diff --git a/c/src/lib/libbsp/powerpc/virtex/startup/bspstart.c b/c/src/lib/libbsp/powerpc/virtex/startup/bspstart.c
index c2bedbe..ff1c550 100644
--- a/c/src/lib/libbsp/powerpc/virtex/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/virtex/startup/bspstart.c
@@ -54,6 +54,8 @@
* Modifications for PPC405GP by Dennis Ehlin
*/
+#include <rtems/cpucounter.h>
+
#include <bsp.h>
#include <bsp/irq.h>
#include <bsp/irq-generic.h>
@@ -87,6 +89,8 @@ void bsp_start( void )
get_ppc_cpu_type();
get_ppc_cpu_revision();
+ rtems_cpu_counter_initialize_converter(bsp_time_base_frequency);
+
/*
* Initialize default raw exception handlers.
*/
diff --git a/c/src/lib/libbsp/powerpc/virtex4/startup/bspstart.c b/c/src/lib/libbsp/powerpc/virtex4/startup/bspstart.c
index 6469979..0779cd0 100644
--- a/c/src/lib/libbsp/powerpc/virtex4/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/virtex4/startup/bspstart.c
@@ -57,6 +57,7 @@
#include <rtems.h>
#include <rtems/config.h>
#include <rtems/bspIo.h>
+#include <rtems/cpucounter.h>
#include <rtems/libio.h>
#include <rtems/libcsupport.h>
@@ -199,6 +200,7 @@ void bsp_start(void)
bsp_timer_internal_clock = true;
bsp_timer_average_overhead = 2;
bsp_timer_least_valid = 3;
+ rtems_cpu_counter_initialize_converter(bsp_clicks_per_usec * 1000000);
/*
* Initialize the interrupt related settings.
diff --git a/c/src/lib/libbsp/powerpc/virtex5/startup/bspstart.c b/c/src/lib/libbsp/powerpc/virtex5/startup/bspstart.c
index a05016f..346a7e4 100644
--- a/c/src/lib/libbsp/powerpc/virtex5/startup/bspstart.c
+++ b/c/src/lib/libbsp/powerpc/virtex5/startup/bspstart.c
@@ -57,6 +57,7 @@
#include <rtems.h>
#include <rtems/config.h>
#include <rtems/bspIo.h>
+#include <rtems/cpucounter.h>
#include <rtems/libio.h>
#include <rtems/libcsupport.h>
@@ -214,6 +215,9 @@ void bsp_start(void)
/* Timebase register ticks/microsecond; The application may override these */
bsp_clicks_per_usec = BSP_bus_frequency/(BSP_time_base_divisor * 1000);
+ rtems_cpu_counter_initialize_converter(
+ BSP_bus_frequency / (BSP_time_base_divisor / 1000)
+ );
bsp_timer_internal_clock = true;
bsp_timer_average_overhead = 2;
bsp_timer_least_valid = 3;
diff --git a/c/src/lib/libbsp/shared/cpucounterget.c b/c/src/lib/libbsp/shared/cpucounterget.c
new file mode 100644
index 0000000..e154670
--- /dev/null
+++ b/c/src/lib/libbsp/shared/cpucounterget.c
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems at embedded-brains.de>
+ *
+ * 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.
+ */
+
+#include <rtems/score/cpu.h>
+
+CPU_counter _CPU_counter_Get( void )
+{
+ static CPU_counter counter;
+
+ CPU_counter snapshot;
+
+ snapshot = counter;
+ counter = snapshot + 1;
+
+ return snapshot;
+}
diff --git a/c/src/lib/libbsp/shared/cpucountersubtract.c b/c/src/lib/libbsp/shared/cpucountersubtract.c
new file mode 100644
index 0000000..8fbfcf4
--- /dev/null
+++ b/c/src/lib/libbsp/shared/cpucountersubtract.c
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems at embedded-brains.de>
+ *
+ * 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.
+ */
+
+#include <rtems/score/cpu.h>
+
+CPU_counter _CPU_counter_Subtract(
+ CPU_counter upper,
+ CPU_counter lower
+)
+{
+ return upper - lower;
+}
diff --git a/c/src/lib/libbsp/sparc/erc32/Makefile.am b/c/src/lib/libbsp/sparc/erc32/Makefile.am
index 16aecca..ec8d876 100644
--- a/c/src/lib/libbsp/sparc/erc32/Makefile.am
+++ b/c/src/lib/libbsp/sparc/erc32/Makefile.am
@@ -35,6 +35,7 @@ libbsp_a_SOURCES += ../../shared/bspclean.c ../../shared/bsplibc.c \
../../shared/sbrk.c startup/setvec.c startup/spurious.c \
startup/erc32mec.c startup/boardinit.S startup/bspidle.c \
startup/bspdelay.c ../../sparc/shared/startup/early_malloc.c
+libbsp_a_SOURCES += ../../shared/cpucounterget.c
# ISR Handler
libbsp_a_SOURCES += ../../sparc/shared/irq_asm.S
# gnatsupp
diff --git a/c/src/lib/libbsp/sparc/leon2/Makefile.am b/c/src/lib/libbsp/sparc/leon2/Makefile.am
index c08f159..a6358c1 100644
--- a/c/src/lib/libbsp/sparc/leon2/Makefile.am
+++ b/c/src/lib/libbsp/sparc/leon2/Makefile.am
@@ -52,6 +52,7 @@ libbsp_a_SOURCES += ../../shared/bspclean.c ../../shared/bsplibc.c \
../../shared/sbrk.c startup/setvec.c startup/spurious.c startup/bspidle.c \
../../shared/bspinit.c startup/bspdelay.c \
../../sparc/shared/startup/early_malloc.c
+libbsp_a_SOURCES += ../../shared/cpucounterget.c
# ISR Handler
libbsp_a_SOURCES += ../../sparc/shared/irq_asm.S
# gnatsupp
diff --git a/c/src/lib/libbsp/sparc/leon3/Makefile.am b/c/src/lib/libbsp/sparc/leon3/Makefile.am
index 1a24cbf..b543f17 100644
--- a/c/src/lib/libbsp/sparc/leon3/Makefile.am
+++ b/c/src/lib/libbsp/sparc/leon3/Makefile.am
@@ -38,6 +38,7 @@ libbsp_a_SOURCES += ../../shared/bspclean.c ../../shared/bsplibc.c \
../../sparc/shared/startup/bspgetworkarea.c ../../shared/sbrk.c startup/setvec.c \
startup/spurious.c startup/bspidle.S startup/bspdelay.c \
../../shared/bspinit.c ../../sparc/shared/startup/early_malloc.c
+libbsp_a_SOURCES += startup/cpucounter.c
# ISR Handler
libbsp_a_SOURCES += ../../sparc/shared/irq_asm.S
diff --git a/c/src/lib/libbsp/sparc/leon3/include/bsp.h b/c/src/lib/libbsp/sparc/leon3/include/bsp.h
index b0a1730..18ae87f 100644
--- a/c/src/lib/libbsp/sparc/leon3/include/bsp.h
+++ b/c/src/lib/libbsp/sparc/leon3/include/bsp.h
@@ -209,6 +209,10 @@ extern void BSP_shared_interrupt_unmask(int irq);
*/
extern void BSP_shared_interrupt_mask(int irq);
+typedef enum {
+ LEON3_FATAL_CPU_COUNTER_INIT
+} leon3_fatal_code;
+
#ifdef __cplusplus
}
#endif
diff --git a/c/src/lib/libbsp/sparc/leon3/include/leon.h b/c/src/lib/libbsp/sparc/leon3/include/leon.h
index deff75d..84567e4 100644
--- a/c/src/lib/libbsp/sparc/leon3/include/leon.h
+++ b/c/src/lib/libbsp/sparc/leon3/include/leon.h
@@ -317,6 +317,8 @@ int apbuart_inbyte_nonblocking(struct apbuart_regs *regs);
*/
void leon3_secondary_cpu_initialize(uint32_t cpu);
+void leon3_cpu_counter_initialize(void);
+
void bsp_debug_uart_init(void);
#endif /* !ASM */
diff --git a/c/src/lib/libbsp/sparc/leon3/startup/bspstart.c b/c/src/lib/libbsp/sparc/leon3/startup/bspstart.c
index 1e8d12c..4b9450d 100644
--- a/c/src/lib/libbsp/sparc/leon3/startup/bspstart.c
+++ b/c/src/lib/libbsp/sparc/leon3/startup/bspstart.c
@@ -79,6 +79,7 @@ void bsp_start( void )
* interrupt support
*/
amba_initialize();
+ leon3_cpu_counter_initialize();
/* find debug UART for printk() */
bsp_debug_uart_init();
diff --git a/c/src/lib/libbsp/sparc/leon3/startup/cpucounter.c b/c/src/lib/libbsp/sparc/leon3/startup/cpucounter.c
new file mode 100644
index 0000000..35652a3
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/leon3/startup/cpucounter.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems at embedded-brains.de>
+ *
+ * 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.
+ */
+
+#include <bsp.h>
+#include <leon.h>
+
+#include <rtems/cpucounter.h>
+
+static volatile struct gptimer_regs *leon3_cpu_counter_gpt;
+
+void leon3_cpu_counter_initialize(void)
+{
+ struct ambapp_dev *adev;
+ int idx = 1;
+ volatile struct gptimer_regs *gpt;
+ unsigned new_prescaler = 8;
+ unsigned prescaler;
+ uint32_t frequency;
+
+ adev = (void *) ambapp_for_each(
+ &ambapp_plb,
+ OPTIONS_ALL | OPTIONS_APB_SLVS,
+ VENDOR_GAISLER,
+ GAISLER_GPTIMER,
+ ambapp_find_by_idx,
+ &idx
+ );
+ if (adev == NULL) {
+ rtems_fatal(RTEMS_FATAL_SOURCE_BSP_SPECIFIC, LEON3_FATAL_CPU_COUNTER_INIT);
+ }
+
+ gpt = (volatile struct gptimer_regs *) DEV_TO_APB(adev)->start;
+
+ prescaler = gpt->scaler_reload + 1;
+ gpt->scaler_reload = new_prescaler - 1;
+ gpt->timer[0].reload = 0xffffffff;
+ gpt->timer[0].ctrl = LEON3_GPTIMER_EN | LEON3_GPTIMER_RL
+ | LEON3_GPTIMER_LD;
+
+ leon3_cpu_counter_gpt = gpt;
+
+ /* Assume that GRMON initialized the timer to 1MHz */
+ frequency = UINT32_C(1000000) * (prescaler / new_prescaler);
+ rtems_cpu_counter_initialize_converter(frequency);
+}
+
+CPU_counter _CPU_counter_Get(void)
+{
+ volatile struct gptimer_regs *gpt = leon3_cpu_counter_gpt;
+
+ return 0U - gpt->timer[0].value;
+}
diff --git a/cpukit/sapi/Makefile.am b/cpukit/sapi/Makefile.am
index 65acfc7..baf6a3e 100644
--- a/cpukit/sapi/Makefile.am
+++ b/cpukit/sapi/Makefile.am
@@ -6,6 +6,7 @@ include_rtemsdir = $(includedir)/rtems
include_rtems_HEADERS = include/confdefs.h
include_rtems_HEADERS += include/rtems/chain.h
include_rtems_HEADERS += include/rtems/config.h
+include_rtems_HEADERS += include/rtems/cpucounter.h
include_rtems_HEADERS += include/rtems/extension.h
include_rtems_HEADERS += include/rtems/extensionimpl.h
include_rtems_HEADERS += include/rtems/fatal.h
@@ -32,6 +33,9 @@ libsapi_a_SOURCES = src/debug.c src/extension.c src/extensioncreate.c \
src/chainprependnotify.c src/rbheap.c src/interrtext.c \
src/fatal2.c src/fatalsrctext.c
libsapi_a_SOURCES += src/chainsmp.c
+libsapi_a_SOURCES += src/cpucounterconverter.c
+libsapi_a_SOURCES += src/delaycpu.c
+libsapi_a_SOURCES += src/delaynano.c
libsapi_a_CPPFLAGS = $(AM_CPPFLAGS)
include $(srcdir)/preinstall.am
diff --git a/cpukit/sapi/include/rtems/cpucounter.h b/cpukit/sapi/include/rtems/cpucounter.h
new file mode 100644
index 0000000..086665b
--- /dev/null
+++ b/cpukit/sapi/include/rtems/cpucounter.h
@@ -0,0 +1,140 @@
+/**
+ * @file
+ *
+ * @ingroup ClassicCPUCounter
+ *
+ * @brief CPU Counter and Delay API
+ */
+
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems at embedded-brains.de>
+ *
+ * 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.
+ */
+
+#ifndef _RTEMS_SAPI_CPUCOUNTER_H
+#define _RTEMS_SAPI_CPUCOUNTER_H
+
+#include <rtems/score/cpu.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @defgroup ClassicCPUCounter CPU Counter and Delay Functions
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * @brief CPU Counter and Delay API.
+ *
+ * A CPU counter is some free-running counter. It ticks usually with a
+ * frequency close to the CPU or system bus clock.
+ *
+ * @{
+ */
+
+/**
+ * @brief Unsigned integer type for CPU counter values.
+ */
+typedef CPU_counter rtems_cpu_counter;
+
+/**
+ * @brief Returns the current CPU counter value.
+ *
+ * @return The current CPU counter value.
+ */
+static inline rtems_cpu_counter rtems_cpu_counter_get( void )
+{
+ return _CPU_counter_Get();
+}
+
+/**
+ * @brief Subtracts the lower CPU counter value from the upper and returns the
+ * result.
+ *
+ * This operation may be carried out as a modulo operation depending on the
+ * range of the CPU counter register.
+ *
+ * @param[in] upper The upper CPU counter value.
+ * @param[in] lower The lower CPU counter value.
+ *
+ * @return Returns upper - lower.
+ */
+static inline rtems_cpu_counter rtems_cpu_counter_subtract(
+ rtems_cpu_counter upper,
+ rtems_cpu_counter lower
+)
+{
+ return _CPU_counter_Subtract( upper, lower );
+}
+
+/**
+ * brief Converts a CPU counter value into nanoseconds.
+ *
+ * @param[in] counter A CPU counter value.
+ *
+ * @return The nanoseconds corresponding to the CPU counter value.
+ */
+uint64_t rtems_cpu_counter_to_nanoseconds(
+ rtems_cpu_counter counter
+);
+
+/**
+ * brief Converts nanoseconds into a CPU counter value.
+ *
+ * @param[in] nanoseconds Some nanoseconds.
+ *
+ * @return The CPU counter value corresponding to the nanoseconds.
+ */
+rtems_cpu_counter rtems_cpu_counter_from_nanoseconds(
+ uint32_t nanoseconds
+);
+
+/**
+ * brief Initializes the CPU counter to/from nanoseconds converter functions.
+ *
+ * This function must be used to initialize the
+ * rtems_cpu_counter_to_nanoseconds() and rtems_cpu_counter_from_nanoseconds()
+ * functions. It should be called during system initialization by the board
+ * support package.
+ *
+ * @param[in] uint32_t frequency The current CPU counter frequency in Hz.
+ */
+void rtems_cpu_counter_initialize_converter( uint32_t frequency );
+
+/**
+ * @brief Busy wait for some CPU counter ticks.
+ *
+ * This function does not disable interrupts. Thus task switches and
+ * interrupts can interfere with this busy wait.
+ *
+ * @param[in] ticks The minimum busy wait time in CPU counter ticks.
+ */
+void rtems_delay_cpu_counter_ticks( rtems_cpu_counter ticks );
+
+/**
+ * @brief Busy wait for some nanoseconds.
+ *
+ * This function does not disable interrupts. Thus task switches and
+ * interrupts can interfere with this busy wait.
+ *
+ * @param[in] nanoseconds The minimum busy wait time in nanoseconds.
+ */
+void rtems_delay_nanoseconds( uint32_t nanoseconds );
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _RTEMS_SAPI_CPUCOUNTER_H */
diff --git a/cpukit/sapi/preinstall.am b/cpukit/sapi/preinstall.am
index 2b247bc..80bf016 100644
--- a/cpukit/sapi/preinstall.am
+++ b/cpukit/sapi/preinstall.am
@@ -40,6 +40,10 @@ $(PROJECT_INCLUDE)/rtems/config.h: include/rtems/config.h $(PROJECT_INCLUDE)/rte
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/config.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/config.h
+$(PROJECT_INCLUDE)/rtems/cpucounter.h: include/rtems/cpucounter.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/cpucounter.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/cpucounter.h
+
$(PROJECT_INCLUDE)/rtems/extension.h: include/rtems/extension.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/extension.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/extension.h
diff --git a/cpukit/sapi/src/cpucounterconverter.c b/cpukit/sapi/src/cpucounterconverter.c
new file mode 100644
index 0000000..6c0f9d9
--- /dev/null
+++ b/cpukit/sapi/src/cpucounterconverter.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems at embedded-brains.de>
+ *
+ * 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.
+ */
+
+#include <rtems/cpucounter.h>
+
+RTEMS_STATIC_ASSERT(sizeof(rtems_cpu_counter) <= sizeof(uint32_t), type);
+
+static uint64_t to_ns_scaler = UINT64_C(1) << 32;
+
+static uint64_t from_ns_scaler = UINT64_C(1) << 32;
+
+uint64_t rtems_cpu_counter_to_nanoseconds( rtems_cpu_counter counter )
+{
+ return (uint32_t) ((counter * to_ns_scaler) >> 32);
+}
+
+rtems_cpu_counter rtems_cpu_counter_from_nanoseconds( uint32_t nanoseconds )
+{
+ return (rtems_cpu_counter) ((nanoseconds * from_ns_scaler) >> 32);
+}
+
+void rtems_cpu_counter_initialize_converter( uint32_t frequency )
+{
+ uint64_t ns_per_s = UINT64_C(1000000000);
+
+ to_ns_scaler = ((ns_per_s << 32) + frequency - 1) / frequency;
+ from_ns_scaler = ((UINT64_C(1) << 32) * frequency + ns_per_s - 1) / ns_per_s;
+}
diff --git a/cpukit/sapi/src/delaycpu.c b/cpukit/sapi/src/delaycpu.c
new file mode 100644
index 0000000..1625239
--- /dev/null
+++ b/cpukit/sapi/src/delaycpu.c
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems at embedded-brains.de>
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <rtems/cpucounter.h>
+
+void rtems_delay_cpu_counter_ticks( rtems_cpu_counter ticks )
+{
+ rtems_cpu_counter a = rtems_cpu_counter_get();
+ rtems_cpu_counter delta = 0;
+
+ do {
+ rtems_cpu_counter b;
+
+ ticks -= delta;
+
+ b = rtems_cpu_counter_get();
+ delta = rtems_cpu_counter_subtract( b, a );
+ a = b;
+ } while ( ticks > delta );
+}
diff --git a/cpukit/sapi/src/delaynano.c b/cpukit/sapi/src/delaynano.c
new file mode 100644
index 0000000..b5266c7
--- /dev/null
+++ b/cpukit/sapi/src/delaynano.c
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems at embedded-brains.de>
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <rtems/cpucounter.h>
+
+void rtems_delay_nanoseconds( uint32_t nanoseconds )
+{
+ rtems_cpu_counter ticks = rtems_cpu_counter_from_nanoseconds( nanoseconds );
+
+ rtems_delay_cpu_counter_ticks( ticks );
+}
diff --git a/cpukit/score/cpu/arm/rtems/score/cpu.h b/cpukit/score/cpu/arm/rtems/score/cpu.h
index a2498aa..dd60634 100644
--- a/cpukit/score/cpu/arm/rtems/score/cpu.h
+++ b/cpukit/score/cpu/arm/rtems/score/cpu.h
@@ -555,6 +555,15 @@ static inline uint16_t CPU_swap_u16( uint16_t value )
#endif
}
+typedef uint32_t CPU_counter;
+
+CPU_counter _CPU_counter_Get( void );
+
+CPU_counter _CPU_counter_Subtract(
+ CPU_counter upper,
+ CPU_counter lower
+);
+
#if CPU_PROVIDES_IDLE_THREAD_BODY == TRUE
void *_CPU_Thread_Idle_body( uintptr_t ignored );
#endif
diff --git a/cpukit/score/cpu/avr/Makefile.am b/cpukit/score/cpu/avr/Makefile.am
index bb5ce35..405afde 100644
--- a/cpukit/score/cpu/avr/Makefile.am
+++ b/cpukit/score/cpu/avr/Makefile.am
@@ -162,6 +162,7 @@ include_rtems_avr_HEADERS += avr/wdt.h
noinst_LIBRARIES = libscorecpu.a
libscorecpu_a_SOURCES = cpu.c cpu_asm.S
+libscorecpu_a_SOURCES += ../no_cpu/cpucounterget.c
libscorecpu_a_SOURCES += avr-exception-frame-print.c
libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/cpukit/score/cpu/avr/rtems/score/cpu.h b/cpukit/score/cpu/avr/rtems/score/cpu.h
index f82b763..374ff01 100644
--- a/cpukit/score/cpu/avr/rtems/score/cpu.h
+++ b/cpukit/score/cpu/avr/rtems/score/cpu.h
@@ -1180,6 +1180,18 @@ static inline uint32_t CPU_swap_u32(
#define CPU_swap_u16( value ) \
(((value&0xff) << 8) | ((value >> 8)&0xff))
+typedef uint32_t CPU_counter;
+
+CPU_counter _CPU_counter_Get( void );
+
+static inline CPU_counter _CPU_counter_Subtract(
+ CPU_counter upper,
+ CPU_counter lower
+)
+{
+ return upper - lower;
+}
+
#endif /* ASM */
#ifdef __cplusplus
diff --git a/cpukit/score/cpu/bfin/Makefile.am b/cpukit/score/cpu/bfin/Makefile.am
index 48dfed4..86bc98b 100644
--- a/cpukit/score/cpu/bfin/Makefile.am
+++ b/cpukit/score/cpu/bfin/Makefile.am
@@ -17,6 +17,7 @@ include_rtems_score_HEADERS += rtems/score/cpuatomic.h
noinst_LIBRARIES = libscorecpu.a
libscorecpu_a_SOURCES = cpu.c cpu_asm.S
+libscorecpu_a_SOURCES += ../no_cpu/cpucounterget.c
libscorecpu_a_SOURCES += bfin-exception-frame-print.c
libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/cpukit/score/cpu/bfin/rtems/score/cpu.h b/cpukit/score/cpu/bfin/rtems/score/cpu.h
index a8c60a5..00c95ac 100644
--- a/cpukit/score/cpu/bfin/rtems/score/cpu.h
+++ b/cpukit/score/cpu/bfin/rtems/score/cpu.h
@@ -1280,6 +1280,18 @@ static inline uint32_t CPU_swap_u32(
#define CPU_swap_u16( value ) \
(((value&0xff) << 8) | ((value >> 8)&0xff))
+typedef uint32_t CPU_counter;
+
+CPU_counter _CPU_counter_Get( void );
+
+static inline CPU_counter _CPU_counter_Subtract(
+ CPU_counter upper,
+ CPU_counter lower
+)
+{
+ return upper - lower;
+}
+
#endif /* ASM */
#ifdef __cplusplus
diff --git a/cpukit/score/cpu/h8300/Makefile.am b/cpukit/score/cpu/h8300/Makefile.am
index db04025..868fc01 100644
--- a/cpukit/score/cpu/h8300/Makefile.am
+++ b/cpukit/score/cpu/h8300/Makefile.am
@@ -11,6 +11,7 @@ include_rtems_score_HEADERS += rtems/score/cpuatomic.h
noinst_LIBRARIES = libscorecpu.a
libscorecpu_a_SOURCES = cpu.c cpu_asm.S
+libscorecpu_a_SOURCES += ../no_cpu/cpucounterget.c
libscorecpu_a_SOURCES += h8300-exception-frame-print.c
libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/cpukit/score/cpu/h8300/rtems/score/cpu.h b/cpukit/score/cpu/h8300/rtems/score/cpu.h
index 66774d4..ccb6157 100644
--- a/cpukit/score/cpu/h8300/rtems/score/cpu.h
+++ b/cpukit/score/cpu/h8300/rtems/score/cpu.h
@@ -1162,6 +1162,18 @@ static inline uint32_t CPU_swap_u32(
#define CPU_swap_u16( value ) \
(((value&0xff) << 8) | ((value >> 8)&0xff))
+typedef uint32_t CPU_counter;
+
+CPU_counter _CPU_counter_Get( void );
+
+static inline CPU_counter _CPU_counter_Subtract(
+ CPU_counter upper,
+ CPU_counter lower
+)
+{
+ return upper - lower;
+}
+
/* to be provided by the BSP */
extern void H8BD_Install_IRQ(
uint32_t vector,
diff --git a/cpukit/score/cpu/i386/Makefile.am b/cpukit/score/cpu/i386/Makefile.am
index e35a81c..0c0a1aa 100644
--- a/cpukit/score/cpu/i386/Makefile.am
+++ b/cpukit/score/cpu/i386/Makefile.am
@@ -15,6 +15,7 @@ include_rtems_score_HEADERS += rtems/score/cpusmplock.h
noinst_LIBRARIES = libscorecpu.a
libscorecpu_a_SOURCES = cpu.c cpu_asm.S
+libscorecpu_a_SOURCES += ../no_cpu/cpucounterget.c
libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
include $(srcdir)/preinstall.am
diff --git a/cpukit/score/cpu/i386/rtems/score/cpu.h b/cpukit/score/cpu/i386/rtems/score/cpu.h
index b308ccf..7572815 100644
--- a/cpukit/score/cpu/i386/rtems/score/cpu.h
+++ b/cpukit/score/cpu/i386/rtems/score/cpu.h
@@ -694,6 +694,18 @@ static inline void _CPU_Context_validate( uintptr_t pattern )
void _CPU_Exception_frame_print( const CPU_Exception_frame *frame );
+typedef uint32_t CPU_counter;
+
+CPU_counter _CPU_counter_Get( void );
+
+static inline CPU_counter _CPU_counter_Subtract(
+ CPU_counter upper,
+ CPU_counter lower
+)
+{
+ return upper - lower;
+}
+
#endif /* ASM */
#ifdef __cplusplus
diff --git a/cpukit/score/cpu/lm32/Makefile.am b/cpukit/score/cpu/lm32/Makefile.am
index 51be260..ea2b843 100644
--- a/cpukit/score/cpu/lm32/Makefile.am
+++ b/cpukit/score/cpu/lm32/Makefile.am
@@ -12,6 +12,7 @@ include_rtems_score_HEADERS += rtems/score/cpuatomic.h
noinst_LIBRARIES = libscorecpu.a
libscorecpu_a_SOURCES = cpu.c cpu_asm.S irq.c
+libscorecpu_a_SOURCES += ../no_cpu/cpucounterget.c
libscorecpu_a_SOURCES += lm32-exception-frame-print.c
libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/cpukit/score/cpu/lm32/rtems/score/cpu.h b/cpukit/score/cpu/lm32/rtems/score/cpu.h
index 4699c1a..d0b470e 100644
--- a/cpukit/score/cpu/lm32/rtems/score/cpu.h
+++ b/cpukit/score/cpu/lm32/rtems/score/cpu.h
@@ -1282,6 +1282,18 @@ static inline uint16_t CPU_swap_u16(uint16_t v)
return v << 8 | v >> 8;
}
+typedef uint32_t CPU_counter;
+
+CPU_counter _CPU_counter_Get( void );
+
+static inline CPU_counter _CPU_counter_Subtract(
+ CPU_counter upper,
+ CPU_counter lower
+)
+{
+ return upper - lower;
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/cpukit/score/cpu/m32c/Makefile.am b/cpukit/score/cpu/m32c/Makefile.am
index 469df12..abfff08 100644
--- a/cpukit/score/cpu/m32c/Makefile.am
+++ b/cpukit/score/cpu/m32c/Makefile.am
@@ -15,6 +15,7 @@ include_rtems_score_HEADERS += rtems/score/cpuatomic.h
noinst_LIBRARIES = libscorecpu.a
libscorecpu_a_SOURCES = cpu.c cpu_asm.c context_switch.S context_init.c \
varvects.S
+libscorecpu_a_SOURCES += ../no_cpu/cpucounterget.c
libscorecpu_a_SOURCES += m32c-exception-frame-print.c
libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/cpukit/score/cpu/m32c/rtems/score/cpu.h b/cpukit/score/cpu/m32c/rtems/score/cpu.h
index 681fb4b..d665abd 100644
--- a/cpukit/score/cpu/m32c/rtems/score/cpu.h
+++ b/cpukit/score/cpu/m32c/rtems/score/cpu.h
@@ -1233,6 +1233,18 @@ static inline uint32_t CPU_swap_u32(
#define CPU_swap_u16( value ) \
(((value&0xff) << 8) | ((value >> 8)&0xff))
+typedef uint32_t CPU_counter;
+
+CPU_counter _CPU_counter_Get( void );
+
+static inline CPU_counter _CPU_counter_Subtract(
+ CPU_counter upper,
+ CPU_counter lower
+)
+{
+ return upper - lower;
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/cpukit/score/cpu/m32r/Makefile.am b/cpukit/score/cpu/m32r/Makefile.am
index 81ee9ac8..d50eb1c 100644
--- a/cpukit/score/cpu/m32r/Makefile.am
+++ b/cpukit/score/cpu/m32r/Makefile.am
@@ -14,6 +14,7 @@ include_rtems_score_HEADERS += rtems/score/cpuatomic.h
noinst_LIBRARIES = libscorecpu.a
libscorecpu_a_SOURCES = cpu.c cpu_asm.c context_switch.S context_init.c
+libscorecpu_a_SOURCES += ../no_cpu/cpucounterget.c
libscorecpu_a_SOURCES += m32r-exception-frame-print.c
libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/cpukit/score/cpu/m32r/rtems/score/cpu.h b/cpukit/score/cpu/m32r/rtems/score/cpu.h
index 95a897a..1e33c51 100644
--- a/cpukit/score/cpu/m32r/rtems/score/cpu.h
+++ b/cpukit/score/cpu/m32r/rtems/score/cpu.h
@@ -1274,6 +1274,18 @@ static inline uint32_t CPU_swap_u32(
#define CPU_swap_u16( value ) \
(((value&0xff) << 8) | ((value >> 8)&0xff))
+typedef uint32_t CPU_counter;
+
+CPU_counter _CPU_counter_Get( void );
+
+static inline CPU_counter _CPU_counter_Subtract(
+ CPU_counter upper,
+ CPU_counter lower
+)
+{
+ return upper - lower;
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/cpukit/score/cpu/m68k/Makefile.am b/cpukit/score/cpu/m68k/Makefile.am
index 9d8d333..0f0f232 100644
--- a/cpukit/score/cpu/m68k/Makefile.am
+++ b/cpukit/score/cpu/m68k/Makefile.am
@@ -19,6 +19,7 @@ include_rtems_score_HEADERS += rtems/score/types.h
include_rtems_score_HEADERS += rtems/score/cpuatomic.h
libscorecpu_a_SOURCES = cpu.c cpu_asm.S
+libscorecpu_a_SOURCES += ../no_cpu/cpucounterget.c
libscorecpu_a_SOURCES += m68k-exception-frame-print.c
libscorecpu_a_SOURCES += __m68k_read_tp.c
diff --git a/cpukit/score/cpu/m68k/rtems/score/cpu.h b/cpukit/score/cpu/m68k/rtems/score/cpu.h
index 9981f53..8a8fad7 100644
--- a/cpukit/score/cpu/m68k/rtems/score/cpu.h
+++ b/cpukit/score/cpu/m68k/rtems/score/cpu.h
@@ -723,6 +723,18 @@ void _CPU_Exception_frame_print(
const CPU_Exception_frame *frame
);
+typedef uint32_t CPU_counter;
+
+CPU_counter _CPU_counter_Get( void );
+
+static inline CPU_counter _CPU_counter_Subtract(
+ CPU_counter upper,
+ CPU_counter lower
+)
+{
+ return upper - lower;
+}
+
#if (M68K_HAS_FPSP_PACKAGE == 1)
/*
* Hooks for the Floating Point Support Package (FPSP) provided by Motorola
diff --git a/cpukit/score/cpu/mips/Makefile.am b/cpukit/score/cpu/mips/Makefile.am
index 7a06fae..a29094516 100644
--- a/cpukit/score/cpu/mips/Makefile.am
+++ b/cpukit/score/cpu/mips/Makefile.am
@@ -15,6 +15,7 @@ include_rtems_score_HEADERS += rtems/score/cpuatomic.h
noinst_LIBRARIES = libscorecpu.a
libscorecpu_a_SOURCES = cpu.c cpu_asm.S
+libscorecpu_a_SOURCES += ../no_cpu/cpucounterget.c
libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
include $(srcdir)/preinstall.am
diff --git a/cpukit/score/cpu/mips/rtems/score/cpu.h b/cpukit/score/cpu/mips/rtems/score/cpu.h
index 6299961..01354ce 100644
--- a/cpukit/score/cpu/mips/rtems/score/cpu.h
+++ b/cpukit/score/cpu/mips/rtems/score/cpu.h
@@ -1193,6 +1193,17 @@ static inline uint32_t CPU_swap_u32(
#define CPU_swap_u16( value ) \
(((value&0xff) << 8) | ((value >> 8)&0xff))
+typedef uint32_t CPU_counter;
+
+CPU_counter _CPU_counter_Get( void );
+
+static inline CPU_counter _CPU_counter_Subtract(
+ CPU_counter upper,
+ CPU_counter lower
+)
+{
+ return upper - lower;
+}
#endif
diff --git a/cpukit/score/cpu/moxie/Makefile.am b/cpukit/score/cpu/moxie/Makefile.am
index a4fb31b..14c4d58 100644
--- a/cpukit/score/cpu/moxie/Makefile.am
+++ b/cpukit/score/cpu/moxie/Makefile.am
@@ -14,6 +14,7 @@ include_rtems_score_HEADERS += rtems/score/cpuatomic.h
noinst_LIBRARIES = libscorecpu.a
libscorecpu_a_SOURCES = cpu.c moxie-exception-frame-print.c cpu_asm.S
+libscorecpu_a_SOURCES += ../no_cpu/cpucounterget.c
libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
include $(srcdir)/preinstall.am
diff --git a/cpukit/score/cpu/moxie/rtems/score/cpu.h b/cpukit/score/cpu/moxie/rtems/score/cpu.h
index 36a956c..586ba0b 100644
--- a/cpukit/score/cpu/moxie/rtems/score/cpu.h
+++ b/cpukit/score/cpu/moxie/rtems/score/cpu.h
@@ -1049,6 +1049,18 @@ static inline uint32_t CPU_swap_u32(
#define CPU_swap_u16( value ) \
(((value&0xff) << 8) | ((value >> 8)&0xff))
+typedef uint32_t CPU_counter;
+
+CPU_counter _CPU_counter_Get( void );
+
+static inline CPU_counter _CPU_counter_Subtract(
+ CPU_counter upper,
+ CPU_counter lower
+)
+{
+ return upper - lower;
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/cpukit/score/cpu/nios2/Makefile.am b/cpukit/score/cpu/nios2/Makefile.am
index 6fdc786..1a3944d 100644
--- a/cpukit/score/cpu/nios2/Makefile.am
+++ b/cpukit/score/cpu/nios2/Makefile.am
@@ -21,6 +21,7 @@ include_rtems_score_HEADERS += rtems/score/cpuatomic.h
noinst_LIBRARIES = libscorecpu.a
libscorecpu_a_SOURCES =
+libscorecpu_a_SOURCES += ../no_cpu/cpucounterget.c
libscorecpu_a_SOURCES += nios2-context-initialize.c
libscorecpu_a_SOURCES += nios2-context-switch.S
libscorecpu_a_SOURCES += nios2-context-validate.S
diff --git a/cpukit/score/cpu/nios2/rtems/score/cpu.h b/cpukit/score/cpu/nios2/rtems/score/cpu.h
index bdd8f57..cb48322 100644
--- a/cpukit/score/cpu/nios2/rtems/score/cpu.h
+++ b/cpukit/score/cpu/nios2/rtems/score/cpu.h
@@ -364,6 +364,18 @@ static inline uint32_t CPU_swap_u32( uint32_t value )
#define CPU_swap_u16( value ) \
(((value&0xff) << 8) | ((value >> 8)&0xff))
+typedef uint32_t CPU_counter;
+
+CPU_counter _CPU_counter_Get( void );
+
+static inline CPU_counter _CPU_counter_Subtract(
+ CPU_counter upper,
+ CPU_counter lower
+)
+{
+ return upper - lower;
+}
+
#endif /* ASM */
#ifdef __cplusplus
diff --git a/cpukit/score/cpu/no_cpu/Makefile.am b/cpukit/score/cpu/no_cpu/Makefile.am
index 2451743..9395922 100644
--- a/cpukit/score/cpu/no_cpu/Makefile.am
+++ b/cpukit/score/cpu/no_cpu/Makefile.am
@@ -12,6 +12,7 @@ include_rtems_score_HEADERS += rtems/score/cpusmplock.h
noinst_LIBRARIES = libscorecpu.a
libscorecpu_a_SOURCES = cpu.c cpu_asm.c
+libscorecpu_a_SOURCES += cpucounterget.c
libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
include $(srcdir)/preinstall.am
diff --git a/cpukit/score/cpu/no_cpu/cpucounterget.c b/cpukit/score/cpu/no_cpu/cpucounterget.c
new file mode 100644
index 0000000..e154670
--- /dev/null
+++ b/cpukit/score/cpu/no_cpu/cpucounterget.c
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems at embedded-brains.de>
+ *
+ * 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.
+ */
+
+#include <rtems/score/cpu.h>
+
+CPU_counter _CPU_counter_Get( void )
+{
+ static CPU_counter counter;
+
+ CPU_counter snapshot;
+
+ snapshot = counter;
+ counter = snapshot + 1;
+
+ return snapshot;
+}
diff --git a/cpukit/score/cpu/no_cpu/rtems/score/cpu.h b/cpukit/score/cpu/no_cpu/rtems/score/cpu.h
index 783da76..f2af54d 100644
--- a/cpukit/score/cpu/no_cpu/rtems/score/cpu.h
+++ b/cpukit/score/cpu/no_cpu/rtems/score/cpu.h
@@ -1426,6 +1426,37 @@ static inline uint32_t CPU_swap_u32(
#define CPU_swap_u16( value ) \
(((value&0xff) << 8) | ((value >> 8)&0xff))
+/**
+ * @brief Unsigned integer type for CPU counter values.
+ */
+typedef uint32_t CPU_counter;
+
+/**
+ * @brief Returns the current CPU counter value.
+ *
+ * A CPU counter is some free-running counter. It ticks usually with a
+ * frequency close to the CPU or system bus clock. The board support package
+ * must ensure that this function works before the RTEMS initialization.
+ * Otherwise invalid profiling statistics will be gathered.
+ *
+ * @return The current CPU counter value.
+ */
+CPU_counter _CPU_counter_Get( void );
+
+/**
+ * @brief Subtracts the lower CPU counter value from the upper and returns the
+ * result.
+ *
+ * This operation may be carried out as a modulo operation depending on the
+ * range of the CPU counter device.
+ *
+ * @param[in] upper The upper CPU counter value.
+ * @param[in] lower The lower CPU counter value.
+ *
+ * @return Returns upper - lower.
+ */
+CPU_counter _CPU_counter_Subtract( CPU_counter upper, CPU_counter lower );
+
#ifdef RTEMS_SMP
/**
* @brief Returns the index of the current processor.
diff --git a/cpukit/score/cpu/powerpc/rtems/score/cpu.h b/cpukit/score/cpu/powerpc/rtems/score/cpu.h
index 45b8827..62ab8d2 100644
--- a/cpukit/score/cpu/powerpc/rtems/score/cpu.h
+++ b/cpukit/score/cpu/powerpc/rtems/score/cpu.h
@@ -769,6 +769,30 @@ static inline uint32_t CPU_swap_u32(
#define CPU_swap_u16( value ) \
(((value&0xff) << 8) | ((value >> 8)&0xff))
+typedef uint32_t CPU_counter;
+
+static inline CPU_counter _CPU_counter_Get( void )
+{
+ CPU_counter value;
+
+#ifdef ppc8540
+ /* Book E has no mftb */
+ __asm__ volatile( "mfspr %0, 268" : "=r" (value) );
+#else
+ __asm__ volatile( "mftb %0" : "=r" (value) );
+#endif
+
+ return value;
+}
+
+static inline CPU_counter _CPU_counter_Subtract(
+ CPU_counter upper,
+ CPU_counter lower
+)
+{
+ return upper - lower;
+}
+
#endif /* ASM */
diff --git a/cpukit/score/cpu/sh/Makefile.am b/cpukit/score/cpu/sh/Makefile.am
index 7eb2297..dd0f4c6 100644
--- a/cpukit/score/cpu/sh/Makefile.am
+++ b/cpukit/score/cpu/sh/Makefile.am
@@ -12,6 +12,7 @@ include_rtems_score_HEADERS += rtems/score/cpuatomic.h
noinst_LIBRARIES = libscorecpu.a
libscorecpu_a_SOURCES = cpu.c context.c
+libscorecpu_a_SOURCES += ../no_cpu/cpucounterget.c
libscorecpu_a_SOURCES += sh-exception-frame-print.c
libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/cpukit/score/cpu/sh/rtems/score/cpu.h b/cpukit/score/cpu/sh/rtems/score/cpu.h
index ff9ad55..3f7eedc 100644
--- a/cpukit/score/cpu/sh/rtems/score/cpu.h
+++ b/cpukit/score/cpu/sh/rtems/score/cpu.h
@@ -910,6 +910,18 @@ typedef CPU_Interrupt_frame CPU_Exception_frame;
void _CPU_Exception_frame_print( const CPU_Exception_frame *frame );
+typedef uint32_t CPU_counter;
+
+CPU_counter _CPU_counter_Get( void );
+
+static inline CPU_counter _CPU_counter_Subtract(
+ CPU_counter upper,
+ CPU_counter lower
+)
+{
+ return upper - lower;
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/cpukit/score/cpu/sparc/rtems/score/cpu.h b/cpukit/score/cpu/sparc/rtems/score/cpu.h
index 9706e45..fe76fa5 100644
--- a/cpukit/score/cpu/sparc/rtems/score/cpu.h
+++ b/cpukit/score/cpu/sparc/rtems/score/cpu.h
@@ -1269,6 +1269,18 @@ static inline uint32_t CPU_swap_u32(
#define CPU_swap_u16( value ) \
(((value&0xff) << 8) | ((value >> 8)&0xff))
+typedef uint32_t CPU_counter;
+
+CPU_counter _CPU_counter_Get( void );
+
+static inline CPU_counter _CPU_counter_Subtract(
+ CPU_counter upper,
+ CPU_counter lower
+)
+{
+ return upper - lower;
+}
+
#endif /* ASM */
#ifdef __cplusplus
diff --git a/cpukit/score/cpu/sparc64/Makefile.am b/cpukit/score/cpu/sparc64/Makefile.am
index 02babb4..1069a51 100644
--- a/cpukit/score/cpu/sparc64/Makefile.am
+++ b/cpukit/score/cpu/sparc64/Makefile.am
@@ -14,6 +14,7 @@ include_rtems_score_HEADERS += rtems/score/cpuatomic.h
noinst_LIBRARIES = libscorecpu.a
libscorecpu_a_SOURCES = context.S cpu.c
+libscorecpu_a_SOURCES += ../no_cpu/cpucounterget.c
libscorecpu_a_SOURCES += sparc64-exception-frame-print.c
libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/cpukit/score/cpu/sparc64/rtems/score/cpu.h b/cpukit/score/cpu/sparc64/rtems/score/cpu.h
index 22ec97d..516a594 100644
--- a/cpukit/score/cpu/sparc64/rtems/score/cpu.h
+++ b/cpukit/score/cpu/sparc64/rtems/score/cpu.h
@@ -1089,6 +1089,18 @@ static inline uint32_t CPU_swap_u32(
#define CPU_swap_u16( value ) \
(((value&0xff) << 8) | ((value >> 8)&0xff))
+typedef uint32_t CPU_counter;
+
+CPU_counter _CPU_counter_Get( void );
+
+static inline CPU_counter _CPU_counter_Subtract(
+ CPU_counter upper,
+ CPU_counter lower
+)
+{
+ return upper - lower;
+}
+
#endif /* ASM */
#ifdef __cplusplus
diff --git a/cpukit/score/cpu/v850/Makefile.am b/cpukit/score/cpu/v850/Makefile.am
index c873bae..86c29d4 100644
--- a/cpukit/score/cpu/v850/Makefile.am
+++ b/cpukit/score/cpu/v850/Makefile.am
@@ -12,6 +12,7 @@ include_rtems_score_HEADERS += rtems/score/cpuatomic.h
noinst_LIBRARIES = libscorecpu.a
libscorecpu_a_SOURCES = cpu.c
libscorecpu_a_SOURCES += cpu_asm.S
+libscorecpu_a_SOURCES += ../no_cpu/cpucounterget.c
libscorecpu_a_SOURCES += v850-exception-frame-print.c
libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/cpukit/score/cpu/v850/rtems/score/cpu.h b/cpukit/score/cpu/v850/rtems/score/cpu.h
index f41bde0..e44811e 100644
--- a/cpukit/score/cpu/v850/rtems/score/cpu.h
+++ b/cpukit/score/cpu/v850/rtems/score/cpu.h
@@ -1233,6 +1233,18 @@ static inline uint16_t CPU_swap_u16( uint16_t value )
return swapped;
}
+typedef uint32_t CPU_counter;
+
+CPU_counter _CPU_counter_Get( void );
+
+static inline CPU_counter _CPU_counter_Subtract(
+ CPU_counter upper,
+ CPU_counter lower
+)
+{
+ return upper - lower;
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/doc/cpu_supplement/general.t b/doc/cpu_supplement/general.t
index cf28eef..6478529 100644
--- a/doc/cpu_supplement/general.t
+++ b/doc/cpu_supplement/general.t
@@ -341,6 +341,25 @@ _TLS_Size = _TLS_BSS_end - _TLS_Data_begin;
_TLS_Alignment = ALIGNOF (.tdata);
@end example
+ at section CPU counter
+
+The CPU support must implement the CPU counter interface. A CPU counter is
+some free-running counter. It ticks usually with a frequency close to the CPU
+or system bus clock. On some architectures the actual implementation is board
+support package dependent. The CPU counter is used for profiling of low-level
+functions. It is also used to implement two busy wait functions
+ at code{rtems_delay_cpu_counter_ticks()} and @code{rtems_delay_nanoseconds()}
+which may be used in device drivers.
+
+The CPU counter interface uses a CPU port specific unsigned integer type
+ at code{CPU_counter} to represent CPU counter values. The CPU port must provide
+the following two functions
+
+ at itemize
+ at item @code{_CPU_counter_Get()} to get the current CPU counter value, and
+ at item @code{_CPU_counter_Subtract()} to subtract two the CPU counter values.
+ at end itemize
+
@c
@c
@c
diff --git a/testsuites/sptests/Makefile.am b/testsuites/sptests/Makefile.am
index 1eacf5c..9829d15 100644
--- a/testsuites/sptests/Makefile.am
+++ b/testsuites/sptests/Makefile.am
@@ -30,6 +30,7 @@ SUBDIRS = \
spsimplesched03 spnsext01 spedfsched01 spedfsched02 spedfsched03 \
spcbssched01 spcbssched02 spcbssched03 spqreslib sptimespec01 \
spregion_err01 sppartition_err01
+SUBDIRS += spcpucounter01
if HAS_CPLUSPLUS
SUBDIRS += sptls02
endif
diff --git a/testsuites/sptests/configure.ac b/testsuites/sptests/configure.ac
index 623e784..c5f20b4 100644
--- a/testsuites/sptests/configure.ac
+++ b/testsuites/sptests/configure.ac
@@ -36,6 +36,7 @@ AM_CONDITIONAL(HAS_CPUSET,test x"${ac_cv_header_sys_cpuset_h}" = x"yes")
# Explicitly list all Makefiles here
AC_CONFIG_FILES([Makefile
+spcpucounter01/Makefile
sptls02/Makefile
sptls01/Makefile
spintrcritical20/Makefile
diff --git a/testsuites/sptests/spcpucounter01/Makefile.am b/testsuites/sptests/spcpucounter01/Makefile.am
new file mode 100644
index 0000000..1cf3ee2
--- /dev/null
+++ b/testsuites/sptests/spcpucounter01/Makefile.am
@@ -0,0 +1,19 @@
+rtems_tests_PROGRAMS = spcpucounter01
+spcpucounter01_SOURCES = init.c
+
+dist_rtems_tests_DATA = spcpucounter01.scn spcpucounter01.doc
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP at .cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(spcpucounter01_OBJECTS)
+LINK_LIBS = $(spcpucounter01_LDLIBS)
+
+spcpucounter01$(EXEEXT): $(spcpucounter01_OBJECTS) $(spcpucounter01_DEPENDENCIES)
+ @rm -f spcpucounter01$(EXEEXT)
+ $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/sptests/spcpucounter01/init.c b/testsuites/sptests/spcpucounter01/init.c
new file mode 100644
index 0000000..280d55c
--- /dev/null
+++ b/testsuites/sptests/spcpucounter01/init.c
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems at embedded-brains.de>
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <stdio.h>
+#include <inttypes.h>
+
+#include <rtems.h>
+#include <rtems/cpucounter.h>
+
+#define TESTS_USE_PRINTF
+#include "tmacros.h"
+
+#define NS_PER_TICK 1000000
+
+static rtems_interval sync_with_clock_tick(void)
+{
+ rtems_interval start = rtems_clock_get_ticks_since_boot();
+ rtems_interval current;
+
+ do {
+ current = rtems_clock_get_ticks_since_boot();
+ } while (current == start);
+
+ return current;
+}
+
+static void test_converter(void)
+{
+ CPU_counter frequency = rtems_cpu_counter_from_nanoseconds(1000000000);
+ uint64_t ns = rtems_cpu_counter_to_nanoseconds(frequency);
+
+ printf("CPU counter frequency: %" PRIu32 "Hz\n", frequency);
+ printf("nanoseconds for frequency count ticks: %" PRIu64 "\n", ns);
+
+ rtems_test_assert(ns == 1000000000);
+}
+
+static void test_delay_nanoseconds(void)
+{
+ rtems_cpu_counter start;
+ rtems_cpu_counter end;
+ rtems_cpu_counter delta;
+ double ns_per_tick = NS_PER_TICK;
+ double ns_delta;
+ rtems_interval tick;
+ int n = 10;
+ int i;
+
+ printf("test delay nanoseconds (%i times)\n", n);
+
+ for (i = 0; i < n; ++i) {
+ tick = sync_with_clock_tick();
+
+ start = rtems_cpu_counter_get();
+ rtems_delay_nanoseconds(NS_PER_TICK);
+ end = rtems_cpu_counter_get();
+
+ rtems_test_assert(tick < rtems_clock_get_ticks_since_boot());
+
+ delta = rtems_cpu_counter_subtract(end, start);
+ ns_delta = rtems_cpu_counter_to_nanoseconds(delta);
+
+ rtems_test_assert(ns_delta > ns_per_tick);
+
+ printf(
+ "busy wait relative to clock tick: %f\n",
+ (ns_delta - ns_per_tick) / ns_per_tick
+ );
+ }
+}
+
+static void Init(rtems_task_argument arg)
+{
+ puts("\n\n*** TEST SPCPUCOUNTER 1 ***");
+
+ test_converter();
+ test_delay_nanoseconds();
+
+ puts("*** END OF TEST SPCPUCOUNTER 1 ***");
+
+ rtems_test_exit(0);
+}
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_MICROSECONDS_PER_TICK (NS_PER_TICK / 1000)
+
+#define CONFIGURE_MAXIMUM_TASKS 1
+
+#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
diff --git a/testsuites/sptests/spcpucounter01/spcpucounter01.doc b/testsuites/sptests/spcpucounter01/spcpucounter01.doc
new file mode 100644
index 0000000..dbbefd6
--- /dev/null
+++ b/testsuites/sptests/spcpucounter01/spcpucounter01.doc
@@ -0,0 +1,16 @@
+This file describes the directives and concepts tested by this test set.
+
+test set name: spcpucounter01
+
+directives:
+
+ - rtems_cpu_counter_get()
+ - rtems_cpu_counter_subtract()
+ - rtems_cpu_counter_to_nanoseconds()
+ - rtems_cpu_counter_from_nanoseconds()
+
+concepts:
+
+ - Ensure that the CPU counter converter functions produce consistent values.
+ - Ensure that the busy wait functions are consistent with the clock tick
+ durations.
diff --git a/testsuites/sptests/spcpucounter01/spcpucounter01.scn b/testsuites/sptests/spcpucounter01/spcpucounter01.scn
new file mode 100644
index 0000000..fc8e849
--- /dev/null
+++ b/testsuites/sptests/spcpucounter01/spcpucounter01.scn
@@ -0,0 +1,15 @@
+*** TEST SPCPUCOUNTER 1 ***
+CPU counter frequency: 25000000Hz
+nanoseconds for frequency count ticks: 1000000000
+test delay nanoseconds (10 times)
+busy wait relative to clock tick: 0.001320
+busy wait relative to clock tick: 0.001640
+busy wait relative to clock tick: 0.001320
+busy wait relative to clock tick: 0.001160
+busy wait relative to clock tick: 0.001280
+busy wait relative to clock tick: 0.001240
+busy wait relative to clock tick: 0.001280
+busy wait relative to clock tick: 0.001280
+busy wait relative to clock tick: 0.001320
+busy wait relative to clock tick: 0.001280
+*** END OF TEST SPCPUCOUNTER 1 ***
--
1.7.7
More information about the devel
mailing list