Advertisement
talofer99

delay samd

Nov 14th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.39 KB | None | 0 0
  1. void _delay_cycles(void *const hw, uint32_t cycles)
  2. {
  3.     (void)hw;
  4.     uint8_t  n   = cycles >> 24;
  5.     uint32_t buf = cycles;
  6.  
  7.     while (n--) {
  8.         SysTick->LOAD = 0xFFFFFF;
  9.         SysTick->VAL  = 0xFFFFFF;
  10.         while (!(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk))
  11.             ;
  12.         buf -= 0xFFFFFF;
  13.     }
  14.  
  15.     SysTick->LOAD = buf;
  16.     SysTick->VAL  = buf;
  17.     while (!(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk))
  18.         ;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement