Skip to content

Commit 27ebb2c

Browse files
committed
Fix #1503, Update timer interval comparison
1 parent b6dca11 commit 27ebb2c

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/unit-tests/ostimer-test/ut_ostimer_test.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ char g_longTimerName[UT_OS_NAME_BUFF_SIZE];
4949

5050
uint32 g_cbLoopCntMax = 5;
5151
uint32 g_toleranceVal = 0;
52+
uint32 g_intervalTime = 0;
5253
uint32 g_timerFirst = 0;
5354
int32 g_status = 0;
5455
osal_id_t g_timerId;
@@ -74,37 +75,35 @@ void UT_os_timercallback(osal_id_t timerId)
7475
{
7576
int deltaTime = 0;
7677
static int32 loopCnt = 0, res = 0;
77-
static uint32 prevIntervalTime = 0;
7878
static uint32 currIntervalTime = 0;
7979
static OS_time_t currTime = {0}, endTime = {0};
8080

8181
if (OS_ObjectIdEqual(timerId, g_timerId))
8282
{
83+
84+
OS_GetLocalTime(&endTime);
85+
8386
if (g_timerFirst)
8487
{
8588
g_timerFirst = 0;
8689
g_status = 0;
87-
prevIntervalTime = 0;
8890
res = 0;
8991
loopCnt = 0;
90-
OS_GetLocalTime(&currTime);
92+
currTime = endTime;
9193
}
9294

93-
OS_GetLocalTime(&endTime);
94-
9595
currIntervalTime = OS_TimeGetTotalMicroseconds(OS_TimeSubtract(endTime, currTime));
9696

97-
if (currIntervalTime >= prevIntervalTime)
98-
deltaTime = currIntervalTime - prevIntervalTime;
97+
if (currIntervalTime >= g_intervalTime)
98+
deltaTime = currIntervalTime - g_intervalTime;
9999
else
100-
deltaTime = prevIntervalTime - currIntervalTime;
100+
deltaTime = g_intervalTime - currIntervalTime;
101101

102102
if ((deltaTime > g_toleranceVal) && (loopCnt > 1))
103103
res = -1;
104104

105105
loopCnt++;
106106
currTime = endTime;
107-
prevIntervalTime = currIntervalTime;
108107

109108
if (loopCnt == g_cbLoopCntMax)
110109
{

src/unit-tests/ostimer-test/ut_ostimer_test.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ extern char g_longTimerName[UT_OS_NAME_BUFF_SIZE];
5151

5252
extern uint32 g_cbLoopCntMax;
5353
extern uint32 g_toleranceVal;
54+
extern uint32 g_intervalTime;
5455
extern uint32 g_timerFirst;
5556
extern int32 g_status;
5657
extern osal_id_t g_timerId;

src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ void UT_os_timerdelete_test()
401401
**--------------------------------------------------------------------------------*/
402402
void UT_os_timerset_test()
403403
{
404-
uint32 startTime = 0, intervalTime = 0;
404+
uint32 startTime = 0;
405405

406406
/*-----------------------------------------------------*/
407407
/* #1 Invalid-id-arg */
@@ -424,18 +424,18 @@ void UT_os_timerset_test()
424424
g_timerFirst = 1;
425425
g_cbLoopCntMax = 10;
426426
startTime = 1000;
427-
intervalTime = 5;
427+
g_intervalTime = 5;
428428
g_toleranceVal = 0;
429429

430430
UtPrintf("\nOS_TimerSet() - #3 Interval-too-short (clk_accuracy=%d)\n", (int)g_clkAccuracy);
431-
if (UT_NOMINAL(OS_TimerSet(g_timerIds[3], startTime, intervalTime)))
431+
if (UT_NOMINAL(OS_TimerSet(g_timerIds[3], startTime, g_intervalTime)))
432432
{
433433
while (g_status == 0)
434434
{
435435
OS_TaskDelay(1);
436436
}
437437

438-
UtAssert_True(g_status < 0, "4# Nominal - callback status %d", (int)g_status);
438+
UtAssert_True(g_status < 0, "#3 Interval-too-short - callback status %d", (int)g_status);
439439
}
440440

441441
/* Reset test environment */
@@ -452,11 +452,11 @@ void UT_os_timerset_test()
452452
g_timerFirst = 1;
453453
g_cbLoopCntMax = 10;
454454
startTime = 1000;
455-
intervalTime = 500000;
456-
g_toleranceVal = intervalTime / 20; /* 5% */
455+
g_intervalTime = 500000;
456+
g_toleranceVal = g_intervalTime / 20; /* 5% */
457457

458458
UtPrintf("\nOS_TimerSet() - #4 Nominal condition (clk_accuracy=%d)\n", (int)g_clkAccuracy);
459-
if (UT_NOMINAL(OS_TimerSet(g_timerIds[4], startTime, intervalTime)))
459+
if (UT_NOMINAL(OS_TimerSet(g_timerIds[4], startTime, g_intervalTime)))
460460
{
461461
while (g_status == 0)
462462
{

0 commit comments

Comments
 (0)