From 463d52dc936167440f61d83adab680135f25b655 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Tue, 11 Jun 2024 20:18:46 +0800 Subject: [PATCH] timers: Replace DEBUGASSERT with the error code fix the issue report here: https://lists.apache.org/thread/sys37yf63rq501fd1v8y3zyh6vk10v1d Signed-off-by: Xiang Xiao --- include/nuttx/timers/oneshot.h | 40 +++++++++++++++++++++++++++------- include/nuttx/timers/timer.h | 32 ++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/include/nuttx/timers/oneshot.h b/include/nuttx/timers/oneshot.h index 6c486ca1cf21d..220fd550230ce 100644 --- a/include/nuttx/timers/oneshot.h +++ b/include/nuttx/timers/oneshot.h @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/include/nuttx/timers/timer.h b/include/nuttx/timers/timer.h index 28ea9e9d0fa83..afa43fc9774ab 100644 --- a/include/nuttx/timers/timer.h +++ b/include/nuttx/timers/timer.h @@ -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) @@ -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)); } @@ -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) @@ -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) @@ -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)); } @@ -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)