diff --git a/include/nuttx/hrtimer.h b/include/nuttx/hrtimer.h index 0bf3cc90996ba..e6c617b6b2937 100644 --- a/include/nuttx/hrtimer.h +++ b/include/nuttx/hrtimer.h @@ -65,8 +65,8 @@ typedef struct hrtimer_node_s hrtimer_node_t; * timer context and must not block. */ -typedef CODE uint64_t -(*hrtimer_cb)(FAR hrtimer_t *hrtimer, uint64_t expired); +typedef CODE uint64_t (*hrtimer_entry_t)(FAR const hrtimer_t *hrtimer, + uint64_t expired); /* Red-black tree node used to order hrtimers by expiration time */ @@ -85,7 +85,7 @@ struct hrtimer_node_s struct hrtimer_s { hrtimer_node_t node; /* RB-tree node for sorted insertion */ - hrtimer_cb func; /* Expiration callback function */ + hrtimer_entry_t func; /* Expiration callback function */ uint64_t expired; /* Absolute expiration time (ns) */ }; diff --git a/sched/Kconfig b/sched/Kconfig index 17892ad4b88f6..d1a1e07c3fbf3 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -2007,5 +2007,6 @@ config CUSTOM_SEMAPHORE_MAXVALUE config HRTIMER bool "High resolution timer support" default n + depends on SYSTEM_TIME64 ---help--- Enable to support high resolution timer diff --git a/sched/Makefile b/sched/Makefile index 92989e81253ad..2d743dfd3bb04 100644 --- a/sched/Makefile +++ b/sched/Makefile @@ -43,6 +43,7 @@ include timer/Make.defs include tls/Make.defs include wdog/Make.defs include wqueue/Make.defs +include hrtimer/Make.defs CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)sched diff --git a/sched/hrtimer/hrtimer_cancel.c b/sched/hrtimer/hrtimer_cancel.c index 27e53f0725fea..c27c2a3a4123d 100644 --- a/sched/hrtimer/hrtimer_cancel.c +++ b/sched/hrtimer/hrtimer_cancel.c @@ -131,9 +131,11 @@ int hrtimer_cancel(FAR hrtimer_t *hrtimer) hrtimer_remove(hrtimer); } - /* Mark timer as cancelled */ + /* If the timer was running, increment its expiration count to prevent + * it from being re-armed by the callback. + */ - hrtimer->expired = UINT64_MAX; + hrtimer->expired++; /* If the canceled timer was the earliest one, update the hardware timer */ diff --git a/sched/hrtimer/hrtimer_process.c b/sched/hrtimer/hrtimer_process.c index d5b9183e1ec3e..d9a915d2a6f58 100644 --- a/sched/hrtimer/hrtimer_process.c +++ b/sched/hrtimer/hrtimer_process.c @@ -71,7 +71,7 @@ void hrtimer_process(uint64_t now) { FAR hrtimer_t *hrtimer; irqstate_t flags; - hrtimer_cb func; + hrtimer_entry_t func; uint64_t expired; uint64_t period; int cpu = this_cpu();