1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

boards: efm32 boards: add support for LETIMER

This commit is contained in:
Thomas Stilwell 2020-01-30 01:59:06 -06:00
parent 37a6cc66f5
commit 754d790b3f
14 changed files with 176 additions and 45 deletions

View File

@ -31,10 +31,14 @@ extern "C" {
/**
* @name Xtimer configuration
*
* The timer runs at 250 KHz to increase accuracy.
* The timer runs at 250 kHz to increase accuracy or 32768 Hz for LETIMER.
* @{
*/
#ifdef EFM32_USE_LETIMER
#define XTIMER_HZ (32768UL)
#else
#define XTIMER_HZ (250000UL)
#endif
#define XTIMER_WIDTH (16)
/** @} */

View File

@ -48,7 +48,6 @@ extern "C" {
#endif
/** @} */
/**
* @name RTT configuration
* @{
@ -82,25 +81,41 @@ static const spi_dev_t spi_config[] = {
/**
* @name Timer configuration
*
* The implementation uses two timers in cascade mode.
* The implementation can use one low-energy timer
* or two regular timers in cascade mode.
* @{
*/
#if EFM32_USE_LETIMER
static const timer_conf_t timer_config[] = {
{
{
.timer = {
.dev = LETIMER0,
.cmu = cmuClock_LETIMER0
},
.irq = LETIMER0_IRQn
}
};
#define TIMER_0_ISR isr_letimer0
#else
static const timer_conf_t timer_config[] = {
{
.prescaler = {
.dev = TIMER0,
.cmu = cmuClock_TIMER0
},
{
.timer = {
.dev = TIMER1,
.cmu = cmuClock_TIMER1
},
.irq = TIMER1_IRQn
}
};
#define TIMER_0_ISR isr_timer1
#endif /* EFM32_USE_LETIMER */
#define TIMER_NUMOF ARRAY_SIZE(timer_config)
#define TIMER_0_ISR isr_timer1
/** @} */
/**

View File

@ -32,10 +32,14 @@ extern "C" {
/**
* @name Xtimer configuration
*
* The timer runs at 250 KHz to increase accuracy.
* The timer runs at 250 KHz to increase accuracy or 32768 Hz for LETIMER.
* @{
*/
#ifdef EFM32_USE_LETIMER
#define XTIMER_HZ (32768UL)
#else
#define XTIMER_HZ (250000UL)
#endif
#define XTIMER_WIDTH (16)
/** @} */

View File

@ -141,25 +141,41 @@ static const spi_dev_t spi_config[] = {
/**
* @name Timer configuration
*
* The implementation uses two timers in cascade mode.
* The implementation can use one low-energy timer
* or two regular timers in cascade mode.
* @{
*/
#if EFM32_USE_LETIMER
static const timer_conf_t timer_config[] = {
{
{
.timer = {
.dev = LETIMER0,
.cmu = cmuClock_LETIMER0
},
.irq = LETIMER0_IRQn
}
};
#define TIMER_0_ISR isr_letimer0
#else
static const timer_conf_t timer_config[] = {
{
.prescaler = {
.dev = TIMER0,
.cmu = cmuClock_TIMER0
},
{
.timer = {
.dev = TIMER1,
.cmu = cmuClock_TIMER1
},
.irq = TIMER1_IRQn
}
};
#define TIMER_0_ISR isr_timer1
#endif /* EFM32_USE_LETIMER */
#define TIMER_NUMOF ARRAY_SIZE(timer_config)
#define TIMER_0_ISR isr_timer1
/** @} */
/**

View File

@ -33,8 +33,13 @@ extern "C" {
* @name Xtimer configuration
* @{
*/
#ifdef EFM32_USE_LETIMER
#define XTIMER_HZ (32768UL)
#define XTIMER_WIDTH (16)
#else
#define XTIMER_HZ (1000000UL)
#define XTIMER_WIDTH (32)
#endif
/** @} */
/**

View File

@ -132,25 +132,41 @@ static const spi_dev_t spi_config[] = {
/**
* @name Timer configuration
*
* The implementation uses two timers in cascade mode.
* The implementation can use one low-energy timer
* or two regular timers in cascade mode.
* @{
*/
#if EFM32_USE_LETIMER
static const timer_conf_t timer_config[] = {
{
{
.timer = {
.dev = LETIMER0,
.cmu = cmuClock_LETIMER0
},
.irq = LETIMER0_IRQn
}
};
#define TIMER_0_ISR isr_letimer0
#else
static const timer_conf_t timer_config[] = {
{
.prescaler = {
.dev = WTIMER0,
.cmu = cmuClock_WTIMER0
},
{
.timer = {
.dev = WTIMER1,
.cmu = cmuClock_WTIMER1
},
.irq = WTIMER1_IRQn
}
};
#define TIMER_0_ISR isr_wtimer1
#endif /* EFM32_USE_LETIMER */
#define TIMER_NUMOF ARRAY_SIZE(timer_config)
#define TIMER_0_ISR isr_wtimer1
/** @} */
/**

View File

@ -32,11 +32,16 @@ extern "C" {
/**
* @name Xtimer configuration
*
* The timer runs at 250 KHz to increase accuracy.
* The timer runs at 250 KHz to increase accuracy or 32768 Hz for LETIMER.
* @{
*/
#ifdef EFM32_USE_LETIMER
#define XTIMER_HZ (32768UL)
#define XTIMER_WIDTH (16)
#else
#define XTIMER_HZ (250000UL)
#define XTIMER_WIDTH (16)
#endif
/** @} */
/**

View File

@ -141,25 +141,41 @@ static const spi_dev_t spi_config[] = {
/**
* @name Timer configuration
*
* The implementation uses two timers in cascade mode.
* The implementation can use one low-energy timer
* or two regular timers in cascade mode.
* @{
*/
#if EFM32_USE_LETIMER
static const timer_conf_t timer_config[] = {
{
{
.timer = {
.dev = LETIMER0,
.cmu = cmuClock_LETIMER0
},
.irq = LETIMER0_IRQn
}
};
#define TIMER_0_ISR isr_letimer0
#else
static const timer_conf_t timer_config[] = {
{
.prescaler = {
.dev = TIMER0,
.cmu = cmuClock_TIMER0
},
{
.timer = {
.dev = TIMER1,
.cmu = cmuClock_TIMER1
},
.irq = TIMER1_IRQn
}
};
#define TIMER_0_ISR isr_timer1
#endif /* EFM32_USE_LETIMER */
#define TIMER_NUMOF ARRAY_SIZE(timer_config)
#define TIMER_0_ISR isr_timer1
/** @} */
/**

View File

@ -32,11 +32,16 @@ extern "C" {
/**
* @name Xtimer configuration
*
* The timer runs at 250 KHz to increase accuracy.
* The timer runs at 250 KHz to increase accuracy or 32768 Hz for LETIMER.
* @{
*/
#ifdef EFM32_USE_LETIMER
#define XTIMER_HZ (32768UL)
#define XTIMER_WIDTH (16)
#else
#define XTIMER_HZ (250000UL)
#define XTIMER_WIDTH (16)
#endif
/** @} */
/**

View File

@ -155,7 +155,6 @@ static const pwm_conf_t pwm_config[] = {
#define PWM_NUMOF ARRAY_SIZE(pwm_channel_config)
/** @} */
/**
* @name RTT configuration
* @{
@ -196,25 +195,41 @@ static const spi_dev_t spi_config[] = {
/**
* @name Timer configuration
*
* The implementation uses two timers in cascade mode.
* The implementation can use one low-energy timer
* or two regular timers in cascade mode.
* @{
*/
#if EFM32_USE_LETIMER
static const timer_conf_t timer_config[] = {
{
{
.timer = {
.dev = LETIMER0,
.cmu = cmuClock_LETIMER0
},
.irq = LETIMER0_IRQn
}
};
#define TIMER_0_ISR isr_letimer0
#else
static const timer_conf_t timer_config[] = {
{
.prescaler = {
.dev = TIMER0,
.cmu = cmuClock_TIMER0
},
{
.timer = {
.dev = TIMER1,
.cmu = cmuClock_TIMER1
},
.irq = TIMER1_IRQn
}
};
#define TIMER_0_ISR isr_timer1
#endif /* EFM32_USE_LETIMER */
#define TIMER_NUMOF ARRAY_SIZE(timer_config)
#define TIMER_0_ISR isr_timer1
/** @} */
/**

View File

@ -32,11 +32,16 @@ extern "C" {
/**
* @name Xtimer configuration
*
* The timer runs at 250 KHz to increase accuracy.
* The timer runs at 250 KHz to increase accuracy or 32768 Hz for LETIMER.
* @{
*/
#ifdef EFM32_USE_LETIMER
#define XTIMER_HZ (32768UL)
#define XTIMER_WIDTH (16)
#else
#define XTIMER_HZ (250000UL)
#define XTIMER_WIDTH (16)
#endif
/** @} */
/**

View File

@ -155,7 +155,6 @@ static const pwm_conf_t pwm_config[] = {
#define PWM_NUMOF ARRAY_SIZE(pwm_channel_config)
/** @} */
/**
* @name RTT configuration
* @{
@ -196,25 +195,41 @@ static const spi_dev_t spi_config[] = {
/**
* @name Timer configuration
*
* The implementation uses two timers in cascade mode.
* The implementation can use one low-energy timer
* or two regular timers in cascade mode.
* @{
*/
#if EFM32_USE_LETIMER
static const timer_conf_t timer_config[] = {
{
{
.timer = {
.dev = LETIMER0,
.cmu = cmuClock_LETIMER0
},
.irq = LETIMER0_IRQn
}
};
#define TIMER_0_ISR isr_letimer0
#else
static const timer_conf_t timer_config[] = {
{
.prescaler = {
.dev = TIMER0,
.cmu = cmuClock_TIMER0
},
{
.timer = {
.dev = TIMER1,
.cmu = cmuClock_TIMER1
},
.irq = TIMER1_IRQn
}
};
#define TIMER_0_ISR isr_timer1
#endif /* EFM32_USE_LETIMER */
#define TIMER_NUMOF ARRAY_SIZE(timer_config)
#define TIMER_0_ISR isr_timer1
/** @} */
/**

View File

@ -359,6 +359,26 @@ typedef struct {
} timer_conf_t;
/** @} */
/**
* @brief The implementation can use one LETIMER or two regular timers cascaded
*/
#ifndef EFM32_USE_LETIMER
#define EFM32_USE_LETIMER 0
#endif
#ifdef EFM32_USE_LETIMER
/**
* @brief This timer implementation has two available channels
*/
#define TIMER_CHANNEL_NUMOF (2)
#else
/**
* @brief This timer implementation has three available channels
*/
#define TIMER_CHANNEL_NUMOF (3)
#endif
/**
* @brief UART device configuration.
*/

View File

@ -32,16 +32,6 @@
#include "em_timer_utils.h"
#include "em_letimer.h"
/**
* @brief This timer implementation has three available channels
*/
#define CC_CHANNELS (3U)
/**
* @brief The LETIMER implementation has two available channels
*/
#define LE_CC_CHANNELS (2U)
/**
* @brief These power modes will be blocked while the timer is running
*/
@ -176,7 +166,7 @@ int timer_set_absolute(tim_t dev, int channel, unsigned int value)
if (!_is_letimer(dev)) {
TIMER_TypeDef *tim = timer_config[dev].timer.dev;
if (channel < 0 || channel >= (int) CC_CHANNELS) {
if (channel < 0 || channel >= TIMER_CHANNEL_NUMOF) {
return -1;
}
@ -295,7 +285,7 @@ void TIMER_0_ISR(void)
if (_is_letimer(dev)) {
LETIMER_TypeDef *tim = timer_config[dev].timer.dev;
for (int i = 0; i < (int) LE_CC_CHANNELS; i++) {
for (int i = 0; i < TIMER_CHANNEL_NUMOF; i++) {
if (tim->IF & (LETIMER_IF_COMP0 << i))
{
LETIMER_IntDisable(tim, LETIMER_IEN_COMP0 << i);
@ -307,7 +297,7 @@ void TIMER_0_ISR(void)
else {
TIMER_TypeDef *tim = timer_config[dev].timer.dev;
for (int i = 0; i < (int) CC_CHANNELS; i++) {
for (int i = 0; i < TIMER_CHANNEL_NUMOF; i++) {
if (tim->IF & (TIMER_IF_CC0 << i)) {
tim->CC[i].CTRL = _TIMER_CC_CTRL_MODE_OFF;
tim->IFC = (TIMER_IFC_CC0 << i);