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 6f49637 commit 4d26e22
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 17 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 -ENOSUPP;
}

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 -ENOSUPP;
}

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 -ENOSUPP;
}

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 -ENOSUPP;
}

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 -ENOSUPP;
}

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 -ENOSUPP;
}

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 -ENOSUPP;
}

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 -ENOSUPP;
}

ret = lower->ops->current(lower, &ts);
*ticks = timespec_to_tick(&ts);
Expand Down
38 changes: 29 additions & 9 deletions include/nuttx/timers/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@
/* Method access helper macros **********************************************/

#define TIMER_START(l) \
((l)->ops->start ? (l)->ops->start(l) : -ENOSYS)
((l)->ops->start ? (l)->ops->start(l) : -ENOSUPP)

#define TIMER_STOP(l) \
((l)->ops->stop ? (l)->ops->stop(l) : -ENOSYS)
((l)->ops->stop ? (l)->ops->stop(l) : -ENOSUPP)

#define TIMER_GETSTATUS(l,s) \
((l)->ops->getstatus ? (l)->ops->getstatus(l,s) : timer_getstatus(l,s))
Expand Down 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 -ENOSUPP;
}

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 -ENOSUPP;
}

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 -ENOSUPP;
}

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 -ENOSUPP;
}

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 -ENOSUPP;
}

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 -ENOSUPP;
}

ret = lower->ops->maxtimeout(lower, maxtimeout);
if (ret >= 0)
Expand Down Expand Up @@ -405,7 +425,7 @@ void timer_unregister(FAR void *handle);
* arg - Argument provided when the callback is called.
*
* Returned Value:
* Zero (OK), if the callback was successfully set, or -ENOSYS if the lower
* Zero (OK), if the callback was successfully set, or -ENOSUPP if the lower
* half driver does not support the operation.
*
****************************************************************************/
Expand Down

0 comments on commit 4d26e22

Please sign in to comment.