© 2001 Ubicom, Inc. All rights reserved. - 2 - www.ubicom.com AN38 Asynchronous Transmitter & Receiver (UART) Virtual Peripheral Implementation 3.0    Source Code Sections The  source  code  for  the  UART  Virtual  Peripheral  is
divided into five sections:
•Equates Section:  Constants that define the operation
     of the UART
•Bank Section:  Memory allocation for the virtual periph-
     eral
•Initialization Section: Must run before the mainline ap-
     plication code can run
•Interrupt Section: The most important part of the virtual
     peripheral; the section of code that continually runs
     (while enabled) and mimics hardware in software
•API Subroutines: Send data to and receive data from
     the Virtual Peripherals.  Analogous to the API routines
     that would be written for accessing hardware, and
     make the operation of the virtual peripheral transpar-
     
ent.
When integrated into an application, each section of the
source code is inserted at an appropriate location in the
main body of the application’s source code.
3.1
          Equates Section
The  equates  section  provides  configuration  constants,
allowing compile-time changes in the functionality of the
UARTs.
UARTRxFs   ,                  UARTTxFs   : These constants define the SAM-
PLING RATE of the UART, and must be calculated by the
software programmer based on the Interrupt Frequency
and on how the
                          ISR-Multitasker   is set-up.  In this ver-
sion   of   the   source   code,   the   UART   transmitter   and
receiver are both sampled at rates of 57600Hz.
InterruptFrequency= UARTTxFs    =    By Default,
   oscillator frequency = 50MHz
   
Interrupt frequency » 230400Hz
   Number of threads calling the rs232Transmit/Receive
routines    = 4
Number of ISR Threads is 16.  
----------------------------------------------------------
Therefore,
UARTTxFs    and UARTRxFs   = 57600. The multitasker rotates interrupt service among 16 slots,
and isrThread1    is  called  from  four  of  these  slots.  In
other examples, one slot of 16 might be sufficient to ser-
vice the UART Virtual Peripheral ISR.
The pins on which the input and output data are received
and sent are also defined in this section. Port A is used
for the external interface.
The port pins are configured as follows:
• ra.0
rs232RTSpin • ra.1 rs232CTSpin • ra.2 rs232Rxpin • ra.3 rs232Txpin intPeriod = 217 UARTfs = 230400 Num = 4 IFDEF baud1200
UARTBaud
= 1200 ENDIF IFDEF baud2400
UARTBaud
= 2400 ENDIF IFDEF baud4800
UARTBaud
= 4800 ENDIF IFDEF baud9600
UARTBaud
= 9600 ENDIF IFDEF baud1920
UARTBaud
= 19200 ENDIF IFDEF baud5760
UARTBaud
= 57600 ENDIF IntPeriod Frequency Oscillator threads ISR of number total Transmit rs calling threads number frequency nterrupt i 232 *