Please select To the mobile version | Continue to access the desktop computer version

OrangePi

 Login            
 Register            
Search
Hot search: orangepi
View: 1198|Reply: 0

[Bare metal] void udelay(uint32_t d)

[Copy link]

2

Threads

3

Posts

10

Credits

Novice

Rank: 1

Credits
10
Post time 2018-6-15 18:36:02 | Show all posts |Read mode
Edited by rpidmx512 at 2018-6-15 11:38

There are several options to implement

  1. #define CNT64_CTRL_LATCH        ((uint32_t)(1<<1))

  2. void udelay(uint32_t d) {
  3. #if defined (_USE_AVS_TIMER_UDELAY)
  4.         uint32_t t1 = H3_TIMER->AVS_CNT1;
  5.         const uint32_t t2 = t1 + d;
  6.         do {
  7.                 t1 = H3_TIMER->AVS_CNT1;
  8.         } while (t2 >= t1);
  9. #elif defined (_USE_HS_TIMER_UDELAY)
  10.         h3_hs_timer_delay(100 * d);
  11. #else
  12.         H3_CNT64->CTRL = CNT64_CTRL_LATCH;
  13.         //isb();
  14.         while ((H3_CNT64->CTRL & CNT64_CTRL_LATCH) == CNT64_CTRL_LATCH)
  15.                 ;

  16.         const uint32_t low = H3_CNT64->LOW / 24;

  17.         do {
  18.                 H3_CNT64->CTRL = CNT64_CTRL_LATCH;
  19.                 //isb();
  20.                 while ((H3_CNT64->CTRL & CNT64_CTRL_LATCH) == CNT64_CTRL_LATCH)
  21.                         ;
  22.         } while (((H3_CNT64->LOW / 24) - low) < d);
  23. #endif
  24. }
Copy the Code

You have to log in before you can reply Login | Register

Points Rules

Archiver|Mobile edition|Darkroom|OrangePi En ( 粤ICP备14086627号-2

2019-11-21 04:30 GMT+8 , Processed in 0.030408 second(s), 23 queries .

Powered by Discuz! X3.2

© 2014-2015 orangepibbs en.

Quick Reply To Top Return to the list