Fix spurious us_ticker/lp_ticker interrupts

If us_ticker/lp_ticker is scheduled and then the interrupt is disabled, the originally scheduled
interrupt may still become pending. If this occurs, then an interrupt will fire twice on the next
call to us_ticker_set_interrupt/lp_ticker_set_interrupt - once immediately and then a second time
at the appropriate time.

This patch prevents the first interrupt by clearing interrupts in
us_ticker_set_interrupt/lp_ticker_set_interrupt before calling NVIC_EnableIRQ.
pull/8341/head
ccli8 2018-08-08 09:38:48 +08:00 committed by adbridge
parent 413ee535da
commit a0c2518761
10 changed files with 40 additions and 20 deletions

View File

@ -101,8 +101,6 @@ void lp_ticker_init(void)
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
* ticker interrupt. */
lp_ticker_disable_interrupt();
lp_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
return;
}
ticker_inited = 1;
@ -203,6 +201,10 @@ timestamp_t lp_ticker_read()
void lp_ticker_set_interrupt(timestamp_t timestamp)
{
/* Clear any previously pending interrupts */
lp_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
/* In continuous mode, counter will be reset to zero with the following sequence:
* 1. Stop counting
* 2. Configure new CMP value

View File

@ -75,8 +75,6 @@ void us_ticker_init(void)
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
* ticker interrupt. */
us_ticker_disable_interrupt();
us_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
return;
}
ticker_inited = 1;
@ -159,6 +157,10 @@ uint32_t us_ticker_read()
void us_ticker_set_interrupt(timestamp_t timestamp)
{
/* Clear any previously pending interrupts */
us_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
/* In continuous mode, counter will be reset to zero with the following sequence:
* 1. Stop counting
* 2. Configure new CMP value

View File

@ -76,8 +76,6 @@ void lp_ticker_init(void)
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
* ticker interrupt. */
lp_ticker_disable_interrupt();
lp_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
return;
}
ticker_inited = 1;
@ -166,6 +164,10 @@ timestamp_t lp_ticker_read()
void lp_ticker_set_interrupt(timestamp_t timestamp)
{
/* Clear any previously pending interrupts */
lp_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
/* In continuous mode, counter will be reset to zero with the following sequence:
* 1. Stop counting
* 2. Configure new CMP value

View File

@ -52,8 +52,6 @@ void us_ticker_init(void)
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
* ticker interrupt. */
us_ticker_disable_interrupt();
us_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
return;
}
ticker_inited = 1;
@ -124,6 +122,10 @@ uint32_t us_ticker_read()
void us_ticker_set_interrupt(timestamp_t timestamp)
{
/* Clear any previously pending interrupts */
us_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
/* In continuous mode, counter will be reset to zero with the following sequence:
* 1. Stop counting
* 2. Configure new CMP value

View File

@ -76,8 +76,6 @@ void lp_ticker_init(void)
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
* ticker interrupt. */
lp_ticker_disable_interrupt();
lp_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
return;
}
ticker_inited = 1;
@ -166,6 +164,10 @@ timestamp_t lp_ticker_read()
void lp_ticker_set_interrupt(timestamp_t timestamp)
{
/* Clear any previously pending interrupts */
lp_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
/* In continuous mode, counter will be reset to zero with the following sequence:
* 1. Stop counting
* 2. Configure new CMP value

View File

@ -52,8 +52,6 @@ void us_ticker_init(void)
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
* ticker interrupt. */
us_ticker_disable_interrupt();
us_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
return;
}
ticker_inited = 1;
@ -124,6 +122,10 @@ uint32_t us_ticker_read()
void us_ticker_set_interrupt(timestamp_t timestamp)
{
/* Clear any previously pending interrupts */
us_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
/* In continuous mode, counter will be reset to zero with the following sequence:
* 1. Stop counting
* 2. Configure new CMP value

View File

@ -78,8 +78,6 @@ void lp_ticker_init(void)
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
* ticker interrupt. */
lp_ticker_disable_interrupt();
lp_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
return;
}
ticker_inited = 1;
@ -170,6 +168,10 @@ timestamp_t lp_ticker_read()
void lp_ticker_set_interrupt(timestamp_t timestamp)
{
/* Clear any previously pending interrupts */
lp_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
/* In continuous mode, counter will be reset to zero with the following sequence:
* 1. Stop counting
* 2. Configure new CMP value

View File

@ -54,8 +54,6 @@ void us_ticker_init(void)
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
* ticker interrupt. */
us_ticker_disable_interrupt();
us_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
return;
}
ticker_inited = 1;
@ -126,6 +124,10 @@ uint32_t us_ticker_read()
void us_ticker_set_interrupt(timestamp_t timestamp)
{
/* Clear any previously pending interrupts */
us_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
/* In continuous mode, counter will be reset to zero with the following sequence:
* 1. Stop counting
* 2. Configure new CMP value

View File

@ -76,8 +76,6 @@ void lp_ticker_init(void)
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
* ticker interrupt. */
lp_ticker_disable_interrupt();
lp_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
return;
}
ticker_inited = 1;
@ -165,6 +163,10 @@ timestamp_t lp_ticker_read()
void lp_ticker_set_interrupt(timestamp_t timestamp)
{
/* Clear any previously pending interrupts */
lp_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
/* In continuous mode, counter will be reset to zero with the following sequence:
* 1. Stop counting
* 2. Configure new CMP value

View File

@ -52,8 +52,6 @@ void us_ticker_init(void)
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
* ticker interrupt. */
us_ticker_disable_interrupt();
us_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
return;
}
ticker_inited = 1;
@ -123,6 +121,10 @@ uint32_t us_ticker_read()
void us_ticker_set_interrupt(timestamp_t timestamp)
{
/* Clear any previously pending interrupts */
us_ticker_clear_interrupt();
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
/* In continuous mode, counter will be reset to zero with the following sequence:
* 1. Stop counting
* 2. Configure new CMP value