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>
This commit is contained in:
Daniel Leung 2016-02-09 13:41:22 -08:00 committed by Gerrit Code Review
commit e20c79c154

View file

@ -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 */