score: Add CPU counter support

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_counter_delay_ticks() and
rtems_counter_delay_nanoseconds() implemented via the CPU counter.
This commit is contained in:
Sebastian Huber
2014-02-12 10:31:38 +01:00
parent 382ea27b6a
commit 24bf11eca1
97 changed files with 985 additions and 5 deletions

View File

@@ -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/cpucounterread.c
libbsp_a_SOURCES += ../../shared/cpucounterdiff.c
# console
libbsp_a_SOURCES += console/uart.c
# abort

View File

@@ -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/cpucounterread.c
libbsp_a_SOURCES += ../../shared/cpucounterdiff.c
# console
libbsp_a_SOURCES += ../../shared/console.c console/uarts.c \
../../shared/console_select.c ../../shared/console_control.c \

View File

@@ -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/cpucounterread.c
libbsp_a_SOURCES += ../../shared/cpucounterdiff.c
# clock
libbsp_a_SOURCES += clock/clockdrv.c

View File

@@ -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/cpucounterread.c
libbsp_a_SOURCES += ../../shared/cpucounterdiff.c
# clock
libbsp_a_SOURCES += clock/clockdrv.c
libbsp_a_SOURCES += ../../shared/clockdrv_shell.h

View File

@@ -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/cpucounterread.c
libbsp_a_SOURCES += ../../shared/cpucounterdiff.c
# console
libbsp_a_SOURCES += ../../shared/console-polled.c console/console-io.c
# clock

View File

@@ -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/cpucounterread.c
libbsp_a_SOURCES += ../../shared/cpucounterdiff.c
# console
libbsp_a_SOURCES += console/uart.c ../../shared/console.c \
../../shared/console_select.c ../../shared/console_control.c \

View File

@@ -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/cpucounterread.c
libbsp_a_SOURCES += ../../shared/cpucounterdiff.c
#console
libbsp_a_SOURCES += console/uarts.c ../../shared/console.c \

View File

@@ -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/cpucounterread.c
libbsp_a_SOURCES += ../../shared/cpucounterdiff.c
libbsp_a_SOURCES += ../../shared/gnatinstallhandler.c
libbsp_a_SOURCES += ../../shared/sbrk.c
libbsp_a_SOURCES += ../../shared/src/stackalloc.c

View File

@@ -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/cpucounterdiff.c
# Startup
libbsp_a_SOURCES += ../shared/startup/bsp-start-memcpy.S

View File

@@ -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/counter.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_counter_initialize_converter(LPC24XX_PCLK);
}
CPU_Counter_ticks _CPU_Counter_read(void)
{
return lpc24xx_timer();
}
void lpc24xx_micro_seconds_delay(unsigned us)

View File

@@ -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/cpucounterdiff.c
libbsp_a_SOURCES += ../../shared/gnatinstallhandler.c
libbsp_a_SOURCES += ../../shared/sbrk.c
libbsp_a_SOURCES += ../../shared/src/stackalloc.c

View File

@@ -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/counter.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_ticks _CPU_Counter_read(void)
{
return lpc32xx_timer();
}
void bsp_start(void)
{
rtems_counter_initialize_converter(LPC32XX_PERIPH_CLK);
bsp_interrupt_initialize();
}

View File

@@ -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/cpucounterread.c
libbsp_a_SOURCES += ../../shared/cpucounterdiff.c
startup_rel_CPPFLAGS = $(AM_CPPFLAGS) -DARM9 -I$(srcdir)/libnds/include
startup_rel_LDFLAGS = $(RTEMS_RELLDFLAGS)

View File

@@ -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/cpucounterread.c
libbsp_a_SOURCES += ../../shared/cpucounterdiff.c
libbsp_a_SOURCES += ../../shared/gnatinstallhandler.c
libbsp_a_SOURCES += ../../shared/sbrk.c
libbsp_a_SOURCES += ../../shared/src/stackalloc.c

View File

@@ -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/cpucounterdiff.c
libbsp_a_SOURCES += ../../shared/gnatinstallhandler.c
libbsp_a_SOURCES += ../../shared/sbrk.c
libbsp_a_SOURCES += ../../shared/timerstub.c

View File

@@ -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/cpucounterread.c
libbsp_a_SOURCES += ../../shared/cpucounterdiff.c
# console
libbsp_a_SOURCES += ../../shared/console.c \
../../shared/console_select.c ../../shared/console_control.c \

View File

@@ -12,6 +12,8 @@
* http://www.rtems.com/license/LICENSE.
*/
#include <rtems/counter.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_counter_initialize_converter((uint32_t) periphclk);
}
CPU_Counter_ticks _CPU_Counter_read(void)
{
volatile a9mpcore_gt *gt = A9MPCORE_GT;
return gt->cntrlower;
}
static void a9mpcore_clock_cleanup(void)

View File

@@ -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/cpucounterread.c
libbsp_a_SOURCES += ../../shared/cpucounterdiff.c
# console
libbsp_a_SOURCES += ../gp32/console/uart.c ../../shared/console.c \
../../shared/console_select.c \

View File

@@ -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/cpucounterread.c
libbsp_a_SOURCES += ../../shared/cpucounterdiff.c
libbsp_a_SOURCES += ../../shared/gnatinstallhandler.c
libbsp_a_SOURCES += ../../shared/sbrk.c
libbsp_a_SOURCES += ../../shared/src/stackalloc.c

View File

@@ -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/cpucounterdiff.c
libbsp_a_SOURCES += ../../shared/gnatinstallhandler.c
libbsp_a_SOURCES += ../../shared/sbrk.c
libbsp_a_SOURCES += ../../shared/timerstub.c

View File

@@ -31,6 +31,7 @@
#include <rtems/libio.h>
#include <rtems/libcsupport.h>
#include <rtems/bspIo.h>
#include <rtems/counter.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_counter_initialize_converter(
BSP_bus_frequency / (BSP_time_base_divisor / 1000)
);
#ifdef SHOW_MORE_INIT_SETTINGS
printk(

View File

@@ -27,6 +27,7 @@
#include <libcpu/cpuIdent.h>
#include <bsp/vectors.h>
#include <rtems/powerpc/powerpc.h>
#include <rtems/counter.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_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!! */

View File

@@ -95,6 +95,7 @@
/***********************************************************************/
#include <rtems.h>
#include <rtems/counter.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_counter_initialize_converter(bsp_time_base_frequency);
/* Initialize exception handler */
ppc_exc_cache_wb_check = 0;

View File

@@ -19,6 +19,8 @@
* http://www.rtems.com/license/LICENSE.
*/
#include <rtems/counter.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_counter_initialize_converter(bsp_time_base_frequency);
/* Initialize some console parameters */
for (i = 0; i < Console_Configuration_Count; ++i) {

View File

@@ -59,6 +59,8 @@
#include <string.h>
#include <fcntl.h>
#include <rtems/counter.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_counter_initialize_converter(bsp_clicks_per_usec * 1000000);
bsp_timer_internal_clock = TRUE;
bsp_timer_average_overhead = 2;

View File

@@ -19,6 +19,7 @@
#include <bsp.h>
#include <bsp/irq.h>
#include <rtems/bspIo.h>
#include <rtems/counter.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_counter_initialize_converter(bsp_clicks_per_usec * 1000000);
bsp_serial_per_sec = 10000000;
bsp_serial_external_clock = true;

View File

@@ -29,6 +29,7 @@
#include <rtems.h>
#include <rtems/config.h>
#include <rtems/counter.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_counter_initialize_converter(bsp_clock_speed);
/* Initialize exceptions */
ppc_exc_initialize_with_vector_base(

View File

@@ -44,6 +44,7 @@
#include <rtems/powerpc/powerpc.h>
#include <rtems/bspIo.h>
#include <rtems/counter.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_counter_initialize_converter(bsp_clock_speed);
#ifdef REV_0_2
/* set up some board specific registers */

View File

@@ -23,6 +23,7 @@
#include <rtems.h>
#include <bsp.h>
#include <rtems/bspIo.h>
#include <rtems/counter.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_counter_initialize_converter(
BSP_bus_frequency / (BSP_time_base_divisor / 1000)
);
/*
* Initalize RTEMS IRQ system

View File

@@ -40,6 +40,7 @@
#include <bsp/bspException.h>
#include <rtems/bspIo.h>
#include <rtems/counter.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_counter_initialize_converter(
BSP_bus_frequency / (BSP_time_base_divisor / 1000)
);
/*
* Initalize RTEMS IRQ system

View File

@@ -20,6 +20,7 @@
#include <bsp/bootcard.h>
#include <bsp/linker-symbols.h>
#include <rtems/bspIo.h>
#include <rtems/counter.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_counter_initialize_converter(bsp_clicks_per_usec * 1000000);
/*
* Initialize default raw exception handlers.

View File

@@ -15,6 +15,8 @@
#include <string.h>
#include <fcntl.h>
#include <rtems/counter.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_counter_initialize_converter(bsp_time_base_frequency);
/*
* Initialize the interrupt related settings.

View File

@@ -22,6 +22,7 @@
#include <rtems.h>
#include <rtems/config.h>
#include <rtems/counter.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_counter_initialize_converter(BSP_bus_frequency / 8);
/* Initialize some console parameters */
for (i = 0; i < Console_Configuration_Count; ++i) {

View File

@@ -19,6 +19,7 @@
#include <rtems/libio.h>
#include <rtems/libcsupport.h>
#include <rtems/bspIo.h>
#include <rtems/counter.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_counter_initialize_converter(bsp_clicks_per_usec * 1000000);
#if BSP_DATA_CACHE_ENABLED
#if DEBUG

View File

@@ -19,6 +19,7 @@
#include <bsp.h>
#include <rtems/bspIo.h>
#include <rtems/counter.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_counter_initialize_converter(
BSP_bus_frequency / (BSP_time_base_divisor / 1000)
);
/*
* Initalize RTEMS IRQ system

View File

@@ -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/counter.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_counter_initialize_converter(BSP_CRYSTAL_HZ / 4);
/*
* Initalize RTEMS IRQ system

View File

@@ -13,6 +13,7 @@
*/
#include <rtems/config.h>
#include <rtems/counter.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_counter_initialize_converter(bsp_time_base_frequency);
/* Initialize exception handler */
ppc_exc_initialize_with_vector_base(
PPC_INTERRUPT_DISABLE_MASK_DEFAULT,

View File

@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <rtems.h>
#include <rtems/counter.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_counter_initialize_converter(bsp_time_base_frequency);
/* Initialize exception handler */
ppc_exc_initialize(

View File

@@ -54,6 +54,8 @@
* Modifications for PPC405GP by Dennis Ehlin
*/
#include <rtems/counter.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_counter_initialize_converter(bsp_time_base_frequency);
/*
* Initialize default raw exception handlers.
*/

View File

@@ -57,6 +57,7 @@
#include <rtems.h>
#include <rtems/config.h>
#include <rtems/bspIo.h>
#include <rtems/counter.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_counter_initialize_converter(bsp_clicks_per_usec * 1000000);
/*
* Initialize the interrupt related settings.

View File

@@ -57,6 +57,7 @@
#include <rtems.h>
#include <rtems/config.h>
#include <rtems/bspIo.h>
#include <rtems/counter.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_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;

View File

@@ -0,0 +1,23 @@
/*
* Copyright (c) 2014 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
* 82178 Puchheim
* Germany
* <rtems@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_ticks _CPU_Counter_difference(
CPU_Counter_ticks second,
CPU_Counter_ticks first
)
{
return second - first;
}

View File

@@ -0,0 +1,27 @@
/*
* Copyright (c) 2014 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
* 82178 Puchheim
* Germany
* <rtems@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_ticks _CPU_Counter_read( void )
{
static CPU_Counter_ticks counter;
CPU_Counter_ticks snapshot;
snapshot = counter;
counter = snapshot + 1;
return snapshot;
}

View File

@@ -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/cpucounterread.c
# ISR Handler
libbsp_a_SOURCES += ../../sparc/shared/irq_asm.S
# gnatsupp

View File

@@ -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/cpucounterread.c
# ISR Handler
libbsp_a_SOURCES += ../../sparc/shared/irq_asm.S
# gnatsupp

View File

@@ -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

View File

@@ -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

View File

@@ -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 */

View File

@@ -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();

View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) 2014 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
* 82178 Puchheim
* Germany
* <rtems@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/counter.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_counter_initialize_converter(frequency);
}
CPU_Counter_ticks _CPU_Counter_read(void)
{
volatile struct gptimer_regs *gpt = leon3_cpu_counter_gpt;
return 0U - gpt->timer[0].value;
}