Skip to content

Commit

Permalink
timers: Replace DEBUGASSERT with the error code
Browse files Browse the repository at this point in the history
fix the issue report here:
https://lists.apache.org/thread/sys37yf63rq501fd1v8y3zyh6vk10v1d

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
  • Loading branch information
xiaoxiang781216 committed Jun 11, 2024
1 parent c8699d4 commit 9ac1147
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 14 deletions.
40 changes: 32 additions & 8 deletions include/nuttx/timers/oneshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ int oneshot_max_delay(FAR struct oneshot_lowerhalf_s *lower,
clock_t tick;
int ret;

DEBUGASSERT(lower->ops->tick_max_delay);
if (lower->ops->tick_max_delay == NULL)
{
return -ENOSYS;
}

ret = lower->ops->tick_max_delay(lower, &tick);
timespec_from_tick(ts, tick);
Expand All @@ -280,7 +283,10 @@ int oneshot_start(FAR struct oneshot_lowerhalf_s *lower,
{
clock_t tick;

DEBUGASSERT(lower->ops->tick_start);
if (lower->ops->tick_start == NULL)
{
return -ENOSYS;
}

tick = timespec_to_tick(ts);
return lower->ops->tick_start(lower, callback, arg, tick);
Expand All @@ -293,7 +299,10 @@ int oneshot_cancel(FAR struct oneshot_lowerhalf_s *lower,
clock_t tick;
int ret;

DEBUGASSERT(lower->ops->tick_cancel);
if (lower->ops->tick_cancel == NULL)
{
return -ENOSYS;
}

ret = lower->ops->tick_cancel(lower, &tick);
timespec_from_tick(ts, tick);
Expand All @@ -308,7 +317,10 @@ int oneshot_current(FAR struct oneshot_lowerhalf_s *lower,
clock_t tick;
int ret;

DEBUGASSERT(lower->ops->tick_current);
if (lower->ops->tick_current == NULL)
{
return -ENOSYS;
}

ret = lower->ops->tick_current(lower, &tick);
timespec_from_tick(ts, tick);
Expand All @@ -323,7 +335,10 @@ int oneshot_tick_max_delay(FAR struct oneshot_lowerhalf_s *lower,
struct timespec ts;
int ret;

DEBUGASSERT(lower->ops->max_delay);
if (lower->ops->max_delay == NULL)
{
return -ENOSYS;
}

ret = lower->ops->max_delay(lower, &ts);
*ticks = timespec_to_tick(&ts);
Expand All @@ -337,7 +352,10 @@ int oneshot_tick_start(FAR struct oneshot_lowerhalf_s *lower,
{
struct timespec ts;

DEBUGASSERT(lower->ops->start);
if (lower->ops->start == NULL)
{
return -ENOSYS;
}

timespec_from_tick(&ts, ticks);
return lower->ops->start(lower, callback, arg, &ts);
Expand All @@ -350,7 +368,10 @@ int oneshot_tick_cancel(FAR struct oneshot_lowerhalf_s *lower,
struct timespec ts;
int ret;

DEBUGASSERT(lower->ops->cancel);
if (lower->ops->cancel == NULL)
{
return -ENOSYS;
}

ret = lower->ops->cancel(lower, &ts);
*ticks = timespec_to_tick(&ts);
Expand All @@ -365,7 +386,10 @@ int oneshot_tick_current(FAR struct oneshot_lowerhalf_s *lower,
struct timespec ts;
int ret;

DEBUGASSERT(lower->ops->current);
if (lower->ops->current == NULL)
{
return -ENOSYS;
}

ret = lower->ops->current(lower, &ts);
*ticks = timespec_to_tick(&ts);
Expand Down
32 changes: 26 additions & 6 deletions include/nuttx/timers/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ int timer_getstatus(FAR struct timer_lowerhalf_s *lower,
{
int ret;

DEBUGASSERT(lower->ops->tick_getstatus);
if (lower->ops->tick_getstatus == NULL)
{
return -ENOSYS;
}

ret = lower->ops->tick_getstatus(lower, status);
if (ret >= 0)
Expand All @@ -269,7 +272,11 @@ static inline
int timer_settimeout(FAR struct timer_lowerhalf_s *lower,
uint32_t timeout)
{
DEBUGASSERT(lower->ops->tick_setttimeout);
if (lower->ops->tick_setttimeout == NULL)
{
return -ENOSYS;
}

return lower->ops->tick_setttimeout(lower, USEC2TICK(timeout));
}

Expand All @@ -279,7 +286,10 @@ int timer_maxtimeout(FAR struct timer_lowerhalf_s *lower,
{
int ret;

DEBUGASSERT(lower->ops->tick_maxtimeout);
if (lower->ops->tick_maxtimeout == NULL)
{
return -ENOSYS;
}

ret = lower->ops->tick_maxtimeout(lower, maxtimeout);
if (ret >= 0)
Expand All @@ -296,7 +306,10 @@ int timer_tick_getstatus(FAR struct timer_lowerhalf_s *lower,
{
int ret;

DEBUGASSERT(lower->ops->getstatus);
if (lower->ops->getstatus == NULL)
{
return -ENOSYS;
}

ret = lower->ops->getstatus(lower, status);
if (ret >= 0)
Expand All @@ -312,7 +325,11 @@ static inline
int timer_tick_settimeout(FAR struct timer_lowerhalf_s *lower,
uint32_t timeout)
{
DEBUGASSERT(lower->ops->settimeout);
if (lower->ops->settimeout == NULL)
{
return -ENOSYS;
}

return lower->ops->settimeout(lower, TICK2USEC(timeout));
}

Expand All @@ -322,7 +339,10 @@ int timer_tick_maxtimeout(FAR struct timer_lowerhalf_s *lower,
{
int ret;

DEBUGASSERT(lower->ops->maxtimeout);
if (lower->ops->maxtimeout == NULL)
{
return -ENOSYS;
}

ret = lower->ops->maxtimeout(lower, maxtimeout);
if (ret >= 0)
Expand Down

0 comments on commit 9ac1147

Please sign in to comment.