Make compare_timespec public so timer driver could reuse it
This commit is contained in:
parent
db4e2dbb6e
commit
20a9a62fdf
@ -84,19 +84,6 @@ static inline void timespec_from_usec(FAR struct timespec *ts,
|
||||
ts->tv_nsec = microseconds * NSEC_PER_USEC;
|
||||
}
|
||||
|
||||
static inline int timespec_compare(FAR const struct timespec *ts1,
|
||||
FAR const struct timespec *ts2)
|
||||
{
|
||||
if (ts1->tv_sec != ts2->tv_sec)
|
||||
{
|
||||
return ts1->tv_sec - ts2->tv_sec;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ts1->tv_nsec - ts2->tv_nsec;
|
||||
}
|
||||
}
|
||||
|
||||
static void udelay_accurate(useconds_t microseconds)
|
||||
{
|
||||
struct timespec now;
|
||||
@ -107,7 +94,7 @@ static void udelay_accurate(useconds_t microseconds)
|
||||
timespec_from_usec(&delta, microseconds);
|
||||
clock_timespec_add(&now, &delta, &end);
|
||||
|
||||
while (timespec_compare(&now, &end) < 0)
|
||||
while (clock_timespec_compare(&now, &end) < 0)
|
||||
{
|
||||
ONESHOT_CURRENT(g_oneshot_lower, &now);
|
||||
}
|
||||
|
@ -270,6 +270,19 @@ EXTERN volatile clock_t g_system_timer;
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: clock_timespec_compare
|
||||
*
|
||||
* Description:
|
||||
* Return < 0 if time ts1 is before time ts2
|
||||
* Return > 0 if time ts2 is before time ts1
|
||||
* Return 0 if time ts1 is the same as time ts2
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int clock_timespec_compare(FAR const struct timespec *ts1,
|
||||
FAR const struct timespec *ts2);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: clock_timespec_add
|
||||
*
|
||||
|
@ -45,11 +45,11 @@
|
||||
#include "clock/clock.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: compare_timespec
|
||||
* Name: clock_timespec_compare
|
||||
*
|
||||
* Description:
|
||||
* Return < 0 if time a is before time b
|
||||
@ -58,8 +58,8 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static long compare_timespec(FAR const struct timespec *a,
|
||||
FAR const struct timespec *b)
|
||||
int clock_timespec_compare(FAR const struct timespec *a,
|
||||
FAR const struct timespec *b)
|
||||
{
|
||||
if (a->tv_sec < b->tv_sec)
|
||||
{
|
||||
@ -71,13 +71,9 @@ static long compare_timespec(FAR const struct timespec *a,
|
||||
return 1;
|
||||
}
|
||||
|
||||
return (long)a->tv_nsec - (long)b->tv_nsec;
|
||||
return a->tv_nsec - b->tv_nsec;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: clock_abstime2ticks
|
||||
*
|
||||
@ -115,7 +111,7 @@ int clock_abstime2ticks(clockid_t clockid, FAR const struct timespec *abstime,
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (compare_timespec(abstime, &currtime) < 0)
|
||||
if (clock_timespec_compare(abstime, &currtime) < 0)
|
||||
{
|
||||
/* Every caller of clock_abstime2ticks check 'ticks < 0' to see if
|
||||
* absolute time is in the past. So lets just return negative tick
|
||||
|
Loading…
Reference in New Issue
Block a user