xiaoxiang781216 commented on code in PR #17065:
URL: https://github.com/apache/nuttx/pull/17065#discussion_r2374542214
##########
arch/tricore/src/common/tricore_systimer.c:
##########
@@ -332,17 +332,83 @@ tricore_systimer_tick_start(struct oneshot_lowerhalf_s
*lower,
static int tricore_systimer_interrupt(int irq, void *context, void *arg)
{
+#ifdef CONFIG_HRTIMER
+ (void)irq;
+ (void)context;
+ (void)arg;
+
+ hrtimer_queue_process(&g_hrtimer_oneshot_queue);
+#else
struct tricore_systimer_lowerhalf_s *priv = arg;
tricore_systimer_set_timecmp(priv, UINT64_MAX);
if (priv->callback != NULL)
{
priv->callback(&priv->lower, priv->arg);
}
+#endif
return 0;
}
+#ifdef CONFIG_HRTIMER
+static int
+tricore_hrtimer_set_expire(FAR const struct hrtimer_driver_s *driver,
+ hrtimer_time_t expiration_time)
+{
+ (void)driver;
+
+ struct tricore_systimer_lowerhalf_s *priv = &g_systimer_lower;
+
+ IfxStm_updateCompare(priv->tbase, IfxStm_Comparator_0, expiration_time);
+
+ return OK;
+}
+
+static hrtimer_time_t
+tricore_hrtimer_current(FAR const struct hrtimer_driver_s *driver)
+{
+ (void)driver;
+
+ struct tricore_systimer_lowerhalf_s *priv = &g_systimer_lower;
+
+ return IfxStm_get(priv->tbase);
+}
+
+static int tricore_hrtimer_start(FAR const struct hrtimer_driver_s *driver)
+{
+ (void)driver;
+
+ up_enable_irq(192);
+
+ return OK;
+}
+
+static int tricore_hrtimer_trigger(FAR const struct hrtimer_driver_s *driver)
+{
+ (void)driver;
+
+ up_trigger_irq(192, 0);
+
+ return OK;
+}
+
+static const struct hrtimer_driver_ops_s g_hrtimer_driver_ops =
+{
+ .set_expire = tricore_hrtimer_set_expire,
+ .current = tricore_hrtimer_current,
+ .start = tricore_hrtimer_start,
+ .trigger = tricore_hrtimer_trigger,
+};
+
+static struct hrtimer_driver_s g_hrtimer_driver =
Review Comment:
why not reuse up_alarm_/up_timer_ interface, and oneshot/timer driver model,
but add new hrtimer_driver_s?
##########
arch/tricore/src/common/tricore_systimer.c:
##########
@@ -376,7 +443,13 @@ tricore_systimer_initialize(volatile void *tbase, int irq,
uint64_t freq)
IfxStm_enableComparatorInterrupt(tbase, IfxStm_Comparator_0);
irq_attach(irq, tricore_systimer_interrupt, priv);
- up_enable_irq(irq);
- return (struct oneshot_lowerhalf_s *)priv;
+ up_alarm_set_lowerhalf((struct oneshot_lowerhalf_s *)priv);
Review Comment:
line 347 is skipped when CONFIG_HRTIMER equal y, how OS activity get
scheduled?
##########
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 ONESHOT
Review Comment:
hrtimer should call up_alarm_/up_timer_ api, not ONESHOT directly
##########
include/nuttx/hrtimer.h:
##########
@@ -0,0 +1,475 @@
+/****************************************************************************
+ * 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>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Select tick type (32-bit or 64-bit) based on configuration */
+
+typedef clock_t hrtimer_time_t;
+
+#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 ((hrtimer_time_t)UINT32_MAX >> 2)
+
+/* Convert microseconds/nanoseconds to hardware timer ticks */
+
+#define HRTIMER_QUEUE_USEC2TICKS(queue, us) \
+ (((hrtimer_time_t)(us)) * ((queue)->driver->freq) / USEC_PER_SEC)
+
+#define HRTIMER_QUEUE_NSEC2TICKS(queue, ns) \
+ (((hrtimer_time_t)(ns)) * ((queue)->driver->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 driver. They define how to set the
+ * expiration, read current time, start and trigger the hardware timer.
+ */
+
+struct hrtimer_driver_ops_s
Review Comment:
we should reuse oneshot or timer drive model, instead creating new one
--
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]