--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/COPYING.LESSER Mon Apr 04 19:18:22 2011 +0200
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
--- a/lib/bistable.txt Mon Apr 04 18:54:55 2011 +0200
+++ b/lib/bistable.txt Mon Apr 04 19:18:22 2011 +0200
@@ -1,21 +1,33 @@
(*
- * (c) 26 Feb 2001 David Campbell
+ * This file is part of matiec - a compiler for the programming
+ * languages defined in IEC 61131-3
*
- * Offered to the public under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
+ * Copyright (C) 2011 Mario de Sousa (msousa@fe.up.pt)
*
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
- * Public License for more details.
+ * See COPYING and COPYING.LESSER files for copyright details.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
*
* This code is made available on the understanding that it will not be
* used in safety-critical situations without a full and competent review.
*)
+
+
(*
- * An IEC 61131-3 IL and ST compiler.
+ * An IEC 61131-3 compiler.
*
* Based on the
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
@@ -31,35 +43,42 @@
* -------------------------
*)
+(* The standard defines the SR FB thus:
+
+ +-----+
+S1----------------| >=1 |---Q1
+ +---+ | |
+ R------O| & |----| |
+ Q1------| | | |
+ +---+ +-----+
+*)
FUNCTION_BLOCK SR
VAR_INPUT
- S1 : BOOL;
- R : BOOL;
+ S1, R : BOOL;
END_VAR
VAR_OUTPUT
Q1 : BOOL;
END_VAR
- VAR
- Q_INTERNAL : BOOL;
- END_VAR
+ Q1 := S1 OR ((NOT R) AND Q1);
+END_FUNCTION_BLOCK
- Q_INTERNAL := S1 OR ( Q_INTERNAL AND (NOT R));
- Q1 := Q_INTERNAL;
-END_FUNCTION_BLOCK
+
+(* The standard defines the RS FB thus:
+ +---+
+R1----------------O| & |---Q1
+ +-----+ | |
+S-------| >=1 |----| |
+Q1------| | | |
+ +-----+ +---+
+*)
FUNCTION_BLOCK RS
VAR_INPUT
- S : BOOL;
- R1 : BOOL;
+ S, R1 : BOOL;
END_VAR
VAR_OUTPUT
Q1 : BOOL;
END_VAR
- VAR
- Q_INTERNAL : BOOL;
- END_VAR
-
- Q_INTERNAL := (NOT R1) AND (S OR Q_INTERNAL);
- Q1 := Q_INTERNAL;
+ Q1 := (NOT R1) AND (S OR Q1);
END_FUNCTION_BLOCK
--- a/lib/counter.txt Mon Apr 04 18:54:55 2011 +0200
+++ b/lib/counter.txt Mon Apr 04 19:18:22 2011 +0200
@@ -18,6 +18,13 @@
*)
+
+(******************)
+(* *)
+(* C T U *)
+(* *)
+(******************)
+
FUNCTION_BLOCK CTU
VAR_INPUT
CU : BOOL;
@@ -28,16 +35,96 @@
Q : BOOL;
CV : INT;
END_VAR
-
- VAR RRR : REAL; END_VAR
- RRR := 9.9;
-
- IF R THEN CV := 0 ;
- ELSIF CU AND (CV < PV)
- THEN CV := CV+1;
- END_IF ;
- Q := (CV >= PV) ;
-END_FUNCTION_BLOCK
+ IF R THEN CV := 0 ;
+ ELSIF CU AND (CV < PV)
+ THEN CV := CV+1;
+ END_IF ;
+ Q := (CV >= PV) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTU_DINT
+ VAR_INPUT
+ CU : BOOL;
+ R : BOOL;
+ PV : DINT;
+ END_VAR
+ VAR_OUTPUT
+ Q : BOOL;
+ CV : DINT;
+ END_VAR
+ IF R THEN CV := 0 ;
+ ELSIF CU AND (CV < PV)
+ THEN CV := CV+1;
+ END_IF ;
+ Q := (CV >= PV) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTU_LINT
+ VAR_INPUT
+ CU : BOOL;
+ R : BOOL;
+ PV : LINT;
+ END_VAR
+ VAR_OUTPUT
+ Q : BOOL;
+ CV : LINT;
+ END_VAR
+ IF R THEN CV := 0 ;
+ ELSIF CU AND (CV < PV)
+ THEN CV := CV+1;
+ END_IF ;
+ Q := (CV >= PV) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTU_UDINT
+ VAR_INPUT
+ CU : BOOL;
+ R : BOOL;
+ PV : UDINT;
+ END_VAR
+ VAR_OUTPUT
+ Q : BOOL;
+ CV : UDINT;
+ END_VAR
+ IF R THEN CV := 0 ;
+ ELSIF CU AND (CV < PV)
+ THEN CV := CV+1;
+ END_IF ;
+ Q := (CV >= PV) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTU_ULINT
+ VAR_INPUT
+ CU : BOOL;
+ R : BOOL;
+ PV : ULINT;
+ END_VAR
+ VAR_OUTPUT
+ Q : BOOL;
+ CV : ULINT;
+ END_VAR
+ IF R THEN CV := 0 ;
+ ELSIF CU AND (CV < PV)
+ THEN CV := CV+1;
+ END_IF ;
+ Q := (CV >= PV) ;
+END_FUNCTION_BLOCK
+
+
+
+
+
+
+
+(******************)
+(* *)
+(* C T D *)
+(* *)
+(******************)
FUNCTION_BLOCK CTD
@@ -58,6 +145,85 @@
END_FUNCTION_BLOCK
+FUNCTION_BLOCK CTD_DINT
+ VAR_INPUT
+ CD : BOOL;
+ LD : BOOL;
+ PV : DINT;
+ END_VAR
+ VAR_OUTPUT
+ Q : BOOL;
+ CV : DINT;
+ END_VAR
+ IF LD THEN CV := PV ;
+ ELSIF CD AND (CV > 0)
+ THEN CV := CV-1;
+ END_IF ;
+ Q := (CV <= 0) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTD_LINT
+ VAR_INPUT
+ CD : BOOL;
+ LD : BOOL;
+ PV : LINT;
+ END_VAR
+ VAR_OUTPUT
+ Q : BOOL;
+ CV : LINT;
+ END_VAR
+ IF LD THEN CV := PV ;
+ ELSIF CD AND (CV > 0)
+ THEN CV := CV-1;
+ END_IF ;
+ Q := (CV <= 0) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTD_UDINT
+ VAR_INPUT
+ CD : BOOL;
+ LD : BOOL;
+ PV : UDINT;
+ END_VAR
+ VAR_OUTPUT
+ Q : BOOL;
+ CV : UDINT;
+ END_VAR
+ IF LD THEN CV := PV ;
+ ELSIF CD AND (CV > 0)
+ THEN CV := CV-1;
+ END_IF ;
+ Q := (CV <= 0) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTD_ULINT
+ VAR_INPUT
+ CD : BOOL;
+ LD : BOOL;
+ PV : ULINT;
+ END_VAR
+ VAR_OUTPUT
+ Q : BOOL;
+ CV : ULINT;
+ END_VAR
+ IF LD THEN CV := PV ;
+ ELSIF CD AND (CV > 0)
+ THEN CV := CV-1;
+ END_IF ;
+ Q := (CV <= 0) ;
+END_FUNCTION_BLOCK
+
+
+(********************)
+(* *)
+(* C T U D *)
+(* *)
+(********************)
+
+
FUNCTION_BLOCK CTUD
VAR_INPUT
CU : BOOL;
@@ -86,3 +252,118 @@
QD := (CV <= 0) ;
END_FUNCTION_BLOCK
+
+FUNCTION_BLOCK CTUD_DINT
+ VAR_INPUT
+ CU : BOOL;
+ CD : BOOL;
+ R : BOOL;
+ LD : BOOL;
+ PV : DINT;
+ END_VAR
+ VAR_OUTPUT
+ QU : BOOL;
+ QD : BOOL;
+ CV : DINT;
+ END_VAR
+ IF R THEN CV := 0 ;
+ ELSIF LD THEN CV := PV ;
+ ELSE
+ IF NOT (CU AND CD) THEN
+ IF CU AND (CV < PV)
+ THEN CV := CV+1;
+ ELSIF CD AND (CV > 0)
+ THEN CV := CV-1;
+ END_IF;
+ END_IF;
+ END_IF ;
+ QU := (CV >= PV) ;
+ QD := (CV <= 0) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTUD_LINT
+ VAR_INPUT
+ CU : BOOL;
+ CD : BOOL;
+ R : BOOL;
+ LD : BOOL;
+ PV : LINT;
+ END_VAR
+ VAR_OUTPUT
+ QU : BOOL;
+ QD : BOOL;
+ CV : LINT;
+ END_VAR
+ IF R THEN CV := 0 ;
+ ELSIF LD THEN CV := PV ;
+ ELSE
+ IF NOT (CU AND CD) THEN
+ IF CU AND (CV < PV)
+ THEN CV := CV+1;
+ ELSIF CD AND (CV > 0)
+ THEN CV := CV-1;
+ END_IF;
+ END_IF;
+ END_IF ;
+ QU := (CV >= PV) ;
+ QD := (CV <= 0) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTUD_UDINT
+ VAR_INPUT
+ CU : BOOL;
+ CD : BOOL;
+ R : BOOL;
+ LD : BOOL;
+ PV : UDINT;
+ END_VAR
+ VAR_OUTPUT
+ QU : BOOL;
+ QD : BOOL;
+ CV : UDINT;
+ END_VAR
+ IF R THEN CV := 0 ;
+ ELSIF LD THEN CV := PV ;
+ ELSE
+ IF NOT (CU AND CD) THEN
+ IF CU AND (CV < PV)
+ THEN CV := CV+1;
+ ELSIF CD AND (CV > 0)
+ THEN CV := CV-1;
+ END_IF;
+ END_IF;
+ END_IF ;
+ QU := (CV >= PV) ;
+ QD := (CV <= 0) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTUD_ULINT
+ VAR_INPUT
+ CU : BOOL;
+ CD : BOOL;
+ R : BOOL;
+ LD : BOOL;
+ PV : ULINT;
+ END_VAR
+ VAR_OUTPUT
+ QU : BOOL;
+ QD : BOOL;
+ CV : ULINT;
+ END_VAR
+ IF R THEN CV := 0 ;
+ ELSIF LD THEN CV := PV ;
+ ELSE
+ IF NOT (CU AND CD) THEN
+ IF CU AND (CV < PV)
+ THEN CV := CV+1;
+ ELSIF CD AND (CV > 0)
+ THEN CV := CV-1;
+ END_IF;
+ END_IF;
+ END_IF ;
+ QU := (CV >= PV) ;
+ QD := (CV <= 0) ;
+END_FUNCTION_BLOCK
--- a/lib/derivative_st.txt Mon Apr 04 18:54:55 2011 +0200
+++ b/lib/derivative_st.txt Mon Apr 04 19:18:22 2011 +0200
@@ -1,3 +1,15 @@
+
+(* Following taken directly from the IEC 61131.3 draft standard *)
+
+(*
+ * An IEC 61131-3 IL and ST compiler.
+ *
+ * Based on the
+ * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
+ *
+ *)
+
+
FUNCTION_BLOCK DERIVATIVE
VAR_INPUT
RUN : BOOL ; (* 0 = reset *)
--- a/lib/hysteresis_st.txt Mon Apr 04 18:54:55 2011 +0200
+++ b/lib/hysteresis_st.txt Mon Apr 04 19:18:22 2011 +0200
@@ -1,3 +1,14 @@
+(* Following taken directly from the IEC 61131.3 draft standard *)
+
+(*
+ * An IEC 61131-3 IL and ST compiler.
+ *
+ * Based on the
+ * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
+ *
+ *)
+
+
FUNCTION_BLOCK HYSTERESIS
(* Boolean hysteresis on difference *)
(* of REAL inputs, XIN1 - XIN2 *)
--- a/lib/integral_st.txt Mon Apr 04 18:54:55 2011 +0200
+++ b/lib/integral_st.txt Mon Apr 04 19:18:22 2011 +0200
@@ -1,3 +1,13 @@
+(* Following taken directly from the IEC 61131.3 draft standard *)
+
+(*
+ * An IEC 61131-3 IL and ST compiler.
+ *
+ * Based on the
+ * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
+ *
+ *)
+
FUNCTION_BLOCK INTEGRAL
VAR_INPUT
RUN : BOOL ; (* 1 = integrate, 0 = hold *)
--- a/lib/pid_st.txt Mon Apr 04 18:54:55 2011 +0200
+++ b/lib/pid_st.txt Mon Apr 04 19:18:22 2011 +0200
@@ -1,3 +1,13 @@
+(* Following taken directly from the IEC 61131.3 draft standard *)
+
+(*
+ * An IEC 61131-3 IL and ST compiler.
+ *
+ * Based on the
+ * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
+ *
+ *)
+
FUNCTION_BLOCK PID
VAR_INPUT
AUTO : BOOL ; (* 0 - manual , 1 - automatic *)
--- a/lib/ramp_st.txt Mon Apr 04 18:54:55 2011 +0200
+++ b/lib/ramp_st.txt Mon Apr 04 19:18:22 2011 +0200
@@ -1,3 +1,13 @@
+(* Following taken directly from the IEC 61131.3 draft standard *)
+
+(*
+ * An IEC 61131-3 IL and ST compiler.
+ *
+ * Based on the
+ * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
+ *
+ *)
+
FUNCTION_BLOCK RAMP
VAR_INPUT
RUN : BOOL ; (* 0 - track X0, 1 - ramp to/track X1 *)
--- a/lib/timer.txt Mon Apr 04 18:54:55 2011 +0200
+++ b/lib/timer.txt Mon Apr 04 19:18:22 2011 +0200
@@ -1,21 +1,31 @@
(*
- * (c) 2005 Mario de Sousa
- *
- * Offered to the public under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
- * Public License for more details.
+ * This file is part of matiec - a compiler for the programming
+ * languages defined in IEC 61131-3
+ *
+ * Copyright (C) 2011 Mario de Sousa (msousa@fe.up.pt)
+ *
+ * See COPYING and COPYING.LESSER files for copyright details.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
*
* This code is made available on the understanding that it will not be
* used in safety-critical situations without a full and competent review.
*)
(*
- * An IEC 61131-3 IL and ST compiler.
+ * An IEC 61131-3 compiler.
*
* Based on the
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
@@ -29,8 +39,8 @@
* Timer Function Blocks
* ---------------------
*
- * NOTE: The timing diagrams in the comments were taken from the
- * IEC 61131-3 standard.
+ * NOTE: The timing diagrams in the comments (except the state variable)
+ * were taken from the IEC 61131-3 standard.
*)