Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/efm32/timer_series2: fix interaction with pm_layered #18814

Merged
merged 2 commits into from
Nov 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions cpu/efm32/periph/timer_series2.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,26 +224,44 @@ unsigned int timer_read(tim_t dev)
return _is_letimer(dev) ? _letimer_read(dev) : _timer_read(dev);
}

static inline bool _letimer_is_running(LETIMER_TypeDef *tim)
{
/* make sure registers are up-to-date and
* we can rely on the STATS register */
LETIMER_SyncWait(tim);

return tim->STATUS & LETIMER_STATUS_RUNNING;
}

static inline bool _timer_is_running(TIMER_TypeDef *tim)
{
/* make sure registers are up-to-date and
* we can rely on the STATS register */
TIMER_SyncWait(tim);

return tim->STATUS & TIMER_STATUS_RUNNING;
}

static inline void _letimer_stop(tim_t dev)
{
LETIMER_TypeDef *tim = timer_config[dev].dev;

if (tim->STATUS & LETIMER_STATUS_RUNNING) {
if (_letimer_is_running(tim)) {
pm_unblock(LETIMER_PM_BLOCKER);
}

LETIMER_Enable(timer_config[dev].dev, false);
LETIMER_Enable(tim, false);
}

static inline void _timer_stop(tim_t dev)
{
TIMER_TypeDef *tim = timer_config[dev].dev;

if (tim->STATUS & TIMER_STATUS_RUNNING) {
if (_timer_is_running(tim)) {
pm_unblock(TIMER_PM_BLOCKER);
}

TIMER_Enable(timer_config[dev].dev, false);
TIMER_Enable(tim, false);
}

void timer_stop(tim_t dev)
Expand All @@ -255,22 +273,22 @@ static inline void _letimer_start(tim_t dev)
{
LETIMER_TypeDef *tim = timer_config[dev].dev;

if (tim->STATUS & LETIMER_STATUS_RUNNING) {
if (!_letimer_is_running(tim)) {
pm_block(LETIMER_PM_BLOCKER);
}

LETIMER_Enable(timer_config[dev].dev, true);
LETIMER_Enable(tim, true);
}

static inline void _timer_start(tim_t dev)
{
TIMER_TypeDef *tim = timer_config[dev].dev;

if (tim->STATUS & TIMER_STATUS_RUNNING) {
if (!_timer_is_running(tim)) {
pm_block(TIMER_PM_BLOCKER);
}

TIMER_Enable(timer_config[dev].dev, true);
TIMER_Enable(tim, true);
}

void timer_start(tim_t dev)
Expand Down