summaryrefslogtreecommitdiffstats
path: root/bsps/arm/include
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-05-22 08:52:13 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-06-15 13:12:05 +0200
commit762fa62ccaebadb7fa486da634c27b02960112b1 (patch)
treeeb762741aa291dd46578667e1533a71dcfc955b3 /bsps/arm/include
parentAdd _CPU_Counter_frequency() (diff)
downloadrtems-762fa62ccaebadb7fa486da634c27b02960112b1.tar.bz2
arm: Simplify CPU counter support
Use the standard ARMv7-M systick module for the ARMv7-M CPU counter instead of DWT counter since the DWT counter is affected by power saving states. Use an inline function for _CPU_Counter_difference() for all ARM BSPs. Update #3456.
Diffstat (limited to 'bsps/arm/include')
-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 */