Download GSM Remote Control System

Transcript
5.2 Program structure
Standard Interrupts
Interrupts works in the same manner as a subroutine, except it is initiated by an external signal. This
can for an example, be an I/O device, that needs to be managed. Each interrupt is given a certain level
related to how important it is. For example input from a keypad, would have a relatively high masking
level. This is done to ensure that the task is attended to as fast as possible. If the system has relatively few
interrupt functions, it is possible to use auto-vectored interrupts. This means, that every time a specific
interrupt is triggered, a certain piece of code is run. The program can only contain 7 interrupts when using
auto-vectored interrupts on the M68k.
Main
program
Interrupt
Figure 5.4: Hardware interrupt incorporated.
Combined program structure
By combining subroutines and interrupts, the main program can be a relatively small loop, where subroutines only will be executed, when the conditions are right. This structure also allows the I/O devices to
interrupt the main program.
By minimizing the main program, the number of local variables, is reduced, since the subroutines still
have to communicate. Using the internal registers of the processor, free variables and incorporating a
series of global variables will, however, simplify the handling of the variables. As a consequence of this,
the stack will not be used much, which further simplifies the flow of the program.
Figure 5.5: A program structure as uses multiple subroutines and interrupts.
5.2.1
Stack
The stack is a convenient way to allocate dynamic workspace in a program. The stack is usually placed at
the top end for the RAM memory, as in this project. The fact that the stack is dynamic means, that it has
no predefined size, but can expand downwards in memory to meet the requirements of the program. The
5. Software Design
69 af 166