View: 7387|Reply: 0

[Bare metal] void udelay(uint32_t d)

[Copy link]

2

threads

3

posts

10

credits

Novice

Rank: 1

credits
10
Published in 2018-6-15 18:36:02 | Show all floors |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 code

You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list