Programmable Interval Timer: Difference between revisions

m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
m (Bot: Replace deprecated source tag with syntaxhighlight)
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
Line 231:
For the "lobyte/hibyte" access mode you need to send the latch command (described above) to avoid getting wrong results. If any other code could try set the PIT channel's reload value or read its current count after you've sent the latch command but before you've read the highest 8 bits, then you have to prevent it. Disabling interrupts works for single CPU computers. For example, to read the count of PIT channel 0 you could use something like:
 
<sourcesyntaxhighlight lang="c">
unsigned read_pit_count(void) {
unsigned count = 0;
Line 246:
return count;
}
</syntaxhighlight>
</source>
 
== Setting The Reload Value ==
Line 449:
In a multitasking system, consider using a linked list or array of these CountDown variables. If your multitasking system supports interprocess communication, you can also store the semaphore/exchange where two processes can talk to, have the interrupt send a message to the waiting process when the timer is done, and have the waiting process block all execution until that message comes:
 
<sourcesyntaxhighlight lang="c">
#define COUNTDOWN_DONE_MSG 1
struct TimerBlock {
Line 477:
WaitForMessageFrom(t->e = getCrntExch());
}
</syntaxhighlight>
</source>
 
In your documentation, note the interval of the timer. For example, if the timer interval is 10 milliseconds per tick, tell the programmer to issue