Dolda2000 GitWeb
/
kokare.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
174dfeb
)
Fixed race condition in getticks.
author
Fredrik Tolf
<fredrik@dolda2000.com>
Wed, 4 Jul 2007 14:41:04 +0000
(14:41 +0000)
committer
Fredrik Tolf
<fredrik@dolda2000.com>
Wed, 4 Jul 2007 14:41:04 +0000
(14:41 +0000)
kokare.c
patch
|
blob
|
blame
|
history
diff --git
a/kokare.c
b/kokare.c
index
64c3754
..
8d151df
100644
(file)
--- a/
kokare.c
+++ b/
kokare.c
@@
-147,9
+147,36
@@
void disphex(unsigned char num)
dsp[1] = font[num & 0x0f];
}
dsp[1] = font[num & 0x0f];
}
+/*
+ * This version is used outside interrupts.
+ * It spins until no overflow has happened.
+ */
unsigned long getticks(void)
{
unsigned long getticks(void)
{
- return(TCNT1 + (((unsigned long)oticks) << 16));
+ uint16_t v;
+ unsigned long r;
+
+ do {
+ v = oticks;
+ r = TCNT1 + (((unsigned long)oticks) << 16);
+ } while(v != oticks);
+ return(r);
+}
+
+/*
+ * This version is used in interrupts
+ */
+unsigned long getticks2(void)
+{
+ uint16_t v;
+ unsigned long r;
+
+ v = TCNT1;
+ r = v + (((unsigned long)oticks) << 16);
+ if((TIFR1 & 0x01) && !(v & 0x8000))
+ return(r + 0x10000);
+ else
+ return(r);
}
void ledcycle(void)
}
void ledcycle(void)
@@
-448,7
+475,7
@@
ISR(SIG_INTERRUPT1)
{
unsigned long now;
{
unsigned long now;
- now = getticks();
+ now = getticks
2
();
if(tstate == 0) {
tstate = 1;
if(tlock != 2)
if(tstate == 0) {
tstate = 1;
if(tlock != 2)