<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Awlsim project file generated by awlsim-0.52 -->
<awlsim_project date_create="2016-03-16 00:00:00.000000"
                date_modify="2017-04-26 20:00:29.828096"
                format_version="1">
	<!-- CPU core configuration -->
	<cpu>
		<!-- CPU core feature specification -->
		<specs nr_accus="2"
		       nr_counters="256"
		       nr_flags="2048"
		       nr_inputs="128"
		       nr_localbytes="1024"
		       nr_outputs="128"
		       nr_timers="256" />

		<!-- CPU core configuration -->
		<config clock_memory_byte="16"
		        ext_insns_enable="0"
		        mnemonics="0"
		        ob_startinfo_enable="0" />
	</cpu>

	<!-- AWL/STL language configuration -->
	<language_awl>
		<!-- AWL/STL source code -->
		<source name="Main"
		        type="0"><![CDATA[
ORGANIZATION_BLOCK "OB_CYCLE"
	TITLE		= Main cycle
	AUTHOR		: Michael Buesch <m@bues.ch>
	// LICENSE	: GPLv2+
BEGIN

	// Run the main state machine
	CALL "FC_statemachine" (
		STATE	:= "MW_statemachine",
		T	:= "T_state",
		PERIOD	:= S5T#500ms,
		T_STATE	:= "M_statemachine",
		Z	:= "Z_state",
	)
	L	"MW_statemachine"
	SPL	def
	SPA	_0	// "STATE_LIGHTCHASER"
	SPA	_1	// "STATE_A"
	SPA	_2	// "STATE_W"
	SPA	_3	// "STATE_L"
	SPA	_4	// "STATE_55"
	SPA	_5	// "STATE_AA"
def:	SPA	end


// "STATE_LIGHTCHASER"
_0:	CALL "FC_lightchaser" (
		PERIOD	:= S5T#100ms,
		T	:= "T_lightchaser",
		MINVAL	:= DW#16#01000000,
		MAXVAL	:= DW#16#80000000,
		REG	:= "MD_lightchaser",
		STATE	:= "M_lightchaser_state",
		DIR	:= "M_lightchaser_dir",
	)
	L	"MD_lightchaser"
	SRD	24
	T	"AB_raspi_GPIO"
	SPA	end


// "STATE_A"
_1:	L	'A'
	T	"AB_raspi_GPIO"
	SPA	end


// "STATE_W"
_2:	L	'W'
	T	"AB_raspi_GPIO"
	SPA	end


// "STATE_L"
_3:	L	'L'
	T	"AB_raspi_GPIO"
	SPA	end


// "STATE_55"
_4:	L	B#16#55
	T	"AB_raspi_GPIO"
	SPA	end


// "STATE_AA"
_5:	L	B#16#AA
	T	"AB_raspi_GPIO"
	SPA	end


end:	BE
END_ORGANIZATION_BLOCK

]]></source>

		<!-- AWL/STL source code -->
		<source name="State machine"
		        type="0"><![CDATA[
FUNCTION "FC_statemachine" : VOID
	TITLE		= Main state machine
	AUTHOR		: Michael Buesch <m@bues.ch>
	// LICENSE	: GPLv2+

	VAR_INPUT
		PERIOD	: S5TIME;
	END_VAR
	VAR_IN_OUT
		STATE	: INT;
		T	: TIMER;
		T_STATE	: BOOL;
		Z	: COUNTER;
	END_VAR
BEGIN
	// Self re-arming timer
	U	#T_STATE
	L	#PERIOD
	SV	#T
	UN	#T
	=	#T_STATE

	// State counter
	U	#T_STATE
	ZV	#Z


	// Check if we are in simple "light chaser only" mode
	L	"STATE_LIGHTCHASER"
	T	#STATE
	U	"E_simple_mode"
	SPB	rst


	// Complex mode. Decide by state counter.

	L	"STATE_LIGHTCHASER"
	T	#STATE
	L	#Z
	L	16
	<I
	BEB

	L	"STATE_A"
	T	#STATE
	L	#Z
	L	17
	<I
	BEB

	L	"STATE_W"
	T	#STATE
	L	#Z
	L	18
	<I
	BEB

	L	"STATE_L"
	T	#STATE
	L	#Z
	L	19
	<I
	BEB

	L	"STATE_55"
	T	#STATE
	L	#Z
	L	20
	<I
	BEB

	L	"STATE_AA"
	T	#STATE
	L	#Z
	L	21
	<I
	BEB

	L	"STATE_55"
	T	#STATE
	L	#Z
	L	22
	<I
	BEB

	L	"STATE_AA"
	T	#STATE
	L	#Z
	L	23
	<I
	BEB

	L	"STATE_55"
	T	#STATE
	L	#Z
	L	24
	<I
	BEB

	L	"STATE_AA"
	T	#STATE
	L	#Z
	L	25
	<I
	BEB

rst:	SET
	R	#Z

	BE
END_FUNCTION

]]></source>

		<!-- AWL/STL source code -->
		<source name="Light chaser"
		        type="0"><![CDATA[
FUNCTION "FC_lightchaser" : VOID
	TITLE		= Light chaser
	AUTHOR		: Michael Buesch <m@bues.ch>
	// LICENSE	: GPLv2+

	VAR_INPUT
		PERIOD	: S5TIME;	// Timer period
		T	: TIMER;	// Timer cell
		MINVAL	: DWORD;	// Minimal #REG value
		MAXVAL	: DWORD;	// Maximal #REG value
	END_VAR
	VAR_IN_OUT
		REG	: DWORD;	// Shift register
		STATE	: BOOL;		// Timer state
		DIR	: BOOL;		// Shift direction
	END_VAR
BEGIN
	// Self re-arming timer
	U	#STATE
	L	#PERIOD
	SV	#T
	UN	#T
	=	#STATE

	// Select sweep direction
	L	#MINVAL
	L	#REG
	==D			// #MINVAL reached?
	S	#DIR		// reverse direction
	L	#MAXVAL
	==D			// #MAXVAL reached?
	R	#DIR		// reverse direction

	// Shift #REG, if required
	L	#REG
	UD	L#-1
	L	#MINVAL		// Initial #REG value
	SPZ	_001		// #REG is uninitialized?
	TAK
	U	#STATE		// Next state?
	SPBN	_001
	U	#DIR		// Left or right?
	SPBN	_000
	RLD	2		// Next state (left)
_000:	RRD	1		// Next state (right)
_001:	T	#REG

	BE
END_FUNCTION

]]></source>
	</language_awl>

	<!-- Symbol table configuration -->
	<symbols>
		<!-- symbol table source code -->
		<source name="Blocks"
		        type="3"><![CDATA[
126,OB_CYCLE                OB 1        OB 1                                                                                      
126,FC_statemachine         FC 1        FC 1                                                                                      
126,FC_lightchaser          FC 2        FC 2                                                                                      
126,T_lightchaser           T 0         TIMER                                                                                     
126,T_state                 T 1         TIMER                                                                                     
126,Z_state                 Z 0         COUNTER                                                                                   

]]></source>

		<!-- symbol table source code -->
		<source name="Memory"
		        type="3"><![CDATA[
126,MD_lightchaser          MD 0        DWORD                                                                                     
126,M_lightchaser_state     M 4.0       BOOL                                                                                      
126,M_lightchaser_dir       M 4.1       BOOL                                                                                      
126,M_statemachine          M 4.2       BOOL                                                                                      
126,MW_statemachine         MW 6        INT                                                                                       
126,MB_clockmem             MB 16       BYTE                                                                                      
126,M_clockmem_0.1s         M 16.0      BOOL                                                                                      
126,M_clockmem_0.2s         M 16.1      BOOL                                                                                      
126,M_clockmem_0.4s         M 16.2      BOOL                                                                                      
126,M_clockmem_0.5s         M 16.3      BOOL                                                                                      
126,M_clockmem_0.8s         M 16.4      BOOL                                                                                      
126,M_clockmem_1.0s         M 16.5      BOOL                                                                                      
126,M_clockmem_1.6s         M 16.6      BOOL                                                                                      
126,M_clockmem_2.0s         M 16.7      BOOL                                                                                      

]]></source>

		<!-- symbol table source code -->
		<source name="Inputs"
		        type="3"><![CDATA[
126,E_simple_mode           E 0.0       BOOL                                                                                      

]]></source>

		<!-- symbol table source code -->
		<source name="Outputs"
		        type="3"><![CDATA[
126,AB_raspi_GPIO           AB 0        BYTE                                                                                      

]]></source>

		<!-- symbol table source code -->
		<source name="Constants"
		        type="3"><![CDATA[
126,STATE_LIGHTCHASER       0           INT                                                                                       
126,STATE_A                 1           INT                                                                                       
126,STATE_W                 2           INT                                                                                       
126,STATE_L                 3           INT                                                                                       
126,STATE_55                4           INT                                                                                       
126,STATE_AA                5           INT                                                                                       

]]></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="pilc"
		         port="4151"
		         timeout_ms="3000" />

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

	<!-- Hardware modules configuration -->
	<hardware>
		<!-- Loaded hardware module -->
		<module name="rpigpio">
			<params>
				<param name="I0.0"
				       value="BCM6" />
				<param name="I0.1"
				       value="BCM13" />
				<param name="I0.2"
				       value="BCM19" />
				<param name="I0.3"
				       value="BCM26" />
				<param name="I0.4"
				       value="BCM21" />
				<param name="I0.5"
				       value="BCM20" />
				<param name="I0.6"
				       value="BCM16" />
				<param name="I0.7"
				       value="BCM12" />
				<param name="Q0.0"
				       value="BCM4" />
				<param name="Q0.1"
				       value="BCM17" />
				<param name="Q0.2"
				       value="BCM27" />
				<param name="Q0.3"
				       value="BCM22" />
				<param name="Q0.4"
				       value="BCM10" />
				<param name="Q0.5"
				       value="BCM9" />
				<param name="Q0.6"
				       value="BCM11" />
				<param name="Q0.7"
				       value="BCM5" />
				<param name="inputAddressBase"
				       value="0" />
				<param name="outputAddressBase"
				       value="0" />
				<param name="removeOnReset"
				       value="false" />
			</params>
		</module>
	</hardware>

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