summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/sparc/erc32/clock/ckinit.c
diff options
context:
space:
mode:
Diffstat (limited to 'c/src/lib/libbsp/sparc/erc32/clock/ckinit.c')
-rw-r--r--c/src/lib/libbsp/sparc/erc32/clock/ckinit.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/sparc/erc32/clock/ckinit.c b/c/src/lib/libbsp/sparc/erc32/clock/ckinit.c
index 1287645064..111a63d2ca 100644
--- a/c/src/lib/libbsp/sparc/erc32/clock/ckinit.c
+++ b/c/src/lib/libbsp/sparc/erc32/clock/ckinit.c
@@ -24,6 +24,7 @@
#include <bsp.h>
#include <bspopts.h>
+#include <rtems/counter.h>
#if SIMSPARC_FAST_IDLE==1
#define CLOCK_DRIVER_USE_FAST_IDLE 1
@@ -63,6 +64,16 @@ uint32_t bsp_clock_nanoseconds_since_last_tick(void)
#define Clock_driver_nanoseconds_since_last_tick \
bsp_clock_nanoseconds_since_last_tick
+static CPU_Counter_ticks erc32_counter_difference(
+ CPU_Counter_ticks second,
+ CPU_Counter_ticks first
+)
+{
+ CPU_Counter_ticks period = rtems_configuration_get_microseconds_per_tick();
+
+ return (first + period - second) % period;
+}
+
#define Clock_driver_support_initialize_hardware() \
do { \
/* approximately 1 us per countdown */ \
@@ -80,6 +91,11 @@ uint32_t bsp_clock_nanoseconds_since_last_tick(void)
ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING | \
ERC32_MEC_TIMER_COUNTER_RELOAD_AT_ZERO \
); \
+ _SPARC_Counter_initialize( \
+ &ERC32_MEC.Real_Time_Clock_Counter, \
+ erc32_counter_difference \
+ ); \
+ rtems_counter_initialize_converter(1000000); \
} while (0)
#define Clock_driver_support_shutdown_hardware() \