<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Awlsim project file generated by awlsim-0.66.0-pre -->
<awlsim_project date_create="2015-01-04 14:29:54.007468"
                date_modify="2018-07-08 18:00:06.516647"
                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="0"
		        mnemonics="0"
		        ob_startinfo_enable="0"
		        run_time_limit_us="-1" />
	</cpu>

	<!-- AWL/STL language configuration -->
	<language_awl>
		<!-- AWL/STL source code -->
		<source enabled="1"
		        name="OB 1"
		        type="0"><![CDATA[
ORGANIZATION_BLOCK OB 1
	VAR_TEMP
		OB1_EV_CLASS   : BYTE;          // Bits 0-3 = 1 (Coming event), Bits 4-7 = 1 (Event class 1)
		OB1_SCAN_1     : BYTE;          // 1 (Cold restart scan 1 of OB 1), 3 (Scan 2-n of OB 1)
		OB1_PRIORITY   : BYTE;          // Priority of OB execution
		OB1_OB_NUMBR   : BYTE;          // 1 (Organization block 1, OB 1)
		OB1_RESERVED_1 : BYTE;
		OB1_RESERVED_2 : BYTE;
		OB1_PREV_CYCLE : INT;           // Cycle time of previous OB 1 scan (milliseconds)
		OB1_MIN_CYCLE  : INT;           // Minimum cycle time of OB 1 (milliseconds)
		OB1_MAX_CYCLE  : INT;           // Maximum cycle time of OB 1 (milliseconds)
		OB1_DATE_TIME  : DATE_AND_TIME; // Date and time OB 1 started
	END_VAR
BEGIN
	
	CALL "FC_heartbeat"
	CALL "FC_limit_switches"
	CALL "FC_home_switches"
	CALL "FC_spindle"
	CALL "FC_coolant"
	CALL "FC_estop"
	
END_ORGANIZATION_BLOCK

]]></source>

		<!-- AWL/STL source code -->
		<source enabled="1"
		        name="Heartbeat"
		        type="0"><![CDATA[
FUNCTION "FC_heartbeat" : VOID
BEGIN
	// Generate the heartbeat output
	UN	"HB_out_Tb"
	=	"Heartbeat_out"
	L	S5T#100ms
	SV	"HB_out_Ta"
	UN	"HB_out_Ta"
	L	S5T#100ms
	SV	"HB_out_Tb"
	
	// Check the heartbeat input
	U	"Heartbeat_in"
	L	S5T#500ms
	SA	"HB_in_T"
	U	"HB_in_T"
	=	"Heartbeat_in_ok"
END_FUNCTION

]]></source>

		<!-- AWL/STL source code -->
		<source enabled="1"
		        name="E-stop"
		        type="0"><![CDATA[
FUNCTION "FC_estop" : VOID
BEGIN
	// Create our emergency stop signal
	U	"Estop_in_not"
	U	"Heartbeat_in_ok"
	=	"Estop_out_not"
END_FUNCTION

]]></source>

		<!-- AWL/STL source code -->
		<source enabled="1"
		        name="Limit switches"
		        type="0"><![CDATA[
FUNCTION "FC_limit_switches" : VOID
BEGIN
	// Emulate limit switches
	
	// X
	O(
	L	"X_position_in"
	L	1.0
	>=R
	)
	O(
	L	"X_position_in"
	L	-201.0
	<=R
	)
	=	"X_limit_out"
	
	// Y
	O(
	L	"Y_position_in"
	L	1.0
	>=R
	)
	O(
	L	"Y_position_in"
	L	-201.0
	<=R
	)
	=	"Y_limit_out"
	
	// Z
	O(
	L	"Z_position_in"
	L	1.0
	>=R
	)
	O(
	L	"Z_position_in"
	L	-201.0
	<=R
	)
	=	"Z_limit_out"
END_FUNCTION

]]></source>

		<!-- AWL/STL source code -->
		<source enabled="1"
		        name="Home switches"
		        type="0"><![CDATA[
FUNCTION "FC_home_switches" : VOID
BEGIN
	// Emulate home switches
	
	// X
	U(
	L	"X_position_in"
	L	-10.0
	<=R
	)
	U(
	L	"X_position_in"
	L	-15.0
	>=R
	)
	=	"X_home_out"
	
	// Y
	U(
	L	"Y_position_in"
	L	-10.0
	<=R
	)
	U(
	L	"Y_position_in"
	L	-15.0
	>=R
	)
	=	"Y_home_out"
	
	// Z
	U(
	L	"Z_position_in"
	L	-10.0
	<=R
	)
	U(
	L	"Z_position_in"
	L	-15.0
	>=R
	)
	=	"Z_home_out"
END_FUNCTION

]]></source>

		<!-- AWL/STL source code -->
		<source enabled="1"
		        name="Spindle"
		        type="0"><![CDATA[
FUNCTION "FC_spindle" : VOID
BEGIN
	// TODO: Handle spindle signals
	// "Spindle_cw_in"
	// "Spindle_ccw_in"
END_FUNCTION

]]></source>

		<!-- AWL/STL source code -->
		<source enabled="1"
		        name="Coolant"
		        type="0"><![CDATA[
FUNCTION "FC_coolant" : VOID
BEGIN
	// TODO: Handle coolant signals
	// "Coolant_mist_in"
	// "Coolant_flood_in"
END_FUNCTION

]]></source>
	</language_awl>

	<!-- Symbol table configuration -->
	<symbols>
		<!-- symbol table source code -->
		<source enabled="1"
		        name="Inputs / outputs"
		        type="3"><![CDATA[
126,X_position_in           ED 0        REAL      The current position (X)
126,Y_position_in           ED 4        REAL      The current position (Y)
126,Z_position_in           ED 8        REAL      The current position (Z)
126,Heartbeat_in            E 12.0      BOOL      LinuxCNC heartbeat input
126,Estop_in_not            E 12.1      BOOL      Emergency stop input
126,Spindle_cw_in           E 12.2      BOOL      Spindle "clockwise" enable input
126,Spindle_ccw_in          E 12.3      BOOL      Spindle "counterclockwise" enable input
126,Coolant_mist_in         E 12.4      BOOL      Mist coolant enable input
126,Coolant_flood_in        E 12.5      BOOL      Flood coolant enable input
126,X_limit_out             A 0.0       BOOL      Limit switch output (X)
126,Y_limit_out             A 0.1       BOOL      Limit switch output (Y)
126,Z_limit_out             A 0.2       BOOL      Limit switch output (Z)
126,X_home_out              A 1.0       BOOL      Home switch output (X)
126,Y_home_out              A 1.1       BOOL      Home switch output (Y)
126,Z_home_out              A 1.2       BOOL      Home switch output (Z)
126,Heartbeat_out           A 2.0       BOOL      LinuxCNC heartbeat output
126,Estop_out_not           A 2.1       BOOL      Emergency stop output

]]></source>

		<!-- symbol table source code -->
		<source enabled="1"
		        name="Flags"
		        type="3"><![CDATA[
126,Heartbeat_in_ok         M 0.0       BOOL      Result of the Heartbeat_in check

]]></source>

		<!-- symbol table source code -->
		<source enabled="1"
		        name="Timers"
		        type="3"><![CDATA[
126,HB_out_Ta               T 1         TIMER     Heartbeat_out timer A
126,HB_out_Tb               T 2         TIMER     Heartbeat_out timer B
126,HB_in_T                 T 3         TIMER     Heartbeat_in check timer

]]></source>

		<!-- symbol table source code -->
		<source enabled="1"
		        name="Functions"
		        type="3"><![CDATA[
126,FC_heartbeat            FC 1        FC 1      Function for heartbeat handling
126,FC_estop                FC 2        FC 2      Function for emergency stop handling
126,FC_limit_switches       FC 3        FC 3      Function for handling limit switches
126,FC_home_switches        FC 4        FC 4      Function for handling home switches
126,FC_spindle              FC 5        FC 5      Function for spindle handling
126,FC_coolant              FC 6        FC 6      Function for coolant handling

]]></source>
	</symbols>

	<!-- Core server link configuration -->
	<core_link>
		<!-- Locally spawned core server -->
		<spawn_local enable="0"
		             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="dummy">
			<params>
				<param name="inputAddressBase"
				       value="128" />
				<param name="outputAddressBase"
				       value="128" />
			</params>
		</module>

		<!-- Loaded hardware module -->
		<module name="linuxcnc">
			<params>
				<param name="hal" />
				<param name="inputAddressBase"
				       value="0" />
				<param name="inputSize"
				       value="16" />
				<param name="outputAddressBase"
				       value="0" />
				<param name="outputSize"
				       value="8" />
			</params>
		</module>
	</hardware>

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