This is used to synchronize with an external event, with minimal response time.
#define FOREVER for( ; ; )
FOREVER {
while( !ready( ) ) ;
do-it( );
}
while( !ready( ) )Maybe this isn't fast enough for you. Here's an "improvement".
L1: NOP L2: NOP ... L1000: NOP L1001: LDR R0, [R3] STR R0, [R4, #4]! BX R5
NOPPolling loops allow you to manage more than one condition/activity pair at the same time.
The basic polling loop
FOREVER {
if( c1 ) a1;
if( c2 ) a2;
...
if( cN ) aN;
}
if( cn ) + execution time of
anSuppose you want a better response time for a1. Then try the loop
FOREVER {
if( c1 ) a1;
if( c2 ) a2;
if( c1 ) a1;
if( c3 ) a3;
...
if( c1 ) a1;
if( cN ) aN;
}
Worst case response time for a1
a1 + \max_n execution time for
if( cn ) anSuppose the response time is still too long, because the execution of one action, say a2, is too long. Then you can break a2 into two parts
FOREVER {
if( c1 ) a1;
if( c2 ) { a2.1; half-done = TRUE }
if( c1 ) a1;
if( halfdone ) a2.2;
...
}
This is strarting to get a little complicated and we haven't said anything about inter-action communication
We can use interrupts to get rid of polling
Like function calls without arguments or return values.
Contrast RT to non-RT
Return to: