Mercurial > ~darius > hgwebdir.cgi > stm32temp
comparison delay.c @ 14:891841f5f785
Fix delay() to be accurate as measured on the cro.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Wed, 14 Nov 2012 12:24:21 +1030 |
parents | 58d76cf522ff |
children | a38003b97de6 |
comparison
equal
deleted
inserted
replaced
13:96c345d304af | 14:891841f5f785 |
---|---|
1 #include <stdint.h> | 1 #include <stdint.h> |
2 #include "stm32f10x.h" | 2 #include "stm32f10x.h" |
3 #include "delay.h" | 3 #include "delay.h" |
4 | 4 |
5 /* This is a bit rough and ready */ | 5 /* Sleep for nCount usec |
6 * TDS1012 on 2.5usec/div shows... | |
7 * 30usec = 29.60usec | |
8 * 60usec = 59.20usec | |
9 * | |
10 * XXX: not sure disable IRQ stuff is working as I see occasional (small) extra delays | |
11 */ | |
6 void | 12 void |
7 delay(__IO uint32_t nCount) { | 13 delay(uint32_t nCount) { |
8 __IO uint32_t i; | 14 __disable_irq(); |
9 | 15 for(; nCount != 0; nCount--) { |
10 for(; nCount != 0; nCount--) | 16 #ifdef SYSCLK_FREQ_72MHz |
11 for (i = 0; i < 3900; i++) | 17 __asm__("nop"); |
12 ; | 18 __asm__("nop"); |
19 __asm__("nop"); | |
20 __asm__("nop"); | |
21 __asm__("nop"); | |
22 __asm__("nop"); | |
23 __asm__("nop"); | |
24 __asm__("nop"); | |
25 | |
26 __asm__("nop"); | |
27 __asm__("nop"); | |
28 __asm__("nop"); | |
29 __asm__("nop"); | |
30 __asm__("nop"); | |
31 __asm__("nop"); | |
32 __asm__("nop"); | |
33 __asm__("nop"); | |
34 | |
35 __asm__("nop"); | |
36 __asm__("nop"); | |
37 __asm__("nop"); | |
38 __asm__("nop"); | |
39 __asm__("nop"); | |
40 __asm__("nop"); | |
41 __asm__("nop"); | |
42 __asm__("nop"); | |
43 | |
44 __asm__("nop"); | |
45 __asm__("nop"); | |
46 __asm__("nop"); | |
47 __asm__("nop"); | |
48 __asm__("nop"); | |
49 __asm__("nop"); | |
50 __asm__("nop"); | |
51 | |
52 __asm__("nop"); | |
53 __asm__("nop"); | |
54 __asm__("nop"); | |
55 __asm__("nop"); | |
56 __asm__("nop"); | |
57 __asm__("nop"); | |
58 __asm__("nop"); | |
59 __asm__("nop"); | |
60 | |
61 __asm__("nop"); | |
62 __asm__("nop"); | |
63 __asm__("nop"); | |
64 __asm__("nop"); | |
65 __asm__("nop"); | |
66 __asm__("nop"); | |
67 __asm__("nop"); | |
68 | |
69 __asm__("nop"); | |
70 __asm__("nop"); | |
71 __asm__("nop"); | |
72 __asm__("nop"); | |
73 __asm__("nop"); | |
74 __asm__("nop"); | |
75 __asm__("nop"); | |
76 __asm__("nop"); | |
77 #else | |
78 #error Unknown clock frequency | |
79 #endif | |
80 } | |
81 __enable_irq(); | |
13 } | 82 } |
14 | 83 |