On Jun 15, 2007, at 4:16 PM, Ben Buckner wrote:
From: "Ian Welch" <[EMAIL PROTECTED]>
Subject: [Tinyos-help] Timer and Atomic Help
Hello,
I'm implementing a clock on my mote and it seems to drift, I
think the
issue is to to too many or too long atomic sections. I was
wondering if
someone could explain to me how atomic sections effect interrupts
(events)
from the timer module.
This is more a general microprocessor programming question than a
TinyOS
question, but, as the documentation says, an atomic section prevents
interrupt execution, so if your timer fires an interrupt during
execution of
atomic code, the interrupt will either not be processed or (less
likely)
will be queued until the atomic section is finished. I don't know
of TinyOS
being implemented on a controller that can queue interrupts, so it
will
probably be lost (definitely lost on Mica*s), but that could be a
platform
dependent behavior.
Almost all processors today (and all for the sake of this discussion)
work in a simple way:
1) when a condition to cause an interrupt occurs, the processor sets
the interrupt pending bit in a control register
2) if an interrupt is enabled and its pending bit it set, the
interrupt fires and the handler executes
2a) depending on the hardware and interrupt source, the pending
bit may be automatically cleared when the interrupt fires
So you only lose an interrupt if it is disabled long enough that the
pending bit is already set when the condition occurs again. In
essence, the processor has a 1-deep queue for each interrupt source.
The TinyOS reference docs may define this behavior - I
don't know, might be worth checking. Consequently, atomic sections
may have
to be synchronously designed so that interrupts will be guaranteed
to be
enabled during a clock tick. That could be doable on a mote
platform, but
good luck doing it. Another approach is to poll the counter state
coming out
of every atomic section to determine whether the clock fired while
you were
in it. Does that scare you? It should. I recommend finding an
alternative to
building a real time software clock.
Phil
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help