etisserant@0: (* msousa@274: * matiec - a compiler for the programming languages defined in IEC 61131-3 etisserant@0: * msousa@274: * Copyright (C) 2011 Mario de Sousa (msousa@fe.up.pt) etisserant@0: * msousa@274: * This program is free software: you can redistribute it and/or modify msousa@274: * it under the terms of the GNU General Public License as published by msousa@274: * the Free Software Foundation, either version 3 of the License, or msousa@274: * (at your option) any later version. msousa@274: * msousa@274: * This program is distributed in the hope that it will be useful, msousa@274: * but WITHOUT ANY WARRANTY; without even the implied warranty of msousa@274: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the msousa@274: * GNU General Public License for more details. msousa@274: * msousa@274: * You should have received a copy of the GNU General Public License msousa@274: * along with this program. If not, see . msousa@274: * etisserant@0: * etisserant@0: * This code is made available on the understanding that it will not be etisserant@0: * used in safety-critical situations without a full and competent review. etisserant@0: *) etisserant@0: etisserant@0: (* msousa@274: * An IEC 61131-3 compiler. etisserant@0: * etisserant@0: * Based on the etisserant@0: * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) etisserant@0: * etisserant@0: *) etisserant@0: etisserant@0: etisserant@0: (* etisserant@0: * This is part of the library conatining the functions etisserant@0: * and function blocks defined in the standard. etisserant@0: * etisserant@0: * SR and RS function blocks etisserant@0: * ------------------------- etisserant@0: *) etisserant@0: msousa@274: (* The standard defines the SR FB thus: msousa@274: msousa@274: +-----+ msousa@274: S1----------------| >=1 |---Q1 msousa@274: +---+ | | msousa@274: R------O| & |----| | msousa@274: Q1------| | | | msousa@274: +---+ +-----+ msousa@274: *) etisserant@0: etisserant@0: FUNCTION_BLOCK SR etisserant@0: VAR_INPUT msousa@274: S1, R : BOOL; etisserant@0: END_VAR etisserant@0: VAR_OUTPUT etisserant@0: Q1 : BOOL; etisserant@0: END_VAR msousa@274: Q1 := S1 OR ((NOT R) AND Q1); msousa@274: END_FUNCTION_BLOCK etisserant@0: msousa@274: msousa@274: (* The standard defines the RS FB thus: msousa@274: +---+ msousa@274: R1----------------O| & |---Q1 msousa@274: +-----+ | | msousa@274: S-------| >=1 |----| | msousa@274: Q1------| | | | msousa@274: +-----+ +---+ msousa@274: *) etisserant@0: etisserant@0: FUNCTION_BLOCK RS etisserant@0: VAR_INPUT msousa@274: S, R1 : BOOL; etisserant@0: END_VAR etisserant@0: VAR_OUTPUT etisserant@0: Q1 : BOOL; etisserant@0: END_VAR msousa@274: Q1 := (NOT R1) AND (S OR Q1); etisserant@0: END_FUNCTION_BLOCK