summaryrefslogtreecommitdiffstats
path: root/bsps/arm/include/bsp/clock-armv7m.h
diff options
context:
space:
mode:
Diffstat (limited to 'bsps/arm/include/bsp/clock-armv7m.h')
-rw-r--r--bsps/arm/include/bsp/clock-armv7m.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/bsps/arm/include/bsp/clock-armv7m.h b/bsps/arm/include/bsp/clock-armv7m.h
new file mode 100644
index 0000000000..d635fb0c1b
--- /dev/null
+++ b/bsps/arm/include/bsp/clock-armv7m.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2011, 2018 Sebastian Huber. 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.org/license/LICENSE.
+ */
+
+#ifndef BSP_CLOCK_ARMV7M_H
+#define BSP_CLOCK_ARMV7M_H
+
+#include <rtems/score/armv7m.h>
+#include <rtems/timecounter.h>
+
+#include <bsp.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#ifdef ARM_MULTILIB_ARCH_V7M
+
+typedef struct {
+ struct timecounter base;
+ uint32_t ticks;
+} ARMV7M_Timecounter;
+
+extern ARMV7M_Timecounter _ARMV7M_TC;
+
+static inline uint32_t _ARMV7M_Clock_frequency(void)
+{
+#ifdef BSP_ARMV7M_SYSTICK_FREQUENCY
+ return BSP_ARMV7M_SYSTICK_FREQUENCY;
+#else
+ volatile ARMV7M_Systick *systick = _ARMV7M_Systick;
+ return ARMV7M_SYSTICK_CALIB_TENMS_GET(systick->calib) * 100;
+#endif
+}
+
+static uint32_t _ARMV7M_Clock_counter(ARMV7M_Timecounter *tc)
+{
+ volatile ARMV7M_Systick *systick;
+ rtems_interrupt_level level;
+ uint32_t interval;
+ uint32_t counter;
+ uint32_t ticks;
+
+ systick = _ARMV7M_Systick;
+ interval = systick->rvr;
+
+ rtems_interrupt_disable(level);
+ counter = systick->cvr;
+ ticks = tc->ticks;
+
+ if ((systick->csr & ARMV7M_SYSTICK_CSR_COUNTFLAG) != 0) {
+ ticks += interval;
+ tc->ticks = ticks;
+ }
+
+ counter = interval - counter + ticks;
+ rtems_interrupt_enable(level);
+
+ return counter;
+}
+
+#endif /* ARM_MULTILIB_ARCH_V7M */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* BSP_CLOCK_ARMV7M_H */