AN2153 Freescale Semiconductor / Motorola, AN2153 Datasheet - Page 35

no-image

AN2153

Manufacturer Part Number
AN2153
Description
A Serial Bootloader for Reprogramming the MC9S12DP256 FLASH Memory
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
AN2153
MOTOROLA
The SCIInit subroutine is used to initialize the SCI hardware and the
related queue data structures. The baud rate register (SCI0BD) value for
the desired baud rate is passed to the subroutine in the D accumulator.
The queue index values RxIn, RxOut, TxIn, TxOut, and the values for
RxBAvail and TxBAvail are not specifically initialized by the
subroutine because the initial values are set at the point of their
declaration. This technique works in this case because the constant
values were copied from the FLASH into RAM. In a situation where the
variables were declared with a ds (define storage) directive each
variable would have to be initialized to its proper value.
When the transmitter and receiver are enabled, notice that only the
receive interrupts are enabled. Unlike the receiver interrupts, which may
be enabled at all times, the transmit interrupt may be enabled only when
the transmit queue contains characters to be sent. Enabling transmit
interrupts at initialization would immediately cause a transmitter interrupt
even though the transmit queue is empty. This is because the TDRE bit
is set whenever the SCI transmitter is in an idle state. The final action
performed by the SCIInit subroutine initializes the SCI0 interrupt
vector to point to the SCI interrupt routine, SCIISR.
Because each SCI only has a single interrupt vector shared by the
transmitter and receiver, a short dispatch routine determines the source
of the interrupt and calls either the RxIRQ or TxIRQ. Note that it is not
an arbitrary choice to have the dispatch routine check for receiver
interrupts before transmitter interrupts. To avoid the loss of received
data, an SCI interrupt dispatch routine should always check the receiver
control and status flags before checking those associated with the
transmitter. Failure to follow this convention will most likely result in
receiver overruns when data is received during message transmissions
longer than a couple of bytes.
The receive interrupt service routine, RxIRQ, has the responsibility of
removing a received byte from the receive data register and placing it in
the receive data queue if space is available. In addition, if space
available in the queue falls below the value of XOffCount, two
variables, SendXOff and XOffSent, are set to a non-zero value and
transmitter interrupts are enabled. These actions cause an XOff
character to be sent to the host computer the next time a transmit
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
Bootloader Software
Application Note
35

Related parts for AN2153