;=============================================================================== ; SPLat Controls. ; ; Product Development Group ; ; Melbourne, AUSTRALIA ; ;=============================================================================== ;PURPOSE: ; SEXI application for a DT16. Maps all the DT16 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 XWsubInitialise ;=============================================================================== ; ; ; ;=============================================================================== ;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 100 ;=============================================================================== ; ; ;RAM storage ; ;=============================================================================== ;=============================================================================== ; ; ;I/O Assignments ; ;=============================================================================== ;-- digital inputs -- iIn0 iEQU 0 iIn1 iEQU 1 iIn2 iEQU 2 iIn3 iEQU 3 iIn4 iEQU 4 iIn5 iEQU 5 iIn6 iEQU 6 iIn7 iEQU 7 iIn8 iEQU 8 iIn9 iEQU 9 iIn10 iEQU 10 iIn11 iEQU 11 iIn12 iEQU 12 iIn13 iEQU 13 iIn14 iEQU 14 iIn15 iEQU 15 iDipSw1 iEQU 16 iDipSw2 iEQU 17 iDipSw3 iEQU 18 iDipSw4 iEQU 19 ;-- digital outputs -- oOut0 oEQU 0 oOut1 oEQU 1 oOut2 oEQU 2 oOut3 oEQU 3 oOut4 oEQU 4 oOut5 oEQU 5 oOut6 oEQU 6 oOut7 oEQU 7 oOut8 oEQU 8 oOut9 oEQU 9 oOut10 oEQU 10 oOut11 oEQU 11 oOut12 oEQU 12 oOut13 oEQU 13 oOut14 oEQU 14 oOut15 oEQU 15 oLedOn oEQU 16 oLedGreen oEQU 17 ;-- analogue inputs -- aiIn0 EQU 0 aiIn1 EQU 1 ;-- analogue outputs -- ;-- serial -- COMTTL EQU 251 COM485 EQU 252 COMUSB EQU 253 ;-- XwirePhys -- XWPhyTTL EQU 0 XWPhy485 EQU 1 ;=============================================================================== ; ;AUTOMATIC RAM ; ;=============================================================================== ; XWsWafEqual defSEM XWsPhy485 defSEM ; XWbAddress defBYTE ; ; ; ; XWkInputLen #EQU 13 XWabInputBuffer defBLOCK XWkInputLen XWbInputSeq defBYTE XWbInputs0_7 defBYTE XWbInputs8_15 defBYTE XWbInputK0_7 defBYTE XWbInputK8_15 defBYTE XWfAnalogIn0 defFLOAT XWfAnalogIn1 defFLOAT XWkOutputLen #EQU 5 XWabOutputBuffer defBLOCK XWkOutputLen XWbInputSeqEcho defBYTE XWbOutput0_7 defBYTE XWbOutput8_15 defBYTE XWbBlink0_7 defBYTE XWbBlink8_15 defBYTE ;=============================================================================== ; ; ; ;=============================================================================== ;=============================================================================== ;DESCRIPTION: ; Start running the tasks. 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: ; <- ;=============================================================================== XWsubInitialise: Pause 10 GoSub subGetAddress Push Store XWbAddress ;remember the address XwireSetAddr ;set I/O board address from dip sw (0 thru 15) GoSub XWsubSetPhys XwireSlave XWpSlave ;start Xwire LaunchTask taskSEXI ;I/O processing task LaunchTask taskAddress 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. ;=============================================================================== taskSEXI: ;Xwire communications lost, turn off all outputs LoadX 0 LoadX %11111111 OutputM 0 ;digital 0 thru 7 LoadX 0 LoadX %11111111 OutputM 8 ;digital 8 thru 15 SetMem XWbOutput0_7,0 SetMem XWbOutput8_15,0 SetMem XWbBlink0_7,0 SetMem XWbBlink8_15,0 Off oLedGreen ;signal we have.. On oLedOn ;..no connection SetMem XWbInputSeq,0 ;setup start up synchronisation SetMem XWbInputSeqEcho,255 SetS XWsWafEqual _XWWafFirstPacket MarkTime ;start the interface toggle timer _XWWafFirstPacketLoop YieldTask GoIfMz XWbInputSeqEcho,_XWGotConnection ;wait for master's first output update LoopIfTiming 100,_XWWafFirstPacketLoop ;waf 1 second GoSub subTogglePhys ;try the other interface Goto _XWWafFirstPacket ;restart the timer _XWGotConnection On oLedGreen ;signal we are now.. On oLedOn ;..connected _XWSendInputs ;-- capture latches LoadX %11111111 ;capture rising edge flags InputMK 0 Store XWbInputK0_7 LoadX %11111111 InputMK 8 Store XWbInputK8_15 ;-- capture digital inputs InputM 0 ;capture debounced input levels Store XWbInputs0_7 InputM 8 Store XWbInputs8_15 ;-- capture analogue inputs fAnIn 0 ;pass latest analogue values to the master fStore XWfAnalogIn0 fAnIn 1 fStore XWfAnalogIn1 Recall XWbInputSeq ;increment the sEQUence number but avoid zero IncX Push GoIfnz _XWStoreSeq IncX _XWStoreSeq Store XWbInputSeq XwireGetPollCntr ;reset the poll counter MarkTime _XWWafNewPacket YieldTask Recall XWbInputSeqEcho ;get the seq number echoed back from the master GoIfST XWsWafEqual,_XWChkEqual ;for the first packet, we await sync XwireGetPollCntr ;have we been polled by the master? GoIfZ _XWChkEqual ;jump if not, wait for master to echo our sEQUence number back to us IncX ;owise, we'll allow the master's seq number to be one behind ours Push ;but skip.. GoIfnz _XWChkEqual IncX ;..zero _XWChkEqual Recall XWbInputSeq ;get our seq number Compare GoIfz _XWHandleNewPacket ;jump if the sequence numbers match (or we've been polled and it's one behind) LoopIfTiming XWkErrorTime,_XWWafNewPacket ;check for Xwire communication error Goto taskSEXI ;owise comms lost, outputs off and re-synchronise _XWHandleNewPacket ClrS XWsWafEqual ;now we've been polled, we'll allow our sync to be one ahead for speed ;--echo digital outputs Recall XWbOutput0_7 ;update outputs if not being blinked Recall XWbBlink0_7 NotM OutputM 0 Recall XWbOutput8_15 Recall XWbBlink8_15 NotM OutputM 8 ;--echo blink Recall XWbBlink0_7 ;update blink outputs BlinkM 0 Recall XWbBlink8_15 BlinkM 8 Goto _XWSendInputs ;=============================================================================== ;DESCRIPTION: ; Monitors the DIP SW and sets the new address if it's changed. ;PARAMETERS: ; -> Nil ;RETURNS: ; <- Nil ;=============================================================================== taskAddress: Pause 100 GoSub subGetAddress ;get the DIP switch address Push Recall XWbAddress ;get the last address we used Compare GoIfZ taskAddress ;loop over if unchanged _ADDRRememberNew Store XWbAddress ;save the new address Pause 100 ;wait another second GoSub subGetAddress ;get the DIP switch address Push Recall XWbAddress ;get the last address we used Compare GoIfNZ _ADDRRememberNew ;loop over if changed XwireSetAddr ;it's now been unchanged for 1 sec, so use it Goto taskAddress ;=============================================================================== ;DESCRIPTION: ; Fetches the address from the DIP SW. ;PARAMETERS: ; -> Nil ;RETURNS: ; <- x:address ;=============================================================================== subGetAddress: InputM iDipSw1 ;figure dip sw LoadX %00001111 AndM ;..value Return ;=============================================================================== ;DESCRIPTION: ; Called when there's no comms connection, tries the other interface. ;PARAMETERS: ; -> Nil ;RETURNS: ; <- Nil ;=============================================================================== subTogglePhys: NotS XWsPhy485 ;choose the other interface Goto XWsubSetPhys ;=============================================================================== ;DESCRIPTION: ; ;PARAMETERS: ; -> Nil ;RETURNS: ; <- Nil ;=============================================================================== XWsubSetPhys: GoIfST XWsPhy485,_PHY485 ;jump if we're now trying 485 XwirePhys XWPhyTTL Return _PHY485 XwirePhys XWPhy485 Return ;=============================================================================== ; ; ; ;=============================================================================== ;=============================================================================== ; ; ; ;=============================================================================== ;=============================================================================== ; ; ; ;=============================================================================== NVEM0 ;Start of non-volatile memory ;=============================================================================== ; ; ;Non-volatile memory data ; ;=============================================================================== XWpSlave NV0Byte XWabInputBuffer,XWkInputlen,XWabOutputBuffer,XWkOutputLen