;=============================================================================== ; SPLat Controls. ; ; Product Development Group ; ; Melbourne, AUSTRALIA ; ;=============================================================================== ;PURPOSE: ; SEXI application for a DA8. Maps all the DA8 I/O into the SEXI address ; space. ; ;=============================================================================== ;=============================================================================== ; Copyright (c) 2015 SPLat Controls. All rights reserved. ; ; ; ; THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SPLat Controls. ; ; The copyright notice above does not evidence any ; ; actual or intended publication of such source code. ; ;=============================================================================== ;=============================================================================== ; ; ; ;=============================================================================== GoSub XWIOsubInitialise ;=============================================================================== ; ; ; ;=============================================================================== ;maximum time between Xwire data transfers (sEQUence number changes) before we ;turn off all outputs and return to the synchronisation phase (10ms increments) XWkErrorTime EQU 30 ;=============================================================================== ; ; ;RAM storage ; ;=============================================================================== ;=============================================================================== ; ; ;I/O Assignments ; ;=============================================================================== ;-- digital inputs -- iIn0 iEQU 0 iIn1 iEQU 1 iIn2 iEQU 2 iIn3 iEQU 3 iDipSw0 iEQU 4 iDipSw1 iEQU 5 iDipSw2 iEQU 6 iDipSw3 iEQU 7 ;-- digital outputs -- oOut0 oEQU 0 oOut1 oEQU 1 oOut2 oEQU 2 oOut3 oEQU 3 oLedOn oEQU 4 oLedGreen oEQU 5 ;-- analogue inputs -- aiIn0 EQU 0 aiIn1 EQU 1 aiIn2 EQU 2 aiIn3 EQU 3 aiIn4 EQU 4 aiIn5 EQU 5 aiIn6 EQU 6 aiIn7 EQU 7 ;-- analogue outputs -- aoOut0 EQU 0 aoOut1 EQU 1 ;-- serial -- COMTTL EQU 251 COM485 EQU 252 ;=============================================================================== ; ;AUTOMATIC RAM ; ;=============================================================================== ; ; ; ; ; ; XWkInputLen #EQU 35 XWabInputBuffer defBLOCK XWkInputLen XWbInputSeq defBYTE XWbInputs0_4 defBYTE XWbInputK0_4 defBYTE XWfAnalogIn0 defFLOAT XWfAnalogIn1 defFLOAT XWfAnalogIn2 defFLOAT XWfAnalogIn3 defFLOAT XWfAnalogIn4 defFLOAT XWfAnalogIn5 defFLOAT XWfAnalogIn6 defFLOAT XWfAnalogIn7 defFLOAT XWkOutputLen #EQU 11 XWabOutputBuffer defBLOCK XWkOutputLen XWbInputSeqEcho defBYTE XWbOutput0_4 defBYTE XWbBlink0_4 defBYTE XWfAnalogOut0 defFLOAT XWfAnalogOut1 defFLOAT ;=============================================================================== ; ; ; ;=============================================================================== ;=============================================================================== ;DESCRIPTION: ; This code will only get executed when this file is compiled as a standalone ; application. ;PARAMETERS: ; -> Nil ;RETURNS: ; <- Nil ;=============================================================================== RunTasksForever ;=============================================================================== ;DESCRIPTION: ; Initialises the SEXI slave task at power-on ;PARAMETERS: ; -> ;RETURNS: ; <- ;=============================================================================== XWIOsubInitialise: InputM iDipSw0 ;figure dip sw LoadX %00001111 AndM ;..value XwireSetAddr ;set I/O board address from dip sw (0 thru 15) XwireSlave XWStab ;start Xwire LaunchTask XWIOTask ;I/O processing task Return ;=============================================================================== ;DESCRIPTION: ; This task sends level and edge input data to the Xwire master. A sequence ; number is used to ensure the input data to the Xwire master is only updated ; once the master has acknowledge receipt of the last data set. During ; operation, the slave increments the sequence number and then waits for the ; return sequence number from the master to be equal before reading the lastest ; input data. ;=============================================================================== XWIOTask: Off oLedGreen ;signal we have.. On oLedOn ;..no connection SetMem XWbInputSeq,0 ;setup start up synchronisation SetMem XWbInputSeqEcho,255 _XWIOWafFirstPacket YieldTask GoIfMz XWbInputSeqEcho,_XWIOGotConnection ;wait for masters first output update Goto _XWIOWafFirstPacket _XWIOGotConnection On oLedGreen ;signal we are now.. On oLedOn ;..connected _XWIOSendInputs LoadX %00001111 ;capture rising edge flags, but not the DIP switches InputMK 0 Store XWbInputK0_4 InputM 0 ;capture debounced input levels LoadX %00001111 ;filter off the.. AndM ;..DIP switches Store XWbInputs0_4 fAnIn 0 ;pass latest analogue values to the master fStore XWfAnalogIn0 fAnIn 1 fStore XWfAnalogIn1 fAnIn 2 fStore XWfAnalogIn2 fAnIn 3 fStore XWfAnalogIn3 fAnIn 4 fStore XWfAnalogIn4 fAnIn 5 fStore XWfAnalogIn5 fAnIn 6 fStore XWfAnalogIn6 fAnIn 7 fStore XWfAnalogIn7 Recall XWbInputSeq ;increment the sEQUence number but avoid zero IncX Push GoIfnz _XWIOStoreSeq IncX _XWIOStoreSeq Store XWbInputSeq MarkTime _XWIOWafNewPacket YieldTask Recall XWbInputSeq ;wait for master to echo our sEQUence number back to us Recall XWbInputSeqEcho Compare GoIfz _XWIOHandleNewPacket LoopIfTiming XWkErrorTime,_XWIOWafNewPacket ;check for Xwire communication error LoadX 0 ;Xwire communications lost, turn off all outputs LoadX %00001111 OutputM 0 ;digital 0 thru 3 fLoadW 0.0 fAnOut 0 fAnOut 1 Goto XWIOTask ;re-synchronise _XWIOHandleNewPacket Recall XWbOutput0_4 ;update outputs if not being blinked Recall XWbBlink0_4 NotM LoadX %00001111 ;only update.. AndM ;..the 4 outputs (not the LED) OutputM 0 Recall XWbBlink0_4 ;update blink outputs BlinkM 0 fRecallW XWfAnalogOut0 ;update the analogue outputs fAnOut 0 fRecallW XWfAnalogOut1 fAnOut 1 Goto _XWIOSendInputs ;=============================================================================== ; ; ; ;=============================================================================== ;=============================================================================== ; ; ; ;=============================================================================== ;=============================================================================== ; ; ; ;=============================================================================== NVEM0 ;Start of non-volatile memory ;=============================================================================== ; ; ;Non-volatile memory data ; ;=============================================================================== XWStab NV0Byte XWabInputBuffer,XWkInputlen,XWabOutputBuffer,XWkOutputLen