© 2000 Ubicom, Inc. All rights reserved.
- 3 -
www.ubicom.com
SX IrDA Virtual Peripheral Implementation
AN16
2.0
Programming Methodology
The IrDA Virtual Peripheral consists of both interrupt and
mainline code. The interrupt service routine implements
the IrDA UART. Rather than implementing an application
by calling the IrDA sub-routines the code works on a call-
back system. Creating a new application involves imple-
menting certain functions which will be called by the IrDA
mainline code. This will become clearer in the section
describing the application layer.
An IrDA frame is processed one byte at a time through
every layer.
For reception the framing layer strips off the header and
passes the payload data one byte at a time to the pay-
load layer (part of the LAP layer). The payload layer
strips off the address and command bytes and if the
frame contains I data then it will pass the data one byte at
a time to the LAP layer which will pass it to the LMP layer.
The LMP layer will strip off the LMP address bytes and if
the frame contains IrComm data then it will pass it to the
application layer. At this point the frame has not yet been
validated by the frame-check-sequence (FCS) CRC nor
has it been validated as the correct frame number by the
LAP layer. Once the integrity of the frame has been
checked by the framing layer it will inform the payload
layer which will inform the LAP layer. The LAP layer will
verify the frame numbering and will inform the LMP layer
of the validity of the frame which will in-turn inform the
IrComm application layer.
The protocol stack is implemented as a number of layers,
each one based on a state-machine. All the state-
machines must operate in parallel and to achieve this the
state machines are event-driven. No state machine may
hold up the processor waiting for an event, but instead
must complete its processing for the incoming event and
return. The event handlers for a layer are subroutines
where the name of the routine is predefined so that the
call to the event handler can be coded in the originating
code.
There are two types of events:
Asynchronous Events
Synchronous Events
Asynchronous events are events that are triggered by the
interrupt service routine (ISR). When an event (e.g. a
received IrDA byte) has been detected by the ISR will set
the appropriate flag in a global ISR status register. The
main code is a loop that tests these flags and will call any
event handlers as appropriate.
Synchronous events are events that are generated by a
layer to inform a higher layer of a situation.
For example, when a byte has been received by the IrDA
UART in the ISR the IrDA UART data available flag will
be set. These asynchronous flags are polled by the main
routine and when the data available flag is detected the
data available event handler in the framing layer will be
called. The framing layer will obtain the data byte, pro-
cess it, and return. However, if the framing layer detects
the byte as payload data then before returning it will call
the payload data available event handler in the payload
layer. The payload layer will process the data, call any
appropriate higher event handlers, and return. When the
end-of-frame byte is received by the framing layer it will
test the FCS bytes and will call either the valid or the
error event handler in the payload layer. If appropriate the
payload layer will inform its higher layer and so on.
The following rules apply to inter-layer events or calls:
The routine name must start with the abbreviation of
the calling layer followed by a 2 followed by the abbre-
viation of the called layer.
The call instruction must be proceeded by a page in-
struction.
The return instruction from the called event must be a
retp instruction.
The called code may change any global or shared reg-
isters.
Upon returning the bank is assumed to have been
changed.
A paged call may be replaced by a paged jump if direct-
ly after the inter-layer call has been completed the code
will issue a return instruction to return from a inter-layer
call.