mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 05:32:45 +01:00
cpu/fe310: add unified rtt configuration
This commit is contained in:
parent
2fb7d84ae5
commit
442b11d0ee
@ -168,17 +168,6 @@ static const spi_conf_t spi_config[] = {
|
||||
#define SPI_NUMOF ARRAY_SIZE(spi_config)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name RTT/RTC configuration
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define RTT_FREQUENCY (1) /* in Hz */
|
||||
#define RTT_MAX_VALUE (0xFFFFFFFF)
|
||||
#define RTT_INTR_PRIORITY (2)
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name PWM configuration
|
||||
*
|
||||
|
@ -169,17 +169,6 @@ static const spi_conf_t spi_config[] = {
|
||||
#define SPI_NUMOF ARRAY_SIZE(spi_config)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name RTT/RTC configuration
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define RTT_FREQUENCY (1) /* in Hz */
|
||||
#define RTT_MAX_VALUE (0xFFFFFFFF)
|
||||
#define RTT_INTR_PRIORITY (2)
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name PWM configuration
|
||||
*
|
||||
|
@ -160,6 +160,25 @@ typedef struct {
|
||||
*/
|
||||
#define WDT_HAS_STOP (1)
|
||||
|
||||
/**
|
||||
* @name RTT/RTC configuration
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define RTT_INTR_PRIORITY (2)
|
||||
|
||||
#define RTT_MAX_VALUE (0xffffffff)
|
||||
#define RTT_CLOCK_FREQUENCY (32768U) /* in Hz */
|
||||
#define RTT_MAX_FREQUENCY (RTT_CLOCK_FREQUENCY) /* in Hz */
|
||||
#define RTT_MIN_FREQUENCY (1U) /* in Hz */
|
||||
|
||||
#ifndef RTT_FREQUENCY
|
||||
#define RTT_FREQUENCY (RTT_MAX_FREQUENCY) /* in Hz */
|
||||
#endif
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -37,41 +37,12 @@
|
||||
#include "debug.h"
|
||||
|
||||
/* Convert RTT freq to pre-scaler value */
|
||||
#if (RTT_FREQUENCY == 32768)
|
||||
#define RTT_SCALE (0)
|
||||
#elif (RTT_FREQUENCY == 16384)
|
||||
#define RTT_SCALE (1)
|
||||
#elif (RTT_FREQUENCY == 8192)
|
||||
#define RTT_SCALE (2)
|
||||
#elif (RTT_FREQUENCY == 4096)
|
||||
#define RTT_SCALE (3)
|
||||
#elif (RTT_FREQUENCY == 2048)
|
||||
#define RTT_SCALE (4)
|
||||
#elif (RTT_FREQUENCY == 1024)
|
||||
#define RTT_SCALE (5)
|
||||
#elif (RTT_FREQUENCY == 512)
|
||||
#define RTT_SCALE (6)
|
||||
#elif (RTT_FREQUENCY == 256)
|
||||
#define RTT_SCALE (7)
|
||||
#elif (RTT_FREQUENCY == 128)
|
||||
#define RTT_SCALE (8)
|
||||
#elif (RTT_FREQUENCY == 64)
|
||||
#define RTT_SCALE (9)
|
||||
#elif (RTT_FREQUENCY == 32)
|
||||
#define RTT_SCALE (10)
|
||||
#elif (RTT_FREQUENCY == 16)
|
||||
#define RTT_SCALE (11)
|
||||
#elif (RTT_FREQUENCY == 8)
|
||||
#define RTT_SCALE (12)
|
||||
#elif (RTT_FREQUENCY == 4)
|
||||
#define RTT_SCALE (13)
|
||||
#elif (RTT_FREQUENCY == 2)
|
||||
#define RTT_SCALE (14)
|
||||
#elif (RTT_FREQUENCY == 1)
|
||||
#define RTT_SCALE (15)
|
||||
#else
|
||||
#ifdef RTT_FREQUENCY
|
||||
#if ((RTT_CLOCK_FREQUENCY % RTT_FREQUENCY) != 0)
|
||||
#error "Invalid RTT_FREQUENCY: Must be power of 2"
|
||||
#endif
|
||||
#endif
|
||||
#define RTT_SCALE __builtin_ctz(RTT_CLOCK_FREQUENCY / RTT_FREQUENCY)
|
||||
|
||||
typedef struct {
|
||||
uint32_t alarm_val; /**< cached alarm val */
|
||||
@ -161,8 +132,14 @@ void rtt_set_counter(uint32_t counter)
|
||||
* Must program HI/LO regs
|
||||
* Write scaled counter reg value
|
||||
*/
|
||||
AON_REG(AON_RTCLO) = counter << RTT_SCALE;
|
||||
AON_REG(AON_RTCHI) = counter >> (32 - RTT_SCALE);
|
||||
/* Use ifdef to avoid out of bound shift when RTT_SCALE == 0 */
|
||||
#if RTT_CLOCK_FREQUENCY == RTT_FREQUENCY
|
||||
AON_REG(AON_RTCLO) = counter;
|
||||
AON_REG(AON_RTCHI) = 0;
|
||||
#else
|
||||
AON_REG(AON_RTCLO) = counter << RTT_SCALE;
|
||||
AON_REG(AON_RTCHI) = counter >> (32 - RTT_SCALE);
|
||||
#endif
|
||||
}
|
||||
|
||||
void rtt_set_alarm(uint32_t alarm, rtt_cb_t cb, void *arg)
|
||||
|
Loading…
Reference in New Issue
Block a user