From a2923d12a78c1bdb6101a3440682769449a691d8 Mon Sep 17 00:00:00 2001 From: ouyangxiangzhen Date: Fri, 29 Aug 2025 21:24:42 +0800 Subject: [PATCH 1/6] arch/arm64: revert oneshot drivers to timespec API. This commit reverted oneshot drivers to timespec API. Signed-off-by: ouyangxiangzhen --- arch/arm64/src/common/arm64_arch_timer.c | 131 ++++++----------------- 1 file changed, 34 insertions(+), 97 deletions(-) diff --git a/arch/arm64/src/common/arm64_arch_timer.c b/arch/arm64/src/common/arm64_arch_timer.c index 3aac9b1615ff1..b487221e20550 100644 --- a/arch/arm64/src/common/arm64_arch_timer.c +++ b/arch/arm64/src/common/arm64_arch_timer.c @@ -89,38 +89,14 @@ static inline void arm64_arch_timer_set_compare(uint64_t value) static inline void arm64_arch_timer_enable(bool enable) { - uint64_t value; - - value = read_sysreg(cntv_ctl_el0); - - if (enable) - { - value |= CNTV_CTL_ENABLE_BIT; - } - else - { - value &= ~CNTV_CTL_ENABLE_BIT; - } - - write_sysreg(value, cntv_ctl_el0); + modify_sysreg(enable ? CNTV_CTL_ENABLE_BIT : 0u, + CNTV_CTL_ENABLE_BIT, cntv_ctl_el0); } static inline void arm64_arch_timer_set_irq_mask(bool mask) { - uint64_t value; - - value = read_sysreg(cntv_ctl_el0); - - if (mask) - { - value |= CNTV_CTL_IMASK_BIT; - } - else - { - value &= ~CNTV_CTL_IMASK_BIT; - } - - write_sysreg(value, cntv_ctl_el0); + modify_sysreg(mask ? CNTV_CTL_IMASK_BIT : 0u, + CNTV_CTL_IMASK_BIT, cntv_ctl_el0); } static inline uint64_t arm64_arch_timer_count(void) @@ -133,45 +109,6 @@ static inline uint64_t arm64_arch_timer_get_cntfrq(void) return read_sysreg(cntfrq_el0); } -static inline uint64_t arm64_arch_cnt2tick(uint64_t count, uint64_t freq) -{ - uint64_t sec; - uint64_t ticks; - - /* In case of count * TICK_PER_SEC overflow. - * We should divide the count into two parts: - * The second part and sub-second part. - */ - - sec = count / freq; - ticks = sec * TICK_PER_SEC; - - /* Here we convert the sub-second part to ticks. */ - - count -= sec * freq; - ticks += count * TICK_PER_SEC / freq; - - return ticks; -} - -static inline uint64_t arm64_arch_tick2cnt(uint64_t ticks, uint64_t freq) -{ - uint64_t count; - uint64_t sec; - - /* First we convert the second part to count. */ - - sec = div_const(ticks, TICK_PER_SEC); - count = sec * freq; - - /* Here we convert the sub-second part to count. */ - - ticks -= sec * TICK_PER_SEC; - count += div_const(ticks * freq, TICK_PER_SEC); - - return count; -} - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -227,12 +164,15 @@ static int arm64_arch_timer_compare_isr(int irq, void *regs, void *arg) * ****************************************************************************/ -static int arm64_tick_max_delay(struct oneshot_lowerhalf_s *lower, - clock_t *ticks) +static int arm64_max_delay(struct oneshot_lowerhalf_s *lower, + struct timespec *ts) { - DEBUGASSERT(ticks != NULL); + uint64_t freq = arm64_arch_timer_get_cntfrq(); - *ticks = (clock_t)UINT32_MAX; + DEBUGASSERT(ts != NULL); + + ts->tv_sec = UINT64_MAX / freq; + ts->tv_nsec = UINT64_MAX % freq * NSEC_PER_SEC / freq; return OK; } @@ -260,13 +200,13 @@ static int arm64_tick_max_delay(struct oneshot_lowerhalf_s *lower, * ****************************************************************************/ -static int arm64_tick_cancel(struct oneshot_lowerhalf_s *lower, - clock_t *ticks) +static int arm64_cancel(struct oneshot_lowerhalf_s *lower, + struct timespec *ts) { struct arm64_oneshot_lowerhalf_s *priv = (struct arm64_oneshot_lowerhalf_s *)lower; - DEBUGASSERT(priv != NULL && ticks != NULL); + DEBUGASSERT(priv != NULL && ts != NULL); /* Disable int */ @@ -296,17 +236,16 @@ static int arm64_tick_cancel(struct oneshot_lowerhalf_s *lower, * ****************************************************************************/ -static int arm64_tick_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, - clock_t ticks) +static int arm64_start(struct oneshot_lowerhalf_s *lower, + oneshot_callback_t callback, void *arg, + const struct timespec *ts) { - uint64_t next_cnt; - uint64_t next_tick; + uint64_t count; struct arm64_oneshot_lowerhalf_s *priv = (struct arm64_oneshot_lowerhalf_s *)lower; uint64_t freq = priv->frequency; - DEBUGASSERT(priv != NULL && callback != NULL); + DEBUGASSERT(priv && callback && ts); /* Save the new handler and its argument */ @@ -315,16 +254,11 @@ static int arm64_tick_start(struct oneshot_lowerhalf_s *lower, priv->running = this_cpu(); - /* Align the timer count to the tick boundary. - * Notice that this is just a work-around. We should pass both - * the current system ticks and the delay ticks as input parameters. - * But we only have the delay tick here due to the oneshot interface. - */ - - next_tick = arm64_arch_cnt2tick(arm64_arch_timer_count(), freq) + ticks; - next_cnt = arm64_arch_tick2cnt(next_tick, freq); + count = arm64_arch_timer_count(); + count += (uint64_t)ts->tv_sec * freq + + (uint64_t)ts->tv_nsec * freq / NSEC_PER_SEC; - arm64_arch_timer_set_compare(next_cnt); + arm64_arch_timer_set_compare(count); arm64_arch_timer_set_irq_mask(false); @@ -345,18 +279,21 @@ static int arm64_tick_start(struct oneshot_lowerhalf_s *lower, * ****************************************************************************/ -static int arm64_tick_current(struct oneshot_lowerhalf_s *lower, - clock_t *ticks) +static int arm64_current(struct oneshot_lowerhalf_s *lower, + struct timespec *ts) { uint64_t count; + uint64_t freq; struct arm64_oneshot_lowerhalf_s *priv = (struct arm64_oneshot_lowerhalf_s *)lower; - DEBUGASSERT(ticks != NULL); + DEBUGASSERT(ts != NULL); + freq = priv->frequency; count = arm64_arch_timer_count(); - *ticks = arm64_arch_cnt2tick(count, priv->frequency); + ts->tv_sec = count / freq; + ts->tv_nsec = (count % freq) * NSEC_PER_SEC / freq; return OK; } @@ -389,10 +326,10 @@ static void arm64_oneshot_initialize_per_cpu(void) static const struct oneshot_operations_s g_oneshot_ops = { - .tick_start = arm64_tick_start, - .tick_current = arm64_tick_current, - .tick_max_delay = arm64_tick_max_delay, - .tick_cancel = arm64_tick_cancel, + .start = arm64_start, + .current = arm64_current, + .max_delay = arm64_max_delay, + .cancel = arm64_cancel, }; /**************************************************************************** From 1de71e31b50f84e8229c21047f154089e303e08b Mon Sep 17 00:00:00 2001 From: ouyangxiangzhen Date: Sat, 30 Aug 2025 10:21:54 +0800 Subject: [PATCH 2/6] arch/arm: revert oneshot drivers to timespec API. This commit reverted oneshot drivers to timespec API. Signed-off-by: ouyangxiangzhen --- arch/arm/src/armv8-r/arm_timer.c | 85 +++++++++++++++++++------------- 1 file changed, 51 insertions(+), 34 deletions(-) diff --git a/arch/arm/src/armv8-r/arm_timer.c b/arch/arm/src/armv8-r/arm_timer.c index 3fa0638596b76..f3119912d752d 100644 --- a/arch/arm/src/armv8-r/arm_timer.c +++ b/arch/arm/src/armv8-r/arm_timer.c @@ -60,7 +60,7 @@ # define GIC_IRQ_PHY_TIMER GIC_IRQ_NONSEC_PHY_TIMER #endif -#define ARM_ARCH_TIMER_IRQ GIC_IRQ_VIRT_TIMER +#define ARM_ARCH_TIMER_IRQ GIC_IRQ_PHY_TIMER #define ARM_ARCH_TIMER_PRIO IRQ_DEFAULT_PRIORITY #define ARM_ARCH_TIMER_FLAGS IRQ_TYPE_LEVEL @@ -81,7 +81,7 @@ struct arm_oneshot_lowerhalf_s /* Private lower half data follows */ void *arg; /* Argument that is passed to the handler */ - uint64_t cycle_per_tick; /* cycle per tick */ + uint32_t frequency; /* Frequency */ oneshot_callback_t callback; /* Internal handler that receives callback */ }; @@ -157,7 +157,7 @@ static int arm_arch_timer_compare_isr(int irq, void *regs, void *arg) } /**************************************************************************** - * Name: arm_tick_max_delay + * Name: arm_max_delay * * Description: * Determine the maximum delay of the one-shot timer (in microseconds) @@ -166,7 +166,7 @@ static int arm_arch_timer_compare_isr(int irq, void *regs, void *arg) * lower An instance of the lower-half oneshot state structure. This * structure must have been previously initialized via a call to * oneshot_initialize(); - * ticks The location in which to return the maximum delay. + * ts The location in which to return the maximum delay. * * Returned Value: * Zero (OK) is returned on success; a negated errno value is returned @@ -174,18 +174,23 @@ static int arm_arch_timer_compare_isr(int irq, void *regs, void *arg) * ****************************************************************************/ -static int arm_tick_max_delay(struct oneshot_lowerhalf_s *lower, - clock_t *ticks) +static int arm_max_delay(struct oneshot_lowerhalf_s *lower, + struct timespec *ts) { - DEBUGASSERT(ticks != NULL); + struct arm_oneshot_lowerhalf_s *priv = + (struct arm_oneshot_lowerhalf_s *)lower; + uint32_t freq = priv->frequency; + + DEBUGASSERT(ts != NULL); - *ticks = (clock_t)UINT64_MAX; + ts->tv_sec = UINT64_MAX / freq; + ts->tv_nsec = UINT64_MAX % freq * NSEC_PER_SEC / freq; return OK; } /**************************************************************************** - * Name: arm_tick_cancel + * Name: arm_cancel * * Description: * Cancel the oneshot timer and return the time remaining on the timer. @@ -197,7 +202,7 @@ static int arm_tick_max_delay(struct oneshot_lowerhalf_s *lower, * lower Caller allocated instance of the oneshot state structure. This * structure must have been previously initialized via a call to * oneshot_initialize(); - * ticks The location in which to return the time remaining on the + * ts The location in which to return the time remaining on the * oneshot timer. * * Returned Value: @@ -207,13 +212,13 @@ static int arm_tick_max_delay(struct oneshot_lowerhalf_s *lower, * ****************************************************************************/ -static int arm_tick_cancel(struct oneshot_lowerhalf_s *lower, - clock_t *ticks) +static int arm_cancel(struct oneshot_lowerhalf_s *lower, + struct timespec *ts) { struct arm_oneshot_lowerhalf_s *priv = (struct arm_oneshot_lowerhalf_s *)lower; - DEBUGASSERT(priv != NULL && ticks != NULL); + DEBUGASSERT(priv != NULL && ts != NULL); /* Disable int */ @@ -223,7 +228,7 @@ static int arm_tick_cancel(struct oneshot_lowerhalf_s *lower, } /**************************************************************************** - * Name: arm_tick_start + * Name: arm_start * * Description: * Start the oneshot timer @@ -234,7 +239,7 @@ static int arm_tick_cancel(struct oneshot_lowerhalf_s *lower, * oneshot_initialize(); * handler The function to call when when the oneshot timer expires. * arg An opaque argument that will accompany the callback. - * ticks Provides the duration of the one shot timer. + * ts Provides the duration of the one shot timer. * * Returned Value: * Zero (OK) is returned on success; a negated errno value is returned @@ -242,14 +247,16 @@ static int arm_tick_cancel(struct oneshot_lowerhalf_s *lower, * ****************************************************************************/ -static int arm_tick_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, - clock_t ticks) +static int arm_start(struct oneshot_lowerhalf_s *lower, + oneshot_callback_t callback, void *arg, + const struct timespec *ts) { + uint64_t count; struct arm_oneshot_lowerhalf_s *priv = (struct arm_oneshot_lowerhalf_s *)lower; + uint64_t freq = priv->frequency; - DEBUGASSERT(priv != NULL && callback != NULL); + DEBUGASSERT(priv && callback && ts); /* Save the new handler and its argument */ @@ -258,8 +265,11 @@ static int arm_tick_start(struct oneshot_lowerhalf_s *lower, /* Set the timeout */ - arm_timer_phy_set_absolute(arm_timer_phy_count() + - priv->cycle_per_tick * ticks); + count = arm_timer_phy_count(); + count += (uint64_t)ts->tv_sec * freq + + (uint64_t)ts->tv_nsec * freq / NSEC_PER_SEC; + + arm_timer_phy_set_absolute(count); /* Try to unmask the timer irq in timer controller * in case of arm_tick_cancel is called. @@ -271,7 +281,7 @@ static int arm_tick_start(struct oneshot_lowerhalf_s *lower, } /**************************************************************************** - * Name: arm_tick_current + * Name: arm_current * * Description: * Get the current time. @@ -280,7 +290,7 @@ static int arm_tick_start(struct oneshot_lowerhalf_s *lower, * lower Caller allocated instance of the oneshot state structure. This * structure must have been previously initialized via a call to * oneshot_initialize(); - * ticks The location in which to return the current time. + * ts The location in which to return the current time. * * Returned Value: * Zero (OK) is returned on success, a negated errno value is returned on @@ -288,15 +298,21 @@ static int arm_tick_start(struct oneshot_lowerhalf_s *lower, * ****************************************************************************/ -static int arm_tick_current(struct oneshot_lowerhalf_s *lower, - clock_t *ticks) +static int arm_current(struct oneshot_lowerhalf_s *lower, + struct timespec *ts) { + uint64_t count; + uint32_t freq; struct arm_oneshot_lowerhalf_s *priv = (struct arm_oneshot_lowerhalf_s *)lower; - DEBUGASSERT(ticks != NULL); + DEBUGASSERT(ts != NULL); + + freq = priv->frequency; + count = arm_timer_phy_count(); - *ticks = arm_timer_phy_count() / priv->cycle_per_tick; + ts->tv_sec = count / freq; + ts->tv_nsec = (count % freq) * NSEC_PER_SEC / freq; return OK; } @@ -307,10 +323,10 @@ static int arm_tick_current(struct oneshot_lowerhalf_s *lower, static const struct oneshot_operations_s g_oneshot_ops = { - .tick_start = arm_tick_start, - .tick_current = arm_tick_current, - .tick_max_delay = arm_tick_max_delay, - .tick_cancel = arm_tick_cancel, + .start = arm_start, + .current = arm_current, + .max_delay = arm_max_delay, + .cancel = arm_cancel, }; /**************************************************************************** @@ -346,9 +362,10 @@ static struct oneshot_lowerhalf_s *arm_oneshot_initialize(void) /* Initialize the lower-half driver structure */ + DEBUGASSERT(arm_timer_get_freq() <= UINT32_MAX); + priv->lh.ops = &g_oneshot_ops; - priv->cycle_per_tick = arm_timer_get_freq() / TICK_PER_SEC; - tmrinfo("cycle_per_tick %" PRIu64 "\n", priv->cycle_per_tick); + priv->frequency = arm_timer_get_freq(); /* Attach handler */ @@ -411,7 +428,7 @@ void up_timer_initialize(void) * timer interrupt ****************************************************************************/ -void arm_timer_secondary_init(void) +void arm_timer_secondary_init(unsigned int freq) { #ifdef CONFIG_SCHED_TICKLESS tmrinfo("arm_arch_timer_secondary_init\n"); From 346e62778d06f16e01dd0da60857752864a1145e Mon Sep 17 00:00:00 2001 From: ouyangxiangzhen Date: Mon, 27 Oct 2025 14:13:40 +0800 Subject: [PATCH 3/6] arch/risc-v: revert oneshot drivers to timespec API. This commit reverted oneshot drivers to timespec API. Signed-off-by: ouyangxiangzhen --- arch/risc-v/src/common/riscv_mtimer.c | 171 -------------------------- 1 file changed, 171 deletions(-) diff --git a/arch/risc-v/src/common/riscv_mtimer.c b/arch/risc-v/src/common/riscv_mtimer.c index 52c6fab3122e5..4a8946b770bcc 100644 --- a/arch/risc-v/src/common/riscv_mtimer.c +++ b/arch/risc-v/src/common/riscv_mtimer.c @@ -64,16 +64,6 @@ static int riscv_mtimer_cancel(struct oneshot_lowerhalf_s *lower, static int riscv_mtimer_current(struct oneshot_lowerhalf_s *lower, struct timespec *ts); -static int riscv_mtimer_tick_max_delay(struct oneshot_lowerhalf_s *lower, - clock_t *ticks); -static int riscv_mtimer_tick_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, - clock_t ticks); -static int riscv_mtimer_tick_cancel(struct oneshot_lowerhalf_s *lower, - clock_t *ticks); -static int riscv_mtimer_tick_current(struct oneshot_lowerhalf_s *lower, - clock_t *ticks); - /**************************************************************************** * Private Data ****************************************************************************/ @@ -84,10 +74,6 @@ static const struct oneshot_operations_s g_riscv_mtimer_ops = .start = riscv_mtimer_start, .cancel = riscv_mtimer_cancel, .current = riscv_mtimer_current, - .tick_start = riscv_mtimer_tick_start, - .tick_current = riscv_mtimer_tick_current, - .tick_max_delay = riscv_mtimer_tick_max_delay, - .tick_cancel = riscv_mtimer_tick_cancel, }; /**************************************************************************** @@ -132,32 +118,6 @@ static int riscv_mtimer_max_delay(struct oneshot_lowerhalf_s *lower, return 0; } -/**************************************************************************** - * Name: riscv_mtimer_tick_max_delay - * - * Description: - * Determine the maximum delay of the one-shot timer - * - * Input Parameters: - * lower An instance of the lower-half oneshot state structure. This - * structure must have been previously initialized via a call to - * oneshot_initialize(); - * ticks The location in which to return the maximum delay. - * - * Returned Value: - * Zero (OK) is returned on success; a negated errno value is returned - * on failure. - * - ****************************************************************************/ - -static int riscv_mtimer_tick_max_delay(struct oneshot_lowerhalf_s *lower, - clock_t *ticks) -{ - *ticks = (clock_t)UINT64_MAX; - - return 0; -} - /**************************************************************************** * Name: riscv_mtimer_start * @@ -204,53 +164,6 @@ static int riscv_mtimer_start(struct oneshot_lowerhalf_s *lower, return 0; } -/**************************************************************************** - * Name: riscv_mtimer_tick_start - * - * Description: - * Start the oneshot timer - * - * Input Parameters: - * lower An instance of the lower-half oneshot state structure. This - * structure must have been previously initialized via a call to - * oneshot_initialize(); - * handler The function to call when when the oneshot timer expires. - * arg An opaque argument that will accompany the callback. - * ticks Provides the duration of the one shot timer. - * - * Returned Value: - * Zero (OK) is returned on success; a negated errno value is returned - * on failure. - * - ****************************************************************************/ - -static int riscv_mtimer_tick_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, - clock_t ticks) -{ - struct riscv_mtimer_lowerhalf_s *priv = - (struct riscv_mtimer_lowerhalf_s *)lower; - irqstate_t flags; - uint64_t mtime; - clock_t current; - uint64_t alarm; - - flags = up_irq_save(); - - mtime = riscv_mtimer_get_mtime(priv); - current = mtime * TICK_PER_SEC / priv->freq; - alarm = (current + ticks) * priv->freq / TICK_PER_SEC; - - priv->alarm = alarm; - priv->callback = callback; - priv->arg = arg; - - riscv_mtimer_set_mtimecmp(priv, priv->alarm); - - up_irq_restore(flags); - return 0; -} - /**************************************************************************** * Name: riscv_mtimer_cancel * @@ -306,59 +219,6 @@ static int riscv_mtimer_cancel(struct oneshot_lowerhalf_s *lower, return 0; } -/**************************************************************************** - * Name: riscv_mtimer_tick_cancel - * - * Description: - * Cancel the oneshot timer and return the time remaining on the timer. - * - * NOTE: This function may execute at a high rate with no timer running (as - * when pre-emption is enabled and disabled). - * - * Input Parameters: - * lower Caller allocated instance of the oneshot state structure. This - * structure must have been previously initialized via a call to - * oneshot_initialize(); - * ticks The location in which to return the time remaining on the - * oneshot timer. A time of zero is returned if the timer is - * not running. - * - * Returned Value: - * Zero (OK) is returned on success. A call to up_timer_cancel() when - * the timer is not active should also return success; a negated errno - * value is returned on any failure. - * - ****************************************************************************/ - -static int riscv_mtimer_tick_cancel(struct oneshot_lowerhalf_s *lower, - clock_t *ticks) -{ - struct riscv_mtimer_lowerhalf_s *priv = - (struct riscv_mtimer_lowerhalf_s *)lower; - uint64_t mtime; - uint64_t alarm; - irqstate_t flags; - - flags = up_irq_save(); - - alarm = priv->alarm; - - mtime = riscv_mtimer_get_mtime(priv); - - riscv_mtimer_set_mtimecmp(priv, UINT64_MAX); - - *ticks = alarm * TICK_PER_SEC / priv->freq - - mtime * TICK_PER_SEC / priv->freq; - - priv->alarm = 0; - priv->callback = NULL; - priv->arg = NULL; - - up_irq_restore(flags); - - return 0; -} - /**************************************************************************** * Name: riscv_mtimer_current * @@ -405,37 +265,6 @@ static int riscv_mtimer_interrupt(int irq, void *context, void *arg) return 0; } -/**************************************************************************** - * Name: riscv_mtimer_tick_current - * - * Description: - * Get the current time. - * - * Input Parameters: - * lower Caller allocated instance of the oneshot state structure. This - * structure must have been previously initialized via a call to - * oneshot_initialize(); - * ticks The location in which to return the current time. A time of zero - * is returned for the initialization moment. - * - * Returned Value: - * Zero (OK) is returned on success, a negated errno value is returned on - * any failure. - * - ****************************************************************************/ - -static int riscv_mtimer_tick_current(struct oneshot_lowerhalf_s *lower, - clock_t *ticks) -{ - struct riscv_mtimer_lowerhalf_s *priv = - (struct riscv_mtimer_lowerhalf_s *)lower; - uint64_t mtime = riscv_mtimer_get_mtime(priv); - - *ticks = mtime * TICK_PER_SEC / priv->freq; - - return OK; -} - /**************************************************************************** * Public Functions ****************************************************************************/ From 1430edac99203cf3d2f0f352484cf3dd336656e9 Mon Sep 17 00:00:00 2001 From: ouyangxiangzhen Date: Wed, 10 Sep 2025 15:33:27 +0800 Subject: [PATCH 4/6] timers/oneshot: Remove all private callback. This commit removed all private callback and handle it on the upperhalf of oneshot. Signed-off-by: ouyangxiangzhen --- arch/arm/src/armv7-a/arm_timer.c | 20 ++--------- arch/arm/src/armv7-r/arm_timer.c | 21 ++--------- arch/arm/src/armv8-r/arm_timer.c | 14 ++------ arch/arm/src/sam34/sam4cm_oneshot_lowerhalf.c | 34 ++++-------------- arch/arm/src/sama5/sam_oneshot_lowerhalf.c | 34 ++++-------------- arch/arm/src/samd5e5/sam_oneshot_lowerhalf.c | 34 ++++-------------- arch/arm/src/samv7/sam_oneshot_lowerhalf.c | 34 ++++-------------- arch/arm/src/stm32/stm32_oneshot_lowerhalf.c | 34 ++++-------------- .../arm/src/stm32h7/stm32_oneshot_lowerhalf.c | 34 ++++-------------- .../src/stm32l4/stm32l4_oneshot_lowerhalf.c | 34 ++++-------------- .../src/stm32wb/stm32wb_oneshot_lowerhalf.c | 34 ++++-------------- arch/arm64/src/common/arm64_arch_timer.c | 11 ++---- .../src/pic32mz/pic32mz_oneshot_lowerhalf.c | 35 ++++--------------- .../src/bl602/bl602_oneshot_lowerhalf.c | 19 ++-------- .../risc-v/src/common/espressif/esp_oneshot.c | 26 ++------------ arch/risc-v/src/common/riscv_mtimer.c | 15 ++------ .../esp32c3_oneshot_lowerhalf.c | 32 ++++------------- arch/sim/src/sim/sim_oneshot.c | 35 +++++-------------- .../src/bm3803/bm3803_oneshot_lowerhalf.c | 34 ++++-------------- arch/tricore/src/common/tricore_systimer.c | 14 ++------ .../src/intel64/intel64_oneshot_lower.c | 35 ++++--------------- arch/xtensa/src/common/xtensa_oneshot.c | 22 +----------- .../src/esp32/esp32_oneshot_lowerhalf.c | 34 ++++-------------- .../src/esp32s2/esp32s2_oneshot_lowerhalf.c | 32 ++++------------- .../src/esp32s3/esp32s3_oneshot_lowerhalf.c | 30 ++++------------ drivers/audio/tone.c | 3 ++ drivers/timers/arch_alarm.c | 3 ++ drivers/timers/goldfish_timer.c | 23 +----------- drivers/timers/oneshot.c | 4 +++ drivers/timers/watchdog.c | 2 ++ include/nuttx/timers/oneshot.h | 12 +++++++ sched/sched/sched_cpuload_oneshot.c | 2 ++ 32 files changed, 144 insertions(+), 606 deletions(-) diff --git a/arch/arm/src/armv7-a/arm_timer.c b/arch/arm/src/armv7-a/arm_timer.c index 81da492a9b6c6..f234acb584287 100644 --- a/arch/arm/src/armv7-a/arm_timer.c +++ b/arch/arm/src/armv7-a/arm_timer.c @@ -63,8 +63,6 @@ struct arm_timer_lowerhalf_s { struct oneshot_lowerhalf_s lh; /* Lower half operations */ uint32_t freq; /* Timer working clock frequency(Hz) */ - oneshot_callback_t callback; /* Current user interrupt callback */ - void *arg; /* Argument passed to upper half callback */ /* which cpu timer is running, -1 indicate timer stoppd */ @@ -180,9 +178,6 @@ static int arm_timer_start(struct oneshot_lowerhalf_s *lower_, flags = up_irq_save(); - lower->callback = callback; - lower->arg = arg; - lower->running = this_cpu(); count = sec_to_count(ts->tv_sec, lower->freq) + @@ -206,8 +201,6 @@ static int arm_timer_cancel(struct oneshot_lowerhalf_s *lower_, flags = up_irq_save(); - lower->callback = NULL; - lower->arg = NULL; lower->running = -1; arm_timer_phy_set_irq_mask(true); @@ -234,23 +227,14 @@ static int arm_timer_current(struct oneshot_lowerhalf_s *lower_, static int arm_timer_interrupt(int irq, void *context, void *arg) { struct arm_timer_lowerhalf_s *lower = arg; - oneshot_callback_t callback; - void *cbarg; DEBUGASSERT(lower != NULL); arm_timer_phy_set_irq_mask(true); - if (lower->callback != NULL && lower->running == this_cpu()) + if (lower->running == this_cpu()) { - callback = lower->callback; - cbarg = lower->arg; - lower->callback = NULL; - lower->arg = NULL; - - /* Then perform the callback */ - - callback(&lower->lh, cbarg); + oneshot_process_callback(&lower->lh); } return 0; diff --git a/arch/arm/src/armv7-r/arm_timer.c b/arch/arm/src/armv7-r/arm_timer.c index c97f3b7ec7bad..62a69e7e3f44b 100644 --- a/arch/arm/src/armv7-r/arm_timer.c +++ b/arch/arm/src/armv7-r/arm_timer.c @@ -62,8 +62,6 @@ struct arm_timer_lowerhalf_s { struct oneshot_lowerhalf_s lh; /* Lower half operations */ uint32_t freq; /* Timer working clock frequency(Hz) */ - oneshot_callback_t callback; /* Current user interrupt callback */ - void *arg; /* Argument passed to upper half callback */ /* which cpu timer is running, -1 indicate timer stoppd */ @@ -173,9 +171,6 @@ static int arm_timer_start(struct oneshot_lowerhalf_s *lower_, flags = up_irq_save(); - lower->callback = callback; - lower->arg = arg; - lower->running = this_cpu(); count = sec_to_count(ts->tv_sec, arm_timer_get_freq()) + @@ -199,8 +194,6 @@ static int arm_timer_cancel(struct oneshot_lowerhalf_s *lower_, flags = up_irq_save(); - lower->callback = NULL; - lower->arg = NULL; lower->running = -1; arm_timer_phy_set_irq_mask(true); @@ -225,23 +218,13 @@ static int arm_timer_current(struct oneshot_lowerhalf_s *lower_, static int arm_timer_interrupt(int irq, void *context, void *arg) { struct arm_timer_lowerhalf_s *lower = arg; - oneshot_callback_t callback; - void *cbarg; - DEBUGASSERT(lower != NULL); arm_timer_phy_set_irq_mask(true); - if (lower->callback != NULL && lower->running == this_cpu()) + if (lower->running == this_cpu()) { - callback = lower->callback; - cbarg = lower->arg; - lower->callback = NULL; - lower->arg = NULL; - - /* Then perform the callback */ - - callback(&lower->lh, cbarg); + oneshot_process_callback(&lower->lh); } return 0; diff --git a/arch/arm/src/armv8-r/arm_timer.c b/arch/arm/src/armv8-r/arm_timer.c index f3119912d752d..aacdd9b9e557a 100644 --- a/arch/arm/src/armv8-r/arm_timer.c +++ b/arch/arm/src/armv8-r/arm_timer.c @@ -80,9 +80,7 @@ struct arm_oneshot_lowerhalf_s /* Private lower half data follows */ - void *arg; /* Argument that is passed to the handler */ uint32_t frequency; /* Frequency */ - oneshot_callback_t callback; /* Internal handler that receives callback */ }; /**************************************************************************** @@ -146,12 +144,9 @@ static int arm_arch_timer_compare_isr(int irq, void *regs, void *arg) arm_timer_phy_set_irq_mask(true); - if (priv->callback) - { - /* Then perform the callback */ + /* Then perform the callback */ - priv->callback(&priv->lh, priv->arg); - } + oneshot_process_callback(&priv->lh); return OK; } @@ -258,11 +253,6 @@ static int arm_start(struct oneshot_lowerhalf_s *lower, DEBUGASSERT(priv && callback && ts); - /* Save the new handler and its argument */ - - priv->callback = callback; - priv->arg = arg; - /* Set the timeout */ count = arm_timer_phy_count(); diff --git a/arch/arm/src/sam34/sam4cm_oneshot_lowerhalf.c b/arch/arm/src/sam34/sam4cm_oneshot_lowerhalf.c index 7b63804f9ce5a..be01d5578cbc5 100644 --- a/arch/arm/src/sam34/sam4cm_oneshot_lowerhalf.c +++ b/arch/arm/src/sam34/sam4cm_oneshot_lowerhalf.c @@ -58,8 +58,6 @@ struct sam_oneshot_lowerhalf_s /* Private lower half data follows */ struct sam_oneshot_s oneshot; /* SAM-specific oneshot state */ - oneshot_callback_t callback; /* internal handler that receives callback */ - void *arg; /* Argument that is passed to the handler */ }; /**************************************************************************** @@ -112,8 +110,6 @@ static void sam_oneshot_handler(void *arg) { struct sam_oneshot_lowerhalf_s *priv = (struct sam_oneshot_lowerhalf_s *)arg; - oneshot_callback_t callback; - void *cbarg; DEBUGASSERT(priv != NULL); @@ -121,21 +117,7 @@ static void sam_oneshot_handler(void *arg) * sam_cancel? */ - if (priv->callback) - { - /* Sample and nullify BEFORE executing callback (in case the callback - * restarts the oneshot). - */ - - callback = priv->callback; - cbarg = priv->arg; - priv->callback = NULL; - priv->arg = NULL; - - /* Then perform the callback */ - - callback(&priv->lh, cbarg); - } + oneshot_process_callback(&priv->lh); } /**************************************************************************** @@ -211,11 +193,9 @@ static int sam_start(struct oneshot_lowerhalf_s *lower, /* Save the callback information and start the timer */ - flags = enter_critical_section(); - priv->callback = callback; - priv->arg = arg; - ret = sam_oneshot_start(&priv->oneshot, NULL, - sam_oneshot_handler, priv, ts); + flags = enter_critical_section(); + ret = sam_oneshot_start(&priv->oneshot, NULL, + sam_oneshot_handler, priv, ts); leave_critical_section(flags); if (ret < 0) @@ -262,10 +242,8 @@ static int sam_cancel(struct oneshot_lowerhalf_s *lower, /* Cancel the timer */ - flags = enter_critical_section(); - ret = sam_oneshot_cancel(&priv->oneshot, NULL, ts); - priv->callback = NULL; - priv->arg = NULL; + flags = enter_critical_section(); + ret = sam_oneshot_cancel(&priv->oneshot, NULL, ts); leave_critical_section(flags); if (ret < 0) diff --git a/arch/arm/src/sama5/sam_oneshot_lowerhalf.c b/arch/arm/src/sama5/sam_oneshot_lowerhalf.c index 6ce17a5b05403..735eaa0bdce4a 100644 --- a/arch/arm/src/sama5/sam_oneshot_lowerhalf.c +++ b/arch/arm/src/sama5/sam_oneshot_lowerhalf.c @@ -60,8 +60,6 @@ struct sam_oneshot_lowerhalf_s /* Private lower half data follows */ struct sam_oneshot_s oneshot; /* SAM-specific oneshot state */ - oneshot_callback_t callback; /* internal handler that receives callback */ - void *arg; /* Argument that is passed to the handler */ }; /**************************************************************************** @@ -114,8 +112,6 @@ static void sam_oneshot_handler(void *arg) { struct sam_oneshot_lowerhalf_s *priv = (struct sam_oneshot_lowerhalf_s *)arg; - oneshot_callback_t callback; - void *cbarg; DEBUGASSERT(priv != NULL); @@ -123,21 +119,7 @@ static void sam_oneshot_handler(void *arg) * sam_cancel? */ - if (priv->callback) - { - /* Sample and nullify BEFORE executing callback (in case the callback - * restarts the oneshot). - */ - - callback = priv->callback; - cbarg = priv->arg; - priv->callback = NULL; - priv->arg = NULL; - - /* Then perform the callback */ - - callback(&priv->lh, cbarg); - } + oneshot_process_callback(&priv->lh); } /**************************************************************************** @@ -213,11 +195,9 @@ static int sam_start(struct oneshot_lowerhalf_s *lower, /* Save the callback information and start the timer */ - flags = enter_critical_section(); - priv->callback = callback; - priv->arg = arg; - ret = sam_oneshot_start(&priv->oneshot, NULL, - sam_oneshot_handler, priv, ts); + flags = enter_critical_section(); + ret = sam_oneshot_start(&priv->oneshot, NULL, + sam_oneshot_handler, priv, ts); leave_critical_section(flags); if (ret < 0) @@ -264,10 +244,8 @@ static int sam_cancel(struct oneshot_lowerhalf_s *lower, /* Cancel the timer */ - flags = enter_critical_section(); - ret = sam_oneshot_cancel(&priv->oneshot, NULL, ts); - priv->callback = NULL; - priv->arg = NULL; + flags = enter_critical_section(); + ret = sam_oneshot_cancel(&priv->oneshot, NULL, ts); leave_critical_section(flags); if (ret < 0) diff --git a/arch/arm/src/samd5e5/sam_oneshot_lowerhalf.c b/arch/arm/src/samd5e5/sam_oneshot_lowerhalf.c index c41675769b1fd..e4c8f2cf6972c 100644 --- a/arch/arm/src/samd5e5/sam_oneshot_lowerhalf.c +++ b/arch/arm/src/samd5e5/sam_oneshot_lowerhalf.c @@ -58,8 +58,6 @@ struct sam_oneshot_lowerhalf_s /* Private lower half data follows */ struct sam_oneshot_s oneshot; /* SAM-specific oneshot state */ - oneshot_callback_t callback; /* internal handler that receives callback */ - void *arg; /* Argument that is passed to the handler */ }; /**************************************************************************** @@ -112,8 +110,6 @@ static void sam_oneshot_handler(void *arg) { struct sam_oneshot_lowerhalf_s *priv = (struct sam_oneshot_lowerhalf_s *)arg; - oneshot_callback_t callback; - void *cbarg; DEBUGASSERT(priv != NULL); @@ -121,21 +117,7 @@ static void sam_oneshot_handler(void *arg) * sam_cancel? */ - if (priv->callback) - { - /* Sample and nullify BEFORE executing callback (in case the callback - * restarts the oneshot). - */ - - callback = priv->callback; - cbarg = priv->arg; - priv->callback = NULL; - priv->arg = NULL; - - /* Then perform the callback */ - - callback(&priv->lh, cbarg); - } + oneshot_process_callback(&priv->lh); } /**************************************************************************** @@ -211,11 +193,9 @@ static int sam_start(struct oneshot_lowerhalf_s *lower, /* Save the callback information and start the timer */ - flags = enter_critical_section(); - priv->callback = callback; - priv->arg = arg; - ret = sam_oneshot_start(&priv->oneshot, NULL, - sam_oneshot_handler, priv, ts); + flags = enter_critical_section(); + ret = sam_oneshot_start(&priv->oneshot, NULL, + sam_oneshot_handler, priv, ts); leave_critical_section(flags); if (ret < 0) @@ -262,10 +242,8 @@ static int sam_cancel(struct oneshot_lowerhalf_s *lower, /* Cancel the timer */ - flags = enter_critical_section(); - ret = sam_oneshot_cancel(&priv->oneshot, NULL, ts); - priv->callback = NULL; - priv->arg = NULL; + flags = enter_critical_section(); + ret = sam_oneshot_cancel(&priv->oneshot, NULL, ts); leave_critical_section(flags); if (ret < 0) diff --git a/arch/arm/src/samv7/sam_oneshot_lowerhalf.c b/arch/arm/src/samv7/sam_oneshot_lowerhalf.c index dc736a3ee5404..1822c3d27af55 100644 --- a/arch/arm/src/samv7/sam_oneshot_lowerhalf.c +++ b/arch/arm/src/samv7/sam_oneshot_lowerhalf.c @@ -58,8 +58,6 @@ struct sam_oneshot_lowerhalf_s /* Private lower half data follows */ struct sam_oneshot_s oneshot; /* SAMV7-specific oneshot state */ - oneshot_callback_t callback; /* internal handler that receives callback */ - void *arg; /* Argument that is passed to the handler */ }; /**************************************************************************** @@ -112,8 +110,6 @@ static void sam_oneshot_handler(void *arg) { struct sam_oneshot_lowerhalf_s *priv = (struct sam_oneshot_lowerhalf_s *)arg; - oneshot_callback_t callback; - void *cbarg; DEBUGASSERT(priv != NULL); @@ -121,21 +117,7 @@ static void sam_oneshot_handler(void *arg) * sam_cancel? */ - if (priv->callback) - { - /* Sample and nullify BEFORE executing callback (in case the callback - * restarts the oneshot). - */ - - callback = priv->callback; - cbarg = priv->arg; - priv->callback = NULL; - priv->arg = NULL; - - /* Then perform the callback */ - - callback(&priv->lh, cbarg); - } + oneshot_process_callback(&priv->lh); } /**************************************************************************** @@ -211,11 +193,9 @@ static int sam_start(struct oneshot_lowerhalf_s *lower, /* Save the callback information and start the timer */ - flags = enter_critical_section(); - priv->callback = callback; - priv->arg = arg; - ret = sam_oneshot_start(&priv->oneshot, NULL, - sam_oneshot_handler, priv, ts); + flags = enter_critical_section(); + ret = sam_oneshot_start(&priv->oneshot, NULL, + sam_oneshot_handler, priv, ts); leave_critical_section(flags); if (ret < 0) @@ -262,10 +242,8 @@ static int sam_cancel(struct oneshot_lowerhalf_s *lower, /* Cancel the timer */ - flags = enter_critical_section(); - ret = sam_oneshot_cancel(&priv->oneshot, NULL, ts); - priv->callback = NULL; - priv->arg = NULL; + flags = enter_critical_section(); + ret = sam_oneshot_cancel(&priv->oneshot, NULL, ts); leave_critical_section(flags); if (ret < 0) diff --git a/arch/arm/src/stm32/stm32_oneshot_lowerhalf.c b/arch/arm/src/stm32/stm32_oneshot_lowerhalf.c index f0b6d2ccf9518..2d6a2c7e6fd93 100644 --- a/arch/arm/src/stm32/stm32_oneshot_lowerhalf.c +++ b/arch/arm/src/stm32/stm32_oneshot_lowerhalf.c @@ -57,8 +57,6 @@ struct stm32_oneshot_lowerhalf_s /* Private lower half data follows */ struct stm32_oneshot_s oneshot; /* STM32-specific oneshot state */ - oneshot_callback_t callback; /* Internal handler that receives callback */ - void *arg; /* Argument that is passed to the handler */ }; /**************************************************************************** @@ -111,8 +109,6 @@ static void stm32_oneshot_handler(void *arg) { struct stm32_oneshot_lowerhalf_s *priv = (struct stm32_oneshot_lowerhalf_s *)arg; - oneshot_callback_t callback; - void *cbarg; DEBUGASSERT(priv != NULL); @@ -120,21 +116,7 @@ static void stm32_oneshot_handler(void *arg) * stm32_cancel? */ - if (priv->callback) - { - /* Sample and nullify BEFORE executing callback (in case the callback - * restarts the oneshot). - */ - - callback = priv->callback; - cbarg = priv->arg; - priv->callback = NULL; - priv->arg = NULL; - - /* Then perform the callback */ - - callback(&priv->lh, cbarg); - } + oneshot_process_callback(&priv->lh); } /**************************************************************************** @@ -210,11 +192,9 @@ static int stm32_start(struct oneshot_lowerhalf_s *lower, /* Save the callback information and start the timer */ - flags = enter_critical_section(); - priv->callback = callback; - priv->arg = arg; - ret = stm32_oneshot_start(&priv->oneshot, - stm32_oneshot_handler, priv, ts); + flags = enter_critical_section(); + ret = stm32_oneshot_start(&priv->oneshot, + stm32_oneshot_handler, priv, ts); leave_critical_section(flags); if (ret < 0) @@ -261,10 +241,8 @@ static int stm32_cancel(struct oneshot_lowerhalf_s *lower, /* Cancel the timer */ - flags = enter_critical_section(); - ret = stm32_oneshot_cancel(&priv->oneshot, ts); - priv->callback = NULL; - priv->arg = NULL; + flags = enter_critical_section(); + ret = stm32_oneshot_cancel(&priv->oneshot, ts); leave_critical_section(flags); if (ret < 0) diff --git a/arch/arm/src/stm32h7/stm32_oneshot_lowerhalf.c b/arch/arm/src/stm32h7/stm32_oneshot_lowerhalf.c index 545f4ebdcf355..8f80f9bec491a 100644 --- a/arch/arm/src/stm32h7/stm32_oneshot_lowerhalf.c +++ b/arch/arm/src/stm32h7/stm32_oneshot_lowerhalf.c @@ -57,8 +57,6 @@ struct stm32_oneshot_lowerhalf_s /* Private lower half data follows */ struct stm32_oneshot_s oneshot; /* STM32-specific oneshot state */ - oneshot_callback_t callback; /* Internal handler that receives callback */ - void *arg; /* Argument that is passed to the handler */ }; /**************************************************************************** @@ -111,8 +109,6 @@ static void stm32_oneshot_handler(void *arg) { struct stm32_oneshot_lowerhalf_s *priv = (struct stm32_oneshot_lowerhalf_s *)arg; - oneshot_callback_t callback; - void *cbarg; DEBUGASSERT(priv != NULL); @@ -120,21 +116,7 @@ static void stm32_oneshot_handler(void *arg) * stm32_cancel? */ - if (priv->callback) - { - /* Sample and nullify BEFORE executing callback (in case the callback - * restarts the oneshot). - */ - - callback = priv->callback; - cbarg = priv->arg; - priv->callback = NULL; - priv->arg = NULL; - - /* Then perform the callback */ - - callback(&priv->lh, cbarg); - } + oneshot_process_callback(&priv->lh); } /**************************************************************************** @@ -210,11 +192,9 @@ static int stm32_start(struct oneshot_lowerhalf_s *lower, /* Save the callback information and start the timer */ - flags = enter_critical_section(); - priv->callback = callback; - priv->arg = arg; - ret = stm32_oneshot_start(&priv->oneshot, - stm32_oneshot_handler, priv, ts); + flags = enter_critical_section(); + ret = stm32_oneshot_start(&priv->oneshot, + stm32_oneshot_handler, priv, ts); leave_critical_section(flags); if (ret < 0) @@ -261,10 +241,8 @@ static int stm32_cancel(struct oneshot_lowerhalf_s *lower, /* Cancel the timer */ - flags = enter_critical_section(); - ret = stm32_oneshot_cancel(&priv->oneshot, ts); - priv->callback = NULL; - priv->arg = NULL; + flags = enter_critical_section(); + ret = stm32_oneshot_cancel(&priv->oneshot, ts); leave_critical_section(flags); if (ret < 0) diff --git a/arch/arm/src/stm32l4/stm32l4_oneshot_lowerhalf.c b/arch/arm/src/stm32l4/stm32l4_oneshot_lowerhalf.c index 61e75d04ffa77..d217c341d5e6b 100644 --- a/arch/arm/src/stm32l4/stm32l4_oneshot_lowerhalf.c +++ b/arch/arm/src/stm32l4/stm32l4_oneshot_lowerhalf.c @@ -58,8 +58,6 @@ struct stm32l4_oneshot_lowerhalf_s /* Private lower half data follows */ struct stm32l4_oneshot_s oneshot; /* STM32-specific oneshot state */ - oneshot_callback_t callback; /* internal handler that receives callback */ - void *arg; /* Argument that is passed to the handler */ }; /**************************************************************************** @@ -112,8 +110,6 @@ static void stm32l4_oneshot_handler(void *arg) { struct stm32l4_oneshot_lowerhalf_s *priv = (struct stm32l4_oneshot_lowerhalf_s *)arg; - oneshot_callback_t callback; - void *cbarg; DEBUGASSERT(priv != NULL); @@ -121,21 +117,7 @@ static void stm32l4_oneshot_handler(void *arg) * stm32l4_cancel? */ - if (priv->callback) - { - /* Sample and nullify BEFORE executing callback (in case the callback - * restarts the oneshot). - */ - - callback = priv->callback; - cbarg = priv->arg; - priv->callback = NULL; - priv->arg = NULL; - - /* Then perform the callback */ - - callback(&priv->lh, cbarg); - } + oneshot_process_callback(&priv->lh); } /**************************************************************************** @@ -211,11 +193,9 @@ static int stm32l4_start(struct oneshot_lowerhalf_s *lower, /* Save the callback information and start the timer */ - flags = enter_critical_section(); - priv->callback = callback; - priv->arg = arg; - ret = stm32l4_oneshot_start(&priv->oneshot, - stm32l4_oneshot_handler, priv, ts); + flags = enter_critical_section(); + ret = stm32l4_oneshot_start(&priv->oneshot, + stm32l4_oneshot_handler, priv, ts); leave_critical_section(flags); if (ret < 0) @@ -262,10 +242,8 @@ static int stm32l4_cancel(struct oneshot_lowerhalf_s *lower, /* Cancel the timer */ - flags = enter_critical_section(); - ret = stm32l4_oneshot_cancel(&priv->oneshot, ts); - priv->callback = NULL; - priv->arg = NULL; + flags = enter_critical_section(); + ret = stm32l4_oneshot_cancel(&priv->oneshot, ts); leave_critical_section(flags); if (ret < 0) diff --git a/arch/arm/src/stm32wb/stm32wb_oneshot_lowerhalf.c b/arch/arm/src/stm32wb/stm32wb_oneshot_lowerhalf.c index 2df58ee753dbd..cae5981a8e640 100644 --- a/arch/arm/src/stm32wb/stm32wb_oneshot_lowerhalf.c +++ b/arch/arm/src/stm32wb/stm32wb_oneshot_lowerhalf.c @@ -58,8 +58,6 @@ struct stm32wb_oneshot_lowerhalf_s /* Private lower half data follows */ struct stm32wb_oneshot_s oneshot; /* STM32-specific oneshot state */ - oneshot_callback_t callback; /* internal handler that receives callback */ - void *arg; /* Argument that is passed to the handler */ }; /**************************************************************************** @@ -112,8 +110,6 @@ static void stm32wb_oneshot_handler(void *arg) { struct stm32wb_oneshot_lowerhalf_s *priv = (struct stm32wb_oneshot_lowerhalf_s *)arg; - oneshot_callback_t callback; - void *cbarg; DEBUGASSERT(priv != NULL); @@ -121,21 +117,7 @@ static void stm32wb_oneshot_handler(void *arg) * stm32wb_cancel? */ - if (priv->callback) - { - /* Sample and nullify BEFORE executing callback (in case the callback - * restarts the oneshot). - */ - - callback = priv->callback; - cbarg = priv->arg; - priv->callback = NULL; - priv->arg = NULL; - - /* Then perform the callback */ - - callback(&priv->lh, cbarg); - } + oneshot_process_callback(&priv->lh); } /**************************************************************************** @@ -211,11 +193,9 @@ static int stm32wb_start(struct oneshot_lowerhalf_s *lower, /* Save the callback information and start the timer */ - flags = enter_critical_section(); - priv->callback = callback; - priv->arg = arg; - ret = stm32wb_oneshot_start(&priv->oneshot, - stm32wb_oneshot_handler, priv, ts); + flags = enter_critical_section(); + ret = stm32wb_oneshot_start(&priv->oneshot, + stm32wb_oneshot_handler, priv, ts); leave_critical_section(flags); if (ret < 0) @@ -262,10 +242,8 @@ static int stm32wb_cancel(struct oneshot_lowerhalf_s *lower, /* Cancel the timer */ - flags = enter_critical_section(); - ret = stm32wb_oneshot_cancel(&priv->oneshot, ts); - priv->callback = NULL; - priv->arg = NULL; + flags = enter_critical_section(); + ret = stm32wb_oneshot_cancel(&priv->oneshot, ts); leave_critical_section(flags); if (ret < 0) diff --git a/arch/arm64/src/common/arm64_arch_timer.c b/arch/arm64/src/common/arm64_arch_timer.c index b487221e20550..89aa274ca0cd0 100644 --- a/arch/arm64/src/common/arm64_arch_timer.c +++ b/arch/arm64/src/common/arm64_arch_timer.c @@ -69,9 +69,7 @@ struct arm64_oneshot_lowerhalf_s /* Private lower half data follows */ - void *arg; /* Argument that is passed to the handler */ uint64_t frequency; /* Frequency in cycle per second */ - oneshot_callback_t callback; /* Internal handler that receives callback */ /* which cpu timer is running, -1 indicate timer stoppd */ @@ -136,11 +134,11 @@ static int arm64_arch_timer_compare_isr(int irq, void *regs, void *arg) arm64_arch_timer_set_irq_mask(true); - if (priv->callback && priv->running == this_cpu()) + if (priv->running == this_cpu()) { /* Then perform the callback */ - priv->callback(&priv->lh, priv->arg); + oneshot_process_callback(&priv->lh); } return OK; @@ -247,11 +245,6 @@ static int arm64_start(struct oneshot_lowerhalf_s *lower, DEBUGASSERT(priv && callback && ts); - /* Save the new handler and its argument */ - - priv->callback = callback; - priv->arg = arg; - priv->running = this_cpu(); count = arm64_arch_timer_count(); diff --git a/arch/mips/src/pic32mz/pic32mz_oneshot_lowerhalf.c b/arch/mips/src/pic32mz/pic32mz_oneshot_lowerhalf.c index da88ae9ee7e29..e63b78c034c89 100644 --- a/arch/mips/src/pic32mz/pic32mz_oneshot_lowerhalf.c +++ b/arch/mips/src/pic32mz/pic32mz_oneshot_lowerhalf.c @@ -56,8 +56,6 @@ struct pic32mz_oneshot_lowerhalf_s /* Private lower half data follows */ struct pic32mz_oneshot_s oneshot; /* PIC32MZ-specific oneshot state */ - oneshot_callback_t callback; /* Handler that receives callback */ - void *arg; /* Argument passed to the handler */ }; /**************************************************************************** @@ -110,8 +108,6 @@ static void pic32mz_oneshot_handler(void *arg) { struct pic32mz_oneshot_lowerhalf_s *priv = (struct pic32mz_oneshot_lowerhalf_s *)arg; - oneshot_callback_t callback; - void *cbarg; DEBUGASSERT(priv != NULL); @@ -119,21 +115,7 @@ static void pic32mz_oneshot_handler(void *arg) * pic32mz_cancel? */ - if (priv->callback) - { - /* Sample and nullify BEFORE executing callback (in case the callback - * restarts the oneshot). - */ - - callback = priv->callback; - cbarg = priv->arg; - priv->callback = NULL; - priv->arg = NULL; - - /* Then perform the callback */ - - callback(&priv->lh, cbarg); - } + oneshot_process_callback(&priv->lh); } /**************************************************************************** @@ -212,12 +194,9 @@ static int pic32mz_start(struct oneshot_lowerhalf_s *lower, /* Save the callback information and start the timer */ - flags = enter_critical_section(); - priv->callback = callback; - priv->arg = arg; - ret = pic32mz_oneshot_start(&priv->oneshot, - pic32mz_oneshot_handler, - priv, ts); + flags = enter_critical_section(); + ret = pic32mz_oneshot_start(&priv->oneshot, + pic32mz_oneshot_handler, priv, ts); leave_critical_section(flags); if (ret < 0) @@ -264,10 +243,8 @@ static int pic32mz_cancel(struct oneshot_lowerhalf_s *lower, /* Cancel the timer */ - flags = enter_critical_section(); - ret = pic32mz_oneshot_cancel(&priv->oneshot, ts); - priv->callback = NULL; - priv->arg = NULL; + flags = enter_critical_section(); + ret = pic32mz_oneshot_cancel(&priv->oneshot, ts); leave_critical_section(flags); if (ret < 0) diff --git a/arch/risc-v/src/bl602/bl602_oneshot_lowerhalf.c b/arch/risc-v/src/bl602/bl602_oneshot_lowerhalf.c index 53d49c2c1d065..f77194ccad4cc 100644 --- a/arch/risc-v/src/bl602/bl602_oneshot_lowerhalf.c +++ b/arch/risc-v/src/bl602/bl602_oneshot_lowerhalf.c @@ -72,8 +72,6 @@ struct bl602_oneshot_lowerhalf_s /* Private lower half data follows */ - oneshot_callback_t callback; /* Internal handler that receives callback */ - void * arg; /* Argument that is passed to the handler */ uint8_t tim; /* timer tim 0,1 */ uint8_t irq; /* IRQ associated with this timer */ bool started; /* True: Timer has been started */ @@ -129,9 +127,6 @@ static int bl602_oneshot_handler(int irq, void *context, void *arg) struct bl602_oneshot_lowerhalf_s *priv = (struct bl602_oneshot_lowerhalf_s *)arg; - oneshot_callback_t callback; - void * cbarg; - /* Clear Interrupt Bits */ uint32_t int_id; @@ -156,13 +151,7 @@ static int bl602_oneshot_handler(int irq, void *context, void *arg) if ((int_id & TIMER_TMSR2_TMSR_0) != 0) { putreg32(ticr_val | TIMER_TICR2_TCLR_0, ticr_addr); - callback = priv->callback; - cbarg = priv->arg; - - if (callback) - { - callback(&priv->lh, cbarg); - } + oneshot_process_callback(&priv->lh); } /* Comparator 1 match interrupt */ @@ -261,9 +250,7 @@ static int bl602_start(struct oneshot_lowerhalf_s *lower, /* Save the callback information and start the timer */ - flags = enter_critical_section(); - priv->callback = callback; - priv->arg = arg; + flags = enter_critical_section(); /* Express the delay in microseconds */ @@ -328,8 +315,6 @@ static int bl602_cancel(struct oneshot_lowerhalf_s *lower, priv->started = false; up_disable_irq(priv->irq); bl602_timer_intmask(priv->tim, TIMER_INT_COMP_0, 1); - priv->callback = NULL; - priv->arg = NULL; leave_critical_section(flags); return OK; diff --git a/arch/risc-v/src/common/espressif/esp_oneshot.c b/arch/risc-v/src/common/espressif/esp_oneshot.c index 909ca0ee67807..732bd6b283ad7 100644 --- a/arch/risc-v/src/common/espressif/esp_oneshot.c +++ b/arch/risc-v/src/common/espressif/esp_oneshot.c @@ -80,8 +80,6 @@ struct esp_oneshot_lowerhalf_s { struct oneshot_lowerhalf_s lh; /* Lower half instance */ timer_hal_context_t hal; /* HAL context */ - oneshot_callback_t callback; /* Current user interrupt callback */ - void *arg; /* Argument passed to upper half callback */ uint16_t resolution; /* Timer resolution in microseconds */ bool running; /* True: the timer is running */ }; @@ -129,8 +127,6 @@ static struct esp_oneshot_lowerhalf_s g_oneshot_lowerhalf = { .ops = &g_oneshot_ops, }, - .callback = NULL, - .arg = NULL }; /**************************************************************************** @@ -223,11 +219,6 @@ static int esp_oneshot_start(struct oneshot_lowerhalf_s *lower, esp_oneshot_cancel(lower, NULL); } - /* Save the new callback and its argument */ - - priv->callback = callback; - priv->arg = arg; - /* Retrieve the duration from timespec in microsecond */ timeout_us = (uint64_t)ts->tv_sec * USEC_PER_SEC + @@ -368,9 +359,7 @@ static int esp_oneshot_cancel(struct oneshot_lowerhalf_s *lower, ts->tv_nsec = remaining_us * NSEC_PER_USEC; } - priv->running = false; - priv->callback = NULL; - priv->arg = NULL; + priv->running = false; return OK; } @@ -441,8 +430,6 @@ IRAM_ATTR static int esp_oneshot_isr(int irq, void *context, void *arg) { struct esp_oneshot_lowerhalf_s *priv = (struct esp_oneshot_lowerhalf_s *)arg; - oneshot_callback_t callback; - void *callback_arg; timer_hal_context_t *hal = &(priv->hal); uint32_t intr_status = timer_ll_get_intr_status(hal->dev); @@ -460,16 +447,9 @@ IRAM_ATTR static int esp_oneshot_isr(int irq, void *context, void *arg) priv->running = false; - /* Forward the event, clearing out any vestiges */ - - callback = priv->callback; - callback_arg = priv->arg; - priv->callback = NULL; - priv->arg = NULL; - /* Call the callback */ - callback(&priv->lh, callback_arg); + oneshot_process_callback(&priv->lh); return OK; } @@ -510,8 +490,6 @@ struct oneshot_lowerhalf_s *oneshot_initialize(int chan, uint16_t resolution) /* Initialize the elements of lower half state structure */ - lower->callback = NULL; - lower->arg = NULL; lower->resolution = resolution; lower->running = false; diff --git a/arch/risc-v/src/common/riscv_mtimer.c b/arch/risc-v/src/common/riscv_mtimer.c index 4a8946b770bcc..23167a98658d9 100644 --- a/arch/risc-v/src/common/riscv_mtimer.c +++ b/arch/risc-v/src/common/riscv_mtimer.c @@ -46,8 +46,6 @@ struct riscv_mtimer_lowerhalf_s uintreg_t mtimecmp; uint64_t freq; uint64_t alarm; - oneshot_callback_t callback; - void *arg; }; /**************************************************************************** @@ -154,9 +152,7 @@ static int riscv_mtimer_start(struct oneshot_lowerhalf_s *lower, alarm = mtime + ts->tv_sec * priv->freq + ts->tv_nsec * priv->freq / NSEC_PER_SEC; - priv->alarm = alarm; - priv->callback = callback; - priv->arg = arg; + priv->alarm = alarm; riscv_mtimer_set_mtimecmp(priv, priv->alarm); @@ -210,9 +206,7 @@ static int riscv_mtimer_cancel(struct oneshot_lowerhalf_s *lower, ts->tv_sec = nsec / NSEC_PER_SEC; ts->tv_nsec = nsec % NSEC_PER_SEC; - priv->alarm = 0; - priv->callback = NULL; - priv->arg = NULL; + priv->alarm = 0; up_irq_restore(flags); @@ -257,10 +251,7 @@ static int riscv_mtimer_interrupt(int irq, void *context, void *arg) { struct riscv_mtimer_lowerhalf_s *priv = arg; - if (priv->callback != NULL) - { - priv->callback(&priv->lower, priv->arg); - } + oneshot_process_callback(&priv->lower); return 0; } diff --git a/arch/risc-v/src/esp32c3-legacy/esp32c3_oneshot_lowerhalf.c b/arch/risc-v/src/esp32c3-legacy/esp32c3_oneshot_lowerhalf.c index 817cedbd70a59..dc5f2853b8baf 100644 --- a/arch/risc-v/src/esp32c3-legacy/esp32c3_oneshot_lowerhalf.c +++ b/arch/risc-v/src/esp32c3-legacy/esp32c3_oneshot_lowerhalf.c @@ -58,8 +58,6 @@ struct esp32c3_oneshot_lowerhalf_s struct oneshot_lowerhalf_s lh; /* Lower half instance */ struct esp32c3_oneshot_s oneshot; /* ESP32-C3-specific oneshot state */ - oneshot_callback_t callback; /* Upper half Interrupt callback */ - void *arg; /* Argument passed to handler */ uint16_t resolution; }; @@ -116,11 +114,8 @@ static void esp32c3_oneshot_lh_handler(void *arg) { struct esp32c3_oneshot_lowerhalf_s *priv = (struct esp32c3_oneshot_lowerhalf_s *)arg; - oneshot_callback_t callback; - void *cb_arg; DEBUGASSERT(priv != NULL); - DEBUGASSERT(priv->callback != NULL); tmrinfo("Oneshot LH handler triggered\n"); @@ -128,14 +123,7 @@ static void esp32c3_oneshot_lh_handler(void *arg) * restarts the oneshot). */ - callback = priv->callback; - cb_arg = priv->arg; - priv->callback = NULL; - priv->arg = NULL; - - /* Then perform the callback */ - - callback(&priv->lh, cb_arg); + oneshot_process_callback(&priv->lh); } /**************************************************************************** @@ -215,13 +203,9 @@ static int oneshot_lh_start(struct oneshot_lowerhalf_s *lower, /* Save the callback information and start the timer */ - flags = enter_critical_section(); - priv->callback = callback; - priv->arg = arg; - ret = esp32c3_oneshot_start(&priv->oneshot, - esp32c3_oneshot_lh_handler, - priv, - ts); + flags = enter_critical_section(); + ret = esp32c3_oneshot_start(&priv->oneshot, esp32c3_oneshot_lh_handler, + priv, ts); leave_critical_section(flags); if (ret < 0) @@ -268,10 +252,8 @@ static int oneshot_lh_cancel(struct oneshot_lowerhalf_s *lower, /* Cancel the timer */ - flags = enter_critical_section(); - ret = esp32c3_oneshot_cancel(&priv->oneshot, ts); - priv->callback = NULL; - priv->arg = NULL; + flags = enter_critical_section(); + ret = esp32c3_oneshot_cancel(&priv->oneshot, ts); leave_critical_section(flags); if (ret < 0) @@ -358,8 +340,6 @@ struct oneshot_lowerhalf_s *oneshot_initialize(int chan, } priv->lh.ops = &g_esp32c3_timer_ops; /* Pointer to the LH operations */ - priv->callback = NULL; /* No callback yet */ - priv->arg = NULL; /* No arg yet */ priv->resolution = resolution; /* Configured resolution */ /* Initialize esp32c3_oneshot_s structure */ diff --git a/arch/sim/src/sim/sim_oneshot.c b/arch/sim/src/sim/sim_oneshot.c index 96e8594169919..d9b0133cc2c73 100644 --- a/arch/sim/src/sim/sim_oneshot.c +++ b/arch/sim/src/sim/sim_oneshot.c @@ -62,9 +62,7 @@ struct sim_oneshot_lowerhalf_s sq_entry_t link; struct timespec alarm; - - oneshot_callback_t callback; /* internal handler that receives callback */ - void *arg; /* Argument that is passed to the handler */ + int running; }; /**************************************************************************** @@ -223,8 +221,6 @@ static void sim_process_tick(sq_entry_t *entry) { struct sim_oneshot_lowerhalf_s *priv = container_of(entry, struct sim_oneshot_lowerhalf_s, link); - oneshot_callback_t callback; - void *cbarg; DEBUGASSERT(priv != NULL); @@ -238,20 +234,10 @@ static void sim_process_tick(sq_entry_t *entry) sim_reset_alarm(&priv->alarm); - if (priv->callback) + if (priv->running == 1) { - /* Sample and nullify BEFORE executing callback (in case the callback - * restarts the oneshot). - */ - - callback = priv->callback; - cbarg = priv->arg; - priv->callback = NULL; - priv->arg = NULL; - - /* Then perform the callback */ - - callback(&priv->lh, cbarg); + priv->running = 0; + oneshot_process_callback(&priv->lh); } } @@ -315,12 +301,10 @@ static int sim_start(struct oneshot_lowerhalf_s *lower, flags = enter_critical_section(); - clock_ticks2time(&priv->alarm, - host_gettime(false) / NSEC_PER_TICK + - clock_time2ticks(ts)); + priv->running = 1; - priv->callback = callback; - priv->arg = arg; + sim_timer_current(¤t); + clock_timespec_add(¤t, ts, &priv->alarm); sim_update_hosttimer(); @@ -374,9 +358,6 @@ static int sim_cancel(struct oneshot_lowerhalf_s *lower, sim_reset_alarm(&priv->alarm); sim_update_hosttimer(); - priv->callback = NULL; - priv->arg = NULL; - leave_critical_section(flags); return OK; @@ -474,6 +455,8 @@ struct oneshot_lowerhalf_s *oneshot_initialize(int chan, /* Initialize the lower-half driver structure */ + priv->running = 0; + sq_addlast(&priv->link, &g_oneshot_list); priv->lh.ops = &g_oneshot_ops; diff --git a/arch/sparc/src/bm3803/bm3803_oneshot_lowerhalf.c b/arch/sparc/src/bm3803/bm3803_oneshot_lowerhalf.c index 5f1bd1f311836..16bbbffe04383 100644 --- a/arch/sparc/src/bm3803/bm3803_oneshot_lowerhalf.c +++ b/arch/sparc/src/bm3803/bm3803_oneshot_lowerhalf.c @@ -60,8 +60,6 @@ struct bm3803_oneshot_lowerhalf_s /* STM32-specific oneshot state */ struct bm3803_oneshot_s oneshot; - oneshot_callback_t callback; /* internal handler that receives callback */ - void *arg; /* Argument that is passed to the handler */ }; /**************************************************************************** @@ -114,8 +112,6 @@ static void bm3803_oneshot_handler(void *arg) { struct bm3803_oneshot_lowerhalf_s *priv = (struct bm3803_oneshot_lowerhalf_s *)arg; - oneshot_callback_t callback; - void *cbarg; DEBUGASSERT(priv != NULL); @@ -123,21 +119,7 @@ static void bm3803_oneshot_handler(void *arg) * bm3803_cancel? */ - if (priv->callback) - { - /* Sample and nullify BEFORE executing callback (in case the callback - * restarts the oneshot). - */ - - callback = priv->callback; - cbarg = priv->arg; - priv->callback = NULL; - priv->arg = NULL; - - /* Then perform the callback */ - - callback(&priv->lh, cbarg); - } + oneshot_process_callback(&priv->lh); } /**************************************************************************** @@ -213,11 +195,9 @@ static int bm3803_start(struct oneshot_lowerhalf_s *lower, /* Save the callback information and start the timer */ - flags = enter_critical_section(); - priv->callback = callback; - priv->arg = arg; - ret = bm3803_oneshot_start(&priv->oneshot, - bm3803_oneshot_handler, priv, ts); + flags = enter_critical_section(); + ret = bm3803_oneshot_start(&priv->oneshot, + bm3803_oneshot_handler, priv, ts); leave_critical_section(flags); if (ret < 0) @@ -264,10 +244,8 @@ static int bm3803_cancel(struct oneshot_lowerhalf_s *lower, /* Cancel the timer */ - flags = enter_critical_section(); - ret = bm3803_oneshot_cancel(&priv->oneshot, ts); - priv->callback = NULL; - priv->arg = NULL; + flags = enter_critical_section(); + ret = bm3803_oneshot_cancel(&priv->oneshot, ts); leave_critical_section(flags); if (ret < 0) diff --git a/arch/tricore/src/common/tricore_systimer.c b/arch/tricore/src/common/tricore_systimer.c index 70ad40629cffb..6405cd8478b4f 100644 --- a/arch/tricore/src/common/tricore_systimer.c +++ b/arch/tricore/src/common/tricore_systimer.c @@ -49,8 +49,6 @@ struct tricore_systimer_lowerhalf_s volatile void *tbase; uint64_t freq; uint64_t alarm; - oneshot_callback_t callback; - void *arg; spinlock_t lock; }; @@ -184,9 +182,6 @@ static int tricore_systimer_start(struct oneshot_lowerhalf_s *lower, priv->alarm = UINT64_MAX; } - priv->callback = callback; - priv->arg = arg; - tricore_systimer_set_timecmp(priv, priv->alarm); return 0; } @@ -239,9 +234,7 @@ static int tricore_systimer_cancel(struct oneshot_lowerhalf_s *lower, ts->tv_nsec = 0; } - priv->alarm = 0; - priv->callback = NULL; - priv->arg = NULL; + priv->alarm = 0; return 0; } @@ -335,10 +328,7 @@ static int tricore_systimer_interrupt(int irq, void *context, void *arg) struct tricore_systimer_lowerhalf_s *priv = arg; tricore_systimer_set_timecmp(priv, UINT64_MAX); - if (priv->callback != NULL) - { - priv->callback(&priv->lower, priv->arg); - } + oneshot_process_callback(&priv->lower); return 0; } diff --git a/arch/x86_64/src/intel64/intel64_oneshot_lower.c b/arch/x86_64/src/intel64/intel64_oneshot_lower.c index f82aace3e9843..126f7c5b6b873 100644 --- a/arch/x86_64/src/intel64/intel64_oneshot_lower.c +++ b/arch/x86_64/src/intel64/intel64_oneshot_lower.c @@ -49,8 +49,6 @@ struct intel64_oneshot_lowerhalf_s { struct oneshot_lowerhalf_s lh; struct intel64_oneshot_s oneshot; - oneshot_callback_t callback; - void *arg; }; /**************************************************************************** @@ -120,8 +118,6 @@ static spinlock_t g_oneshotlow_spin; static void intel64_oneshot_handler(void *arg) { struct intel64_oneshot_lowerhalf_s *priv = arg; - oneshot_callback_t callback; - void *cbarg; DEBUGASSERT(priv != NULL); @@ -129,21 +125,7 @@ static void intel64_oneshot_handler(void *arg) * intel64_cancel? */ - if (priv->callback) - { - /* Sample and nullify BEFORE executing callback (in case the callback - * restarts the oneshot). - */ - - callback = priv->callback; - cbarg = priv->arg; - priv->callback = NULL; - priv->arg = NULL; - - /* Then perform the callback */ - - callback(&priv->lh, cbarg); - } + oneshot_process_callback(&priv->lh); } /**************************************************************************** @@ -220,12 +202,9 @@ static int intel64_start(struct oneshot_lowerhalf_s *lower, /* Save the callback information and start the timer */ - flags = spin_lock_irqsave(&g_oneshotlow_spin); - priv->callback = callback; - priv->arg = arg; - ret = intel64_oneshot_start(&priv->oneshot, - intel64_oneshot_handler, - priv, ts); + flags = spin_lock_irqsave(&g_oneshotlow_spin); + ret = intel64_oneshot_start(&priv->oneshot, intel64_oneshot_handler, + priv, ts); spin_unlock_irqrestore(&g_oneshotlow_spin, flags); if (ret < 0) @@ -272,10 +251,8 @@ static int intel64_cancel(struct oneshot_lowerhalf_s *lower, /* Cancel the timer */ - flags = spin_lock_irqsave(&g_oneshotlow_spin); - ret = intel64_oneshot_cancel(&priv->oneshot, ts); - priv->callback = NULL; - priv->arg = NULL; + flags = spin_lock_irqsave(&g_oneshotlow_spin); + ret = intel64_oneshot_cancel(&priv->oneshot, ts); spin_unlock_irqrestore(&g_oneshotlow_spin, flags); if (ret < 0) diff --git a/arch/xtensa/src/common/xtensa_oneshot.c b/arch/xtensa/src/common/xtensa_oneshot.c index 100500349e62e..4317070acf985 100644 --- a/arch/xtensa/src/common/xtensa_oneshot.c +++ b/arch/xtensa/src/common/xtensa_oneshot.c @@ -47,8 +47,6 @@ struct xoneshot_lowerhalf_s { struct oneshot_lowerhalf_s lh; /* Lower half operations */ uint32_t freq; /* Timer working clock frequency(Hz) */ - oneshot_callback_t callback; /* Current user interrupt callback */ - void *arg; /* Argument passed to upper half callback */ uint32_t irq; }; @@ -105,9 +103,6 @@ static int xtensa_oneshot_start(struct oneshot_lowerhalf_s *lower_, flags = enter_critical_section(); - lower->callback = callback; - lower->arg = arg; - count = sec_to_count((uint64_t)ts->tv_sec, lower->freq) + nsec_to_count((uint64_t)ts->tv_nsec, lower->freq); @@ -130,9 +125,6 @@ static int xtensa_oneshot_cancel(struct oneshot_lowerhalf_s *lower_, flags = enter_critical_section(); - lower->callback = NULL; - lower->arg = NULL; - up_disable_irq(lower->irq); leave_critical_section(flags); @@ -157,22 +149,10 @@ static int xtensa_oneshot_maxdelay(struct oneshot_lowerhalf_s *lower_, static int xtensa_oneshot_interrupt(int irq, void *context, void *arg) { struct xoneshot_lowerhalf_s *lower = arg; - oneshot_callback_t callback; - void *cbarg; DEBUGASSERT(lower != NULL); - if (lower->callback != NULL) - { - callback = lower->callback; - cbarg = lower->arg; - lower->callback = NULL; - lower->arg = NULL; - - /* Then perform the callback */ - - callback(&lower->lh, cbarg); - } + oneshot_process_callback(&lower->lh); return 0; } diff --git a/arch/xtensa/src/esp32/esp32_oneshot_lowerhalf.c b/arch/xtensa/src/esp32/esp32_oneshot_lowerhalf.c index b98f0758323e4..e9945d0d2e022 100644 --- a/arch/xtensa/src/esp32/esp32_oneshot_lowerhalf.c +++ b/arch/xtensa/src/esp32/esp32_oneshot_lowerhalf.c @@ -58,8 +58,6 @@ struct esp32_oneshot_lowerhalf_s struct oneshot_lowerhalf_s lh; /* Lower half instance */ struct esp32_oneshot_s oneshot; /* ESP32-specific oneshot state */ - oneshot_callback_t callback; /* Upper half Interrupt callback */ - void *arg; /* Argument passed to handler */ uint16_t resolution; /* Timer's resulation in uS */ spinlock_t lock; /* Device specific lock */ }; @@ -117,26 +115,12 @@ static void esp32_oneshot_lh_handler(void *arg) { struct esp32_oneshot_lowerhalf_s *priv = (struct esp32_oneshot_lowerhalf_s *)arg; - oneshot_callback_t callback; - void *cb_arg; DEBUGASSERT(priv != NULL); - DEBUGASSERT(priv->callback != NULL); tmrinfo("Oneshot LH handler triggered\n"); - /* Sample and nullify BEFORE executing callback (in case the callback - * restarts the oneshot). - */ - - callback = priv->callback; - cb_arg = priv->arg; - priv->callback = NULL; - priv->arg = NULL; - - /* Then perform the callback */ - - callback(&priv->lh, cb_arg); + oneshot_process_callback(&priv->lh); } /**************************************************************************** @@ -215,11 +199,9 @@ static int esp32_lh_start(struct oneshot_lowerhalf_s *lower, /* Save the callback information and start the timer */ - flags = spin_lock_irqsave(&priv->lock); - priv->callback = callback; - priv->arg = arg; - ret = esp32_oneshot_start(&priv->oneshot, - esp32_oneshot_lh_handler, priv, ts); + flags = spin_lock_irqsave(&priv->lock); + ret = esp32_oneshot_start(&priv->oneshot, + esp32_oneshot_lh_handler, priv, ts); spin_unlock_irqrestore(&priv->lock, flags); if (ret < 0) @@ -266,10 +248,8 @@ static int esp32_lh_cancel(struct oneshot_lowerhalf_s *lower, /* Cancel the timer */ - flags = spin_lock_irqsave(&priv->lock); - ret = esp32_oneshot_cancel(&priv->oneshot, ts); - priv->callback = NULL; - priv->arg = NULL; + flags = spin_lock_irqsave(&priv->lock); + ret = esp32_oneshot_cancel(&priv->oneshot, ts); spin_unlock_irqrestore(&priv->lock, flags); if (ret < 0) @@ -356,8 +336,6 @@ struct oneshot_lowerhalf_s *oneshot_initialize(int chan, } priv->lh.ops = &g_esp32_timer_ops; /* Pointer to the LH operations */ - priv->callback = NULL; /* No callback yet */ - priv->arg = NULL; /* No arg yet */ priv->resolution = resolution; /* Configured resolution */ /* Initialize esp32_oneshot_s structure */ diff --git a/arch/xtensa/src/esp32s2/esp32s2_oneshot_lowerhalf.c b/arch/xtensa/src/esp32s2/esp32s2_oneshot_lowerhalf.c index 0c1fe3929cf23..26083bbc62e8c 100644 --- a/arch/xtensa/src/esp32s2/esp32s2_oneshot_lowerhalf.c +++ b/arch/xtensa/src/esp32s2/esp32s2_oneshot_lowerhalf.c @@ -56,8 +56,6 @@ struct esp32s2_oneshot_lowerhalf_s struct oneshot_lowerhalf_s lh; /* Lower half instance */ struct esp32s2_oneshot_s oneshot; /* ESP32-S2-specific oneshot state */ - oneshot_callback_t callback; /* Upper half Interrupt callback */ - void *arg; /* Argument passed to handler */ uint16_t resolution; }; @@ -114,11 +112,8 @@ static void esp32s2_oneshot_lh_handler(void *arg) { struct esp32s2_oneshot_lowerhalf_s *priv = (struct esp32s2_oneshot_lowerhalf_s *)arg; - oneshot_callback_t callback; - void *cb_arg; DEBUGASSERT(priv != NULL); - DEBUGASSERT(priv->callback != NULL); tmrinfo("Oneshot LH handler triggered\n"); @@ -126,14 +121,7 @@ static void esp32s2_oneshot_lh_handler(void *arg) * restarts the oneshot). */ - callback = priv->callback; - cb_arg = priv->arg; - priv->callback = NULL; - priv->arg = NULL; - - /* Then perform the callback */ - - callback(&priv->lh, cb_arg); + oneshot_process_callback(&priv->lh); } /**************************************************************************** @@ -213,13 +201,9 @@ static int oneshot_lh_start(struct oneshot_lowerhalf_s *lower, /* Save the callback information and start the timer */ - flags = enter_critical_section(); - priv->callback = callback; - priv->arg = arg; - ret = esp32s2_oneshot_start(&priv->oneshot, - esp32s2_oneshot_lh_handler, - priv, - ts); + flags = enter_critical_section(); + ret = esp32s2_oneshot_start(&priv->oneshot, esp32s2_oneshot_lh_handler, + priv, ts); leave_critical_section(flags); if (ret < 0) @@ -266,10 +250,8 @@ static int oneshot_lh_cancel(struct oneshot_lowerhalf_s *lower, /* Cancel the timer */ - flags = enter_critical_section(); - ret = esp32s2_oneshot_cancel(&priv->oneshot, ts); - priv->callback = NULL; - priv->arg = NULL; + flags = enter_critical_section(); + ret = esp32s2_oneshot_cancel(&priv->oneshot, ts); leave_critical_section(flags); if (ret < 0) @@ -356,8 +338,6 @@ struct oneshot_lowerhalf_s *oneshot_initialize(int chan, } priv->lh.ops = &g_esp32s2_timer_ops; /* Pointer to the LH operations */ - priv->callback = NULL; /* No callback yet */ - priv->arg = NULL; /* No arg yet */ priv->resolution = resolution; /* Configured resolution */ /* Initialize esp32s2_oneshot_s structure */ diff --git a/arch/xtensa/src/esp32s3/esp32s3_oneshot_lowerhalf.c b/arch/xtensa/src/esp32s3/esp32s3_oneshot_lowerhalf.c index af621f26f37d9..65e9992c6b8a6 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_oneshot_lowerhalf.c +++ b/arch/xtensa/src/esp32s3/esp32s3_oneshot_lowerhalf.c @@ -57,8 +57,6 @@ struct esp32s3_oneshot_lowerhalf_s struct oneshot_lowerhalf_s lh; /* Lower-half instance */ struct esp32s3_oneshot_s oneshot; /* ESP32-S3-specific oneshot state */ - oneshot_callback_t callback; /* Upper-half Interrupt callback */ - void *arg; /* Argument passed to handler */ uint16_t resolution; /* Timer's resolution in microseconds */ spinlock_t lock; /* Device-specific lock */ }; @@ -116,11 +114,8 @@ static void oneshot_lh_handler(void *arg) { struct esp32s3_oneshot_lowerhalf_s *priv = (struct esp32s3_oneshot_lowerhalf_s *)arg; - oneshot_callback_t callback; - void *cb_arg; DEBUGASSERT(priv != NULL); - DEBUGASSERT(priv->callback != NULL); tmrinfo("Oneshot LH handler triggered\n"); @@ -128,14 +123,7 @@ static void oneshot_lh_handler(void *arg) * restarts the oneshot). */ - callback = priv->callback; - cb_arg = priv->arg; - priv->callback = NULL; - priv->arg = NULL; - - /* Then perform the callback */ - - callback(&priv->lh, cb_arg); + oneshot_process_callback(&priv->lh); } /**************************************************************************** @@ -212,11 +200,9 @@ static int oneshot_lh_start(struct oneshot_lowerhalf_s *lower, /* Save the callback information and start the timer */ - flags = spin_lock_irqsave(&priv->lock); - priv->callback = callback; - priv->arg = arg; - ret = esp32s3_oneshot_start(&priv->oneshot, oneshot_lh_handler, - priv, ts); + flags = spin_lock_irqsave(&priv->lock); + ret = esp32s3_oneshot_start(&priv->oneshot, oneshot_lh_handler, + priv, ts); spin_unlock_irqrestore(&priv->lock, flags); if (ret < 0) @@ -263,10 +249,8 @@ static int oneshot_lh_cancel(struct oneshot_lowerhalf_s *lower, /* Cancel the timer */ - flags = spin_lock_irqsave(&priv->lock); - ret = esp32s3_oneshot_cancel(&priv->oneshot, ts); - priv->callback = NULL; - priv->arg = NULL; + flags = spin_lock_irqsave(&priv->lock); + ret = esp32s3_oneshot_cancel(&priv->oneshot, ts); spin_unlock_irqrestore(&priv->lock, flags); if (ret < 0) @@ -352,8 +336,6 @@ struct oneshot_lowerhalf_s *oneshot_initialize(int chan, uint16_t resolution) } priv->lh.ops = &g_esp32s3_timer_ops; /* Pointer to the LH operations */ - priv->callback = NULL; /* No callback yet */ - priv->arg = NULL; /* No arg yet */ priv->resolution = resolution; /* Configured resolution */ /* Initialize esp32s3_oneshot_s structure */ diff --git a/drivers/audio/tone.c b/drivers/audio/tone.c index 5465258d75ff5..dd4730d688d86 100644 --- a/drivers/audio/tone.c +++ b/drivers/audio/tone.c @@ -958,6 +958,9 @@ int tone_register(FAR const char *path, FAR struct pwm_lowerhalf_s *tone, upper->channel = (uint8_t)channel; #endif + upper->oneshot->callback = oneshot_callback; + upper->oneshot->arg = upper; + /* Register the PWM device */ audinfo("Registering %s\n", path); diff --git a/drivers/timers/arch_alarm.c b/drivers/timers/arch_alarm.c index fe37816c4f425..6a345ed2fd5c9 100644 --- a/drivers/timers/arch_alarm.c +++ b/drivers/timers/arch_alarm.c @@ -90,6 +90,9 @@ void up_alarm_set_lowerhalf(FAR struct oneshot_lowerhalf_s *lower) g_oneshot_lower = lower; + lower->callback = oneshot_callback; + lower->arg = lower; + #ifdef CONFIG_SCHED_TICKLESS ONESHOT_TICK_MAX_DELAY(g_oneshot_lower, &ticks); g_oneshot_maxticks = ticks < UINT32_MAX ? ticks : UINT32_MAX; diff --git a/drivers/timers/goldfish_timer.c b/drivers/timers/goldfish_timer.c index 05b2a8575e714..afd680c8fc5e5 100644 --- a/drivers/timers/goldfish_timer.c +++ b/drivers/timers/goldfish_timer.c @@ -64,8 +64,6 @@ struct goldfish_timer_lowerhalf_s { struct oneshot_lowerhalf_s lh; /* Lower half operations */ - oneshot_callback_t callback; /* Current user interrupt callback */ - FAR void *arg; /* Argument passed to upper half callback */ uintptr_t base; /* Base address of registers */ spinlock_t lock; /* Lock for interrupt handling */ }; @@ -126,9 +124,6 @@ static int goldfish_timer_start(FAR struct oneshot_lowerhalf_s *lower_, flags = spin_lock_irqsave(&lower->lock); - lower->callback = callback; - lower->arg = arg; - nsec = ts->tv_sec * 1000000000 + ts->tv_nsec; l32 = getreg32(lower->base + GOLDFISH_TIMER_TIME_LOW); h32 = getreg32(lower->base + GOLDFISH_TIMER_TIME_HIGH); @@ -154,9 +149,6 @@ static int goldfish_timer_cancel(FAR struct oneshot_lowerhalf_s *lower_, flags = spin_lock_irqsave(&lower->lock); - lower->callback = NULL; - lower->arg = NULL; - putreg32(0, lower->base + GOLDFISH_TIMER_IRQ_ENABLED); putreg32(1, lower->base + GOLDFISH_TIMER_CLEAR_ALARM); @@ -196,9 +188,7 @@ static int goldfish_timer_interrupt(int irq, FAR void *arg) { FAR struct goldfish_timer_lowerhalf_s *lower = arg; - oneshot_callback_t callback = NULL; irqstate_t flags; - void *cbarg; DEBUGASSERT(lower != NULL); @@ -207,22 +197,11 @@ static int goldfish_timer_interrupt(int irq, putreg32(1, lower->base + GOLDFISH_TIMER_CLEAR_ALARM); putreg32(1, lower->base + GOLDFISH_TIMER_CLEAR_INTERRUPT); - if (lower->callback != NULL) - { - callback = lower->callback; - cbarg = lower->arg; - lower->callback = NULL; - lower->arg = NULL; - } - spin_unlock_irqrestore(&lower->lock, flags); /* Then perform the callback */ - if (callback) - { - callback(&lower->lh, cbarg); - } + oneshot_process_callback(&lower->lh); return 0; } diff --git a/drivers/timers/oneshot.c b/drivers/timers/oneshot.c index 605baccf9f645..9b78a8573bde5 100644 --- a/drivers/timers/oneshot.c +++ b/drivers/timers/oneshot.c @@ -311,6 +311,10 @@ int oneshot_register(FAR const char *devname, /* Initialize the new oneshot timer driver instance */ priv->od_lower = lower; + + lower->callback = oneshot_callback; + lower->arg = lower; + nxmutex_init(&priv->od_lock); /* And register the oneshot timer driver */ diff --git a/drivers/timers/watchdog.c b/drivers/timers/watchdog.c index 0f964805e6824..9e87eaba3663d 100644 --- a/drivers/timers/watchdog.c +++ b/drivers/timers/watchdog.c @@ -848,6 +848,8 @@ FAR void *watchdog_register(FAR const char *path, } #if defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_ONESHOT) + upper->oneshot->callback = watchdog_automonitor_oneshot; + upper->oneshot->arg = upper; watchdog_automonitor_start(upper, oneshot); #elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER) watchdog_automonitor_start(upper, timer); diff --git a/include/nuttx/timers/oneshot.h b/include/nuttx/timers/oneshot.h index a9d09d8ed167b..e713a13f0e21b 100644 --- a/include/nuttx/timers/oneshot.h +++ b/include/nuttx/timers/oneshot.h @@ -231,6 +231,9 @@ struct oneshot_lowerhalf_s FAR const struct oneshot_operations_s *ops; + FAR oneshot_callback_t callback; + FAR void *arg; + /* Private lower half data may follow */ }; @@ -400,6 +403,15 @@ int oneshot_tick_current(FAR struct oneshot_lowerhalf_s *lower, return ret; } +static inline_function +void oneshot_process_callback(FAR struct oneshot_lowerhalf_s *lower) +{ + if (lower->callback) + { + lower->callback(lower, lower->arg); + } +} + /**************************************************************************** * Name: oneshot_initialize * diff --git a/sched/sched/sched_cpuload_oneshot.c b/sched/sched/sched_cpuload_oneshot.c index cb87fa97a8e46..78bafd8ea3c7a 100644 --- a/sched/sched/sched_cpuload_oneshot.c +++ b/sched/sched/sched_cpuload_oneshot.c @@ -328,6 +328,8 @@ void nxsched_oneshot_extclk(FAR struct oneshot_lowerhalf_s *lower) /* Then start the oneshot */ g_sched_oneshot.oneshot = lower; + lower->callback = nxsched_oneshot_callback; + lower->arg = NULL; nxsched_oneshot_start(); } #endif From b65997cce9e0445e9af9d0133af0009a0c6037a0 Mon Sep 17 00:00:00 2001 From: ouyangxiangzhen Date: Thu, 11 Sep 2025 16:19:44 +0800 Subject: [PATCH 5/6] timers/oneshot: Remove all callback and args. This commit remove all callback and args in the APIs. Signed-off-by: ouyangxiangzhen --- arch/arm/src/armv7-a/arm_timer.c | 2 -- arch/arm/src/armv7-r/arm_timer.c | 2 -- arch/arm/src/armv8-r/arm_timer.c | 3 +-- arch/arm/src/sam34/sam4cm_oneshot_lowerhalf.c | 4 +--- arch/arm/src/sama5/sam_oneshot_lowerhalf.c | 4 +--- arch/arm/src/samd5e5/sam_oneshot_lowerhalf.c | 4 +--- arch/arm/src/samv7/sam_oneshot_lowerhalf.c | 4 +--- arch/arm/src/stm32/stm32_oneshot_lowerhalf.c | 4 +--- arch/arm/src/stm32h7/stm32_oneshot_lowerhalf.c | 4 +--- arch/arm/src/stm32l4/stm32l4_oneshot_lowerhalf.c | 4 +--- arch/arm/src/stm32wb/stm32wb_oneshot_lowerhalf.c | 6 ++---- arch/arm64/src/common/arm64_arch_timer.c | 3 +-- .../mips/src/pic32mz/pic32mz_oneshot_lowerhalf.c | 4 +--- arch/risc-v/src/bl602/bl602_oneshot_lowerhalf.c | 6 +----- arch/risc-v/src/common/espressif/esp_oneshot.c | 15 +++------------ arch/risc-v/src/common/riscv_mtimer.c | 2 -- .../esp32c3-legacy/esp32c3_oneshot_lowerhalf.c | 6 ------ arch/sim/src/sim/sim_oneshot.c | 5 ++--- arch/sparc/src/bm3803/bm3803_oneshot_lowerhalf.c | 8 +++----- arch/tricore/src/common/tricore_systimer.c | 2 -- arch/x86_64/src/intel64/intel64_oneshot_lower.c | 12 ++++-------- arch/xtensa/src/common/xtensa_oneshot.c | 2 -- arch/xtensa/src/esp32/esp32_oneshot_lowerhalf.c | 5 ----- .../src/esp32s2/esp32s2_oneshot_lowerhalf.c | 6 ------ .../src/esp32s3/esp32s3_oneshot_lowerhalf.c | 5 ----- drivers/audio/tone.c | 8 ++++---- drivers/timers/arch_alarm.c | 7 +++---- drivers/timers/goldfish_timer.c | 4 ---- drivers/timers/oneshot.c | 3 +-- drivers/timers/watchdog.c | 4 ++-- include/nuttx/timers/oneshot.h | 16 ++++++---------- sched/sched/sched_cpuload_oneshot.c | 3 +-- 32 files changed, 42 insertions(+), 125 deletions(-) diff --git a/arch/arm/src/armv7-a/arm_timer.c b/arch/arm/src/armv7-a/arm_timer.c index f234acb584287..9d99152e3e1bc 100644 --- a/arch/arm/src/armv7-a/arm_timer.c +++ b/arch/arm/src/armv7-a/arm_timer.c @@ -76,7 +76,6 @@ struct arm_timer_lowerhalf_s static int arm_timer_maxdelay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int arm_timer_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts); static int arm_timer_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -168,7 +167,6 @@ static int arm_timer_maxdelay(struct oneshot_lowerhalf_s *lower_, } static int arm_timer_start(struct oneshot_lowerhalf_s *lower_, - oneshot_callback_t callback, void *arg, const struct timespec *ts) { struct arm_timer_lowerhalf_s *lower = diff --git a/arch/arm/src/armv7-r/arm_timer.c b/arch/arm/src/armv7-r/arm_timer.c index 62a69e7e3f44b..433c6a21fac98 100644 --- a/arch/arm/src/armv7-r/arm_timer.c +++ b/arch/arm/src/armv7-r/arm_timer.c @@ -75,7 +75,6 @@ struct arm_timer_lowerhalf_s static int arm_timer_maxdelay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int arm_timer_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts); static int arm_timer_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -161,7 +160,6 @@ static int arm_timer_maxdelay(struct oneshot_lowerhalf_s *lower_, } static int arm_timer_start(struct oneshot_lowerhalf_s *lower_, - oneshot_callback_t callback, void *arg, const struct timespec *ts) { struct arm_timer_lowerhalf_s *lower = diff --git a/arch/arm/src/armv8-r/arm_timer.c b/arch/arm/src/armv8-r/arm_timer.c index aacdd9b9e557a..79f4d752f55bd 100644 --- a/arch/arm/src/armv8-r/arm_timer.c +++ b/arch/arm/src/armv8-r/arm_timer.c @@ -243,7 +243,6 @@ static int arm_cancel(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int arm_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts) { uint64_t count; @@ -251,7 +250,7 @@ static int arm_start(struct oneshot_lowerhalf_s *lower, (struct arm_oneshot_lowerhalf_s *)lower; uint64_t freq = priv->frequency; - DEBUGASSERT(priv && callback && ts); + DEBUGASSERT(priv && ts); /* Set the timeout */ diff --git a/arch/arm/src/sam34/sam4cm_oneshot_lowerhalf.c b/arch/arm/src/sam34/sam4cm_oneshot_lowerhalf.c index be01d5578cbc5..78427367cd0b5 100644 --- a/arch/arm/src/sam34/sam4cm_oneshot_lowerhalf.c +++ b/arch/arm/src/sam34/sam4cm_oneshot_lowerhalf.c @@ -69,7 +69,6 @@ static void sam_oneshot_handler(void *arg); static int sam_max_delay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int sam_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts); static int sam_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -181,7 +180,6 @@ static int sam_max_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int sam_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts) { struct sam_oneshot_lowerhalf_s *priv = @@ -189,7 +187,7 @@ static int sam_start(struct oneshot_lowerhalf_s *lower, irqstate_t flags; int ret; - DEBUGASSERT(priv != NULL && callback != NULL && ts != NULL); + DEBUGASSERT(priv != NULL && ts != NULL); /* Save the callback information and start the timer */ diff --git a/arch/arm/src/sama5/sam_oneshot_lowerhalf.c b/arch/arm/src/sama5/sam_oneshot_lowerhalf.c index 735eaa0bdce4a..e937eb7d48f3c 100644 --- a/arch/arm/src/sama5/sam_oneshot_lowerhalf.c +++ b/arch/arm/src/sama5/sam_oneshot_lowerhalf.c @@ -71,7 +71,6 @@ static void sam_oneshot_handler(void *arg); static int sam_max_delay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int sam_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts); static int sam_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -183,7 +182,6 @@ static int sam_max_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int sam_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts) { struct sam_oneshot_lowerhalf_s *priv = @@ -191,7 +189,7 @@ static int sam_start(struct oneshot_lowerhalf_s *lower, irqstate_t flags; int ret; - DEBUGASSERT(priv != NULL && callback != NULL && ts != NULL); + DEBUGASSERT(priv != NULL && ts != NULL); /* Save the callback information and start the timer */ diff --git a/arch/arm/src/samd5e5/sam_oneshot_lowerhalf.c b/arch/arm/src/samd5e5/sam_oneshot_lowerhalf.c index e4c8f2cf6972c..8df89f6b5d980 100644 --- a/arch/arm/src/samd5e5/sam_oneshot_lowerhalf.c +++ b/arch/arm/src/samd5e5/sam_oneshot_lowerhalf.c @@ -69,7 +69,6 @@ static void sam_oneshot_handler(void *arg); static int sam_max_delay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int sam_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts); static int sam_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -181,7 +180,6 @@ static int sam_max_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int sam_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts) { struct sam_oneshot_lowerhalf_s *priv = @@ -189,7 +187,7 @@ static int sam_start(struct oneshot_lowerhalf_s *lower, irqstate_t flags; int ret; - DEBUGASSERT(priv != NULL && callback != NULL && ts != NULL); + DEBUGASSERT(priv != NULL && ts != NULL); /* Save the callback information and start the timer */ diff --git a/arch/arm/src/samv7/sam_oneshot_lowerhalf.c b/arch/arm/src/samv7/sam_oneshot_lowerhalf.c index 1822c3d27af55..60362290bedf3 100644 --- a/arch/arm/src/samv7/sam_oneshot_lowerhalf.c +++ b/arch/arm/src/samv7/sam_oneshot_lowerhalf.c @@ -69,7 +69,6 @@ static void sam_oneshot_handler(void *arg); static int sam_max_delay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int sam_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts); static int sam_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -181,7 +180,6 @@ static int sam_max_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int sam_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts) { struct sam_oneshot_lowerhalf_s *priv = @@ -189,7 +187,7 @@ static int sam_start(struct oneshot_lowerhalf_s *lower, irqstate_t flags; int ret; - DEBUGASSERT(priv != NULL && callback != NULL && ts != NULL); + DEBUGASSERT(priv != NULL && ts != NULL); /* Save the callback information and start the timer */ diff --git a/arch/arm/src/stm32/stm32_oneshot_lowerhalf.c b/arch/arm/src/stm32/stm32_oneshot_lowerhalf.c index 2d6a2c7e6fd93..a6afcd2a94414 100644 --- a/arch/arm/src/stm32/stm32_oneshot_lowerhalf.c +++ b/arch/arm/src/stm32/stm32_oneshot_lowerhalf.c @@ -68,7 +68,6 @@ static void stm32_oneshot_handler(void *arg); static int stm32_max_delay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int stm32_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts); static int stm32_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -180,7 +179,6 @@ static int stm32_max_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int stm32_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts) { struct stm32_oneshot_lowerhalf_s *priv = @@ -188,7 +186,7 @@ static int stm32_start(struct oneshot_lowerhalf_s *lower, irqstate_t flags; int ret; - DEBUGASSERT(priv != NULL && callback != NULL && ts != NULL); + DEBUGASSERT(priv != NULL && ts != NULL); /* Save the callback information and start the timer */ diff --git a/arch/arm/src/stm32h7/stm32_oneshot_lowerhalf.c b/arch/arm/src/stm32h7/stm32_oneshot_lowerhalf.c index 8f80f9bec491a..da8112d52ba6e 100644 --- a/arch/arm/src/stm32h7/stm32_oneshot_lowerhalf.c +++ b/arch/arm/src/stm32h7/stm32_oneshot_lowerhalf.c @@ -68,7 +68,6 @@ static void stm32_oneshot_handler(void *arg); static int stm32_max_delay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int stm32_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts); static int stm32_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -180,7 +179,6 @@ static int stm32_max_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int stm32_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts) { struct stm32_oneshot_lowerhalf_s *priv = @@ -188,7 +186,7 @@ static int stm32_start(struct oneshot_lowerhalf_s *lower, irqstate_t flags; int ret; - DEBUGASSERT(priv != NULL && callback != NULL && ts != NULL); + DEBUGASSERT(priv != NULL && ts != NULL); /* Save the callback information and start the timer */ diff --git a/arch/arm/src/stm32l4/stm32l4_oneshot_lowerhalf.c b/arch/arm/src/stm32l4/stm32l4_oneshot_lowerhalf.c index d217c341d5e6b..63d31d39f10a4 100644 --- a/arch/arm/src/stm32l4/stm32l4_oneshot_lowerhalf.c +++ b/arch/arm/src/stm32l4/stm32l4_oneshot_lowerhalf.c @@ -69,7 +69,6 @@ static void stm32l4_oneshot_handler(void *arg); static int stm32l4_max_delay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int stm32l4_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts); static int stm32l4_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -181,7 +180,6 @@ static int stm32l4_max_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int stm32l4_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts) { struct stm32l4_oneshot_lowerhalf_s *priv = @@ -189,7 +187,7 @@ static int stm32l4_start(struct oneshot_lowerhalf_s *lower, irqstate_t flags; int ret; - DEBUGASSERT(priv != NULL && callback != NULL && ts != NULL); + DEBUGASSERT(priv != NULL && ts != NULL); /* Save the callback information and start the timer */ diff --git a/arch/arm/src/stm32wb/stm32wb_oneshot_lowerhalf.c b/arch/arm/src/stm32wb/stm32wb_oneshot_lowerhalf.c index cae5981a8e640..b1d3bebdfcdd3 100644 --- a/arch/arm/src/stm32wb/stm32wb_oneshot_lowerhalf.c +++ b/arch/arm/src/stm32wb/stm32wb_oneshot_lowerhalf.c @@ -69,7 +69,6 @@ static void stm32wb_oneshot_handler(void *arg); static int stm32wb_max_delay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int stm32wb_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts); static int stm32wb_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -181,15 +180,14 @@ static int stm32wb_max_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int stm32wb_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, - const struct timespec *ts) + const struct timespec *ts) { struct stm32wb_oneshot_lowerhalf_s *priv = (struct stm32wb_oneshot_lowerhalf_s *)lower; irqstate_t flags; int ret; - DEBUGASSERT(priv != NULL && callback != NULL && ts != NULL); + DEBUGASSERT(priv != NULL && ts != NULL); /* Save the callback information and start the timer */ diff --git a/arch/arm64/src/common/arm64_arch_timer.c b/arch/arm64/src/common/arm64_arch_timer.c index 89aa274ca0cd0..5c1bd0d89a460 100644 --- a/arch/arm64/src/common/arm64_arch_timer.c +++ b/arch/arm64/src/common/arm64_arch_timer.c @@ -235,7 +235,6 @@ static int arm64_cancel(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int arm64_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts) { uint64_t count; @@ -243,7 +242,7 @@ static int arm64_start(struct oneshot_lowerhalf_s *lower, (struct arm64_oneshot_lowerhalf_s *)lower; uint64_t freq = priv->frequency; - DEBUGASSERT(priv && callback && ts); + DEBUGASSERT(priv && ts); priv->running = this_cpu(); diff --git a/arch/mips/src/pic32mz/pic32mz_oneshot_lowerhalf.c b/arch/mips/src/pic32mz/pic32mz_oneshot_lowerhalf.c index e63b78c034c89..8a7d8dd3a92a2 100644 --- a/arch/mips/src/pic32mz/pic32mz_oneshot_lowerhalf.c +++ b/arch/mips/src/pic32mz/pic32mz_oneshot_lowerhalf.c @@ -67,7 +67,6 @@ static void pic32mz_oneshot_handler(void *arg); static int pic32mz_max_delay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int pic32mz_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts); static int pic32mz_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -182,7 +181,6 @@ static int pic32mz_max_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int pic32mz_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts) { struct pic32mz_oneshot_lowerhalf_s *priv = @@ -190,7 +188,7 @@ static int pic32mz_start(struct oneshot_lowerhalf_s *lower, irqstate_t flags; int ret; - DEBUGASSERT(priv != NULL && callback != NULL && ts != NULL); + DEBUGASSERT(priv != NULL && ts != NULL); /* Save the callback information and start the timer */ diff --git a/arch/risc-v/src/bl602/bl602_oneshot_lowerhalf.c b/arch/risc-v/src/bl602/bl602_oneshot_lowerhalf.c index f77194ccad4cc..4e7ee8b8c2678 100644 --- a/arch/risc-v/src/bl602/bl602_oneshot_lowerhalf.c +++ b/arch/risc-v/src/bl602/bl602_oneshot_lowerhalf.c @@ -84,8 +84,6 @@ struct bl602_oneshot_lowerhalf_s static int bl602_max_delay(struct oneshot_lowerhalf_s *lower, struct timespec * ts); static int bl602_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, - void * arg, const struct timespec * ts); static int bl602_cancel(struct oneshot_lowerhalf_s *lower, struct timespec * ts); @@ -229,8 +227,6 @@ static int bl602_max_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int bl602_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, - void * arg, const struct timespec * ts) { struct bl602_oneshot_lowerhalf_s *priv = @@ -238,7 +234,7 @@ static int bl602_start(struct oneshot_lowerhalf_s *lower, irqstate_t flags; uint64_t usec; - DEBUGASSERT(priv != NULL && callback != NULL && ts != NULL); + DEBUGASSERT(priv != NULL && ts != NULL); if (priv->started == true) { diff --git a/arch/risc-v/src/common/espressif/esp_oneshot.c b/arch/risc-v/src/common/espressif/esp_oneshot.c index 732bd6b283ad7..75809226b32b4 100644 --- a/arch/risc-v/src/common/espressif/esp_oneshot.c +++ b/arch/risc-v/src/common/espressif/esp_oneshot.c @@ -97,8 +97,6 @@ static int esp_oneshot_isr(int irq, void *context, void *arg); static int esp_oneshot_maxdelay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int esp_oneshot_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, - void *arg, const struct timespec *ts); static int esp_oneshot_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -193,8 +191,6 @@ static int esp_oneshot_maxdelay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int esp_oneshot_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, - void *arg, const struct timespec *ts) { struct esp_oneshot_lowerhalf_s *priv = @@ -202,11 +198,9 @@ static int esp_oneshot_start(struct oneshot_lowerhalf_s *lower, uint64_t timeout_us; DEBUGASSERT(priv != NULL); - DEBUGASSERT(callback != NULL); DEBUGASSERT(ts != NULL); - tmrinfo("callback=%p arg=%p, ts=(%lu, %ld)\n", - callback, arg, (unsigned long)ts->tv_sec, ts->tv_nsec); + tmrinfo("ts=(%lu, %ld)\n", (unsigned long)ts->tv_sec, ts->tv_nsec); if (priv->running) { @@ -269,11 +263,8 @@ static int esp_oneshot_start(struct oneshot_lowerhalf_s *lower, /* Configure callback, in case a handler was provided before */ - if (priv->callback != NULL) - { - timer_ll_enable_intr(hal->dev, TIMER_LL_EVENT_ALARM(hal->timer_id), - true); - } + timer_ll_enable_intr(hal->dev, TIMER_LL_EVENT_ALARM(hal->timer_id), + true); /* Finally, start the timer */ diff --git a/arch/risc-v/src/common/riscv_mtimer.c b/arch/risc-v/src/common/riscv_mtimer.c index 23167a98658d9..4e1a632ad02e5 100644 --- a/arch/risc-v/src/common/riscv_mtimer.c +++ b/arch/risc-v/src/common/riscv_mtimer.c @@ -55,7 +55,6 @@ struct riscv_mtimer_lowerhalf_s static int riscv_mtimer_max_delay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int riscv_mtimer_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts); static int riscv_mtimer_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -137,7 +136,6 @@ static int riscv_mtimer_max_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int riscv_mtimer_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts) { struct riscv_mtimer_lowerhalf_s *priv = diff --git a/arch/risc-v/src/esp32c3-legacy/esp32c3_oneshot_lowerhalf.c b/arch/risc-v/src/esp32c3-legacy/esp32c3_oneshot_lowerhalf.c index dc5f2853b8baf..6a620fbd570b2 100644 --- a/arch/risc-v/src/esp32c3-legacy/esp32c3_oneshot_lowerhalf.c +++ b/arch/risc-v/src/esp32c3-legacy/esp32c3_oneshot_lowerhalf.c @@ -72,8 +72,6 @@ static void esp32c3_oneshot_lh_handler(void *arg); static int oneshot_lh_max_delay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int oneshot_lh_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, - void *arg, const struct timespec *ts); static int oneshot_lh_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -187,8 +185,6 @@ static int oneshot_lh_max_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int oneshot_lh_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, - void *arg, const struct timespec *ts) { struct esp32c3_oneshot_lowerhalf_s *priv = @@ -197,8 +193,6 @@ static int oneshot_lh_start(struct oneshot_lowerhalf_s *lower, irqstate_t flags; DEBUGASSERT(priv != NULL); - DEBUGASSERT(callback != NULL); - DEBUGASSERT(arg != NULL); DEBUGASSERT(ts != NULL); /* Save the callback information and start the timer */ diff --git a/arch/sim/src/sim/sim_oneshot.c b/arch/sim/src/sim/sim_oneshot.c index d9b0133cc2c73..02b787f853fb4 100644 --- a/arch/sim/src/sim/sim_oneshot.c +++ b/arch/sim/src/sim/sim_oneshot.c @@ -74,7 +74,6 @@ static void sim_process_tick(sq_entry_t *entry); static int sim_max_delay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int sim_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts); static int sim_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -290,14 +289,14 @@ static int sim_max_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int sim_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts) { struct sim_oneshot_lowerhalf_s *priv = (struct sim_oneshot_lowerhalf_s *)lower; + struct timespec current; irqstate_t flags; - DEBUGASSERT(priv != NULL && callback != NULL && ts != NULL); + DEBUGASSERT(priv != NULL && ts != NULL); flags = enter_critical_section(); diff --git a/arch/sparc/src/bm3803/bm3803_oneshot_lowerhalf.c b/arch/sparc/src/bm3803/bm3803_oneshot_lowerhalf.c index 16bbbffe04383..d3a7cb5ed5292 100644 --- a/arch/sparc/src/bm3803/bm3803_oneshot_lowerhalf.c +++ b/arch/sparc/src/bm3803/bm3803_oneshot_lowerhalf.c @@ -71,8 +71,7 @@ static void bm3803_oneshot_handler(void *arg); static int bm3803_max_delay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int bm3803_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, - const struct timespec *ts); + const struct timespec *ts); static int bm3803_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -183,15 +182,14 @@ static int bm3803_max_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int bm3803_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, - const struct timespec *ts) + const struct timespec *ts) { struct bm3803_oneshot_lowerhalf_s *priv = (struct bm3803_oneshot_lowerhalf_s *)lower; irqstate_t flags; int ret; - DEBUGASSERT(priv != NULL && callback != NULL && ts != NULL); + DEBUGASSERT(priv != NULL && ts != NULL); /* Save the callback information and start the timer */ diff --git a/arch/tricore/src/common/tricore_systimer.c b/arch/tricore/src/common/tricore_systimer.c index 6405cd8478b4f..7ac11436deea9 100644 --- a/arch/tricore/src/common/tricore_systimer.c +++ b/arch/tricore/src/common/tricore_systimer.c @@ -59,7 +59,6 @@ struct tricore_systimer_lowerhalf_s static int tricore_systimer_max_delay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int tricore_systimer_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts); static int tricore_systimer_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -168,7 +167,6 @@ static int tricore_systimer_max_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int tricore_systimer_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts) { struct tricore_systimer_lowerhalf_s *priv = diff --git a/arch/x86_64/src/intel64/intel64_oneshot_lower.c b/arch/x86_64/src/intel64/intel64_oneshot_lower.c index 126f7c5b6b873..d8c6dd9234598 100644 --- a/arch/x86_64/src/intel64/intel64_oneshot_lower.c +++ b/arch/x86_64/src/intel64/intel64_oneshot_lower.c @@ -60,16 +60,14 @@ static void intel64_oneshot_handler(void *arg); static int intel64_max_delay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int intel64_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, - const struct timespec *ts); + const struct timespec *ts); static int intel64_cancel(struct oneshot_lowerhalf_s *lower, - struct timespec *ts); + struct timespec *ts); static int intel64_current(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int intel64_tick_max_delay(struct oneshot_lowerhalf_s *lower, clock_t *ticks); static int intel64_tick_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, clock_t ticks); static int intel64_tick_cancel(struct oneshot_lowerhalf_s *lower, clock_t *ticks); @@ -190,7 +188,6 @@ static int intel64_max_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int intel64_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts) { struct intel64_oneshot_lowerhalf_s *priv = @@ -198,7 +195,7 @@ static int intel64_start(struct oneshot_lowerhalf_s *lower, irqstate_t flags; int ret; - DEBUGASSERT(priv != NULL && callback != NULL && ts != NULL); + DEBUGASSERT(priv != NULL && ts != NULL); /* Save the callback information and start the timer */ @@ -352,7 +349,6 @@ static int intel64_tick_max_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int intel64_tick_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, clock_t ticks) { struct timespec ts; @@ -361,7 +357,7 @@ static int intel64_tick_start(struct oneshot_lowerhalf_s *lower, clock_ticks2time(&ts, ticks); - return intel64_start(lower, callback, arg, &ts); + return intel64_start(lower, &ts); } /**************************************************************************** diff --git a/arch/xtensa/src/common/xtensa_oneshot.c b/arch/xtensa/src/common/xtensa_oneshot.c index 4317070acf985..c3bf1b151c833 100644 --- a/arch/xtensa/src/common/xtensa_oneshot.c +++ b/arch/xtensa/src/common/xtensa_oneshot.c @@ -57,7 +57,6 @@ struct xoneshot_lowerhalf_s static int xtensa_oneshot_maxdelay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int xtensa_oneshot_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, const struct timespec *ts); static int xtensa_oneshot_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -93,7 +92,6 @@ static inline uint64_t sec_to_count(uint32_t sec, uint32_t freq) } static int xtensa_oneshot_start(struct oneshot_lowerhalf_s *lower_, - oneshot_callback_t callback, void *arg, const struct timespec *ts) { struct xoneshot_lowerhalf_s *lower = diff --git a/arch/xtensa/src/esp32/esp32_oneshot_lowerhalf.c b/arch/xtensa/src/esp32/esp32_oneshot_lowerhalf.c index e9945d0d2e022..4adba56bf95ee 100644 --- a/arch/xtensa/src/esp32/esp32_oneshot_lowerhalf.c +++ b/arch/xtensa/src/esp32/esp32_oneshot_lowerhalf.c @@ -73,8 +73,6 @@ static void esp32_oneshot_lh_handler(void *arg); static int esp32_max_lh_delay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int esp32_lh_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, - void *arg, const struct timespec *ts); static int esp32_lh_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -184,8 +182,6 @@ static int esp32_max_lh_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int esp32_lh_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, - void *arg, const struct timespec *ts) { struct esp32_oneshot_lowerhalf_s *priv = @@ -194,7 +190,6 @@ static int esp32_lh_start(struct oneshot_lowerhalf_s *lower, irqstate_t flags; DEBUGASSERT(priv != NULL); - DEBUGASSERT(callback != NULL); DEBUGASSERT(ts != NULL); /* Save the callback information and start the timer */ diff --git a/arch/xtensa/src/esp32s2/esp32s2_oneshot_lowerhalf.c b/arch/xtensa/src/esp32s2/esp32s2_oneshot_lowerhalf.c index 26083bbc62e8c..3f52825dbfdef 100644 --- a/arch/xtensa/src/esp32s2/esp32s2_oneshot_lowerhalf.c +++ b/arch/xtensa/src/esp32s2/esp32s2_oneshot_lowerhalf.c @@ -70,8 +70,6 @@ static void esp32s2_oneshot_lh_handler(void *arg); static int oneshot_lh_max_delay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int oneshot_lh_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, - void *arg, const struct timespec *ts); static int oneshot_lh_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -185,8 +183,6 @@ static int oneshot_lh_max_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int oneshot_lh_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, - void *arg, const struct timespec *ts) { struct esp32s2_oneshot_lowerhalf_s *priv = @@ -195,8 +191,6 @@ static int oneshot_lh_start(struct oneshot_lowerhalf_s *lower, irqstate_t flags; DEBUGASSERT(priv != NULL); - DEBUGASSERT(callback != NULL); - DEBUGASSERT(arg != NULL); DEBUGASSERT(ts != NULL); /* Save the callback information and start the timer */ diff --git a/arch/xtensa/src/esp32s3/esp32s3_oneshot_lowerhalf.c b/arch/xtensa/src/esp32s3/esp32s3_oneshot_lowerhalf.c index 65e9992c6b8a6..53d4481ffe036 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_oneshot_lowerhalf.c +++ b/arch/xtensa/src/esp32s3/esp32s3_oneshot_lowerhalf.c @@ -72,8 +72,6 @@ static void oneshot_lh_handler(void *arg); static int oneshot_lh_max_delay(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int oneshot_lh_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, - void *arg, const struct timespec *ts); static int oneshot_lh_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); @@ -185,8 +183,6 @@ static int oneshot_lh_max_delay(struct oneshot_lowerhalf_s *lower, ****************************************************************************/ static int oneshot_lh_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, - void *arg, const struct timespec *ts) { struct esp32s3_oneshot_lowerhalf_s *priv = @@ -195,7 +191,6 @@ static int oneshot_lh_start(struct oneshot_lowerhalf_s *lower, irqstate_t flags; DEBUGASSERT(priv != NULL); - DEBUGASSERT(callback != NULL); DEBUGASSERT(ts != NULL); /* Save the callback information and start the timer */ diff --git a/drivers/audio/tone.c b/drivers/audio/tone.c index dd4730d688d86..93247fe57b354 100644 --- a/drivers/audio/tone.c +++ b/drivers/audio/tone.c @@ -390,7 +390,7 @@ static void next_note(FAR struct tone_upperhalf_s *upper) ts.tv_sec = (time_t) sec; ts.tv_nsec = (unsigned long)nsec; - ONESHOT_START(upper->oneshot, oneshot_callback, upper, &ts); + ONESHOT_START(upper->oneshot, &ts); g_silence_length = 0; return; @@ -524,7 +524,7 @@ static void next_note(FAR struct tone_upperhalf_s *upper) ts.tv_sec = (time_t) sec; ts.tv_nsec = (unsigned long)nsec; - ONESHOT_START(upper->oneshot, oneshot_callback, upper, &ts); + ONESHOT_START(upper->oneshot, &ts); return; /* Change tempo */ @@ -567,7 +567,7 @@ static void next_note(FAR struct tone_upperhalf_s *upper) ts.tv_sec = (time_t) sec; ts.tv_nsec = (unsigned long)nsec; - ONESHOT_START(upper->oneshot, oneshot_callback, upper, &ts); + ONESHOT_START(upper->oneshot, &ts); return; } @@ -651,7 +651,7 @@ static void next_note(FAR struct tone_upperhalf_s *upper) /* And arrange a callback when the note should stop */ - ONESHOT_START(upper->oneshot, oneshot_callback, upper, &ts); + ONESHOT_START(upper->oneshot, &ts); return; /* Tune looks bad (unexpected EOF, bad character, etc.) */ diff --git a/drivers/timers/arch_alarm.c b/drivers/timers/arch_alarm.c index 6a345ed2fd5c9..09adbdb45dae3 100644 --- a/drivers/timers/arch_alarm.c +++ b/drivers/timers/arch_alarm.c @@ -59,7 +59,7 @@ static void oneshot_callback(FAR struct oneshot_lowerhalf_s *lower, * atomically w. respect to a HW timer */ - ONESHOT_TICK_START(g_oneshot_lower, oneshot_callback, NULL, 1); + ONESHOT_TICK_START(g_oneshot_lower, 1); /* It is always an error if this progresses more than 1 tick at a time. * That would break any timer based on wdog; such timers might timeout @@ -98,7 +98,7 @@ void up_alarm_set_lowerhalf(FAR struct oneshot_lowerhalf_s *lower) g_oneshot_maxticks = ticks < UINT32_MAX ? ticks : UINT32_MAX; #else ONESHOT_TICK_CURRENT(g_oneshot_lower, &g_current_tick); - ONESHOT_TICK_START(g_oneshot_lower, oneshot_callback, NULL, 1); + ONESHOT_TICK_START(g_oneshot_lower, 1); #endif } @@ -272,8 +272,7 @@ int weak_function up_alarm_tick_start(clock_t ticks) delta = 0; } - ret = ONESHOT_TICK_START(g_oneshot_lower, oneshot_callback, - NULL, delta); + ret = ONESHOT_TICK_START(g_oneshot_lower, delta); } return ret; diff --git a/drivers/timers/goldfish_timer.c b/drivers/timers/goldfish_timer.c index afd680c8fc5e5..5e8d1a2d74601 100644 --- a/drivers/timers/goldfish_timer.c +++ b/drivers/timers/goldfish_timer.c @@ -75,8 +75,6 @@ struct goldfish_timer_lowerhalf_s static int goldfish_timer_maxdelay(FAR struct oneshot_lowerhalf_s *lower, FAR struct timespec *ts); static int goldfish_timer_start(FAR struct oneshot_lowerhalf_s *lower, - FAR oneshot_callback_t callback, - FAR void *arg, FAR const struct timespec *ts); static int goldfish_timer_cancel(FAR struct oneshot_lowerhalf_s *lower, FAR struct timespec *ts); @@ -109,8 +107,6 @@ static int goldfish_timer_maxdelay(FAR struct oneshot_lowerhalf_s *lower_, } static int goldfish_timer_start(FAR struct oneshot_lowerhalf_s *lower_, - FAR oneshot_callback_t callback, - FAR void *arg, FAR const struct timespec *ts) { FAR struct goldfish_timer_lowerhalf_s *lower = diff --git a/drivers/timers/oneshot.c b/drivers/timers/oneshot.c index 9b78a8573bde5..9c1204fa8c045 100644 --- a/drivers/timers/oneshot.c +++ b/drivers/timers/oneshot.c @@ -215,8 +215,7 @@ static int oneshot_ioctl(FAR struct file *filep, int cmd, unsigned long arg) /* Start the oneshot timer */ - ret = ONESHOT_START(priv->od_lower, oneshot_callback, priv, - &start->ts); + ret = ONESHOT_START(priv->od_lower, &start->ts); } break; diff --git a/drivers/timers/watchdog.c b/drivers/timers/watchdog.c index 9e87eaba3663d..7ec6d33c43223 100644 --- a/drivers/timers/watchdog.c +++ b/drivers/timers/watchdog.c @@ -187,7 +187,7 @@ watchdog_automonitor_oneshot(FAR struct oneshot_lowerhalf_s *oneshot, }; lower->ops->keepalive(lower); - ONESHOT_START(oneshot, watchdog_automonitor_oneshot, upper, &ts); + ONESHOT_START(oneshot, &ts); } } #elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER) @@ -275,7 +275,7 @@ watchdog_automonitor_start(FAR struct watchdog_upperhalf_s *upper) }; upper->oneshot = oneshot; - ONESHOT_START(oneshot, watchdog_automonitor_oneshot, upper, &ts); + ONESHOT_START(oneshot, &ts); #elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER) upper->timer = timer; timer->ops->setcallback(timer, watchdog_automonitor_timer, upper); diff --git a/include/nuttx/timers/oneshot.h b/include/nuttx/timers/oneshot.h index e713a13f0e21b..747d494ab73de 100644 --- a/include/nuttx/timers/oneshot.h +++ b/include/nuttx/timers/oneshot.h @@ -120,10 +120,10 @@ * ****************************************************************************/ -#define ONESHOT_START(l,h,a,t) \ - ((l)->ops->start ? (l)->ops->start(l,h,a,t) : oneshot_start(l,h,a,t)) -#define ONESHOT_TICK_START(l,h,a,t) \ - ((l)->ops->tick_start ? (l)->ops->tick_start(l,h,a,t) : oneshot_tick_start(l,h,a,t)) +#define ONESHOT_START(l,t) \ + ((l)->ops->start ? (l)->ops->start(l,t) : oneshot_start(l,t)) +#define ONESHOT_TICK_START(l,t) \ + ((l)->ops->tick_start ? (l)->ops->tick_start(l,t) : oneshot_tick_start(l,t)) /**************************************************************************** * Name: ONESHOT_CANCEL @@ -202,7 +202,6 @@ struct oneshot_operations_s CODE int (*max_delay)(FAR struct oneshot_lowerhalf_s *lower, FAR struct timespec *ts); CODE int (*start)(FAR struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, FAR void *arg, FAR const struct timespec *ts); CODE int (*cancel)(FAR struct oneshot_lowerhalf_s *lower, FAR struct timespec *ts); @@ -211,7 +210,6 @@ struct oneshot_operations_s CODE int (*tick_max_delay)(FAR struct oneshot_lowerhalf_s *lower, FAR clock_t *ticks); CODE int (*tick_start)(FAR struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, FAR void *arg, clock_t ticks); CODE int (*tick_cancel)(FAR struct oneshot_lowerhalf_s *lower, FAR clock_t *ticks); @@ -284,7 +282,6 @@ int oneshot_max_delay(FAR struct oneshot_lowerhalf_s *lower, static inline int oneshot_start(FAR struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, FAR void *arg, FAR const struct timespec *ts) { clock_t tick; @@ -295,7 +292,7 @@ int oneshot_start(FAR struct oneshot_lowerhalf_s *lower, } tick = clock_time2ticks(ts); - return lower->ops->tick_start(lower, callback, arg, tick); + return lower->ops->tick_start(lower, tick); } static inline @@ -353,7 +350,6 @@ int oneshot_tick_max_delay(FAR struct oneshot_lowerhalf_s *lower, static inline int oneshot_tick_start(FAR struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, FAR void *arg, clock_t ticks) { struct timespec ts; @@ -364,7 +360,7 @@ int oneshot_tick_start(FAR struct oneshot_lowerhalf_s *lower, } clock_ticks2time(&ts, ticks); - return lower->ops->start(lower, callback, arg, &ts); + return lower->ops->start(lower, &ts); } static inline diff --git a/sched/sched/sched_cpuload_oneshot.c b/sched/sched/sched_cpuload_oneshot.c index 78bafd8ea3c7a..608a14b74bd2a 100644 --- a/sched/sched/sched_cpuload_oneshot.c +++ b/sched/sched/sched_cpuload_oneshot.c @@ -199,8 +199,7 @@ static void nxsched_oneshot_start(void) ts.tv_sec = secs; ts.tv_nsec = 1000 * usecs; - DEBUGVERIFY(ONESHOT_START(g_sched_oneshot.oneshot, - nxsched_oneshot_callback, NULL, &ts)); + DEBUGVERIFY(ONESHOT_START(g_sched_oneshot.oneshot, &ts)); } /**************************************************************************** From 8619e90b2a564270fb9f44cb254464e2be9905ce Mon Sep 17 00:00:00 2001 From: ouyangxiangzhen Date: Tue, 29 Jul 2025 17:11:32 +0800 Subject: [PATCH 6/6] timers/oneshot: Remove oneshot tick API. This commit removed all oneshot tick API for new clkdev API. Signed-off-by: ouyangxiangzhen --- arch/tricore/src/common/tricore_systimer.c | 47 ------ .../src/intel64/intel64_oneshot_lower.c | 150 +----------------- include/nuttx/timers/oneshot.h | 106 ++----------- 3 files changed, 14 insertions(+), 289 deletions(-) diff --git a/arch/tricore/src/common/tricore_systimer.c b/arch/tricore/src/common/tricore_systimer.c index 7ac11436deea9..c3d574dc92efc 100644 --- a/arch/tricore/src/common/tricore_systimer.c +++ b/arch/tricore/src/common/tricore_systimer.c @@ -64,10 +64,6 @@ static int tricore_systimer_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int tricore_systimer_current(struct oneshot_lowerhalf_s *lower, struct timespec *ts); -static int -tricore_systimer_tick_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, - clock_t ticks); /**************************************************************************** * Private Data @@ -79,7 +75,6 @@ static const struct oneshot_operations_s g_tricore_systimer_ops = .start = tricore_systimer_start, .cancel = tricore_systimer_cancel, .current = tricore_systimer_current, - .tick_start = tricore_systimer_tick_start, }; static struct tricore_systimer_lowerhalf_s g_systimer_lower = @@ -270,48 +265,6 @@ static int tricore_systimer_current(struct oneshot_lowerhalf_s *lower, return 0; } -/**************************************************************************** - * Name: tricore_systimer_tick_start - * - * Description: - * Start the oneshot timer - * - * Input Parameters: - * lower An instance of the lower-half oneshot state structure. This - * structure must have been previously initialized via a call to - * oneshot_initialize(); - * handler The function to call when when the oneshot timer expires. - * arg An opaque argument that will accompany the callback. - * ticks Provides the duration of the one shot timer. - * - * Returned Value: - * Zero (OK) is returned on success; a negated errno value is returned - * on failure. - * - ****************************************************************************/ - -static int -tricore_systimer_tick_start(struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, void *arg, - clock_t ticks) -{ - struct tricore_systimer_lowerhalf_s *priv = - (struct tricore_systimer_lowerhalf_s *)lower; - uint64_t mtime = tricore_systimer_get_time(priv); - - priv->alarm = mtime + priv->freq * ticks / TICK_PER_SEC; - if (priv->alarm < mtime) - { - priv->alarm = UINT64_MAX; - } - - priv->callback = callback; - priv->arg = arg; - - tricore_systimer_set_timecmp(priv, priv->alarm); - return 0; -} - /**************************************************************************** * Name: tricore_systimer_interrupt * diff --git a/arch/x86_64/src/intel64/intel64_oneshot_lower.c b/arch/x86_64/src/intel64/intel64_oneshot_lower.c index d8c6dd9234598..bb8e55d23058d 100644 --- a/arch/x86_64/src/intel64/intel64_oneshot_lower.c +++ b/arch/x86_64/src/intel64/intel64_oneshot_lower.c @@ -65,14 +65,6 @@ static int intel64_cancel(struct oneshot_lowerhalf_s *lower, struct timespec *ts); static int intel64_current(struct oneshot_lowerhalf_s *lower, struct timespec *ts); -static int intel64_tick_max_delay(struct oneshot_lowerhalf_s *lower, - clock_t *ticks); -static int intel64_tick_start(struct oneshot_lowerhalf_s *lower, - clock_t ticks); -static int intel64_tick_cancel(struct oneshot_lowerhalf_s *lower, - clock_t *ticks); -static int intel64_tick_current(struct oneshot_lowerhalf_s *lower, - clock_t *ticks); /**************************************************************************** * Private Data @@ -85,11 +77,7 @@ static const struct oneshot_operations_s g_oneshot_ops = .max_delay = intel64_max_delay, .start = intel64_start, .cancel = intel64_cancel, - .current = intel64_current, - .tick_max_delay = intel64_tick_max_delay, - .tick_start = intel64_tick_start, - .tick_cancel = intel64_tick_cancel, - .tick_current = intel64_tick_current, + .current = intel64_current }; static spinlock_t g_oneshotlow_spin; @@ -295,142 +283,6 @@ static int intel64_current(struct oneshot_lowerhalf_s *lower, return OK; } -/**************************************************************************** - * Name: intel64_tick_max_delay - * - * Description: - * Determine the maximum delay of the one-shot timer (in microseconds) - * - * Input Parameters: - * lower An instance of the lower-half oneshot state structure. This - * structure must have been previously initialized via a call to - * oneshot_initialize(); - * ticks The location in which to return the maximum delay. - * - * Returned Value: - * Zero (OK) is returned on success; a negated errno value is returned - * on failure. - * - ****************************************************************************/ - -static int intel64_tick_max_delay(struct oneshot_lowerhalf_s *lower, - clock_t *ticks) -{ - struct timespec ts; - int ret; - - ret = intel64_max_delay(lower, &ts); - - /* Convert time to ticks */ - - *ticks = clock_time2ticks(&ts); - - return ret; -} - -/**************************************************************************** - * Name: intel64_tick_start - * - * Description: - * Start the oneshot timer - * - * Input Parameters: - * lower An instance of the lower-half oneshot state structure. This - * structure must have been previously initialized via a call to - * oneshot_initialize(); - * handler The function to call when when the oneshot timer expires. - * arg An opaque argument that will accompany the callback. - * ticks Provides the duration of the one shot timer. - * - * Returned Value: - * Zero (OK) is returned on success; a negated errno value is returned - * on failure. - * - ****************************************************************************/ - -static int intel64_tick_start(struct oneshot_lowerhalf_s *lower, - clock_t ticks) -{ - struct timespec ts; - - /* Convert ticks to time */ - - clock_ticks2time(&ts, ticks); - - return intel64_start(lower, &ts); -} - -/**************************************************************************** - * Name: intel64_tick_cancel - * - * Description: - * Cancel the oneshot timer and return the time remaining on the timer. - * - * NOTE: This function may execute at a high rate with no timer running (as - * when pre-emption is enabled and disabled). - * - * Input Parameters: - * lower Caller allocated instance of the oneshot state structure. This - * structure must have been previously initialized via a call to - * oneshot_initialize(); - * ticks The location in which to return the time remaining on the - * oneshot timer. - * - * Returned Value: - * Zero (OK) is returned on success. A call to up_timer_cancel() when - * the timer is not active should also return success; a negated errno - * value is returned on any failure. - * - ****************************************************************************/ - -static int intel64_tick_cancel(struct oneshot_lowerhalf_s *lower, - clock_t *ticks) -{ - struct timespec ts; - int ret; - - ret = intel64_cancel(lower, &ts); - - /* Convert time to ticks */ - - *ticks = clock_time2ticks(&ts); - - return ret; -} - -/**************************************************************************** - * Name: intel64_tick_current - * - * Description: - * Get the current time. - * - * Input Parameters: - * lower Caller allocated instance of the oneshot state structure. This - * structure must have been previously initialized via a call to - * oneshot_initialize(); - * ticks The location in which to return the current time. - * - * Returned Value: - * Zero (OK) is returned on success, a negated errno value is returned on - * any failure. - * - ****************************************************************************/ - -static int intel64_tick_current(struct oneshot_lowerhalf_s *lower, - clock_t *ticks) -{ - struct timespec ts; - int ret; - - ret = intel64_current(lower, &ts); - - /* Convert time to ticks */ - - *ticks = clock_time2ticks(&ts); - - return ret; -} - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/include/nuttx/timers/oneshot.h b/include/nuttx/timers/oneshot.h index 747d494ab73de..642bd138f202b 100644 --- a/include/nuttx/timers/oneshot.h +++ b/include/nuttx/timers/oneshot.h @@ -95,10 +95,8 @@ * ****************************************************************************/ -#define ONESHOT_MAX_DELAY(l,t) \ - ((l)->ops->max_delay ? (l)->ops->max_delay(l,t) : oneshot_max_delay(l,t)) -#define ONESHOT_TICK_MAX_DELAY(l,t) \ - ((l)->ops->tick_max_delay ? (l)->ops->tick_max_delay(l,t) : oneshot_tick_max_delay(l,t)) +#define ONESHOT_MAX_DELAY(l,t) (l)->ops->max_delay(l,t) +#define ONESHOT_TICK_MAX_DELAY(l,t) oneshot_tick_max_delay(l,t) /**************************************************************************** * Name: ONESHOT_START @@ -120,10 +118,8 @@ * ****************************************************************************/ -#define ONESHOT_START(l,t) \ - ((l)->ops->start ? (l)->ops->start(l,t) : oneshot_start(l,t)) -#define ONESHOT_TICK_START(l,t) \ - ((l)->ops->tick_start ? (l)->ops->tick_start(l,t) : oneshot_tick_start(l,t)) +#define ONESHOT_START(l,t) (l)->ops->start(l,t) +#define ONESHOT_TICK_START(l,t) oneshot_tick_start(l,t) /**************************************************************************** * Name: ONESHOT_CANCEL @@ -149,10 +145,8 @@ * ****************************************************************************/ -#define ONESHOT_CANCEL(l,t) \ - ((l)->ops->cancel ? (l)->ops->cancel(l,t) : oneshot_cancel(l,t)) -#define ONESHOT_TICK_CANCEL(l,t) \ - ((l)->ops->tick_cancel ? (l)->ops->tick_cancel(l,t) : oneshot_tick_cancel(l,t)) +#define ONESHOT_CANCEL(l,t) (l)->ops->cancel(l,t) +#define ONESHOT_TICK_CANCEL(l,t) oneshot_tick_cancel(l,t) /**************************************************************************** * Name: ONESHOT_CURRENT @@ -173,10 +167,8 @@ * ****************************************************************************/ -#define ONESHOT_CURRENT(l,t) \ - ((l)->ops->current ? (l)->ops->current(l,t) : oneshot_current(l,t)) -#define ONESHOT_TICK_CURRENT(l,t) \ - ((l)->ops->tick_current ? (l)->ops->tick_current(l,t) : oneshot_tick_current(l,t)) +#define ONESHOT_CURRENT(l,t) (l)->ops->current(l,t) +#define ONESHOT_TICK_CURRENT(l,t) oneshot_tick_current(l,t) /**************************************************************************** * Public Types @@ -207,14 +199,6 @@ struct oneshot_operations_s FAR struct timespec *ts); CODE int (*current)(FAR struct oneshot_lowerhalf_s *lower, FAR struct timespec *ts); - CODE int (*tick_max_delay)(FAR struct oneshot_lowerhalf_s *lower, - FAR clock_t *ticks); - CODE int (*tick_start)(FAR struct oneshot_lowerhalf_s *lower, - clock_t ticks); - CODE int (*tick_cancel)(FAR struct oneshot_lowerhalf_s *lower, - FAR clock_t *ticks); - CODE int (*tick_current)(FAR struct oneshot_lowerhalf_s *lower, - FAR clock_t *ticks); }; /* This structure describes the state of the oneshot timer lower-half @@ -260,77 +244,9 @@ extern "C" #endif /**************************************************************************** - * Public Function Prototypes + * Inline Functions ****************************************************************************/ -static inline -int oneshot_max_delay(FAR struct oneshot_lowerhalf_s *lower, - FAR struct timespec *ts) -{ - clock_t tick; - int ret; - - if (lower->ops->tick_max_delay == NULL) - { - return -ENOTSUP; - } - - ret = lower->ops->tick_max_delay(lower, &tick); - clock_ticks2time(ts, tick); - return ret; -} - -static inline -int oneshot_start(FAR struct oneshot_lowerhalf_s *lower, - FAR const struct timespec *ts) -{ - clock_t tick; - - if (lower->ops->tick_start == NULL) - { - return -ENOTSUP; - } - - tick = clock_time2ticks(ts); - return lower->ops->tick_start(lower, tick); -} - -static inline -int oneshot_cancel(FAR struct oneshot_lowerhalf_s *lower, - FAR struct timespec *ts) -{ - clock_t tick; - int ret; - - if (lower->ops->tick_cancel == NULL) - { - return -ENOTSUP; - } - - ret = lower->ops->tick_cancel(lower, &tick); - clock_ticks2time(ts, tick); - - return ret; -} - -static inline -int oneshot_current(FAR struct oneshot_lowerhalf_s *lower, - FAR struct timespec *ts) -{ - clock_t tick; - int ret; - - if (lower->ops->tick_current == NULL) - { - return -ENOTSUP; - } - - ret = lower->ops->tick_current(lower, &tick); - clock_ticks2time(ts, tick); - - return ret; -} - static inline int oneshot_tick_max_delay(FAR struct oneshot_lowerhalf_s *lower, FAR clock_t *ticks) @@ -408,6 +324,10 @@ void oneshot_process_callback(FAR struct oneshot_lowerhalf_s *lower) } } +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + /**************************************************************************** * Name: oneshot_initialize *