annotate delay.c @ 30:435c6330896c

Set tv_usec in gettimeofday() by using the prescaler counter.
author Daniel O'Connor <darius@dons.net.au>
date Tue, 27 Nov 2012 13:19:11 +1030
parents 891841f5f785
children a38003b97de6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
58d76cf522ff Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 #include <stdint.h>
58d76cf522ff Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2 #include "stm32f10x.h"
58d76cf522ff Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
3 #include "delay.h"
58d76cf522ff Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4
14
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
5 /* Sleep for nCount usec
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
6 * TDS1012 on 2.5usec/div shows...
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
7 * 30usec = 29.60usec
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
8 * 60usec = 59.20usec
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
9 *
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
10 * XXX: not sure disable IRQ stuff is working as I see occasional (small) extra delays
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
11 */
8
58d76cf522ff Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
12 void
14
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
13 delay(uint32_t nCount) {
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
14 __disable_irq();
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
15 for(; nCount != 0; nCount--) {
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
16 #ifdef SYSCLK_FREQ_72MHz
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
17 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
18 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
19 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
20 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
21 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
22 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
23 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
24 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
25
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
26 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
27 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
28 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
29 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
30 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
31 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
32 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
33 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
34
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
35 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
36 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
37 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
38 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
39 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
40 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
41 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
42 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
43
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
44 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
45 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
46 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
47 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
48 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
49 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
50 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
51
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
52 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
53 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
54 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
55 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
56 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
57 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
58 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
59 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
60
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
61 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
62 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
63 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
64 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
65 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
66 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
67 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
68
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
69 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
70 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
71 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
72 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
73 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
74 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
75 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
76 __asm__("nop");
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
77 #else
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
78 #error Unknown clock frequency
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
79 #endif
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
80 }
891841f5f785 Fix delay() to be accurate as measured on the cro.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
81 __enable_irq();
8
58d76cf522ff Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
82 }
58d76cf522ff Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
83