© 2000 Ubicom, Inc. All rights reserved. - 18 - www.ubicom.com AN16 SX IrDA Virtual Peripheral Implementation If  the  application  was  simplex  (one  direction  only),  for
example a printer, then the data could be buffered as the
SX would be capable of buffering a 62 byte frame. It is
not, however, capable of buffering both a 62 byte transmit
and a 62 byte receive frame.
The application layer cannot call the LMP layer. Instead
the LMP layer will call the “event handlers” in the applica-
tion  layer  as  specified  in  Figure  3-10.  An  event  handler
should be in the following form:
lmp2appRxCommData bank ApplicationBank ;Correct local register bank ... ;Event handling code retp ;Paged return For   reception   the   LMP   layer   will   call   the   application
layer’s   lmp2appRxCommData   event   handler   with   the
data byte in the w register. The application is free to pro-
cess the byte however it must return when it has finished
processing the data and cannot hold up the CPU waiting
for   something   to   happen.   This   event   handler   will   be
called for every IrComm data byte in the incoming frame
(up     to     62     times)     before     the     LMP     layer     calls
lmp2appRxCommValid to validate the data or lmp2appRxCommError to reject the data.
For  transmission  the  LMP  layer  will  ask  if  there  is  any
data  to  be  sent  by  calling  lmp2appTxCommStart.  The
application layer should return z clear if there is data to
send. For example:
lmp2appTxCommStart bank ApplicationBank ;Correct local register bank test DataCounter ;Z is set if no data to send retp ;Z is clear if data to send If the application layer indicates that there is data to be
sent  then  the  LMP  layer  will  call  lmp2appTxCommData
when  it  is  ready  to  transmit  the  first  byte  of  data.  The
application layer must return with w containing the data
byte to be sent and z indicating if there is more data to be
sent. If z is true then this is the last byte to be sent and no
more  data  will  be  requested.  If  z  is  false  then  another
byte  will  be  requested  when  the  LMP  layer  is  ready  to
accept  it.  The  LMP  layer  will  accept  up  to  62  bytes  of
data for a frame thus the 62nd byte will be considered to
be the last byte by the LMP layer regardless of the z flag.
lmp2appTxCommData bank ApplicationBank ;Correct local register bank mov w, DataPointer ;w = Pointer to register with data inc DataPointer ;increment pointer to next register mov FSR, w ;apply register pointer mov w, INDF ;w = data to send bank ApplicationBank ;ensure correct register bank dec DataCounter ;Z is set if no more data to send retp ;Z is clear if more data to send lmp2appRxCommData (w=data) Incoming IrComm data. lmp2appRxCommValid () Data bytes passed since last Valid/Error message have been validated. lmp2appRxCommError () Data bytes passed since last Valid/Error message are erroneous. lmp2appTxCommStart (ret z=none) A request to find out if the application has IrComm data waiting to be
sent.
lmp2appTxCommData (ret w=data, z=last) A request for IrComm data so that it can be transmitted. lmp2appTxCommValid () All data passed since last Valid/Error message were acknowledged as
received by the remote station.
lmp2appTxCommError () All data passed since last Valid/Error message were discarded and will
need to be sent again.
Figure 3-10.  IrComm API