This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 1a267dc62d6e6b1e1ffcda681ba46698a3e1d65c
Author: Jukka Laitinen <[email protected]>
AuthorDate: Tue Oct 22 14:57:15 2024 +0300

    drivers/timers/arch_alarm.c: Remove ndelay_accurate
    
    Using ONESHOT_CURRENT retrieves the tick number multiplied by tick time; 
thus
    it doesn't give the accurate monotonic time - it is quantized by
    the tick time. This cannot be used as a ndelay timer, it would always loop
    at least to the end of the ongoing tick.
    
    Revert the up_udelay to use the original "coarse" looping. The "accurate" 
udelay,
    if such is needed, should either be done under arch specific code, or there 
should be
    a function for getting the accurate time that is available for all the 
platforms.
    
    Signed-off-by: Jukka Laitinen <[email protected]>
---
 drivers/timers/arch_alarm.c | 25 +------------------------
 1 file changed, 1 insertion(+), 24 deletions(-)

diff --git a/drivers/timers/arch_alarm.c b/drivers/timers/arch_alarm.c
index 43371c45d3..f9f646c734 100644
--- a/drivers/timers/arch_alarm.c
+++ b/drivers/timers/arch_alarm.c
@@ -50,22 +50,6 @@ static clock_t g_current_tick;
  * Private Functions
  ****************************************************************************/
 
-static void ndelay_accurate(unsigned long nanoseconds)
-{
-  struct timespec now;
-  struct timespec end;
-  struct timespec delta;
-
-  ONESHOT_CURRENT(g_oneshot_lower, &now);
-  clock_nsec2time(&delta, nanoseconds);
-  clock_timespec_add(&now, &delta, &end);
-
-  while (clock_timespec_compare(&now, &end) < 0)
-    {
-      ONESHOT_CURRENT(g_oneshot_lower, &now);
-    }
-}
-
 static void udelay_coarse(useconds_t microseconds)
 {
   volatile int i;
@@ -442,12 +426,5 @@ void weak_function up_udelay(useconds_t microseconds)
 
 void weak_function up_ndelay(unsigned long nanoseconds)
 {
-  if (g_oneshot_lower != NULL)
-    {
-      ndelay_accurate(nanoseconds);
-    }
-  else /* Oneshot timer hasn't been initialized yet */
-    {
-      udelay_coarse((nanoseconds + NSEC_PER_USEC - 1) / NSEC_PER_USEC);
-    }
+  udelay_coarse((nanoseconds + NSEC_PER_USEC - 1) / NSEC_PER_USEC);
 }

Reply via email to