[timer] multiple microseconds timer support (#1962)

* [timer] multiple microseconds timer support

* Remove TimerSchedulerLocator, Timer inherit from Ip6Locator instead to get TimerScheduler.

* Add separate UsecTimer and UsecTimerScheduler for multiple microseconds timer support.

* [timer] refine Timer names

* Rename alarm header files to alarm-milli.h and alarm-micro.h

* Rename alarm APIs to start with otPlatAlarmMilli and otPlatAlarmMicro

* Rename Timer classes to TimerMilli/TimerMilliScheduler and TimerMicro/TimerMicroScheduler

* [Timer] Refactor Timer code structure

* Create TimerBase and TimerSchedulerBase class for common functions;

* Use TimerMilli/TimerMicro and TimerMilliScheduler/TimerMicroScheduler for different functions;

* Define AlarmApi, so then TimerMilliScheduler/TimerMicroScheduler could use different AlarmApi.
This commit is contained in:
Shu Chen
2017-07-10 16:01:27 -07:00
committed by Jonathan Hui
parent 529c291f7a
commit 129c419107
104 changed files with 775 additions and 614 deletions
+23 -23
View File
@@ -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);