summaryrefslogtreecommitdiff
path: root/c/src/lib/libbsp/arm/xm-tms570/clock/clock.c
diff options
context:
space:
mode:
Diffstat (limited to 'c/src/lib/libbsp/arm/xm-tms570/clock/clock.c')
-rw-r--r--c/src/lib/libbsp/arm/xm-tms570/clock/clock.c113
1 files changed, 113 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/arm/xm-tms570/clock/clock.c b/c/src/lib/libbsp/arm/xm-tms570/clock/clock.c
new file mode 100644
index 0000000000..379376b09d
--- /dev/null
+++ b/c/src/lib/libbsp/arm/xm-tms570/clock/clock.c
@@ -0,0 +1,113 @@
+/*
+ * @file clock.c
+ *
+ * @author Miguel Masmano <mmasmano@fentiss.com>
+ *
+ * @copyright
+ * Copyright 2016 Fent Innovative Software Solutions (FENTISS).
+ * All rights reserved.
+ *
+ * Copyright 2017 embedded brains GmbH.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#include <rtems/timecounter.h>
+
+#include <bsp.h>
+#include <bsp/irq.h>
+#include <bsp/fatal.h>
+#include <xm.h>
+
+static struct timecounter xm_tms570_tc;
+
+static uint32_t xm_tms570_clock_last;
+
+static uint32_t xm_tms570_clock_get_time(void)
+{
+ xmTime_t now;
+ XM_get_time(XM_HW_CLOCK, &now);
+ return (uint32_t) now;
+}
+
+static uint32_t xm_tms570_clock_get_timecount(struct timecounter *tc)
+{
+ (void) tc;
+ return xm_tms570_clock_get_time();
+}
+
+static void xm_tms570_clock_initialize_hardware(void)
+{
+ xmTime_t now;
+ uint32_t us_per_tick;
+
+ XM_get_time(XM_HW_CLOCK, &now);
+ us_per_tick = rtems_configuration_get_microseconds_per_tick();
+ XM_set_timer(XM_HW_CLOCK, now + us_per_tick, us_per_tick);
+ xm_tms570_clock_last = (uint32_t) now;
+
+ xm_tms570_tc.tc_get_timecount = xm_tms570_clock_get_timecount;
+ xm_tms570_tc.tc_counter_mask = 0xffffffff;
+ xm_tms570_tc.tc_frequency = 1000000;
+ xm_tms570_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
+ rtems_timecounter_install(&xm_tms570_tc);
+}
+
+static void xm_tms570_clock_timecounter_tick(void)
+{
+ uint32_t us_per_tick;
+ uint32_t now;
+ uint32_t last;
+
+ now = xm_tms570_clock_get_time();
+ us_per_tick = rtems_configuration_get_microseconds_per_tick();
+ last = xm_tms570_clock_last;
+
+ while ((now - last) >= us_per_tick) {
+ rtems_timecounter_tick();
+ last += us_per_tick;
+ }
+
+ xm_tms570_clock_last = last;
+}
+
+static void xm_tms570_clock_shutdown_hardware(void)
+{
+ XM_set_irqmask(0, 1U << XM_VT_EXT_HW_TIMER);
+ XM_set_timer(XM_HW_CLOCK, 0, 0);
+}
+
+static void xm_tms570_clock_install_isr(rtems_interrupt_handler handler)
+{
+ rtems_status_code sc;
+
+ sc = rtems_interrupt_handler_install(
+ XM_TMS570_IRQ_HWTIMER,
+ "Clock",
+ RTEMS_INTERRUPT_UNIQUE,
+ handler,
+ NULL
+ );
+ if (sc != RTEMS_SUCCESSFUL) {
+ bsp_fatal(XM_BSP_FATAL_TMS570_CLOCK_IRQ_INSTALL);
+ }
+}
+
+#define Clock_driver_support_initialize_hardware \
+ xm_tms570_clock_initialize_hardware
+
+#define Clock_driver_timecounter_tick() \
+ xm_tms570_clock_timecounter_tick()
+
+#define Clock_driver_support_initialize_hardware \
+ xm_tms570_clock_initialize_hardware
+
+#define Clock_driver_support_shutdown_hardware \
+ xm_tms570_clock_shutdown_hardware
+
+#define Clock_driver_support_install_isr(clock_isr, old_isr) \
+ xm_tms570_clock_install_isr(clock_isr)
+
+#include "../../../shared/clockdrv_shell.h"