
          9/25/89

                                  Application Note

                          MC68302 UART FLOW CONTROL ROUTINE



          The Problem

          When implementing flow control with the UARTs on the MC68302, XON
          and  XOFF  characters  must  be  received  and  transmitted.  The
          reception  is  easily handled with the use of  the  UART  Control
          Characters  Table  (p. 4-39 of the MC68302  User's  Manual).  The
          UART   can   be   programmed  to   recognize   these   characters
          automatically  and generate interrupts to the M68000 core (p.  4-
          51).  However, it is the transmit case that is discussed in  this
          note.  When  a UART on the MC68302 transmits a data  buffer,  the
          M68000 core may wish to send an XON or XOFF character immediately
          (without  waiting  until the end of the buffer) and  then  resume
          transmission of that data buffer.

          The suggested software routine:

                 Host CPU action                     MC68302 action
                 ---------------                     --------------

          1.  Issue Stop Tx Command to        1. Command received.  No more
              the IMP (p. 4-37)                  characters are moved into
                                                 the SCCTxFIFO.  A maximum
          2.  Wait until the Command             of three characters are
              Semaphore Flag is cleared          stored in the SCCFIFO and
              (p. 4-5).  Note that until         will be transmitted.
              the RESTART TRANSMIT command
              is given, a CTS status change   2. The MC68302 transmits the
              indication is available in the     XOFF or XON buffer fol-
              UART Event register (p. 4-49).     lowed by the remaining
                                                 portion of the aborted
          3.  Read the SCC's current Transmit    buffer.
              Internal Buffer Number (TBD#)
              (p. 4-27).  It points to the
              Buffer Descriptor (BD) for the
              "aborted" buffer.  Next, read
              the SCC's Tx Internal Data
              Pointer (p. 4-27).  It points
              to the next byte in the aborted
              buffer to be transmitted.

          4.  Readjust the TBD# to point to
              the previous BD (see p. 4-28).

          5.  Prepare a one byte buffer (the
              XOFF or XON character) and link
              it into the BD currently pointed
              to by TBD#.

          6.  Update the next BD for the "aborted"
              buffer (p. 4-48).  The Data Length
              filed should be reduced to the number
              of octets yet to be transmitted in the
              aborted buffer.  This is easily done
              through the Tx internal Byte Count
              (p. 4-27).

          7.  The TX Buffer Pointer field (p. 4-49)
              should be updated to point to the
              beginning of the untransmitted portion
              of the data buffer.

              TX Buffer Pointer <= Tx Internal Data Pointer

          8.  Issue a RESTART TRANSMIT command to the
              MC68302 (p. 4-38).


          NOTES:

          1.  The user should verify that the STOP TRANSMIT command was
              not given after (or while) the last character in the buffer
              has been moved to the TX FIFO.  To do this, the Tx Internal
              Byte Count value is checked (p. 4-27).  If, after the com-
              mand is given, the Tx Internal Byte Count equals zero, the
              buffer was not aborted, and this same buffer should be used
              for the XOFF character.  (This will always occur if one-byte
              buffers are used).

          2.  Another variation is possible -- the sending of control cha-
              racters, for a period of time, followed by a return to normal
              transmission of data.  In this case, the sequence is similar
              except that the CPU should clear the Ready bit on the
              "aborted" BD, and issue a RESTART TRANSMIT command (after
              readjusting the TBD# back by 1 BD) each time a control
              character needs to be sent.  Thus, only one BD is used for
              that period of time.

          Written      by:  Kobi     Ben-Zvi     and      Moti      Kurnick
