|
Micros
run forever. Sometimes they sleep, sometimes they restart, but generally
speaking they always repeat their operation. This is because they always
have to serve the same thing. Now, how do we achieve this repetition in
software? We use an endless loop. It is called “super loop architecture”
and goes like this …
int main(void) // program starts here
{
Initialize(); // executed once
// Superloop starts here
// These tasks will be executed repetitively
while (1)
{
Task1(); // say read temperature
Task2(); // say process temperature
Task3(); // say display temperature
}
}
Any exceptions? Yes, interrupts. If interrupts are used,
when they trigger, they force the execution of the interrupt service routine
asynchronously with the main code. In other words, internal or external
interrupts produce an event that causes a routine to be executed at the
triggering time, then normal execution carries on. And what if an interrupt
triggers when an interrupt service routine is currently executed? Well,
interrupts go with priorities, if the just arrived interrupt has higher
priority than the currently being serviced one, it will get attention otherwise
it will be stacked.
The
super loop architecture is used for tasks of low (and medium) complexity.
The other alternative is having an operating system (no, not Windows XP),
which again is going to be repetitive somehow but, not in the same simple
manner.
|