mirror of https://github.com/ARMmbed/mbed-os.git
[Nuvoton] Meet new us_ticker HAL spec (Mbed OS 5.9)
1. Add USTICKER in device_has option of targets.json file. 2. Disable ticker interrupt in us_ticker_init 3. Add us_ticker_free 4. Enable interrupt in us_ticker_set_interruptpull/7029/head
parent
f3424da060
commit
ebd93ba753
|
@ -15,6 +15,9 @@
|
|||
*/
|
||||
|
||||
#include "us_ticker_api.h"
|
||||
|
||||
#if DEVICE_USTICKER
|
||||
|
||||
#include "sleep_api.h"
|
||||
#include "mbed_assert.h"
|
||||
#include "nu_modutil.h"
|
||||
|
@ -45,6 +48,10 @@ static int ticker_inited = 0;
|
|||
void us_ticker_init(void)
|
||||
{
|
||||
if (ticker_inited) {
|
||||
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
|
||||
* ticker interrupt. */
|
||||
us_ticker_disable_interrupt();
|
||||
us_ticker_clear_interrupt();
|
||||
return;
|
||||
}
|
||||
ticker_inited = 1;
|
||||
|
@ -75,13 +82,32 @@ void us_ticker_init(void)
|
|||
|
||||
NVIC_EnableIRQ(TIMER_MODINIT.irq_n);
|
||||
|
||||
TIMER_EnableInt(timer_base);
|
||||
TIMER_DisableInt(timer_base);
|
||||
|
||||
TIMER_Start(timer_base);
|
||||
/* Wait for timer to start counting and raise active flag */
|
||||
while(! (timer_base->CTL & TIMER_CTL_ACTSTS_Msk));
|
||||
}
|
||||
|
||||
void us_ticker_free(void)
|
||||
{
|
||||
TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname);
|
||||
|
||||
/* Stop counting */
|
||||
TIMER_Stop(timer_base);
|
||||
/* Wait for timer to stop counting and unset active flag */
|
||||
while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk));
|
||||
|
||||
/* Disable interrupt */
|
||||
TIMER_DisableInt(timer_base);
|
||||
NVIC_DisableIRQ(TIMER_MODINIT.irq_n);
|
||||
|
||||
/* Disable IP clock */
|
||||
CLK_DisableModuleClock(TIMER_MODINIT.clkidx);
|
||||
|
||||
ticker_inited = 0;
|
||||
}
|
||||
|
||||
uint32_t us_ticker_read()
|
||||
{
|
||||
if (! ticker_inited) {
|
||||
|
@ -110,6 +136,8 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
|
|||
uint32_t cmp_timer = timestamp * NU_TMRCLK_PER_TICK;
|
||||
cmp_timer = NU_CLAMP(cmp_timer, TMR_CMP_MIN, TMR_CMP_MAX);
|
||||
timer_base->CMP = cmp_timer;
|
||||
|
||||
TIMER_EnableInt(timer_base);
|
||||
}
|
||||
|
||||
void us_ticker_disable_interrupt(void)
|
||||
|
@ -145,3 +173,5 @@ static void tmr0_vec(void)
|
|||
// NOTE: us_ticker_set_interrupt() may get called in us_ticker_irq_handler();
|
||||
us_ticker_irq_handler();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
*/
|
||||
|
||||
#include "us_ticker_api.h"
|
||||
|
||||
#if DEVICE_USTICKER
|
||||
|
||||
#include "sleep_api.h"
|
||||
#include "mbed_assert.h"
|
||||
#include "nu_modutil.h"
|
||||
|
@ -45,6 +48,10 @@ static int ticker_inited = 0;
|
|||
void us_ticker_init(void)
|
||||
{
|
||||
if (ticker_inited) {
|
||||
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
|
||||
* ticker interrupt. */
|
||||
us_ticker_disable_interrupt();
|
||||
us_ticker_clear_interrupt();
|
||||
return;
|
||||
}
|
||||
ticker_inited = 1;
|
||||
|
@ -75,13 +82,33 @@ void us_ticker_init(void)
|
|||
|
||||
NVIC_EnableIRQ(TIMER_MODINIT.irq_n);
|
||||
|
||||
TIMER_EnableInt(timer_base);
|
||||
TIMER_DisableInt(timer_base);
|
||||
|
||||
TIMER_Start(timer_base);
|
||||
/* Wait for timer to start counting and raise active flag */
|
||||
while(! (timer_base->CTL & TIMER_CTL_ACTSTS_Msk));
|
||||
}
|
||||
|
||||
void us_ticker_free(void)
|
||||
{
|
||||
TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname);
|
||||
|
||||
/* Stop counting */
|
||||
TIMER_Stop(timer_base);
|
||||
|
||||
/* Wait for timer to stop counting and unset active flag */
|
||||
while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk));
|
||||
|
||||
/* Disable interrupt */
|
||||
TIMER_DisableInt(timer_base);
|
||||
NVIC_DisableIRQ(TIMER_MODINIT.irq_n);
|
||||
|
||||
/* Disable IP clock */
|
||||
CLK_DisableModuleClock(TIMER_MODINIT.clkidx);
|
||||
|
||||
ticker_inited = 0;
|
||||
}
|
||||
|
||||
uint32_t us_ticker_read()
|
||||
{
|
||||
if (! ticker_inited) {
|
||||
|
@ -110,6 +137,8 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
|
|||
uint32_t cmp_timer = timestamp * NU_TMRCLK_PER_TICK;
|
||||
cmp_timer = NU_CLAMP(cmp_timer, TMR_CMP_MIN, TMR_CMP_MAX);
|
||||
timer_base->CMP = cmp_timer;
|
||||
|
||||
TIMER_EnableInt(timer_base);
|
||||
}
|
||||
|
||||
void us_ticker_disable_interrupt(void)
|
||||
|
@ -145,3 +174,5 @@ static void tmr0_vec(void)
|
|||
// NOTE: us_ticker_set_interrupt() may get called in us_ticker_irq_handler();
|
||||
us_ticker_irq_handler();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
*/
|
||||
|
||||
#include "us_ticker_api.h"
|
||||
|
||||
#if DEVICE_USTICKER
|
||||
|
||||
#include "sleep_api.h"
|
||||
#include "mbed_assert.h"
|
||||
#include "nu_modutil.h"
|
||||
|
@ -47,6 +50,10 @@ static int ticker_inited = 0;
|
|||
void us_ticker_init(void)
|
||||
{
|
||||
if (ticker_inited) {
|
||||
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
|
||||
* ticker interrupt. */
|
||||
us_ticker_disable_interrupt();
|
||||
us_ticker_clear_interrupt();
|
||||
return;
|
||||
}
|
||||
ticker_inited = 1;
|
||||
|
@ -77,13 +84,33 @@ void us_ticker_init(void)
|
|||
|
||||
NVIC_EnableIRQ(TIMER_MODINIT.irq_n);
|
||||
|
||||
TIMER_EnableInt(timer_base);
|
||||
TIMER_DisableInt(timer_base);
|
||||
|
||||
TIMER_Start(timer_base);
|
||||
/* Wait for timer to start counting and raise active flag */
|
||||
while(! (timer_base->CTL & TIMER_CTL_TMR_ACT_Msk));
|
||||
}
|
||||
|
||||
void us_ticker_free(void)
|
||||
{
|
||||
TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname);
|
||||
|
||||
/* Stop counting */
|
||||
TIMER_Stop(timer_base);
|
||||
|
||||
/* Wait for timer to stop counting and unset active flag */
|
||||
while((timer_base->CTL & TIMER_CTL_TMR_ACT_Msk));
|
||||
|
||||
/* Disable interrupt */
|
||||
TIMER_DisableInt(timer_base);
|
||||
NVIC_DisableIRQ(TIMER_MODINIT.irq_n);
|
||||
|
||||
/* Disable IP clock */
|
||||
CLK_DisableModuleClock(TIMER_MODINIT.clkidx);
|
||||
|
||||
ticker_inited = 0;
|
||||
}
|
||||
|
||||
uint32_t us_ticker_read()
|
||||
{
|
||||
if (! ticker_inited) {
|
||||
|
@ -112,6 +139,8 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
|
|||
uint32_t cmp_timer = timestamp * NU_TMRCLK_PER_TICK;
|
||||
cmp_timer = NU_CLAMP(cmp_timer, TMR_CMP_MIN, TMR_CMP_MAX);
|
||||
timer_base->CMPR = cmp_timer;
|
||||
|
||||
TIMER_EnableInt(timer_base);
|
||||
}
|
||||
|
||||
void us_ticker_disable_interrupt(void)
|
||||
|
@ -147,3 +176,5 @@ void TMR0_IRQHandler(void)
|
|||
// NOTE: us_ticker_set_interrupt() may get called in us_ticker_irq_handler();
|
||||
us_ticker_irq_handler();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
*/
|
||||
|
||||
#include "us_ticker_api.h"
|
||||
|
||||
#if DEVICE_USTICKER
|
||||
|
||||
#include "sleep_api.h"
|
||||
#include "mbed_assert.h"
|
||||
#include "nu_modutil.h"
|
||||
|
@ -45,6 +48,10 @@ static int ticker_inited = 0;
|
|||
void us_ticker_init(void)
|
||||
{
|
||||
if (ticker_inited) {
|
||||
/* By HAL spec, ticker_init allows the ticker to keep counting and disables the
|
||||
* ticker interrupt. */
|
||||
us_ticker_disable_interrupt();
|
||||
us_ticker_clear_interrupt();
|
||||
return;
|
||||
}
|
||||
ticker_inited = 1;
|
||||
|
@ -74,13 +81,33 @@ void us_ticker_init(void)
|
|||
|
||||
NVIC_EnableIRQ(TIMER_MODINIT.irq_n);
|
||||
|
||||
TIMER_EnableInt(timer_base);
|
||||
TIMER_DisableInt(timer_base);
|
||||
|
||||
TIMER_Start(timer_base);
|
||||
/* Wait for timer to start counting and raise active flag */
|
||||
while(! (timer_base->CTL & TIMER_CTL_ACTSTS_Msk));
|
||||
}
|
||||
|
||||
void us_ticker_free(void)
|
||||
{
|
||||
TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname);
|
||||
|
||||
/* Stop counting */
|
||||
TIMER_Stop(timer_base);
|
||||
|
||||
/* Wait for timer to stop counting and unset active flag */
|
||||
while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk));
|
||||
|
||||
/* Disable interrupt */
|
||||
TIMER_DisableInt(timer_base);
|
||||
NVIC_DisableIRQ(TIMER_MODINIT.irq_n);
|
||||
|
||||
/* Disable IP clock */
|
||||
CLK_DisableModuleClock(TIMER_MODINIT.clkidx);
|
||||
|
||||
ticker_inited = 0;
|
||||
}
|
||||
|
||||
uint32_t us_ticker_read()
|
||||
{
|
||||
if (! ticker_inited) {
|
||||
|
@ -109,6 +136,8 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
|
|||
uint32_t cmp_timer = timestamp * NU_TMRCLK_PER_TICK;
|
||||
cmp_timer = NU_CLAMP(cmp_timer, TMR_CMP_MIN, TMR_CMP_MAX);
|
||||
timer_base->CMP = cmp_timer;
|
||||
|
||||
TIMER_EnableInt(timer_base);
|
||||
}
|
||||
|
||||
void us_ticker_disable_interrupt(void)
|
||||
|
@ -144,3 +173,5 @@ static void tmr0_vec(void)
|
|||
// NOTE: us_ticker_set_interrupt() may get called in us_ticker_irq_handler();
|
||||
us_ticker_irq_handler();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3844,7 +3844,7 @@
|
|||
},
|
||||
"inherits": ["Target"],
|
||||
"macros_add": ["MBEDTLS_CONFIG_HW_SUPPORT"],
|
||||
"device_has": ["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"],
|
||||
"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"],
|
||||
"release_versions": ["5"],
|
||||
"device_name": "NUC472HI8AE",
|
||||
"bootloader_supported": true,
|
||||
|
@ -3915,7 +3915,7 @@
|
|||
},
|
||||
"inherits": ["Target"],
|
||||
"progen": {"target": "numaker-pfm-m453"},
|
||||
"device_has": ["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"],
|
||||
"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"],
|
||||
"release_versions": ["2", "5"],
|
||||
"device_name": "M453VG6AE",
|
||||
"bootloader_supported": true
|
||||
|
@ -3946,7 +3946,7 @@
|
|||
},
|
||||
"inherits": ["Target"],
|
||||
"macros": ["CMSIS_VECTAB_VIRTUAL", "CMSIS_VECTAB_VIRTUAL_HEADER_FILE=\"cmsis_nvic.h\"","MBED_FAULT_HANDLER_DISABLED"],
|
||||
"device_has": ["RTC", "ANALOGIN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "STDIO_MESSAGES", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH"],
|
||||
"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"],
|
||||
"release_versions": ["5"],
|
||||
"device_name": "NANO130KE3BN"
|
||||
},
|
||||
|
@ -4113,7 +4113,7 @@
|
|||
},
|
||||
"inherits": ["Target"],
|
||||
"macros_add": ["MBEDTLS_CONFIG_HW_SUPPORT"],
|
||||
"device_has": ["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"],
|
||||
"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"],
|
||||
"release_versions": ["5"],
|
||||
"device_name": "M487JIDAE",
|
||||
"bootloader_supported": true,
|
||||
|
|
Loading…
Reference in New Issue