author | mjsousa |
Sun, 15 Mar 2015 20:49:55 +0000 | |
changeset 998 | 694127983aa4 |
parent 279 | c0453b7f99df |
permissions | -rwxr-xr-x |
279
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
1 |
/* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
2 |
* matiec - a compiler for the programming languages defined in IEC 61131-3 |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
3 |
* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
4 |
* Copyright (C) 2009-2011 Mario de Sousa (msousa@fe.up.pt) |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
5 |
* Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
6 |
* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
7 |
* This program is free software: you can redistribute it and/or modify |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
8 |
* it under the terms of the GNU General Public License as published by |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
9 |
* the Free Software Foundation, either version 3 of the License, or |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
10 |
* (at your option) any later version. |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
11 |
* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
12 |
* This program is distributed in the hope that it will be useful, |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
15 |
* GNU General Public License for more details. |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
16 |
* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
18 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
19 |
* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
20 |
* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
21 |
* This code is made available on the understanding that it will not be |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
22 |
* used in safety-critical situations without a full and competent review. |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
23 |
* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
24 |
* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
25 |
* Simple PLC run cycle test implementation - prints every located at each cycle |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
26 |
* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
27 |
*/ |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
132
diff
changeset
|
28 |
|
57
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
29 |
#include "iec_std_lib.h" |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
30 |
#include <stdio.h> |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
31 |
|
132 | 32 |
#define __print_BOOL(name) printf(" %s = (BOOL) %s\n",#name, name?"TRUE":"FALSE"); |
33 |
#define __print_SINT(name) printf(" %s = (SINT) %d\n",#name, name); |
|
34 |
#define __print_INT(name) printf(" %s = (INT) %d\n",#name, name); |
|
35 |
#define __print_DINT(name) printf(" %s = (DINT) %d\n",#name, name); |
|
36 |
#define __print_LINT(name) printf(" %s = (LINT) %d\n",#name, name); |
|
37 |
#define __print_USINT(name) printf(" %s = (USINT) %u\n",#name, name); |
|
38 |
#define __print_UINT(name) printf(" %s = (UINT) %u\n",#name, name); |
|
39 |
#define __print_UDINT(name) printf(" %s = (UDINT) %u\n",#name, name); |
|
40 |
#define __print_ULINT(name) printf(" %s = (ULINT) %lu\n",#name, name); |
|
41 |
#define __print_REAL(name) printf(" %s = (REAL) %f\n",#name, (double)name); |
|
42 |
#define __print_LREAL(name) printf(" %s = (LREAL) %f\n",#name, (double)name); |
|
43 |
#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);} |
|
44 |
#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);} |
|
45 |
#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);} |
|
46 |
#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);} |
|
47 |
#define __print_STRING(name) printf(" %s = (STRING) {%d, \"%*s\"}\n",#name, name->len, name->len, &name->body); |
|
48 |
#define __print_BYTE(name) printf(" %s = (BYTE) 0x%2.2x\n",#name, name); |
|
49 |
#define __print_WORD(name) printf(" %s = (WORD) 0x%4.4x\n",#name, name); |
|
50 |
#define __print_DWORD(name) printf(" %s = (DWORD) 0x%8.8x\n",#name, name); |
|
51 |
#define __print_LWORD(name) printf(" %s = (LWORD) 0x%16.16lx\n",#name, name); |
|
57
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
52 |
/* |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
53 |
* Functions and variables provied by generated C softPLC |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
54 |
**/ |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
55 |
void config_run__(int tick); |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
56 |
void config_init__(void); |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
57 |
|
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
58 |
/* |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
59 |
* Functions and variables to export to generated C softPLC |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
60 |
**/ |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
61 |
|
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
62 |
TIME __CURRENT_TIME; |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
63 |
|
132 | 64 |
#define __LOCATED_VAR(type, name, ...) type __##name; |
65 |
#include "LOCATED_VARIABLES.h" |
|
66 |
#undef __LOCATED_VAR |
|
67 |
#define __LOCATED_VAR(type, name, ...) type* name = &__##name; |
|
57
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
68 |
#include "LOCATED_VARIABLES.h" |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
69 |
#undef __LOCATED_VAR |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
70 |
|
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
71 |
static int tick = 0; |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
72 |
|
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
73 |
void run() |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
74 |
{ |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
75 |
printf("Tick %d\n",tick); |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
76 |
config_run__(tick++); |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
77 |
printf(" Located variables : \n"); |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
78 |
#define __LOCATED_VAR(type, name,...) __print_##type(name); |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
79 |
#include "LOCATED_VARIABLES.h" |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
80 |
#undef __LOCATED_VAR |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
81 |
} |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
diff
changeset
|
82 |