1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 14:33:52 +01:00

Merge pull request #16344 from kfessel/p-efm32-rtt-freq

cpu/efm32: add RTT_FREQUENCY support to efm32
This commit is contained in:
Francisco 2021-04-21 09:59:10 +02:00 committed by GitHub
commit d5f9b99555
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 128 additions and 25 deletions

View File

@ -106,8 +106,9 @@ static const i2c_conf_t i2c_config[] = {
* @name RTT configuration
* @{
*/
#define RTT_MAX_VALUE (0xFFFFFFFF)
#define RTT_FREQUENCY (1U)
#ifndef RTT_FREQUENCY
#define RTT_FREQUENCY (1U) /* in Hz */
#endif
/** @} */
/**

View File

@ -84,8 +84,9 @@ static const adc_chan_conf_t adc_channel_config[] = {
* @name RTT configuration
* @{
*/
#define RTT_MAX_VALUE (0xFFFFFFFF)
#define RTT_FREQUENCY (1U)
#ifndef RTT_FREQUENCY
#define RTT_FREQUENCY (1U) /* in Hz */
#endif
/** @} */
/**

View File

@ -82,8 +82,9 @@ static const adc_chan_conf_t adc_channel_config[] = {
* @name RTT configuration
* @{
*/
#define RTT_MAX_VALUE (0xFFFFFFFF)
#define RTT_FREQUENCY (1U)
#ifndef RTT_FREQUENCY
#define RTT_FREQUENCY (1U) /* in Hz */
#endif
/** @} */
/**

View File

@ -101,8 +101,9 @@ static const i2c_conf_t i2c_config[] = {
* @name RTT configuration
* @{
*/
#define RTT_MAX_VALUE (0xFFFFFF)
#define RTT_FREQUENCY (1U)
#ifndef RTT_FREQUENCY
#define RTT_FREQUENCY (1U) /* in Hz */
#endif
/** @} */
/**

View File

@ -113,8 +113,9 @@ static const i2c_conf_t i2c_config[] = {
* @name RTT configuration
* @{
*/
#define RTT_MAX_VALUE (0xFFFFFFFF)
#define RTT_FREQUENCY (1U)
#ifndef RTT_FREQUENCY
#define RTT_FREQUENCY (1U) /* in Hz */
#endif
/** @} */
/**

View File

@ -104,8 +104,9 @@ static const i2c_conf_t i2c_config[] = {
* @name RTT configuration
* @{
*/
#define RTT_MAX_VALUE (0xFFFFFFFF)
#define RTT_FREQUENCY (1U)
#ifndef RTT_FREQUENCY
#define RTT_FREQUENCY (1U) /* in Hz */
#endif
/** @} */
/**

View File

@ -113,8 +113,9 @@ static const i2c_conf_t i2c_config[] = {
* @name RTT configuration
* @{
*/
#define RTT_MAX_VALUE (0xFFFFFFFF)
#define RTT_FREQUENCY (1U)
#ifndef RTT_FREQUENCY
#define RTT_FREQUENCY (1U) /* in Hz */
#endif
/** @} */
/**

View File

@ -154,8 +154,9 @@ static const pwm_conf_t pwm_config[] = {
* @name RTT configuration
* @{
*/
#define RTT_MAX_VALUE (0xFFFFFF)
#define RTT_FREQUENCY (1U)
#ifndef RTT_FREQUENCY
#define RTT_FREQUENCY (1U) /* in Hz */
#endif
/** @} */
/**

View File

@ -100,8 +100,9 @@ static const i2c_conf_t i2c_config[] = {
* @name RTT configuration
* @{
*/
#define RTT_MAX_VALUE (0xFFFFFF)
#define RTT_FREQUENCY (1U)
#ifndef RTT_FREQUENCY
#define RTT_FREQUENCY (1U) /* in Hz */
#endif
/** @} */
/**

View File

@ -159,8 +159,9 @@ static const pwm_conf_t pwm_config[] = {
* @name RTT configuration
* @{
*/
#define RTT_MAX_VALUE (0xFFFFFF)
#define RTT_FREQUENCY (1U)
#ifndef RTT_FREQUENCY
#define RTT_FREQUENCY (1U) /* in Hz */
#endif
/** @} */
/**

View File

@ -159,8 +159,9 @@ static const pwm_conf_t pwm_config[] = {
* @name RTT configuration
* @{
*/
#define RTT_MAX_VALUE (0xFFFFFF)
#define RTT_FREQUENCY (1U)
#ifndef RTT_FREQUENCY
#define RTT_FREQUENCY (1U) /* in Hz */
#endif
/** @} */
/**

View File

@ -32,6 +32,7 @@
#include "em_timer.h"
#include "em_usart.h"
#include "em_wdog.h"
#include "em_rtc.h"
#if defined(_SILICON_LABS_32B_SERIES_0)
#include "em_dac.h"
#endif
@ -119,6 +120,23 @@ typedef struct {
} dac_chan_conf_t;
#endif
/**
* @name Real time counter configuration
* @{
*/
/* RTT_MAX_VALUE some are 24bit, some are 32bit */
#ifdef _RTC_CNT_MASK
#define RTT_MAX_VALUE _RTC_CNT_MASK /* mask has all bits set ==> MAX*/
#endif
#ifdef _RTCC_CNT_MASK
#define RTT_MAX_VALUE _RTCC_CNT_MASK /* mask has all bits set ==> MAX*/
#endif
#define RTT_MAX_FREQUENCY (32768U) /* in Hz */
#define RTT_MIN_FREQUENCY (1U) /* in Hz */
#define RTT_CLOCK_FREQUENCY (32768U) /* in Hz, LFCLK*/
/** @} */
/**
* @brief Define a custom type for GPIO pins.
* @{

View File

@ -34,10 +34,47 @@ typedef struct {
static rtt_state_t rtt_state;
/* prescaler of 32768 = 1 s of resolution and overflow each 194 days */
#if RTT_FREQUENCY == 1
#define RTT_CMU_CLK_DIV cmuClkDiv_32768
#elif RTT_FREQUENCY == 2
#define RTT_CMU_CLK_DIV cmuClkDiv_16384
#elif RTT_FREQUENCY == 4
#define RTT_CMU_CLK_DIV cmuClkDiv_8192
#elif RTT_FREQUENCY == 8
#define RTT_CMU_CLK_DIV cmuClkDiv_4096
#elif RTT_FREQUENCY == 16
#define RTT_CMU_CLK_DIV cmuClkDiv_2048
#elif RTT_FREQUENCY == 32
#define RTT_CMU_CLK_DIV cmuClkDiv_1024
#elif RTT_FREQUENCY == 64
#define RTT_CMU_CLK_DIV cmuClkDiv_512
#elif RTT_FREQUENCY == 128
#define RTT_CMU_CLK_DIV cmuClkDiv_256
#elif RTT_FREQUENCY == 256
#define RTT_CMU_CLK_DIV cmuClkDiv_128
#elif RTT_FREQUENCY == 512
#define RTT_CMU_CLK_DIV cmuClkDiv_64
#elif RTT_FREQUENCY == 1024
#define RTT_CMU_CLK_DIV cmuClkDiv_32
#elif RTT_FREQUENCY == 2048
#define RTT_CMU_CLK_DIV cmuClkDiv_16
#elif RTT_FREQUENCY == 4096
#define RTT_CMU_CLK_DIV cmuClkDiv_8
#elif RTT_FREQUENCY == 8192
#define RTT_CMU_CLK_DIV cmuClkDiv_4
#elif RTT_FREQUENCY == 16384
#define RTT_CMU_CLK_DIV cmuClkDiv_2
#elif RTT_FREQUENCY == 32768
#define RTT_CMU_CLK_DIV cmuClkDiv_1
#else
#warning "no matching prescaler for RTT_FREQUENCY"
#endif
void rtt_init(void)
{
/* prescaler of 32768 = 1 s of resolution and overflow each 194 days */
CMU_ClockDivSet(cmuClock_RTC, cmuClkDiv_32768);
/* setup prescaler */
CMU_ClockDivSet(cmuClock_RTC, RTT_CMU_CLK_DIV);
/* enable clocks */
CMU_ClockEnable(cmuClock_CORELE, true);

View File

@ -35,6 +35,43 @@ typedef struct {
static rtt_state_t rtt_state;
/* prescaler of 32768 = 1 s of resolution and overflow each 194 days */
#if RTT_FREQUENCY == 1
#define RTT_CMU_CLK_DIV rtccCntPresc_32768
#elif RTT_FREQUENCY == 2
#define RTT_CMU_CLK_DIV rtccCntPresc_16384
#elif RTT_FREQUENCY == 4
#define RTT_CMU_CLK_DIV rtccCntPresc_8192
#elif RTT_FREQUENCY == 8
#define RTT_CMU_CLK_DIV rtccCntPresc_4096
#elif RTT_FREQUENCY == 16
#define RTT_CMU_CLK_DIV rtccCntPresc_2048
#elif RTT_FREQUENCY == 32
#define RTT_CMU_CLK_DIV rtccCntPresc_1024
#elif RTT_FREQUENCY == 64
#define RTT_CMU_CLK_DIV rtccCntPresc_512
#elif RTT_FREQUENCY == 128
#define RTT_CMU_CLK_DIV rtccCntPresc_256
#elif RTT_FREQUENCY == 256
#define RTT_CMU_CLK_DIV rtccCntPresc_128
#elif RTT_FREQUENCY == 512
#define RTT_CMU_CLK_DIV rtccCntPresc_64
#elif RTT_FREQUENCY == 1024
#define RTT_CMU_CLK_DIV rtccCntPresc_32
#elif RTT_FREQUENCY == 2048
#define RTT_CMU_CLK_DIV rtccCntPresc_16
#elif RTT_FREQUENCY == 4096
#define RTT_CMU_CLK_DIV rtccCntPresc_8
#elif RTT_FREQUENCY == 8192
#define RTT_CMU_CLK_DIV rtccCntPresc_4
#elif RTT_FREQUENCY == 16384
#define RTT_CMU_CLK_DIV rtccCntPresc_2
#elif RTT_FREQUENCY == 32768
#define RTT_CMU_CLK_DIV rtccCntPresc_1
#else
#warning "no matching prescaler for RTT_FREQUENCY"
#endif
void rtt_init(void)
{
/* enable clocks */
@ -45,7 +82,7 @@ void rtt_init(void)
RTCC_Init_TypeDef init = RTCC_INIT_DEFAULT;
init.enable = false;
init.presc = rtccCntPresc_32768;
init.presc = RTT_CMU_CLK_DIV;
RTCC_Reset();
RTCC_Init(&init);