Stefan Schuermans commited on 2012-05-06 11:55:04
Showing 2 changed files, with 19 additions and 4 deletions.
| ... | ... |
@@ -5,6 +5,7 @@ |
| 5 | 5 |
|
| 6 | 6 |
#include <avr/io.h> |
| 7 | 7 |
#include <avr/interrupt.h> |
| 8 |
+#include <util/atomic.h> |
|
| 8 | 9 |
|
| 9 | 10 |
#include "arp.h" |
| 10 | 11 |
#include "cf.h" |
| ... | ... |
@@ -17,6 +18,9 @@ |
| 17 | 18 |
#include "timing.h" |
| 18 | 19 |
#include "udp.h" |
| 19 | 20 |
|
| 21 |
+// global timer in ms |
|
| 22 |
+volatile unsigned long TimingMs = 0; |
|
| 23 |
+ |
|
| 20 | 24 |
// 2ms tick counter to generate 20ms ticks |
| 21 | 25 |
volatile unsigned char Timing2_10 = 0; |
| 22 | 26 |
|
| ... | ... |
@@ -32,6 +36,8 @@ unsigned char Timing20_10 = 0; |
| 32 | 36 |
// 2ms interrupt (timer 0 compare match) |
| 33 | 37 |
SIGNAL(SIG_OUTPUT_COMPARE0) |
| 34 | 38 |
{
|
| 39 |
+ // advance global timer |
|
| 40 |
+ TimingMs += 2; |
|
| 35 | 41 |
// set flag every 20ms |
| 36 | 42 |
Timing2_10++; |
| 37 | 43 |
if (Timing2_10 >= 10) {
|
| ... | ... |
@@ -55,10 +61,16 @@ void TimingInit(void) // (extern) |
| 55 | 61 |
|
| 56 | 62 |
// configure timer 1 to count cycles |
| 57 | 63 |
TCCR1A = 0 << WGM11 | 0 << WGM10; // normal mode |
| 58 |
- TCCR1B = 0 << WGM13 | 0 << WGM12 | 0 << CS12 | 0 << CS11 | 1 << CS10; // normal |
|
| 59 |
- // mode, |
|
| 60 |
- // no |
|
| 61 |
- // prescaler |
|
| 64 |
+ TCCR1B = 0 << WGM13 | 0 << WGM12 | // normale mode |
|
| 65 |
+ 0 << CS12 | 0 << CS11 | 1 << CS10; // no prescaler |
|
| 66 |
+} |
|
| 67 |
+ |
|
| 68 |
+// get time in milliseconds |
|
| 69 |
+void TimingGetMs(unsigned long *ms) // (extern) |
|
| 70 |
+{
|
|
| 71 |
+ ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
|
| 72 |
+ *ms = TimingMs; |
|
| 73 |
+ } |
|
| 62 | 74 |
} |
| 63 | 75 |
|
| 64 | 76 |
// provide curent time stamp as entropy to random number generator |