Skip to content

Commit 3f86142

Browse files
committed
[Nuvoton] Meet new lp_ticker HAL spec (Mbed OS 5.9)
1. Add LPTICKER in device_has option of targets.json file. 2. Disable ticker interrupt in lp_ticker_init 3. Add lp_ticker_free 4. Enable interrupt in lp_ticker_set_interrupt
1 parent ebd93ba commit 3f86142

File tree

5 files changed

+144
-8
lines changed

5 files changed

+144
-8
lines changed

targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ static int ticker_inited = 0;
5353
void lp_ticker_init(void)
5454
{
5555
if (ticker_inited) {
56+
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
57+
* ticker interrupt. */
58+
lp_ticker_disable_interrupt();
59+
lp_ticker_clear_interrupt();
5660
return;
5761
}
5862
ticker_inited = 1;
@@ -88,7 +92,7 @@ void lp_ticker_init(void)
8892

8993
NVIC_EnableIRQ(TIMER_MODINIT.irq_n);
9094

91-
TIMER_EnableInt(timer_base);
95+
TIMER_DisableInt(timer_base);
9296
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
9397

9498
TIMER_EnableWakeup(timer_base);
@@ -101,6 +105,33 @@ void lp_ticker_init(void)
101105
while(! (timer_base->CTL & TIMER_CTL_ACTSTS_Msk));
102106
}
103107

108+
void lp_ticker_free(void)
109+
{
110+
TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname);
111+
112+
/* Stop counting */
113+
TIMER_Stop(timer_base);
114+
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
115+
116+
/* Wait for timer to stop counting and unset active flag */
117+
while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk));
118+
119+
/* Disable wakeup */
120+
TIMER_DisableWakeup(timer_base);
121+
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
122+
123+
/* Disable interrupt */
124+
TIMER_DisableInt(timer_base);
125+
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
126+
127+
NVIC_DisableIRQ(TIMER_MODINIT.irq_n);
128+
129+
/* Disable IP clock */
130+
CLK_DisableModuleClock(TIMER_MODINIT.clkidx);
131+
132+
ticker_inited = 0;
133+
}
134+
104135
timestamp_t lp_ticker_read()
105136
{
106137
if (! ticker_inited) {
@@ -131,6 +162,9 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
131162

132163
timer_base->CMP = cmp_timer;
133164
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
165+
166+
TIMER_EnableInt(timer_base);
167+
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
134168
}
135169

136170
void lp_ticker_disable_interrupt(void)

targets/TARGET_NUVOTON/TARGET_M480/lp_ticker.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ static int ticker_inited = 0;
5353
void lp_ticker_init(void)
5454
{
5555
if (ticker_inited) {
56+
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
57+
* ticker interrupt. */
58+
lp_ticker_disable_interrupt();
59+
lp_ticker_clear_interrupt();
5660
return;
5761
}
5862
ticker_inited = 1;
@@ -88,7 +92,7 @@ void lp_ticker_init(void)
8892

8993
NVIC_EnableIRQ(TIMER_MODINIT.irq_n);
9094

91-
TIMER_EnableInt(timer_base);
95+
TIMER_DisableInt(timer_base);
9296
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
9397

9498
TIMER_EnableWakeup(timer_base);
@@ -101,6 +105,33 @@ void lp_ticker_init(void)
101105
while(! (timer_base->CTL & TIMER_CTL_ACTSTS_Msk));
102106
}
103107

108+
void lp_ticker_free(void)
109+
{
110+
TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname);
111+
112+
/* Stop counting */
113+
TIMER_Stop(timer_base);
114+
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
115+
116+
/* Wait for timer to stop counting and unset active flag */
117+
while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk));
118+
119+
/* Disable wakeup */
120+
TIMER_DisableWakeup(timer_base);
121+
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
122+
123+
/* Disable interrupt */
124+
TIMER_DisableInt(timer_base);
125+
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
126+
127+
NVIC_DisableIRQ(TIMER_MODINIT.irq_n);
128+
129+
/* Disable IP clock */
130+
CLK_DisableModuleClock(TIMER_MODINIT.clkidx);
131+
132+
ticker_inited = 0;
133+
}
134+
104135
timestamp_t lp_ticker_read()
105136
{
106137
if (! ticker_inited) {
@@ -131,6 +162,9 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
131162

132163
timer_base->CMP = cmp_timer;
133164
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
165+
166+
TIMER_EnableInt(timer_base);
167+
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
134168
}
135169

136170
void lp_ticker_disable_interrupt(void)

targets/TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ static int ticker_inited = 0;
5555
void lp_ticker_init(void)
5656
{
5757
if (ticker_inited) {
58+
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
59+
* ticker interrupt. */
60+
lp_ticker_disable_interrupt();
61+
lp_ticker_clear_interrupt();
5862
return;
5963
}
6064
ticker_inited = 1;
@@ -92,7 +96,7 @@ void lp_ticker_init(void)
9296

9397
NVIC_EnableIRQ(TIMER_MODINIT.irq_n);
9498

95-
TIMER_EnableInt(timer_base);
99+
TIMER_DisableInt(timer_base);
96100
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
97101

98102
TIMER_EnableWakeup(timer_base);
@@ -105,6 +109,33 @@ void lp_ticker_init(void)
105109
while(! (timer_base->CTL & TIMER_CTL_TMR_ACT_Msk));
106110
}
107111

112+
void lp_ticker_free(void)
113+
{
114+
TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname);
115+
116+
/* Stop counting */
117+
TIMER_Stop(timer_base);
118+
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
119+
120+
/* Wait for timer to stop counting and unset active flag */
121+
while((timer_base->CTL & TIMER_CTL_TMR_ACT_Msk));
122+
123+
/* Disable wakeup */
124+
TIMER_DisableWakeup(timer_base);
125+
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
126+
127+
/* Disable interrupt */
128+
TIMER_DisableInt(timer_base);
129+
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
130+
131+
NVIC_DisableIRQ(TIMER_MODINIT.irq_n);
132+
133+
/* Disable IP clock */
134+
CLK_DisableModuleClock(TIMER_MODINIT.clkidx);
135+
136+
ticker_inited = 0;
137+
}
138+
108139
timestamp_t lp_ticker_read()
109140
{
110141
if (! ticker_inited) {
@@ -135,6 +166,9 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
135166

136167
timer_base->CMPR = cmp_timer;
137168
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
169+
170+
TIMER_EnableInt(timer_base);
171+
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
138172
}
139173

140174
void lp_ticker_disable_interrupt(void)

targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ static int ticker_inited = 0;
5353
void lp_ticker_init(void)
5454
{
5555
if (ticker_inited) {
56+
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
57+
* ticker interrupt. */
58+
lp_ticker_disable_interrupt();
59+
lp_ticker_clear_interrupt();
5660
return;
5761
}
5862
ticker_inited = 1;
@@ -87,7 +91,7 @@ void lp_ticker_init(void)
8791

8892
NVIC_EnableIRQ(TIMER_MODINIT.irq_n);
8993

90-
TIMER_EnableInt(timer_base);
94+
TIMER_DisableInt(timer_base);
9195
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
9296

9397
TIMER_EnableWakeup(timer_base);
@@ -100,6 +104,33 @@ void lp_ticker_init(void)
100104
while(! (timer_base->CTL & TIMER_CTL_ACTSTS_Msk));
101105
}
102106

107+
void lp_ticker_free(void)
108+
{
109+
TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname);
110+
111+
/* Stop counting */
112+
TIMER_Stop(timer_base);
113+
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
114+
115+
/* Wait for timer to stop counting and unset active flag */
116+
while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk));
117+
118+
/* Disable wakeup */
119+
TIMER_DisableWakeup(timer_base);
120+
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
121+
122+
/* Disable interrupt */
123+
TIMER_DisableInt(timer_base);
124+
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
125+
126+
NVIC_DisableIRQ(TIMER_MODINIT.irq_n);
127+
128+
/* Disable IP clock */
129+
CLK_DisableModuleClock(TIMER_MODINIT.clkidx);
130+
131+
ticker_inited = 0;
132+
}
133+
103134
timestamp_t lp_ticker_read()
104135
{
105136
if (! ticker_inited) {
@@ -130,6 +161,9 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
130161

131162
timer_base->CMP = cmp_timer;
132163
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
164+
165+
TIMER_EnableInt(timer_base);
166+
wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3);
133167
}
134168

135169
void lp_ticker_disable_interrupt(void)

targets/targets.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3844,7 +3844,7 @@
38443844
},
38453845
"inherits": ["Target"],
38463846
"macros_add": ["MBEDTLS_CONFIG_HW_SUPPORT"],
3847-
"device_has": ["USTICKER", "RTC", "ANALOGIN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "STDIO_MESSAGES", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "TRNG", "CAN", "FLASH", "EMAC"],
3847+
"device_has": ["USTICKER", "LPTICKER", "RTC", "ANALOGIN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "STDIO_MESSAGES", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "TRNG", "CAN", "FLASH", "EMAC"],
38483848
"release_versions": ["5"],
38493849
"device_name": "NUC472HI8AE",
38503850
"bootloader_supported": true,
@@ -3915,7 +3915,7 @@
39153915
},
39163916
"inherits": ["Target"],
39173917
"progen": {"target": "numaker-pfm-m453"},
3918-
"device_has": ["USTICKER", "RTC", "ANALOGIN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "STDIO_MESSAGES", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "CAN", "FLASH"],
3918+
"device_has": ["USTICKER", "LPTICKER", "RTC", "ANALOGIN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "STDIO_MESSAGES", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "CAN", "FLASH"],
39193919
"release_versions": ["2", "5"],
39203920
"device_name": "M453VG6AE",
39213921
"bootloader_supported": true
@@ -3946,7 +3946,7 @@
39463946
},
39473947
"inherits": ["Target"],
39483948
"macros": ["CMSIS_VECTAB_VIRTUAL", "CMSIS_VECTAB_VIRTUAL_HEADER_FILE=\"cmsis_nvic.h\"","MBED_FAULT_HANDLER_DISABLED"],
3949-
"device_has": ["USTICKER", "RTC", "ANALOGIN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "STDIO_MESSAGES", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH"],
3949+
"device_has": ["USTICKER", "LPTICKER", "RTC", "ANALOGIN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "STDIO_MESSAGES", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH"],
39503950
"release_versions": ["5"],
39513951
"device_name": "NANO130KE3BN"
39523952
},
@@ -4113,7 +4113,7 @@
41134113
},
41144114
"inherits": ["Target"],
41154115
"macros_add": ["MBEDTLS_CONFIG_HW_SUPPORT"],
4116-
"device_has": ["USTICKER", "RTC", "ANALOGIN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "STDIO_MESSAGES", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "TRNG", "FLASH", "CAN", "EMAC"],
4116+
"device_has": ["USTICKER", "LPTICKER", "RTC", "ANALOGIN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "STDIO_MESSAGES", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "TRNG", "FLASH", "CAN", "EMAC"],
41174117
"release_versions": ["5"],
41184118
"device_name": "M487JIDAE",
41194119
"bootloader_supported": true,

0 commit comments

Comments
 (0)