author | Laurent Bessard |
Sun, 12 May 2013 23:30:00 +0200 | |
changeset 1122 | 84de51ab40d2 |
parent 1099 | d9c28879e55b |
child 1125 | 1b1472e76f07 |
permissions | -rw-r--r-- |
734 | 1 |
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
1099 | 2 |
<CodeFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="codefile.xsd"> |
734 | 3 |
<includes> |
953
1fb6cf5a4c4d
Fixed dead code in c_ext, and updated test accordingly
Edouard Tisserant
parents:
862
diff
changeset
|
4 |
<![CDATA[#include "stdio.h"]]> |
734 | 5 |
</includes> |
859
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
6 |
<variables> |
1099 | 7 |
<variable name="TestInput" type="SINT" initial="0"/> |
8 |
<variable name="TestOutput" type="SINT"/> |
|
859
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
9 |
</variables> |
734 | 10 |
<globals> |
859
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
11 |
<![CDATA[volatile long Lock=0; |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
12 |
volatile char PtoC=1,CtoP=2; |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
13 |
|
1086 | 14 |
extern long AtomicCompareExchange(long*,long, long); |
15 |
||
859
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
16 |
int Simple_C_Call(int val){ |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
17 |
return val+1; |
734 | 18 |
} |
859
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
19 |
|
862
bb59865db6e6
Introduced FBID in tests/python example. Fixed type error leading to segfault
Edouard Tisserant
parents:
860
diff
changeset
|
20 |
int Python_to_C_Call(char toC, char *fromC){ |
859
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
21 |
/* Code called by python should never touch to |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
22 |
variables modified by PLC thread directly |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
23 |
|
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
24 |
AtomicCompareExchange comes from |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
25 |
beremiz' runtime implementation */ |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
26 |
|
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
27 |
int res = 0; |
1086 | 28 |
if(!AtomicCompareExchange((long*)&Lock, 0, 1)){ |
859
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
29 |
PtoC=toC; |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
30 |
*fromC=CtoP; |
1086 | 31 |
AtomicCompareExchange((long*)&Lock, 1, 0); |
859
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
32 |
res=1; |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
33 |
} |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
34 |
printf("C code called by Python: toC %d fromC %d\n",toC,*fromC); |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
35 |
return res; |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
36 |
} |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
37 |
|
862
bb59865db6e6
Introduced FBID in tests/python example. Fixed type error leading to segfault
Edouard Tisserant
parents:
860
diff
changeset
|
38 |
int PLC_C_Call(char fromPLC, char *toPLC){ |
859
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
39 |
/* PLC also have to be realy carefull not to |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
40 |
conflict with asynchronous python access */ |
1086 | 41 |
if(!AtomicCompareExchange((long*)&Lock, 0, 1)){ |
859
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
42 |
CtoP = fromPLC; |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
43 |
*toPLC = PtoC; |
1086 | 44 |
AtomicCompareExchange((long*)&Lock, 1, 0); |
859
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
45 |
return 1; |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
46 |
} |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
47 |
return 0; |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
48 |
}]]> |
734 | 49 |
</globals> |
50 |
<initFunction> |
|
51 |
<![CDATA[]]> |
|
52 |
</initFunction> |
|
53 |
<cleanUpFunction> |
|
54 |
<![CDATA[]]> |
|
55 |
</cleanUpFunction> |
|
56 |
<retrieveFunction> |
|
57 |
<![CDATA[]]> |
|
58 |
</retrieveFunction> |
|
59 |
<publishFunction> |
|
1086 | 60 |
<![CDATA[if(!AtomicCompareExchange((long*)&Lock, 0, 1)){ |
860
8a51046010d7
Even more pedagogical tests/python. Renaming will not help
Edouard Tisserant
parents:
859
diff
changeset
|
61 |
TestInput = CtoP + PtoC + TestOutput; |
1086 | 62 |
AtomicCompareExchange((long*)&Lock, 1, 0); |
860
8a51046010d7
Even more pedagogical tests/python. Renaming will not help
Edouard Tisserant
parents:
859
diff
changeset
|
63 |
}]]> |
734 | 64 |
</publishFunction> |
1099 | 65 |
</CodeFile> |