Using interrupt handlers

Use an interrupt handler for your operating system to pass data to the CPU. Typically, a static function without parameters is added by passing its address to an operating system operation like InstallIntHdlr (operating system-dependent). The static function can be either a special singleton object or a function defined within a package. This operation must use compiler-specific utilities to get to the registers. Eventually, it must return and execute a return from the interrupt instruction.

About this task

You can pass the data from the interrupt handler to the CPU (assuming that the interrupt handler needs to), in the following ways:

  • Generate an event (using the GEN() macro), which then goes through the operating system to the reactive object (which is in a different thread).
  • Use a rendezvous object with a read/write toggle lock. The interrupt handler checks whether the lock is in the write state, then updates the data and puts the lock in the read state. The reader (in another thread) periodically checks the lock and only reads when it is in the read state. If it is in that state, the reader reads the data and updates the lock to its write state. This update can easily be extended to a queue structure.
  • Write the interrupt handler manually outside Rhapsody® and send it to the operating system message queue for the target thread. Typically, if the operating system does not support interrupt handlers directly, you store the current handler in your function and write the address of the function in the appropriate place in the interrupt vector table. When the interrupt goes off, either the new function replaces the old interrupt handler (meaning when it is done it simply returns) or it chains to it (calls the original). In any event, when the interrupt handler is decommissioned, you replace the vector in the vector table with the original address.