Skip to content

Commit

Permalink
Fixed osal_timer_diff bug (OpenEtherCATsociety#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
zchen24 authored and nakarlsson committed May 25, 2017
1 parent fb975cb commit e78bb66
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
12 changes: 7 additions & 5 deletions osal/linux/osal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
14 changes: 8 additions & 6 deletions osal/vxworks/osal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions osal/win32/osal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit e78bb66

Please sign in to comment.