Actually real-world programming, which means
tension between flexibility and performance
In cs452 we take guaranteed response time as the defining quality of real-time computation.
How does one keep time in a computer?
This is used to synchronize with an external event, minimizing response time.
#define FOREVER for( ; ; )
FOREVER {
while( !ready( ) ) ;
do-it( );
}
or in another form
FOREVER {
if ( ready( ) ) do-it( );
}
Sometimes you only want to do the thing once, as you do when putting a character on a serial line.
#define UART1_BASE 0x808c0000
#define UART_DATA_OFFSET 0x00 // low 8 bits
#define UART_FLAG_OFFSET 0x18 // low 8 bits
#define TXFF_MASK 0x20 // Transmit buffer full
flags = (int *)( UART1_BASE + UART_FLAG_OFFSET );
data = (int *)( UART1_BASE + UART_DATA_OFFSET );
while( ( *flags & TXFF_MASK ) ) ;
*data = c;
Note. The volatile keyword.
From the time that the ready bit sets until the first instruction of do-it is executed
while( !ready ) ; do-it;
ready:
ldb r0, STATUS-ADDRESS
and r0, r0, READY-BIT
beq _ready
do-it:
ldb r0, DATA-ADDRESS
Here do-it is acquiring a single byte from interface hardware when the status register indicates that valid data is available in the dara register.
and,
beq, ldb, and and
beqWhat if the CPU has to two things at once?
E.g.,
Unless the rate of bytes coming in and rate of clock ticks are identical
Polling 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( c<n> ) +
execution time of a<n>}Suppose you put busy-wait I/O to the train controller into an action
Will you catch it in your testing?
Suppose 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
if( c1 ) + maximum over n of 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( half-done ) { a2.2; half-done = FALSE; }
...
}
This is strarting to get a little complicated and we haven't said anything about inter-action communication
Return to: