next up previous contents
Next: 14.3 The Binary Object Up: 14 Binary Programs Previous: 14.1.2 Declaring an Initialization

14.2 Interrupt-Driven Binary Programs

  
Figure 3: Interrupt Structure Before User Program Installation

Interrupt-driven binary programs use the initialization sequence of the binary module to install a piece of code into the interrupt structure of the 6811.

The 6811 has a number of different interrupts, mostly dealing with its on-chip hardware such as timers and counters. One of these interrupts is used by the runtime software to implement time-keeping and other periodic functions (such as LCD screen management). This interrupt, dubbed the ``System Interrupt,'' runs at 1000 Hertz.

Instead of using another 6811 interrupt to run user binary programs, additional programs (that need to run at 1000 Hz. or less) may install themselves into the System Interrupt. User programs would be then become part of the 1000 Hz interrupt sequence.

This is accomplished by having the user program ``intercept'' the original 6811 interrupt vector that points to runtime interrupt code. This vector is made to point at the user program. When user program finishes, it jumps to the start of the runtime interrupt code.

  
Figure 4: Interrupt Structure After User Program Installation

Figure 3 depicts the interrupt structure before user program installation. The 6811 vector location points to system software code, which terminates in a ``return from interrupt'' instruction.

Figure 4 illustrates the result after the user program is installed. The 6811 vector points to the user program, which exits by jumping to the system software driver. This driver exits as before, with the RTI instruction.

Multiple user programs could be installed in this fashion. Each one would install itself ahead of the previous one. Some standard library functions, such as the shaft encoder software, is implemented in this fashion.

  
Figure 5: sysibeep.asm: Binary Program that Installs into System Interrupt

Figure 5 shows an example program that installs itself into the System Interrupt. This program toggles the signal line controlling the piezo beeper every time it is run; since the System Interrupt runs at 1000 Hz., this program will create a continous tone of 500 Hz.

The first line after the comment header includes a file named ``

6811regs.asm''. This file contains equates for all 6811 registers and interrupt vectors; most binary programs will need at least a few of these. It is simplest to keep them all in one file that can be easily included.

The subroutine_initialize_module declaration begins the initialization portion of the program. The file ``

ldxibase.asm'' is then included. This file contains a few lines of 6811 assembler code that perform the function of determining the base pointer to the 6811 interrupt vector area, and loading this pointer into the 6811 X register.

The following four lines of code install the interrupt program (beginning with the label interrupt_code_start) according to the method that was illustrated in Figure 4.

First, the existing interrupt pointer is fetched. As indicated by the comment, the 6811's TOC4 timer is used to implement the System Interrupt. The vector is poked into the JMP instruction that will conclude the interrupt code itself.

Next, the 6811 interrupt pointer is replaced with a pointer to the new code. These two steps complete the initialization sequence.

The actual interrupt code is quite short. It toggles bit 3 of the 6811's PORTA register. The PORTA register controls the eight pins of Port A that connect to external hardware; bit 3 is connected to the piezo beeper.

The interrupt code exits with a jump instruction. The argument for this jump is poked in by the initialization program.

The method allows any number of programs located in separate files to attach themselves to the System Interrupt. Because these files can be loaded from the C environment, this system affords maximal flexibility to the user, with small overhead in terms of code efficiency.



next up previous contents
Next: 14.3 The Binary Object Up: 14 Binary Programs Previous: 14.1.2 Declaring an Initialization



Fred G. Martin
Fri Mar 29 17:44:15 EST 1996