<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Awlsim project file generated by awlsim-0.65.0-pre -->
<awlsim_project date_create="2016-03-16 00:00:00.000000"
                date_modify="2018-06-22 21:17:25.341065"
                format_version="1">
	<!-- CPU core configuration -->
	<cpu>
		<!-- CPU core feature specification -->
		<specs call_stack_size="256"
		       nr_accus="2"
		       nr_counters="256"
		       nr_flags="2048"
		       nr_inputs="128"
		       nr_localbytes="1024"
		       nr_outputs="128"
		       nr_timers="256"
		       parenthesis_stack_size="7" />

		<!-- CPU core configuration -->
		<config clock_memory_byte="-1"
		        cycle_time_limit_us="1000000"
		        ext_insns_enable="1"
		        mnemonics="2"
		        ob_startinfo_enable="0"
		        run_time_limit_us="-1" />
	</cpu>

	<!-- AWL/STL language configuration -->
	<language_awl>
		<!-- AWL/STL source code -->
		<source enabled="1"
		        name="source"
		        type="0"><![CDATA[
// Digital input (DI) / output (DO) tests.
// PiXtend DIs are wired to EB 1
// PiXtend DOs are wired to AB 1
FUNCTION FC 1 : VOID
BEGIN
	// Calculate the expected EB 1 from AB 1.
	// The fake PiXtend spidev module wires DI do DO in the following way:
	// EB1 := ((AB1 & 0x3F) | (((AB1 ^ 0x03) & 0x03) << 6))
	L		AB 1
	UW		W#16#3F
	L		AB 1
	XOW		W#16#03
	UW		W#16#03
	SLW		6
	OW
	T		MB 10

	// Compare the actual EB 1 to the expected EB 1 (MB 10)
	L		EB 1
	L		MB 10
	__ASSERT==	__ACCU 1,	__ACCU 2

	// Increment the EB 1 / AB 1 test pattern by one
	L		AB 1
	+		1
	T		AB 1
END_FUNCTION


// GPIO tests
// PiXtend GPIO 0 is wired to E 2.0
// PiXtend GPIO 1 is wired to A 2.0
FUNCTION FC 2 : VOID
BEGIN
	// Calculate the expected E 2.0 from A 2.0
	// The fake PiXtend spidev module wires GPIO 1 to GPIO 0
	L		AB 2
	UW		W#16#01
	T		MB 20

	// Compare the actual EB 1 to the expected EB 1 (MB 20)
	L		EB 2
	L		MB 20
	__ASSERT==	__ACCU 1,	__ACCU 2

	// Increment the EB 2 / AB 2 test pattern by one
	L		AB 2
	+		1
	T		AB 2
END_FUNCTION


// Analog input tests
FUNCTION FC 3 : VOID
BEGIN
	// Check AI0
	// The fake PiXtend spidev module always reports 1 V
	L		EW 10
	L		2754
	__ASSERT==	__ACCU 1,	__ACCU 2

	// Check AI1
	// The fake PiXtend spidev module always reports 2 V
	L		EW 12
	L		5535
	__ASSERT==	__ACCU 1,	__ACCU 2

	// Check AI2
	// The fake PiXtend spidev module always reports 20.1 mA
	L		EW 14
	L		27663
	__ASSERT==	__ACCU 1,	__ACCU 2

	// Check AI3
	// The fake PiXtend spidev module always reports 14.1 mA
	L		EW 16
	L		17295
	__ASSERT==	__ACCU 1,	__ACCU 2
END_FUNCTION


// Analog output tests
FUNCTION FC 4 : VOID
BEGIN
	// Check DAC_A
	// The magic value is checked by the fake PiXtend-Spidev module
	L		27648
	T		AW 10
	
	// Check DAC_B
	// The magic value is checked by the fake PiXtend-Spidev module
	L		2764
	T		AW 12
END_FUNCTION


// PWM output tests
FUNCTION FC 5 : VOID
BEGIN
	// Set PWM0
	// The magic value is checked by the fake PiXtend-Spidev module
	L		W#16#1234
	T		AW 20
	
	// Set PWM1
	// The magic value is checked by the fake PiXtend-Spidev module
	L		W#16#4321
	T		AW 22
END_FUNCTION


ORGANIZATION_BLOCK OB 1
BEGIN
	// This test only works with the fake PiXtend-Spidev module

	CALL		FC 1	// Test DI/DO
	CALL		FC 2	// Test GPIOs
	CALL		FC 3	// Test analog inputs
	CALL		FC 4	// Test analog outputs
	CALL		FC 5	// Test PWMs

	// If we ran 256 test cycles then exit.
	L		MW 100
	+		1
	T		MW 100
	L		256
	<I
	BEB
	CALL		SFC 46 // Exit test; Stop CPU.
END_ORGANIZATION_BLOCK


ORGANIZATION_BLOCK OB 100
BEGIN
	L		0
	T		AB 1
	T		AB 2
	T		MW 100
	CALL		FC 4	// Init analog outputs
	CALL		FC 5	// Init PWMs
END_ORGANIZATION_BLOCK

]]></source>
	</language_awl>

	<!-- Symbol table configuration -->
	<symbols>
		<!-- symbol table source code -->
		<source enabled="1"
		        name="Main table"
		        type="3"><![CDATA[

]]></source>
	</symbols>

	<!-- Core server link configuration -->
	<core_link>
		<!-- Locally spawned core server -->
		<spawn_local enable="1"
		             interpreters="$DEFAULT"
		             port_range_begin="4183"
		             port_range_end="8278" />

		<!-- Remote server connection -->
		<connect host="localhost"
		         port="4151"
		         timeout_ms="3000" />

		<!-- Transport tunnel -->
		<tunnel local_port="-1"
		        type="0">
			<ssh executable="ssh"
			     port="22"
			     user="pi" />
		</tunnel>
	</core_link>

	<!-- Hardware modules configuration -->
	<hardware>
		<!-- Loaded hardware module -->
		<module name="pixtend">
			<params>
				<param name="analogIn0_10V"
				       value="True" />
				<param name="analogIn0_addr"
				       value="IW 10" />
				<param name="analogIn0_nos"
				       value="10" />
				<param name="analogIn1_10V"
				       value="True" />
				<param name="analogIn1_addr"
				       value="IW 12" />
				<param name="analogIn1_nos"
				       value="10" />
				<param name="analogIn2_addr"
				       value="IW 14" />
				<param name="analogIn2_nos"
				       value="10" />
				<param name="analogIn3_addr"
				       value="IW 16" />
				<param name="analogIn3_nos"
				       value="10" />
				<param name="analogIn_kHz"
				       value="125" />
				<param name="analogOut0_addr"
				       value="AW 10" />
				<param name="analogOut1_addr"
				       value="AW 12" />
				<param name="boardType"
				       value="v1.x" />
				<param name="digitalIn0_addr"
				       value="I 1.0" />
				<param name="digitalIn1_addr"
				       value="I 1.1" />
				<param name="digitalIn2_addr"
				       value="I 1.2" />
				<param name="digitalIn3_addr"
				       value="I 1.3" />
				<param name="digitalIn4_addr"
				       value="I 1.4" />
				<param name="digitalIn5_addr"
				       value="I 1.5" />
				<param name="digitalIn6_addr"
				       value="I 1.6" />
				<param name="digitalIn7_addr"
				       value="I 1.7" />
				<param name="digitalOut0_addr"
				       value="Q1.0" />
				<param name="digitalOut1_addr"
				       value="Q1.1" />
				<param name="digitalOut2_addr"
				       value="Q1.2" />
				<param name="digitalOut3_addr"
				       value="Q1.3" />
				<param name="digitalOut4_addr"
				       value="Q1.4" />
				<param name="digitalOut5_addr"
				       value="Q1.5" />
				<param name="enabled"
				       value="True" />
				<param name="gpio0_addr"
				       value="I 2.0" />
				<param name="gpio0_hum_addr" />
				<param name="gpio0_mode"
				       value="GPIO" />
				<param name="gpio0_pullup"
				       value="False" />
				<param name="gpio0_temp_addr" />
				<param name="gpio1_addr"
				       value="Q 2.0" />
				<param name="gpio1_hum_addr" />
				<param name="gpio1_mode"
				       value="GPIO" />
				<param name="gpio1_pullup"
				       value="False" />
				<param name="gpio1_temp_addr" />
				<param name="gpio2_addr" />
				<param name="gpio2_hum_addr" />
				<param name="gpio2_mode"
				       value="GPIO" />
				<param name="gpio2_pullup"
				       value="False" />
				<param name="gpio2_temp_addr" />
				<param name="gpio3_addr" />
				<param name="gpio3_hum_addr" />
				<param name="gpio3_mode"
				       value="GPIO" />
				<param name="gpio3_pullup"
				       value="False" />
				<param name="gpio3_temp_addr" />
				<param name="inputAddressBase"
				       value="0" />
				<param name="outputAddressBase"
				       value="0" />
				<param name="pollIntMs"
				       value="25" />
				<param name="pwm0A_addr"
				       value="AW 20" />
				<param name="pwm0B_addr"
				       value="AW 22" />
				<param name="pwm0_baseFreqHz"
				       value="16000000" />
				<param name="pwm0_mode"
				       value="dutycycle" />
				<param name="pwm0_period"
				       value="65000" />
				<param name="pwm1A_addr" />
				<param name="pwm1B_addr" />
				<param name="pwm1_baseFreqHz"
				       value="0" />
				<param name="pwm1_mode"
				       value="dutycycle" />
				<param name="pwm1_period" />
				<param name="pwm_servoMode"
				       value="False" />
				<param name="relay0_addr"
				       value="Q 0.0" />
				<param name="relay1_addr"
				       value="Q 0.1" />
				<param name="relay2_addr"
				       value="Q 0.2" />
				<param name="relay3_addr"
				       value="Q 0.3" />
				<param name="rs485"
				       value="True" />
				<param name="testMode"
				       value="True" />
			</params>
		</module>
	</hardware>

	<!-- Graphical user interface configuration -->
	<gui>
		<editor autoindent="1"
		        paste_autoindent="1"
		        validation="1" />
	</gui>
</awlsim_project>
