Skip to content

Commit a0c2518

Browse files
ccli8adbridge
authored andcommitted
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.
1 parent 413ee53 commit a0c2518

File tree

10 files changed

+40
-20
lines changed

10 files changed

+40
-20
lines changed

targets/TARGET_NUVOTON/TARGET_M2351/lp_ticker.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ void lp_ticker_init(void)
101101
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
102102
* ticker interrupt. */
103103
lp_ticker_disable_interrupt();
104-
lp_ticker_clear_interrupt();
105-
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
106104
return;
107105
}
108106
ticker_inited = 1;
@@ -203,6 +201,10 @@ timestamp_t lp_ticker_read()
203201

204202
void lp_ticker_set_interrupt(timestamp_t timestamp)
205203
{
204+
/* Clear any previously pending interrupts */
205+
lp_ticker_clear_interrupt();
206+
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
207+
206208
/* In continuous mode, counter will be reset to zero with the following sequence:
207209
* 1. Stop counting
208210
* 2. Configure new CMP value

targets/TARGET_NUVOTON/TARGET_M2351/us_ticker.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ void us_ticker_init(void)
7575
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
7676
* ticker interrupt. */
7777
us_ticker_disable_interrupt();
78-
us_ticker_clear_interrupt();
79-
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
8078
return;
8179
}
8280
ticker_inited = 1;
@@ -159,6 +157,10 @@ uint32_t us_ticker_read()
159157

160158
void us_ticker_set_interrupt(timestamp_t timestamp)
161159
{
160+
/* Clear any previously pending interrupts */
161+
us_ticker_clear_interrupt();
162+
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
163+
162164
/* In continuous mode, counter will be reset to zero with the following sequence:
163165
* 1. Stop counting
164166
* 2. Configure new CMP value

targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ void lp_ticker_init(void)
7676
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
7777
* ticker interrupt. */
7878
lp_ticker_disable_interrupt();
79-
lp_ticker_clear_interrupt();
80-
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
8179
return;
8280
}
8381
ticker_inited = 1;
@@ -166,6 +164,10 @@ timestamp_t lp_ticker_read()
166164

167165
void lp_ticker_set_interrupt(timestamp_t timestamp)
168166
{
167+
/* Clear any previously pending interrupts */
168+
lp_ticker_clear_interrupt();
169+
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
170+
169171
/* In continuous mode, counter will be reset to zero with the following sequence:
170172
* 1. Stop counting
171173
* 2. Configure new CMP value

targets/TARGET_NUVOTON/TARGET_M451/us_ticker.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ void us_ticker_init(void)
5252
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
5353
* ticker interrupt. */
5454
us_ticker_disable_interrupt();
55-
us_ticker_clear_interrupt();
56-
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
5755
return;
5856
}
5957
ticker_inited = 1;
@@ -124,6 +122,10 @@ uint32_t us_ticker_read()
124122

125123
void us_ticker_set_interrupt(timestamp_t timestamp)
126124
{
125+
/* Clear any previously pending interrupts */
126+
us_ticker_clear_interrupt();
127+
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
128+
127129
/* In continuous mode, counter will be reset to zero with the following sequence:
128130
* 1. Stop counting
129131
* 2. Configure new CMP value

targets/TARGET_NUVOTON/TARGET_M480/lp_ticker.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ void lp_ticker_init(void)
7676
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
7777
* ticker interrupt. */
7878
lp_ticker_disable_interrupt();
79-
lp_ticker_clear_interrupt();
80-
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
8179
return;
8280
}
8381
ticker_inited = 1;
@@ -166,6 +164,10 @@ timestamp_t lp_ticker_read()
166164

167165
void lp_ticker_set_interrupt(timestamp_t timestamp)
168166
{
167+
/* Clear any previously pending interrupts */
168+
lp_ticker_clear_interrupt();
169+
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
170+
169171
/* In continuous mode, counter will be reset to zero with the following sequence:
170172
* 1. Stop counting
171173
* 2. Configure new CMP value

targets/TARGET_NUVOTON/TARGET_M480/us_ticker.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ void us_ticker_init(void)
5252
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
5353
* ticker interrupt. */
5454
us_ticker_disable_interrupt();
55-
us_ticker_clear_interrupt();
56-
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
5755
return;
5856
}
5957
ticker_inited = 1;
@@ -124,6 +122,10 @@ uint32_t us_ticker_read()
124122

125123
void us_ticker_set_interrupt(timestamp_t timestamp)
126124
{
125+
/* Clear any previously pending interrupts */
126+
us_ticker_clear_interrupt();
127+
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
128+
127129
/* In continuous mode, counter will be reset to zero with the following sequence:
128130
* 1. Stop counting
129131
* 2. Configure new CMP value

targets/TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ void lp_ticker_init(void)
7878
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
7979
* ticker interrupt. */
8080
lp_ticker_disable_interrupt();
81-
lp_ticker_clear_interrupt();
82-
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
8381
return;
8482
}
8583
ticker_inited = 1;
@@ -170,6 +168,10 @@ timestamp_t lp_ticker_read()
170168

171169
void lp_ticker_set_interrupt(timestamp_t timestamp)
172170
{
171+
/* Clear any previously pending interrupts */
172+
lp_ticker_clear_interrupt();
173+
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
174+
173175
/* In continuous mode, counter will be reset to zero with the following sequence:
174176
* 1. Stop counting
175177
* 2. Configure new CMP value

targets/TARGET_NUVOTON/TARGET_NANO100/us_ticker.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ void us_ticker_init(void)
5454
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
5555
* ticker interrupt. */
5656
us_ticker_disable_interrupt();
57-
us_ticker_clear_interrupt();
58-
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
5957
return;
6058
}
6159
ticker_inited = 1;
@@ -126,6 +124,10 @@ uint32_t us_ticker_read()
126124

127125
void us_ticker_set_interrupt(timestamp_t timestamp)
128126
{
127+
/* Clear any previously pending interrupts */
128+
us_ticker_clear_interrupt();
129+
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
130+
129131
/* In continuous mode, counter will be reset to zero with the following sequence:
130132
* 1. Stop counting
131133
* 2. Configure new CMP value

targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ void lp_ticker_init(void)
7676
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
7777
* ticker interrupt. */
7878
lp_ticker_disable_interrupt();
79-
lp_ticker_clear_interrupt();
80-
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
8179
return;
8280
}
8381
ticker_inited = 1;
@@ -165,6 +163,10 @@ timestamp_t lp_ticker_read()
165163

166164
void lp_ticker_set_interrupt(timestamp_t timestamp)
167165
{
166+
/* Clear any previously pending interrupts */
167+
lp_ticker_clear_interrupt();
168+
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
169+
168170
/* In continuous mode, counter will be reset to zero with the following sequence:
169171
* 1. Stop counting
170172
* 2. Configure new CMP value

targets/TARGET_NUVOTON/TARGET_NUC472/us_ticker.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ void us_ticker_init(void)
5252
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
5353
* ticker interrupt. */
5454
us_ticker_disable_interrupt();
55-
us_ticker_clear_interrupt();
56-
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
5755
return;
5856
}
5957
ticker_inited = 1;
@@ -123,6 +121,10 @@ uint32_t us_ticker_read()
123121

124122
void us_ticker_set_interrupt(timestamp_t timestamp)
125123
{
124+
/* Clear any previously pending interrupts */
125+
us_ticker_clear_interrupt();
126+
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
127+
126128
/* In continuous mode, counter will be reset to zero with the following sequence:
127129
* 1. Stop counting
128130
* 2. Configure new CMP value

0 commit comments

Comments
 (0)