diff --git a/examples/drivers/windows/otLwf/alarm.c b/examples/drivers/windows/otLwf/alarm.c index f087d4819..dfff301e2 100644 --- a/examples/drivers/windows/otLwf/alarm.c +++ b/examples/drivers/windows/otLwf/alarm.c @@ -36,7 +36,7 @@ #include "alarm.tmh" uint32_t -otPlatAlarmGetNow() +otPlatAlarmMilliGetNow() { // Return number of 'ticks' LARGE_INTEGER PerformanceCounter = KeQueryPerformanceCounter(NULL); @@ -46,22 +46,22 @@ otPlatAlarmGetNow() } void -otPlatAlarmStop( +otPlatAlarmMilliStop( _In_ otInstance *otCtx ) { - LogVerbose(DRIVER_DEFAULT, "otPlatAlarmStop"); + LogVerbose(DRIVER_DEFAULT, "otPlatAlarmMilliStop"); otLwfEventProcessingIndicateNewWaitTime(otCtxToFilter(otCtx), (ULONG)(-1)); } void -otPlatAlarmStartAt( +otPlatAlarmMilliStartAt( _In_ otInstance *otCtx, uint32_t now, uint32_t waitTime ) { UNREFERENCED_PARAMETER(now); - LogVerbose(DRIVER_DEFAULT, "otPlatAlarmStartAt %u ms", waitTime); + LogVerbose(DRIVER_DEFAULT, "otPlatAlarmMilliStartAt %u ms", waitTime); otLwfEventProcessingIndicateNewWaitTime(otCtxToFilter(otCtx), waitTime); } diff --git a/examples/drivers/windows/otLwf/eventprocessing.c b/examples/drivers/windows/otLwf/eventprocessing.c index 2e9eebeb7..d540931a3 100644 --- a/examples/drivers/windows/otLwf/eventprocessing.c +++ b/examples/drivers/windows/otLwf/eventprocessing.c @@ -863,7 +863,7 @@ otLwfEventWorkerThread( pFilter->EventTimerState = OT_EVENT_TIMER_NOT_RUNNING; // Indicate to OpenThread that the alarm has fired - otPlatAlarmFired(pFilter->otCtx); + otPlatAlarmMilliFired(pFilter->otCtx); } else if (status == STATUS_WAIT_0 + 1) // EventWorkerThreadProcessNBLs fired { diff --git a/examples/drivers/windows/otLwf/precomp.h b/examples/drivers/windows/otLwf/precomp.h index 31ef93032..824eea70d 100644 --- a/examples/drivers/windows/otLwf/precomp.h +++ b/examples/drivers/windows/otLwf/precomp.h @@ -77,7 +77,7 @@ RtlCopyBufferToMdl( #include #include #include -#include +#include #include #include #include diff --git a/examples/platforms/cc2538/alarm.c b/examples/platforms/cc2538/alarm.c index 252f3ab0c..d768c79c5 100644 --- a/examples/platforms/cc2538/alarm.c +++ b/examples/platforms/cc2538/alarm.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include #include @@ -60,12 +60,12 @@ void cc2538AlarmInit(void) HWREG(NVIC_ST_CTRL) = NVIC_ST_CTRL_CLK_SRC | NVIC_ST_CTRL_INTEN | NVIC_ST_CTRL_ENABLE; } -uint32_t otPlatAlarmGetNow(void) +uint32_t otPlatAlarmMilliGetNow(void) { return sCounter; } -void otPlatAlarmStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt) +void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt) { (void)aInstance; sAlarmT0 = t0; @@ -73,7 +73,7 @@ void otPlatAlarmStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt) sIsRunning = true; } -void otPlatAlarmStop(otInstance *aInstance) +void otPlatAlarmMilliStop(otInstance *aInstance) { (void)aInstance; sIsRunning = false; @@ -116,7 +116,7 @@ void cc2538AlarmProcess(otInstance *aInstance) else #endif { - otPlatAlarmFired(aInstance); + otPlatAlarmMilliFired(aInstance); } } } diff --git a/examples/platforms/cc2538/diag.c b/examples/platforms/cc2538/diag.c index 68f234b06..7bbbe7c5b 100644 --- a/examples/platforms/cc2538/diag.c +++ b/examples/platforms/cc2538/diag.c @@ -33,7 +33,7 @@ #include #include -#include +#include #include #include "platform-cc2538.h" diff --git a/examples/platforms/cc2538/flash.c b/examples/platforms/cc2538/flash.c index dcf79413f..312e58934 100644 --- a/examples/platforms/cc2538/flash.c +++ b/examples/platforms/cc2538/flash.c @@ -32,7 +32,7 @@ #include #include -#include +#include #include "platform-cc2538.h" #include "rom-utility.h" @@ -102,10 +102,10 @@ exit: otError utilsFlashStatusWait(uint32_t aTimeout) { otError error = OT_ERROR_NONE; - uint32_t start = otPlatAlarmGetNow(); + uint32_t start = otPlatAlarmMilliGetNow(); uint32_t busy = 1; - while (busy && ((otPlatAlarmGetNow() - start) < aTimeout)) + while (busy && ((otPlatAlarmMilliGetNow() - start) < aTimeout)) { busy = HWREG(FLASH_CTRL_FCTL) & FLASH_CTRL_FCTL_BUSY; } diff --git a/examples/platforms/cc2650/alarm.c b/examples/platforms/cc2650/alarm.c index adffe9c59..f44650056 100644 --- a/examples/platforms/cc2650/alarm.c +++ b/examples/platforms/cc2650/alarm.c @@ -31,7 +31,7 @@ #include #include -#include +#include #include /** @@ -56,9 +56,9 @@ void cc2650AlarmInit(void) } /** - * Function documented in platform/alarm.h + * Function documented in platform/alarm-milli.h */ -uint32_t otPlatAlarmGetNow(void) +uint32_t otPlatAlarmMilliGetNow(void) { /* * This is current value of RTC as it appears in the register. @@ -70,9 +70,9 @@ uint32_t otPlatAlarmGetNow(void) } /** - * Function documented in platform/alarm.h + * Function documented in platform/alarm-milli.h */ -void otPlatAlarmStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt) +void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt) { (void)aInstance; sTime0 = aT0; @@ -81,9 +81,9 @@ void otPlatAlarmStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt) } /** - * Function documented in platform/alarm.h + * Function documented in platform/alarm-milli.h */ -void otPlatAlarmStop(otInstance *aInstance) +void otPlatAlarmMilliStop(otInstance *aInstance) { (void)aInstance; sIsRunning = false; @@ -99,7 +99,7 @@ void cc2650AlarmProcess(otInstance *aInstance) if (sIsRunning) { /* unsinged subtraction will result in the absolute offset */ - offsetTime = otPlatAlarmGetNow() - sTime0; + offsetTime = otPlatAlarmMilliGetNow() - sTime0; if (sAlarmTime <= offsetTime) { @@ -113,7 +113,7 @@ void cc2650AlarmProcess(otInstance *aInstance) else #endif /* OPENTHREAD_ENABLE_DIAG */ { - otPlatAlarmFired(aInstance); + otPlatAlarmMilliFired(aInstance); } } } diff --git a/examples/platforms/da15000/alarm.c b/examples/platforms/da15000/alarm.c index 3c7389b60..1bb2ede60 100644 --- a/examples/platforms/da15000/alarm.c +++ b/examples/platforms/da15000/alarm.c @@ -36,7 +36,7 @@ #include #include -#include +#include #include "hw_timer0.h" #include "hw_gpio.h" @@ -57,7 +57,7 @@ void da15000AlarmProcess(otInstance *aInstance) if ((sIsRunning) && (sAlarm <= sCounter)) { sIsRunning = false; - otPlatAlarmFired(aInstance); + otPlatAlarmMilliFired(aInstance); } } @@ -72,12 +72,12 @@ void da15000AlarmInit(void) hw_timer0_set_on_clock_div(false); } -uint32_t otPlatAlarmGetNow(void) +uint32_t otPlatAlarmMilliGetNow(void) { return sCounter; } -void otPlatAlarmStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt) +void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt) { (void)aInstance; sAlarm = t0 + dt; @@ -97,7 +97,7 @@ void otPlatAlarmStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt) hw_timer0_unfreeze(); } -void otPlatAlarmStop(otInstance *aInstance) +void otPlatAlarmMilliStop(otInstance *aInstance) { (void)aInstance; sIsRunning = false; diff --git a/examples/platforms/da15000/flash.c b/examples/platforms/da15000/flash.c index 9164aaf98..ca5667cd8 100644 --- a/examples/platforms/da15000/flash.c +++ b/examples/platforms/da15000/flash.c @@ -28,7 +28,7 @@ #include #include -#include +#include #include "hw_qspi.h" #include "qspi_automode.h" @@ -81,9 +81,9 @@ uint32_t utilsFlashGetSize(void) otError utilsFlashStatusWait(uint32_t aTimeout) { - sWaitStatusTimeout = otPlatAlarmGetNow(); + sWaitStatusTimeout = otPlatAlarmMilliGetNow(); - while (qspi_get_erase_status() && ((otPlatAlarmGetNow() - sWaitStatusTimeout) < aTimeout)); + while (qspi_get_erase_status() && ((otPlatAlarmMilliGetNow() - sWaitStatusTimeout) < aTimeout)); if (qspi_get_erase_status()) { diff --git a/examples/platforms/da15000/platform.c b/examples/platforms/da15000/platform.c index d9a362a5b..3cdd10950 100644 --- a/examples/platforms/da15000/platform.c +++ b/examples/platforms/da15000/platform.c @@ -35,7 +35,7 @@ #include #include -#include +#include #include #include "platform-da15000.h" @@ -107,13 +107,13 @@ void ExampleProcess(otInstance *aInstance) devRole = otThreadGetDeviceRole(aInstance); - if (sBlink == false && otPlatAlarmGetNow() != 0) + if (sBlink == false && otPlatAlarmMilliGetNow() != 0) { - sMsCounterInit = otPlatAlarmGetNow(); + sMsCounterInit = otPlatAlarmMilliGetNow(); sBlink = true; } - sMsCounter = otPlatAlarmGetNow() - sMsCounterInit; + sMsCounter = otPlatAlarmMilliGetNow() - sMsCounterInit; switch (devRole) { @@ -136,7 +136,7 @@ void ExampleProcess(otInstance *aInstance) if ((thrValue != 0x00) && (sMsCounter >= thrValue)) { hw_gpio_toggle(HW_GPIO_PORT_1, HW_GPIO_PIN_5); - sMsCounterInit = otPlatAlarmGetNow(); + sMsCounterInit = otPlatAlarmMilliGetNow(); } if (thrValue == 0) diff --git a/examples/platforms/da15000/radio.c b/examples/platforms/da15000/radio.c index d4fac5f0f..cf4acafed 100644 --- a/examples/platforms/da15000/radio.c +++ b/examples/platforms/da15000/radio.c @@ -32,7 +32,7 @@ */ #include -#include +#include #include #include "utils/code_utils.h" @@ -222,10 +222,10 @@ otError otPlatRadioSleep(otInstance *aInstance) if (sRadioState == OT_RADIO_STATE_RECEIVE && sSleepInitDelay == 0) { - sSleepInitDelay = otPlatAlarmGetNow(); + sSleepInitDelay = otPlatAlarmMilliGetNow(); return OT_ERROR_NONE; } - else if ((otPlatAlarmGetNow() - sSleepInitDelay) < dg_configINITIAL_SLEEP_DELAY_TIME) + else if ((otPlatAlarmMilliGetNow() - sSleepInitDelay) < dg_configINITIAL_SLEEP_DELAY_TIME) { return OT_ERROR_NONE; } diff --git a/examples/platforms/efr32/alarm.c b/examples/platforms/efr32/alarm.c index 9406ad891..de4440681 100644 --- a/examples/platforms/efr32/alarm.c +++ b/examples/platforms/efr32/alarm.c @@ -36,7 +36,7 @@ #include #include -#include +#include #include #include @@ -54,7 +54,7 @@ void efr32AlarmInit(void) { } -uint32_t otPlatAlarmGetNow(void) +uint32_t otPlatAlarmMilliGetNow(void) { uint32_t timer_lo; @@ -70,7 +70,7 @@ uint32_t otPlatAlarmGetNow(void) return (((uint64_t)sTimerHi << 32) | sTimerLo) / 1000; } -void otPlatAlarmStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt) +void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt) { (void)aInstance; sAlarmT0 = t0; @@ -78,7 +78,7 @@ void otPlatAlarmStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt) sIsRunning = true; } -void otPlatAlarmStop(otInstance *aInstance) +void otPlatAlarmMilliStop(otInstance *aInstance) { (void)aInstance; sIsRunning = false; @@ -86,7 +86,7 @@ void otPlatAlarmStop(otInstance *aInstance) void efr32AlarmProcess(otInstance *aInstance) { - uint32_t now = otPlatAlarmGetNow(); + uint32_t now = otPlatAlarmMilliGetNow(); uint32_t expires; bool fire = false; @@ -116,7 +116,7 @@ void efr32AlarmProcess(otInstance *aInstance) else #endif { - otPlatAlarmFired(aInstance); + otPlatAlarmMilliFired(aInstance); } } diff --git a/examples/platforms/efr32/diag.c b/examples/platforms/efr32/diag.c index 4c2db4591..98807d5e6 100644 --- a/examples/platforms/efr32/diag.c +++ b/examples/platforms/efr32/diag.c @@ -38,7 +38,7 @@ #include #include -#include +#include #include #include "platform-efr32.h" diff --git a/examples/platforms/efr32/flash.c b/examples/platforms/efr32/flash.c index a8bd52157..49c5c74a9 100644 --- a/examples/platforms/efr32/flash.c +++ b/examples/platforms/efr32/flash.c @@ -32,7 +32,7 @@ */ #include -#include +#include #include "utils/code_utils.h" #include "utils/flash.h" @@ -93,7 +93,7 @@ otError utilsFlashErasePage(uint32_t aAddress) otError utilsFlashStatusWait(uint32_t aTimeout) { otError error = OT_ERROR_BUSY; - uint32_t start = otPlatAlarmGetNow(); + uint32_t start = otPlatAlarmMilliGetNow(); do { @@ -103,7 +103,7 @@ otError utilsFlashStatusWait(uint32_t aTimeout) break; } } - while (aTimeout && ((otPlatAlarmGetNow() - start) < aTimeout)); + while (aTimeout && ((otPlatAlarmMilliGetNow() - start) < aTimeout)); return error; } diff --git a/examples/platforms/emsk/alarm.c b/examples/platforms/emsk/alarm.c index 53e0d618f..58c132ec1 100755 --- a/examples/platforms/emsk/alarm.c +++ b/examples/platforms/emsk/alarm.c @@ -34,7 +34,7 @@ #include #include -#include "openthread/platform/alarm.h" +#include "openthread/platform/alarm-milli.h" #include "platform-emsk.h" static uint32_t sCounter = 0; @@ -46,19 +46,19 @@ void emskAlarmInit(void) sCounter = OSP_GET_CUR_MS(); } -uint32_t otPlatAlarmGetNow(void) +uint32_t otPlatAlarmMilliGetNow(void) { return (OSP_GET_CUR_MS() - sCounter); } -void otPlatAlarmStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt) +void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt) { (void)aInstance; expires = t0 + dt; sIsRunning = true; } -void otPlatAlarmStop(otInstance *aInstance) +void otPlatAlarmMilliStop(otInstance *aInstance) { (void)aInstance; sIsRunning = false; @@ -72,7 +72,7 @@ void emskAlarmUpdateTimeout(int32_t *aTimeout) if (sIsRunning) { - remaining = (int32_t)(expires - otPlatAlarmGetNow()); + remaining = (int32_t)(expires - otPlatAlarmMilliGetNow()); if (remaining > 0) { @@ -99,12 +99,12 @@ void emskAlarmProcess(otInstance *aInstance) if (sIsRunning) { - remaining = (int32_t)(expires - otPlatAlarmGetNow()); + remaining = (int32_t)(expires - otPlatAlarmMilliGetNow()); if (remaining <= 0) { sIsRunning = false; - otPlatAlarmFired(aInstance); + otPlatAlarmMilliFired(aInstance); } } diff --git a/examples/platforms/emsk/flash.c b/examples/platforms/emsk/flash.c index 890ede8f2..b789ff0a8 100644 --- a/examples/platforms/emsk/flash.c +++ b/examples/platforms/emsk/flash.c @@ -33,7 +33,7 @@ */ #include -#include "openthread/platform/alarm.h" +#include "openthread/platform/alarm-milli.h" #include #include #include "platform-emsk.h" @@ -105,11 +105,11 @@ exit: otError utilsFlashStatusWait(uint32_t aTimeout) { otError error = OT_ERROR_NONE; - uint32_t start = otPlatAlarmGetNow(); + uint32_t start = otPlatAlarmMilliGetNow(); bool busy = true; uint32_t status = 0x01; - while (busy && ((otPlatAlarmGetNow() - start) < aTimeout)) + while (busy && ((otPlatAlarmMilliGetNow() - start) < aTimeout)) { status = flash_read_status(); busy = status & 0x01; diff --git a/examples/platforms/kw41z/alarm.c b/examples/platforms/kw41z/alarm.c index 5a660bf7f..1463a78c0 100644 --- a/examples/platforms/kw41z/alarm.c +++ b/examples/platforms/kw41z/alarm.c @@ -39,7 +39,7 @@ #include "openthread/openthread.h" #include "openthread/platform/platform.h" -#include "openthread/platform/alarm.h" +#include "openthread/platform/alarm-milli.h" #include "openthread/platform/diag.h" static volatile uint32_t sTime = 0; @@ -74,24 +74,24 @@ void kw41zAlarmProcess(otInstance *aInstance) else #endif { - otPlatAlarmFired(aInstance); + otPlatAlarmMilliFired(aInstance); } } } -void otPlatAlarmStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt) +void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt) { (void)aInstance; sAlarmTime = aT0 + aDt; } -void otPlatAlarmStop(otInstance *aInstance) +void otPlatAlarmMilliStop(otInstance *aInstance) { (void)aInstance; sAlarmTime = 0; } -uint32_t otPlatAlarmGetNow(void) +uint32_t otPlatAlarmMilliGetNow(void) { return sTime; } diff --git a/examples/platforms/kw41z/diag.c b/examples/platforms/kw41z/diag.c index 28648efd0..6f4d9c664 100644 --- a/examples/platforms/kw41z/diag.c +++ b/examples/platforms/kw41z/diag.c @@ -38,7 +38,7 @@ #include "fsl_device_registers.h" #include "openthread/openthread.h" -#include "openthread/platform/alarm.h" +#include "openthread/platform/alarm-milli.h" #include "openthread/platform/radio.h" /** diff --git a/examples/platforms/kw41z/flash.c b/examples/platforms/kw41z/flash.c index 8ee8d03c8..eb050c981 100644 --- a/examples/platforms/kw41z/flash.c +++ b/examples/platforms/kw41z/flash.c @@ -29,7 +29,7 @@ #include #include "fsl_device_registers.h" #include "fsl_flash.h" -#include "openthread/platform/alarm.h" +#include "openthread/platform/alarm-milli.h" #include #include @@ -78,7 +78,7 @@ otError utilsFlashErasePage(uint32_t aAddress) otError utilsFlashStatusWait(uint32_t aTimeout) { otError error = OT_ERROR_BUSY; - uint32_t start = otPlatAlarmGetNow(); + uint32_t start = otPlatAlarmMilliGetNow(); do { @@ -88,7 +88,7 @@ otError utilsFlashStatusWait(uint32_t aTimeout) break; } } - while (aTimeout && ((otPlatAlarmGetNow() - start) < aTimeout)); + while (aTimeout && ((otPlatAlarmMilliGetNow() - start) < aTimeout)); return error; } diff --git a/examples/platforms/nrf52840/alarm.c b/examples/platforms/nrf52840/alarm.c index 5f033a7fb..bf2cd0db1 100644 --- a/examples/platforms/nrf52840/alarm.c +++ b/examples/platforms/nrf52840/alarm.c @@ -37,9 +37,9 @@ #include #include -#include +#include +#include #include -#include #include "platform-config.h" #include "cmsis/core_cmFunc.h" @@ -100,9 +100,6 @@ static const AlarmChannelData sChannelData[kNumTimers] = } }; -static otPlatUsecAlarmHandler sUsecHandler = NULL; ///< Handler called when usec alarm fires. -static void *sUsecContext = NULL; ///< The context information passed to the usec handler callback. - static void HandleOverflow(void); static inline uint32_t TimeToTicks(uint32_t aTime, AlarmIndex aIndex) @@ -335,7 +332,7 @@ void nrf5AlarmProcess(otInstance *aInstance) else #endif { - otPlatAlarmFired(aInstance); + otPlatAlarmMilliFired(aInstance); } } @@ -343,16 +340,16 @@ void nrf5AlarmProcess(otInstance *aInstance) { sTimerData[kUsTimer].mFireAlarm = false; - sUsecHandler(sUsecContext); + otPlatAlarmMicroFired(aInstance); } } -uint32_t otPlatAlarmGetNow(void) +uint32_t otPlatAlarmMilliGetNow(void) { return (uint32_t)(AlarmGetCurrentTime() / US_PER_MS); } -void otPlatAlarmStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt) +void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt) { (void)aInstance; uint32_t targetTime = aT0 + aDt; @@ -360,31 +357,27 @@ void otPlatAlarmStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt) AlarmStartAt(targetTime, kMsTimer); } -void otPlatAlarmStop(otInstance *aInstance) +void otPlatAlarmMilliStop(otInstance *aInstance) { (void)aInstance; AlarmStop(kMsTimer); } -uint32_t otPlatUsecAlarmGetNow(void) +uint32_t otPlatAlarmMicroGetNow(void) { return (uint32_t)AlarmGetCurrentTime(); } -void otPlatUsecAlarmStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt, - otPlatUsecAlarmHandler aHandler, void *aContext) +void otPlatAlarmMicroStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt) { (void)aInstance; uint32_t targetTime = aT0 + aDt; AlarmStartAt(targetTime, kUsTimer); - - sUsecHandler = aHandler; - sUsecContext = aContext; } -void otPlatUsecAlarmStop(otInstance *aInstance) +void otPlatAlarmMicroStop(otInstance *aInstance) { (void)aInstance; diff --git a/examples/platforms/nrf52840/diag.c b/examples/platforms/nrf52840/diag.c index 3cbf34184..31212f295 100644 --- a/examples/platforms/nrf52840/diag.c +++ b/examples/platforms/nrf52840/diag.c @@ -32,8 +32,8 @@ #include #include +#include #include -#include #include #include @@ -150,17 +150,17 @@ static void processTransmit(otInstance *aInstance, int argc, char *argv[], char } else if (strcmp(argv[0], "stop") == 0) { - otPlatAlarmStop(aInstance); + otPlatAlarmMilliStop(aInstance); snprintf(aOutput, aOutputMaxLen, "diagnostic message transmission is stopped\r\nstatus 0x%02x\r\n", error); sTransmitActive = false; } else if (strcmp(argv[0], "start") == 0) { - otPlatAlarmStop(aInstance); + otPlatAlarmMilliStop(aInstance); sTransmitActive = true; sTxCount = sTxRequestedCount; - uint32_t now = otPlatAlarmGetNow(); - otPlatAlarmStartAt(aInstance, now, sTxPeriod); + uint32_t now = otPlatAlarmMilliGetNow(); + otPlatAlarmMilliStartAt(aInstance, now, sTxPeriod); snprintf(aOutput, aOutputMaxLen, "sending %" PRId32 " diagnostic messages with %" PRIu32 " ms interval\r\nstatus 0x%02x\r\n", sTxRequestedCount, sTxPeriod, error); @@ -300,13 +300,13 @@ void otPlatDiagAlarmCallback(otInstance *aInstance) sTxCount--; } - uint32_t now = otPlatAlarmGetNow(); - otPlatAlarmStartAt(aInstance, now, sTxPeriod); + uint32_t now = otPlatAlarmMilliGetNow(); + otPlatAlarmMilliStartAt(aInstance, now, sTxPeriod); } else { sTransmitActive = false; - otPlatAlarmStop(aInstance); + otPlatAlarmMilliStop(aInstance); otPlatLog(OT_LOG_LEVEL_DEBG, OT_LOG_REGION_PLATFORM, "Transmit done"); } } diff --git a/examples/platforms/nrf52840/flash.c b/examples/platforms/nrf52840/flash.c index 2582a2ef7..176ac6710 100644 --- a/examples/platforms/nrf52840/flash.c +++ b/examples/platforms/nrf52840/flash.c @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include @@ -88,7 +88,7 @@ otError utilsFlashStatusWait(uint32_t aTimeout) } else { - uint32_t startTime = otPlatAlarmGetNow(); + uint32_t startTime = otPlatAlarmMilliGetNow(); do { @@ -98,7 +98,7 @@ otError utilsFlashStatusWait(uint32_t aTimeout) break; } } - while (otPlatAlarmGetNow() - startTime < aTimeout); + while (otPlatAlarmMilliGetNow() - startTime < aTimeout); } return error; diff --git a/examples/platforms/nrf52840/flash_sd.c b/examples/platforms/nrf52840/flash_sd.c index d99d3b41b..e829179ed 100644 --- a/examples/platforms/nrf52840/flash_sd.c +++ b/examples/platforms/nrf52840/flash_sd.c @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include @@ -80,7 +80,7 @@ void nrf5SdSocFlashProcess(uint32_t aEvtId) static otError sdFlashSingleWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize) { uint32_t retval; - uint32_t startTime = otPlatAlarmGetNow(); + uint32_t startTime = otPlatAlarmMilliGetNow(); // Expect SotfDevice Flash Complete event. sFlashStatus = FLASH_STATUS_PENDING; @@ -97,7 +97,7 @@ static otError sdFlashSingleWrite(uint32_t aAddress, uint8_t *aData, uint32_t aS break; } } - while (otPlatAlarmGetNow() - startTime < FLASH_TIMEOUT); + while (otPlatAlarmMilliGetNow() - startTime < FLASH_TIMEOUT); if (sFlashStatus != FLASH_STATUS_SUCCESS) { @@ -113,7 +113,7 @@ static otError sdFlashSingleWrite(uint32_t aAddress, uint8_t *aData, uint32_t aS otError nrf5FlashPageErase(uint32_t aAddress) { uint32_t retval; - uint32_t startTime = otPlatAlarmGetNow(); + uint32_t startTime = otPlatAlarmMilliGetNow(); // Expect SotfDevice Flash Complete event. sFlashStatus = FLASH_STATUS_PENDING; @@ -130,7 +130,7 @@ otError nrf5FlashPageErase(uint32_t aAddress) break; } } - while (otPlatAlarmGetNow() - startTime < FLASH_TIMEOUT); + while (otPlatAlarmMilliGetNow() - startTime < FLASH_TIMEOUT); if (sFlashStatus != FLASH_STATUS_SUCCESS) { diff --git a/examples/platforms/nrf52840/logging.c b/examples/platforms/nrf52840/logging.c index 961d16800..8947cccf3 100644 --- a/examples/platforms/nrf52840/logging.c +++ b/examples/platforms/nrf52840/logging.c @@ -36,7 +36,7 @@ #include #include -#include +#include #include #include "platform-nrf5.h" @@ -103,7 +103,7 @@ static inline const char *levelToString(otLogLevel aLogLevel) static inline uint16_t logTimestamp(char *aLogString, uint16_t aMaxSize) { return snprintf(aLogString, aMaxSize, "%s[%010ld]", RTT_COLOR_CODE_CYAN, - otPlatAlarmGetNow()); + otPlatAlarmMilliGetNow()); } #endif diff --git a/examples/platforms/nrf52840/openthread-core-nrf52840-config.h b/examples/platforms/nrf52840/openthread-core-nrf52840-config.h index 7330486ac..a54b0a7a7 100644 --- a/examples/platforms/nrf52840/openthread-core-nrf52840-config.h +++ b/examples/platforms/nrf52840/openthread-core-nrf52840-config.h @@ -84,12 +84,12 @@ #define OPENTHREAD_CONFIG_ENABLE_SOFTWARE_RETRANSMIT 1 /** - * @def OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_BACKOFF_TIMER + * @def OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER * - * Define to 1 if you want to enable microsecond backoff timer implemented in platform. + * Define to 1 if you want to support microsecond timer in platform. * */ -#define OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_BACKOFF_TIMER 1 +#define OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER 1 /** * @def SETTINGS_CONFIG_BASE_ADDRESS diff --git a/examples/platforms/posix/alarm.c b/examples/platforms/posix/alarm.c index 778d45126..23c9f428f 100644 --- a/examples/platforms/posix/alarm.c +++ b/examples/platforms/posix/alarm.c @@ -32,7 +32,7 @@ #include #include -#include +#include #include static bool s_is_running = false; @@ -44,7 +44,7 @@ void platformAlarmInit(void) gettimeofday(&s_start, NULL); } -uint32_t otPlatAlarmGetNow(void) +uint32_t otPlatAlarmMilliGetNow(void) { struct timeval tv; @@ -54,14 +54,14 @@ uint32_t otPlatAlarmGetNow(void) return (uint32_t)((tv.tv_sec * 1000) + (tv.tv_usec / 1000)); } -void otPlatAlarmStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt) +void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt) { (void)aInstance; s_alarm = t0 + dt; s_is_running = true; } -void otPlatAlarmStop(otInstance *aInstance) +void otPlatAlarmMilliStop(otInstance *aInstance) { (void)aInstance; s_is_running = false; @@ -78,7 +78,7 @@ void platformAlarmUpdateTimeout(struct timeval *aTimeout) if (s_is_running) { - remaining = (int32_t)(s_alarm - otPlatAlarmGetNow()); + remaining = (int32_t)(s_alarm - otPlatAlarmMilliGetNow()); if (remaining > 0) { @@ -104,7 +104,7 @@ void platformAlarmProcess(otInstance *aInstance) if (s_is_running) { - remaining = (int32_t)(s_alarm - otPlatAlarmGetNow()); + remaining = (int32_t)(s_alarm - otPlatAlarmMilliGetNow()); if (remaining <= 0) { @@ -119,7 +119,7 @@ void platformAlarmProcess(otInstance *aInstance) else #endif { - otPlatAlarmFired(aInstance); + otPlatAlarmMilliFired(aInstance); } } } diff --git a/examples/platforms/posix/diag.c b/examples/platforms/posix/diag.c index 88ec53d9f..662a7f9ad 100644 --- a/examples/platforms/posix/diag.c +++ b/examples/platforms/posix/diag.c @@ -35,7 +35,7 @@ #include #include -#include +#include #include /** diff --git a/examples/platforms/posix/flash.c b/examples/platforms/posix/flash.c index e4a62ac59..6bd191ec6 100644 --- a/examples/platforms/posix/flash.c +++ b/examples/platforms/posix/flash.c @@ -40,7 +40,7 @@ #include "utils/code_utils.h" #include "utils/flash.h" -static int sFlashFd; +static int sFlashFd = -1; uint32_t sEraseAddress; enum diff --git a/examples/platforms/posix/platform.c b/examples/platforms/posix/platform.c index 25f143680..3ab6209a7 100644 --- a/examples/platforms/posix/platform.c +++ b/examples/platforms/posix/platform.c @@ -48,7 +48,7 @@ #include #include -#include +#include uint32_t NODE_ID = 1; uint32_t WELLKNOWN_NODE_ID = 34; diff --git a/include/openthread/platform/Makefile.am b/include/openthread/platform/Makefile.am index dda796790..3108989b7 100644 --- a/include/openthread/platform/Makefile.am +++ b/include/openthread/platform/Makefile.am @@ -29,7 +29,8 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am ot_platform_headers =\ - alarm.h \ + alarm-micro.h \ + alarm-milli.h \ diag.h \ memory.h \ misc.h \ @@ -42,7 +43,6 @@ ot_platform_headers =\ settings.h \ messagepool.h \ toolchain.h \ - usec-alarm.h \ $(NULL) ot_platformdir = $(includedir)/openthread/platform diff --git a/include/openthread/platform/usec-alarm.h b/include/openthread/platform/alarm-micro.h similarity index 77% rename from include/openthread/platform/usec-alarm.h rename to include/openthread/platform/alarm-micro.h index 0c7dd6290..b3825e580 100644 --- a/include/openthread/platform/usec-alarm.h +++ b/include/openthread/platform/alarm-micro.h @@ -32,8 +32,8 @@ * This file includes the platform abstraction for the microsecond alarm service. */ -#ifndef USEC_ALARM_H_ -#define USEC_ALARM_H_ +#ifndef ALARM_MICRO_H_ +#define ALARM_MICRO_H_ #include @@ -50,26 +50,15 @@ extern "C" { * */ -/** - * This defines the callback for indicating when the alarm has expired. - * - * @param[in] aContext A pointer to arbitrary context information. - * - */ -typedef void (*otPlatUsecAlarmHandler)(void *aContext); - /** * Set the alarm to fire at @p aDt microseconds after @p aT0. * * @param[in] aInstance The OpenThread instance structure. * @param[in] aT0 The reference time. * @param[in] aDt The time delay in microseconds from @p aT0. - * @param[in] aHandler A pointer to a function that is called when the timer expires. - * @param[in] aContext A pointer to arbitrary context information. * */ -void otPlatUsecAlarmStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt, - otPlatUsecAlarmHandler aHandler, void *aContext); +void otPlatAlarmMicroStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt); /** * Stop the alarm. @@ -77,7 +66,7 @@ void otPlatUsecAlarmStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt, * @param[in] aInstance The OpenThread instance structure. * */ -void otPlatUsecAlarmStop(otInstance *aInstance); +void otPlatAlarmMicroStop(otInstance *aInstance); /** * Get the current time. @@ -85,7 +74,14 @@ void otPlatUsecAlarmStop(otInstance *aInstance); * @param[out] aNow The current time in microseconds. * */ -uint32_t otPlatUsecAlarmGetNow(void); +uint32_t otPlatAlarmMicroGetNow(void); + +/** + * Signal that the alarm has fired. + * + * @param[in] aInstance The OpenThread instance structure. + */ +extern void otPlatAlarmMicroFired(otInstance *aInstance); /** * @} @@ -96,4 +92,4 @@ uint32_t otPlatUsecAlarmGetNow(void); } // extern "C" #endif -#endif // USEC_ALARM_H_ +#endif // ALARM_MICRO_H_ diff --git a/include/openthread/platform/alarm.h b/include/openthread/platform/alarm-milli.h similarity index 90% rename from include/openthread/platform/alarm.h rename to include/openthread/platform/alarm-milli.h index 050ee7efe..ae49609cb 100644 --- a/include/openthread/platform/alarm.h +++ b/include/openthread/platform/alarm-milli.h @@ -32,8 +32,8 @@ * This file includes the platform abstraction for the millisecond alarm service. */ -#ifndef ALARM_H_ -#define ALARM_H_ +#ifndef ALARM_MILLI_H_ +#define ALARM_MILLI_H_ #include @@ -60,28 +60,28 @@ extern "C" { * @param[in] aT0 The reference time. * @param[in] aDt The time delay in milliseconds from @p aT0. */ -void otPlatAlarmStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt); +void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt); /** * Stop the alarm. * * @param[in] aInstance The OpenThread instance structure. */ -void otPlatAlarmStop(otInstance *aInstance); +void otPlatAlarmMilliStop(otInstance *aInstance); /** * Get the current time. * * @returns The current time in milliseconds. */ -uint32_t otPlatAlarmGetNow(void); +uint32_t otPlatAlarmMilliGetNow(void); /** * Signal that the alarm has fired. * * @param[in] aInstance The OpenThread instance structure. */ -extern void otPlatAlarmFired(otInstance *aInstance); +extern void otPlatAlarmMilliFired(otInstance *aInstance); /** * Signal diagnostics module that the alarm has fired. @@ -99,4 +99,4 @@ extern void otPlatDiagAlarmFired(otInstance *aInstance); } // extern "C" #endif -#endif // ALARM_H_ +#endif // ALARM_MILLI_H_ diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 8ef49f8f2..4d0a7689e 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -243,7 +243,7 @@ Interpreter::Interpreter(otInstance *aInstance): mLength(8), mCount(1), mInterval(1000), - mPingTimer(aInstance->mIp6.mTimerScheduler, &Interpreter::s_HandlePingTimer, this), + mPingTimer(aInstance->mIp6, &Interpreter::s_HandlePingTimer, this), #if OPENTHREAD_ENABLE_DNS_CLIENT mResolvingInProgress(0), #endif @@ -1607,7 +1607,7 @@ void Interpreter::HandleIcmpReceive(Message &aMessage, const Ip6::MessageInfo &a if (aMessage.Read(aMessage.GetOffset(), sizeof(uint32_t), ×tamp) >= static_cast(sizeof(uint32_t))) { - mServer->OutputFormat(" time=%dms", Timer::GetNow() - HostSwap32(timestamp)); + mServer->OutputFormat(" time=%dms", TimerMilli::GetNow() - HostSwap32(timestamp)); } mServer->OutputFormat("\r\n"); @@ -1690,7 +1690,7 @@ void Interpreter::s_HandlePingTimer(Timer &aTimer) void Interpreter::HandlePingTimer() { otError error = OT_ERROR_NONE; - uint32_t timestamp = HostSwap32(Timer::GetNow()); + uint32_t timestamp = HostSwap32(TimerMilli::GetNow()); otMessage *message; const otMessageInfo *messageInfo = static_cast(&mMessageInfo); diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index e44b9aafb..90c9aed0e 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -364,7 +364,7 @@ private: uint16_t mLength; uint16_t mCount; uint32_t mInterval; - Timer mPingTimer; + TimerMilli mPingTimer; otNetifAddress mSlaacAddresses[OPENTHREAD_CONFIG_NUM_SLAAC_ADDRESSES]; #if OPENTHREAD_ENABLE_DHCP6_CLIENT diff --git a/src/core/api/instance_api.cpp b/src/core/api/instance_api.cpp index 1cf4b5dff..60987ecdd 100644 --- a/src/core/api/instance_api.cpp +++ b/src/core/api/instance_api.cpp @@ -64,11 +64,6 @@ ot::MeshForwarder &otGetMeshForwarder(void) return sInstance->mThreadNetif.GetMeshForwarder(); } -ot::TimerScheduler &otGetTimerScheduler(void) -{ - return sInstance->mIp6.mTimerScheduler; -} - ot::TaskletScheduler &otGetTaskletScheduler(void) { return sInstance->mIp6.mTaskletScheduler; diff --git a/src/core/api/link_raw.hpp b/src/core/api/link_raw.hpp index 53ed61252..e39629503 100644 --- a/src/core/api/link_raw.hpp +++ b/src/core/api/link_raw.hpp @@ -131,10 +131,12 @@ private: kTimerReasonEnergyScanComplete, }; - Timer mTimer; + TimerMilli mTimer; TimerReason mTimerReason; +#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER + TimerMicro mTimerMicro; +#endif - static void HandleTimer(void *aContext); static void HandleTimer(Timer &aTimer); void HandleTimer(void); diff --git a/src/core/api/link_raw_api.cpp b/src/core/api/link_raw_api.cpp index 499af271f..558be9f9f 100644 --- a/src/core/api/link_raw_api.cpp +++ b/src/core/api/link_raw_api.cpp @@ -34,7 +34,6 @@ #include #include -#include #include "openthread-instance.h" #include "common/debug.hpp" @@ -270,8 +269,11 @@ LinkRaw::LinkRaw(otInstance &aInstance): mTransmitDoneCallback(NULL), mEnergyScanDoneCallback(NULL) #if OPENTHREAD_LINKRAW_TIMER_REQUIRED - , mTimer(aInstance.mIp6.mTimerScheduler, &LinkRaw::HandleTimer, this) + , mTimer(aInstance.mIp6, &LinkRaw::HandleTimer, this) , mTimerReason(kTimerReasonNone) +#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER + , mTimerMicro(aInstance.mIp6, &LinkRaw::HandleTimer, this) +#endif #endif // OPENTHREAD_LINKRAW_TIMER_REQUIRED #if OPENTHREAD_CONFIG_ENABLE_SOFTWARE_ENERGY_SCAN , mEnergyScanTask(aInstance.mIp6.mTaskletScheduler, &LinkRaw::HandleEnergyScanTask, this) @@ -479,11 +481,6 @@ void LinkRaw::InvokeEnergyScanDone(int8_t aEnergyScanMaxRssi) #if OPENTHREAD_LINKRAW_TIMER_REQUIRED -void LinkRaw::HandleTimer(void *aContext) -{ - static_cast(aContext)->HandleTimer(); -} - void LinkRaw::HandleTimer(Timer &aTimer) { GetOwner(aTimer).HandleTimer(); @@ -565,11 +562,11 @@ void LinkRaw::StartCsmaBackoff(void) otLogDebgPlat(aInstance, "LinkRaw Starting RetransmitTimeout Timer (%d ms)", backoff); mTimerReason = kTimerReasonRetransmitTimeout; -#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_BACKOFF_TIMER - otPlatUsecAlarmStartAt(&mInstance, otPlatUsecAlarmGetNow(), backoff, &HandleTimer, this); -#else // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_BACKOFF_TIMER +#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER + mTimerMicro.Start(backoff); +#else // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER mTimer.Start(backoff / 1000UL); -#endif // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_BACKOFF_TIMER +#endif // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER } #endif // OPENTHREAD_CONFIG_ENABLE_SOFTWARE_RETRANSMIT diff --git a/src/core/api/thread_api.cpp b/src/core/api/thread_api.cpp index f68ce7d5d..bf68c4769 100644 --- a/src/core/api/thread_api.cpp +++ b/src/core/api/thread_api.cpp @@ -317,7 +317,8 @@ otError otThreadGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo) aParentInfo->mPathCost = parent->GetCost(); aParentInfo->mLinkQualityIn = parent->GetLinkInfo().GetLinkQuality(aInstance->mThreadNetif.GetMac().GetNoiseFloor()); aParentInfo->mLinkQualityOut = parent->GetLinkQualityOut(); - aParentInfo->mAge = static_cast(Timer::MsecToSec(Timer::GetNow() - parent->GetLastHeard())); + aParentInfo->mAge = static_cast(TimerMilli::MsecToSec(TimerMilli::GetNow() - + parent->GetLastHeard())); aParentInfo->mAllocated = parent->IsAllocated(); aParentInfo->mLinkEstablished = parent->GetState() == Neighbor::kStateValid; diff --git a/src/core/coap/coap.cpp b/src/core/coap/coap.cpp index 3c380ebc9..2fd2cfaed 100644 --- a/src/core/coap/coap.cpp +++ b/src/core/coap/coap.cpp @@ -52,7 +52,7 @@ namespace Coap { Coap::Coap(ThreadNetif &aNetif): ThreadNetifLocator(aNetif), mSocket(aNetif.GetIp6().mUdp), - mRetransmissionTimer(aNetif.GetIp6().mTimerScheduler, &Coap::HandleRetransmissionTimer, this), + mRetransmissionTimer(aNetif.GetIp6(), &Coap::HandleRetransmissionTimer, this), mResources(NULL), mContext(NULL), mInterceptor(NULL), @@ -305,7 +305,7 @@ void Coap::HandleRetransmissionTimer(Timer &aTimer) void Coap::HandleRetransmissionTimer(void) { - uint32_t now = otPlatAlarmGetNow(); + uint32_t now = TimerMilli::GetNow(); uint32_t nextDelta = 0xffffffff; CoapMetadata coapMetadata; Message *message = mPendingRequests.GetHead(); @@ -740,20 +740,20 @@ CoapMetadata::CoapMetadata(bool aConfirmable, const Ip6::MessageInfo &aMessageIn mResponseHandler = aHandler; mResponseContext = aContext; mRetransmissionCount = 0; - mRetransmissionTimeout = Timer::SecToMsec(kAckTimeout); + mRetransmissionTimeout = TimerMilli::SecToMsec(kAckTimeout); mRetransmissionTimeout += otPlatRandomGet() % - (Timer::SecToMsec(kAckTimeout) * kAckRandomFactorNumerator / kAckRandomFactorDenominator - - Timer::SecToMsec(kAckTimeout) + 1); + (TimerMilli::SecToMsec(kAckTimeout) * kAckRandomFactorNumerator / kAckRandomFactorDenominator - + TimerMilli::SecToMsec(kAckTimeout) + 1); if (aConfirmable) { // Set next retransmission timeout. - mNextTimerShot = Timer::GetNow() + mRetransmissionTimeout; + mNextTimerShot = TimerMilli::GetNow() + mRetransmissionTimeout; } else { // Set overall response timeout. - mNextTimerShot = Timer::GetNow() + kMaxTransmitWait; + mNextTimerShot = TimerMilli::GetNow() + kMaxTransmitWait; } mAcknowledged = false; @@ -761,7 +761,7 @@ CoapMetadata::CoapMetadata(bool aConfirmable, const Ip6::MessageInfo &aMessageIn } ResponsesQueue::ResponsesQueue(ThreadNetif &aNetif): - mTimer(aNetif.GetIp6().mTimerScheduler, &ResponsesQueue::HandleTimer, this) + mTimer(aNetif.GetIp6(), &ResponsesQueue::HandleTimer, this) { } @@ -870,7 +870,7 @@ void ResponsesQueue::EnqueueResponse(Message &aMessage, const Ip6::MessageInfo & if (!mTimer.IsRunning()) { - mTimer.Start(Timer::SecToMsec(kExchangeLifetime)); + mTimer.Start(TimerMilli::SecToMsec(kExchangeLifetime)); } exit: @@ -923,7 +923,7 @@ void ResponsesQueue::HandleTimer(void) { enqueuedResponseHeader.ReadFrom(*message); - if (enqueuedResponseHeader.IsEarlier(Timer::GetNow())) + if (enqueuedResponseHeader.IsEarlier(TimerMilli::GetNow())) { DequeueResponse(*message); } @@ -937,7 +937,7 @@ void ResponsesQueue::HandleTimer(void) uint32_t EnqueuedResponseHeader::GetRemainingTime(void) const { - int32_t remainingTime = static_cast(mDequeueTime - Timer::GetNow()); + int32_t remainingTime = static_cast(mDequeueTime - TimerMilli::GetNow()); return remainingTime >= 0 ? static_cast(remainingTime) : 0; } diff --git a/src/core/coap/coap.hpp b/src/core/coap/coap.hpp index bcc9dbaf9..05637c261 100644 --- a/src/core/coap/coap.hpp +++ b/src/core/coap/coap.hpp @@ -253,7 +253,7 @@ public: * */ EnqueuedResponseHeader(const Ip6::MessageInfo &aMessageInfo): - mDequeueTime(Timer::GetNow() + Timer::SecToMsec(kExchangeLifetime)), + mDequeueTime(TimerMilli::GetNow() + TimerMilli::SecToMsec(kExchangeLifetime)), mMessageInfo(aMessageInfo) {} /** @@ -413,7 +413,7 @@ private: void HandleTimer(void); MessageQueue mQueue; - Timer mTimer; + TimerMilli mTimer; }; /** @@ -695,7 +695,7 @@ private: MessageQueue mPendingRequests; uint16_t mMessageId; - Timer mRetransmissionTimer; + TimerMilli mRetransmissionTimer; Resource *mResources; diff --git a/src/core/common/locator.cpp b/src/core/common/locator.cpp index c4a66b8b8..16622709c 100644 --- a/src/core/common/locator.cpp +++ b/src/core/common/locator.cpp @@ -54,11 +54,6 @@ otInstance *MeshForwarderLocator::GetInstance(void) const return otInstanceFromThreadNetif(&GetMeshForwarder().GetNetif()); } -otInstance *TimerSchedulerLocator::GetInstance(void) const -{ - return otInstanceFromIp6(Ip6::Ip6FromTimerScheduler(&GetTimerScheduler())); -} - otInstance *TaskletSchedulerLocator::GetInstance(void) const { return otInstanceFromIp6(Ip6::Ip6FromTaskletScheduler(&GetTaskletScheduler())); diff --git a/src/core/common/locator.hpp b/src/core/common/locator.hpp index 1e38525d5..e65524b08 100644 --- a/src/core/common/locator.hpp +++ b/src/core/common/locator.hpp @@ -46,7 +46,6 @@ namespace ot { class ThreadNetif; class MeshForwarder; class TaskletScheduler; -class TimerScheduler; namespace Ip6 { class Ip6; } /** @@ -168,47 +167,6 @@ protected: MeshForwarderLocator(MeshForwarder &aMeshForwarder): Locator(aMeshForwarder) { } }; -/** - * This class implements a locator for TimerScheduler object. - * - */ -class TimerSchedulerLocator: private Locator -{ -public: - /** - * This method returns a reference to the TimerScheduler. - * - * @returns A reference to the TimerScheduler. - * - */ -#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES - TimerScheduler &GetTimerScheduler(void) const { return mLocatorObject; } -#else - TimerScheduler &GetTimerScheduler(void) const { return otGetTimerScheduler(); } -#endif - - /** - * This method returns the pointer to the parent otInstance structure. - * - * @returns The pointer to the parent otInstance structure, or NULL if the instance has been finalized. - * - */ -#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES - otInstance *GetInstance(void) const; -#else - otInstance *GetInstance(void) const { return otGetInstance(); } -#endif - -protected: - /** - * This constructor initializes the object. - * - * @param[in] aTimerScheduler A reference to the TimerScheduler. - * - */ - TimerSchedulerLocator(TimerScheduler &aTimerScheduler): Locator(aTimerScheduler) { } -}; - /** * This class implements a locator for TaskletScheduler object. * diff --git a/src/core/common/timer.cpp b/src/core/common/timer.cpp index 7a452d076..d83d2e748 100644 --- a/src/core/common/timer.cpp +++ b/src/core/common/timer.cpp @@ -37,8 +37,6 @@ #include "timer.hpp" -#include - #include "openthread-instance.h" #include "common/code_utils.hpp" #include "common/debug.hpp" @@ -47,20 +45,63 @@ namespace ot { -TimerScheduler::TimerScheduler(void): - mHead(NULL) +const TimerScheduler::AlarmApi TimerMilliScheduler::sAlarmMilliApi = { + &otPlatAlarmMilliStartAt, + &otPlatAlarmMilliStop, + &otPlatAlarmMilliGetNow +}; + +bool Timer::DoesFireBefore(const Timer &aSecondTimer, uint32_t aNow) +{ + bool retval; + bool isBeforeNow = TimerScheduler::IsStrictlyBefore(GetFireTime(), aNow); + + // Check if one timer is before `now` and the other one is not. + if (TimerScheduler::IsStrictlyBefore(aSecondTimer.GetFireTime(), aNow) != isBeforeNow) + { + // One timer is before `now` and the other one is not, so if this timer's fire time is before `now` then + // the second fire time would be after `now` and this timer would fire before the second timer. + + retval = isBeforeNow; + } + else + { + // Both timers are before `now` or both are after `now`. Either way the difference is guaranteed to be less + // than `kMaxDt` so we can safely compare the fire times directly. + + retval = TimerScheduler::IsStrictlyBefore(GetFireTime(), aSecondTimer.GetFireTime()); + } + + return retval; } -void TimerScheduler::Add(Timer &aTimer) +void TimerMilli::StartAt(uint32_t aT0, uint32_t aDt) { - Remove(aTimer); + assert(aDt <= kMaxDt); + mFireTime = aT0 + aDt; + GetTimerMilliScheduler().Add(*this); +} + +void TimerMilli::Stop(void) +{ + GetTimerMilliScheduler().Remove(*this); +} + +TimerMilliScheduler &TimerMilli::GetTimerMilliScheduler(void) const +{ + return GetIp6().mTimerMilliScheduler; +} + +void TimerScheduler::Add(Timer &aTimer, const AlarmApi &aAlarmApi) +{ + Remove(aTimer, aAlarmApi); if (mHead == NULL) { mHead = &aTimer; aTimer.mNext = NULL; - SetAlarm(); + SetAlarm(aAlarmApi); } else { @@ -69,7 +110,7 @@ void TimerScheduler::Add(Timer &aTimer) for (cur = mHead; cur; cur = cur->mNext) { - if (aTimer.DoesFireBefore(*cur)) + if (aTimer.DoesFireBefore(*cur, aAlarmApi.AlarmGetNow())) { if (prev) { @@ -80,7 +121,7 @@ void TimerScheduler::Add(Timer &aTimer) { aTimer.mNext = mHead; mHead = &aTimer; - SetAlarm(); + SetAlarm(aAlarmApi); } break; @@ -97,14 +138,14 @@ void TimerScheduler::Add(Timer &aTimer) } } -void TimerScheduler::Remove(Timer &aTimer) +void TimerScheduler::Remove(Timer &aTimer, const AlarmApi &aAlarmApi) { VerifyOrExit(aTimer.mNext != &aTimer); if (mHead == &aTimer) { mHead = aTimer.mNext; - SetAlarm(); + SetAlarm(aAlarmApi); } else { @@ -124,55 +165,43 @@ exit: return; } -void TimerScheduler::SetAlarm(void) +void TimerScheduler::SetAlarm(const AlarmApi &aAlarmApi) { if (mHead == NULL) { - otPlatAlarmStop(GetIp6()->GetInstance()); + aAlarmApi.AlarmStop(GetIp6().GetInstance()); } else { - uint32_t now = otPlatAlarmGetNow(); + uint32_t now = aAlarmApi.AlarmGetNow(); uint32_t remaining = IsStrictlyBefore(now, mHead->mFireTime) ? (mHead->mFireTime - now) : 0; - otPlatAlarmStartAt(GetIp6()->GetInstance(), now, remaining); + aAlarmApi.AlarmStartAt(GetIp6().GetInstance(), now, remaining); } } -extern "C" void otPlatAlarmFired(otInstance *aInstance) -{ - otLogFuncEntry(); - aInstance->mIp6.mTimerScheduler.ProcessTimers(); - otLogFuncExit(); -} - -void TimerScheduler::ProcessTimers(void) +void TimerScheduler::ProcessTimers(const AlarmApi &aAlarmApi) { Timer *timer = mHead; if (timer) { - if (!IsStrictlyBefore(otPlatAlarmGetNow(), timer->mFireTime)) + if (!IsStrictlyBefore(aAlarmApi.AlarmGetNow(), timer->mFireTime)) { - Remove(*timer); + Remove(*timer, aAlarmApi); timer->Fired(); } else { - SetAlarm(); + SetAlarm(aAlarmApi); } } else { - SetAlarm(); + SetAlarm(aAlarmApi); } } -Ip6::Ip6 *TimerScheduler::GetIp6(void) -{ - return Ip6::Ip6FromTimerScheduler(this); -} - bool TimerScheduler::IsStrictlyBefore(uint32_t aTimeA, uint32_t aTimeB) { uint32_t diff = aTimeA - aTimeB; @@ -185,29 +214,44 @@ bool TimerScheduler::IsStrictlyBefore(uint32_t aTimeA, uint32_t aTimeB) return ((diff & (1UL << 31)) != 0); } -bool Timer::DoesFireBefore(const Timer &aSecondTimer) +extern "C" void otPlatAlarmMilliFired(otInstance *aInstance) { - bool retval; - uint32_t now = GetNow(); - bool isBeforeNow = TimerScheduler::IsStrictlyBefore(GetFireTime(), now); - - // Check if one timer is before `now` and the other one is not. - if (TimerScheduler::IsStrictlyBefore(aSecondTimer.GetFireTime(), now) != isBeforeNow) - { - // One timer is before `now` and the other one is not, so if this timer's fire time is before `now` then - // the second fire time would be after `now` and this timer would fire before the second timer. - - retval = isBeforeNow; - } - else - { - // Both timers are before `now` or both are after `now`. Either way the difference is guaranteed to be less - // than `kMaxDt` so we can safely compare the fire times directly. - - retval = TimerScheduler::IsStrictlyBefore(GetFireTime(), aSecondTimer.GetFireTime()); - } - - return retval; + otLogFuncEntry(); + aInstance->mIp6.mTimerMilliScheduler.ProcessTimers(); + otLogFuncExit(); } +#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +const TimerScheduler::AlarmApi TimerMicroScheduler::sAlarmMicroApi = +{ + &otPlatAlarmMicroStartAt, + &otPlatAlarmMicroStop, + &otPlatAlarmMicroGetNow +}; + +void TimerMicro::StartAt(uint32_t aT0, uint32_t aDt) +{ + assert(aDt <= kMaxDt); + mFireTime = aT0 + aDt; + GetTimerMicroScheduler().Add(*this); +} + +void TimerMicro::Stop(void) +{ + GetTimerMicroScheduler().Remove(*this); +} + +TimerMicroScheduler &TimerMicro::GetTimerMicroScheduler(void) const +{ + return GetIp6().mTimerMicroScheduler; +} + +extern "C" void otPlatAlarmMicroFired(otInstance *aInstance) +{ + otLogFuncEntry(); + aInstance->mIp6.mTimerMicroScheduler.ProcessTimers(); + otLogFuncExit(); +} +#endif // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER + } // namespace ot diff --git a/src/core/common/timer.hpp b/src/core/common/timer.hpp index ac5ef22e5..fd9271fb0 100644 --- a/src/core/common/timer.hpp +++ b/src/core/common/timer.hpp @@ -38,7 +38,8 @@ #include "utils/wrap_stdint.h" #include -#include +#include +#include #include "common/context.hpp" #include "common/debug.hpp" @@ -49,7 +50,7 @@ namespace ot { namespace Ip6 { class Ip6; } -class Timer; +class TimerMilliScheduler; /** * @addtogroup core-timer @@ -61,81 +62,11 @@ class Timer; * */ -/** - * This class implements the timer scheduler. - * - */ -class TimerScheduler -{ - friend class Timer; - -public: - /** - * This constructor initializes the object. - * - */ - TimerScheduler(void); - - /** - * This method adds a timer instance to the timer scheduler. - * - * @param[in] aTimer A reference to the timer instance. - * - */ - void Add(Timer &aTimer); - - /** - * This method removes a timer instance to the timer scheduler. - * - * @param[in] aTimer A reference to the timer instance. - * - */ - void Remove(Timer &aTimer); - - /** - * This method processes the running timers. - * - */ - void ProcessTimers(void); - -private: - /** - * This method sets the platform alarm based on timer at front of the list. - * - */ - void SetAlarm(void); - - /** - * This method returns the pointer to the parent Ip6 structure. - * - * @returns The pointer to the parent Ip6 structure. - * - */ - Ip6::Ip6 *GetIp6(void); - - /** - * This static method compares two times and indicates if the first time is strictly before (earlier) than the - * second time. - * - * This method requires that the difference between the two given times to be smaller than kMaxDt. - * - * @param[in] aTimerA The first time for comparison. - * @param[in] aTimerB The second time for comparison. - * - * @returns TRUE if aTimeA is before aTimeB. - * @returns FALSE if aTimeA is same time or after aTimeB. - * - */ - static bool IsStrictlyBefore(uint32_t aTimeA, uint32_t aTimeB); - - Timer *mHead; -}; - /** * This class implements a timer. * */ -class Timer: public TimerSchedulerLocator, public Context +class Timer: public Ip6Locator, public Context { friend class TimerScheduler; @@ -157,13 +88,13 @@ public: /** * This constructor creates a timer instance. * - * @param[in] aScheduler A reference to the timer scheduler. + * @param[in] aIp6 A reference to the IPv6 network object. * @param[in] aHandler A pointer to a function that is called when the timer expires. * @param[in] aContext A pointer to arbitrary context information. * */ - Timer(TimerScheduler &aScheduler, Handler aHandler, void *aContext): - TimerSchedulerLocator(aScheduler), + Timer(Ip6::Ip6 &aIp6, Handler aHandler, void *aContext): + Ip6Locator(aIp6), Context(aContext), mHandler(aHandler), mFireTime(0), @@ -187,6 +118,45 @@ public: */ bool IsRunning(void) const { return (mNext != this); } +protected: + /** + * This method indicates if the fire time of this timer is strictly before the fire time of a second given timer. + * + * @param[in] aTimer A reference to the second timer object. + * @param[in] aNow The current time (may in milliseconds or microsecond, which depends on the timer type). + * + * @retval TRUE If the fire time of this timer object is strictly before aTimer's fire time + * @retval FALSE If the fire time of this timer object is the same or after aTimer's fire time. + * + */ + bool DoesFireBefore(const Timer &aTimer, uint32_t aNow); + + void Fired(void) { mHandler(*this); } + + Handler mHandler; + uint32_t mFireTime; + Timer *mNext; +}; + +/** + * This class implements the millisecond timer. + * + */ +class TimerMilli: public Timer +{ +public: + /** + * This constructor creates a millisecond timer instance. + * + * @param[in] aIp6 A reference to the IPv6 network object. + * @param[in] aHandler A pointer to a function that is called when the timer expires. + * @param[in] aContext A pointer to arbitrary context information. + * + */ + TimerMilli(Ip6::Ip6 &aIp6, Handler aHandler, void *aContext): + Timer(aIp6, aHandler, aContext) { + } + /** * This method schedules the timer to fire a @p dt milliseconds from now. * @@ -204,17 +174,13 @@ public: * (aDt must be smaller than or equal to kMaxDt). * */ - void StartAt(uint32_t aT0, uint32_t aDt) { - assert(aDt <= kMaxDt); - mFireTime = aT0 + aDt; - GetTimerScheduler().Add(*this); - } + void StartAt(uint32_t aT0, uint32_t aDt); /** * This method stops the timer. * */ - void Stop(void) { GetTimerScheduler().Remove(*this); } + void Stop(void); /** * This static method returns the current time in milliseconds. @@ -222,7 +188,7 @@ public: * @returns The current time in milliseconds. * */ - static uint32_t GetNow(void) { return otPlatAlarmGetNow(); } + static uint32_t GetNow(void) { return otPlatAlarmMilliGetNow(); } /** * This static method returns the number of milliseconds given seconds. @@ -242,23 +208,250 @@ public: private: /** - * This method indicates if the fire time of this timer is strictly before the fire time of a second given timer. + * This method returns a reference to the TimerMilliScheduler. * - * @param[in] aTimer A reference to the second timer object. - * - * @retval TRUE If the fire time of this timer object is strictly before aTimer's fire time - * @retval FALSE If the fire time of this timer object is the same or after aTimer's fire time. + * @returns A reference to the TimerMilliScheduler. * */ - bool DoesFireBefore(const Timer &aTimer); - - void Fired(void) { mHandler(*this); } - - Handler mHandler; - uint32_t mFireTime; - Timer *mNext; + TimerMilliScheduler &GetTimerMilliScheduler(void) const; }; + +/** + * This class implements the base timer scheduler. + * + */ +class TimerScheduler: public Ip6Locator +{ + friend class Timer; + +protected: + /** + * The Alarm APIs definition + * + */ + struct AlarmApi + { + void (*AlarmStartAt)(otInstance *aInstance, uint32_t aT0, uint32_t aDt); + void (*AlarmStop)(otInstance *aInstance); + uint32_t (*AlarmGetNow)(void); + }; + + /** + * This constructor initializes the object. + * + * @param[in] aIp6 A reference to the IPv6 network object. + * + */ + TimerScheduler(Ip6::Ip6 &aIp6): + Ip6Locator(aIp6), + mHead(NULL) { + } + + /** + * This method adds a timer instance to the timer scheduler. + * + * @param[in] aTimer A reference to the timer instance. + * @param[in] aAlarmApi A reference to the Alarm APIs. + * + */ + void Add(Timer &aTimer, const AlarmApi &aAlarmApi); + + /** + * This method removes a timer instance to the timer scheduler. + * + * @param[in] aTimer A reference to the timer instance. + * @param[in] aAlarmApi A reference to the Alarm APIs. + * + */ + void Remove(Timer &aTimer, const AlarmApi &aAlarmApi); + + /** + * This method processes the running timers. + * + * @param[in] aAlarmApi A reference to the Alarm APIs. + * + */ + void ProcessTimers(const AlarmApi &aAlarmApi); + + /** + * This method sets the platform alarm based on timer at front of the list. + * + * @param[in] aAlarmApi A reference to the Alarm APIs. + * + */ + void SetAlarm(const AlarmApi &aAlarmApi); + + /** + * This static method compares two times and indicates if the first time is strictly before (earlier) than the + * second time. + * + * This method requires that the difference between the two given times to be smaller than kMaxDt. + * + * @param[in] aTimerA The first time for comparison. + * @param[in] aTimerB The second time for comparison. + * + * @returns TRUE if aTimeA is before aTimeB. + * @returns FALSE if aTimeA is same time or after aTimeB. + * + */ + static bool IsStrictlyBefore(uint32_t aTimeA, uint32_t aTimeB); + + Timer *mHead; +}; + +/** + * This class implements the millisecond timer scheduler. + * + */ +class TimerMilliScheduler: public TimerScheduler +{ +public: + /** + * This constructor initializes the object. + * + * @param[in] aIp6 A reference to the IPv6 network object. + * + */ + TimerMilliScheduler(Ip6::Ip6 &aIp6): + TimerScheduler(aIp6) { + } + + /** + * This method adds a timer instance to the timer scheduler. + * + * @param[in] aTimer A reference to the timer instance. + * + */ + void Add(TimerMilli &aTimer) { TimerScheduler::Add(aTimer, sAlarmMilliApi); } + + /** + * This method removes a timer instance to the timer scheduler. + * + * @param[in] aTimer A reference to the timer instance. + * + */ + void Remove(TimerMilli &aTimer) { TimerScheduler::Remove(aTimer, sAlarmMilliApi); }; + + /** + * This method processes the running timers. + * + */ + void ProcessTimers(void) { TimerScheduler::ProcessTimers(sAlarmMilliApi); } + +private: + static const AlarmApi sAlarmMilliApi; +}; + +#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +class TimerMicroScheduler; + +/** + * This class implements the microsecond timer. + * + */ +class TimerMicro: public Timer +{ +public: + /** + * This constructor creates a timer instance. + * + * @param[in] aIp6 A reference to the IPv6 network object. + * @param[in] aHandler A pointer to a function that is called when the timer expires. + * @param[in] aContext A pointer to arbitrary context information. + * + */ + TimerMicro(Ip6::Ip6 &aIp6, Handler aHandler, void *aContext): + Timer(aIp6, aHandler, aContext) { + } + + /** + * This method schedules the timer to fire a @p dt microseconds from now. + * + * @param[in] aDt The expire time in microseconds from now. + * (aDt must be smaller than or equal to kMaxDt). + * + */ + void Start(uint32_t aDt) { StartAt(GetNow(), aDt); } + + /** + * This method schedules the timer to fire at @p aDt microseconds from @p aT0. + * + * @param[in] aT0 The start time in microseconds. + * @param[in] aDt The expire time in microseconds from @p aT0. + * (aDt must be smaller than or equal to kMaxDt). + * + */ + void StartAt(uint32_t aT0, uint32_t aDt); + + /** + * This method stops the timer. + * + */ + void Stop(void); + + /** + * This static method returns the current time in microseconds. + * + * @returns The current time in microseconds. + * + */ + static uint32_t GetNow(void) { return otPlatAlarmMicroGetNow(); } + +private: + /** + * This method returns a reference to the TimerMicroScheduler. + * + * @returns A reference to the TimerMicroScheduler. + * + */ + TimerMicroScheduler &GetTimerMicroScheduler(void) const; +}; + +/** + * This class implements the microsecond timer scheduler. + * + */ +class TimerMicroScheduler: public TimerScheduler +{ +public: + /** + * This constructor initializes the object. + * + * @param[in] aIp6 A reference to the IPv6 network object. + * + */ + TimerMicroScheduler(Ip6::Ip6 &aIp6): + TimerScheduler(aIp6) { + } + + /** + * This method adds a timer instance to the timer scheduler. + * + * @param[in] aTimer A reference to the timer instance. + * + */ + void Add(TimerMicro &aTimer) { TimerScheduler::Add(aTimer, sAlarmMicroApi); } + + /** + * This method removes a timer instance to the timer scheduler. + * + * @param[in] aTimer A reference to the timer instance. + * + */ + void Remove(TimerMicro &aTimer) { TimerScheduler::Remove(aTimer, sAlarmMicroApi); }; + + /** + * This method processes the running timers. + * + */ + void ProcessTimers(void) { TimerScheduler::ProcessTimers(sAlarmMicroApi); } + +private: + static const AlarmApi sAlarmMicroApi; +}; +#endif // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER + /** * @} * diff --git a/src/core/common/trickle_timer.cpp b/src/core/common/trickle_timer.cpp index d71873c02..79e878e34 100644 --- a/src/core/common/trickle_timer.cpp +++ b/src/core/common/trickle_timer.cpp @@ -44,13 +44,13 @@ namespace ot { TrickleTimer::TrickleTimer( - TimerScheduler &aScheduler, + Ip6::Ip6 &aIp6, #ifdef ENABLE_TRICKLE_TIMER_SUPPRESSION_SUPPORT uint32_t aRedundancyConstant, #endif Handler aTransmitHandler, Handler aIntervalExpiredHandler, void *aContext) : - Timer(aScheduler, HandleTimerFired, aContext), + TimerMilli(aIp6, HandleTimerFired, aContext), #ifdef ENABLE_TRICKLE_TIMER_SUPPRESSION_SUPPORT k(aRedundancyConstant), c(0), @@ -97,7 +97,7 @@ void TrickleTimer::Start(uint32_t aIntervalMin, uint32_t aIntervalMax, Mode aMod void TrickleTimer::Stop(void) { mPhase = kPhaseDormant; - Timer::Stop(); + TimerMilli::Stop(); } #ifdef ENABLE_TRICKLE_TIMER_SUPPRESSION_SUPPORT @@ -117,7 +117,7 @@ void TrickleTimer::IndicateInconsistent(void) I = Imin; // Stop the existing timer - Timer::Stop(); + TimerMilli::Stop(); // Start a new interval StartNewInterval(); @@ -156,7 +156,7 @@ void TrickleTimer::StartNewInterval(void) } // Start the timer for 't' milliseconds from now - Timer::Start(t); + TimerMilli::Start(t); } void TrickleTimer::HandleTimerFired(Timer &aTimer) @@ -204,7 +204,7 @@ void TrickleTimer::HandleTimerFired(void) mPhase = kPhaseInterval; // Start the time for 'I - t' milliseconds - Timer::Start(I - t); + TimerMilli::Start(I - t); } } diff --git a/src/core/common/trickle_timer.hpp b/src/core/common/trickle_timer.hpp index 0d37399b0..5c812d503 100644 --- a/src/core/common/trickle_timer.hpp +++ b/src/core/common/trickle_timer.hpp @@ -53,7 +53,7 @@ namespace ot { * This class implements a trickle timer. * */ -class TrickleTimer: public Timer +class TrickleTimer: public TimerMilli { public: @@ -80,14 +80,14 @@ public: /** * This constructor creates a trickle timer instance. * - * @param[in] aScheduler A reference to the timer scheduler. + * @param[in] aIp6 A reference to the IPv6 network object. * @param[in] aRedundancyConstant The redundancy constant for the timer, k. * @param[in] aTransmitHandler A pointer to a function that is called when transmission should occur. * @param[in] aIntervalExpiredHandler An optional pointer to a function that is called when the interval expires. * @param[in] aContext A pointer to arbitrary context information. * */ - TrickleTimer(TimerScheduler &aScheduler, + TrickleTimer(Ip6::Ip6 &aIp6, #ifdef ENABLE_TRICKLE_TIMER_SUPPRESSION_SUPPORT uint32_t aRedundancyConstant, #endif diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index 1380e25f0..91c53b7e3 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -40,7 +40,6 @@ #include "utils/wrap_string.h" #include -#include #include "openthread-instance.h" #include "common/code_utils.hpp" @@ -98,21 +97,19 @@ void Mac::StartCsmaBackoff(void) backoff = (otPlatRandomGet() % (1UL << backoffExponent)); backoff *= (static_cast(kUnitBackoffPeriod) * OT_RADIO_SYMBOL_TIME); -#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_BACKOFF_TIMER - otPlatUsecAlarmStartAt(GetInstance(), otPlatUsecAlarmGetNow(), backoff, &Mac::HandleBeginTransmit, this); -#else // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_BACKOFF_TIMER +#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER + mBackoffTimer.Start(backoff); +#else // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER mBackoffTimer.Start(backoff / 1000UL); -#endif // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_BACKOFF_TIMER +#endif // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER } } Mac::Mac(ThreadNetif &aThreadNetif): ThreadNetifLocator(aThreadNetif), - mMacTimer(aThreadNetif.GetIp6().mTimerScheduler, &Mac::HandleMacTimer, this), -#if !OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_BACKOFF_TIMER - mBackoffTimer(aThreadNetif.GetIp6().mTimerScheduler, &Mac::HandleBeginTransmit, this), -#endif - mReceiveTimer(aThreadNetif.GetIp6().mTimerScheduler, &Mac::HandleReceiveTimer, this), + mMacTimer(aThreadNetif.GetIp6(), &Mac::HandleMacTimer, this), + mBackoffTimer(aThreadNetif.GetIp6(), &Mac::HandleBeginTransmit, this), + mReceiveTimer(aThreadNetif.GetIp6(), &Mac::HandleReceiveTimer, this), mShortAddress(kShortAddrInvalid), mPanId(kPanIdBroadcast), mChannel(OPENTHREAD_CONFIG_DEFAULT_CHANNEL), @@ -771,11 +768,6 @@ exit: return; } -void Mac::HandleBeginTransmit(void *aContext) -{ - static_cast(aContext)->HandleBeginTransmit(); -} - void Mac::HandleBeginTransmit(Timer &aTimer) { GetOwner(aTimer).HandleBeginTransmit(); diff --git a/src/core/mac/mac.hpp b/src/core/mac/mac.hpp index 8e744b347..8e3533f34 100644 --- a/src/core/mac/mac.hpp +++ b/src/core/mac/mac.hpp @@ -674,7 +674,6 @@ private: static void HandleMacTimer(Timer &aTimer); void HandleMacTimer(void); - static void HandleBeginTransmit(void *aContext); static void HandleBeginTransmit(Timer &aTimer); void HandleBeginTransmit(void); static void HandleReceiveTimer(Timer &aTimer); @@ -691,11 +690,13 @@ private: static Mac &GetOwner(const Context &aContext); - Timer mMacTimer; -#if !OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_BACKOFF_TIMER - Timer mBackoffTimer; + TimerMilli mMacTimer; +#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER + TimerMicro mBackoffTimer; +#else + TimerMilli mBackoffTimer; #endif - Timer mReceiveTimer; + TimerMilli mReceiveTimer; ExtAddress mExtAddress; ShortAddress mShortAddress; diff --git a/src/core/meshcop/commissioner.cpp b/src/core/meshcop/commissioner.cpp index fcb83b6e1..edbfbad73 100644 --- a/src/core/meshcop/commissioner.cpp +++ b/src/core/meshcop/commissioner.cpp @@ -70,8 +70,8 @@ Commissioner::Commissioner(ThreadNetif &aThreadNetif): mState(OT_COMMISSIONER_STATE_DISABLED), mJoinerPort(0), mJoinerRloc(0), - mJoinerExpirationTimer(aThreadNetif.GetIp6().mTimerScheduler, HandleJoinerExpirationTimer, this), - mTimer(aThreadNetif.GetIp6().mTimerScheduler, HandleTimer, this), + mJoinerExpirationTimer(aThreadNetif.GetIp6(), HandleJoinerExpirationTimer, this), + mTimer(aThreadNetif.GetIp6(), HandleTimer, this), mSessionId(0), mTransmitAttempts(0), mRelayReceive(OT_URI_PATH_RELAY_RX, &Commissioner::HandleRelayReceive, this), @@ -232,7 +232,7 @@ otError Commissioner::AddJoiner(const Mac::ExtAddress *aExtAddress, const char * (void)strlcpy(mJoiners[i].mPsk, aPSKd, sizeof(mJoiners[i].mPsk)); mJoiners[i].mValid = true; - mJoiners[i].mExpirationTime = Timer::GetNow() + Timer::SecToMsec(aTimeout); + mJoiners[i].mExpirationTime = TimerMilli::GetNow() + TimerMilli::SecToMsec(aTimeout); UpdateJoinerExpirationTimer(); @@ -275,12 +275,12 @@ otError Commissioner::RemoveJoiner(const Mac::ExtAddress *aExtAddress, uint32_t if (aDelay > 0) { - uint32_t now = Timer::GetNow(); + uint32_t now = TimerMilli::GetNow(); if ((static_cast(mJoiners[i].mExpirationTime - now) > 0) && - (static_cast(mJoiners[i].mExpirationTime - now) > Timer::SecToMsec(aDelay))) + (static_cast(mJoiners[i].mExpirationTime - now) > TimerMilli::SecToMsec(aDelay))) { - mJoiners[i].mExpirationTime = now + Timer::SecToMsec(aDelay); + mJoiners[i].mExpirationTime = now + TimerMilli::SecToMsec(aDelay); UpdateJoinerExpirationTimer(); } } @@ -343,7 +343,7 @@ void Commissioner::HandleJoinerExpirationTimer(Timer &aTimer) void Commissioner::HandleJoinerExpirationTimer(void) { - uint32_t now = Timer::GetNow(); + uint32_t now = TimerMilli::GetNow(); // Remove Joiners. for (size_t i = 0; i < sizeof(mJoiners) / sizeof(mJoiners[0]); i++) @@ -365,7 +365,7 @@ void Commissioner::HandleJoinerExpirationTimer(void) void Commissioner::UpdateJoinerExpirationTimer(void) { - uint32_t now = Timer::GetNow(); + uint32_t now = TimerMilli::GetNow(); uint32_t nextTimeout = 0xffffffff; // Check if timer should be set for next Joiner. @@ -655,7 +655,7 @@ void Commissioner::HandleLeaderPetitionResponse(Coap::Header *aHeader, Message * mState = OT_COMMISSIONER_STATE_ACTIVE; mTransmitAttempts = 0; - mTimer.Start(Timer::SecToMsec(kKeepAliveTimeout) / 2); + mTimer.Start(TimerMilli::SecToMsec(kKeepAliveTimeout) / 2); exit: @@ -667,7 +667,7 @@ exit: } else { - mTimer.Start(Timer::SecToMsec(kPetitionRetryDelay)); + mTimer.Start(TimerMilli::SecToMsec(kPetitionRetryDelay)); } } @@ -748,7 +748,7 @@ void Commissioner::HandleLeaderKeepAliveResponse(Coap::Header *aHeader, Message VerifyOrExit(state.GetState() == StateTlv::kAccept, mState = OT_COMMISSIONER_STATE_DISABLED); - mTimer.Start(Timer::SecToMsec(kKeepAliveTimeout) / 2); + mTimer.Start(TimerMilli::SecToMsec(kKeepAliveTimeout) / 2); exit: diff --git a/src/core/meshcop/commissioner.hpp b/src/core/meshcop/commissioner.hpp index 7e82cb5ec..bfc76c2e0 100644 --- a/src/core/meshcop/commissioner.hpp +++ b/src/core/meshcop/commissioner.hpp @@ -279,9 +279,9 @@ private: }; uint16_t mJoinerPort; uint16_t mJoinerRloc; - Timer mJoinerExpirationTimer; + TimerMilli mJoinerExpirationTimer; - Timer mTimer; + TimerMilli mTimer; uint16_t mSessionId; uint8_t mTransmitAttempts; diff --git a/src/core/meshcop/dataset.cpp b/src/core/meshcop/dataset.cpp index 4f19b6920..dbb013b95 100644 --- a/src/core/meshcop/dataset.cpp +++ b/src/core/meshcop/dataset.cpp @@ -358,7 +358,7 @@ otError Dataset::Set(const otOperationalDataset &aDataset) Set(tlv); } - mUpdateTime = Timer::GetNow(); + mUpdateTime = TimerMilli::GetNow(); exit: return error; @@ -427,7 +427,7 @@ otError Dataset::Set(const Tlv &aTlv) memcpy(mTlvs + mLength, &aTlv, sizeof(Tlv) + aTlv.GetLength()); mLength += sizeof(Tlv) + aTlv.GetLength(); - mUpdateTime = Timer::GetNow(); + mUpdateTime = TimerMilli::GetNow(); exit: return error; @@ -440,7 +440,7 @@ otError Dataset::Set(const Message &aMessage, uint16_t aOffset, uint8_t aLength) VerifyOrExit(aLength == aMessage.Read(aOffset, aLength, mTlvs), error = OT_ERROR_INVALID_ARGS); mLength = aLength; - mUpdateTime = Timer::GetNow(); + mUpdateTime = TimerMilli::GetNow(); exit: return error; @@ -481,7 +481,7 @@ otError Dataset::AppendMleDatasetTlv(Message &aMessage) const } else if (cur->GetType() == Tlv::kDelayTimer) { - uint32_t elapsed = Timer::GetNow() - mUpdateTime; + uint32_t elapsed = TimerMilli::GetNow() - mUpdateTime; DelayTimerTlv delayTimer; memcpy(&delayTimer, cur, sizeof(delayTimer)); diff --git a/src/core/meshcop/dataset_local.cpp b/src/core/meshcop/dataset_local.cpp index 0390ada2b..a0a9b1e2e 100644 --- a/src/core/meshcop/dataset_local.cpp +++ b/src/core/meshcop/dataset_local.cpp @@ -82,7 +82,7 @@ otError DatasetLocal::Get(Dataset &aDataset) delayTimer = static_cast(aDataset.Get(Tlv::kDelayTimer)); VerifyOrExit(delayTimer); - elapsed = Timer::GetNow() - mUpdateTime; + elapsed = TimerMilli::GetNow() - mUpdateTime; if (delayTimer->GetDelayTimer() > elapsed) { @@ -93,7 +93,7 @@ otError DatasetLocal::Get(Dataset &aDataset) delayTimer->SetDelayTimer(0); } - aDataset.mUpdateTime = Timer::GetNow(); + aDataset.mUpdateTime = TimerMilli::GetNow(); exit: return error; @@ -396,7 +396,7 @@ otError DatasetLocal::Set(const Dataset &aDataset) SuccessOrExit(error); - mUpdateTime = Timer::GetNow(); + mUpdateTime = TimerMilli::GetNow(); exit: return error; diff --git a/src/core/meshcop/dataset_manager.cpp b/src/core/meshcop/dataset_manager.cpp index 12cb1c0e7..a91d376e7 100644 --- a/src/core/meshcop/dataset_manager.cpp +++ b/src/core/meshcop/dataset_manager.cpp @@ -66,7 +66,7 @@ DatasetManager::DatasetManager(ThreadNetif &aThreadNetif, const Tlv::Type aType, ThreadNetifLocator(aThreadNetif), mLocal(aThreadNetif.GetInstance(), aType), mNetwork(aType), - mTimer(aThreadNetif.GetIp6().mTimerScheduler, aTimerHander, this), + mTimer(aThreadNetif.GetIp6(), aTimerHander, this), mUriSet(aUriSet), mUriGet(aUriGet) { @@ -1022,7 +1022,7 @@ static PendingDatasetBase &GetPendingDatasetOwner(const Context &aContext) PendingDatasetBase::PendingDatasetBase(ThreadNetif &aThreadNetif): DatasetManager(aThreadNetif, Tlv::kPendingTimestamp, OT_URI_PATH_PENDING_SET, OT_URI_PATH_PENDING_GET, &PendingDatasetBase::HandleTimer), - mDelayTimer(aThreadNetif.GetIp6().mTimerScheduler, &PendingDatasetBase::HandleDelayTimer, this), + mDelayTimer(aThreadNetif.GetIp6(), &PendingDatasetBase::HandleDelayTimer, this), mResourceGet(OT_URI_PATH_PENDING_GET, &PendingDatasetBase::HandleGet, this) { aThreadNetif.GetCoap().AddResource(mResourceGet); diff --git a/src/core/meshcop/dataset_manager.hpp b/src/core/meshcop/dataset_manager.hpp index 366a14f5c..4d3159c97 100644 --- a/src/core/meshcop/dataset_manager.hpp +++ b/src/core/meshcop/dataset_manager.hpp @@ -131,7 +131,7 @@ protected: * */ DatasetManager(ThreadNetif &aThreadNetif, const Tlv::Type aType, const char *aUriSet, const char *aUriGet, - Timer::Handler aTimerHander); + TimerMilli::Handler aTimerHander); /** * This method restores the Operational Dataset from non-volatile memory. @@ -213,7 +213,7 @@ private: void SendGetResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo, uint8_t *aTlvs, uint8_t aLength) const; - Timer mTimer; + TimerMilli mTimer; const char *mUriSet; const char *mUriGet; @@ -442,7 +442,7 @@ protected: void StartDelayTimer(void); void HandleNetworkUpdate(void); - Timer mDelayTimer; + TimerMilli mDelayTimer; private: static void HandleGet(void *aContext, otCoapHeader *aHeader, otMessage *aMessage, diff --git a/src/core/meshcop/dtls.cpp b/src/core/meshcop/dtls.cpp index 719defb93..73d064c79 100644 --- a/src/core/meshcop/dtls.cpp +++ b/src/core/meshcop/dtls.cpp @@ -57,7 +57,7 @@ Dtls::Dtls(ThreadNetif &aNetif): ThreadNetifLocator(aNetif), mPskLength(0), mStarted(false), - mTimer(aNetif.GetIp6().mTimerScheduler, &Dtls::HandleTimer, this), + mTimer(aNetif.GetIp6(), &Dtls::HandleTimer, this), mTimerIntermediate(0), mTimerSet(false), mReceiveMessage(NULL), @@ -311,7 +311,7 @@ int Dtls::HandleMbedtlsGetTimer(void) { rval = 2; } - else if (static_cast(mTimerIntermediate - Timer::GetNow()) <= 0) + else if (static_cast(mTimerIntermediate - TimerMilli::GetNow()) <= 0) { rval = 1; } @@ -341,7 +341,7 @@ void Dtls::HandleMbedtlsSetTimer(uint32_t aIntermediate, uint32_t aFinish) { mTimerSet = true; mTimer.Start(aFinish); - mTimerIntermediate = Timer::GetNow() + aIntermediate; + mTimerIntermediate = TimerMilli::GetNow() + aIntermediate; } } diff --git a/src/core/meshcop/dtls.hpp b/src/core/meshcop/dtls.hpp index 60d0390c1..0ec052ec9 100644 --- a/src/core/meshcop/dtls.hpp +++ b/src/core/meshcop/dtls.hpp @@ -235,7 +235,7 @@ private: mbedtls_ssl_cookie_ctx mCookieCtx; bool mStarted; - Timer mTimer; + TimerMilli mTimer; uint32_t mTimerIntermediate; bool mTimerSet; diff --git a/src/core/meshcop/joiner.cpp b/src/core/meshcop/joiner.cpp index a551ab19a..c8a68d1a5 100644 --- a/src/core/meshcop/joiner.cpp +++ b/src/core/meshcop/joiner.cpp @@ -74,7 +74,7 @@ Joiner::Joiner(ThreadNetif &aNetif): mVendorModel(NULL), mVendorSwVersion(NULL), mVendorData(NULL), - mTimer(aNetif.GetIp6().mTimerScheduler, &Joiner::HandleTimer, this), + mTimer(aNetif.GetIp6(), &Joiner::HandleTimer, this), mJoinerEntrust(OT_URI_PATH_JOINER_ENTRUST, &Joiner::HandleJoinerEntrust, this) { aNetif.GetCoap().AddResource(mJoinerEntrust); diff --git a/src/core/meshcop/joiner.hpp b/src/core/meshcop/joiner.hpp index eb7064192..e67b67a6e 100644 --- a/src/core/meshcop/joiner.hpp +++ b/src/core/meshcop/joiner.hpp @@ -150,7 +150,7 @@ private: const char *mVendorSwVersion; const char *mVendorData; - Timer mTimer; + TimerMilli mTimer; Coap::Resource mJoinerEntrust; }; diff --git a/src/core/meshcop/joiner_router.cpp b/src/core/meshcop/joiner_router.cpp index a7790e411..b00f9da8b 100644 --- a/src/core/meshcop/joiner_router.cpp +++ b/src/core/meshcop/joiner_router.cpp @@ -61,7 +61,7 @@ JoinerRouter::JoinerRouter(ThreadNetif &aNetif): ThreadNetifLocator(aNetif), mSocket(aNetif.GetIp6().mUdp), mRelayTransmit(OT_URI_PATH_RELAY_TX, &JoinerRouter::HandleRelayTransmit, this), - mTimer(aNetif.GetIp6().mTimerScheduler, &JoinerRouter::HandleTimer, this), + mTimer(aNetif.GetIp6(), &JoinerRouter::HandleTimer, this), mJoinerUdpPort(0), mIsJoinerPortConfigured(false), mExpectJoinEntRsp(false) @@ -407,7 +407,7 @@ otError JoinerRouter::DelaySendingJoinerEntrust(const Ip6::MessageInfo &aMessage messageInfo = aMessageInfo; messageInfo.SetPeerPort(kCoapUdpPort); - delayedMessage = DelayedJoinEntHeader(Timer::GetNow() + kDelayJoinEnt, messageInfo, aKek.GetKek()); + delayedMessage = DelayedJoinEntHeader(TimerMilli::GetNow() + kDelayJoinEnt, messageInfo, aKek.GetKek()); SuccessOrExit(delayedMessage.AppendTo(*message)); mDelayedJoinEnts.Enqueue(*message); @@ -442,7 +442,7 @@ void JoinerRouter::SendDelayedJoinerEntrust(void) ThreadNetif &netif = GetNetif(); DelayedJoinEntHeader delayedJoinEnt; Message *message = mDelayedJoinEnts.GetHead(); - uint32_t now = Timer::GetNow(); + uint32_t now = TimerMilli::GetNow(); Ip6::MessageInfo messageInfo; VerifyOrExit(message != NULL); diff --git a/src/core/meshcop/joiner_router.hpp b/src/core/meshcop/joiner_router.hpp index 456f72647..6a3f3f578 100644 --- a/src/core/meshcop/joiner_router.hpp +++ b/src/core/meshcop/joiner_router.hpp @@ -118,7 +118,7 @@ private: Ip6::UdpSocket mSocket; Coap::Resource mRelayTransmit; - Timer mTimer; + TimerMilli mTimer; MessageQueue mDelayedJoinEnts; uint16_t mJoinerUdpPort; diff --git a/src/core/meshcop/leader.cpp b/src/core/meshcop/leader.cpp index 24d2ee938..de433acfb 100644 --- a/src/core/meshcop/leader.cpp +++ b/src/core/meshcop/leader.cpp @@ -60,7 +60,7 @@ Leader::Leader(ThreadNetif &aThreadNetif): ThreadNetifLocator(aThreadNetif), mPetition(OT_URI_PATH_LEADER_PETITION, Leader::HandlePetition, this), mKeepAlive(OT_URI_PATH_LEADER_KEEP_ALIVE, Leader::HandleKeepAlive, this), - mTimer(aThreadNetif.GetIp6().mTimerScheduler, HandleTimer, this), + mTimer(aThreadNetif.GetIp6(), HandleTimer, this), mDelayTimerMinimal(DelayTimerTlv::kDelayTimerMinimal), mSessionId(0xffff) { @@ -111,7 +111,7 @@ void Leader::HandlePetition(Coap::Header &aHeader, Message &aMessage, const Ip6: mCommissionerId = commissionerId; state = StateTlv::kAccept; - mTimer.Start(Timer::SecToMsec(kTimeoutLeaderPetition)); + mTimer.Start(TimerMilli::SecToMsec(kTimeoutLeaderPetition)); exit: OT_UNUSED_VARIABLE(aMessageInfo); @@ -198,7 +198,7 @@ void Leader::HandleKeepAlive(Coap::Header &aHeader, Message &aMessage, const Ip6 else { responseState = StateTlv::kAccept; - mTimer.Start(Timer::SecToMsec(kTimeoutLeaderPetition)); + mTimer.Start(TimerMilli::SecToMsec(kTimeoutLeaderPetition)); } SendKeepAliveResponse(aHeader, aMessageInfo, responseState); diff --git a/src/core/meshcop/leader.hpp b/src/core/meshcop/leader.hpp index b9dc7b703..a691aee8c 100644 --- a/src/core/meshcop/leader.hpp +++ b/src/core/meshcop/leader.hpp @@ -135,7 +135,7 @@ private: Coap::Resource mPetition; Coap::Resource mKeepAlive; - Timer mTimer; + TimerMilli mTimer; uint32_t mDelayTimerMinimal; diff --git a/src/core/net/dhcp6_client.cpp b/src/core/net/dhcp6_client.cpp index ce3b28a50..44f6ad3ff 100644 --- a/src/core/net/dhcp6_client.cpp +++ b/src/core/net/dhcp6_client.cpp @@ -59,7 +59,7 @@ namespace Dhcp6 { Dhcp6Client::Dhcp6Client(ThreadNetif &aThreadNetif) : ThreadNetifLocator(aThreadNetif), - mTrickleTimer(aThreadNetif.GetIp6().mTimerScheduler, &Dhcp6Client::HandleTrickleTimer, NULL, this), + mTrickleTimer(aThreadNetif.GetIp6(), &Dhcp6Client::HandleTrickleTimer, NULL, this), mSocket(aThreadNetif.GetIp6().mUdp), mStartTime(0), mAddresses(NULL), @@ -318,8 +318,8 @@ bool Dhcp6Client::ProcessNextIdentityAssociation() } mTrickleTimer.Start( - Timer::SecToMsec(kTrickleTimerImin), - Timer::SecToMsec(kTrickleTimerImax), + TimerMilli::SecToMsec(kTrickleTimerImin), + TimerMilli::SecToMsec(kTrickleTimerImax), TrickleTimer::kModeNormal); mTrickleTimer.IndicateInconsistent(); @@ -345,7 +345,7 @@ bool Dhcp6Client::HandleTrickleTimer(void) switch (mIdentityAssociationHead->GetStatus()) { case IdentityAssociation::kStatusSolicit: - mStartTime = otPlatAlarmGetNow(); + mStartTime = TimerMilli::GetNow(); mIdentityAssociationHead->SetStatus(IdentityAssociation::kStatusSoliciting); // fall through @@ -427,7 +427,7 @@ otError Dhcp6Client::AppendElapsedTime(Message &aMessage) ElapsedTime option; option.Init(); - option.SetElapsedTime(static_cast(Timer::MsecToSec(otPlatAlarmGetNow() - mStartTime))); + option.SetElapsedTime(static_cast(TimerMilli::MsecToSec(TimerMilli::GetNow() - mStartTime))); return aMessage.Append(&option, sizeof(option)); } diff --git a/src/core/net/dns_client.cpp b/src/core/net/dns_client.cpp index fc0c34ad9..92304d806 100644 --- a/src/core/net/dns_client.cpp +++ b/src/core/net/dns_client.cpp @@ -112,7 +112,7 @@ otError Client::Query(const otDnsQuery *aQuery, otDnsResponseHandler aHandler, v messageInfo = static_cast(aQuery->mMessageInfo); queryMetadata.mHostname = aQuery->mHostname; - queryMetadata.mTransmissionTime = Timer::GetNow() + kResponseTimeout; + queryMetadata.mTransmissionTime = TimerMilli::GetNow() + kResponseTimeout; queryMetadata.mSourceAddress = messageInfo->GetSockAddr(); queryMetadata.mDestinationPort = messageInfo->GetPeerPort(); queryMetadata.mDestinationAddress = messageInfo->GetPeerAddr(); @@ -155,7 +155,7 @@ exit: Message *Client::CopyAndEnqueueMessage(const Message &aMessage, const QueryMetadata &aQueryMetadata) { otError error = OT_ERROR_NONE; - uint32_t now = Timer::GetNow(); + uint32_t now = TimerMilli::GetNow(); Message *messageCopy = NULL; uint32_t nextTransmissionTime; @@ -389,7 +389,7 @@ void Client::HandleRetransmissionTimer(Timer &aTimer) void Client::HandleRetransmissionTimer(void) { - uint32_t now = Timer::GetNow(); + uint32_t now = TimerMilli::GetNow(); uint32_t nextDelta = 0xffffffff; QueryMetadata queryMetadata; Message *message = mPendingQueries.GetHead(); diff --git a/src/core/net/dns_client.hpp b/src/core/net/dns_client.hpp index 8b6ab8283..e3fc4a603 100644 --- a/src/core/net/dns_client.hpp +++ b/src/core/net/dns_client.hpp @@ -159,7 +159,7 @@ public: Client(Ip6::Netif &aNetif): mSocket(aNetif.GetIp6().mUdp), mMessageId(0), - mRetransmissionTimer(aNetif.GetIp6().mTimerScheduler, &Client::HandleRetransmissionTimer, this) { + mRetransmissionTimer(aNetif.GetIp6(), &Client::HandleRetransmissionTimer, this) { }; /** @@ -256,7 +256,7 @@ private: uint16_t mMessageId; MessageQueue mPendingQueries; - Timer mRetransmissionTimer; + TimerMilli mRetransmissionTimer; }; } // namespace Dns diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index d0dc0cd7a..09de30c04 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -58,6 +58,10 @@ Ip6::Ip6(void): mUdp(*this), mMpl(*this), mMessagePool(GetInstance()), + mTimerMilliScheduler(*this), +#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER + mTimerMicroScheduler(*this), +#endif mForwardingEnabled(false), mSendQueueTask(mTaskletScheduler, HandleSendQueue, this), mReceiveIp6DatagramCallback(NULL), diff --git a/src/core/net/ip6.hpp b/src/core/net/ip6.hpp index 002a16eae..abddda748 100644 --- a/src/core/net/ip6.hpp +++ b/src/core/net/ip6.hpp @@ -374,7 +374,10 @@ public: MessagePool mMessagePool; TaskletScheduler mTaskletScheduler; - TimerScheduler mTimerScheduler; + TimerMilliScheduler mTimerMilliScheduler; +#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER + TimerMicroScheduler mTimerMicroScheduler; +#endif private: static void HandleSendQueue(Tasklet &aTasklet); @@ -412,11 +415,6 @@ static inline Ip6 *Ip6FromTaskletScheduler(TaskletScheduler *aTaskletScheduler) return (Ip6 *)CONTAINING_RECORD(aTaskletScheduler, Ip6, mTaskletScheduler); } -static inline Ip6 *Ip6FromTimerScheduler(TimerScheduler *aTimerScheduler) -{ - return (Ip6 *)CONTAINING_RECORD(aTimerScheduler, Ip6, mTimerScheduler); -} - /** * @} * diff --git a/src/core/net/ip6_mpl.cpp b/src/core/net/ip6_mpl.cpp index ef718d964..b38924ec0 100644 --- a/src/core/net/ip6_mpl.cpp +++ b/src/core/net/ip6_mpl.cpp @@ -57,8 +57,8 @@ void MplBufferedMessageMetadata::GenerateNextTransmissionTime(uint32_t aCurrentT Mpl::Mpl(Ip6 &aIp6): Ip6Locator(aIp6), - mSeedSetTimer(aIp6.mTimerScheduler, &Mpl::HandleSeedSetTimer, this), - mRetransmissionTimer(aIp6.mTimerScheduler, &Mpl::HandleRetransmissionTimer, this), + mSeedSetTimer(aIp6, &Mpl::HandleSeedSetTimer, this), + mRetransmissionTimer(aIp6, &Mpl::HandleRetransmissionTimer, this), mTimerExpirations(0), mSequence(0), mSeedId(0), @@ -164,7 +164,7 @@ exit: void Mpl::AddBufferedMessage(Message &aMessage, uint16_t aSeedId, uint8_t aSequence, bool aIsOutbound) { - uint32_t now = Timer::GetNow(); + uint32_t now = TimerMilli::GetNow(); otError error = OT_ERROR_NONE; Message *messageCopy = NULL; MplBufferedMessageMetadata messageMetadata; @@ -258,7 +258,7 @@ void Mpl::HandleRetransmissionTimer(Timer &aTimer) void Mpl::HandleRetransmissionTimer(void) { - uint32_t now = Timer::GetNow(); + uint32_t now = TimerMilli::GetNow(); uint32_t nextDelta = 0xffffffff; MplBufferedMessageMetadata messageMetadata; diff --git a/src/core/net/ip6_mpl.hpp b/src/core/net/ip6_mpl.hpp index a035cfdaa..525834334 100644 --- a/src/core/net/ip6_mpl.hpp +++ b/src/core/net/ip6_mpl.hpp @@ -535,8 +535,8 @@ private: static Mpl &GetOwner(const Context &aContext); - Timer mSeedSetTimer; - Timer mRetransmissionTimer; + TimerMilli mSeedSetTimer; + TimerMilli mRetransmissionTimer; uint8_t mTimerExpirations; uint8_t mSequence; diff --git a/src/core/openthread-core-default-config.h b/src/core/openthread-core-default-config.h index 7499aa64f..3e8496f08 100644 --- a/src/core/openthread-core-default-config.h +++ b/src/core/openthread-core-default-config.h @@ -735,13 +735,13 @@ #endif /** - * @def OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_BACKOFF_TIMER + * @def OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER * * Define to 1 if you want to enable microsecond backoff timer implemented in platform. * */ -#ifndef OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_BACKOFF_TIMER -#define OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_BACKOFF_TIMER 0 +#ifndef OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#define OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER 0 #endif /** diff --git a/src/core/openthread-single-instance.h b/src/core/openthread-single-instance.h index 32ca540d3..99fc8c6ba 100644 --- a/src/core/openthread-single-instance.h +++ b/src/core/openthread-single-instance.h @@ -48,7 +48,6 @@ namespace ot { class ThreadNetif; class MeshForwarder; -class TimerScheduler; class TaskletScheduler; namespace Ip6 { class Ip6; } @@ -79,14 +78,6 @@ ot::ThreadNetif &otGetThreadNetif(void); */ ot::MeshForwarder &otGetMeshForwarder(void); -/** - * This function returns a reference to the single TimerScheduler instance. - * - * @returns A reference to the TimerScheduler instance. - * - */ -ot::TimerScheduler &otGetTimerScheduler(void); - /** * This function returns a reference to the single TaskletShceduler instance. * diff --git a/src/core/thread/address_resolver.cpp b/src/core/thread/address_resolver.cpp index fbac186d3..4fe2b834f 100644 --- a/src/core/thread/address_resolver.cpp +++ b/src/core/thread/address_resolver.cpp @@ -64,7 +64,7 @@ AddressResolver::AddressResolver(ThreadNetif &aThreadNetif) : mAddressQuery(OT_URI_PATH_ADDRESS_QUERY, &AddressResolver::HandleAddressQuery, this), mAddressNotification(OT_URI_PATH_ADDRESS_NOTIFY, &AddressResolver::HandleAddressNotification, this), mIcmpHandler(&AddressResolver::HandleIcmpReceive, this), - mTimer(aThreadNetif.GetIp6().mTimerScheduler, &AddressResolver::HandleTimer, this) + mTimer(aThreadNetif.GetIp6(), &AddressResolver::HandleTimer, this) { Clear(); @@ -557,7 +557,7 @@ void AddressResolver::HandleAddressQuery(Coap::Header &aHeader, Message &aMessag } mlIidTlv.SetIid(children[i].GetExtAddress()); - lastTransactionTimeTlv.SetTime(Timer::GetNow() - children[i].GetLastHeard()); + lastTransactionTimeTlv.SetTime(TimerMilli::GetNow() - children[i].GetLastHeard()); SendAddressQueryResponse(targetTlv, mlIidTlv, &lastTransactionTimeTlv, aMessageInfo.GetPeerAddr()); ExitNow(); } diff --git a/src/core/thread/address_resolver.hpp b/src/core/thread/address_resolver.hpp index 99daa6982..573b10a9f 100644 --- a/src/core/thread/address_resolver.hpp +++ b/src/core/thread/address_resolver.hpp @@ -189,7 +189,7 @@ private: Coap::Resource mAddressNotification; Cache mCache[kCacheEntries]; Ip6::IcmpHandler mIcmpHandler; - Timer mTimer; + TimerMilli mTimer; }; /** diff --git a/src/core/thread/announce_begin_server.cpp b/src/core/thread/announce_begin_server.cpp index d3add4ae4..61579c02d 100644 --- a/src/core/thread/announce_begin_server.cpp +++ b/src/core/thread/announce_begin_server.cpp @@ -58,7 +58,7 @@ AnnounceBeginServer::AnnounceBeginServer(ThreadNetif &aThreadNetif) : mPeriod(0), mCount(0), mChannel(0), - mTimer(aThreadNetif.GetIp6().mTimerScheduler, &AnnounceBeginServer::HandleTimer, this), + mTimer(aThreadNetif.GetIp6(), &AnnounceBeginServer::HandleTimer, this), mAnnounceBegin(OT_URI_PATH_ANNOUNCE_BEGIN, &AnnounceBeginServer::HandleRequest, this) { aThreadNetif.GetCoap().AddResource(mAnnounceBegin); diff --git a/src/core/thread/announce_begin_server.hpp b/src/core/thread/announce_begin_server.hpp index 9845ac8c4..8bad1fe12 100644 --- a/src/core/thread/announce_begin_server.hpp +++ b/src/core/thread/announce_begin_server.hpp @@ -100,7 +100,7 @@ private: uint8_t mCount; uint8_t mChannel; - Timer mTimer; + TimerMilli mTimer; Coap::Resource mAnnounceBegin; }; diff --git a/src/core/thread/data_poll_manager.cpp b/src/core/thread/data_poll_manager.cpp index 2b0ab745b..3867beef2 100644 --- a/src/core/thread/data_poll_manager.cpp +++ b/src/core/thread/data_poll_manager.cpp @@ -51,7 +51,7 @@ namespace ot { DataPollManager::DataPollManager(MeshForwarder &aMeshForwarder): MeshForwarderLocator(aMeshForwarder), - mTimer(aMeshForwarder.GetNetif().GetIp6().mTimerScheduler, &DataPollManager::HandlePollTimer, this), + mTimer(aMeshForwarder.GetNetif().GetIp6(), &DataPollManager::HandlePollTimer, this), mTimerStartTime(0), mExternalPollPeriod(0), mPollPeriod(0), @@ -345,7 +345,7 @@ void DataPollManager::ScheduleNextPoll(PollPeriodSelector aPollPeriodSelector) } else { - mTimerStartTime = Timer::GetNow(); + mTimerStartTime = TimerMilli::GetNow(); mTimer.StartAt(mTimerStartTime, mPollPeriod); } } @@ -422,7 +422,7 @@ DataPollManager &DataPollManager::GetOwner(Context &aContext) uint32_t DataPollManager::GetDefaultPollPeriod(void) const { - return Timer::SecToMsec(GetMeshForwarder().GetNetif().GetMle().GetTimeout()) - + return TimerMilli::SecToMsec(GetMeshForwarder().GetNetif().GetMle().GetTimeout()) - static_cast(kRetxPollPeriod) * kMaxPollRetxAttempts; } diff --git a/src/core/thread/data_poll_manager.hpp b/src/core/thread/data_poll_manager.hpp index fbbe49ef3..9fe5395f8 100644 --- a/src/core/thread/data_poll_manager.hpp +++ b/src/core/thread/data_poll_manager.hpp @@ -221,18 +221,18 @@ private: static DataPollManager &GetOwner(Context &aContext); uint32_t GetDefaultPollPeriod(void) const; - Timer mTimer; - uint32_t mTimerStartTime; - uint32_t mExternalPollPeriod; - uint32_t mPollPeriod; + TimerMilli mTimer; + uint32_t mTimerStartTime; + uint32_t mExternalPollPeriod; + uint32_t mPollPeriod; - bool mEnabled: 1; //< Indicates whether data polling is enabled/started. - bool mAttachMode: 1; //< Indicates whether in attach mode (to use attach poll period). - bool mRetxMode: 1; //< Indicates whether last poll tx failed at mac/radio layer (poll retx mode). - bool mNoBufferRetxMode: 1; //< Indicates whether last poll tx failed due to insufficient buffer. - uint8_t mPollTimeoutCounter: 4; //< Poll timeouts counter (0 to `kQuickPollsAfterTimout`). - uint8_t mPollTxFailureCounter: 4; //< Poll tx failure counter (0 to `kMaxPollRetxAttempts`). - uint8_t mRemainingFastPolls: 4; //< Number of remaining fast polls when in transient fast polling mode. + bool mEnabled: 1; //< Indicates whether data polling is enabled/started. + bool mAttachMode: 1; //< Indicates whether in attach mode (to use attach poll period). + bool mRetxMode: 1; //< Indicates whether last poll tx failed at mac/radio layer (poll retx mode). + bool mNoBufferRetxMode: 1; //< Indicates whether last poll tx failed due to insufficient buffer. + uint8_t mPollTimeoutCounter: 4; //< Poll timeouts counter (0 to `kQuickPollsAfterTimout`). + uint8_t mPollTxFailureCounter: 4; //< Poll tx failure counter (0 to `kMaxPollRetxAttempts`). + uint8_t mRemainingFastPolls: 4; //< Number of remaining fast polls when in transient fast polling mode. }; /** diff --git a/src/core/thread/energy_scan_server.cpp b/src/core/thread/energy_scan_server.cpp index bcf5b4b3c..2c475d601 100644 --- a/src/core/thread/energy_scan_server.cpp +++ b/src/core/thread/energy_scan_server.cpp @@ -59,7 +59,7 @@ EnergyScanServer::EnergyScanServer(ThreadNetif &aThreadNetif) : mCount(0), mActive(false), mScanResultsLength(0), - mTimer(aThreadNetif.GetIp6().mTimerScheduler, &EnergyScanServer::HandleTimer, this), + mTimer(aThreadNetif.GetIp6(), &EnergyScanServer::HandleTimer, this), mEnergyScan(OT_URI_PATH_ENERGY_SCAN, &EnergyScanServer::HandleRequest, this) { mNetifCallback.Set(&EnergyScanServer::HandleNetifStateChanged, this); diff --git a/src/core/thread/energy_scan_server.hpp b/src/core/thread/energy_scan_server.hpp index b2e210465..3f75becb4 100644 --- a/src/core/thread/energy_scan_server.hpp +++ b/src/core/thread/energy_scan_server.hpp @@ -99,7 +99,7 @@ private: int8_t mScanResults[OPENTHREAD_CONFIG_MAX_ENERGY_RESULTS]; uint8_t mScanResultsLength; - Timer mTimer; + TimerMilli mTimer; Ip6::NetifCallback mNetifCallback; diff --git a/src/core/thread/key_manager.cpp b/src/core/thread/key_manager.cpp index 19ce0075e..da8b727b6 100644 --- a/src/core/thread/key_manager.cpp +++ b/src/core/thread/key_manager.cpp @@ -61,7 +61,7 @@ KeyManager::KeyManager(ThreadNetif &aThreadNetif): mKeyRotationTime(kDefaultKeyRotationTime), mKeySwitchGuardTime(kDefaultKeySwitchGuardTime), mKeySwitchGuardEnabled(false), - mKeyRotationTimer(aThreadNetif.GetIp6().mTimerScheduler, &KeyManager::HandleKeyRotationTimer, this), + mKeyRotationTimer(aThreadNetif.GetIp6(), &KeyManager::HandleKeyRotationTimer, this), mKekFrameCounter(0), mSecurityPolicyFlags(0xff) { diff --git a/src/core/thread/key_manager.hpp b/src/core/thread/key_manager.hpp index b403fea2a..e5fe3fd0c 100644 --- a/src/core/thread/key_manager.hpp +++ b/src/core/thread/key_manager.hpp @@ -357,7 +357,7 @@ private: uint32_t mKeyRotationTime; uint32_t mKeySwitchGuardTime; bool mKeySwitchGuardEnabled; - Timer mKeyRotationTimer; + TimerMilli mKeyRotationTimer; #if OPENTHREAD_FTD uint8_t mPSKc[kMaxKeyLength]; diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index c510b9e8f..15b148b23 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -62,8 +62,8 @@ MeshForwarder::MeshForwarder(ThreadNetif &aThreadNetif): ThreadNetifLocator(aThreadNetif), mMacReceiver(&MeshForwarder::HandleReceivedFrame, &MeshForwarder::HandleDataPollTimeout, this), mMacSender(&MeshForwarder::HandleFrameRequest, &MeshForwarder::HandleSentFrame, this), - mDiscoverTimer(aThreadNetif.GetIp6().mTimerScheduler, &MeshForwarder::HandleDiscoverTimer, this), - mReassemblyTimer(aThreadNetif.GetIp6().mTimerScheduler, &MeshForwarder::HandleReassemblyTimer, this), + mDiscoverTimer(aThreadNetif.GetIp6(), &MeshForwarder::HandleDiscoverTimer, this), + mReassemblyTimer(aThreadNetif.GetIp6(), &MeshForwarder::HandleReassemblyTimer, this), mMessageNextOffset(0), mSendMessageFrameCounter(0), mSendMessage(NULL), @@ -2192,7 +2192,7 @@ void MeshForwarder::HandleDataRequest(const Mac::Address &aMacSource, const Thre VerifyOrExit(netif.GetMle().GetRole() != OT_DEVICE_ROLE_DETACHED); VerifyOrExit((child = netif.GetMle().GetChild(aMacSource)) != NULL); - child->SetLastHeard(Timer::GetNow()); + child->SetLastHeard(TimerMilli::GetNow()); child->ResetLinkFailures(); indirectMsgCount = child->GetIndirectMessageCount(); diff --git a/src/core/thread/mesh_forwarder.hpp b/src/core/thread/mesh_forwarder.hpp index b688b2c3b..0f2fc83c9 100644 --- a/src/core/thread/mesh_forwarder.hpp +++ b/src/core/thread/mesh_forwarder.hpp @@ -296,8 +296,8 @@ private: Mac::Receiver mMacReceiver; Mac::Sender mMacSender; - Timer mDiscoverTimer; - Timer mReassemblyTimer; + TimerMilli mDiscoverTimer; + TimerMilli mReassemblyTimer; PriorityQueue mSendQueue; MessageQueue mReassemblyList; diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 68073cc85..a3decd6b3 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -71,8 +71,8 @@ Mle::Mle(ThreadNetif &aThreadNetif) : mAssignLinkMargin(0), mParentRequestState(kParentIdle), mReattachState(kReattachStop), - mParentRequestTimer(aThreadNetif.GetIp6().mTimerScheduler, &Mle::HandleParentRequestTimer, this), - mDelayedResponseTimer(aThreadNetif.GetIp6().mTimerScheduler, &Mle::HandleDelayedResponseTimer, this), + mParentRequestTimer(aThreadNetif.GetIp6(), &Mle::HandleParentRequestTimer, this), + mDelayedResponseTimer(aThreadNetif.GetIp6(), &Mle::HandleDelayedResponseTimer, this), mLastPartitionRouterIdSequence(0), mLastPartitionId(0), mParentLeaderCost(0), @@ -591,7 +591,7 @@ otError Mle::SetStateChild(uint16_t aRloc16) if ((mDeviceMode & ModeTlv::kModeRxOnWhenIdle) != 0) { - mParentRequestTimer.Start(Timer::SecToMsec(mTimeout) - + mParentRequestTimer.Start(TimerMilli::SecToMsec(mTimeout) - static_cast(kUnicastRetransmissionDelay) * kMaxChildKeepAliveAttempts); } @@ -1451,7 +1451,7 @@ void Mle::HandleDelayedResponseTimer(Timer &aTimer) void Mle::HandleDelayedResponseTimer(void) { DelayedResponseHeader delayedResponse; - uint32_t now = otPlatAlarmGetNow(); + uint32_t now = TimerMilli::GetNow(); uint32_t nextDelay = 0xffffffff; Message *message = mDelayedResponses.GetHead(); Message *nextMessage = NULL; @@ -1978,7 +1978,7 @@ otError Mle::AddDelayedResponse(Message &aMessage, const Ip6::Address &aDestinat { otError error = OT_ERROR_NONE; uint32_t alarmFireTime; - uint32_t sendTime = otPlatAlarmGetNow() + aDelay; + uint32_t sendTime = TimerMilli::GetNow() + aDelay; // Append the message with DelayedRespnoseHeader and add to the list. DelayedResponseHeader delayedResponse(sendTime, aDestination); @@ -2317,7 +2317,7 @@ otError Mle::HandleAdvertisement(const Message &aMessage, const Ip6::MessageInfo } isNeighbor = true; - mParent.SetLastHeard(Timer::GetNow()); + mParent.SetLastHeard(TimerMilli::GetNow()); break; case OT_DEVICE_ROLE_ROUTER: @@ -2987,7 +2987,7 @@ otError Mle::HandleChildUpdateResponse(const Message &aMessage, const Ip6::Messa } else { - mParentRequestTimer.Start(Timer::SecToMsec(mTimeout) - + mParentRequestTimer.Start(TimerMilli::SecToMsec(mTimeout) - static_cast(kUnicastRetransmissionDelay) * kMaxChildKeepAliveAttempts); netif.GetMeshForwarder().SetRxOnWhenIdle(true); } diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 43dec0c8f..cad6f9f17 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -1350,8 +1350,8 @@ protected: }; ReattachState mReattachState; - Timer mParentRequestTimer; ///< The timer for driving the Parent Request process. - Timer mDelayedResponseTimer; ///< The timer to delay MLE responses. + TimerMilli mParentRequestTimer; ///< The timer for driving the Parent Request process. + TimerMilli mDelayedResponseTimer; ///< The timer to delay MLE responses. uint8_t mLastPartitionRouterIdSequence; uint32_t mLastPartitionId; diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index 697f5a63c..2405ad073 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -60,8 +60,8 @@ namespace Mle { MleRouter::MleRouter(ThreadNetif &aThreadNetif): Mle(aThreadNetif), - mAdvertiseTimer(aThreadNetif.GetIp6().mTimerScheduler, &MleRouter::HandleAdvertiseTimer, NULL, this), - mStateUpdateTimer(aThreadNetif.GetIp6().mTimerScheduler, &MleRouter::HandleStateUpdateTimer, this), + mAdvertiseTimer(aThreadNetif.GetIp6(), &MleRouter::HandleAdvertiseTimer, NULL, this), + mStateUpdateTimer(aThreadNetif.GetIp6(), &MleRouter::HandleStateUpdateTimer, this), mAddressSolicit(OT_URI_PATH_ADDRESS_SOLICIT, &MleRouter::HandleAddressSolicit, this), mAddressRelease(OT_URI_PATH_ADDRESS_RELEASE, &MleRouter::HandleAddressRelease, this), mRouterIdSequence(0), @@ -178,12 +178,12 @@ uint8_t MleRouter::AllocateRouterId(uint8_t aRouterId) // init router state router->SetAllocated(true); - router->SetLastHeard(Timer::GetNow()); + router->SetLastHeard(TimerMilli::GetNow()); router->ClearExtAddress(); // bump sequence number mRouterIdSequence++; - mRouterIdSequenceLastUpdated = Timer::GetNow(); + mRouterIdSequenceLastUpdated = TimerMilli::GetNow(); rval = aRouterId; otLogInfoMle(GetInstance(), "add router id %d", aRouterId); @@ -217,7 +217,7 @@ otError MleRouter::ReleaseRouterId(uint8_t aRouterId) } mRouterIdSequence++; - mRouterIdSequenceLastUpdated = Timer::GetNow(); + mRouterIdSequenceLastUpdated = TimerMilli::GetNow(); netif.GetAddressResolver().Remove(aRouterId); netif.GetNetworkDataLeader().RemoveBorderRouter(GetRloc16(aRouterId)); ResetAdvertiseInterval(); @@ -228,7 +228,7 @@ exit: uint32_t MleRouter::GetLeaderAge(void) const { - return Timer::MsecToSec(Timer::GetNow() - mRouterIdSequenceLastUpdated); + return TimerMilli::MsecToSec(TimerMilli::GetNow() - mRouterIdSequenceLastUpdated); } otError MleRouter::BecomeRouter(ThreadStatusTlv::Status aStatus) @@ -356,7 +356,7 @@ otError MleRouter::HandleChildStart(AttachMode aMode) { ThreadNetif &netif = GetNetif(); otError error = OT_ERROR_NONE; - mRouterIdSequenceLastUpdated = Timer::GetNow(); + mRouterIdSequenceLastUpdated = TimerMilli::GetNow(); mRouterSelectionJitterTimeout = (otPlatRandomGet() % mRouterSelectionJitter) + 1; StopLeader(); @@ -476,7 +476,7 @@ otError MleRouter::SetStateLeader(uint16_t aRloc16) mRouters[mRouterId].SetNextHop(mRouterId); mPreviousPartitionId = mLeaderData.GetPartitionId(); mStateUpdateTimer.Start(kStateUpdatePeriod); - mRouters[mRouterId].SetLastHeard(Timer::GetNow()); + mRouters[mRouterId].SetLastHeard(TimerMilli::GetNow()); netif.GetNetworkDataLeader().Start(); netif.GetActiveDataset().StartLeader(); @@ -529,8 +529,8 @@ void MleRouter::ResetAdvertiseInterval(void) if (!mAdvertiseTimer.IsRunning()) { mAdvertiseTimer.Start( - Timer::SecToMsec(kAdvertiseIntervalMin), - Timer::SecToMsec(kAdvertiseIntervalMax), + TimerMilli::SecToMsec(kAdvertiseIntervalMin), + TimerMilli::SecToMsec(kAdvertiseIntervalMax), TrickleTimer::kModeNormal); } @@ -1017,7 +1017,7 @@ otError MleRouter::HandleLinkAccept(const Message &aMessage, const Ip6::MessageI router->SetRloc16(sourceAddress.GetRloc16()); router->SetLinkFrameCounter(linkFrameCounter.GetFrameCounter()); router->SetMleFrameCounter(mleFrameCounter.GetFrameCounter()); - router->SetLastHeard(Timer::GetNow()); + router->SetLastHeard(TimerMilli::GetNow()); router->SetDeviceMode(ModeTlv::kModeFFD | ModeTlv::kModeRxOnWhenIdle | ModeTlv::kModeFullNetworkData); router->GetLinkInfo().Clear(); router->GetLinkInfo().AddRss(GetNetif().GetMac().GetNoiseFloor(), threadMessageInfo->mRss); @@ -1159,7 +1159,7 @@ otError MleRouter::ProcessRouteTlv(const RouteTlv &aRoute) otError error = OT_ERROR_NONE; mRouterIdSequence = aRoute.GetRouterIdSequence(); - mRouterIdSequenceLastUpdated = Timer::GetNow(); + mRouterIdSequenceLastUpdated = TimerMilli::GetNow(); for (uint8_t i = 0; i <= kMaxRouterId; i++) { @@ -1457,7 +1457,7 @@ otError MleRouter::HandleAdvertisement(const Message &aMessage, const Ip6::Messa ExitNow(error = OT_ERROR_NO_ROUTE); } - router->SetLastHeard(Timer::GetNow()); + router->SetLastHeard(TimerMilli::GetNow()); ExitNow(); @@ -1505,7 +1505,7 @@ otError MleRouter::HandleAdvertisement(const Message &aMessage, const Ip6::Messa ExitNow(error = OT_ERROR_NO_ROUTE); } - router->SetLastHeard(Timer::GetNow()); + router->SetLastHeard(TimerMilli::GetNow()); break; } @@ -1599,7 +1599,7 @@ void MleRouter::UpdateRoutes(const RouteTlv &aRoute, uint8_t aRouterId) mRouters[i].SetNextHop(kInvalidRouterId); mRouters[i].SetCost(0); - mRouters[i].SetLastHeard(Timer::GetNow()); + mRouters[i].SetLastHeard(TimerMilli::GetNow()); } } } @@ -1727,8 +1727,8 @@ otError MleRouter::HandleParentRequest(const Message &aMessage, const Ip6::Messa child->SetState(Neighbor::kStateParentRequest); child->SetDataRequestPending(false); - child->SetLastHeard(Timer::GetNow()); - child->SetTimeout(Timer::MsecToSec(kMaxChildIdRequestTimeout)); + child->SetLastHeard(TimerMilli::GetNow()); + child->SetTimeout(TimerMilli::MsecToSec(kMaxChildIdRequestTimeout)); } SuccessOrExit(error = SendParentResponse(child, challenge, !scanMask.IsEndDeviceFlagSet())); @@ -1784,8 +1784,8 @@ void MleRouter::HandleStateUpdateTimer(void) SendAdvertisement(); mAdvertiseTimer.Start( - Timer::SecToMsec(kReedAdvertiseInterval), - Timer::SecToMsec(kReedAdvertiseInterval + kReedAdvertiseJitter), + TimerMilli::SecToMsec(kReedAdvertiseInterval), + TimerMilli::SecToMsec(kReedAdvertiseInterval + kReedAdvertiseJitter), TrickleTimer::kModePlainTimer); } @@ -1817,7 +1817,7 @@ void MleRouter::HandleStateUpdateTimer(void) if (GetLeaderAge() >= kRouterIdSequencePeriod) { mRouterIdSequence++; - mRouterIdSequenceLastUpdated = Timer::GetNow(); + mRouterIdSequenceLastUpdated = TimerMilli::GetNow(); } break; @@ -1858,7 +1858,7 @@ void MleRouter::HandleStateUpdateTimer(void) case Neighbor::kStateValid: case Neighbor::kStateRestored: case Neighbor::kStateChildUpdateRequest: - timeout = Timer::SecToMsec(mChildren[i].GetTimeout()); + timeout = TimerMilli::SecToMsec(mChildren[i].GetTimeout()); break; case Neighbor::kStateLinkRequest: @@ -1866,7 +1866,7 @@ void MleRouter::HandleStateUpdateTimer(void) break; } - if ((Timer::GetNow() - mChildren[i].GetLastHeard()) >= timeout) + if ((TimerMilli::GetNow() - mChildren[i].GetLastHeard()) >= timeout) { RemoveNeighbor(mChildren[i]); } @@ -1877,7 +1877,7 @@ void MleRouter::HandleStateUpdateTimer(void) { if (mRouters[i].GetState() == Neighbor::kStateValid) { - if ((Timer::GetNow() - mRouters[i].GetLastHeard()) >= Timer::SecToMsec(kMaxNeighborAge)) + if ((TimerMilli::GetNow() - mRouters[i].GetLastHeard()) >= TimerMilli::SecToMsec(kMaxNeighborAge)) { RemoveNeighbor(mRouters[i]); } @@ -1889,15 +1889,15 @@ void MleRouter::HandleStateUpdateTimer(void) { if (!IsRouterIdValid(mRouters[i].GetNextHop()) && GetLinkCost(i) >= kMaxRouteCost && - (Timer::GetNow() - mRouters[i].GetLastHeard()) >= Timer::SecToMsec(kMaxLeaderToRouterTimeout)) + (TimerMilli::GetNow() - mRouters[i].GetLastHeard()) >= TimerMilli::SecToMsec(kMaxLeaderToRouterTimeout)) { ReleaseRouterId(i); } } else if (mRouters[i].IsReclaimDelay()) { - if ((Timer::GetNow() - mRouters[i].GetLastHeard()) >= - Timer::SecToMsec((kMaxLeaderToRouterTimeout + kRouterIdReuseDelay))) + if ((TimerMilli::GetNow() - mRouters[i].GetLastHeard()) >= + TimerMilli::SecToMsec((kMaxLeaderToRouterTimeout + kRouterIdReuseDelay))) { mRouters[i].SetReclaimDelay(false); } @@ -2164,7 +2164,7 @@ otError MleRouter::HandleChildIdRequest(const Message &aMessage, const Ip6::Mess } - child->SetLastHeard(Timer::GetNow()); + child->SetLastHeard(TimerMilli::GetNow()); child->SetLinkFrameCounter(linkFrameCounter.GetFrameCounter()); child->SetMleFrameCounter(mleFrameCounter.GetFrameCounter()); child->SetKeySequence(aKeySequence); @@ -2323,7 +2323,7 @@ otError MleRouter::HandleChildUpdateRequest(const Message &aMessage, const Ip6:: } } - child->SetLastHeard(Timer::GetNow()); + child->SetLastHeard(TimerMilli::GetNow()); if (child->IsStateRestoring()) { @@ -2418,7 +2418,7 @@ otError MleRouter::HandleChildUpdateResponse(const Message &aMessage, const Ip6: } SetChildStateToValid(child); - child->SetLastHeard(Timer::GetNow()); + child->SetLastHeard(TimerMilli::GetNow()); child->SetKeySequence(aKeySequence); child->GetLinkInfo().AddRss(GetNetif().GetMac().GetNoiseFloor(), threadMessageInfo->mRss); @@ -3125,7 +3125,7 @@ otError MleRouter::RemoveNeighbor(Neighbor &aNeighbor) Router &routerToRemove = static_cast(aNeighbor); routerToRemove.SetLinkQualityOut(0); - routerToRemove.SetLastHeard(Timer::GetNow()); + routerToRemove.SetLastHeard(TimerMilli::GetNow()); for (uint8_t j = 0; j <= kMaxRouterId; j++) { @@ -3536,7 +3536,7 @@ otError MleRouter::RestoreChildren(void) child->SetTimeout(childInfo.mTimeout); child->SetDeviceMode(childInfo.mMode); child->SetState(Neighbor::kStateRestored); - child->SetLastHeard(Timer::GetNow()); + child->SetLastHeard(TimerMilli::GetNow()); GetNetif().GetMeshForwarder().GetSourceMatchController().SetSrcMatchAsShort(*child, true); } @@ -3623,7 +3623,7 @@ otError MleRouter::GetChildInfo(Child &aChild, otChildInfo &aChildInfo) aChildInfo.mRloc16 = aChild.GetRloc16(); aChildInfo.mChildId = GetChildId(aChild.GetRloc16()); aChildInfo.mNetworkDataVersion = aChild.GetNetworkDataVersion(); - aChildInfo.mAge = Timer::MsecToSec(Timer::GetNow() - aChild.GetLastHeard()); + aChildInfo.mAge = TimerMilli::MsecToSec(TimerMilli::GetNow() - aChild.GetLastHeard()); aChildInfo.mLinkQualityIn = aChild.GetLinkInfo().GetLinkQuality(GetNetif().GetMac().GetNoiseFloor()); aChildInfo.mAverageRssi = aChild.GetLinkInfo().GetAverageRss(); aChildInfo.mLastRssi = aChild.GetLinkInfo().GetLastRss(); @@ -3665,7 +3665,8 @@ otError MleRouter::GetRouterInfo(uint16_t aRouterId, otRouterInfo &aRouterInfo) aRouterInfo.mPathCost = router->GetCost(); aRouterInfo.mLinkQualityIn = router->GetLinkInfo().GetLinkQuality(GetNetif().GetMac().GetNoiseFloor()); aRouterInfo.mLinkQualityOut = router->GetLinkQualityOut(); - aRouterInfo.mAge = static_cast(Timer::MsecToSec(Timer::GetNow() - router->GetLastHeard())); + aRouterInfo.mAge = static_cast(TimerMilli::MsecToSec(TimerMilli::GetNow() - + router->GetLastHeard())); exit: return error; @@ -3720,7 +3721,7 @@ exit: if (neighbor != NULL) { memcpy(&aNeighInfo.mExtAddress, &neighbor->GetExtAddress(), sizeof(aNeighInfo.mExtAddress)); - aNeighInfo.mAge = Timer::MsecToSec(Timer::GetNow() - neighbor->GetLastHeard()); + aNeighInfo.mAge = TimerMilli::MsecToSec(TimerMilli::GetNow() - neighbor->GetLastHeard()); aNeighInfo.mRloc16 = neighbor->GetRloc16(); aNeighInfo.mLinkFrameCounter = neighbor->GetLinkFrameCounter(); aNeighInfo.mMleFrameCounter = neighbor->GetMleFrameCounter(); @@ -3967,7 +3968,7 @@ void MleRouter::HandleAddressSolicitResponse(Coap::Header *aHeader, Message *aMe // copy router id information mRouterIdSequence = routerMaskTlv.GetIdSequence(); - mRouterIdSequenceLastUpdated = Timer::GetNow(); + mRouterIdSequenceLastUpdated = TimerMilli::GetNow(); for (uint8_t i = 0; i <= kMaxRouterId; i++) { diff --git a/src/core/thread/mle_router_ftd.hpp b/src/core/thread/mle_router_ftd.hpp index fca7fae3c..87d52f5f5 100644 --- a/src/core/thread/mle_router_ftd.hpp +++ b/src/core/thread/mle_router_ftd.hpp @@ -793,7 +793,7 @@ private: static MleRouter &GetOwner(const Context &aContext); TrickleTimer mAdvertiseTimer; - Timer mStateUpdateTimer; + TimerMilli mStateUpdateTimer; Coap::Resource mAddressSolicit; Coap::Resource mAddressRelease; diff --git a/src/core/thread/network_data.cpp b/src/core/thread/network_data.cpp index 6dea77a9c..e0a824efe 100644 --- a/src/core/thread/network_data.cpp +++ b/src/core/thread/network_data.cpp @@ -608,7 +608,7 @@ otError NetworkData::SendServerDataNotification(uint16_t aRloc16) Message *message = NULL; Ip6::MessageInfo messageInfo; - VerifyOrExit(!mLastAttemptWait || static_cast(Timer::GetNow() - mLastAttempt) < kDataResubmitDelay, + VerifyOrExit(!mLastAttemptWait || static_cast(TimerMilli::GetNow() - mLastAttempt) < kDataResubmitDelay, error = OT_ERROR_ALREADY); header.Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST); @@ -642,7 +642,7 @@ otError NetworkData::SendServerDataNotification(uint16_t aRloc16) if (mLocal) { - mLastAttempt = Timer::GetNow(); + mLastAttempt = TimerMilli::GetNow(); mLastAttemptWait = true; } diff --git a/src/core/thread/network_data_leader_ftd.cpp b/src/core/thread/network_data_leader_ftd.cpp index e237ee9f7..af14ad5ed 100644 --- a/src/core/thread/network_data_leader_ftd.cpp +++ b/src/core/thread/network_data_leader_ftd.cpp @@ -63,7 +63,7 @@ namespace NetworkData { Leader::Leader(ThreadNetif &aThreadNetif): LeaderBase(aThreadNetif), - mTimer(aThreadNetif.GetIp6().mTimerScheduler, &Leader::HandleTimer, this), + mTimer(aThreadNetif.GetIp6(), &Leader::HandleTimer, this), mServerData(OT_URI_PATH_SERVER_DATA, &Leader::HandleServerData, this), mCommissioningDataGet(OT_URI_PATH_COMMISSIONER_GET, &Leader::HandleCommissioningGet, this), mCommissioningDataSet(OT_URI_PATH_COMMISSIONER_SET, &Leader::HandleCommissioningSet, this) @@ -897,7 +897,7 @@ otError Leader::RemoveRloc(PrefixTlv &prefix, uint16_t aRloc16) if (prefix.GetSubTlvsLength() == sizeof(ContextTlv)) { context->ClearCompress(); - mContextLastUsed[context->GetContextId() - kMinContextId] = Timer::GetNow(); + mContextLastUsed[context->GetContextId() - kMinContextId] = TimerMilli::GetNow(); if (mContextLastUsed[context->GetContextId() - kMinContextId] == 0) { @@ -1066,7 +1066,7 @@ void Leader::HandleTimer(void) continue; } - if ((Timer::GetNow() - mContextLastUsed[i]) >= Timer::SecToMsec(mContextIdReuseDelay)) + if ((TimerMilli::GetNow() - mContextLastUsed[i]) >= TimerMilli::SecToMsec(mContextIdReuseDelay)) { FreeContext(kMinContextId + i); } diff --git a/src/core/thread/network_data_leader_ftd.hpp b/src/core/thread/network_data_leader_ftd.hpp index 44984838d..483b0f56c 100644 --- a/src/core/thread/network_data_leader_ftd.hpp +++ b/src/core/thread/network_data_leader_ftd.hpp @@ -200,7 +200,7 @@ private: uint16_t mContextUsed; uint32_t mContextLastUsed[kNumContextIds]; uint32_t mContextIdReuseDelay; - Timer mTimer; + TimerMilli mTimer; Coap::Resource mServerData; diff --git a/src/core/thread/network_diagnostic.cpp b/src/core/thread/network_diagnostic.cpp index a17dfdaf7..63a1d8856 100644 --- a/src/core/thread/network_diagnostic.cpp +++ b/src/core/thread/network_diagnostic.cpp @@ -317,7 +317,7 @@ otError NetworkDiagnostic::FillRequestedTlvs(Message &aRequest, Message &aRespon TimeoutTlv tlv; tlv.Init(); tlv.SetTimeout( - Timer::MsecToSec(netif.GetMeshForwarder().GetDataPollManager().GetKeepAlivePollPeriod())); + TimerMilli::MsecToSec(netif.GetMeshForwarder().GetDataPollManager().GetKeepAlivePollPeriod())); SuccessOrExit(error = aResponse.Append(&tlv, sizeof(tlv))); } diff --git a/src/core/thread/panid_query_server.cpp b/src/core/thread/panid_query_server.cpp index aa33583be..201be7840 100644 --- a/src/core/thread/panid_query_server.cpp +++ b/src/core/thread/panid_query_server.cpp @@ -55,7 +55,7 @@ PanIdQueryServer::PanIdQueryServer(ThreadNetif &aThreadNetif) : ThreadNetifLocator(aThreadNetif), mChannelMask(0), mPanId(Mac::kPanIdBroadcast), - mTimer(aThreadNetif.GetIp6().mTimerScheduler, &PanIdQueryServer::HandleTimer, this), + mTimer(aThreadNetif.GetIp6(), &PanIdQueryServer::HandleTimer, this), mPanIdQuery(OT_URI_PATH_PANID_QUERY, &PanIdQueryServer::HandleQuery, this) { aThreadNetif.GetCoap().AddResource(mPanIdQuery); diff --git a/src/core/thread/panid_query_server.hpp b/src/core/thread/panid_query_server.hpp index 622f7f86b..65544ef7b 100644 --- a/src/core/thread/panid_query_server.hpp +++ b/src/core/thread/panid_query_server.hpp @@ -89,7 +89,7 @@ private: uint32_t mChannelMask; uint16_t mPanId; - Timer mTimer; + TimerMilli mTimer; Coap::Resource mPanIdQuery; }; diff --git a/src/core/utils/child_supervision.cpp b/src/core/utils/child_supervision.cpp index ed4806eb4..41541220d 100644 --- a/src/core/utils/child_supervision.cpp +++ b/src/core/utils/child_supervision.cpp @@ -52,7 +52,7 @@ namespace Utils { ChildSupervisor::ChildSupervisor(ThreadNetif &aThreadNetif) : ThreadNetifLocator(aThreadNetif), - mTimer(aThreadNetif.GetIp6().mTimerScheduler, &ChildSupervisor::HandleTimer, this), + mTimer(aThreadNetif.GetIp6(), &ChildSupervisor::HandleTimer, this), mSupervisionInterval(kDefaultSupervisionInterval) { } @@ -133,7 +133,7 @@ void ChildSupervisor::UpdateOnSend(Child &aChild) aChild.ResetSecondsSinceLastSupervision(); } -void ChildSupervisor::HandleTimer(Timer &aTimer) +void ChildSupervisor::HandleTimer(TimerMilli &aTimer) { GetOwner(aTimer).HandleTimer(); } @@ -183,7 +183,7 @@ ChildSupervisor &ChildSupervisor::GetOwner(const Context &aContext) SupervisionListener::SupervisionListener(ThreadNetif &aThreadNetif) : ThreadNetifLocator(aThreadNetif), - mTimer(aThreadNetif.GetIp6().mTimerScheduler, &SupervisionListener::HandleTimer, this), + mTimer(aThreadNetif.GetIp6().mTimerMilliScheduler, &SupervisionListener::HandleTimer, this), mTimeout(0) { SetTimeout(kDefaultTimeout); @@ -232,7 +232,7 @@ void SupervisionListener::RestartTimer(void) if ((mTimeout != 0) && (netif.GetMle().GetRole() == OT_DEVICE_ROLE_CHILD) && (netif.GetMeshForwarder().GetRxOnWhenIdle() == false)) { - mTimer.Start(Timer::SecToMsec(mTimeout)); + mTimer.Start(TimerMilli::SecToMsec(mTimeout)); } else { @@ -240,7 +240,7 @@ void SupervisionListener::RestartTimer(void) } } -void SupervisionListener::HandleTimer(Timer &aTimer) +void SupervisionListener::HandleTimer(TimerMilli &aTimer) { GetOwner(aTimer).HandleTimer(); } diff --git a/src/core/utils/child_supervision.hpp b/src/core/utils/child_supervision.hpp index 22c2dd158..5bfab2f79 100644 --- a/src/core/utils/child_supervision.hpp +++ b/src/core/utils/child_supervision.hpp @@ -156,11 +156,11 @@ private: }; void SendMessage(Child &aChild); - static void HandleTimer(Timer &aTimer); + static void HandleTimer(TimerMilli &aTimer); void HandleTimer(void); static ChildSupervisor &GetOwner(const Context &aContext); - Timer mTimer; + TimerMilli mTimer; uint16_t mSupervisionInterval; }; @@ -248,11 +248,11 @@ private: }; void RestartTimer(void); - static void HandleTimer(Timer &aTimer); + static void HandleTimer(TimerMilli &aTimer); void HandleTimer(void); static SupervisionListener &GetOwner(const Context &aContext); - Timer mTimer; + TimerMilli mTimer; uint16_t mTimeout; }; diff --git a/src/core/utils/jam_detector.cpp b/src/core/utils/jam_detector.cpp index 6eda86749..d332dfd19 100644 --- a/src/core/utils/jam_detector.cpp +++ b/src/core/utils/jam_detector.cpp @@ -52,7 +52,7 @@ JamDetector::JamDetector(ThreadNetif &aNetif) : mHandler(NULL), mContext(NULL), mRssiThreshold(kDefaultRssiThreshold), - mTimer(aNetif.GetIp6().mTimerScheduler, &JamDetector::HandleTimer, this), + mTimer(aNetif.GetIp6(), &JamDetector::HandleTimer, this), mHistoryBitmap(0), mCurSecondStartTime(0), mSampleInterval(0), @@ -76,7 +76,7 @@ otError JamDetector::Start(Handler aHandler, void *aContext) mEnabled = true; - mCurSecondStartTime = Timer::GetNow(); + mCurSecondStartTime = TimerMilli::GetNow(); mAlwaysAboveThreshold = true; mHistoryBitmap = 0; mJamState = false; @@ -184,7 +184,7 @@ exit: void JamDetector::UpdateHistory(bool aDidExceedThreshold) { - uint32_t now = Timer::GetNow(); + uint32_t now = TimerMilli::GetNow(); // If the RSSI is ever below the threshold, update mAlwaysAboveThreshold // for current second interval. diff --git a/src/core/utils/jam_detector.hpp b/src/core/utils/jam_detector.hpp index ca314e3b8..402999a76 100644 --- a/src/core/utils/jam_detector.hpp +++ b/src/core/utils/jam_detector.hpp @@ -196,7 +196,7 @@ private: Handler mHandler; // Handler/callback to inform about jamming state void *mContext; // Context for handler/callback int8_t mRssiThreshold; // RSSI threshold for jam detection - Timer mTimer; // RSSI sample timer + TimerMilli mTimer; // RSSI sample timer uint64_t mHistoryBitmap; // History bitmap, each bit correspond to 1 sec interval uint32_t mCurSecondStartTime; // Start time for current 1 sec interval uint16_t mSampleInterval; // Current sample interval diff --git a/src/diag/diag_process.cpp b/src/diag/diag_process.cpp index 2f5e3a898..502ebea95 100644 --- a/src/diag/diag_process.cpp +++ b/src/diag/diag_process.cpp @@ -136,7 +136,7 @@ void Diag::ProcessStart(int argc, char *argv[], char *aOutput, size_t aOutputMax otPlatRadioSetPromiscuous(sContext, true); // stop timer - otPlatAlarmStop(sContext); + otPlatAlarmMilliStop(sContext); // start to listen on the default channel SuccessOrExit(error = otPlatRadioReceive(sContext, sChannel)); @@ -160,7 +160,7 @@ void Diag::ProcessStop(int argc, char *argv[], char *aOutput, size_t aOutputMaxL VerifyOrExit(otPlatDiagModeGet(), error = OT_ERROR_INVALID_STATE); - otPlatAlarmStop(sContext); + otPlatAlarmMilliStop(sContext); otPlatDiagModeSet(false); otPlatRadioSetPromiscuous(sContext, false); @@ -277,7 +277,7 @@ void Diag::ProcessRepeat(int argc, char *argv[], char *aOutput, size_t aOutputMa if (strcmp(argv[0], "stop") == 0) { - otPlatAlarmStop(sContext); + otPlatAlarmMilliStop(sContext); sRepeatActive = false; snprintf(aOutput, aOutputMaxLen, "repeated packet transmission is stopped\r\nstatus 0x%02x\r\n", error); } @@ -295,8 +295,8 @@ void Diag::ProcessRepeat(int argc, char *argv[], char *aOutput, size_t aOutputMa sTxLen = static_cast(value); sRepeatActive = true; - uint32_t now = otPlatAlarmGetNow(); - otPlatAlarmStartAt(sContext, now, sTxPeriod); + uint32_t now = otPlatAlarmMilliGetNow(); + otPlatAlarmMilliStartAt(sContext, now, sTxPeriod); snprintf(aOutput, aOutputMaxLen, "sending packets of length %#x at the delay of %#x ms\r\nstatus 0x%02x\r\n", static_cast(sTxLen), static_cast(sTxPeriod), error); } @@ -376,10 +376,10 @@ void Diag::AlarmFired(otInstance *aInstance) { if(sRepeatActive) { - uint32_t now = otPlatAlarmGetNow(); + uint32_t now = otPlatAlarmMilliGetNow(); TxPacket(); - otPlatAlarmStartAt(aInstance, now, sTxPeriod); + otPlatAlarmMilliStartAt(aInstance, now, sTxPeriod); } else { diff --git a/src/diag/diag_process.hpp b/src/diag/diag_process.hpp index f569a084c..44afadfb3 100644 --- a/src/diag/diag_process.hpp +++ b/src/diag/diag_process.hpp @@ -39,7 +39,7 @@ #include #include -#include +#include #include #include diff --git a/tests/unit/test_diag.cpp b/tests/unit/test_diag.cpp index e114aa7e6..e881bc946 100644 --- a/tests/unit/test_diag.cpp +++ b/tests/unit/test_diag.cpp @@ -53,7 +53,7 @@ extern "C" void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength) (void)aBufLength; } -extern "C" void otPlatAlarmFired(otInstance *) +extern "C" void otPlatAlarmMilliFired(otInstance *) { } diff --git a/tests/unit/test_fuzz.cpp b/tests/unit/test_fuzz.cpp index a94ab72f3..46f28d3e0 100644 --- a/tests/unit/test_fuzz.cpp +++ b/tests/unit/test_fuzz.cpp @@ -98,7 +98,7 @@ void TestFuzz(uint32_t aSeconds) g_testPlatRadioGetTransmitBuffer = testFuzztRadioGetTransmitBuffer; // Initialize our timing variables - uint32_t tStart = otPlatAlarmGetNow(); + uint32_t tStart = otPlatAlarmMilliGetNow(); uint32_t tEnd = tStart + (aSeconds * 1000); otInstance *aInstance; @@ -136,14 +136,14 @@ void TestFuzz(uint32_t aSeconds) uint32_t countRecv = 0; - while (otPlatAlarmGetNow() < tEnd) + while (otPlatAlarmMilliGetNow() < tEnd) { otTaskletsProcess(aInstance); - if (g_testPlatAlarmSet && otPlatAlarmGetNow() >= g_testPlatAlarmNext) + if (g_testPlatAlarmSet && otPlatAlarmMilliGetNow() >= g_testPlatAlarmNext) { g_testPlatAlarmSet = false; - otPlatAlarmFired(aInstance); + otPlatAlarmMilliFired(aInstance); } if (g_fRadioEnabled) diff --git a/tests/unit/test_platform.cpp b/tests/unit/test_platform.cpp index dacafde17..c7793ff54 100644 --- a/tests/unit/test_platform.cpp +++ b/tests/unit/test_platform.cpp @@ -135,7 +135,7 @@ extern "C" { // Alarm // - void otPlatAlarmStop(otInstance *aInstance) + void otPlatAlarmMilliStop(otInstance *aInstance) { if (g_testPlatAlarmStop) { @@ -147,7 +147,7 @@ extern "C" { } } - void otPlatAlarmStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt) + void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt) { if (g_testPlatAlarmStartAt) { @@ -160,7 +160,7 @@ extern "C" { } } - uint32_t otPlatAlarmGetNow(void) + uint32_t otPlatAlarmMilliGetNow(void) { if (g_testPlatAlarmGetNow) { diff --git a/tests/unit/test_platform.h b/tests/unit/test_platform.h index 2abff7524..99fea4d8f 100644 --- a/tests/unit/test_platform.h +++ b/tests/unit/test_platform.h @@ -39,7 +39,7 @@ #include #include -#include +#include #include #include #include diff --git a/tests/unit/test_timer.cpp b/tests/unit/test_timer.cpp index 0cc415766..801f30370 100644 --- a/tests/unit/test_timer.cpp +++ b/tests/unit/test_timer.cpp @@ -79,14 +79,14 @@ void InitCounters(void) } /** - * `TestTimer` sub-classes `ot::Timer` and provides a handler and a counter to keep track of number of times timer gets + * `TestTimer` sub-classes `ot::TimerMilli` and provides a handler and a counter to keep track of number of times timer gets * fired. */ -class TestTimer: public ot::Timer +class TestTimer: public ot::TimerMilli { public: TestTimer(otInstance *aInstance): - ot::Timer(aInstance->mIp6.mTimerScheduler, TestTimer::HandleTimerFired, NULL), + ot::TimerMilli(aInstance->mIp6, TestTimer::HandleTimerFired, NULL), mFiredCounter(0) { } @@ -136,7 +136,7 @@ int TestOneTimer(void) sNow += kTimerInterval; - otPlatAlarmFired(instance); + otPlatAlarmMilliFired(instance); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStart] == 1, "TestOneTimer: Start CallCount Failed.\n"); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStop] == 1, "TestOneTimer: Stop CallCount Failed.\n"); @@ -160,7 +160,7 @@ int TestOneTimer(void) sNow += kTimerInterval; - otPlatAlarmFired(instance); + otPlatAlarmMilliFired(instance); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStart] == 1, "TestOneTimer: Start CallCount Failed.\n"); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStop] == 1, "TestOneTimer: Stop CallCount Failed.\n"); @@ -184,7 +184,7 @@ int TestOneTimer(void) sNow += kTimerInterval + 5; - otPlatAlarmFired(instance); + otPlatAlarmMilliFired(instance); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStart] == 1, "TestOneTimer: Start CallCount Failed.\n"); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStop] == 1, "TestOneTimer: Stop CallCount Failed.\n"); @@ -208,7 +208,7 @@ int TestOneTimer(void) sNow += kTimerInterval - 2; - otPlatAlarmFired(instance); + otPlatAlarmMilliFired(instance); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStart] == 2, "TestOneTimer: Start CallCount Failed.\n"); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStop] == 0, "TestOneTimer: Stop CallCount Failed.\n"); @@ -218,7 +218,7 @@ int TestOneTimer(void) sNow += kTimerInterval; - otPlatAlarmFired(instance); + otPlatAlarmMilliFired(instance); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStart] == 2, "TestOneTimer: Start CallCount Failed.\n"); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStop] == 1, "TestOneTimer: Stop CallCount Failed.\n"); @@ -274,7 +274,7 @@ int TestTwoTimers(void) VerifyOrQuit(timer2.IsRunning() == true, "TestTwoTimers: Timer running Failed.\n"); VerifyOrQuit(sTimerOn, "TestTwoTimers: Platform Timer State Failed.\n"); - otPlatAlarmFired(instance); + otPlatAlarmMilliFired(instance); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStart] == 2, "TestTwoTimers: Start CallCount Failed.\n"); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStop] == 0, "TestTwoTimers: Stop CallCount Failed.\n"); @@ -286,7 +286,7 @@ int TestTwoTimers(void) VerifyOrQuit(sTimerOn == true, "TestTwoTimers: Platform Timer State Failed.\n"); sNow += kTimerInterval; - otPlatAlarmFired(instance); + otPlatAlarmMilliFired(instance); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStart] == 2, "TestTwoTimers: Start CallCount Failed.\n"); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStop] == 1, "TestTwoTimers: Stop CallCount Failed.\n"); @@ -296,7 +296,7 @@ int TestTwoTimers(void) VerifyOrQuit(timer2.IsRunning() == false, "TestTwoTimers: Timer running Failed.\n"); VerifyOrQuit(sTimerOn == false, "TestTwoTimers: Platform Timer State Failed.\n"); - // Test when second timer starts at the fire time of first timer (before otPlatAlarmFired()) and its fire time + // Test when second timer starts at the fire time of first timer (before otPlatAlarmMilliFired()) and its fire time // is before the first timer. Ensure that the second timer handler is invoked before the first one. InitCounters(); @@ -323,7 +323,7 @@ int TestTwoTimers(void) VerifyOrQuit(timer2.IsRunning() == true, "TestTwoTimers: Timer running Failed.\n"); VerifyOrQuit(sTimerOn, "TestTwoTimers: Platform Timer State Failed.\n"); - otPlatAlarmFired(instance); + otPlatAlarmMilliFired(instance); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStop] == 0, "TestTwoTimers: Stop CallCount Failed.\n"); VerifyOrQuit(sCallCount[kCallCountIndexTimerHandler] == 1, "TestTwoTimers: Handler CallCount Failed.\n"); @@ -333,7 +333,7 @@ int TestTwoTimers(void) VerifyOrQuit(timer2.IsRunning() == false, "TestTwoTimers: Timer running Failed.\n"); VerifyOrQuit(sTimerOn == true, "TestTwoTimers: Platform Timer State Failed.\n"); - otPlatAlarmFired(instance); + otPlatAlarmMilliFired(instance); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStop] == 1, "TestTwoTimers: Stop CallCount Failed.\n"); VerifyOrQuit(sCallCount[kCallCountIndexTimerHandler] == 2, "TestTwoTimers: Handler CallCount Failed.\n"); @@ -342,7 +342,7 @@ int TestTwoTimers(void) VerifyOrQuit(timer2.IsRunning() == false, "TestTwoTimers: Timer running Failed.\n"); VerifyOrQuit(sTimerOn == false, "TestTwoTimers: Platform Timer State Failed.\n"); - // Timer 1 fire callback is late by some ticks/ms, and second timer is scheduled (before call to otPlatAlarmFired) + // Timer 1 fire callback is late by some ticks/ms, and second timer is scheduled (before call to otPlatAlarmMilliFired) // with a maximum interval. This is to test (corner-case) scenario where the fire time of two timers spanning over // the maximum interval. @@ -372,20 +372,20 @@ int TestTwoTimers(void) VerifyOrQuit(timer2.IsRunning() == true, "TestTwoTimers: Timer running Failed.\n"); VerifyOrQuit(sTimerOn, "TestTwoTimers: Platform Timer State Failed.\n"); - otPlatAlarmFired(instance); + otPlatAlarmMilliFired(instance); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStart] == 2, "TestTwoTimers: Start CallCount Failed.\n"); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStop] == 0, "TestTwoTimers: Stop CallCount Failed.\n"); VerifyOrQuit(sCallCount[kCallCountIndexTimerHandler] == 1, "TestTwoTimers: Handler CallCount Failed.\n"); VerifyOrQuit(timer1.GetFiredCounter() == 1, "TestTwoTimers: Fire Counter failed.\n"); VerifyOrQuit(sPlatT0 == sNow, "TestTwoTimers: Start params Failed.\n"); - VerifyOrQuit(sPlatDt == ot::Timer::kMaxDt, "TestTwoTimers: Start params Failed.\n"); + VerifyOrQuit(sPlatDt == ot::Timer::kMaxDt, "TestTwoTimers: Start params Failed.\n"); VerifyOrQuit(timer1.IsRunning() == false, "TestTwoTimers: Timer running Failed.\n"); VerifyOrQuit(timer2.IsRunning() == true, "TestTwoTimers: Timer running Failed.\n"); VerifyOrQuit(sTimerOn == true, "TestTwoTimers: Platform Timer State Failed.\n"); sNow += ot::Timer::kMaxDt; - otPlatAlarmFired(instance); + otPlatAlarmMilliFired(instance); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStart] == 2, "TestTwoTimers: Start CallCount Failed.\n"); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStop] == 1, "TestTwoTimers: Stop CallCount Failed.\n"); @@ -564,7 +564,7 @@ static void TenTimers(uint32_t aTimeShift) timers[i]->Start(kTimerInterval[i]); } - // given the order in which timers are started, the TimerScheduler should call otPlatAlarmStartAt 2 times. + // given the order in which timers are started, the TimerScheduler should call otPlatAlarmMilliStartAt 2 times. // one for timer[0] and one for timer[5] which will supercede timer[0]. VerifyOrQuit(sCallCount[kCallCountIndexAlarmStart] == 2, "TestTenTimer: Start CallCount Failed.\n"); VerifyOrQuit(sCallCount[kCallCountIndexAlarmStop] == 0, "TestTenTimer: Stop CallCount Failed.\n"); @@ -586,13 +586,13 @@ static void TenTimers(uint32_t aTimeShift) do { - // By design, each call to otPlatAlarmFired() can result in 0 or 1 calls to a timer handler. - // For some combinations of sNow and Timers queued, it is necessary to call otPlatAlarmFired() + // By design, each call to otPlatAlarmMilliFired() can result in 0 or 1 calls to a timer handler. + // For some combinations of sNow and Timers queued, it is necessary to call otPlatAlarmMilliFired() // multiple times in order to handle all the expired timers. It can be determined that another - // timer is ready to be triggered by examining the aDt arg passed into otPlatAlarmStartAt(). If - // that value is 0, then otPlatAlarmFired should be fired immediately. This loop calls otPlatAlarmFired() + // timer is ready to be triggered by examining the aDt arg passed into otPlatAlarmMilliStartAt(). If + // that value is 0, then otPlatAlarmMilliFired should be fired immediately. This loop calls otPlatAlarmMilliFired() // the requisite number of times based on the aDt argument. - otPlatAlarmFired(instance); + otPlatAlarmMilliFired(instance); } while (sPlatDt == 0);