xiaoxiang781216 commented on code in PR #17489:
URL: https://github.com/apache/nuttx/pull/17489#discussion_r2617226512


##########
arch/tricore/src/common/tricore_systimer.c:
##########
@@ -323,3 +323,35 @@ tricore_systimer_initialize(volatile void *tbase, int irq, 
uint64_t freq)
 
   return (struct oneshot_lowerhalf_s *)priv;
 }
+
+int up_alarm_start(FAR const struct timespec *ts)

Review Comment:
   why need implement up_alarm_start manually, and not reuse arch_alarm?



##########
drivers/timers/arch_alarm.c:
##########


Review Comment:
   why not continue use nxsched_process_timer?



##########
Documentation/reference/os/time_clock.rst:
##########
@@ -657,3 +657,65 @@ with NuttX tasks.
     #else
     typedef uint32_t  wdparm_t;
     #endif
+
+High-resolution Timer Interfaces
+================================
+
+NuttX provides a high-resolution timer facility. This facility
+allows the NuttX user to specify a hrtimer function that
+will run after a specified delay in nanosec resolution. The hrtimer
+function will run in the context of the timer interrupt handler.
+Because of this, a limited number of NuttX interfaces are available to he
+hrtimer function. However, the hrtimer function may
+use ``mq_send()``, ``sigqueue()``, ``nxevent_post()``, or ``kill()``
+to communicate with NuttX tasks.
+
+- :c:func:`hrtimer_init`
+- :c:func:`hrtimer_cancel`
+- :c:func:`hrtimer_start`
+- High-resolution Timer Callback
+
+.. c:function:: void hrtimer_init(FAR hrtimer_t *hrtimer, hrtentry_t func, \
+                                  FAR void *arg)
+
+  This function initializes a high-resolution timer instance.
+  Sets the expiration callback and its argument. The timer is
+  not started by this function.
+
+  :param hrtimer: Pointer to hrtimer instance
+  :param func: Expiration callback function
+  :param arg: Callback argument
+
+  :return: None.
+
+  **POSIX Compatibility:** This is a NON-POSIX interface.
+
+.. c:function:: int hrtimer_cancel(FAR hrtimer_t *hrtimer)
+
+  This function cancels a high-resolution timer if it is pending.
+  The timer callback will not be called if the timer was successfully
+  canceled.
+
+  :param hrtimer: Timer instance to cancel
+
+  :return: ``OK`` on success; negated errno on failure.
+
+  **POSIX Compatibility:** This is a NON-POSIX interface.
+
+.. c:function:: int hrtimer_start(FAR hrtimer_t *hrtimer, uint64_t ns, \

Review Comment:
   where the test case for the new hrtimer api?



##########
sched/hrtimer/hrtimer_start.c:
##########
@@ -0,0 +1,135 @@
+/****************************************************************************
+ * sched/hrtimer/hrtimer_start.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/arch.h>
+#include <nuttx/clock.h>
+#include <errno.h>
+#include <hrtimer/hrtimer.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: hrtimer_insert
+ *
+ * Description:
+ *   Insert the given high-resolution timer into the active timer RB-tree.
+ *   If the timer already exists, it will be removed and re-inserted.
+ *   If the inserted timer is the earliest in the tree, start the hardware
+ *   timer to fire at its expiration.
+ *
+ * Input Parameters:
+ *   hrtimer - Pointer to the hrtimer structure to be inserted.
+ *
+ * Returned Value:
+ *   OK (0) on success, or a negated errno value on failure.
+ *
+ * Assumptions/Notes:
+ *   - This function should be called with interrupts disabled or under
+ *     spinlock protection to ensure RB-tree integrity.
+ *   - Inline function for performance in critical path.
+ ****************************************************************************/
+
+static inline_function
+int hrtimer_insert(FAR hrtimer_t *hrtimer)
+{
+  int ret = OK;
+  FAR struct hrtimer_node_s *inserted =
+    RB_INSERT(hrtimer_tree_s, &g_activetree, &hrtimer->node);
+
+  if (inserted == NULL)
+    {
+      if (&hrtimer->node == RB_MIN(hrtimer_tree_s, &g_activetree))
+        {
+          /* If new timer is the earliest, start hardware timer */
+
+          ret = hrtimer_starttimer(hrtimer->expired);

Review Comment:
   should reuse nxsched_reassess_timer to program the hardware timer



-- 
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]

Reply via email to