;=============================================================================== ; SPLat Controls. ; ; Product Development Group ; ; Melbourne, AUSTRALIA ; ;=============================================================================== ;PURPOSE: ; SEXI application for a UI216. Maps all the UI420 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 RunTasksForever ;=============================================================================== ; ; ; ;=============================================================================== ;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 ; ;=============================================================================== ;--perm mem, 6 thru 18 XWIObInterface EQU 6 ;=============================================================================== ; ; ;I/O Assignments ; ;=============================================================================== ;-- digital inputs -- iPot0 iEQU 0 iPot1 iEQU 1 iBtnLeft iEQU 2 iBtnMid iEQU 3 iBtnRight iEQU 4 iBtnDn iEQU 5 iBtnUp iEQU 6 ;-- digital outputs -- oLED0On oEQU 0 oLED0Green oEQU 1 oBuzzer oEQU 2 oBacklight oEQU 3 ;-- analogue inputs -- ;-- analogue outputs -- ;-- serial -- ;=============================================================================== ; ;AUTOMATIC RAM ; ;=============================================================================== ; ; ; ; ; ; 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: ; Initialises the SEXI slave task at power-on ;PARAMETERS: ; -> ;RETURNS: ; <- ;=============================================================================== XWIOsubInitialise: On oBacklight Pause 10 GoSub XWIOsubSetInterface LoadX 10 ;set I/O board address XwireSetAddr XwireSlave XWStab ;start Xwire LaunchTask XWIOTask 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: LoadX 0 ;signal we have.. LoadX %11111111 OutputM 0 On oLED0On ;..no connection OBLCD_Cls OBLCD_Dim 0,5,3 ;0123456789012345 OBLCD_Text "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 OBLCD_Cls ;master now controls the LCD Off oLED0On ;master now controls the LED OBLCD_Dim 0,5,3 ;default the backlight to low=0 (off), on=5 (8 is max), delay on->low=3minutes _XWIOSendInputs 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 _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 %11111111 OutputM 0 ;digital 0 thru 7 Goto XWIOTask ;re-synchronise _XWIOHandleNewPacket Recall XWbOutput0_7 ;update outputs if not being blinked Recall XWbBlink0_7 NotM OutputM 0 Recall XWbBlink0_7 ;update blink outputs BlinkM 0 Goto _XWIOSendInputs ;=============================================================================== ;DESCRIPTION: ; This routine is called at power on to set the Xwire interface as either TTL ; or RS485. Holding the UP button will force TTL while the DOWN button will ; force 485. These will be remembered and automatically used at the next power ; on if no button is pressed. ;PARAMETERS: ; -> Nil ;RETURNS: ; <- Nil ;=============================================================================== XWIOsubSetInterface: GoIfInOn iBtnUp,_XWIOSetTTL ;if the button is being pressed at power on, force the interface to TTL GoIfInOn iBtnDn,_XWIOSet485 ;if the button is being pressed at power on, force the interface to 485 PermRecall ;owise recall what it was last time GoIfXge 2,Return ;jump if perm recall failed GoIfMgt XWIObInterface,1,Return ;owise jump if recalled interface number illegal (default to TTL) BranchM XWIObInterface Target _XWIODoTTL Target _XWIODo485 _XWIODoTTL XwirePhys 0 Return _XWIODo485 XwirePhys 1 Return _XWIOSetTTL ;0123456789012345 OBLCD_Text "Xwire set to TTL" ;show a message XwirePhys 0 LoadX 0 Goto _XWIOStoreInterface _XWIOSet485 ;0123456789012345 OBLCD_Text "Xwire set to 485" XwirePhys 1 LoadX 1 Goto _XWIOStoreInterface _XWIOStoreInterface Store XWIObInterface ;store the new interface PermStore ;remember for next time Pause 200 ;leave the message for a couple of seconds OBLCD_Cls Return ;=============================================================================== ;DESCRIPTION: ; Allows return as a goto. ;PARAMETERS: ; -> Nil ;RETURNS: ; <- Nil ;=============================================================================== Return: Return ;=============================================================================== ; ; ; ;=============================================================================== ;=============================================================================== ; ; ; ;=============================================================================== ;=============================================================================== ; ; ; ;=============================================================================== NVEM0 ;Start of non-volatile memory ;=============================================================================== ; ; ;Non-volatile memory data ; ;=============================================================================== XWStab NV0Byte XWabInputBuffer,XWkInputLen,XWabOutputBuffer,XWkOutputLen