etisserant@0: (* msousa@277: * This file is part of matiec - a compiler for the programming msousa@277: * languages defined in IEC 61131-3 etisserant@0: * msousa@274: * Copyright (C) 2011 Mario de Sousa (msousa@fe.up.pt) etisserant@0: * msousa@277: * See COPYING and COPYING.LESSER files for copyright details. msousa@277: * This library is free software; you can redistribute it and/or msousa@277: * modify it under the terms of the GNU Lesser General Public msousa@277: * License as published by the Free Software Foundation; either msousa@277: * version 3 of the License, or (at your option) any later version. msousa@274: * msousa@277: * This library is distributed in the hope that it will be useful, msousa@277: * but WITHOUT ANY WARRANTY; without even the implied warranty of msousa@277: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU msousa@277: * Lesser General Public License for more details. msousa@277: * msousa@277: * You should have received a copy of the GNU Lesser General Public msousa@277: * License along with this library; if not, write to the Free Software msousa@277: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 msousa@277: * USA 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: msousa@277: msousa@277: 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