sched: return 0 from clock_systime_ticks if failed

Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
This commit is contained in:
Xu Xingliang 2023-09-15 16:12:39 +08:00 committed by Xiang Xiao
parent 415fe60695
commit 3cd5e20f74
2 changed files with 28 additions and 11 deletions

View File

@ -1655,7 +1655,7 @@ void up_timer_initialize(void);
* set a time in the future and get an event when that alarm goes off. * set a time in the future and get an event when that alarm goes off.
* *
* int up_alarm_cancel(void): Cancel the alarm. * int up_alarm_cancel(void): Cancel the alarm.
* int up_alarm_start(FAR const struct timespec *ts): Enable (or re-anable * int up_alarm_start(FAR const struct timespec *ts): Enable (or re-enable
* the alarm. * the alarm.
* #else * #else
* int up_timer_cancel(void): Cancels the interval timer. * int up_timer_cancel(void): Cancels the interval timer.

View File

@ -84,8 +84,8 @@ clock_t clock_systime_ticks(void)
/* Get the time from the platform specific hardware */ /* Get the time from the platform specific hardware */
clock_systime_timespec(&ts); if (clock_systime_timespec(&ts) == OK)
{
/* Convert to a 64-bit value in microseconds, /* Convert to a 64-bit value in microseconds,
* then in clock tick units. * then in clock tick units.
*/ */
@ -93,6 +93,11 @@ clock_t clock_systime_ticks(void)
return timespec_to_tick(&ts); return timespec_to_tick(&ts);
} }
else else
{
return 0;
}
}
else
#endif #endif
{ {
/* In tickless mode, all timing is controlled by platform-specific /* In tickless mode, all timing is controlled by platform-specific
@ -101,12 +106,24 @@ clock_t clock_systime_ticks(void)
#if defined(CONFIG_SCHED_TICKLESS_TICK_ARGUMENT) #if defined(CONFIG_SCHED_TICKLESS_TICK_ARGUMENT)
clock_t ticks; clock_t ticks;
up_timer_gettick(&ticks); if (up_timer_gettick(&ticks) == OK)
{
return ticks; return ticks;
}
else
{
return 0;
}
#elif defined(CONFIG_SCHED_TICKLESS) #elif defined(CONFIG_SCHED_TICKLESS)
struct timespec ts; struct timespec ts;
up_timer_gettime(&ts); if (up_timer_gettime(&ts) == OK)
{
return timespec_to_tick(&ts); return timespec_to_tick(&ts);
}
else
{
return 0;
}
#elif defined(CONFIG_SYSTEM_TIME64) #elif defined(CONFIG_SYSTEM_TIME64)
clock_t sample; clock_t sample;