From e20c79c154b7d5064a393f5d9c3f24f239faa24a Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Tue, 9 Feb 2016 13:41:22 -0800 Subject: 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 --- .../test/test_tickless/src/timestamps.c | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'samples') 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 + +#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 */ -- cgit v1.2.3