Use safe System::Clock types for system timers (#10779)
#### Problem
Timer functions take plain integer arguments and rely on callers to
get the units correct.
Part of #10062 _Some operations on System::Clock types are not safe_
#### Change overview
Change `System::Layer` and `PlatformManager` timers to take
`System::Clock::Timeout` instead of plain integers.
This change primarily converts arguments at call sites by wrapping
with a `Clock::Milliseconds32()` constructor or similar operation.
Future changes will convert types further up the call stack.
#### Testing
CI; no change to functionality intended.
diff --git a/examples/all-clusters-app/esp32/main/DeviceCallbacks.cpp b/examples/all-clusters-app/esp32/main/DeviceCallbacks.cpp
index e7b2709..9c6f544 100644
--- a/examples/all-clusters-app/esp32/main/DeviceCallbacks.cpp
+++ b/examples/all-clusters-app/esp32/main/DeviceCallbacks.cpp
@@ -217,7 +217,7 @@
if (identifyTimerCount)
{
- systemLayer->StartTimer(kIdentifyTimerDelayMS, IdentifyTimerHandler, appState);
+ systemLayer->StartTimer(Clock::Milliseconds32(kIdentifyTimerDelayMS), IdentifyTimerHandler, appState);
// Decrement the timer count.
identifyTimerCount--;
}
@@ -236,7 +236,7 @@
identifyTimerCount = (*value) * 4;
DeviceLayer::SystemLayer().CancelTimer(IdentifyTimerHandler, this);
- DeviceLayer::SystemLayer().StartTimer(kIdentifyTimerDelayMS, IdentifyTimerHandler, this);
+ DeviceLayer::SystemLayer().StartTimer(Clock::Milliseconds32(kIdentifyTimerDelayMS), IdentifyTimerHandler, this);
exit:
return;
diff --git a/examples/chip-tool/commands/common/CHIPCommand.cpp b/examples/chip-tool/commands/common/CHIPCommand.cpp
index d9e81e2..37c3b90 100644
--- a/examples/chip-tool/commands/common/CHIPCommand.cpp
+++ b/examples/chip-tool/commands/common/CHIPCommand.cpp
@@ -123,7 +123,8 @@
}
LogErrorOnFailure(chip::DeviceLayer::PlatformMgr().StopEventLoopTask());
#else
- ReturnLogErrorOnFailure(chip::DeviceLayer::SystemLayer().StartTimer(seconds * 1000, OnResponseTimeout, this));
+ ReturnLogErrorOnFailure(
+ chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(seconds), OnResponseTimeout, this));
chip::DeviceLayer::PlatformMgr().RunEventLoop();
#endif // CONFIG_USE_SEPARATE_EVENTLOOP
diff --git a/examples/chip-tool/commands/tests/TestCommand.cpp b/examples/chip-tool/commands/tests/TestCommand.cpp
index 97b1914..c5d7b91 100644
--- a/examples/chip-tool/commands/tests/TestCommand.cpp
+++ b/examples/chip-tool/commands/tests/TestCommand.cpp
@@ -49,7 +49,7 @@
CHIP_ERROR TestCommand::WaitForMs(uint32_t ms)
{
- return chip::DeviceLayer::SystemLayer().StartTimer(ms, OnWaitForMsFn, this);
+ return chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(ms), OnWaitForMsFn, this);
}
CHIP_ERROR TestCommand::Log(const char * message)
diff --git a/examples/lighting-app/qpg/src/AppTask.cpp b/examples/lighting-app/qpg/src/AppTask.cpp
index f148022..4d55f3b 100644
--- a/examples/lighting-app/qpg/src/AppTask.cpp
+++ b/examples/lighting-app/qpg/src/AppTask.cpp
@@ -374,7 +374,7 @@
{
CHIP_ERROR err;
- err = SystemLayer().StartTimer(aTimeoutInMs, TimerEventHandler, this);
+ err = SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(aTimeoutInMs), TimerEventHandler, this);
SuccessOrExit(err);
mFunctionTimerActive = true;
diff --git a/examples/lock-app/esp32/main/AppTask.cpp b/examples/lock-app/esp32/main/AppTask.cpp
index 5abc0a3..08b2708 100644
--- a/examples/lock-app/esp32/main/AppTask.cpp
+++ b/examples/lock-app/esp32/main/AppTask.cpp
@@ -171,9 +171,9 @@
sLockLED.Animate();
Clock::MonotonicMicroseconds nowUS = SystemClock().GetMonotonicMicroseconds();
- Clock::MonotonicMicroseconds nextChangeTimeUS = Clock::AddOffset(mLastChangeTimeUS, 5 * 1000 * 1000UL);
+ Clock::MonotonicMicroseconds nextChangeTimeUS = mLastChangeTimeUS + (5 * 1000 * 1000UL);
- if (Clock::IsEarlier(nextChangeTimeUS, nowUS))
+ if (nextChangeTimeUS < nowUS)
{
mLastChangeTimeUS = nowUS;
}
diff --git a/examples/lock-app/esp32/main/LEDWidget.cpp b/examples/lock-app/esp32/main/LEDWidget.cpp
index d4c834a..108533c 100644
--- a/examples/lock-app/esp32/main/LEDWidget.cpp
+++ b/examples/lock-app/esp32/main/LEDWidget.cpp
@@ -63,9 +63,9 @@
{
chip::System::Clock::MonotonicMicroseconds nowUS = chip::System::SystemClock().GetMonotonicMicroseconds();
chip::System::Clock::MonotonicMicroseconds stateDurUS = ((mState) ? mBlinkOnTimeMS : mBlinkOffTimeMS) * 1000LL;
- chip::System::Clock::MonotonicMicroseconds nextChangeTimeUS = chip::System::Clock::AddOffset(mLastChangeTimeUS, stateDurUS);
+ chip::System::Clock::MonotonicMicroseconds nextChangeTimeUS = mLastChangeTimeUS + stateDurUS;
- if (chip::System::Clock::IsEarlier(nextChangeTimeUS, nowUS))
+ if (nextChangeTimeUS < nowUS)
{
DoSet(!mState);
mLastChangeTimeUS = nowUS;
diff --git a/examples/lock-app/qpg/src/AppTask.cpp b/examples/lock-app/qpg/src/AppTask.cpp
index 770d753..3428752 100644
--- a/examples/lock-app/qpg/src/AppTask.cpp
+++ b/examples/lock-app/qpg/src/AppTask.cpp
@@ -390,7 +390,7 @@
CHIP_ERROR err;
chip::DeviceLayer::SystemLayer().CancelTimer(TimerEventHandler, this);
- err = chip::DeviceLayer::SystemLayer().StartTimer(aTimeoutInMs, TimerEventHandler, this);
+ err = chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(aTimeoutInMs), TimerEventHandler, this);
SuccessOrExit(err);
mFunctionTimerActive = true;
diff --git a/examples/platform/efr32/LEDWidget.cpp b/examples/platform/efr32/LEDWidget.cpp
index f9dcae4..3ce9668 100644
--- a/examples/platform/efr32/LEDWidget.cpp
+++ b/examples/platform/efr32/LEDWidget.cpp
@@ -77,7 +77,7 @@
Clock::MonotonicMicroseconds stateDurUS = ((sl_led_get_state(mLed)) ? mBlinkOnTimeMS : mBlinkOffTimeMS) * 1000LL;
Clock::MonotonicMicroseconds nextChangeTimeUS = mLastChangeTimeUS + stateDurUS;
- if (Clock::IsEarlier(nextChangeTimeUS, nowUS))
+ if (nextChangeTimeUS < nowUS)
{
Invert();
mLastChangeTimeUS = nowUS;
diff --git a/examples/platform/mbed/util/LEDWidget.cpp b/examples/platform/mbed/util/LEDWidget.cpp
index 308ca4f..84278e1 100644
--- a/examples/platform/mbed/util/LEDWidget.cpp
+++ b/examples/platform/mbed/util/LEDWidget.cpp
@@ -61,7 +61,7 @@
chip::System::Clock::MonotonicMilliseconds stateDurMS = (mLED == LED_ACTIVE_STATE) ? mBlinkOnTimeMS : mBlinkOffTimeMS;
chip::System::Clock::MonotonicMilliseconds nextChangeTimeMS = mLastChangeTimeMS + stateDurMS;
- if (chip::System::Clock::IsEarlier(nextChangeTimeMS, nowMS))
+ if (nextChangeTimeMS < nowMS)
{
mLED = !mLED;
mLastChangeTimeMS = nowMS;
diff --git a/examples/platform/nxp/k32w/k32w0/util/LEDWidget.cpp b/examples/platform/nxp/k32w/k32w0/util/LEDWidget.cpp
index b606c7b..55a1f6c 100644
--- a/examples/platform/nxp/k32w/k32w0/util/LEDWidget.cpp
+++ b/examples/platform/nxp/k32w/k32w0/util/LEDWidget.cpp
@@ -63,7 +63,7 @@
chip::System::Clock::MonotonicMicroseconds stateDurUS = ((mState) ? mBlinkOnTimeMS : mBlinkOffTimeMS) * 1000LL;
chip::System::Clock::MonotonicMicroseconds nextChangeTimeUS = mLastChangeTimeUS + stateDurUS;
- if (chip::System::Clock::IsEarlier(nextChangeTimeUS, nowUS))
+ if (nextChangeTimeUS < nowUS)
{
DoSet(!mState);
mLastChangeTimeUS = nowUS;
diff --git a/examples/platform/p6/LEDWidget.cpp b/examples/platform/p6/LEDWidget.cpp
index a502051..76e861b 100644
--- a/examples/platform/p6/LEDWidget.cpp
+++ b/examples/platform/p6/LEDWidget.cpp
@@ -65,7 +65,7 @@
chip::System::Clock::MonotonicMicroseconds stateDurUS = ((mState) ? mBlinkOnTimeMS : mBlinkOffTimeMS) * 1000LL;
chip::System::Clock::MonotonicMicroseconds nextChangeTimeUS = mLastChangeTimeUS + stateDurUS;
- if (chip::System::Clock::IsEarlier(nextChangeTimeUS, nowUS))
+ if (nextChangeTimeUS < nowUS)
{
DoSet(!mState);
mLastChangeTimeUS = nowUS;
diff --git a/examples/shell/shell_common/cmd_ping.cpp b/examples/shell/shell_common/cmd_ping.cpp
index b312168..f4a44af 100644
--- a/examples/shell/shell_common/cmd_ping.cpp
+++ b/examples/shell/shell_common/cmd_ping.cpp
@@ -211,7 +211,8 @@
}
gPingArguments.SetLastEchoTime(System::SystemClock().GetMonotonicMilliseconds());
- SuccessOrExit(chip::DeviceLayer::SystemLayer().StartTimer(gPingArguments.GetEchoInterval(), EchoTimerHandler, NULL));
+ SuccessOrExit(chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(gPingArguments.GetEchoInterval()),
+ EchoTimerHandler, NULL));
streamer_printf(stream, "\nSend echo request message with payload size: %d bytes to Node: %" PRIu64 "\n", payloadSize,
kTestDeviceNodeId);
diff --git a/examples/tv-casting-app/linux/main.cpp b/examples/tv-casting-app/linux/main.cpp
index b605b78..305c143 100644
--- a/examples/tv-casting-app/linux/main.cpp
+++ b/examples/tv-casting-app/linux/main.cpp
@@ -208,7 +208,7 @@
// Give commissioners some time to respond and then ScheduleWork to initiate commissioning
DeviceLayer::SystemLayer().StartTimer(
- kCommissionerDiscoveryTimeoutInMs,
+ chip::System::Clock::Milliseconds32(kCommissionerDiscoveryTimeoutInMs),
[](System::Layer *, void *) { chip::DeviceLayer::PlatformMgr().ScheduleWork(InitCommissioningFlow); }, nullptr);
// TBD: Content casting commands
diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp
index 7ce9f4b..ef2007f 100644
--- a/src/app/ReadClient.cpp
+++ b/src/app/ReadClient.cpp
@@ -541,7 +541,7 @@
CancelLivenessCheckTimer();
ChipLogProgress(DataManagement, "Refresh LivenessCheckTime with %d seconds", mMaxIntervalCeilingSeconds);
CHIP_ERROR err = InteractionModelEngine::GetInstance()->GetExchangeManager()->GetSessionManager()->SystemLayer()->StartTimer(
- mMaxIntervalCeilingSeconds * kMillisecondsPerSecond, OnLivenessTimeoutCallback, this);
+ System::Clock::Seconds16(mMaxIntervalCeilingSeconds), OnLivenessTimeoutCallback, this);
if (err != CHIP_NO_ERROR)
{
diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp
index 3e40831..e0b13b1 100644
--- a/src/app/ReadHandler.cpp
+++ b/src/app/ReadHandler.cpp
@@ -584,7 +584,7 @@
OnRefreshSubscribeTimerSyncCallback, this);
mHoldReport = true;
return InteractionModelEngine::GetInstance()->GetExchangeManager()->GetSessionManager()->SystemLayer()->StartTimer(
- mMinIntervalFloorSeconds * kMillisecondsPerSecond, OnRefreshSubscribeTimerSyncCallback, this);
+ System::Clock::Seconds16(mMinIntervalFloorSeconds), OnRefreshSubscribeTimerSyncCallback, this);
}
} // namespace app
} // namespace chip
diff --git a/src/app/clusters/identify-server/identify-server.cpp b/src/app/clusters/identify-server/identify-server.cpp
index 0968048..81e457b 100644
--- a/src/app/clusters/identify-server/identify-server.cpp
+++ b/src/app/clusters/identify-server/identify-server.cpp
@@ -169,7 +169,7 @@
/* finish identify process */
if (EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_FINISH_EFFECT == identify->mCurrentEffectIdentifier && identifyTime > 0)
{
- (void) chip::DeviceLayer::SystemLayer().StartTimer(MILLISECOND_TICKS_PER_SECOND, onIdentifyClusterTick,
+ (void) chip::DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(1), onIdentifyClusterTick,
identify);
return;
}
@@ -196,7 +196,7 @@
/* we only start if both callbacks are set */
identify_activate(identify);
- (void) chip::DeviceLayer::SystemLayer().StartTimer(MILLISECOND_TICKS_PER_SECOND, onIdentifyClusterTick, identify);
+ (void) chip::DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(1), onIdentifyClusterTick, identify);
return;
}
else
diff --git a/src/app/server/CommissioningWindowManager.cpp b/src/app/server/CommissioningWindowManager.cpp
index b5e66a7..1601a57 100644
--- a/src/app/server/CommissioningWindowManager.cpp
+++ b/src/app/server/CommissioningWindowManager.cpp
@@ -120,8 +120,8 @@
void CommissioningWindowManager::OnSessionEstablishmentStarted()
{
// As per specifications, section 5.5: Commissioning Flows
- constexpr uint16_t kPASESessionEstablishmentTimeoutSeconds = 60;
- DeviceLayer::SystemLayer().StartTimer(kPASESessionEstablishmentTimeoutSeconds * 1000, HandleSessionEstablishmentTimeout, this);
+ constexpr System::Clock::Timeout kPASESessionEstablishmentTimeout = System::Clock::Seconds16(60);
+ DeviceLayer::SystemLayer().StartTimer(kPASESessionEstablishmentTimeout, HandleSessionEstablishmentTimeout, this);
}
void CommissioningWindowManager::OnSessionEstablished()
@@ -159,8 +159,8 @@
if (mCommissioningTimeoutSeconds != kNoCommissioningTimeout)
{
- ReturnErrorOnFailure(
- DeviceLayer::SystemLayer().StartTimer(mCommissioningTimeoutSeconds * 1000, HandleCommissioningWindowTimeout, this));
+ ReturnErrorOnFailure(DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(mCommissioningTimeoutSeconds),
+ HandleCommissioningWindowTimeout, this));
}
ReturnErrorOnFailure(mServer->GetExchangeManager().RegisterUnsolicitedMessageHandlerForType(
diff --git a/src/app/server/Dnssd.cpp b/src/app/server/Dnssd.cpp
index 9b7a5df..d99da49 100644
--- a/src/app/server/Dnssd.cpp
+++ b/src/app/server/Dnssd.cpp
@@ -214,7 +214,7 @@
mDiscoveryExpirationMs = mTimeSource.GetCurrentMonotonicTimeMs() + static_cast<uint64_t>(mDiscoveryTimeoutSecs) * 1000;
- return DeviceLayer::SystemLayer().StartTimer(static_cast<uint32_t>(mDiscoveryTimeoutSecs) * 1000, HandleDiscoveryExpiration,
+ return DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(mDiscoveryTimeoutSecs), HandleDiscoveryExpiration,
nullptr);
}
@@ -231,7 +231,7 @@
mExtendedDiscoveryExpirationMs =
mTimeSource.GetCurrentMonotonicTimeMs() + static_cast<uint64_t>(extendedDiscoveryTimeoutSecs) * 1000;
- return DeviceLayer::SystemLayer().StartTimer(static_cast<uint32_t>(extendedDiscoveryTimeoutSecs) * 1000,
+ return DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(extendedDiscoveryTimeoutSecs),
HandleExtendedDiscoveryExpiration, nullptr);
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY
diff --git a/src/app/tests/TestCommissionManager.cpp b/src/app/tests/TestCommissionManager.cpp
index 0e1085f..2851af1 100644
--- a/src/app/tests/TestCommissionManager.cpp
+++ b/src/app/tests/TestCommissionManager.cpp
@@ -88,7 +88,8 @@
CHIP_ERROR err = commissionMgr.OpenBasicCommissioningWindow(kTimeoutSeconds, CommissioningWindowAdvertisement::kDnssdOnly);
NL_TEST_ASSERT(suite, err == CHIP_NO_ERROR);
NL_TEST_ASSERT(suite, commissionMgr.IsCommissioningWindowOpen());
- chip::DeviceLayer::SystemLayer().StartTimer(kTimeoutMs + kSleepPadding, CheckCommissioningWindowManagerWindowClosedTask, suite);
+ chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(kTimeoutMs + kSleepPadding),
+ CheckCommissioningWindowManagerWindowClosedTask, suite);
}
void CheckCommissioningWindowManagerWindowTimeout(nlTestSuite * suite, void *)
diff --git a/src/app/tests/integration/MockEvents.cpp b/src/app/tests/integration/MockEvents.cpp
index aec5320..d89b0a3 100644
--- a/src/app/tests/integration/MockEvents.cpp
+++ b/src/app/tests/integration/MockEvents.cpp
@@ -154,7 +154,8 @@
mEventsLeft = mpEventGenerator->GetNumStates();
if (mTimeBetweenEvents != 0)
- mpExchangeMgr->GetSessionManager()->SystemLayer()->StartTimer(mTimeBetweenEvents, HandleNextEvent, this);
+ mpExchangeMgr->GetSessionManager()->SystemLayer()->StartTimer(chip::System::Clock::Milliseconds32(mTimeBetweenEvents),
+ HandleNextEvent, this);
return err;
}
@@ -173,7 +174,8 @@
generator->mEventsLeft--;
if ((generator->mEventWraparound) || (generator->mEventsLeft > 0))
{
- apSystemLayer->StartTimer(generator->mTimeBetweenEvents, HandleNextEvent, generator);
+ apSystemLayer->StartTimer(chip::System::Clock::Milliseconds32(generator->mTimeBetweenEvents), HandleNextEvent,
+ generator);
}
}
}
@@ -186,7 +188,7 @@
// This helps quit the standalone app in an orderly way without
// spurious leaked timers.
if (mTimeBetweenEvents != 0)
- mpExchangeMgr->GetSessionManager()->SystemLayer()->StartTimer(0, HandleNextEvent, this);
+ mpExchangeMgr->GetSessionManager()->SystemLayer()->StartTimer(chip::System::Clock::Zero, HandleNextEvent, this);
}
bool MockEventGeneratorImpl::IsEventGeneratorStopped()
diff --git a/src/app/tests/integration/chip_im_initiator.cpp b/src/app/tests/integration/chip_im_initiator.cpp
index 226691b..9485922 100644
--- a/src/app/tests/integration/chip_im_initiator.cpp
+++ b/src/app/tests/integration/chip_im_initiator.cpp
@@ -463,12 +463,14 @@
err = SendCommandRequest(std::move(commandSender));
VerifyOrExit(err == CHIP_NO_ERROR, printf("Failed to send command request with error: %s\n", chip::ErrorStr(err)));
- err = chip::DeviceLayer::SystemLayer().StartTimer(gMessageIntervalMsec, CommandRequestTimerHandler, NULL);
+ err = chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(gMessageIntervalMsec),
+ CommandRequestTimerHandler, NULL);
VerifyOrExit(err == CHIP_NO_ERROR, printf("Failed to schedule timer with error: %s\n", chip::ErrorStr(err)));
}
else
{
- err = chip::DeviceLayer::SystemLayer().StartTimer(gMessageIntervalMsec, BadCommandRequestTimerHandler, NULL);
+ err = chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(gMessageIntervalMsec),
+ BadCommandRequestTimerHandler, NULL);
VerifyOrExit(err == CHIP_NO_ERROR, printf("Failed to schedule timer with error: %s\n", chip::ErrorStr(err)));
}
@@ -489,7 +491,8 @@
err = SendBadCommandRequest(std::move(commandSender));
VerifyOrExit(err == CHIP_NO_ERROR, printf("Failed to send bad command request with error: %s\n", chip::ErrorStr(err)));
- err = chip::DeviceLayer::SystemLayer().StartTimer(gMessageIntervalMsec, ReadRequestTimerHandler, NULL);
+ err = chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(gMessageIntervalMsec),
+ ReadRequestTimerHandler, NULL);
VerifyOrExit(err == CHIP_NO_ERROR, printf("Failed to schedule timer with error: %s\n", chip::ErrorStr(err)));
exit:
@@ -516,12 +519,14 @@
err = SendReadRequest();
VerifyOrExit(err == CHIP_NO_ERROR, printf("Failed to send read request with error: %s\n", chip::ErrorStr(err)));
- err = chip::DeviceLayer::SystemLayer().StartTimer(gMessageIntervalMsec, ReadRequestTimerHandler, NULL);
+ err = chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(gMessageIntervalMsec),
+ ReadRequestTimerHandler, NULL);
VerifyOrExit(err == CHIP_NO_ERROR, printf("Failed to schedule timer with error: %s\n", chip::ErrorStr(err)));
}
else
{
- err = chip::DeviceLayer::SystemLayer().StartTimer(gMessageIntervalMsec, WriteRequestTimerHandler, NULL);
+ err = chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(gMessageIntervalMsec),
+ WriteRequestTimerHandler, NULL);
VerifyOrExit(err == CHIP_NO_ERROR, printf("Failed to schedule timer with error: %s\n", chip::ErrorStr(err)));
}
@@ -553,12 +558,14 @@
err = SendWriteRequest(writeClient);
VerifyOrExit(err == CHIP_NO_ERROR, printf("Failed to send write request with error: %s\n", chip::ErrorStr(err)));
- err = chip::DeviceLayer::SystemLayer().StartTimer(gMessageIntervalMsec, WriteRequestTimerHandler, NULL);
+ err = chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(gMessageIntervalMsec),
+ WriteRequestTimerHandler, NULL);
VerifyOrExit(err == CHIP_NO_ERROR, printf("Failed to schedule timer with error: %s\n", chip::ErrorStr(err)));
}
else
{
- err = chip::DeviceLayer::SystemLayer().StartTimer(gMessageIntervalSeconds * 1000, SubscribeRequestTimerHandler, NULL);
+ err = chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(gMessageIntervalSeconds * 1000),
+ SubscribeRequestTimerHandler, NULL);
VerifyOrExit(err == CHIP_NO_ERROR, printf("Failed to schedule timer with error: %s\n", chip::ErrorStr(err)));
}
@@ -586,7 +593,7 @@
err = SendSubscribeRequest();
VerifyOrExit(err == CHIP_NO_ERROR, printf("Failed to send write request with error: %s\n", chip::ErrorStr(err)));
- err = chip::DeviceLayer::SystemLayer().StartTimer(20 * 1000, SubscribeRequestTimerHandler, NULL);
+ err = chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(20), SubscribeRequestTimerHandler, NULL);
VerifyOrExit(err == CHIP_NO_ERROR, printf("Failed to schedule timer with error: %s\n", chip::ErrorStr(err)));
}
else
@@ -703,7 +710,7 @@
err = EstablishSecureSession();
SuccessOrExit(err);
- err = chip::DeviceLayer::SystemLayer().StartTimer(0, CommandRequestTimerHandler, NULL);
+ err = chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Zero, CommandRequestTimerHandler, NULL);
SuccessOrExit(err);
chip::DeviceLayer::PlatformMgr().RunEventLoop();
diff --git a/src/app/tests/integration/chip_im_responder.cpp b/src/app/tests/integration/chip_im_responder.cpp
index 4a8f6b5..0aa92dc 100644
--- a/src/app/tests/integration/chip_im_responder.cpp
+++ b/src/app/tests/integration/chip_im_responder.cpp
@@ -178,7 +178,7 @@
dirtyPath.mFieldId = 1;
chip::app::InteractionModelEngine::GetInstance()->GetReportingEngine().SetDirty(dirtyPath);
chip::app::InteractionModelEngine::GetInstance()->GetReportingEngine().ScheduleRun();
- chip::DeviceLayer::SystemLayer().StartTimer(1000, MutateClusterHandler, NULL);
+ chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(1), MutateClusterHandler, NULL);
testSyncReport = true;
}
else
@@ -195,7 +195,7 @@
public:
virtual CHIP_ERROR SubscriptionEstablished(const chip::app::ReadHandler * apReadHandler)
{
- chip::DeviceLayer::SystemLayer().StartTimer(1000, MutateClusterHandler, NULL);
+ chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(1), MutateClusterHandler, NULL);
return CHIP_NO_ERROR;
}
};
diff --git a/src/app/util/af-event.cpp b/src/app/util/af-event.cpp
index 8a602ad..59b69ed 100644
--- a/src/app/util/af-event.cpp
+++ b/src/app/util/af-event.cpp
@@ -155,7 +155,7 @@
{
control->status = EMBER_EVENT_MS_TIME;
#if !CHIP_DEVICE_LAYER_NONE
- chip::DeviceLayer::SystemLayer().StartTimer(delayMs, EventControlHandler, control);
+ chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(delayMs), EventControlHandler, control);
#endif
}
else
diff --git a/src/ble/BLEEndPoint.cpp b/src/ble/BLEEndPoint.cpp
index 814c1a9..2cfb380 100644
--- a/src/ble/BLEEndPoint.cpp
+++ b/src/ble/BLEEndPoint.cpp
@@ -1414,7 +1414,8 @@
CHIP_ERROR BLEEndPoint::StartConnectTimer()
{
- const CHIP_ERROR timerErr = mBle->mSystemLayer->StartTimer(BLE_CONNECT_TIMEOUT_MS, HandleConnectTimeout, this);
+ const CHIP_ERROR timerErr =
+ mBle->mSystemLayer->StartTimer(System::Clock::Milliseconds32(BLE_CONNECT_TIMEOUT_MS), HandleConnectTimeout, this);
ReturnErrorOnFailure(timerErr);
mTimerStateFlags.Set(TimerStateFlag::kConnectTimerRunning);
@@ -1423,7 +1424,8 @@
CHIP_ERROR BLEEndPoint::StartReceiveConnectionTimer()
{
- const CHIP_ERROR timerErr = mBle->mSystemLayer->StartTimer(BLE_CONNECT_TIMEOUT_MS, HandleReceiveConnectionTimeout, this);
+ const CHIP_ERROR timerErr =
+ mBle->mSystemLayer->StartTimer(System::Clock::Milliseconds32(BLE_CONNECT_TIMEOUT_MS), HandleReceiveConnectionTimeout, this);
ReturnErrorOnFailure(timerErr);
mTimerStateFlags.Set(TimerStateFlag::kReceiveConnectionTimerRunning);
@@ -1434,7 +1436,8 @@
{
if (!mTimerStateFlags.Has(TimerStateFlag::kAckReceivedTimerRunning))
{
- const CHIP_ERROR timerErr = mBle->mSystemLayer->StartTimer(BTP_ACK_RECEIVED_TIMEOUT_MS, HandleAckReceivedTimeout, this);
+ const CHIP_ERROR timerErr = mBle->mSystemLayer->StartTimer(System::Clock::Milliseconds32(BTP_ACK_RECEIVED_TIMEOUT_MS),
+ HandleAckReceivedTimeout, this);
ReturnErrorOnFailure(timerErr);
mTimerStateFlags.Set(TimerStateFlag::kAckReceivedTimerRunning);
@@ -1459,7 +1462,8 @@
if (!mTimerStateFlags.Has(TimerStateFlag::kSendAckTimerRunning))
{
ChipLogDebugBleEndPoint(Ble, "starting new SendAckTimer");
- const CHIP_ERROR timerErr = mBle->mSystemLayer->StartTimer(BTP_ACK_SEND_TIMEOUT_MS, HandleSendAckTimeout, this);
+ const CHIP_ERROR timerErr =
+ mBle->mSystemLayer->StartTimer(System::Clock::Milliseconds32(BTP_ACK_SEND_TIMEOUT_MS), HandleSendAckTimeout, this);
ReturnErrorOnFailure(timerErr);
mTimerStateFlags.Set(TimerStateFlag::kSendAckTimerRunning);
@@ -1470,7 +1474,8 @@
CHIP_ERROR BLEEndPoint::StartUnsubscribeTimer()
{
- const CHIP_ERROR timerErr = mBle->mSystemLayer->StartTimer(BLE_UNSUBSCRIBE_TIMEOUT_MS, HandleUnsubscribeTimeout, this);
+ const CHIP_ERROR timerErr =
+ mBle->mSystemLayer->StartTimer(System::Clock::Milliseconds32(BLE_UNSUBSCRIBE_TIMEOUT_MS), HandleUnsubscribeTimeout, this);
ReturnErrorOnFailure(timerErr);
mTimerStateFlags.Set(TimerStateFlag::kUnsubscribeTimerRunning);
diff --git a/src/channel/ChannelContext.cpp b/src/channel/ChannelContext.cpp
index 1ec6a70..fd3e9ba 100644
--- a/src/channel/ChannelContext.cpp
+++ b/src/channel/ChannelContext.cpp
@@ -182,7 +182,8 @@
if (mState == ChannelState::kPreparing && GetPrepareVars().mState == PrepareState::kAddressResolving)
{
System::Layer * layer = mExchangeManager->GetSessionManager()->SystemLayer();
- layer->StartTimer(CHIP_CONFIG_NODE_ADDRESS_RESOLVE_TIMEOUT_MSECS, AddressResolveTimeout, this);
+ layer->StartTimer(System::Clock::Milliseconds32(CHIP_CONFIG_NODE_ADDRESS_RESOLVE_TIMEOUT_MSECS), AddressResolveTimeout,
+ this);
Retain(); // Keep the pointer in the timer
}
}
diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp
index ec69963..93718ec 100644
--- a/src/controller/CHIPDeviceController.cpp
+++ b/src/controller/CHIPDeviceController.cpp
@@ -763,7 +763,8 @@
device->Init(GetControllerDeviceInitParams(), remoteDeviceId, peerAddress, fabric->GetFabricIndex());
- mSystemState->SystemLayer()->StartTimer(kSessionEstablishmentTimeout, OnSessionEstablishmentTimeoutCallback, this);
+ mSystemState->SystemLayer()->StartTimer(chip::System::Clock::Milliseconds32(kSessionEstablishmentTimeout),
+ OnSessionEstablishmentTimeoutCallback, this);
if (params.GetPeerAddress().GetTransportType() != Transport::Type::kBle)
{
device->SetAddress(params.GetPeerAddress().GetIPAddress());
diff --git a/src/include/platform/PlatformManager.h b/src/include/platform/PlatformManager.h
index ca3fe5a..9f268cb 100644
--- a/src/include/platform/PlatformManager.h
+++ b/src/include/platform/PlatformManager.h
@@ -217,7 +217,7 @@
[[nodiscard]] CHIP_ERROR PostEvent(const ChipDeviceEvent * event);
void PostEventOrDie(const ChipDeviceEvent * event);
void DispatchEvent(const ChipDeviceEvent * event);
- CHIP_ERROR StartChipTimer(uint32_t durationMS);
+ CHIP_ERROR StartChipTimer(System::Clock::Timeout duration);
protected:
// Construction/destruction limited to subclasses.
@@ -408,9 +408,9 @@
static_cast<ImplClass *>(this)->_DispatchEvent(event);
}
-inline CHIP_ERROR PlatformManager::StartChipTimer(uint32_t durationMS)
+inline CHIP_ERROR PlatformManager::StartChipTimer(System::Clock::Timeout duration)
{
- return static_cast<ImplClass *>(this)->_StartChipTimer(durationMS);
+ return static_cast<ImplClass *>(this)->_StartChipTimer(duration);
}
inline CHIP_ERROR PlatformManager::GetCurrentHeapFree(uint64_t & currentHeapFree)
diff --git a/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.cpp b/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.cpp
index 7963e6a..9368734 100644
--- a/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.cpp
+++ b/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.cpp
@@ -209,11 +209,11 @@
}
template <class ImplClass>
-CHIP_ERROR GenericPlatformManagerImpl_FreeRTOS<ImplClass>::_StartChipTimer(uint32_t aMilliseconds)
+CHIP_ERROR GenericPlatformManagerImpl_FreeRTOS<ImplClass>::_StartChipTimer(System::Clock::Timeout delay)
{
mChipTimerActive = true;
vTaskSetTimeOutState(&mNextTimerBaseTime);
- mNextTimerDurationTicks = pdMS_TO_TICKS(aMilliseconds);
+ mNextTimerDurationTicks = pdMS_TO_TICKS(System::Clock::Milliseconds64(delay).count());
// If the platform timer is being updated by a thread other than the event loop thread,
// trigger the event loop thread to recalculate its wait time by posting a no-op event
diff --git a/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.h b/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.h
index 79d6ba2..ab114ec 100644
--- a/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.h
+++ b/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.h
@@ -73,7 +73,7 @@
void _RunEventLoop(void);
CHIP_ERROR _StartEventLoopTask(void);
CHIP_ERROR _StopEventLoopTask();
- CHIP_ERROR _StartChipTimer(uint32_t durationMS);
+ CHIP_ERROR _StartChipTimer(System::Clock::Timeout duration);
CHIP_ERROR _Shutdown(void);
// ===== Methods available to the implementation subclass.
diff --git a/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.cpp b/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.cpp
index 7451737..69156a3 100644
--- a/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.cpp
+++ b/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.cpp
@@ -120,7 +120,7 @@
#endif
template <class ImplClass>
-CHIP_ERROR GenericPlatformManagerImpl_POSIX<ImplClass>::_StartChipTimer(int64_t aMilliseconds)
+CHIP_ERROR GenericPlatformManagerImpl_POSIX<ImplClass>::_StartChipTimer(System::Clock::Timeout delay)
{
// Let System::LayerSocketsLoop.PrepareEvents() handle timers.
return CHIP_NO_ERROR;
diff --git a/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.h b/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.h
index de0250e..e2d5fee 100644
--- a/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.h
+++ b/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.h
@@ -93,7 +93,7 @@
void _RunEventLoop();
CHIP_ERROR _StartEventLoopTask();
CHIP_ERROR _StopEventLoopTask();
- CHIP_ERROR _StartChipTimer(int64_t durationMS);
+ CHIP_ERROR _StartChipTimer(System::Clock::Timeout duration);
CHIP_ERROR _Shutdown();
#if CHIP_STACK_LOCK_TRACKING_ENABLED
diff --git a/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.cpp b/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.cpp
index a5ce0b1..9b584d6 100644
--- a/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.cpp
+++ b/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.cpp
@@ -88,7 +88,7 @@
}
template <class ImplClass>
-CHIP_ERROR GenericPlatformManagerImpl_Zephyr<ImplClass>::_StartChipTimer(uint32_t aMilliseconds)
+CHIP_ERROR GenericPlatformManagerImpl_Zephyr<ImplClass>::_StartChipTimer(System::Clock::Timeout delay)
{
// Let Systemlayer.PrepareEvents() handle timers.
return CHIP_NO_ERROR;
diff --git a/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.h b/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.h
index 3e99c11..684c7ca 100644
--- a/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.h
+++ b/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.h
@@ -78,7 +78,7 @@
void _RunEventLoop(void);
CHIP_ERROR _StartEventLoopTask(void);
CHIP_ERROR _StopEventLoopTask();
- CHIP_ERROR _StartChipTimer(uint32_t durationMS);
+ CHIP_ERROR _StartChipTimer(System::Clock::Timeout duration);
CHIP_ERROR _Shutdown(void);
// ===== Methods available to the implementation subclass.
diff --git a/src/inet/InetLayer.cpp b/src/inet/InetLayer.cpp
index c5f67d4..3b1c2cb 100644
--- a/src/inet/InetLayer.cpp
+++ b/src/inet/InetLayer.cpp
@@ -602,7 +602,8 @@
if (lTimerRequired)
{
- aSystemLayer->StartTimer(INET_TCP_IDLE_CHECK_INTERVAL, HandleTCPInactivityTimer, &lInetLayer);
+ aSystemLayer->StartTimer(System::Clock::Milliseconds32(INET_TCP_IDLE_CHECK_INTERVAL), HandleTCPInactivityTimer,
+ &lInetLayer);
}
}
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT && INET_TCP_IDLE_CHECK_INTERVAL > 0
diff --git a/src/inet/TCPEndPoint.cpp b/src/inet/TCPEndPoint.cpp
index dba5199..a1b6a70 100644
--- a/src/inet/TCPEndPoint.cpp
+++ b/src/inet/TCPEndPoint.cpp
@@ -2522,7 +2522,8 @@
if (!isIdleTimerRunning && mIdleTimeout)
{
- Layer().SystemLayer()->StartTimer(INET_TCP_IDLE_CHECK_INTERVAL, InetLayer::HandleTCPInactivityTimer, &lInetLayer);
+ Layer().SystemLayer()->StartTimer(System::Clock::Milliseconds32(INET_TCP_IDLE_CHECK_INTERVAL),
+ InetLayer::HandleTCPInactivityTimer, &lInetLayer);
}
}
#endif // INET_TCP_IDLE_CHECK_INTERVAL > 0
@@ -2554,7 +2555,7 @@
{
if (mConnectTimeoutMsecs > 0)
{
- Layer().SystemLayer()->StartTimer(mConnectTimeoutMsecs, TCPConnectTimeoutHandler, this);
+ Layer().SystemLayer()->StartTimer(System::Clock::Milliseconds32(mConnectTimeoutMsecs), TCPConnectTimeoutHandler, this);
}
}
@@ -2746,7 +2747,7 @@
void TCPEndPoint::ScheduleNextTCPUserTimeoutPoll(uint32_t aTimeOut)
{
- Layer().SystemLayer()->StartTimer(aTimeOut, TCPUserTimeoutHandler, this);
+ Layer().SystemLayer()->StartTimer(System::Clock::Milliseconds32(aTimeOut), TCPUserTimeoutHandler, this);
}
#if INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS
diff --git a/src/inet/tests/TestInetCommonPosix.cpp b/src/inet/tests/TestInetCommonPosix.cpp
index 1cdb9a2..4895ac3 100644
--- a/src/inet/tests/TestInetCommonPosix.cpp
+++ b/src/inet/tests/TestInetCommonPosix.cpp
@@ -442,7 +442,7 @@
// Start a timer (with a no-op callback) to ensure that WaitForEvents() does not block longer than aSleepTimeMilliseconds.
gSystemLayer.StartTimer(
- aSleepTimeMilliseconds, [](System::Layer *, void *) -> void {}, nullptr);
+ System::Clock::Milliseconds32(aSleepTimeMilliseconds), [](System::Layer *, void *) -> void {}, nullptr);
#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
gSystemLayer.PrepareEvents();
diff --git a/src/inet/tests/TestInetEndPoint.cpp b/src/inet/tests/TestInetEndPoint.cpp
index 3843d07..8e8aa81 100644
--- a/src/inet/tests/TestInetEndPoint.cpp
+++ b/src/inet/tests/TestInetEndPoint.cpp
@@ -53,6 +53,7 @@
using namespace chip;
using namespace chip::Inet;
using namespace chip::System;
+using namespace chip::System::Clock::Literals;
#define TOOL_NAME "TestInetEndPoint"
@@ -105,7 +106,7 @@
NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE);
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
- err = gSystemLayer.StartTimer(10, HandleTimer, nullptr);
+ err = gSystemLayer.StartTimer(10_ms32, HandleTimer, nullptr);
NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE);
// then init network
@@ -333,14 +334,14 @@
// Verify same aComplete and aAppState args do not exhaust timer pool
for (int i = 0; i < CHIP_SYSTEM_CONFIG_NUM_TIMERS + 1; i++)
{
- err = gSystemLayer.StartTimer(10, HandleTimer, nullptr);
+ err = gSystemLayer.StartTimer(10_ms32, HandleTimer, nullptr);
NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
}
#if CHIP_SYSTEM_CONFIG_USE_TIMER_POOL
char numTimersTest[CHIP_SYSTEM_CONFIG_NUM_TIMERS + 1];
for (int i = 0; i < CHIP_SYSTEM_CONFIG_NUM_TIMERS + 1; i++)
- err = gSystemLayer.StartTimer(10, HandleTimer, &numTimersTest[i]);
+ err = gSystemLayer.StartTimer(10_ms32, HandleTimer, &numTimersTest[i]);
NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_NO_MEMORY);
#endif // CHIP_SYSTEM_CONFIG_USE_TIMER_POOL
diff --git a/src/inet/tests/TestInetLayer.cpp b/src/inet/tests/TestInetLayer.cpp
index cbda0f0..61a5438 100644
--- a/src/inet/tests/TestInetLayer.cpp
+++ b/src/inet/tests/TestInetLayer.cpp
@@ -524,7 +524,7 @@
gSendIntervalExpired = false;
gSystemLayer.CancelTimer(Common::HandleSendTimerComplete, nullptr);
- gSystemLayer.StartTimer(gSendIntervalMs, Common::HandleSendTimerComplete, nullptr);
+ gSystemLayer.StartTimer(System::Clock::Milliseconds32(gSendIntervalMs), Common::HandleSendTimerComplete, nullptr);
SetStatusFailed(sTestState.mStatus);
}
@@ -760,7 +760,7 @@
else
{
gSendIntervalExpired = false;
- gSystemLayer.StartTimer(gSendIntervalMs, Common::HandleSendTimerComplete, nullptr);
+ gSystemLayer.StartTimer(System::Clock::Milliseconds32(gSendIntervalMs), Common::HandleSendTimerComplete, nullptr);
if (sTestState.mStats.mTransmit.mActual < sTestState.mStats.mTransmit.mExpected)
{
diff --git a/src/inet/tests/TestInetLayerMulticast.cpp b/src/inet/tests/TestInetLayerMulticast.cpp
index af9be78..7e2ad4d 100644
--- a/src/inet/tests/TestInetLayerMulticast.cpp
+++ b/src/inet/tests/TestInetLayerMulticast.cpp
@@ -701,7 +701,7 @@
else
{
gSendIntervalExpired = false;
- gSystemLayer.StartTimer(gSendIntervalMs, Common::HandleSendTimerComplete, nullptr);
+ gSystemLayer.StartTimer(System::Clock::Milliseconds32(gSendIntervalMs), Common::HandleSendTimerComplete, nullptr);
lStatus = DriveSendForGroups(sGroupAddresses);
SuccessOrExit(lStatus);
diff --git a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp
index 1cd1dbd..d4e3583 100644
--- a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp
+++ b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp
@@ -520,7 +520,7 @@
return CHIP_NO_ERROR;
}
- return mSystemLayer->StartTimer(delayMs.Value(), &ResolveRetryCallback, this);
+ return mSystemLayer->StartTimer(System::Clock::Milliseconds32(delayMs.Value()), &ResolveRetryCallback, this);
}
void MinMdnsResolver::ResolveRetryCallback(System::Layer *, void * self)
diff --git a/src/lib/dnssd/minimal_mdns/tests/TestActiveResolveAttempts.cpp b/src/lib/dnssd/minimal_mdns/tests/TestActiveResolveAttempts.cpp
index 0170bf6..d100ce8 100644
--- a/src/lib/dnssd/minimal_mdns/tests/TestActiveResolveAttempts.cpp
+++ b/src/lib/dnssd/minimal_mdns/tests/TestActiveResolveAttempts.cpp
@@ -27,14 +27,17 @@
class MockClock : public System::Clock::ClockBase
{
public:
- System::Clock::Microseconds64 GetMonotonicMicroseconds64() override { return System::Clock::Microseconds64(mUsec); }
- System::Clock::Milliseconds64 GetMonotonicMilliseconds64() override { return System::Clock::Milliseconds64(mUsec / 1000); }
+ System::Clock::Microseconds64 GetMonotonicMicroseconds64() override { return mUsec; }
+ System::Clock::Milliseconds64 GetMonotonicMilliseconds64() override
+ {
+ return std::chrono::duration_cast<System::Clock::Milliseconds64>(mUsec);
+ }
- void AdvanceMs(MonotonicMilliseconds ms) { mUsec += ms * 1000L; }
- void AdvanceSec(uint32_t s) { AdvanceMs(s * 1000); }
+ void AdvanceMs(uint32_t ms) { mUsec += System::Clock::Milliseconds32(ms); }
+ void AdvanceSec(uint32_t s) { mUsec += System::Clock::Seconds32(s); }
private:
- MonotonicMicroseconds mUsec = 0;
+ System::Clock::Microseconds64 mUsec;
};
PeerId MakePeerId(NodeId nodeId)
diff --git a/src/messaging/ExchangeContext.cpp b/src/messaging/ExchangeContext.cpp
index 3f358be..24ee625 100644
--- a/src/messaging/ExchangeContext.cpp
+++ b/src/messaging/ExchangeContext.cpp
@@ -338,7 +338,7 @@
return CHIP_ERROR_INTERNAL;
}
- return lSystemLayer->StartTimer(mResponseTimeout, HandleResponseTimeout, this);
+ return lSystemLayer->StartTimer(chip::System::Clock::Milliseconds32(mResponseTimeout), HandleResponseTimeout, this);
}
void ExchangeContext::CancelResponseTimer()
diff --git a/src/messaging/ReliableMessageMgr.cpp b/src/messaging/ReliableMessageMgr.cpp
index 66219af..d866311 100644
--- a/src/messaging/ReliableMessageMgr.cpp
+++ b/src/messaging/ReliableMessageMgr.cpp
@@ -454,7 +454,7 @@
ChipLogDetail(ExchangeManager, "ReliableMessageMgr::StartTimer set timer for %" PRIu64, timerArmValue);
#endif
StopTimer();
- res = mSystemLayer->StartTimer((uint32_t) timerArmValue, Timeout, this);
+ res = mSystemLayer->StartTimer(System::Clock::Milliseconds32(timerArmValue), Timeout, this);
VerifyOrDieWithMsg(res == CHIP_NO_ERROR, ExchangeManager,
"Cannot start ReliableMessageMgr::Timeout %" CHIP_ERROR_FORMAT, res.Format());
@@ -471,7 +471,7 @@
{
#if defined(RMP_TICKLESS_DEBUG)
ChipLogDetail(ExchangeManager, "Not setting ReliableMessageProtocol timeout at %" PRIu64,
- System::SystemClock().GetMonotonicMilliseconds());
+ System::SystemClock().GetMonotonicTimestamp().count());
#endif
StopTimer();
}
diff --git a/src/messaging/tests/echo/echo_requester.cpp b/src/messaging/tests/echo/echo_requester.cpp
index a71e312..d2f8780 100644
--- a/src/messaging/tests/echo/echo_requester.cpp
+++ b/src/messaging/tests/echo/echo_requester.cpp
@@ -123,7 +123,7 @@
gLastEchoTime = chip::System::SystemClock().GetMonotonicMilliseconds();
- err = chip::DeviceLayer::SystemLayer().StartTimer(gEchoInterval, EchoTimerHandler, NULL);
+ err = chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(gEchoInterval), EchoTimerHandler, NULL);
if (err != CHIP_NO_ERROR)
{
printf("Unable to schedule timer\n");
@@ -262,7 +262,7 @@
// Arrange to get a callback whenever an Echo Response is received.
gEchoClient.SetEchoResponseReceived(HandleEchoResponseReceived);
- err = chip::DeviceLayer::SystemLayer().StartTimer(0, EchoTimerHandler, NULL);
+ err = chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Zero, EchoTimerHandler, NULL);
SuccessOrExit(err);
chip::DeviceLayer::PlatformMgr().RunEventLoop();
diff --git a/src/platform/Darwin/PlatformManagerImpl.h b/src/platform/Darwin/PlatformManagerImpl.h
index 1c58a1c..40eab2a 100644
--- a/src/platform/Darwin/PlatformManagerImpl.h
+++ b/src/platform/Darwin/PlatformManagerImpl.h
@@ -58,7 +58,7 @@
CHIP_ERROR _InitChipStack();
CHIP_ERROR _Shutdown();
- CHIP_ERROR _StartChipTimer(int64_t aMilliseconds) { return CHIP_ERROR_NOT_IMPLEMENTED; };
+ CHIP_ERROR _StartChipTimer(System::Clock::Timeout delay) { return CHIP_ERROR_NOT_IMPLEMENTED; };
CHIP_ERROR _StartEventLoopTask();
CHIP_ERROR _StopEventLoopTask();
void _RunEventLoop();
diff --git a/src/platform/DeviceControlServer.cpp b/src/platform/DeviceControlServer.cpp
index 92f4847..9d8707e 100644
--- a/src/platform/DeviceControlServer.cpp
+++ b/src/platform/DeviceControlServer.cpp
@@ -55,8 +55,7 @@
CHIP_ERROR DeviceControlServer::ArmFailSafe(uint16_t expiryLengthSeconds)
{
- uint32_t timerMs = expiryLengthSeconds * 1000;
- DeviceLayer::SystemLayer().StartTimer(timerMs, HandleArmFailSafe, this);
+ DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(expiryLengthSeconds), HandleArmFailSafe, this);
return CHIP_NO_ERROR;
}
diff --git a/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp b/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp
index 52672a0..c7ee1c9 100644
--- a/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp
+++ b/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp
@@ -624,7 +624,8 @@
ChipLogProgress(DeviceLayer, "Next WiFi station reconnect in %" PRIu32 " ms", timeToNextConnect);
- ReturnOnFailure(DeviceLayer::SystemLayer().StartTimer(timeToNextConnect, DriveStationState, NULL));
+ ReturnOnFailure(DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(timeToNextConnect),
+ DriveStationState, NULL));
}
}
}
@@ -747,7 +748,7 @@
// Compute the amount of idle time before the AP should be deactivated and
// arm a timer to fire at that time.
apTimeout = (uint32_t)((mLastAPDemandTime + mWiFiAPIdleTimeoutMS) - now);
- err = DeviceLayer::SystemLayer().StartTimer(apTimeout, DriveAPState, NULL);
+ err = DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(apTimeout), DriveAPState, NULL);
SuccessOrExit(err);
ChipLogProgress(DeviceLayer, "Next WiFi AP timeout in %" PRIu32 " ms", apTimeout);
}
diff --git a/src/platform/ESP32/bluedroid/BLEManagerImpl.cpp b/src/platform/ESP32/bluedroid/BLEManagerImpl.cpp
index 8a512d8..d01cdc6 100644
--- a/src/platform/ESP32/bluedroid/BLEManagerImpl.cpp
+++ b/src/platform/ESP32/bluedroid/BLEManagerImpl.cpp
@@ -176,8 +176,10 @@
if (val)
{
mAdvertiseStartTime = System::SystemClock().GetMonotonicMilliseconds();
- ReturnErrorOnFailure(DeviceLayer::SystemLayer().StartTimer(kAdvertiseTimeout, HandleAdvertisementTimer, this));
- ReturnErrorOnFailure(DeviceLayer::SystemLayer().StartTimer(kFastAdvertiseTimeout, HandleFastAdvertisementTimer, this));
+ ReturnErrorOnFailure(DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(kAdvertiseTimeout),
+ HandleAdvertisementTimer, this));
+ ReturnErrorOnFailure(DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(kFastAdvertiseTimeout),
+ HandleFastAdvertisementTimer, this));
}
mFlags.Set(Flags::kFastAdvertisingEnabled, val);
mFlags.Set(Flags::kAdvertisingRefreshNeeded, 1);
diff --git a/src/platform/ESP32/nimble/BLEManagerImpl.cpp b/src/platform/ESP32/nimble/BLEManagerImpl.cpp
index 061406d..e1ec0f9 100644
--- a/src/platform/ESP32/nimble/BLEManagerImpl.cpp
+++ b/src/platform/ESP32/nimble/BLEManagerImpl.cpp
@@ -172,8 +172,10 @@
if (val)
{
mAdvertiseStartTime = System::SystemClock().GetMonotonicMilliseconds();
- ReturnErrorOnFailure(DeviceLayer::SystemLayer().StartTimer(kAdvertiseTimeout, HandleAdvertisementTimer, this));
- ReturnErrorOnFailure(DeviceLayer::SystemLayer().StartTimer(kFastAdvertiseTimeout, HandleFastAdvertisementTimer, this));
+ ReturnErrorOnFailure(DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(kAdvertiseTimeout),
+ HandleAdvertisementTimer, this));
+ ReturnErrorOnFailure(DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(kFastAdvertiseTimeout),
+ HandleFastAdvertisementTimer, this));
}
mFlags.Set(Flags::kFastAdvertisingEnabled, val);
diff --git a/src/platform/Linux/BLEManagerImpl.cpp b/src/platform/Linux/BLEManagerImpl.cpp
index 9a6ea42..1b03f0f 100644
--- a/src/platform/Linux/BLEManagerImpl.cpp
+++ b/src/platform/Linux/BLEManagerImpl.cpp
@@ -803,7 +803,7 @@
}
mBLEScanConfig.mBleScanState = BleScanState::kConnecting;
- DeviceLayer::SystemLayer().StartTimer(kConnectTimeoutMs, HandleConnectTimeout, mpEndpoint);
+ DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(kConnectTimeoutMs), HandleConnectTimeout, mpEndpoint);
mDeviceScanner->StopScan();
ConnectDevice(device, mpEndpoint);
diff --git a/src/platform/Linux/ConnectivityManagerImpl.cpp b/src/platform/Linux/ConnectivityManagerImpl.cpp
index dad2821..4433ccd 100644
--- a/src/platform/Linux/ConnectivityManagerImpl.cpp
+++ b/src/platform/Linux/ConnectivityManagerImpl.cpp
@@ -731,7 +731,7 @@
// Compute the amount of idle time before the AP should be deactivated and
// arm a timer to fire at that time.
apTimeout = (uint32_t)((mLastAPDemandTime + mWiFiAPIdleTimeoutMS) - now);
- err = DeviceLayer::SystemLayer().StartTimer(apTimeout, DriveAPState, NULL);
+ err = DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(apTimeout), DriveAPState, NULL);
SuccessOrExit(err);
ChipLogProgress(DeviceLayer, "Next WiFi AP timeout in %" PRIu32 " s", apTimeout / 1000);
}
diff --git a/src/platform/Linux/DnssdImpl.cpp b/src/platform/Linux/DnssdImpl.cpp
index c415aef..e8865c6 100644
--- a/src/platform/Linux/DnssdImpl.cpp
+++ b/src/platform/Linux/DnssdImpl.cpp
@@ -315,7 +315,7 @@
{
mEarliestTimeout = timer->mAbsTimeout;
auto msDelay = std::chrono::duration_cast<std::chrono::milliseconds>(steady_clock::now() - mEarliestTimeout).count();
- DeviceLayer::SystemLayer().StartTimer(msDelay, SystemTimerCallback, this);
+ DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(msDelay), SystemTimerCallback, this);
}
}
diff --git a/src/platform/Linux/bluez/ChipDeviceScanner.cpp b/src/platform/Linux/bluez/ChipDeviceScanner.cpp
index 79ff95b..b6da0f4 100644
--- a/src/platform/Linux/bluez/ChipDeviceScanner.cpp
+++ b/src/platform/Linux/bluez/ChipDeviceScanner.cpp
@@ -131,7 +131,8 @@
return CHIP_ERROR_INTERNAL;
}
- CHIP_ERROR err = chip::DeviceLayer::SystemLayer().StartTimer(timeoutMs, TimerExpiredCallback, static_cast<void *>(this));
+ CHIP_ERROR err = chip::DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(timeoutMs), TimerExpiredCallback,
+ static_cast<void *>(this));
if (err != CHIP_NO_ERROR)
{
diff --git a/src/platform/LwIPEventSupport.cpp b/src/platform/LwIPEventSupport.cpp
index 0b2165a..0a4cead 100644
--- a/src/platform/LwIPEventSupport.cpp
+++ b/src/platform/LwIPEventSupport.cpp
@@ -55,9 +55,9 @@
return PlatformMgr().PostEvent(&event);
}
-CHIP_ERROR PlatformEventing::StartTimer(System::Layer & aLayer, uint32_t aMilliseconds)
+CHIP_ERROR PlatformEventing::StartTimer(System::Layer & aLayer, System::Clock::Timeout delay)
{
- return PlatformMgr().StartChipTimer(aMilliseconds);
+ return PlatformMgr().StartChipTimer(delay);
}
} // namespace System
diff --git a/src/platform/P6/ConnectivityManagerImpl.cpp b/src/platform/P6/ConnectivityManagerImpl.cpp
index a7095b4..a397a15 100644
--- a/src/platform/P6/ConnectivityManagerImpl.cpp
+++ b/src/platform/P6/ConnectivityManagerImpl.cpp
@@ -413,7 +413,7 @@
// Compute the amount of idle time before the AP should be deactivated and
// arm a timer to fire at that time.
apTimeout = (uint32_t)((mLastAPDemandTime + mWiFiAPIdleTimeoutMS) - now);
- err = DeviceLayer::SystemLayer().StartTimer(apTimeout, DriveAPState, NULL);
+ err = DeviceLayer::SystemLayer().StartTimer(Clock::Milliseconds32(apTimeout), DriveAPState, NULL);
SuccessOrExit(err);
ChipLogProgress(DeviceLayer, "Next WiFi AP timeout in %" PRIu32 " ms", apTimeout);
}
@@ -570,7 +570,7 @@
uint32_t timeToNextConnect = (uint32_t)((mLastStationConnectFailTime + mWiFiStationReconnectIntervalMS) - now);
ChipLogProgress(DeviceLayer, "Next WiFi station reconnect in %" PRId32 " ms ", timeToNextConnect);
- err = DeviceLayer::SystemLayer().StartTimer(timeToNextConnect, DriveStationState, NULL);
+ err = DeviceLayer::SystemLayer().StartTimer(Clock::Milliseconds32(timeToNextConnect), DriveStationState, NULL);
SuccessOrExit(err);
}
}
diff --git a/src/platform/Zephyr/BLEManagerImpl.cpp b/src/platform/Zephyr/BLEManagerImpl.cpp
index 0ad70bd..8b7696d 100644
--- a/src/platform/Zephyr/BLEManagerImpl.cpp
+++ b/src/platform/Zephyr/BLEManagerImpl.cpp
@@ -291,15 +291,17 @@
if (mFlags.Has(Flags::kFastAdvertisingEnabled))
{
// Start timer to change advertising interval.
- DeviceLayer::SystemLayer().StartTimer(CHIP_DEVICE_CONFIG_BLE_ADVERTISING_INTERVAL_CHANGE_TIME,
- HandleBLEAdvertisementIntervalChange, this);
+ DeviceLayer::SystemLayer().StartTimer(
+ System::Clock::Milliseconds32(CHIP_DEVICE_CONFIG_BLE_ADVERTISING_INTERVAL_CHANGE_TIME),
+ HandleBLEAdvertisementIntervalChange, this);
}
// Start timer to disable CHIPoBLE advertisement after timeout expiration only if it isn't advertising rerun (in that case
// timer is already running).
if (!isAdvertisingRerun)
{
- DeviceLayer::SystemLayer().StartTimer(CHIP_DEVICE_CONFIG_BLE_ADVERTISING_TIMEOUT, HandleBLEAdvertisementTimeout, this);
+ DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(CHIP_DEVICE_CONFIG_BLE_ADVERTISING_TIMEOUT),
+ HandleBLEAdvertisementTimeout, this);
}
}
diff --git a/src/platform/fake/PlatformManagerImpl.h b/src/platform/fake/PlatformManagerImpl.h
index 0a3a16c..4bbd9df 100644
--- a/src/platform/fake/PlatformManagerImpl.h
+++ b/src/platform/fake/PlatformManagerImpl.h
@@ -52,7 +52,7 @@
CHIP_ERROR _StopEventLoopTask() { return CHIP_ERROR_NOT_IMPLEMENTED; }
CHIP_ERROR _PostEvent(const ChipDeviceEvent * event) { return CHIP_NO_ERROR; }
void _DispatchEvent(const ChipDeviceEvent * event) {}
- CHIP_ERROR _StartChipTimer(int64_t durationMS) { return CHIP_ERROR_NOT_IMPLEMENTED; }
+ CHIP_ERROR _StartChipTimer(System::Clock::Timeout duration) { return CHIP_ERROR_NOT_IMPLEMENTED; }
void _LockChipStack() {}
bool _TryLockChipStack() { return true; }
diff --git a/src/platform/mbed/PlatformManagerImpl.cpp b/src/platform/mbed/PlatformManagerImpl.cpp
index d03f7b8..0dc462c 100644
--- a/src/platform/mbed/PlatformManagerImpl.cpp
+++ b/src/platform/mbed/PlatformManagerImpl.cpp
@@ -257,7 +257,7 @@
return TranslateOsStatus(err);
}
-CHIP_ERROR PlatformManagerImpl::_StartChipTimer(int64_t durationMS)
+CHIP_ERROR PlatformManagerImpl::_StartChipTimer(System::Clock::Timeout duration)
{
// Let LayerSocketsLoop::PrepareSelect() handle timers.
return CHIP_NO_ERROR;
diff --git a/src/platform/mbed/PlatformManagerImpl.h b/src/platform/mbed/PlatformManagerImpl.h
index 6c73cd0..59b1198 100644
--- a/src/platform/mbed/PlatformManagerImpl.h
+++ b/src/platform/mbed/PlatformManagerImpl.h
@@ -88,7 +88,7 @@
void _RunEventLoop();
CHIP_ERROR _StartEventLoopTask();
CHIP_ERROR _StopEventLoopTask();
- CHIP_ERROR _StartChipTimer(int64_t durationMS);
+ CHIP_ERROR _StartChipTimer(System::Clock::Timeout duration);
CHIP_ERROR _Shutdown();
void ProcessDeviceEvents();
diff --git a/src/platform/tests/TestPlatformMgr.cpp b/src/platform/tests/TestPlatformMgr.cpp
index fd8bbe5..aab3a66 100644
--- a/src/platform/tests/TestPlatformMgr.cpp
+++ b/src/platform/tests/TestPlatformMgr.cpp
@@ -181,7 +181,7 @@
class MockSystemLayer : public System::LayerImpl
{
public:
- CHIP_ERROR StartTimer(uint32_t aDelayMilliseconds, System::TimerCompleteCallback aComplete, void * aAppState) override
+ CHIP_ERROR StartTimer(System::Clock::Timeout aDelay, System::TimerCompleteCallback aComplete, void * aAppState) override
{
return CHIP_APPLICATION_ERROR(1);
}
@@ -202,7 +202,8 @@
NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, &DeviceLayer::SystemLayer() == static_cast<chip::System::Layer *>(&systemLayer));
- NL_TEST_ASSERT(inSuite, DeviceLayer::SystemLayer().StartTimer(0, nullptr, nullptr) == CHIP_APPLICATION_ERROR(1));
+ NL_TEST_ASSERT(inSuite,
+ DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Zero, nullptr, nullptr) == CHIP_APPLICATION_ERROR(1));
NL_TEST_ASSERT(inSuite, DeviceLayer::SystemLayer().ScheduleWork(nullptr, nullptr) == CHIP_APPLICATION_ERROR(2));
err = PlatformMgr().Shutdown();
diff --git a/src/protocols/bdx/TransferFacilitator.cpp b/src/protocols/bdx/TransferFacilitator.cpp
index 861fb18..98ff832 100644
--- a/src/protocols/bdx/TransferFacilitator.cpp
+++ b/src/protocols/bdx/TransferFacilitator.cpp
@@ -75,13 +75,13 @@
HandleTransferSessionOutput(outEvent);
VerifyOrReturn(mSystemLayer != nullptr, ChipLogError(BDX, "%s mSystemLayer is null", __FUNCTION__));
- mSystemLayer->StartTimer(mPollFreqMs, PollTimerHandler, this);
+ mSystemLayer->StartTimer(System::Clock::Milliseconds32(mPollFreqMs), PollTimerHandler, this);
}
void TransferFacilitator::ScheduleImmediatePoll()
{
VerifyOrReturn(mSystemLayer != nullptr, ChipLogError(BDX, "%s mSystemLayer is null", __FUNCTION__));
- mSystemLayer->StartTimer(kImmediatePollDelayMs, PollTimerHandler, this);
+ mSystemLayer->StartTimer(System::Clock::Milliseconds32(kImmediatePollDelayMs), PollTimerHandler, this);
}
CHIP_ERROR Responder::PrepareForTransfer(System::Layer * layer, TransferRole role, BitFlags<TransferControlFlags> xferControlOpts,
@@ -94,7 +94,7 @@
ReturnErrorOnFailure(mTransfer.WaitForTransfer(role, xferControlOpts, maxBlockSize, timeoutMs));
- mSystemLayer->StartTimer(mPollFreqMs, PollTimerHandler, this);
+ mSystemLayer->StartTimer(System::Clock::Milliseconds32(mPollFreqMs), PollTimerHandler, this);
return CHIP_NO_ERROR;
}
@@ -108,7 +108,7 @@
ReturnErrorOnFailure(mTransfer.StartTransfer(role, initData, timeoutMs));
- mSystemLayer->StartTimer(mPollFreqMs, PollTimerHandler, this);
+ mSystemLayer->StartTimer(System::Clock::Milliseconds32(mPollFreqMs), PollTimerHandler, this);
return CHIP_NO_ERROR;
}
diff --git a/src/system/LwIPEventSupport.h b/src/system/LwIPEventSupport.h
index 7a2511e..3679bec 100644
--- a/src/system/LwIPEventSupport.h
+++ b/src/system/LwIPEventSupport.h
@@ -31,7 +31,7 @@
public:
static CHIP_ERROR ScheduleLambdaBridge(System::Layer & aLayer, const LambdaBridge & bridge);
static CHIP_ERROR PostEvent(System::Layer & aLayer, Object & aTarget, EventType aType, uintptr_t aArgument);
- static CHIP_ERROR StartTimer(System::Layer & aLayer, uint32_t aMilliseconds);
+ static CHIP_ERROR StartTimer(System::Layer & aLayer, System::Clock::Timeout aTimeout);
};
} // namespace System
diff --git a/src/system/SystemClock.cpp b/src/system/SystemClock.cpp
index 0912bba..1ec09aa 100644
--- a/src/system/SystemClock.cpp
+++ b/src/system/SystemClock.cpp
@@ -170,24 +170,6 @@
#endif // CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME
-static_assert(std::is_unsigned<ClockBase::Tick>::value, "ClockBase::Tick must be unsigned");
-constexpr ClockBase::Tick kMaxTick = static_cast<ClockBase::Tick>(0) - static_cast<ClockBase::Tick>(1);
-constexpr ClockBase::Tick kHalfMaxTick = static_cast<ClockBase::Tick>(kMaxTick / 2);
-
-bool IsEarlier(const ClockBase::Tick & inFirst, const ClockBase::Tick & inSecond)
-{
- // account for timer wrap with the assumption that no two input times will "naturally"
- // be more than half the timer range apart.
- return (((inFirst < inSecond) && (inSecond - inFirst < kHalfMaxTick)) ||
- ((inFirst > inSecond) && (inFirst - inSecond > kHalfMaxTick)));
-}
-
-ClockBase::Tick AddOffset(const ClockBase::Tick & base, const ClockBase::Tick & offset)
-{
- const ClockBase::Tick increment = (offset < kHalfMaxTick) ? offset : (kHalfMaxTick - 1);
- return base + increment;
-}
-
#if CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS || CHIP_SYSTEM_CONFIG_USE_SOCKETS
Microseconds64 TimevalToMicroseconds(const timeval & tv)
@@ -195,15 +177,12 @@
return Seconds64(tv.tv_sec) + Microseconds64(tv.tv_usec);
}
-MonotonicMilliseconds TimevalToMilliseconds(const timeval & in)
+void ToTimeval(Microseconds64 in, timeval & out)
{
- return static_cast<MonotonicMilliseconds>(in.tv_sec) * 1000 + static_cast<MonotonicMilliseconds>(in.tv_usec / 1000);
-}
-
-void MillisecondsToTimeval(MonotonicMilliseconds in, timeval & out)
-{
- out.tv_sec = static_cast<time_t>(in / 1000);
- out.tv_usec = static_cast<suseconds_t>((in % 1000) * 1000);
+ Seconds32 seconds = std::chrono::duration_cast<Seconds32>(in);
+ in -= seconds;
+ out.tv_sec = static_cast<time_t>(seconds.count());
+ out.tv_usec = static_cast<suseconds_t>(in.count());
}
#endif // CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS || CHIP_SYSTEM_CONFIG_USE_SOCKETS
diff --git a/src/system/SystemClock.h b/src/system/SystemClock.h
index d918dad..6d02572 100644
--- a/src/system/SystemClock.h
+++ b/src/system/SystemClock.h
@@ -221,29 +221,9 @@
using MonotonicMicroseconds = ClockBase::MonotonicMicroseconds;
using MonotonicMilliseconds = ClockBase::MonotonicMilliseconds;
-/**
- * Compares two time values and returns true if the first value is earlier than the second value.
- *
- * A static API that gets called to compare 2 time values. This API attempts to account for timer wrap by assuming that
- * the difference between the 2 input values will only be more than half the timestamp scalar range if a timer wrap has
- * occurred between the 2 samples.
- *
- * @note
- * This implementation assumes that ClockBase::Tick is an unsigned scalar type.
- *
- * @return true if the first param is earlier than the second, false otherwise.
- */
-bool IsEarlier(const ClockBase::Tick & first, const ClockBase::Tick & second);
-
-/**
- * Returns a time value plus an offset, with the offset clamped below half the time range.
- */
-ClockBase::Tick AddOffset(const ClockBase::Tick & base, const ClockBase::Tick & offset);
-
#if CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS || CHIP_SYSTEM_CONFIG_USE_SOCKETS
Microseconds64 TimevalToMicroseconds(const timeval & in);
-MonotonicMilliseconds TimevalToMilliseconds(const timeval & in);
-void MillisecondsToTimeval(MonotonicMilliseconds in, timeval & out);
+void ToTimeval(Microseconds64 in, timeval & out);
#endif // CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS || CHIP_SYSTEM_CONFIG_USE_SOCKETS
} // namespace Clock
diff --git a/src/system/SystemLayer.h b/src/system/SystemLayer.h
index 32d0738..b731ec3 100644
--- a/src/system/SystemLayer.h
+++ b/src/system/SystemLayer.h
@@ -32,6 +32,8 @@
#include <lib/support/CodeUtils.h>
#include <lib/support/DLLUtil.h>
+#include <lib/support/ObjectLifeCycle.h>
+#include <system/SystemClock.h>
#include <system/SystemError.h>
#include <system/SystemEvent.h>
#include <system/SystemObject.h>
@@ -100,7 +102,7 @@
* arguments. If called with @a aComplete and @a aAppState identical to an existing timer,
* the currently-running timer will first be cancelled.
*
- * @param[in] aDelayMilliseconds Time in milliseconds before this timer fires.
+ * @param[in] aDelay Time before this timer fires.
* @param[in] aComplete A pointer to the function called when timer expires.
* @param[in] aAppState A pointer to the application state object used when timer expires.
*
@@ -108,7 +110,7 @@
* @return CHIP_ERROR_NO_MEMORY If a timer cannot be allocated.
* @return Other Value indicating timer failed to start.
*/
- virtual CHIP_ERROR StartTimer(uint32_t aDelayMilliseconds, TimerCompleteCallback aComplete, void * aAppState) = 0;
+ virtual CHIP_ERROR StartTimer(Clock::Timeout aDelay, TimerCompleteCallback aComplete, void * aAppState) = 0;
/**
* @brief
diff --git a/src/system/SystemLayerImplLibevent.cpp b/src/system/SystemLayerImplLibevent.cpp
index 2dc60a4..2820394 100644
--- a/src/system/SystemLayerImplLibevent.cpp
+++ b/src/system/SystemLayerImplLibevent.cpp
@@ -164,7 +164,7 @@
}
}
-CHIP_ERROR LayerImplLibevent::StartTimer(uint32_t delayMilliseconds, TimerCompleteCallback onComplete, void * appState)
+CHIP_ERROR LayerImplLibevent::StartTimer(Clock::Timeout delay, TimerCompleteCallback onComplete, void * appState)
{
VerifyOrReturnError(mLayerState.IsInitialized(), CHIP_ERROR_INCORRECT_STATE);
@@ -181,9 +181,9 @@
VerifyOrReturnError(e != nullptr, CHIP_ERROR_NO_MEMORY);
timer->mEvent = e;
- timeval delay;
- Clock::MillisecondsToTimeval(delayMilliseconds, delay);
- int status = evtimer_add(e, &delay);
+ timeval tv;
+ Clock::ToTimeval(delay, tv);
+ int status = evtimer_add(e, &tv);
VerifyOrReturnError(status == 0, CHIP_ERROR_INTERNAL);
return CHIP_NO_ERROR;
@@ -210,7 +210,7 @@
assertChipStackLockedByCurrentThread();
VerifyOrReturnError(mLayerState.IsInitialized(), CHIP_ERROR_INCORRECT_STATE);
- return StartTimer(0, onComplete, appState);
+ return StartTimer(Clock::Zero, onComplete, appState);
}
// static
diff --git a/src/system/SystemLayerImplLibevent.h b/src/system/SystemLayerImplLibevent.h
index 7db74b5..c013d73 100644
--- a/src/system/SystemLayerImplLibevent.h
+++ b/src/system/SystemLayerImplLibevent.h
@@ -50,7 +50,7 @@
CHIP_ERROR Init() override;
CHIP_ERROR Shutdown() override;
bool IsInitialized() const override { return mLayerState.IsInitialized(); }
- CHIP_ERROR StartTimer(uint32_t delayMilliseconds, TimerCompleteCallback onComplete, void * appState) override;
+ CHIP_ERROR StartTimer(Clock::Timeout delay, TimerCompleteCallback onComplete, void * appState) override;
void CancelTimer(TimerCompleteCallback onComplete, void * appState) override;
CHIP_ERROR ScheduleWork(TimerCompleteCallback onComplete, void * appState) override;
diff --git a/src/system/SystemLayerImplLwIP.cpp b/src/system/SystemLayerImplLwIP.cpp
index 10a145a..ac4e6e7 100644
--- a/src/system/SystemLayerImplLwIP.cpp
+++ b/src/system/SystemLayerImplLwIP.cpp
@@ -52,15 +52,15 @@
return CHIP_NO_ERROR;
}
-CHIP_ERROR LayerImplLwIP::StartTimer(uint32_t delayMilliseconds, TimerCompleteCallback onComplete, void * appState)
+CHIP_ERROR LayerImplLwIP::StartTimer(Clock::Timeout delay, TimerCompleteCallback onComplete, void * appState)
{
VerifyOrReturnError(mLayerState.IsInitialized(), CHIP_ERROR_INCORRECT_STATE);
- CHIP_SYSTEM_FAULT_INJECT(FaultInjection::kFault_TimeoutImmediate, delayMilliseconds = 0);
+ CHIP_SYSTEM_FAULT_INJECT(FaultInjection::kFault_TimeoutImmediate, delay = Clock::Zero);
CancelTimer(onComplete, appState);
- Timer * timer = Timer::New(*this, delayMilliseconds, onComplete, appState);
+ Timer * timer = Timer::New(*this, delay, onComplete, appState);
VerifyOrReturnError(timer != nullptr, CHIP_ERROR_NO_MEMORY);
if (mTimerList.Add(timer) == timer)
@@ -70,7 +70,7 @@
// HandleExpiredTimers() to re-start the timer.
if (!mHandlingTimerComplete)
{
- StartPlatformTimer(delayMilliseconds);
+ StartPlatformTimer(delay);
}
}
return CHIP_NO_ERROR;
@@ -91,7 +91,7 @@
{
VerifyOrReturnError(mLayerState.IsInitialized(), CHIP_ERROR_INCORRECT_STATE);
- Timer * timer = Timer::New(*this, 0, onComplete, appState);
+ Timer * timer = Timer::New(*this, System::Clock::Zero, onComplete, appState);
VerifyOrReturnError(timer != nullptr, CHIP_ERROR_NO_MEMORY);
return ScheduleLambda([timer] { timer->HandleComplete(); });
@@ -194,15 +194,15 @@
* Calls the Platform specific API to start a platform timer. This API is called by the chip::System::Timer class when
* one or more timers are active and require deferred execution.
*
- * @param[in] aDelayMilliseconds The timer duration in milliseconds.
+ * @param[in] aDelay The timer duration in milliseconds.
*
* @return CHIP_NO_ERROR on success, error code otherwise.
*
*/
-CHIP_ERROR LayerImplLwIP::StartPlatformTimer(uint32_t aDelayMilliseconds)
+CHIP_ERROR LayerImplLwIP::StartPlatformTimer(System::Clock::Timeout aDelay)
{
VerifyOrReturnError(IsInitialized(), CHIP_ERROR_INCORRECT_STATE);
- CHIP_ERROR status = PlatformEventing::StartTimer(*this, aDelayMilliseconds);
+ CHIP_ERROR status = PlatformEventing::StartTimer(*this, aDelay);
return status;
}
@@ -227,16 +227,16 @@
// Expire each timer in turn until an unexpired timer is reached or the timerlist is emptied. We set the current expiration
// time outside the loop; that way timers set after the current tick will not be executed within this expiration window
- // regardless how long the processing of the currently expired timers took
- Clock::MonotonicMilliseconds currentTime = SystemClock().GetMonotonicMilliseconds();
+ // regardless how long the processing of the currently expired timers took.
+ // The platform timer API has MSEC resolution so expire any timer with less than 1 msec remaining.
+ Clock::Timestamp expirationTime = SystemClock().GetMonotonicTimestamp() + Clock::Timeout(1);
// limit the number of timers handled before the control is returned to the event queue. The bound is similar to
// (though not exactly same) as that on the sockets-based systems.
- // The platform timer API has MSEC resolution so expire any timer with less than 1 msec remaining.
size_t timersHandled = 0;
Timer * timer = nullptr;
- while ((timersHandled < CHIP_SYSTEM_CONFIG_NUM_TIMERS) && ((timer = mTimerList.PopIfEarlier(currentTime + 1)) != nullptr))
+ while ((timersHandled < CHIP_SYSTEM_CONFIG_NUM_TIMERS) && ((timer = mTimerList.PopIfEarlier(expirationTime)) != nullptr))
{
mHandlingTimerComplete = true;
timer->HandleComplete();
@@ -248,24 +248,17 @@
if (!mTimerList.Empty())
{
// timers still exist so restart the platform timer.
- uint64_t delayMilliseconds = 0ULL;
+ Clock::Timeout delay{ 0 };
- currentTime = SystemClock().GetMonotonicMilliseconds();
+ Clock::Timestamp currentTime = SystemClock().GetMonotonicTimestamp();
- // the next timer expires in the future, so set the delayMilliseconds to a non-zero value
if (currentTime < mTimerList.Earliest()->mAwakenTime)
{
- delayMilliseconds = mTimerList.Earliest()->mAwakenTime - currentTime;
+ // the next timer expires in the future, so set the delay to a non-zero value
+ delay = mTimerList.Earliest()->mAwakenTime - currentTime;
}
- /*
- * StartPlatformTimer() accepts a 32bit value in milliseconds. Timestamps are 64bit numbers. The only way in which this
- * could overflow is if time went backwards (e.g. as a result of a time adjustment from time synchronization). Verify
- * that the timer can still be executed (even if it is very late) and exit if that is the case. Note: if the time sync
- * ever ends up adjusting the clock, we should implement a method that deals with all the timers in the system.
- */
- VerifyOrDie(delayMilliseconds <= UINT32_MAX);
- StartPlatformTimer(static_cast<uint32_t>(delayMilliseconds));
+ StartPlatformTimer(delay);
}
return CHIP_NO_ERROR;
diff --git a/src/system/SystemLayerImplLwIP.h b/src/system/SystemLayerImplLwIP.h
index b2f4d31..4ff2686 100644
--- a/src/system/SystemLayerImplLwIP.h
+++ b/src/system/SystemLayerImplLwIP.h
@@ -38,7 +38,7 @@
CHIP_ERROR Init() override;
CHIP_ERROR Shutdown() override;
bool IsInitialized() const override { return mLayerState.IsInitialized(); }
- CHIP_ERROR StartTimer(uint32_t delayMilliseconds, TimerCompleteCallback onComplete, void * appState) override;
+ CHIP_ERROR StartTimer(Clock::Timeout delay, TimerCompleteCallback onComplete, void * appState) override;
void CancelTimer(TimerCompleteCallback onComplete, void * appState) override;
CHIP_ERROR ScheduleWork(TimerCompleteCallback onComplete, void * appState) override;
@@ -55,7 +55,7 @@
private:
friend class PlatformEventing;
- CHIP_ERROR StartPlatformTimer(uint32_t aDelayMilliseconds);
+ CHIP_ERROR StartPlatformTimer(System::Clock::Timeout aDelay);
Timer::MutexedList mTimerList;
bool mHandlingTimerComplete; // true while handling any timer completion
diff --git a/src/system/SystemLayerImplSelect.cpp b/src/system/SystemLayerImplSelect.cpp
index 14d2c4c..0a7e783 100644
--- a/src/system/SystemLayerImplSelect.cpp
+++ b/src/system/SystemLayerImplSelect.cpp
@@ -30,8 +30,6 @@
#include <errno.h>
-#define DEFAULT_MIN_SLEEP_PERIOD (60 * 60 * 24 * 30) // Month [sec]
-
// Choose an approximation of PTHREAD_NULL if pthread.h doesn't define one.
#if CHIP_SYSTEM_CONFIG_POSIX_LOCKING && !defined(PTHREAD_NULL)
#define PTHREAD_NULL 0
@@ -40,6 +38,8 @@
namespace chip {
namespace System {
+constexpr Clock::Seconds64 kDefaultMinSleepPeriod{ 60 * 60 * 24 * 30 }; // Month [sec]
+
CHIP_ERROR LayerImplSelect::Init()
{
VerifyOrReturnError(mLayerState.SetInitializing(), CHIP_ERROR_INCORRECT_STATE);
@@ -116,15 +116,15 @@
}
}
-CHIP_ERROR LayerImplSelect::StartTimer(uint32_t delayMilliseconds, TimerCompleteCallback onComplete, void * appState)
+CHIP_ERROR LayerImplSelect::StartTimer(Clock::Timeout delay, TimerCompleteCallback onComplete, void * appState)
{
VerifyOrReturnError(mLayerState.IsInitialized(), CHIP_ERROR_INCORRECT_STATE);
- CHIP_SYSTEM_FAULT_INJECT(FaultInjection::kFault_TimeoutImmediate, delayMilliseconds = 0);
+ CHIP_SYSTEM_FAULT_INJECT(FaultInjection::kFault_TimeoutImmediate, delay = System::Clock::Zero);
CancelTimer(onComplete, appState);
- Timer * timer = Timer::New(*this, delayMilliseconds, onComplete, appState);
+ Timer * timer = Timer::New(*this, delay, onComplete, appState);
VerifyOrReturnError(timer != nullptr, CHIP_ERROR_NO_MEMORY);
#if CHIP_SYSTEM_CONFIG_USE_DISPATCH
@@ -139,7 +139,9 @@
}
timer->mTimerSource = timerSource;
- dispatch_source_set_timer(timerSource, dispatch_walltime(NULL, delayMilliseconds * NSEC_PER_MSEC), 0, 2 * NSEC_PER_MSEC);
+ dispatch_source_set_timer(
+ timerSource, dispatch_walltime(NULL, static_cast<int64_t>(Clock::Milliseconds64(delay).count() * NSEC_PER_MSEC)), 0,
+ 2 * NSEC_PER_MSEC);
dispatch_source_set_event_handler(timerSource, ^{
dispatch_source_cancel(timerSource);
dispatch_release(timerSource);
@@ -186,7 +188,7 @@
CancelTimer(onComplete, appState);
- Timer * timer = Timer::New(*this, 0, onComplete, appState);
+ Timer * timer = Timer::New(*this, Clock::Zero, onComplete, appState);
VerifyOrReturnError(timer != nullptr, CHIP_ERROR_NO_MEMORY);
#if CHIP_SYSTEM_CONFIG_USE_DISPATCH
@@ -328,19 +330,17 @@
{
assertChipStackLockedByCurrentThread();
- constexpr Clock::MonotonicMilliseconds kMaxTimeout =
- static_cast<Clock::MonotonicMilliseconds>(DEFAULT_MIN_SLEEP_PERIOD) * kMillisecondsPerSecond;
- const Clock::MonotonicMilliseconds currentTime = SystemClock().GetMonotonicMilliseconds();
- Clock::MonotonicMilliseconds awakenTime = currentTime + kMaxTimeout;
+ const Clock::Timestamp currentTime = SystemClock().GetMonotonicTimestamp();
+ Clock::Timestamp awakenTime = currentTime + kDefaultMinSleepPeriod;
Timer * timer = mTimerList.Earliest();
- if (timer && Clock::IsEarlier(timer->AwakenTime(), awakenTime))
+ if (timer && timer->AwakenTime() < awakenTime)
{
awakenTime = timer->AwakenTime();
}
- const Clock::MonotonicMilliseconds sleepTime = (awakenTime > currentTime) ? (awakenTime - currentTime) : 0;
- Clock::MillisecondsToTimeval(sleepTime, mNextTimeout);
+ const Clock::Timestamp sleepTime = (awakenTime > currentTime) ? (awakenTime - currentTime) : Clock::Zero;
+ Clock::ToTimeval(sleepTime, mNextTimeout);
mMaxFd = -1;
FD_ZERO(&mSelected.mReadSet);
@@ -387,7 +387,7 @@
// Obtain the list of currently expired timers. Any new timers added by timer callback are NOT handled on this pass,
// since that could result in infinite handling of new timers blocking any other progress.
- Timer::List expiredTimers(mTimerList.ExtractEarlier(1 + SystemClock().GetMonotonicMilliseconds()));
+ Timer::List expiredTimers(mTimerList.ExtractEarlier(Clock::Timeout(1) + SystemClock().GetMonotonicTimestamp()));
Timer * timer = nullptr;
while ((timer = expiredTimers.PopEarliest()) != nullptr)
{
diff --git a/src/system/SystemLayerImplSelect.h b/src/system/SystemLayerImplSelect.h
index e8b035f..d079d8c 100644
--- a/src/system/SystemLayerImplSelect.h
+++ b/src/system/SystemLayerImplSelect.h
@@ -46,7 +46,7 @@
CHIP_ERROR Init() override;
CHIP_ERROR Shutdown() override;
bool IsInitialized() const override { return mLayerState.IsInitialized(); }
- CHIP_ERROR StartTimer(uint32_t delayMilliseconds, TimerCompleteCallback onComplete, void * appState) override;
+ CHIP_ERROR StartTimer(Clock::Timeout delay, TimerCompleteCallback onComplete, void * appState) override;
void CancelTimer(TimerCompleteCallback onComplete, void * appState) override;
CHIP_ERROR ScheduleWork(TimerCompleteCallback onComplete, void * appState) override;
diff --git a/src/system/SystemTimer.cpp b/src/system/SystemTimer.cpp
index d776a8b..97caaf3 100644
--- a/src/system/SystemTimer.cpp
+++ b/src/system/SystemTimer.cpp
@@ -76,7 +76,7 @@
ObjectPool<Timer, CHIP_SYSTEM_CONFIG_NUM_TIMERS> Timer::sPool;
-Timer * Timer::New(System::Layer & systemLayer, uint32_t delayMilliseconds, TimerCompleteCallback onComplete, void * appState)
+Timer * Timer::New(System::Layer & systemLayer, System::Clock::Timeout delay, TimerCompleteCallback onComplete, void * appState)
{
Timer * timer = Timer::sPool.TryCreate();
if (timer == nullptr)
@@ -87,7 +87,7 @@
{
timer->AppState = appState;
timer->mSystemLayer = &systemLayer;
- timer->mAwakenTime = Clock::AddOffset(SystemClock().GetMonotonicMilliseconds(), delayMilliseconds);
+ timer->mAwakenTime = SystemClock().GetMonotonicTimestamp() + delay;
if (!__sync_bool_compare_and_swap(&timer->mOnComplete, nullptr, onComplete))
{
chipDie();
@@ -136,7 +136,7 @@
Timer * Timer::List::Add(Timer * add)
{
VerifyOrDie(add != mHead);
- if (mHead == NULL || Clock::IsEarlier(add->mAwakenTime, mHead->mAwakenTime))
+ if (mHead == NULL || (add->mAwakenTime < mHead->mAwakenTime))
{
add->mNextTimer = mHead;
mHead = add;
@@ -147,7 +147,7 @@
while (lTimer->mNextTimer)
{
VerifyOrDie(lTimer->mNextTimer != add);
- if (Clock::IsEarlier(add->mAwakenTime, lTimer->mNextTimer->mAwakenTime))
+ if (add->mAwakenTime < lTimer->mNextTimer->mAwakenTime)
{
// found the insert location.
break;
@@ -223,9 +223,9 @@
return earliest;
}
-Timer * Timer::List::PopIfEarlier(Clock::MonotonicMilliseconds t)
+Timer * Timer::List::PopIfEarlier(Clock::Timestamp t)
{
- if ((mHead == nullptr) || !Clock::IsEarlier(mHead->mAwakenTime, t))
+ if ((mHead == nullptr) || !(mHead->mAwakenTime < t))
{
return nullptr;
}
@@ -235,15 +235,15 @@
return earliest;
}
-Timer * Timer::List::ExtractEarlier(Clock::MonotonicMilliseconds t)
+Timer * Timer::List::ExtractEarlier(Clock::Timestamp t)
{
- if ((mHead == nullptr) || !Clock::IsEarlier(mHead->mAwakenTime, t))
+ if ((mHead == nullptr) || !(mHead->mAwakenTime < t))
{
return nullptr;
}
Timer * begin = mHead;
Timer * end = mHead;
- while ((end->mNextTimer != nullptr) && Clock::IsEarlier(end->mNextTimer->mAwakenTime, t))
+ while ((end->mNextTimer != nullptr) && (end->mNextTimer->mAwakenTime < t))
{
end = end->mNextTimer;
}
diff --git a/src/system/SystemTimer.h b/src/system/SystemTimer.h
index 6427c8d..2534d4f 100644
--- a/src/system/SystemTimer.h
+++ b/src/system/SystemTimer.h
@@ -106,14 +106,14 @@
*
* @return The earliest timer expiring before @a t, or nullptr if there is no such timer.
*/
- Timer * PopIfEarlier(Clock::MonotonicMilliseconds t);
+ Timer * PopIfEarlier(Clock::Timestamp t);
/**
* Remove and return all timers that expire before the given time @a t.
*
* @return An ordered linked list (by `mNextTimer`) of all timers that expire before @a t, or nullptr if there are none.
*/
- Timer * ExtractEarlier(Clock::MonotonicMilliseconds t);
+ Timer * ExtractEarlier(Clock::Timestamp t);
/**
* Get the earliest timer in the list.
@@ -160,12 +160,12 @@
std::lock_guard<Mutex> lock(mMutex);
return List::PopEarliest();
}
- Timer * PopIfEarlier(Clock::MonotonicMilliseconds t)
+ Timer * PopIfEarlier(Clock::Timestamp t)
{
std::lock_guard<Mutex> lock(mMutex);
return List::PopIfEarlier(t);
}
- Timer * ExtractEarlier(Clock::MonotonicMilliseconds t)
+ Timer * ExtractEarlier(Clock::Timestamp t)
{
std::lock_guard<Mutex> lock(mMutex);
return List::ExtractEarlier(t);
@@ -187,12 +187,13 @@
/**
* Obtain a new timer from the system object pool.
*/
- static Timer * New(System::Layer & systemLayer, uint32_t delayMilliseconds, TimerCompleteCallback onComplete, void * appState);
+ static Timer * New(System::Layer & systemLayer, System::Clock::Timeout delay, TimerCompleteCallback onComplete,
+ void * appState);
/**
* Return the expiration time.
*/
- Clock::MonotonicMilliseconds AwakenTime() const { return mAwakenTime; }
+ Clock::Timestamp AwakenTime() const { return mAwakenTime; }
/**
* Fire the timer.
@@ -224,7 +225,7 @@
static ObjectPool<Timer, CHIP_SYSTEM_CONFIG_NUM_TIMERS> sPool;
TimerCompleteCallback mOnComplete;
- Clock::MonotonicMilliseconds mAwakenTime;
+ Clock::Timestamp mAwakenTime;
Timer * mNextTimer;
Layer * mSystemLayer;
diff --git a/src/system/tests/TestSystemTimer.cpp b/src/system/tests/TestSystemTimer.cpp
index a156dfc..4d0c1af 100644
--- a/src/system/tests/TestSystemTimer.cpp
+++ b/src/system/tests/TestSystemTimer.cpp
@@ -122,8 +122,8 @@
static void CheckOverflow(nlTestSuite * inSuite, void * aContext)
{
- uint32_t timeout_overflow_0ms = 652835029;
- uint32_t timeout_10ms = 10;
+ chip::System::Clock::Milliseconds32 timeout_overflow_0ms{ 652835029 };
+ chip::System::Clock::Milliseconds32 timeout_10ms{ 10 };
TestContext & lContext = *static_cast<TestContext *>(aContext);
Layer & lSys = *lContext.mLayer;
@@ -154,7 +154,7 @@
return;
}
- aLayer->StartTimer(0, HandleGreedyTimer, aState);
+ aLayer->StartTimer(chip::System::Clock::Zero, HandleGreedyTimer, aState);
sNumTimersHandled++;
}
@@ -163,7 +163,7 @@
TestContext & lContext = *static_cast<TestContext *>(aContext);
Layer & lSys = *lContext.mLayer;
- lSys.StartTimer(0, HandleGreedyTimer, aContext);
+ lSys.StartTimer(chip::System::Clock::Zero, HandleGreedyTimer, aContext);
ServiceEvents(lSys);
}
diff --git a/src/transport/SessionManager.cpp b/src/transport/SessionManager.cpp
index 7dc32a4..6bf6d5d 100644
--- a/src/transport/SessionManager.cpp
+++ b/src/transport/SessionManager.cpp
@@ -306,8 +306,8 @@
void SessionManager::ScheduleExpiryTimer()
{
- CHIP_ERROR err =
- mSystemLayer->StartTimer(CHIP_PEER_CONNECTION_TIMEOUT_CHECK_FREQUENCY_MS, SessionManager::ExpiryTimerCallback, this);
+ CHIP_ERROR err = mSystemLayer->StartTimer(System::Clock::Milliseconds32(CHIP_PEER_CONNECTION_TIMEOUT_CHECK_FREQUENCY_MS),
+ SessionManager::ExpiryTimerCallback, this);
VerifyOrDie(err == CHIP_NO_ERROR);
}