summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorDaniel Leung <daniel.leung@intel.com>2016-02-09 13:41:22 -0800
committerGerrit Code Review <gerrit@zephyrproject.org>2016-02-10 01:35:33 +0000
commite20c79c154b7d5064a393f5d9c3f24f239faa24a (patch)
tree7924533234ecd72bc6f601f4ca310097ec3bb5e0 /samples
parent3c66686a43ffa78932aaa6b1e2338c2f3d347a13 (diff)
samples: test_tickless: enable test for Atmel SAM3
This adds the necessary functions to enable the tickless idle test for Atmel SAM3 family processor. Change-Id: I19e2a8c898dbbc687c980d06bb6c19de693b97a4 Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Diffstat (limited to 'samples')
-rw-r--r--samples/microkernel/test/test_tickless/src/timestamps.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/samples/microkernel/test/test_tickless/src/timestamps.c b/samples/microkernel/test/test_tickless/src/timestamps.c
index 2209abe04..7d3ccf1f3 100644
--- a/samples/microkernel/test/test_tickless/src/timestamps.c
+++ b/samples/microkernel/test/test_tickless/src/timestamps.c
@@ -245,6 +245,73 @@ void _TimestampClose(void)
_TIMESTAMP_CTRL = 0x0; /* disable oscillator */
}
+#elif defined(CONFIG_SOC_ATMEL_SAM3)
+/* Atmel SAM3 family processor - use RTT (Real-time Timer) */
+
+#include <soc.h>
+
+#define _TIMESTAMP_ADDR (0x400E1A30)
+
+#define _TIMESTAMP_MODE (*((volatile uint32_t *)(_TIMESTAMP_ADDR + 0x00)))
+#define _TIMESTAMP_VAL (*((volatile uint32_t *)(_TIMESTAMP_ADDR + 0x08)))
+
+/**
+ *
+ * @brief Timestamp initialization
+ *
+ * This routine initializes the timestamp timer.
+ *
+ * @return N/A
+ */
+void _TimestampOpen(void)
+{
+ /* enable RTT clock from PMC */
+ __PMC->pcer0 = (1 << PID_RTT);
+
+ /* Reset RTT and set prescaler to 1 */
+ _TIMESTAMP_MODE = (1 << 18) | (1 << 0);
+}
+
+/**
+ *
+ * @brief Timestamp timer read
+ *
+ * This routine returns the timestamp value.
+ *
+ * @return timestamp value
+ */
+uint32_t _TimestampRead(void)
+{
+ static uint32_t last_val;
+ uint32_t tmr_val = _TIMESTAMP_VAL;
+ uint32_t ticks;
+
+ /* handle rollover */
+ if (tmr_val < last_val) {
+ ticks = ((0xFFFFFFFF - last_val)) + 1 + tmr_val;
+ } else {
+ ticks = tmr_val - last_val;
+ }
+
+ last_val = tmr_val;
+
+ return ticks;
+}
+
+/**
+ *
+ * @brief Timestamp release
+ *
+ * This routine releases the timestamp timer.
+ *
+ * @return N/A
+ */
+void _TimestampClose(void)
+{
+ /* disable RTT clock from PMC */
+ __PMC->pcdr0 = (1 << PID_RTT);
+}
+
#else
#error "Unknown platform"
#endif /* CONFIG_SOC_xxx */