mirror of https://github.com/ARMmbed/mbed-os.git
These changes allow us to re-implement us-Ticker using the RTC for the
nRF51822. There are two major themes here: 1. timestamp_t as an abstraction for time values managed by Ticker. Using uint64_t for timestamp_t allows a wraparound-free Ticker. This change forces us to update the definitions of usTicker for all platforms; but the changes beyond nRF51822 aren't major. 2. reduce power consumption on the nRF51822 by removing the need for the high-frequency processor timer; and reimplementing it using the RTC. I've also replaced high-frequency clock with low-frequency external clock during system startup of the nRF51822. This brings a major win in power consumption.pull/467/merge
commit
734f365d7d
|
@ -83,7 +83,7 @@ public:
|
|||
* @param fptr pointer to the function to be called
|
||||
* @param t the time between calls in micro-seconds
|
||||
*/
|
||||
void attach_us(void (*fptr)(void), unsigned int t) {
|
||||
void attach_us(void (*fptr)(void), timestamp_t t) {
|
||||
_function.attach(fptr);
|
||||
setup(t);
|
||||
}
|
||||
|
@ -95,21 +95,26 @@ public:
|
|||
* @param t the time between calls in micro-seconds
|
||||
*/
|
||||
template<typename T>
|
||||
void attach_us(T* tptr, void (T::*mptr)(void), unsigned int t) {
|
||||
void attach_us(T* tptr, void (T::*mptr)(void), timestamp_t t) {
|
||||
_function.attach(tptr, mptr);
|
||||
setup(t);
|
||||
}
|
||||
|
||||
virtual ~Ticker() {
|
||||
detach();
|
||||
}
|
||||
|
||||
/** Detach the function
|
||||
*/
|
||||
void detach();
|
||||
|
||||
protected:
|
||||
void setup(unsigned int t);
|
||||
void setup(timestamp_t t);
|
||||
virtual void handler();
|
||||
|
||||
unsigned int _delay;
|
||||
FunctionPointer _function;
|
||||
protected:
|
||||
timestamp_t _delay; /**< Time delay (in microseconds) for re-setting the multi-shot callback. */
|
||||
FunctionPointer _function; /**< Callback. */
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
|
|
@ -39,7 +39,7 @@ protected:
|
|||
virtual void handler() = 0;
|
||||
|
||||
// insert in to linked list
|
||||
void insert(unsigned int timestamp);
|
||||
void insert(timestamp_t timestamp);
|
||||
|
||||
// remove from linked list, if in it
|
||||
void remove();
|
||||
|
|
|
@ -25,7 +25,7 @@ void Ticker::detach() {
|
|||
_function.attach(0);
|
||||
}
|
||||
|
||||
void Ticker::setup(unsigned int t) {
|
||||
void Ticker::setup(timestamp_t t) {
|
||||
remove();
|
||||
_delay = t;
|
||||
insert(_delay + us_ticker_read());
|
||||
|
|
|
@ -34,7 +34,7 @@ TimerEvent::~TimerEvent() {
|
|||
}
|
||||
|
||||
// insert in to linked list
|
||||
void TimerEvent::insert(unsigned int timestamp) {
|
||||
void TimerEvent::insert(timestamp_t timestamp) {
|
||||
us_ticker_insert_event(&event, timestamp, (uint32_t)this);
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,8 @@ void us_ticker_irq_handler(void) {
|
|||
if (event_handler != NULL) {
|
||||
event_handler(p->id); // NOTE: the handler can set new events
|
||||
}
|
||||
/* Note: We continue back to examining the head because calling the
|
||||
* event handler may have altered the chain of pending events. */
|
||||
} else {
|
||||
// This event and the following ones in the list are in the future:
|
||||
// set it as next interrupt and return
|
||||
|
@ -54,7 +56,7 @@ void us_ticker_irq_handler(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void us_ticker_insert_event(ticker_event_t *obj, unsigned int timestamp, uint32_t id) {
|
||||
void us_ticker_insert_event(ticker_event_t *obj, timestamp_t timestamp, uint32_t id) {
|
||||
/* disable interrupts for the duration of the function */
|
||||
__disable_irq();
|
||||
|
||||
|
@ -95,7 +97,9 @@ void us_ticker_remove_event(ticker_event_t *obj) {
|
|||
if (head == obj) {
|
||||
// first in the list, so just drop me
|
||||
head = obj->next;
|
||||
if (obj->next != NULL) {
|
||||
if (head == NULL) {
|
||||
us_ticker_disable_interrupt();
|
||||
} else {
|
||||
us_ticker_set_interrupt(head->timestamp);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -22,24 +22,26 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef uint64_t timestamp_t;
|
||||
|
||||
uint32_t us_ticker_read(void);
|
||||
|
||||
typedef void (*ticker_event_handler)(uint32_t id);
|
||||
void us_ticker_set_handler(ticker_event_handler handler);
|
||||
|
||||
typedef struct ticker_event_s {
|
||||
uint32_t timestamp;
|
||||
uint32_t id;
|
||||
timestamp_t timestamp;
|
||||
uint32_t id;
|
||||
struct ticker_event_s *next;
|
||||
} ticker_event_t;
|
||||
|
||||
void us_ticker_init(void);
|
||||
void us_ticker_set_interrupt(unsigned int timestamp);
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp);
|
||||
void us_ticker_disable_interrupt(void);
|
||||
void us_ticker_clear_interrupt(void);
|
||||
void us_ticker_irq_handler(void);
|
||||
|
||||
void us_ticker_insert_event(ticker_event_t *obj, unsigned int timestamp, uint32_t id);
|
||||
void us_ticker_insert_event(ticker_event_t *obj, timestamp_t timestamp, uint32_t id);
|
||||
void us_ticker_remove_event(ticker_event_t *obj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -29,7 +29,7 @@ static bool is_disabled_in_debug_needed(void);
|
|||
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
|
||||
uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
|
||||
#elif defined ( __ICCARM__ )
|
||||
__root uint32_t SystemCoreClock = __SYSTEM_CLOCK;
|
||||
#elif defined ( __GNUC__ )
|
||||
|
@ -43,35 +43,36 @@ void SystemCoreClockUpdate(void)
|
|||
}
|
||||
|
||||
void SystemInit(void)
|
||||
{
|
||||
{
|
||||
// Prepare the peripherals for use as indicated by the PAN 26 "System: Manual setup is required
|
||||
// to enable the use of peripherals" found at Product Anomaly document for your device found at
|
||||
// https://www.nordicsemi.com/. The side effect of executing these instructions in the devices
|
||||
// https://www.nordicsemi.com/. The side effect of executing these instructions in the devices
|
||||
// that do not need it is that the new peripherals in the second generation devices (LPCOMP for
|
||||
// example) will not be available.
|
||||
if (is_manual_peripheral_setup_needed()){
|
||||
*(uint32_t volatile *)0x40000504 = 0xC007FFDF;
|
||||
*(uint32_t volatile *)0x40006C18 = 0x00008000;
|
||||
}
|
||||
|
||||
|
||||
// Disable PROTENSET registers under debug, as indicated by PAN 59 "MPU: Reset value of DISABLEINDEBUG
|
||||
// register is incorrect" found at Product Anomaly document four your device found at
|
||||
// https://www.nordicsemi.com/. There is no side effect of using these instruction if not needed.
|
||||
// register is incorrect" found at Product Anomaly document four your device found at
|
||||
// https://www.nordicsemi.com/. There is no side effect of using these instruction if not needed.
|
||||
if (is_disabled_in_debug_needed()){
|
||||
NRF_MPU->DISABLEINDEBUG = MPU_DISABLEINDEBUG_DISABLEINDEBUG_Disabled << MPU_DISABLEINDEBUG_DISABLEINDEBUG_Pos;
|
||||
}
|
||||
|
||||
// Start 16 MHz crystal oscillator.
|
||||
NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
|
||||
NRF_CLOCK->TASKS_HFCLKSTART = 1;
|
||||
|
||||
// Start the external 32khz crystal oscillator.
|
||||
NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
|
||||
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
|
||||
NRF_CLOCK->TASKS_LFCLKSTART = 1;
|
||||
|
||||
// Wait for the external oscillator to start up.
|
||||
while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {
|
||||
while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
static bool is_manual_peripheral_setup_needed(void)
|
||||
static bool is_manual_peripheral_setup_needed(void)
|
||||
{
|
||||
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x1) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0))
|
||||
{
|
||||
|
@ -88,11 +89,11 @@ static bool is_manual_peripheral_setup_needed(void)
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool is_disabled_in_debug_needed(void)
|
||||
static bool is_disabled_in_debug_needed(void)
|
||||
{
|
||||
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x1) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0))
|
||||
{
|
||||
|
@ -101,7 +102,7 @@ static bool is_disabled_in_debug_needed(void)
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -135,8 +135,8 @@ static void ticker_isr(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
int delta = (int)(timestamp - us_ticker_read());
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
int delta = (int)((uint32_t)timestamp - us_ticker_read());
|
||||
if (delta <= 0) {
|
||||
// This event was in the past:
|
||||
us_ticker_irq_handler();
|
||||
|
|
|
@ -167,8 +167,8 @@ static void lptmr_isr(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
int delta = (int)(timestamp - us_ticker_read());
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
int delta = (int)((uint32_t)timestamp - us_ticker_read());
|
||||
if (delta <= 0) {
|
||||
// This event was in the past:
|
||||
us_ticker_irq_handler();
|
||||
|
|
|
@ -133,8 +133,8 @@ static void lptmr_isr(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
int delta = (int)(timestamp - us_ticker_read());
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
int delta = (int)((uint32_t)timestamp - us_ticker_read());
|
||||
if (delta <= 0) {
|
||||
// This event was in the past:
|
||||
us_ticker_irq_handler();
|
||||
|
|
|
@ -17,113 +17,88 @@
|
|||
#include "us_ticker_api.h"
|
||||
#include "cmsis.h"
|
||||
#include "PeripheralNames.h"
|
||||
#include "app_timer.h"
|
||||
|
||||
#define US_TICKER_TIMER NRF_TIMER1
|
||||
#define US_TICKER_TIMER_IRQn TIMER1_IRQn
|
||||
static bool us_ticker_inited = false;
|
||||
static volatile bool us_ticker_appTimerRunning = false;
|
||||
static app_timer_id_t us_ticker_appTimerID = TIMER_NULL;
|
||||
|
||||
int us_ticker_inited = 0;
|
||||
volatile uint16_t overflow = 0; //overflow value that forms the upper 16 bits of the counter
|
||||
volatile uint16_t timeStamp = 0;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void TIMER1_IRQHandler(void)
|
||||
{
|
||||
if ((US_TICKER_TIMER->EVENTS_COMPARE[1] != 0) &&
|
||||
((US_TICKER_TIMER->INTENSET & TIMER_INTENSET_COMPARE1_Msk) != 0)) {
|
||||
US_TICKER_TIMER->EVENTS_COMPARE[1] = 0;
|
||||
overflow++;
|
||||
US_TICKER_TIMER->CC[1] = 0xFFFF;
|
||||
if (timeStamp>0) {
|
||||
timeStamp--;
|
||||
if (timeStamp==0) {
|
||||
us_ticker_clear_interrupt();
|
||||
us_ticker_disable_interrupt();
|
||||
us_ticker_irq_handler();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((US_TICKER_TIMER->EVENTS_COMPARE[0] != 0) &&
|
||||
((US_TICKER_TIMER->INTENSET & TIMER_INTENSET_COMPARE0_Msk) != 0)) {
|
||||
us_ticker_clear_interrupt();
|
||||
us_ticker_disable_interrupt();
|
||||
if (timeStamp==0) {
|
||||
us_ticker_irq_handler();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
void us_ticker_init(void)
|
||||
{
|
||||
if (us_ticker_inited && US_TICKER_TIMER->POWER) {
|
||||
if (us_ticker_inited) {
|
||||
return;
|
||||
}
|
||||
|
||||
us_ticker_inited = 1;
|
||||
APP_TIMER_INIT(0 /*CFG_TIMER_PRESCALER*/ , 1 /*CFG_TIMER_MAX_INSTANCE*/, 1 /*CFG_TIMER_OPERATION_QUEUE_SIZE*/, false /*CFG_SCHEDULER_ENABLE*/);
|
||||
|
||||
US_TICKER_TIMER->POWER = 0;
|
||||
US_TICKER_TIMER->POWER = 1;
|
||||
|
||||
US_TICKER_TIMER->MODE = TIMER_MODE_MODE_Timer;
|
||||
|
||||
US_TICKER_TIMER->PRESCALER = 4;
|
||||
US_TICKER_TIMER->BITMODE = TIMER_BITMODE_BITMODE_16Bit;
|
||||
US_TICKER_TIMER->TASKS_CLEAR = 1;
|
||||
US_TICKER_TIMER->CC[1] = 0xFFFF;
|
||||
US_TICKER_TIMER->INTENSET = TIMER_INTENSET_COMPARE1_Set << TIMER_INTENSET_COMPARE1_Pos;
|
||||
|
||||
NVIC_SetPriority(US_TICKER_TIMER_IRQn, 3);
|
||||
NVIC_EnableIRQ(US_TICKER_TIMER_IRQn);
|
||||
|
||||
US_TICKER_TIMER->TASKS_START = 0x01;
|
||||
us_ticker_inited = true;
|
||||
}
|
||||
|
||||
uint32_t us_ticker_read()
|
||||
{
|
||||
if (!us_ticker_inited || (US_TICKER_TIMER->POWER==0)) {
|
||||
if (!us_ticker_inited) {
|
||||
us_ticker_init();
|
||||
}
|
||||
|
||||
uint16_t bufferedOverFlow = overflow;
|
||||
US_TICKER_TIMER->TASKS_CAPTURE[2] = 1;
|
||||
|
||||
if (overflow!=bufferedOverFlow) {
|
||||
bufferedOverFlow = overflow;
|
||||
US_TICKER_TIMER->TASKS_CAPTURE[2] = 1;
|
||||
}
|
||||
return (((uint32_t)bufferedOverFlow << 16) | US_TICKER_TIMER->CC[2]);
|
||||
timestamp_t value;
|
||||
app_timer_cnt_get(&value); /* This returns the RTC counter (which is fed by the 32khz crystal clock source) */
|
||||
return (uint32_t)((value * 1000000) / APP_TIMER_CLOCK_FREQ); /* Return a pseudo microsecond counter value.
|
||||
* This is only as precise as the 32khz low-freq
|
||||
* clock source, but could be adequate.*/
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp)
|
||||
/* An adaptor to interface us_ticker_irq_handler with the app_timer callback.
|
||||
* Needed because the irq_handler() doesn't take any parameter.*/
|
||||
static void us_ticker_app_timer_callback(void *context)
|
||||
{
|
||||
if (!us_ticker_inited || (US_TICKER_TIMER->POWER == 0)) {
|
||||
us_ticker_appTimerRunning = false;
|
||||
us_ticker_irq_handler();
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp)
|
||||
{
|
||||
if (!us_ticker_inited) {
|
||||
us_ticker_init();
|
||||
}
|
||||
|
||||
US_TICKER_TIMER->TASKS_CAPTURE[0] = 1;
|
||||
uint16_t tsUpper16 = (uint16_t)((timestamp - us_ticker_read()) >> 16);
|
||||
if (tsUpper16>0) {
|
||||
if ((timeStamp ==0) || (timeStamp> tsUpper16)) {
|
||||
timeStamp = tsUpper16;
|
||||
if (us_ticker_appTimerID == TIMER_NULL) {
|
||||
if (app_timer_create(&us_ticker_appTimerID, APP_TIMER_MODE_SINGLE_SHOT, us_ticker_app_timer_callback) != NRF_SUCCESS) {
|
||||
/* placeholder to do something to recover from error */
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
US_TICKER_TIMER->INTENSET |= TIMER_INTENSET_COMPARE0_Set << TIMER_INTENSET_COMPARE0_Pos;
|
||||
US_TICKER_TIMER->CC[0] += timestamp - us_ticker_read();
|
||||
}
|
||||
|
||||
if (us_ticker_appTimerRunning) {
|
||||
return;
|
||||
}
|
||||
|
||||
timestamp_t currentCounter64;
|
||||
app_timer_cnt_get(¤tCounter64);
|
||||
uint32_t currentCounter = currentCounter64 & MAX_RTC_COUNTER_VAL;
|
||||
uint32_t targetCounter = ((uint32_t)((timestamp * (uint64_t)APP_TIMER_CLOCK_FREQ) / 1000000) + 1) & MAX_RTC_COUNTER_VAL;
|
||||
uint32_t ticksToCount = (targetCounter >= currentCounter) ?
|
||||
(targetCounter - currentCounter) : (MAX_RTC_COUNTER_VAL + 1) - (currentCounter - targetCounter);
|
||||
if (ticksToCount > 0) {
|
||||
uint32_t rc;
|
||||
rc = app_timer_start(us_ticker_appTimerID, ticksToCount, NULL /*p_context*/);
|
||||
if (rc != NRF_SUCCESS) {
|
||||
/* placeholder to do something to recover from error */
|
||||
return;
|
||||
}
|
||||
us_ticker_appTimerRunning = true;
|
||||
}
|
||||
}
|
||||
|
||||
void us_ticker_disable_interrupt(void)
|
||||
{
|
||||
US_TICKER_TIMER->INTENCLR = TIMER_INTENCLR_COMPARE0_Clear << TIMER_INTENCLR_COMPARE0_Pos;
|
||||
if (us_ticker_appTimerRunning) {
|
||||
app_timer_stop(us_ticker_appTimerID);
|
||||
}
|
||||
}
|
||||
|
||||
void us_ticker_clear_interrupt(void)
|
||||
{
|
||||
US_TICKER_TIMER->EVENTS_COMPARE[0] = 0;
|
||||
if (us_ticker_appTimerRunning) {
|
||||
app_timer_stop(us_ticker_appTimerID);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,9 +46,9 @@ uint32_t us_ticker_read() {
|
|||
return US_TICKER_TIMER->TC;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
// set match value
|
||||
US_TICKER_TIMER->MR0 = timestamp;
|
||||
US_TICKER_TIMER->MR0 = (uint32_t)timestamp;
|
||||
// enable match interrupt
|
||||
US_TICKER_TIMER->MCR |= 1;
|
||||
}
|
||||
|
|
|
@ -46,9 +46,9 @@ uint32_t us_ticker_read() {
|
|||
return US_TICKER_TIMER->TC;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
// set match value
|
||||
US_TICKER_TIMER->MR0 = timestamp;
|
||||
US_TICKER_TIMER->MR0 = (uint32_t)timestamp;
|
||||
// enable match interrupt
|
||||
US_TICKER_TIMER->MCR |= 1;
|
||||
}
|
||||
|
|
|
@ -46,9 +46,9 @@ uint32_t us_ticker_read() {
|
|||
return US_TICKER_TIMER->TC;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
// set match value
|
||||
US_TICKER_TIMER->MR0 = timestamp;
|
||||
US_TICKER_TIMER->MR0 = (uint32_t)timestamp;
|
||||
// enable match interrupt
|
||||
US_TICKER_TIMER->MCR |= 1;
|
||||
}
|
||||
|
|
|
@ -46,9 +46,9 @@ uint32_t us_ticker_read() {
|
|||
return US_TICKER_TIMER->TC;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
// set match value
|
||||
US_TICKER_TIMER->MR0 = timestamp;
|
||||
US_TICKER_TIMER->MR0 = (uint32_t)timestamp;
|
||||
// enable match interrupt
|
||||
US_TICKER_TIMER->MCR |= 1;
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ uint32_t us_ticker_read() {
|
|||
return (uint32_t)temp;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
uint64_t temp = ((uint64_t)timestamp * (SystemCoreClock/1000000));
|
||||
LPC_RIT->COMPVAL = (temp & 0xFFFFFFFFL);
|
||||
LPC_RIT->COMPVAL_H = ((temp >> 32)& 0x0000FFFFL);
|
||||
|
|
|
@ -48,9 +48,9 @@ uint32_t us_ticker_read() {
|
|||
return US_TICKER_TIMER->TC;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
// set match value
|
||||
US_TICKER_TIMER->MR0 = timestamp;
|
||||
US_TICKER_TIMER->MR0 = (uint32_t)timestamp;
|
||||
// enable match interrupt
|
||||
US_TICKER_TIMER->MCR |= 1;
|
||||
}
|
||||
|
|
|
@ -48,9 +48,9 @@ uint32_t us_ticker_read() {
|
|||
return US_TICKER_TIMER->TC;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
// set match value
|
||||
US_TICKER_TIMER->MR0 = timestamp;
|
||||
US_TICKER_TIMER->MR0 = (uint32_t)timestamp;
|
||||
// enable match interrupt
|
||||
US_TICKER_TIMER->MCR |= 1;
|
||||
}
|
||||
|
|
|
@ -48,9 +48,9 @@ uint32_t us_ticker_read() {
|
|||
return US_TICKER_TIMER->TC;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
// set match value
|
||||
US_TICKER_TIMER->MR0 = timestamp;
|
||||
US_TICKER_TIMER->MR0 = (uint32_t)timestamp;
|
||||
// enable match interrupt
|
||||
US_TICKER_TIMER->MCR |= 1;
|
||||
}
|
||||
|
|
|
@ -48,9 +48,9 @@ uint32_t us_ticker_read() {
|
|||
return US_TICKER_TIMER->TC;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
// set match value
|
||||
US_TICKER_TIMER->MR[0] = timestamp;
|
||||
US_TICKER_TIMER->MR[0] = (uint32_t)timestamp;
|
||||
// enable match interrupt
|
||||
US_TICKER_TIMER->MCR |= 1;
|
||||
}
|
||||
|
|
|
@ -55,13 +55,13 @@ uint32_t us_ticker_read() {
|
|||
return LPC_SCT->COUNT_U;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
// halt the counter:
|
||||
// - setting bit 2 of the CTRL register
|
||||
LPC_SCT->CTRL_L |= (1 << 2);
|
||||
|
||||
// set timestamp in compare register
|
||||
LPC_SCT->MATCH[0].U = timestamp;
|
||||
LPC_SCT->MATCH[0].U = (uint32_t)timestamp;
|
||||
|
||||
// unhalt the counter:
|
||||
// - clearing bit 2 of the CTRL register
|
||||
|
|
|
@ -90,7 +90,7 @@ void us_ticker_init(void) {
|
|||
// Configure time base
|
||||
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
|
||||
TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 µs tick
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 <EFBFBD>s tick
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
TIM_TimeBaseInit(TIM_MST, &TIM_TimeBaseStructure);
|
||||
|
@ -131,8 +131,8 @@ uint32_t us_ticker_read() {
|
|||
return counter2;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
int delta = (int)(timestamp - us_ticker_read());
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
int delta = (int)((uint32_t)timestamp - us_ticker_read());
|
||||
uint16_t cval = TIM_MST->CNT;
|
||||
|
||||
if (delta <= 0) { // This event was in the past
|
||||
|
|
|
@ -92,7 +92,7 @@ void us_ticker_init(void) {
|
|||
// Configure time base
|
||||
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
|
||||
TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 µs tick
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 <EFBFBD>s tick
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
TIM_TimeBaseInit(TIM_MST, &TIM_TimeBaseStructure);
|
||||
|
@ -133,8 +133,8 @@ uint32_t us_ticker_read() {
|
|||
return counter2;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
int delta = (int)(timestamp - us_ticker_read());
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
int delta = (int)((uint32_t)timestamp - us_ticker_read());
|
||||
uint16_t cval = TIM_MST->CNT;
|
||||
|
||||
if (delta <= 0) { // This event was in the past
|
||||
|
|
|
@ -48,7 +48,7 @@ void us_ticker_init(void) {
|
|||
// Configure time base
|
||||
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
|
||||
TIM_TimeBaseStructure.TIM_Period = 0xFFFFFFFF;
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 µs tick
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 <EFBFBD>s tick
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
TIM_TimeBaseInit(TIM_MST, &TIM_TimeBaseStructure);
|
||||
|
@ -65,9 +65,9 @@ uint32_t us_ticker_read() {
|
|||
return TIM_MST->CNT;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
// Set new output compare value
|
||||
TIM_SetCompare1(TIM_MST, timestamp);
|
||||
TIM_SetCompare1(TIM_MST, (uint32_t)timestamp);
|
||||
// Enable IT
|
||||
TIM_ITConfig(TIM_MST, TIM_IT_CC1, ENABLE);
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ void us_ticker_init(void) {
|
|||
// Configure time base
|
||||
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
|
||||
TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 µs tick
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 <EFBFBD>s tick
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
TIM_TimeBaseInit(TIM_MST, &TIM_TimeBaseStructure);
|
||||
|
@ -131,8 +131,8 @@ uint32_t us_ticker_read() {
|
|||
return counter2;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
int delta = (int)(timestamp - us_ticker_read());
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
int delta = (int)((uint32_t)timestamp - us_ticker_read());
|
||||
uint16_t cval = TIM_MST->CNT;
|
||||
|
||||
if (delta <= 0) { // This event was in the past
|
||||
|
|
|
@ -50,7 +50,7 @@ void us_ticker_init(void) {
|
|||
// Configure time base
|
||||
TimMasterHandle.Instance = TIM_MST;
|
||||
TimMasterHandle.Init.Period = 0xFFFFFFFF;
|
||||
TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 µs tick
|
||||
TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 <EFBFBD>s tick
|
||||
TimMasterHandle.Init.ClockDivision = 0;
|
||||
TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
TimMasterHandle.Init.RepetitionCounter = 0;
|
||||
|
@ -68,9 +68,9 @@ uint32_t us_ticker_read() {
|
|||
return TIM_MST->CNT;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
// Set new output compare value
|
||||
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, timestamp);
|
||||
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
|
||||
// Enable IT
|
||||
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ void us_ticker_init(void) {
|
|||
// Configure time base
|
||||
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
|
||||
TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 µs tick
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 <EFBFBD>s tick
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
TIM_TimeBaseInit(TIM_MST, &TIM_TimeBaseStructure);
|
||||
|
@ -121,8 +121,8 @@ uint32_t us_ticker_read() {
|
|||
return counter2;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
int delta = (int)(timestamp - us_ticker_read());
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
int delta = (int)((uint32_t)timestamp - us_ticker_read());
|
||||
uint16_t cval = TIM_MST->CNT;
|
||||
|
||||
if (delta <= 0) { // This event was in the past
|
||||
|
|
|
@ -48,7 +48,7 @@ void us_ticker_init(void) {
|
|||
// Configure time base
|
||||
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
|
||||
TIM_TimeBaseStructure.TIM_Period = 0xFFFFFFFF;
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 µs tick
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 <EFBFBD>s tick
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
TIM_TimeBaseInit(TIM_MST, &TIM_TimeBaseStructure);
|
||||
|
@ -65,9 +65,9 @@ uint32_t us_ticker_read() {
|
|||
return TIM_MST->CNT;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
// Set new output compare value
|
||||
TIM_SetCompare1(TIM_MST, timestamp);
|
||||
TIM_SetCompare1(TIM_MST, (uint32_t)timestamp);
|
||||
// Enable IT
|
||||
TIM_ITConfig(TIM_MST, TIM_IT_CC1, ENABLE);
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ void us_ticker_init(void)
|
|||
// Configure time base
|
||||
TimMasterHandle.Instance = TIM_MST;
|
||||
TimMasterHandle.Init.Period = 0xFFFFFFFF;
|
||||
TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 µs tick
|
||||
TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 <EFBFBD>s tick
|
||||
TimMasterHandle.Init.ClockDivision = 0;
|
||||
TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
TimMasterHandle.Init.RepetitionCounter = 0;
|
||||
|
@ -70,10 +70,10 @@ uint32_t us_ticker_read()
|
|||
return TIM_MST->CNT;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp)
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp)
|
||||
{
|
||||
// Set new output compare value
|
||||
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, timestamp);
|
||||
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
|
||||
// Enable IT
|
||||
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
|
||||
}
|
||||
|
|
|
@ -48,9 +48,9 @@ uint32_t us_ticker_read() {
|
|||
return TIM_MST->CNT;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
// Set new output compare value
|
||||
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, timestamp);
|
||||
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
|
||||
// Enable IT
|
||||
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
|
||||
}
|
||||
|
|
|
@ -50,10 +50,10 @@ uint32_t us_ticker_read()
|
|||
return TIM_MST->CNT;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp)
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp)
|
||||
{
|
||||
// Set new output compare value
|
||||
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, timestamp);
|
||||
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
|
||||
// Enable IT
|
||||
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ void us_ticker_init(void) {
|
|||
// Configure time base
|
||||
TimMasterHandle.Instance = TIM_MST;
|
||||
TimMasterHandle.Init.Period = 0xFFFF;
|
||||
TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 µs tick
|
||||
TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 <EFBFBD>s tick
|
||||
TimMasterHandle.Init.ClockDivision = 0;
|
||||
TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
HAL_TIM_Base_Init(&TimMasterHandle);
|
||||
|
@ -123,8 +123,8 @@ uint32_t us_ticker_read() {
|
|||
return counter2;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
int delta = (int)(timestamp - us_ticker_read());
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
int delta = (int)((uint32_t)timestamp - us_ticker_read());
|
||||
uint16_t cval = TIM_MST->CNT;
|
||||
|
||||
if (delta <= 0) { // This event was in the past
|
||||
|
|
|
@ -48,7 +48,7 @@ void us_ticker_init(void) {
|
|||
// Configure time base
|
||||
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
|
||||
TIM_TimeBaseStructure.TIM_Period = 0xFFFFFFFF;
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 µs tick
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 <EFBFBD>s tick
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
TIM_TimeBaseInit(TIM_MST, &TIM_TimeBaseStructure);
|
||||
|
@ -65,9 +65,9 @@ uint32_t us_ticker_read() {
|
|||
return TIM_MST->CNT;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
// Set new output compare value
|
||||
TIM_SetCompare1(TIM_MST, timestamp);
|
||||
TIM_SetCompare1(TIM_MST, (uint32_t)timestamp);
|
||||
// Enable IT
|
||||
TIM_ITConfig(TIM_MST, TIM_IT_CC1, ENABLE);
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ void us_ticker_init(void) {
|
|||
// Configure time base
|
||||
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
|
||||
TIM_TimeBaseStructure.TIM_Period = 0xFFFFFFFF;
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 µs tick
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 <EFBFBD>s tick
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
TIM_TimeBaseInit(TIM_MST, &TIM_TimeBaseStructure);
|
||||
|
@ -65,9 +65,9 @@ uint32_t us_ticker_read() {
|
|||
return TIM_MST->CNT;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
// Set new output compare value
|
||||
TIM_SetCompare1(TIM_MST, timestamp);
|
||||
TIM_SetCompare1(TIM_MST, (uint32_t)timestamp);
|
||||
// Enable IT
|
||||
TIM_ITConfig(TIM_MST, TIM_IT_CC1, ENABLE);
|
||||
}
|
||||
|
|
|
@ -48,9 +48,9 @@ uint32_t us_ticker_read() {
|
|||
return TIM_MST->CNT;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
// Set new output compare value
|
||||
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, timestamp);
|
||||
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
|
||||
// Enable IT
|
||||
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
|
||||
}
|
||||
|
|
|
@ -47,9 +47,9 @@ uint32_t us_ticker_read() {
|
|||
return US_TICKER_TIMER->CNT;
|
||||
}
|
||||
|
||||
void us_ticker_set_interrupt(unsigned int timestamp) {
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp) {
|
||||
// set match value
|
||||
US_TICKER_TIMER->CCR1 = timestamp;
|
||||
US_TICKER_TIMER->CCR1 = (uint32_t)timestamp;
|
||||
// enable compare interrupt
|
||||
US_TICKER_TIMER->DIER |= TIM_DIER_CC1IE;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue