AN2153 Freescale Semiconductor / Motorola, AN2153 Datasheet - Page 26

no-image

AN2153

Manufacturer Part Number
AN2153
Description
A Serial Bootloader for Reprogramming the MC9S12DP256 FLASH Memory
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
Application Note
Bootloader
Control Loop
26
The final actions performed by the startup code initialize the FCLKDIV
register and call the SCIInit subroutine. The value written to the
FCLKDIV register is calculated by the assembler and is based on the
MC9S12DP256’s oscillator frequency, not the bus frequency. The
SCIInit subroutine initializes the SCI0 hardware and associated data
structures needed to support buffered, interrupt driven communications.
It accepts a single parameter in the D accumulator that is used to set the
initial baud rate.
After the startup code has completed its task, a sign-on message is
displayed and the bootloader enters its main control loop. At the start of
the loop, the X index register is loaded with the address of the bootloader
prompt and the subroutine PromptResp is called. The PromptResp
subroutine is used to display a null terminated ($00) character string and
then waits for a single character response from the operator. Upon
receipt of a character, the PromptResp subroutine returns and a range
check is performed on the received character to ensure it is a valid
command. If the received character is not a valid command, the entry is
ignored and the prompt is redisplayed.
If the received character is one of the three valid commands, its ASCII
value is used as an index into a table of offsets. However, before being
used as an offset, the upper four bits of the ASCII value must be
removed. Next, one must be subtracted from the remaining value
because the first entry in the table is at an offset of zero. The result of
the subtraction must then be multiplied by two because each entry in the
table consists of two bytes. Next the LEAX instruction is used in
conjunction with program counter relative (PCR) indexed addressing to
load the address of the command table into the X index register in a
position independent manner. Because the B accumulator contains an
offset to the proper entry in the command table, the LDD instruction uses
B accumulator offset indexed addressing to retrieve the entry from the
table.
Examining the command table at label CmdTable, it can be seen that
the table does not contain the absolute address of the command to
execute. Rather each table entry contains an offset from the beginning
of the table to the start of the command. This offset, when added to the
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
AN2153

Related parts for AN2153