wangchdo opened a new pull request, #17065:
URL: https://github.com/apache/nuttx/pull/17065

                 
     Add a high resolution timer module in sched
     to support hard real time cases
   
   *Note: Please adhere to [Contributing 
Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).*
   
   ## Summary
   
   Nuttx only provide wdog for delayed function execution, wdog is mainly used 
for OS-internal timeouts (e.g., task scheduling, time slicing) and periodic 
callbacks. Resolution depends on system tick.
   
   This PR introduces hrtimer to Nuttx acting as a high-resolution timer, it 
can deliver deliver precise timing events (nanosecond or microsecond accuracy).
   
   **Aspect              | NuttX hrtimer                                        
| NuttX wdog
   
--------------------+---------------------------------------------------------------------+---------
   Purpose              | High-resolution timer                             | 
Lightweight software timer
                              | for precise event scheduling.                  
| for delayed callbacks and OS timeouts.
   
   
   Resolution          | Nanosecond / microsecond accuracy,    | tick-based (ms 
level)
                              | independent of system tick.                   |
   
   Accuracy            | Very high, suitable for                             | 
Limited by system tick;
                             | hard real-time and                               
   | not sufficient for hard real-time control.
                             | multimedia workloads.
   
   
   Implementation      | min-queue tree for timers.                 | Linked 
list of timers, sorted by expiration,
                                   | sorted by expiration,                      
    | integrated into scheduler.
   
   
   Usage Pattern       | Create `hrtimer_int()`,                           | 
Allocate `wdog_t`,
                                | start with `hrtimer_start()`,                 
   | start with `wd_start()`,
                                | cancel with `hrtimer_cancel()`.              
| cancel with `wd_cancel()`.
   
   
   Callback Context    | Runs in interrupt                                | 
Runs in interrupt context
                                 | context                                      
          |(scheduler tick or hrtimer).
   
   
   Use Cases           | Precise scheduling,                                | 
Task time slicing,
                              | hard RT tasks, multimedia,                     
| timeout handling,
                              | networking,                                     
       | simple periodic events.
                              | low-latency wake-ups.
   
   Complexity          | A little Complex                                     | 
 Simple and lightweight;
                              | but optimized for embedded RTOS,
                              | no rb-tree, but use priority-queue
   
   Footprint           | Larger memory and CPU overhead.        | Minimal 
memory and CPU usage.**
   
   
   ## Impact
   
   A new module added in sched, 
   
   **if it is enabled:**
   1. new functions will be introduced, hrtimer_init(), hrtimer_start(), 
hrtimer_cancel()
   2. wdog will be driven by hrtimer as a timer
   
   **if it is not enabled:**
   nothing happen
   
   ## Testing
   
   **enable** hrtimer in a2g-tc397-5v-tft:
   
   <img width="699" height="529" alt="image" 
src="https://github.com/user-attachments/assets/d5a88118-e8a0-4c57-98e3-1fb920deb45f";
 />
   
   **ostest passed**
   
   <img width="649" height="714" alt="image" 
src="https://github.com/user-attachments/assets/7cfa7afa-b527-4d41-a28b-a92f00e480b3";
 />
   
   


-- 
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: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to