Fixed osal_timer_diff bug (#106)

This commit is contained in:
Zihan Chen 2017-05-25 04:09:10 -04:00 committed by nakarlsson
parent fb975cbc70
commit e78bb66327
3 changed files with 22 additions and 16 deletions

View File

@ -49,11 +49,13 @@ ec_timet osal_current_time(void)
void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff)
{
diff->sec = end->sec - start->sec;
diff->usec = end->usec - start->usec;
if (diff->usec < 0) {
--diff->sec;
diff->usec += 1000000;
if (end->usec < start->usec) {
diff->sec = end->sec - start->sec - 1;
diff->usec = end->usec + 1000000 - start->usec;
}
else {
diff->sec = end->sec - start->sec;
diff->usec = end->usec - start->usec;
}
}

View File

@ -92,12 +92,14 @@ ec_timet osal_current_time(void)
void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff)
{
diff->sec = end->sec - start->sec;
diff->usec = end->usec - start->usec;
if (diff->usec < 0) {
--diff->sec;
diff->usec += 1000000;
}
if (end->usec < start->usec) {
diff->sec = end->sec - start->sec - 1;
diff->usec = end->usec + 1000000 - start->usec;
}
else {
diff->sec = end->sec - start->sec;
diff->usec = end->usec - start->usec;
}
}
void osal_timer_start(osal_timert * self, uint32 timeout_usec)

View File

@ -42,11 +42,13 @@ ec_timet osal_current_time (void)
void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff)
{
diff->sec = end->sec - start->sec;
diff->usec = end->usec - start->usec;
if (diff->usec < 0) {
--diff->sec;
diff->usec += 1000000;
if (end->usec < start->usec) {
diff->sec = end->sec - start->sec - 1;
diff->usec = end->usec + 1000000 - start->usec;
}
else {
diff->sec = end->sec - start->sec;
diff->usec = end->usec - start->usec;
}
}