📄 appendxa.htm
字号:
timetest.h16.
<h4><a name="linker_command_file">Linker Command File</a></h4>
<pre><code>
#
+h # multi-segment output
-max 0xfffff # maximum size
-ps16 -pc. # set up banking options
+map=timetest.ma # create a memory map file
-o timetest.h16 # output file name
+text -b 0 # reset vectors start address
vectors.o # vectors
+text -b 0x400 # program start address
+data -b 0x20000 # data start address
crts.o # startup routine
timetest.o # application program
ooplib.h16 # oop library
c:/cc16/lib/libi.h16 # C library (if needed)
c:/cc16/lib/libm.h16 # machine library
+def __memory=__bss__ # symbol used by library
<h4>
Listing 2. Linker Command File
</h4>
</code></pre><p> This compiler system generates several different sections during its execution.
These sections are linked into different modules at link time. An output code section is
identified as a +text section, and an output data section is identified as +data. In the
command file, the next operation is to load the vector table. More about this part of the
program will be covered later. The vector table is to be loaded at the address 0. The line
text -b 0 sets up the linker to put this program at zero. There are no data contents to this
portion of the program so no +data command is needed as yet. At the completion of the
vector table, the startup routine followed by the main program followed by any library
functions needed will be loaded. These portions of the program will be started at the
address 0x400, and any data needed for these sections of the program will be loaded at
0x20000. These program modules will be loaded contiguously in their respective
memories. After the program is loaded, three libraries will be searched for missing
program modules. The first of these libraries is a special library generated for these test
programs, and the next two, libi.h16 and libm.h16 are the standard integer and machine
libraries for the M68HC16. The initialized data memory area is called the bss, and the
internal representation of the end of this memory area is __bss__. This value is saved in
the global memory location named __memory so that the executing program can find the
end of the used RAM storage area.
<p> This command file is redirected onto the linker command lnkh16 . The output
from the linker is a file with an h16 extension. This output must be converted to an
approprioate ascii file to be loaded into the development system board. Also, the format
of the h16 file must be converted to an appropriate debug level control file to aid in the
source level debug of the program. The following command file will execute all of these
operations:
<h4><a name="link_phase_command_file">Link Phase Command File</a></h4>
<pre><code>
lnkh16 < %1.lnk
hexh16 -s -o %1.s19 %1.h16
topne %1.h16
pause
<h4>
Listing 3. Link Phase Command File
</h4>
</code></pre><p>
This file can be combined with the compile command file if the programmer
wishes to compile in link with one command.
<p> There are two more files that should be considered at this time. The first is the
vector file. A listing of one such file is shown below in Listing 4. There are two lines at
the head of the file that contain code that is not portable ANSI compatible code. These
lines of code are specifically needed to pass into the program addresses of functions
needed in the vector table. The entries look like function prototypes that are marked as
external with the extern key word. The first is the start-up code that is addressed as
_stext in the file crts.s. The key word @far notifies the compiler that it should use a 20
bit address for this function and that it has the nature of an interrupt service routine. The
modifier @port identifies _stext() as an interrupt service routine. The next line of code is
a function prototype for an interrupt service routine named _int(). The code for this
function is found at the end of this file.
You can see that this file simply contains a single structure. The first four
members of the structure are book keeping items that are needed to bring the chip on-
line after reset. The first word is a combination of the several extension registers that
will be loaded at reset. The next location contains the least significant sixteen bits of the
initial program counter value. The next entry is the initial stack pointer, and finally the
next memory location contains the least significant bits of the Z register at reset. These
mandatory entries are followed by an array of 251 exception service routine addresses.
The first 0x18 entries in this portion of the list are the preset exception vectors for the
part and the initialization addresses. The address of a dummy service routine is placed
in each of these vector addresses. This dummy routine called _int() merely returns
control of the program to the background mode monitor. In debug, it is very important
that _int() execute a bgnd command which will cause control of the program to be
returned to the background mode monitor. This approach will let the programmer know
that an unexpected exception has occurred. As the program is developed, it is expected
that these vectors will be changed to proper locations within the program being
developed. Also
at the close of the program development, the bgnd command in _int() sholud be change
to a catch-all function that handles any accidental exception that might occur during
normal operation.
<h4><a name="vector_table">Vector Table File</a></h4>
<pre><code>
/* RESET AND INTERRUPT VECTORS
*/
extern @far @port void _stext(void); /* startup routine */
extern @port void OC3_Isr(void); /* OC3 isr address */
static @port void _int(void);
static const struct reset {
@far @port void (*rst)(void); /* reset+code extension */
unsigned short isp; /* initial stack pointer */
unsigned short dpp; /* direct page pointer */
@port void (*vector[252])(void); /* interrupt vectors */
} _reset = {
_stext, /* 1-start 20-bit address */
0x03fe, /* 2-stack pointer */
0x0000, /* 3-page pointer */
_int, /* 4-Breakpoint */
_int, /* 5-Bus Error */
_int, /* 6-Software Interrupt */
_int, /* 7-Illegal Instruction */
_int, /* 8-Divide by Zero */
_int, /* 9-Reserved */
_int, /* a-Reserved */
_int, /* b-Reserved */
_int, /* c-Reserved */
_int, /* d-Reserved */
_int, /* e-Reserved */
_int, /* f-Uninitialized Interrupt */
_int, /* 10-Reserved */
_int, /* 11-Level 1 Interrupt Autovector */
_int, /* 12-Level 2 Interrupt Autovector */
_int, /* 13-Level 3 Interrupt Autovector */
_int, /* 14-Level 4 Interrupt Autovector */
_int, /* 15-Level 5 Interrupt Autovector */
_int, /* 16-Level 6 Interrupt Autovector */
_int, /* 17-Level 7 Interrupt Autovector */
_int, /* 18-Spurious Interrupt */
/* vectors 0x19-0x37 unassinged, reserved */
0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* put timer at vector 0x46 0x40 from ICR and 6 for OC3 */
0,0,0,0,0,0,OC3_Isr /* OC3_Isr vector at 0x46 address
0x8c*/
};
/* function to receive an undefined interrupt */
static @port void _int(void)
{
_asm("bgnd\n");
}
<h4>
Listing 4. Vector Table File
</h4>
</code></pre>
<p> Vectors 0x19 throught 0x37 are reserved and not available for use at this time.
Vectors 0x38 through 0xff are available for use by the program. We can see above how
these vectors can be used. The program in this case needs an interrupt service routine for
Output Compare number 3. This routine is named OC3_Isr(). The programmer wants
this interrupt service routine to be placed in the vector 0x46 which is at the address 0x8c.
This externally linked routine is placed in vector 0x46 in the above routine. This routine
is then compiled and linked with the main program at link time.
<h4><a name="crts">Initialization File</a></h4>
<p> We next have a small assembly language program that is used to initialize the
part after reset. This routine is called crts.s. When a file has an extention .s it can be
assembled by the compiler exactly as a C program.
<p> In this program, there are several things that must be properly handled. The first
business in the program below is to set up the chip internal RAM to be located at the hex
address 0x20000. The first seven instructions take care of this matter. The control
registers for the internal RAM are found in the address range 0xffb00 through 0xffb04.
One means of accessing this memory range is to use extended addressing with the EK
register loaded with a 0xf. The first two instructions place an 0xf into EK. The next
instruction places a 2 into the location 64260 (0xfb04). This action places the address at
0x20000. Next some bits are set in the RAM module control register RAMMCR. The
two instructions involving bits 2 and 3 place a value 2 in the RASP bit field which causes
the RAM to be placed in both program and data space. The next instruction clears the
STOPR bit which causes the RAM to operate in normal mode. Usually, these operations
are easily done in the C portion of the program. There is one small problem, however.
You will note that near the end of the program, a jsr instruction--jump to subroutine--is
executed. If the stack is not placed in valid RAM when this program instruction is
executed, the program will crash and burn. Therefore, we put the RAM setup into the
assembly language initialization portion of the program.
<pre><code>
; C STARTUP FOR 68HC16
;
.external _main, __memory
.external ._main, .__bss__
.public _exit, __stext
.psect _bss
sbss:
.psect _text
__stext:
ldk #15 ; ram control registers are
tbek ; in top memory page
ldd #2 ; put internal ram at 0x20000
std 64260 ; 0xfb04
bclr 64256,#3 ; ram for both program and 0xfb00
bset 64256,#2 ; data
bclr 64256,#128 ; ram in normal mode
ldk #.__bss__
tbek ; initialize the extension
tbxk ; registers to the msb of
tbyk ; the bss
tbzk
tbsk
ldx #sbss ; start of bss
clrd ; to be zeroed
bra mtest ; start loop
bcl:
std 0,x ; clear memory
aix #2 ; next word
mtest:
cpx #__memory ; end of memory ?
blo bcl ; no, continue
lds #1022 ; put stack at 203fe
jsr _main,#._main; call application
_exit:
bgnd ; enter background mode here
; in the event of unexpected
; return from main
;
.end
<h4>
Listing 5. Initialization program crts.s
</h4>
</code></pre>
<hr>
<p>
<a href="copyrite.htm#copyright">Copyright</a>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -