AN2153 Freescale Semiconductor / Motorola, AN2153 Datasheet - Page 32

no-image

AN2153

Manufacturer Part Number
AN2153
Description
A Serial Bootloader for Reprogramming the MC9S12DP256 FLASH Memory
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
Freescale Semiconductor, Inc.
Application Note
checksum field. The variable CheckSum is used to contain the
calculated checksum value as the S-record is received. The X index
register is initialized to point to the beginning of the 24-bit global variable,
LoadAddr, where the received S-record’s address is stored. Note also
that the most significant byte of LoadAddr is cleared in case an S1
record is received.
After the initializations, a search is begun for the character pairs S0, S1,
S2, S8, or S9 which indicate the start of a valid S-record. Once a valid
start of record is found, the number of bytes in the load address plus one
is stored in the global variable DataBytes. This value is subsequently
subtracted from the received S-record length byte to produce a result
representing the code/data field length. Before receiving the S-record
length byte, the second character of the start of record pair is stored in
the global RecType. After receiving the S-record length byte, the value
is saved in the local variable SRecBytes. This value is also used to
initialize CheckSum which is used to calculate a checksum value as the
S-record is received.
The loop beginning at the label RcvData receives the remainder of the
S-record including the load address, the code/data field, and the
checksum. Note that because each received byte is stored in successive
memory locations, the global variables LoadAddr and SRecData must
remain in the order they are declared. As each data byte and the
checksum is received, it is added into the calculated checksum value.
Because the received checksum is actually the one’s complement of
what the calculated checksum should be, adding the two values should
produce a result of $FF. incrementing the CheckSum variable at the end
of the receive loop should produce a result of zero if the checksum and
all the S-record fields were received properly. This results in an “equal”
condition (CCR Z = 1) being returned if the S-record was properly
received and a “not equal” condition (CCR Z = 0) being returned if a
problem occurred receiving the S-record.
Operation of the GetSRecord subroutine is supported by the three
additional subroutines GetHexByte, IsHex, and CvtHex. The
GetHexByte subroutine retrieves two ASCII hex bytes from the serial
port and converts them into a single 8-bit data byte that is returned in the
B accumulator. The IsHex subroutine is used to check received byte to
AN2153
32
MOTOROLA
For More Information On This Product,
Go to: www.freescale.com

Related parts for AN2153