author | Laurent Bessard |
Tue, 14 May 2013 22:25:33 +0200 | |
changeset 1139 | f9cf74053b7d |
parent 1125 | 1b1472e76f07 |
child 1401 | 611fded24ce4 |
permissions | -rw-r--r-- |
734 | 1 |
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
1125 | 2 |
<CFile> |
734 | 3 |
<includes> |
1125 | 4 |
<![CDATA[ |
5 |
]]> |
|
734 | 6 |
</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
|
7 |
<variables> |
1099 | 8 |
<variable name="TestInput" type="SINT" initial="0"/> |
9 |
<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
|
10 |
</variables> |
734 | 11 |
<globals> |
1125 | 12 |
<![CDATA[ |
13 |
volatile long Lock=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
|
14 |
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
|
15 |
|
1086 | 16 |
extern long AtomicCompareExchange(long*,long, long); |
17 |
||
859
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
18 |
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
|
19 |
return val+1; |
734 | 20 |
} |
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 |
|
862
bb59865db6e6
Introduced FBID in tests/python example. Fixed type error leading to segfault
Edouard Tisserant
parents:
860
diff
changeset
|
22 |
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
|
23 |
/* 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
|
24 |
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
|
25 |
|
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
26 |
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
|
27 |
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
|
28 |
|
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
29 |
int res = 0; |
1086 | 30 |
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
|
31 |
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
|
32 |
*fromC=CtoP; |
1086 | 33 |
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
|
34 |
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
|
35 |
} |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
36 |
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
|
37 |
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
|
38 |
} |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
39 |
|
862
bb59865db6e6
Introduced FBID in tests/python example. Fixed type error leading to segfault
Edouard Tisserant
parents:
860
diff
changeset
|
40 |
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
|
41 |
/* 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
|
42 |
conflict with asynchronous python access */ |
1086 | 43 |
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
|
44 |
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
|
45 |
*toPLC = PtoC; |
1086 | 46 |
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
|
47 |
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
|
48 |
} |
dbf82971f09d
More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents:
734
diff
changeset
|
49 |
return 0; |
1125 | 50 |
} |
51 |
]]> |
|
734 | 52 |
</globals> |
53 |
<initFunction> |
|
1125 | 54 |
<![CDATA[ |
55 |
]]> |
|
734 | 56 |
</initFunction> |
57 |
<cleanUpFunction> |
|
1125 | 58 |
<![CDATA[ |
59 |
]]> |
|
734 | 60 |
</cleanUpFunction> |
61 |
<retrieveFunction> |
|
1125 | 62 |
<![CDATA[ |
63 |
]]> |
|
734 | 64 |
</retrieveFunction> |
65 |
<publishFunction> |
|
1125 | 66 |
<![CDATA[ |
67 |
if(!AtomicCompareExchange((long*)&Lock, 0, 1)){ |
|
860
8a51046010d7
Even more pedagogical tests/python. Renaming will not help
Edouard Tisserant
parents:
859
diff
changeset
|
68 |
TestInput = CtoP + PtoC + TestOutput; |
1086 | 69 |
AtomicCompareExchange((long*)&Lock, 1, 0); |
1125 | 70 |
} |
71 |
]]> |
|
734 | 72 |
</publishFunction> |
1125 | 73 |
</CFile> |