You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by je...@apache.org on 2025/11/18 12:02:39 UTC
(nuttx) 04/06: timers/oneshot: Remove all private callback.
This is an automated email from the ASF dual-hosted git repository.
jerpelea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 5c113f79b78a47df3343ce08c591683eef69e61f
Author: ouyangxiangzhen <ou...@xiaomi.com>
AuthorDate: Wed Sep 10 15:33:27 2025 +0800
timers/oneshot: Remove all private callback.
This commit removed all private callback and handle it on the upperhalf
of oneshot.
Signed-off-by: ouyangxiangzhen <ou...@xiaomi.com>
---
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 ++++-----------------
arch/arm/src/stm32h7/stm32_oneshot_lowerhalf.c | 34 ++++-----------------
arch/arm/src/stm32l4/stm32l4_oneshot_lowerhalf.c | 34 ++++-----------------
arch/arm/src/stm32wb/stm32wb_oneshot_lowerhalf.c | 34 ++++-----------------
arch/arm64/src/common/arm64_arch_timer.c | 11 ++-----
arch/mips/src/pic32mz/pic32mz_oneshot_lowerhalf.c | 35 ++++------------------
arch/risc-v/src/bl602/bl602_oneshot_lowerhalf.c | 19 ++----------
arch/risc-v/src/common/espressif/esp_oneshot.c | 26 ++--------------
arch/risc-v/src/common/riscv_mtimer.c | 15 ++--------
.../src/esp32c3-legacy/esp32c3_oneshot_lowerhalf.c | 32 ++++----------------
arch/sim/src/sim/sim_oneshot.c | 35 ++++++----------------
arch/sparc/src/bm3803/bm3803_oneshot_lowerhalf.c | 34 ++++-----------------
arch/tricore/src/common/tricore_systimer.c | 14 ++-------
arch/x86_64/src/intel64/intel64_oneshot_lower.c | 35 ++++------------------
arch/xtensa/src/common/xtensa_oneshot.c | 22 +-------------
arch/xtensa/src/esp32/esp32_oneshot_lowerhalf.c | 34 ++++-----------------
.../xtensa/src/esp32s2/esp32s2_oneshot_lowerhalf.c | 32 ++++----------------
.../xtensa/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 81da492a9b6..f234acb5842 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 c97f3b7ec7b..62a69e7e3f4 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 f3119912d75..aacdd9b9e55 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 7b63804f9ce..be01d5578cb 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 6ce17a5b054..735eaa0bdce 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 c41675769b1..e4c8f2cf697 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 dc736a3ee54..1822c3d27af 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 f0b6d2ccf95..2d6a2c7e6fd 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 545f4ebdcf3..8f80f9bec49 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 61e75d04ffa..d217c341d5e 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 2df58ee753d..cae5981a8e6 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 b487221e205..89aa274ca0c 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 da88ae9ee7e..e63b78c034c 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 53d49c2c1d0..f77194ccad4 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 909ca0ee678..732bd6b283a 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 4a8946b770b..23167a98658 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 817cedbd70a..dc5f2853b8b 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 96e85941699..d9b0133cc2c 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 5f1bd1f3118..16bbbffe043 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 70ad40629cf..6405cd8478b 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 f82aace3e98..126f7c5b6b8 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 100500349e6..4317070acf9 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 b98f0758323..e9945d0d2e0 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 0c1fe3929cf..26083bbc62e 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 af621f26f37..65e9992c6b8 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 5465258d75f..dd4730d688d 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 fe37816c4f4..6a345ed2fd5 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 05b2a8575e7..afd680c8fc5 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 605baccf9f6..9b78a8573bd 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 0f964805e68..9e87eaba366 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 a9d09d8ed16..e713a13f0e2 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 cb87fa97a8e..78bafd8ea3c 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