xiaoxiang781216 commented on code in PR #17065:
URL: https://github.com/apache/nuttx/pull/17065#discussion_r2375039327
##########
arch/tricore/src/common/tricore_systimer.c:
##########
@@ -321,6 +339,50 @@ tricore_systimer_tick_start(struct oneshot_lowerhalf_s
*lower,
return 0;
}
+#ifdef CONFIG_HRTIMER
+static int
+tricore_hrtimer_setexpire(struct oneshot_lowerhalf_s *lower,
+ clock_t expiration_time)
+{
+ (void)lower;
+
+ struct tricore_systimer_lowerhalf_s *priv = &g_systimer_lower;
Review Comment:
why not cast lower
##########
sched/Kconfig:
##########
@@ -2034,3 +2034,21 @@ config CUSTOM_SEMAPHORE_MAXVALUE
---help---
Enable to support custom max value for semaphores.
When this option is enabled, the max value of a semaphore can
be set
+
+config HRTIMER
+ bool "High-resolution timer (hrtimer) support"
+ depends on ALARM_ARCH
+ default n
+ ---help---
+ Enable high-resolution timers (hrtimers) for precise time-based
+ operations within the system.
+
+if HRTIMER
+config HRTIMER_ONESHOT_QUEUE_SIZE
+ int "Size of oneshot hrtimer queue"
+ default 64
Review Comment:
why not hrtimter without the number config
##########
arch/tricore/src/common/tricore_systimer.c:
##########
@@ -321,6 +339,50 @@ tricore_systimer_tick_start(struct oneshot_lowerhalf_s
*lower,
return 0;
}
+#ifdef CONFIG_HRTIMER
+static int
+tricore_hrtimer_setexpire(struct oneshot_lowerhalf_s *lower,
+ clock_t expiration_time)
+{
+ (void)lower;
+
+ struct tricore_systimer_lowerhalf_s *priv = &g_systimer_lower;
+
+ IfxStm_updateCompare(priv->tbase, IfxStm_Comparator_0, expiration_time);
+
+ return OK;
+}
+
+static clock_t
+tricore_hrtimer_current(struct oneshot_lowerhalf_s *lower)
+{
+ (void)lower;
+
+ struct tricore_systimer_lowerhalf_s *priv = &g_systimer_lower;
Review Comment:
ditto
##########
include/nuttx/hrtimer.h:
##########
@@ -0,0 +1,457 @@
+/****************************************************************************
+ * include/nuttx/hrtimer.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_TIMERS_HRTIMER_H
+#define __INCLUDE_NUTTX_TIMERS_HRTIMER_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/clock.h>
+#include <nuttx/spinlock.h>
+#include <nuttx/timers/oneshot.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Select tick type (32-bit or 64-bit) based on configuration */
+
+#ifdef CONFIG_SYSTEM_TIME64
+# define HRTIMER_MAX_VALUE UINT64_MAX
+#else
+# define HRTIMER_MAX_VALUE UINT32_MAX
+#endif
+
+/* The maximum increment that can be safely distinguished without overflow */
+
+#define HRTIMER_MAX_INCREMENT (HRTIMER_MAX_VALUE >> 1)
+
+/* Default expiration increment if no timer is active */
+
+#define HRTIMER_DEFAULT_INCREMENT ((clock_t)UINT32_MAX >> 2)
+
+/* Convert microseconds/nanoseconds to hardware timer ticks */
+
+#define HRTIMER_QUEUE_USEC2TICKS(queue, us) \
+ (((clock_t)(us)) * ((queue)->lower->freq) / USEC_PER_SEC)
+
+#define HRTIMER_QUEUE_NSEC2TICKS(queue, ns) \
+ (((clock_t)(ns)) * ((queue)->lower->freq) / NSEC_PER_SEC)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Timer mode: absolute or relative */
+
+enum hrtimer_mode
+{
+ HRTIMER_MODE_ABS = 0x0, /* Absolute expiration time */
+ HRTIMER_MODE_REL = 0x1 /* Relative delay from now */
+};
+
+/* Forward declarations */
+
+struct hrtimer_s;
+struct hrtimer_queue_s;
+
+/* Callback type for high-resolution timer expiration */
+
+typedef void (*hrtimer_callback_t)(FAR struct hrtimer_s *);
+
+/* Hardware-specific timer operations. These must be provided by the
+ * underlying architecture/platform lower. They define how to set the
+ * expiration, read current time, start and trigger the hardware timer.
+ */
+
+/* High-resolution timer instance */
+
+struct hrtimer_s
+{
+ clock_t expiration_time; /* Expiration tick */
+ FAR struct hrtimer_queue_s *queue; /* Associated timer queue */
+ hrtimer_callback_t callback; /* Expiration callback */
+ FAR void *args; /* Optional callback argument */
+};
+
+/* Timer queue implemented as a min-heap */
+
+struct hrtimer_queue_s
+{
+ FAR struct hrtimer_s **heap; /* Heap of active timers */
+ FAR struct oneshot_lowerhalf_s *lower; /* Oneshot lower */
Review Comment:
hrtimer should design like wdog to call up_alarm/up_timer api, not
oneshot_lowerhalf api
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]