Afternoon all
I am creating a library for asynchronous soft deadline timeouts. It allows me to timerCreate(), timerStart(), timerStop and timerDelete(), and timerHasItExpired() - with various parameters to them all.
I'm relatively new to this chip, and am having some troubles with what exactly to do to correctly deal with the interrupts, and also to disable the interrupt at various points in my library.
In my ISR, should I disable the interrupt at the AIC? Then I read the status reg for TC and act on it. Should I be stopping the clock for TC0 in here? Ideally, i'd like to keep the clock running, but stop the interrupt so it cant recur while in the ISR.
So, which of these should I do?
Code:
void tc0_isr()
{
(disable interrupt?)
(stop clock?)
do my work
(start clock?)
(enable interrupt?)
}
The second part is that I need to ensure that the ISR does not run while in the functions. If it does, it could scramble some of my structures' data.
So, for example, which of these should I do?
Code:
x timerHasItExpired(y)
{
(disable interrupts?)
(stop clock?)
do my stuff, safe in the knowledge that isr wont run...
(enable clock?)
(enable interrupts?)
}
Seemingly I cannot _just_ start the clock by setting CLKEN, it doesnt seem to start the clock again after using CLKDIS. Only SWTRG is starting the clock again, but that resets the counter. So if I use SWTRG every time I want to restart the clock, then when I poll timerHasItExpired(), the clock never progresses to fire its interrupt.
Hope someone out there has some ideas.
Cheers
Rich