//------------------------------------------------------
// Toggle/Slide Switch: XJEase device file
// SWITCH_TOGGLE.xje Revision: 1.1
// (c)2002-2007 XJTAG Limited
//
// Disclaimer: XJTAG makes no guarantees whatsoever
// about this code.  You use it at your own risk ...
// This code requires XJTAG version 1.4 or later.
//---------------------------------------------------------

DEVICE NAME := "SWITCH_TOGGLE"

  PINS
    VALUE := 2;
  END;

  DISABLE DEVICE
    // Cannot disable the switch; it is always driving the net,
    // therefore the net must not be driven.
    VALUE := Z;
  END;

  TEST COVERAGE
    VALUE := OPEN HI LO;
  END;

END;

//------------------------------------------------------
// Constants
//------------------------------------------------------

CONST INT RESULT_PASS := FALSE;
CONST INT RESULT_FAIL := TRUE;

//------------------------------------------------------
Test()(INT result)
//------------------------------------------------------

  INT temp;
  INT initialValue;

  SET initialValue := VALUE;

  PRINT("\tChange switch ", DEVICE_REF, " or press a key to abort...\n");

  // Wait for the switch to change state.
  DO
    // Read the switch.
    SET temp := VALUE;
    IF GETKEY() THEN
      result := RESULT_FAIL;
      RETURN;
    END;
  WHILE (temp = initialValue)

  END;

  PRINT("\t...and back again, or press a key to abort...\n");

  // Wait for the switch to change back again
  DO
    SET temp := VALUE;
    IF GETKEY() THEN
      result := RESULT_FAIL;
      RETURN;
    END;
  WHILE (temp != initialValue)
  END;

  result := RESULT_PASS;

END;