Knowledge Base
==============================================================================
= Sample program gets and display the IP address of the SX10509.  Runs on    =
= either a MS120 or MMi202                                                   =
==============================================================================
;--Network Commands
kCMD_Idle         EQU      '00
kCMD_WriteA       EQU      '01
kCMD_WriteB       EQU      '81
kCMD_ReadA        EQU      '02
kCMD_ReadB        EQU      '82
kCMD_ServerA      EQU      '03
kCMD_ServerB      EQU      '83
kCMD_Port         EQU      '04
kCMD_PathA        EQU      '05
kCMD_PathB        EQU      '85
kCMD_ContentTypeA EQU      '06
kCMD_ContentTypeB EQU      '86
kCMD_DoGet        EQU      '07
kCMD_DoPost       EQU      '08
kCMD_GetID        EQU      '09
kCMD_GetGMT       EQU      '0A
kCMD_GetIP        EQU      '0B

;SX10509 NETWORK buffer
                  defBLOCK 32        ;transmit buffer
bTxCmd            defBYTE            ;command (bit 7 toggles the next iteration of the current command)
bTxLength         defBYTE            ;length of transmit data
kTxDataLen        EQU      30
abTxData          defBYTE  30        ;transmit data

                  defBLOCK 32        ;receive buffer (chose 32 as this is the SX10509 default)
bRxCmdDone        defBYTE            ;copy of the last completed command (will match bTxCmd when done)
bRxLength         defBYTE            ;receive data length
kRxDataLen        EQU      30
abRxData          defBYTE  30        ;received data


   XwireMaster    pXwireTable        ;run the controller as an Xwire master
   OBLCD_Cls                         ;clear the LCD
   OBLCD_Text     "Requesting..."    ;display a message
_RequestIP:
   LoadX          kCMD_GetIP         ;ask the SX10509 for..
   Store          bTxCmd             ;..its IP address
_WAFIP:
   GoIfMNE        bRxCmdDone,kCMD_GetIP,_WAFIP ;loop until we get a reply
   OBLCD_Cls                         ;clear the screen
   OBLCD_Text     "IP:"              ;display the title
   OBLCD_SetCur   1,0                ;next line
   LoadI          0                                   ;start with the first IP byte
_IPPrintLoop:
   iRecall        bRxLength         ;get the IP byte
   OBLCD_UDecDispXVW                ;display the number
   IncI                             ;move the index to the next IP byte
   ItoX                             ;have we displayed all..
   GoIfXEQ        4,_EndIPPrint     ;..the bytes?  jump if yes.
   OBLCD_Text     "."               ;otherwise more bytes to display, so add a '.' separator
   Goto           _IPPrintLoop      ;display the next byte
_EndIPPrint:
   LoadX          kCMD_Idle         ;optional, inform the controller..
   Store          bTxCmd            ;..we've finished (will allow us to ask for the IP again)
   Pause          10                ;sleep for a bit
   Goto           _RequestIP        ;request the IP again


;============================================================
   NVEM0                                              ;start of NVM data

pXwireTable
   ;SX10509 Xwire NETWORK configuration
   NV0Byte     64                   ;Address of the SPLat Call Home board
   NV0Byte     bTxCmd               ;Address of the Tx buffer
   NV0Byte     32                   ;Length of the Tx buffer
   NV0Byte     bRxCmdDone           ;Address of the Rx buffer
   NV0Byte     32                   ;Length of the Rx buffer

   NV0Byte     255