Edouard@279: /*
Edouard@279: * matiec - a compiler for the programming languages defined in IEC 61131-3
Edouard@279: *
Edouard@279: * Copyright (C) 2009-2011 Mario de Sousa (msousa@fe.up.pt)
Edouard@279: * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant
Edouard@279: *
Edouard@279: * This program is free software: you can redistribute it and/or modify
Edouard@279: * it under the terms of the GNU General Public License as published by
Edouard@279: * the Free Software Foundation, either version 3 of the License, or
Edouard@279: * (at your option) any later version.
Edouard@279: *
Edouard@279: * This program is distributed in the hope that it will be useful,
Edouard@279: * but WITHOUT ANY WARRANTY; without even the implied warranty of
Edouard@279: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Edouard@279: * GNU General Public License for more details.
Edouard@279: *
Edouard@279: * You should have received a copy of the GNU General Public License
Edouard@279: * along with this program. If not, see .
Edouard@279: *
Edouard@279: *
Edouard@279: * This code is made available on the understanding that it will not be
Edouard@279: * used in safety-critical situations without a full and competent review.
Edouard@279: *
Edouard@279: *
Edouard@279: * Simple PLC run cycle test implementation - prints every located at each cycle
Edouard@279: *
Edouard@279: */
Edouard@279:
etisserant@57: #include "iec_std_lib.h"
etisserant@57: #include
etisserant@57:
etisserant@132: #define __print_BOOL(name) printf(" %s = (BOOL) %s\n",#name, name?"TRUE":"FALSE");
etisserant@132: #define __print_SINT(name) printf(" %s = (SINT) %d\n",#name, name);
etisserant@132: #define __print_INT(name) printf(" %s = (INT) %d\n",#name, name);
etisserant@132: #define __print_DINT(name) printf(" %s = (DINT) %d\n",#name, name);
etisserant@132: #define __print_LINT(name) printf(" %s = (LINT) %d\n",#name, name);
etisserant@132: #define __print_USINT(name) printf(" %s = (USINT) %u\n",#name, name);
etisserant@132: #define __print_UINT(name) printf(" %s = (UINT) %u\n",#name, name);
etisserant@132: #define __print_UDINT(name) printf(" %s = (UDINT) %u\n",#name, name);
etisserant@132: #define __print_ULINT(name) printf(" %s = (ULINT) %lu\n",#name, name);
etisserant@132: #define __print_REAL(name) printf(" %s = (REAL) %f\n",#name, (double)name);
etisserant@132: #define __print_LREAL(name) printf(" %s = (LREAL) %f\n",#name, (double)name);
etisserant@132: #define __print_TIME(name) {STRING __tmp = __time_to_string(name);__tmp.body[__tmp.len] = 0; printf(" %s = (TIME) %*s\n",#name, __tmp.len, &__tmp.body);}
etisserant@132: #define __print_DATE(name) {STRING __tmp = __date_to_string(name);__tmp.body[__tmp.len] = 0; printf(" %s = (DATE) %*s\n",#name, __tmp.len, &__tmp.body);}
etisserant@132: #define __print_TOD(name) {STRING __tmp = __tod_to_string(name);__tmp.body[__tmp.len] = 0; printf(" %s = (TOD) %*s\n",#name, __tmp.len, &__tmp.body);}
etisserant@132: #define __print_DT(name) {STRING __tmp = __dt_to_string(name);__tmp.body[__tmp.len] = 0; printf(" %s = (DT) %*s\n",#name, __tmp.len, &__tmp.body);}
etisserant@132: #define __print_STRING(name) printf(" %s = (STRING) {%d, \"%*s\"}\n",#name, name->len, name->len, &name->body);
etisserant@132: #define __print_BYTE(name) printf(" %s = (BYTE) 0x%2.2x\n",#name, name);
etisserant@132: #define __print_WORD(name) printf(" %s = (WORD) 0x%4.4x\n",#name, name);
etisserant@132: #define __print_DWORD(name) printf(" %s = (DWORD) 0x%8.8x\n",#name, name);
etisserant@132: #define __print_LWORD(name) printf(" %s = (LWORD) 0x%16.16lx\n",#name, name);
etisserant@57: /*
etisserant@57: * Functions and variables provied by generated C softPLC
etisserant@57: **/
etisserant@57: void config_run__(int tick);
etisserant@57: void config_init__(void);
etisserant@57:
etisserant@57: /*
etisserant@57: * Functions and variables to export to generated C softPLC
etisserant@57: **/
etisserant@57:
etisserant@57: TIME __CURRENT_TIME;
etisserant@57:
etisserant@132: #define __LOCATED_VAR(type, name, ...) type __##name;
etisserant@132: #include "LOCATED_VARIABLES.h"
etisserant@132: #undef __LOCATED_VAR
etisserant@132: #define __LOCATED_VAR(type, name, ...) type* name = &__##name;
etisserant@57: #include "LOCATED_VARIABLES.h"
etisserant@57: #undef __LOCATED_VAR
etisserant@57:
etisserant@57: static int tick = 0;
etisserant@57:
etisserant@57: void run()
etisserant@57: {
etisserant@57: printf("Tick %d\n",tick);
etisserant@57: config_run__(tick++);
etisserant@57: printf(" Located variables : \n");
etisserant@57: #define __LOCATED_VAR(type, name,...) __print_##type(name);
etisserant@57: #include "LOCATED_VARIABLES.h"
etisserant@57: #undef __LOCATED_VAR
etisserant@57: }
etisserant@57: