06.08.2013 Views

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2.5. Interrupts, pre-emption, and reentrance<br />

course, the time in software will then be discrete (incremented one step for<br />

each timer interrupt) opposed to the true time which is continuous. Discrete<br />

time is, however, inherent to computer control anyway so it suits our purposes<br />

well.<br />

Note that if we were only simulating our system, the time variable could<br />

be stepwise increased by the scheduler; when all processing is done for one<br />

point of time, the scheduler simply lets time jump to the next time referred<br />

to by the application. But here we aim at software that interacts with the<br />

physical environment which (by the laws of nature) has time as an independent<br />

and continuously increasing variable. The time variable in our software is the<br />

sampled value of the real time.<br />

The timer interrupt actually turns out to be a general and minimum requirement<br />

for both desktop and control computers. Additionally, there are<br />

some low-level and system-specific events that require particularly timely service.<br />

For instance, the Windows-95/98 user may review his/her IRQ settings,<br />

typically finding them allocated by the sound card, the game port, the hard<br />

disk, etc. (The settings are found by selecting IRQ in the panel found by<br />

clicking on Control panel -> System -> Device Manager -> Computer -><br />

Properties.) Then note that the first interrupt (IRQ 00, having the highest<br />

priority) is used by the “System Timer” which then provides the time base<br />

for the entire operating system. Giving the timer interrupt the highest priority,<br />

allowing it to interrupt other interrupts, is to ensure maintenance of the<br />

time variable. Otherwise, a too excessive number of interrupts could not be<br />

detected.<br />

In embedded computers there are usually also some kind of time-out or<br />

stall-alarm interrupt connected to the very highest (unmaskable) interrupt<br />

level. It is then the obligation of the so called idle loop (the loop being<br />

executed when there are nothing else to do) to reset that timer so it never<br />

expires. But if that should happen, the CPU is overloaded and the controlled<br />

machine must be shut down because without enough time for the feedback<br />

control the system may behave very badly (crazy robot, crashing airplane,<br />

etc.). To prevent this, we will use special programming techniques in later<br />

chapters. In desktop applications, on the other hand, the user simply has to<br />

wait.<br />

2.5.2 Pre-emption<br />

When the scheduler, as a consequence of a timer interrupt, suspends execution<br />

of one activity and lets the program resume execution at another point (where<br />

execution was suspended at some earlier stage), we call it pre-emption. The<br />

term is used also in connection with operating systems; pre-emptive multitasking.<br />

Pre-emption means that execution may be suspended even if there is<br />

nothing in the executing code that explicitly admits the change of execution<br />

27

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!