Skip to content

Commit ab882c3

Browse files
authored
Merge pull request #8030 from OpenNuvoton/nuvoton_fix_common_tickers_fail
Nuvoton: Fix Greentea test common_tickers failed
2 parents 54afd1c + 4888ff2 commit ab882c3

File tree

11 files changed

+44
-146
lines changed

11 files changed

+44
-146
lines changed

TESTS/mbed_hal/common_tickers/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,14 @@ void ticker_speed_test(void)
473473

474474
/* ---- Test fire_interrupt function. ---- */
475475
counter = NUM_OF_CALLS;
476+
/* Disable ticker interrupt which would interfere with speed test */
477+
core_util_critical_section_enter();
476478
start = us_ticker_read();
477479
while (counter--) {
478480
intf->fire_interrupt();
479481
}
480482
stop = us_ticker_read();
483+
core_util_critical_section_exit();
481484

482485
TEST_ASSERT(diff_us(start, stop, us_ticker_info) < (NUM_OF_CALLS * (MAX_FUNC_EXEC_TIME_US + DELTA_FUNC_EXEC_TIME_US)));
483486

@@ -569,7 +572,7 @@ utest::v1::status_t lp_ticker_teardown(const Case *const source, const size_t pa
569572

570573
utest::v1::status_t test_setup(const size_t number_of_cases)
571574
{
572-
GREENTEA_SETUP(30, "default_auto");
575+
GREENTEA_SETUP(80, "default_auto");
573576
return verbose_test_setup_handler(number_of_cases);
574577
}
575578

targets/TARGET_NUVOTON/TARGET_M2351/lp_ticker.c

Lines changed: 4 additions & 18 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;
@@ -162,23 +160,7 @@ void lp_ticker_init(void)
162160

163161
void lp_ticker_free(void)
164162
{
165-
TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname);
166-
167-
/* Stop counting */
168-
TIMER_Stop(timer_base);
169-
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
170-
171-
/* Wait for timer to stop counting and unset active flag */
172-
while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk));
173-
174-
/* Disable wakeup */
175-
TIMER_DisableWakeup(timer_base);
176-
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
177-
178163
/* Disable interrupt */
179-
TIMER_DisableInt(timer_base);
180-
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
181-
182164
NVIC_DisableIRQ(TIMER_MODINIT.irq_n);
183165

184166
/* Disable IP clock
@@ -203,6 +185,10 @@ timestamp_t lp_ticker_read()
203185

204186
void lp_ticker_set_interrupt(timestamp_t timestamp)
205187
{
188+
/* Clear any previously pending interrupts */
189+
lp_ticker_clear_interrupt();
190+
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
191+
206192
/* In continuous mode, counter will be reset to zero with the following sequence:
207193
* 1. Stop counting
208194
* 2. Configure new CMP value

targets/TARGET_NUVOTON/TARGET_M2351/us_ticker.c

Lines changed: 4 additions & 11 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;
@@ -125,16 +123,7 @@ void us_ticker_init(void)
125123

126124
void us_ticker_free(void)
127125
{
128-
TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname);
129-
130-
/* Stop counting */
131-
TIMER_Stop(timer_base);
132-
133-
/* Wait for timer to stop counting and unset active flag */
134-
while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk));
135-
136126
/* Disable interrupt */
137-
TIMER_DisableInt(timer_base);
138127
NVIC_DisableIRQ(TIMER_MODINIT.irq_n);
139128

140129
/* Disable IP clock
@@ -159,6 +148,10 @@ uint32_t us_ticker_read()
159148

160149
void us_ticker_set_interrupt(timestamp_t timestamp)
161150
{
151+
/* Clear any previously pending interrupts */
152+
us_ticker_clear_interrupt();
153+
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
154+
162155
/* In continuous mode, counter will be reset to zero with the following sequence:
163156
* 1. Stop counting
164157
* 2. Configure new CMP value

targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c

Lines changed: 4 additions & 18 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;
@@ -128,23 +126,7 @@ void lp_ticker_init(void)
128126

129127
void lp_ticker_free(void)
130128
{
131-
TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname);
132-
133-
/* Stop counting */
134-
TIMER_Stop(timer_base);
135-
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
136-
137-
/* Wait for timer to stop counting and unset active flag */
138-
while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk));
139-
140-
/* Disable wakeup */
141-
TIMER_DisableWakeup(timer_base);
142-
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
143-
144129
/* Disable interrupt */
145-
TIMER_DisableInt(timer_base);
146-
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
147-
148130
NVIC_DisableIRQ(TIMER_MODINIT.irq_n);
149131

150132
/* Disable IP clock */
@@ -166,6 +148,10 @@ timestamp_t lp_ticker_read()
166148

167149
void lp_ticker_set_interrupt(timestamp_t timestamp)
168150
{
151+
/* Clear any previously pending interrupts */
152+
lp_ticker_clear_interrupt();
153+
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
154+
169155
/* In continuous mode, counter will be reset to zero with the following sequence:
170156
* 1. Stop counting
171157
* 2. Configure new CMP value

targets/TARGET_NUVOTON/TARGET_M451/us_ticker.c

Lines changed: 4 additions & 11 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;
@@ -93,16 +91,7 @@ void us_ticker_init(void)
9391

9492
void us_ticker_free(void)
9593
{
96-
TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname);
97-
98-
/* Stop counting */
99-
TIMER_Stop(timer_base);
100-
101-
/* Wait for timer to stop counting and unset active flag */
102-
while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk));
103-
10494
/* Disable interrupt */
105-
TIMER_DisableInt(timer_base);
10695
NVIC_DisableIRQ(TIMER_MODINIT.irq_n);
10796

10897
/* Disable IP clock */
@@ -124,6 +113,10 @@ uint32_t us_ticker_read()
124113

125114
void us_ticker_set_interrupt(timestamp_t timestamp)
126115
{
116+
/* Clear any previously pending interrupts */
117+
us_ticker_clear_interrupt();
118+
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
119+
127120
/* In continuous mode, counter will be reset to zero with the following sequence:
128121
* 1. Stop counting
129122
* 2. Configure new CMP value

targets/TARGET_NUVOTON/TARGET_M480/lp_ticker.c

Lines changed: 4 additions & 18 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;
@@ -128,23 +126,7 @@ void lp_ticker_init(void)
128126

129127
void lp_ticker_free(void)
130128
{
131-
TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname);
132-
133-
/* Stop counting */
134-
TIMER_Stop(timer_base);
135-
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
136-
137-
/* Wait for timer to stop counting and unset active flag */
138-
while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk));
139-
140-
/* Disable wakeup */
141-
TIMER_DisableWakeup(timer_base);
142-
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
143-
144129
/* Disable interrupt */
145-
TIMER_DisableInt(timer_base);
146-
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
147-
148130
NVIC_DisableIRQ(TIMER_MODINIT.irq_n);
149131

150132
/* Disable IP clock */
@@ -166,6 +148,10 @@ timestamp_t lp_ticker_read()
166148

167149
void lp_ticker_set_interrupt(timestamp_t timestamp)
168150
{
151+
/* Clear any previously pending interrupts */
152+
lp_ticker_clear_interrupt();
153+
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
154+
169155
/* In continuous mode, counter will be reset to zero with the following sequence:
170156
* 1. Stop counting
171157
* 2. Configure new CMP value

targets/TARGET_NUVOTON/TARGET_M480/us_ticker.c

Lines changed: 4 additions & 11 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;
@@ -93,16 +91,7 @@ void us_ticker_init(void)
9391

9492
void us_ticker_free(void)
9593
{
96-
TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname);
97-
98-
/* Stop counting */
99-
TIMER_Stop(timer_base);
100-
101-
/* Wait for timer to stop counting and unset active flag */
102-
while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk));
103-
10494
/* Disable interrupt */
105-
TIMER_DisableInt(timer_base);
10695
NVIC_DisableIRQ(TIMER_MODINIT.irq_n);
10796

10897
/* Disable IP clock */
@@ -124,6 +113,10 @@ uint32_t us_ticker_read()
124113

125114
void us_ticker_set_interrupt(timestamp_t timestamp)
126115
{
116+
/* Clear any previously pending interrupts */
117+
us_ticker_clear_interrupt();
118+
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
119+
127120
/* In continuous mode, counter will be reset to zero with the following sequence:
128121
* 1. Stop counting
129122
* 2. Configure new CMP value

targets/TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c

Lines changed: 4 additions & 18 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;
@@ -132,23 +130,7 @@ void lp_ticker_init(void)
132130

133131
void lp_ticker_free(void)
134132
{
135-
TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname);
136-
137-
/* Stop counting */
138-
TIMER_Stop(timer_base);
139-
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
140-
141-
/* Wait for timer to stop counting and unset active flag */
142-
while((timer_base->CTL & TIMER_CTL_TMR_ACT_Msk));
143-
144-
/* Disable wakeup */
145-
TIMER_DisableWakeup(timer_base);
146-
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
147-
148133
/* Disable interrupt */
149-
TIMER_DisableInt(timer_base);
150-
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
151-
152134
NVIC_DisableIRQ(TIMER_MODINIT.irq_n);
153135

154136
/* Disable IP clock */
@@ -170,6 +152,10 @@ timestamp_t lp_ticker_read()
170152

171153
void lp_ticker_set_interrupt(timestamp_t timestamp)
172154
{
155+
/* Clear any previously pending interrupts */
156+
lp_ticker_clear_interrupt();
157+
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
158+
173159
/* In continuous mode, counter will be reset to zero with the following sequence:
174160
* 1. Stop counting
175161
* 2. Configure new CMP value

targets/TARGET_NUVOTON/TARGET_NANO100/us_ticker.c

Lines changed: 4 additions & 11 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;
@@ -95,16 +93,7 @@ void us_ticker_init(void)
9593

9694
void us_ticker_free(void)
9795
{
98-
TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname);
99-
100-
/* Stop counting */
101-
TIMER_Stop(timer_base);
102-
103-
/* Wait for timer to stop counting and unset active flag */
104-
while((timer_base->CTL & TIMER_CTL_TMR_ACT_Msk));
105-
10696
/* Disable interrupt */
107-
TIMER_DisableInt(timer_base);
10897
NVIC_DisableIRQ(TIMER_MODINIT.irq_n);
10998

11099
/* Disable IP clock */
@@ -126,6 +115,10 @@ uint32_t us_ticker_read()
126115

127116
void us_ticker_set_interrupt(timestamp_t timestamp)
128117
{
118+
/* Clear any previously pending interrupts */
119+
us_ticker_clear_interrupt();
120+
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
121+
129122
/* In continuous mode, counter will be reset to zero with the following sequence:
130123
* 1. Stop counting
131124
* 2. Configure new CMP value

targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c

Lines changed: 4 additions & 18 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;
@@ -127,23 +125,7 @@ void lp_ticker_init(void)
127125

128126
void lp_ticker_free(void)
129127
{
130-
TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname);
131-
132-
/* Stop counting */
133-
TIMER_Stop(timer_base);
134-
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
135-
136-
/* Wait for timer to stop counting and unset active flag */
137-
while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk));
138-
139-
/* Disable wakeup */
140-
TIMER_DisableWakeup(timer_base);
141-
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
142-
143128
/* Disable interrupt */
144-
TIMER_DisableInt(timer_base);
145-
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
146-
147129
NVIC_DisableIRQ(TIMER_MODINIT.irq_n);
148130

149131
/* Disable IP clock */
@@ -165,6 +147,10 @@ timestamp_t lp_ticker_read()
165147

166148
void lp_ticker_set_interrupt(timestamp_t timestamp)
167149
{
150+
/* Clear any previously pending interrupts */
151+
lp_ticker_clear_interrupt();
152+
NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n);
153+
168154
/* In continuous mode, counter will be reset to zero with the following sequence:
169155
* 1. Stop counting
170156
* 2. Configure new CMP value

0 commit comments

Comments
 (0)