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
when driver no support for ops, should not panic, prefer errno.
  • Loading branch information
xiaoxiang781216 committed Jan 15, 2025
1 parent 32406c7 commit 768a127
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 18 deletions.
40 changes: 32 additions & 8 deletions include/nuttx/timers/oneshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,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 -ENOTSUP;
}

ret = lower->ops->tick_max_delay(lower, &tick);
clock_ticks2time(ts, tick);
Expand All @@ -283,7 +286,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 -ENOTSUP;
}

tick = clock_time2ticks(ts);
return lower->ops->tick_start(lower, callback, arg, tick);
Expand All @@ -296,7 +302,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 -ENOTSUP;
}

ret = lower->ops->tick_cancel(lower, &tick);
clock_ticks2time(ts, tick);
Expand All @@ -311,7 +320,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 -ENOTSUP;
}

ret = lower->ops->tick_current(lower, &tick);
clock_ticks2time(ts, tick);
Expand All @@ -326,7 +338,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 -ENOTSUP;
}

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

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

clock_ticks2time(&ts, ticks);
return lower->ops->start(lower, callback, arg, &ts);
Expand All @@ -353,7 +371,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 -ENOTSUP;
}

ret = lower->ops->cancel(lower, &ts);
*ticks = clock_time2ticks(&ts);
Expand All @@ -368,7 +389,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 -ENOTSUP;
}

ret = lower->ops->current(lower, &ts);
*ticks = clock_time2ticks(&ts);
Expand Down
41 changes: 31 additions & 10 deletions include/nuttx/timers/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <nuttx/compiler.h>
#include <nuttx/irq.h>
#include <nuttx/fs/ioctl.h>
#include <errno.h>
#include <signal.h>
#include <stdbool.h>
#include <sys/types.h>
Expand Down Expand Up @@ -95,10 +96,10 @@
/* Method access helper macros **********************************************/

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

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

#define TIMER_GETSTATUS(l,s) \
((l)->ops->getstatus ? (l)->ops->getstatus(l,s) : timer_getstatus(l,s))
Expand Down Expand Up @@ -256,7 +257,10 @@ int timer_getstatus(FAR struct timer_lowerhalf_s *lower,
{
int ret;

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

ret = lower->ops->tick_getstatus(lower, status);
if (ret >= 0)
Expand All @@ -272,7 +276,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 -ENOTSUP;
}

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

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

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

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

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

ret = lower->ops->getstatus(lower, status);
if (ret >= 0)
Expand All @@ -315,7 +329,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 -ENOTSUP;
}

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

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

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

ret = lower->ops->maxtimeout(lower, maxtimeout);
if (ret >= 0)
Expand Down Expand Up @@ -408,8 +429,8 @@ 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
* half driver does not support the operation.
* Zero (OK), if the callback was successfully set, or -ENOTSUP if the
* lower half driver does not support the operation.
*
****************************************************************************/

Expand Down

0 comments on commit 768a127

Please sign in to comment.