mbed-os v5.9 USTICKER implementation

pull/7009/head
Jesse Marroquin 2018-05-17 14:45:55 -05:00 committed by Bartek Szatkowski
parent 11748bf95c
commit b88329acb8
4 changed files with 59 additions and 68 deletions

View File

@ -41,36 +41,33 @@
#define US_TIMER_MODE TMR32_MODE_COMPARE
#define US_TIMER_WIDTH 32
static volatile int us_ticker_inited = 0;
//******************************************************************************
void us_ticker_init(void)
{
tmr32_cfg_t cfg;
// Disable and deconfigure
US_TIMER->ctrl = 0;
US_TIMER->term_cnt32 = 0;
US_TIMER->inten = 0;
US_TIMER->intfl = MXC_F_TMR_INTFL_TIMER0;
if (us_ticker_inited) {
return;
}
us_ticker_inited = 1;
// Configure and enable
US_TIMER->ctrl = MXC_F_TMR_CTRL_ENABLE0 |
(US_TIMER_MODE << MXC_F_TMR_CTRL_MODE_POS) |
(US_TIMER_PRESCALE << MXC_F_TMR_CTRL_PRESCALE_POS);
cfg.mode = US_TIMER_MODE;
cfg.polarity = TMR_POLARITY_UNUSED;
cfg.compareCount = UINT32_MAX;
TMR_Init(US_TIMER, US_TIMER_PRESCALE, NULL);
TMR32_Config(US_TIMER, &cfg);
NVIC_SetVector(US_TIMER_IRQn, (uint32_t)us_ticker_irq_handler);
NVIC_EnableIRQ(US_TIMER_IRQn);
TMR32_Start(US_TIMER);
}
//******************************************************************************
void us_ticker_free(void)
{
US_TIMER->ctrl = 0;
}
//******************************************************************************
uint32_t us_ticker_read(void)
{
if (!us_ticker_inited) {
us_ticker_init();
}
return US_TIMER->count32;
}
@ -78,7 +75,7 @@ uint32_t us_ticker_read(void)
void us_ticker_set_interrupt(timestamp_t timestamp)
{
US_TIMER->ctrl = 0;
US_TIMER->term_cnt32 = timestamp;
US_TIMER->term_cnt32 = (timestamp) ? timestamp : 1;
US_TIMER->inten = MXC_F_TMR_INTEN_TIMER0;
US_TIMER->ctrl = MXC_F_TMR_CTRL_ENABLE0 |
(US_TIMER_MODE << MXC_F_TMR_CTRL_MODE_POS) |

View File

@ -41,36 +41,33 @@
#define US_TIMER_MODE TMR32_MODE_COMPARE
#define US_TIMER_WIDTH 32
static volatile int us_ticker_inited = 0;
//******************************************************************************
void us_ticker_init(void)
{
tmr32_cfg_t cfg;
// Disable and deconfigure
US_TIMER->ctrl = 0;
US_TIMER->term_cnt32 = 0;
US_TIMER->inten = 0;
US_TIMER->intfl = MXC_F_TMR_INTFL_TIMER0;
if (us_ticker_inited) {
return;
}
us_ticker_inited = 1;
// Configure and enable
US_TIMER->ctrl = MXC_F_TMR_CTRL_ENABLE0 |
(US_TIMER_MODE << MXC_F_TMR_CTRL_MODE_POS) |
(US_TIMER_PRESCALE << MXC_F_TMR_CTRL_PRESCALE_POS);
cfg.mode = US_TIMER_MODE;
cfg.polarity = TMR_POLARITY_UNUSED;
cfg.compareCount = UINT32_MAX;
TMR_Init(US_TIMER, US_TIMER_PRESCALE, NULL);
TMR32_Config(US_TIMER, &cfg);
NVIC_SetVector(US_TIMER_IRQn, (uint32_t)us_ticker_irq_handler);
NVIC_EnableIRQ(US_TIMER_IRQn);
TMR32_Start(US_TIMER);
}
//******************************************************************************
void us_ticker_free(void)
{
US_TIMER->ctrl = 0;
}
//******************************************************************************
uint32_t us_ticker_read(void)
{
if (!us_ticker_inited) {
us_ticker_init();
}
return US_TIMER->count32;
}
@ -78,7 +75,7 @@ uint32_t us_ticker_read(void)
void us_ticker_set_interrupt(timestamp_t timestamp)
{
US_TIMER->ctrl = 0;
US_TIMER->term_cnt32 = timestamp;
US_TIMER->term_cnt32 = (timestamp) ? timestamp : 1;
US_TIMER->inten = MXC_F_TMR_INTEN_TIMER0;
US_TIMER->ctrl = MXC_F_TMR_CTRL_ENABLE0 |
(US_TIMER_MODE << MXC_F_TMR_CTRL_MODE_POS) |

View File

@ -35,42 +35,39 @@
#include "us_ticker_api.h"
#include "tmr.h"
#define US_TIMER MXC_TMR0
#define US_TIMER_IRQn TMR0_0_IRQn
#define US_TIMER_PRESCALE TMR_PRESCALE_DIV_2_5
#define US_TIMER_MODE TMR32_MODE_COMPARE
#define US_TIMER_WIDTH 32
static volatile int us_ticker_inited = 0;
#define US_TIMER MXC_TMR0
#define US_TIMER_IRQn TMR0_0_IRQn
#define US_TIMER_PRESCALE TMR_PRESCALE_DIV_2_5
#define US_TIMER_MODE TMR32_MODE_COMPARE
#define US_TIMER_WIDTH 32
//******************************************************************************
void us_ticker_init(void)
{
tmr32_cfg_t cfg;
// Disable and deconfigure
US_TIMER->ctrl = 0;
US_TIMER->term_cnt32 = 0;
US_TIMER->inten = 0;
US_TIMER->intfl = MXC_F_TMR_INTFL_TIMER0;
if (us_ticker_inited) {
return;
}
us_ticker_inited = 1;
// Configure and enable
US_TIMER->ctrl = MXC_F_TMR_CTRL_ENABLE0 |
(US_TIMER_MODE << MXC_F_TMR_CTRL_MODE_POS) |
(US_TIMER_PRESCALE << MXC_F_TMR_CTRL_PRESCALE_POS);
cfg.mode = US_TIMER_MODE;
cfg.polarity = TMR_POLARITY_UNUSED;
cfg.compareCount = UINT32_MAX;
TMR_Init(US_TIMER, US_TIMER_PRESCALE, NULL);
TMR32_Config(US_TIMER, &cfg);
NVIC_SetVector(US_TIMER_IRQn, (uint32_t)us_ticker_irq_handler);
NVIC_EnableIRQ(US_TIMER_IRQn);
TMR32_Start(US_TIMER);
}
//******************************************************************************
void us_ticker_free(void)
{
US_TIMER->ctrl = 0;
}
//******************************************************************************
uint32_t us_ticker_read(void)
{
if (!us_ticker_inited) {
us_ticker_init();
}
return US_TIMER->count32;
}
@ -78,12 +75,12 @@ uint32_t us_ticker_read(void)
void us_ticker_set_interrupt(timestamp_t timestamp)
{
US_TIMER->ctrl = 0;
US_TIMER->term_cnt32 = timestamp;
US_TIMER->term_cnt32 = (timestamp) ? timestamp : 1;
US_TIMER->inten = MXC_F_TMR_INTEN_TIMER0;
US_TIMER->ctrl = MXC_F_TMR_CTRL_ENABLE0 |
(US_TIMER_MODE << MXC_F_TMR_CTRL_MODE_POS) |
(US_TIMER_PRESCALE << MXC_F_TMR_CTRL_PRESCALE_POS);
}
}
//******************************************************************************
void us_ticker_fire_interrupt(void)

View File

@ -2849,8 +2849,8 @@
"macros": ["__SYSTEM_HFX=96000000","TARGET=MAX32620","TARGET_REV=0x4332","OPEN_DRAIN_LEDS"],
"extra_labels": ["Maxim", "MAX32620C"],
"supported_toolchains": ["GCC_ARM", "IAR", "ARM"],
"device_has": ["ANALOGIN", "I2C", "INTERRUPTIN", "LPTICKER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "STDIO_MESSAGES"],
"release_versions": ["2"]
"device_has": ["ANALOGIN", "I2C", "INTERRUPTIN", "LPTICKER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "STDIO_MESSAGES", "USTICKER"],
"release_versions": ["2", "5"]
},
"MAX32625_BASE": {
"inherits": ["Target"],
@ -2858,8 +2858,8 @@
"macros": ["TARGET=MAX32625","TARGET_REV=0x4132", "OPEN_DRAIN_LEDS"],
"extra_labels": ["Maxim", "MAX32625"],
"supported_toolchains": ["GCC_ARM", "IAR", "ARM"],
"device_has": ["ANALOGIN", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "STDIO_MESSAGES"],
"release_versions": ["2"],
"device_has": ["ANALOGIN", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "STDIO_MESSAGES", "USTICKER"],
"release_versions": ["2", "5"],
"public": false
},
"MAX32625_BOOT": {
@ -2893,7 +2893,7 @@
"macros": ["__SYSTEM_HFX=96000000", "TARGET=MAX32630", "TARGET_REV=0x4132", "BLE_HCI_UART", "OPEN_DRAIN_LEDS"],
"extra_labels": ["Maxim", "MAX32630"],
"supported_toolchains": ["GCC_ARM", "IAR", "ARM"],
"device_has": ["ANALOGIN", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "STDIO_MESSAGES"],
"device_has": ["ANALOGIN", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "STDIO_MESSAGES", "USTICKER"],
"features": ["BLE"],
"release_versions": []
},