summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/sparc
diff options
context:
space:
mode:
authorAlexander Krutwig <alexander.krutwig@embedded-brains.de>2015-04-01 15:33:25 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2015-05-20 08:40:34 +0200
commit75acd9e69f906cbd880a17ee4ca705ad7caa92c0 (patch)
tree71529028154cb323286b02392def2e5277eed312 /c/src/lib/libbsp/sparc
parenttimecounter: Use in RTEMS (diff)
downloadrtems-75acd9e69f906cbd880a17ee4ca705ad7caa92c0.tar.bz2
bsps: Convert clock drivers to use a timecounter
Update #2271.
Diffstat (limited to 'c/src/lib/libbsp/sparc')
-rw-r--r--c/src/lib/libbsp/sparc/erc32/clock/ckinit.c52
-rw-r--r--c/src/lib/libbsp/sparc/leon2/clock/ckinit.c52
-rw-r--r--c/src/lib/libbsp/sparc/leon3/clock/ckinit.c97
3 files changed, 138 insertions, 63 deletions
diff --git a/c/src/lib/libbsp/sparc/erc32/clock/ckinit.c b/c/src/lib/libbsp/sparc/erc32/clock/ckinit.c
index 2afe770b4b..46f99a5e7d 100644
--- a/c/src/lib/libbsp/sparc/erc32/clock/ckinit.c
+++ b/c/src/lib/libbsp/sparc/erc32/clock/ckinit.c
@@ -25,6 +25,7 @@
#include <bsp.h>
#include <bspopts.h>
#include <rtems/counter.h>
+#include <rtems/timecounter.h>
#if SIMSPARC_FAST_IDLE==1
#define CLOCK_DRIVER_USE_FAST_IDLE 1
@@ -44,24 +45,34 @@
extern int CLOCK_SPEED;
-static uint32_t bsp_clock_nanoseconds_since_last_tick(void)
+static rtems_timecounter_simple erc32_tc;
+
+static uint32_t erc32_tc_get( rtems_timecounter_simple *tc )
+{
+ return ERC32_MEC.Real_Time_Clock_Counter;
+}
+
+static bool erc32_tc_is_pending( rtems_timecounter_simple *tc )
+{
+ return ERC32_Is_interrupt_pending( ERC32_INTERRUPT_REAL_TIME_CLOCK );
+}
+
+static uint32_t erc32_tc_get_timecount( struct timecounter *tc )
{
- uint32_t clicks;
- uint32_t usecs;
-
- clicks = ERC32_MEC.Real_Time_Clock_Counter;
-
- if ( ERC32_Is_interrupt_pending( ERC32_INTERRUPT_REAL_TIME_CLOCK ) ) {
- clicks = ERC32_MEC.Real_Time_Clock_Counter;
- usecs = (2*rtems_configuration_get_microseconds_per_tick() - clicks);
- } else {
- usecs = (rtems_configuration_get_microseconds_per_tick() - clicks);
- }
- return usecs * 1000;
+ return rtems_timecounter_simple_downcounter_get(
+ tc,
+ erc32_tc_get,
+ erc32_tc_is_pending
+ );
}
-#define Clock_driver_nanoseconds_since_last_tick \
- bsp_clock_nanoseconds_since_last_tick
+static void erc32_tc_tick( void )
+{
+ rtems_timecounter_simple_downcounter_tick(
+ &erc32_tc,
+ erc32_tc_get
+ );
+}
static CPU_Counter_ticks erc32_counter_difference(
CPU_Counter_ticks second,
@@ -75,6 +86,7 @@ static CPU_Counter_ticks erc32_counter_difference(
#define Clock_driver_support_initialize_hardware() \
do { \
+ uint32_t frequency = 1000000; \
/* approximately 1 us per countdown */ \
ERC32_MEC.Real_Time_Clock_Scalar = CLOCK_SPEED - 1; \
ERC32_MEC.Real_Time_Clock_Counter = \
@@ -89,14 +101,22 @@ static CPU_Counter_ticks erc32_counter_difference(
ERC32_MEC_Set_Real_Time_Clock_Timer_Control( \
ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING | \
ERC32_MEC_TIMER_COUNTER_RELOAD_AT_ZERO \
+ ); \
+ rtems_timecounter_simple_install( \
+ &erc32_tc, \
+ frequency, \
+ rtems_configuration_get_microseconds_per_tick(), \
+ erc32_tc_get_timecount \
); \
_SPARC_Counter_initialize( \
&ERC32_MEC.Real_Time_Clock_Counter, \
erc32_counter_difference \
); \
- rtems_counter_initialize_converter(1000000); \
+ rtems_counter_initialize_converter( frequency ); \
} while (0)
+#define Clock_driver_timecounter_tick() erc32_tc_tick()
+
#define Clock_driver_support_shutdown_hardware() \
do { \
ERC32_Mask_interrupt( ERC32_INTERRUPT_REAL_TIME_CLOCK ); \
diff --git a/c/src/lib/libbsp/sparc/leon2/clock/ckinit.c b/c/src/lib/libbsp/sparc/leon2/clock/ckinit.c
index ab4efa0e8a..3dd68e080a 100644
--- a/c/src/lib/libbsp/sparc/leon2/clock/ckinit.c
+++ b/c/src/lib/libbsp/sparc/leon2/clock/ckinit.c
@@ -24,11 +24,38 @@
#include <bsp.h>
#include <bspopts.h>
+#include <rtems/timecounter.h>
#if SIMSPARC_FAST_IDLE==1
#define CLOCK_DRIVER_USE_FAST_IDLE 1
#endif
+static rtems_timecounter_simple leon2_tc;
+
+static uint32_t leon2_tc_get( rtems_timecounter_simple *tc )
+{
+ return LEON_REG.Timer_Counter_1;
+}
+
+static bool leon2_tc_is_pending( rtems_timecounter_simple *tc )
+{
+ return LEON_Is_interrupt_pending( LEON_INTERRUPT_TIMER1 );
+}
+
+static uint32_t leon2_tc_get_timecount( struct timecounter *tc )
+{
+ return rtems_timecounter_simple_downcounter_get(
+ tc,
+ leon2_tc_get,
+ leon2_tc_is_pending
+ );
+}
+
+static void leon2_tc_tick( void )
+{
+ rtems_timecounter_simple_downcounter_tick( &leon2_tc, leon2_tc_get );
+}
+
/*
* The Real Time Clock Counter Timer uses this trap type.
*/
@@ -54,6 +81,12 @@ extern int CLOCK_SPEED;
LEON_REG_TIMER_COUNTER_RELOAD_AT_ZERO | \
LEON_REG_TIMER_COUNTER_LOAD_COUNTER \
); \
+ rtems_timecounter_simple_install( \
+ &leon2_tc, \
+ 1000000, \
+ rtems_configuration_get_microseconds_per_tick(), \
+ leon2_tc_get_timecount \
+ ); \
} while (0)
#define Clock_driver_support_shutdown_hardware() \
@@ -62,23 +95,6 @@ extern int CLOCK_SPEED;
LEON_REG.Timer_Control_1 = 0; \
} while (0)
-static uint32_t bsp_clock_nanoseconds_since_last_tick(void)
-{
- uint32_t clicks;
- uint32_t usecs;
-
- clicks = LEON_REG.Timer_Counter_1;
-
- if ( LEON_Is_interrupt_pending( LEON_INTERRUPT_TIMER1 ) ) {
- clicks = LEON_REG.Timer_Counter_1;
- usecs = (2*rtems_configuration_get_microseconds_per_tick() - clicks);
- } else {
- usecs = (rtems_configuration_get_microseconds_per_tick() - clicks);
- }
- return usecs * 1000;
-}
-
-#define Clock_driver_nanoseconds_since_last_tick \
- bsp_clock_nanoseconds_since_last_tick
+#define Clock_driver_timecounter_tick() leon2_tc_tick()
#include "../../../shared/clockdrv_shell.h"
diff --git a/c/src/lib/libbsp/sparc/leon3/clock/ckinit.c b/c/src/lib/libbsp/sparc/leon3/clock/ckinit.c
index ad226161bc..b82b457866 100644
--- a/c/src/lib/libbsp/sparc/leon3/clock/ckinit.c
+++ b/c/src/lib/libbsp/sparc/leon3/clock/ckinit.c
@@ -24,6 +24,7 @@
#include <rtems/rtems/intr.h>
#include <ambapp.h>
#include <rtems/score/profiling.h>
+#include <rtems/timecounter.h>
/* The LEON3 BSP Timer driver can rely on the Driver Manager if the
* DrvMgr is initialized during startup. Otherwise the classic driver
@@ -40,6 +41,43 @@
/* LEON3 Timer system interrupt number */
static int clkirq;
+static bool leon3_tc_use_irqmp;
+
+static rtems_timecounter_simple leon3_tc;
+
+static uint32_t leon3_tc_get(rtems_timecounter_simple *tc)
+{
+ return LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value;
+}
+
+static bool leon3_tc_is_pending(rtems_timecounter_simple *tc)
+{
+ return LEON_Is_interrupt_pending(clkirq);
+}
+
+static uint32_t leon3_tc_get_timecount(struct timecounter *tc)
+{
+ return rtems_timecounter_simple_downcounter_get(
+ tc,
+ leon3_tc_get,
+ leon3_tc_is_pending
+ );
+}
+
+static uint32_t leon3_tc_get_timecount_irqmp(struct timecounter *tc)
+{
+ return LEON3_IrqCtrl_Regs->timestamp[0].counter;
+}
+
+static void leon3_tc_tick(void)
+{
+ if (leon3_tc_use_irqmp) {
+ rtems_timecounter_tick();
+ } else {
+ rtems_timecounter_simple_downcounter_tick(&leon3_tc, leon3_tc_get);
+ }
+}
+
static void leon3_clock_profiling_interrupt_delay(void)
{
#ifdef RTEMS_PROFILING
@@ -112,15 +150,36 @@ static void bsp_clock_handler_install(rtems_isr *new)
}
}
+static void leon3_clock_initialize(void)
+{
+ volatile struct irqmp_timestamp_regs *irqmp_ts =
+ &LEON3_IrqCtrl_Regs->timestamp[0];
+
+ LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].reload =
+ rtems_configuration_get_microseconds_per_tick() - 1;
+ LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].ctrl =
+ GPTIMER_TIMER_CTRL_EN | GPTIMER_TIMER_CTRL_RS |
+ GPTIMER_TIMER_CTRL_LD | GPTIMER_TIMER_CTRL_IE;
+
+ if (leon3_irqmp_has_timestamp(irqmp_ts)) {
+ leon3_tc.tc.tc_get_timecount = leon3_tc_get_timecount_irqmp;
+ leon3_tc.tc.tc_counter_mask = 0xffffffff;
+ leon3_tc.tc.tc_frequency = ambapp_freq_get(&ambapp_plb, LEON3_Timer_Adev);
+ leon3_tc.tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
+ leon3_tc_use_irqmp = true;
+ rtems_timecounter_install(&leon3_tc.tc);
+ } else {
+ rtems_timecounter_simple_install(
+ &leon3_tc,
+ LEON3_GPTIMER_0_FREQUENCY_SET_BY_BOOT_LOADER,
+ rtems_configuration_get_microseconds_per_tick(),
+ leon3_tc_get_timecount
+ );
+ }
+}
+
#define Clock_driver_support_initialize_hardware() \
- do { \
- LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].reload = \
- rtems_configuration_get_microseconds_per_tick() - 1; \
- \
- LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].ctrl = \
- GPTIMER_TIMER_CTRL_EN | GPTIMER_TIMER_CTRL_RS | \
- GPTIMER_TIMER_CTRL_LD | GPTIMER_TIMER_CTRL_IE; \
- } while (0)
+ leon3_clock_initialize()
#define Clock_driver_support_shutdown_hardware() \
do { \
@@ -128,27 +187,7 @@ static void bsp_clock_handler_install(rtems_isr *new)
LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].ctrl = 0; \
} while (0)
-static uint32_t bsp_clock_nanoseconds_since_last_tick(void)
-{
- uint32_t clicks;
- uint32_t usecs;
-
- if ( !LEON3_Timer_Regs )
- return 0;
-
- clicks = LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value;
-
- if ( LEON_Is_interrupt_pending( clkirq ) ) {
- clicks = LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value;
- usecs = (2*rtems_configuration_get_microseconds_per_tick() - clicks);
- } else {
- usecs = (rtems_configuration_get_microseconds_per_tick() - clicks);
- }
- return usecs * 1000;
-}
-
-#define Clock_driver_nanoseconds_since_last_tick \
- bsp_clock_nanoseconds_since_last_tick
+#define Clock_driver_timecounter_tick() leon3_tc_tick()
#include "../../../shared/clockdrv_shell.h"