;=============================================================================== ; SPLat Controls. ; ; Product Development Group ; ; Melbourne, AUSTRALIA ; ;=============================================================================== ;PURPOSE: ; SEXI application for a DR240. Maps all the DR240 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 iDipSw0 iEQU 8 iDipSw1 iEQU 9 iDipSw2 iEQU 10 iDipSw3 iEQU 11 ;-- digital outputs -- oRly0 oEQU 0 oRly1 oEQU 1 oRly2 oEQU 2 oRly3 oEQU 3 oRly4 oEQU 4 oRly5 oEQU 5 oRly6 oEQU 6 oRly7 oEQU 7 oLedOn oEQU 8 oLedGreen oEQU 9 ;-- analogue inputs -- aiVdd EQU 0 ;-- 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 3 XWabInputBuffer defBLOCK XWkInputLen XWbInputSeq defBYTE XWbInputs0_7 defBYTE XWbInputK0_7 defBYTE XWkOutputLen #EQU 3 XWabOutputBuffer defBLOCK XWkOutputLen XWbInputSeqEcho defBYTE XWbOutput0_7 defBYTE XWbBlink0_7 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 SetMem XWbOutput0_7,0 SetMem XWbBlink0_7,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 InputM 0 ;capture debounced input levels Store XWbInputs0_7 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 ;--echo blink Recall XWbBlink0_7 ;update blink outputs BlinkM 0 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