Technical information

AN2216/D
CodeWarrior Compiler
MOTOROLA MC9S12DP256 Software Development Using Metrowerk’s Codewarrior 7
constant data to the segment ROM_VAR. All constant variables following the
#pragma CONST_SEG statement are included in the segment until the next
#pragma CONST_SEG statement. Thus assignment of the default segment is
a convenient means of terminating a specific segment:
#pragma CONST_SEG DEFAULT
Any declarations of external data variables must be within the same data
segment as the data variable definition itself. Thus if var2 is defined in a
constant data segment B in a file, any other files which contain code which
accesses var2 would contain the declaration:
#pragma CONST_SEG B
extern const int var2;
#pragma CONST_SEG DEFAULT
Interrupt Service
Routines
If the application uses interrupts, each interrupt service routine must have the
#pragma TRAP_PROC command immediately preceding the function, as
shown in Figure 4
#pragma CODE_SEG __NEAR_SEG INTERRUPT_ROUTINES
#pragma TRAP_PROC
void interrupt_func1(void)
{
/* code */
};
#pragma CODE_SEG DEFAULT
Figure 4. Example of ISR
The #pragma TRAP_PROC causes the interrupt routine to be terminated with
a RTI instruction instead of a RTS instruction. Furthermore, if the compiler
option -CpPpage=RUNTIME is specified due to paged data variable accesses,
it is also necessary to specify the compiler option –CpPpage=0x30. This
specifies the address of the PPAGE register which will be saved on the stack
at the start of the interrupt routine and restored at the end of the interrupt
routine.
The interrupt vectors themselves are only 16-bits wide and therefore can only
point to non-paged memory. This means that the interrupt service routines
must be located in non-paged memory. This is easily achieved by creating a
specific segment for interrupt routines. In the example in Figure 4, the code
segment name INTERRUPT_ROUTINES is defined. Note the use of the
attribute __NEAR_SEG in the #pragma statement; this makes it quite explicit
that the code segment has to be placed into non-banked memory.