comparison delay.c @ 79:cecb0506f4b8

No point disabling IRQs inside the function calls since any pending IRQs happen when we return. The caller must do it.
author Daniel O'Connor <darius@dons.net.au>
date Sun, 07 Jul 2013 22:48:17 +0930
parents a38003b97de6
children
comparison
equal deleted inserted replaced
78:4c1db877452b 79:cecb0506f4b8
7 */ 7 */
8 void 8 void
9 delay(uint32_t nCount) { 9 delay(uint32_t nCount) {
10 uint32_t dly, cnt, clk_per_usec, max_dly; 10 uint32_t dly, cnt, clk_per_usec, max_dly;
11 volatile uint32_t *DWT_CYCCNT = (uint32_t *)0xe0001004; 11 volatile uint32_t *DWT_CYCCNT = (uint32_t *)0xe0001004;
12
13 __disable_irq();
14 12
15 #ifdef SYSCLK_FREQ_72MHz 13 #ifdef SYSCLK_FREQ_72MHz
16 clk_per_usec = 72; 14 clk_per_usec = 72;
17 max_dly = (1<<31) / clk_per_usec; /* Really half the maximum (still ~30 seconds at 72MHz) */ 15 max_dly = (1<<31) / clk_per_usec; /* Really half the maximum (still ~30 seconds at 72MHz) */
18 #else 16 #else
28 while (*DWT_CYCCNT > cnt) 26 while (*DWT_CYCCNT > cnt)
29 ; 27 ;
30 /* Wait until we get to the stop count */ 28 /* Wait until we get to the stop count */
31 while (*DWT_CYCCNT < dly) 29 while (*DWT_CYCCNT < dly)
32 ; 30 ;
33
34 __enable_irq();
35 } 31 }
36 32