tests/python/c_code@c_ext/cfile.xml
author Edouard Tisserant
Fri, 13 Mar 2015 22:36:52 +0100
changeset 1457 ff7cfce737ca
parent 1401 611fded24ce4
child 1463 de311ffe3961
permissions -rw-r--r--
Added PLCID variable accessible from C side, set with binarie's MD5. Added retain init and cleanup calls. Extended tests/python to test PLCID
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1125
diff changeset
     1
<?xml version='1.0' encoding='utf-8'?>
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1125
diff changeset
     2
<CFile xmlns:xhtml="http://www.w3.org/1999/xhtml">
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
     3
  <includes>
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1125
diff changeset
     4
    <xhtml:p><![CDATA[
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1125
diff changeset
     5
]]></xhtml:p>
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
     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
d9c28879e55b Updated python test
Laurent Bessard
parents: 1086
diff changeset
     8
    <variable name="TestInput" type="SINT" initial="0"/>
d9c28879e55b Updated python test
Laurent Bessard
parents: 1086
diff changeset
     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
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    11
  <globals>
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1125
diff changeset
    12
    <xhtml:p><![CDATA[
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    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
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    16
extern long AtomicCompareExchange(long*,long, long);
1457
ff7cfce737ca Added PLCID variable accessible from C side, set with binarie's MD5. Added retain init and cleanup calls. Extended tests/python to test PLCID
Edouard Tisserant
parents: 1401
diff changeset
    17
extern char *PLCID;
1086
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    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
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
    20
  return val+1;
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    21
}
859
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    22
862
bb59865db6e6 Introduced FBID in tests/python example. Fixed type error leading to segfault
Edouard Tisserant
parents: 860
diff changeset
    23
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
    24
  /* 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
    25
     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
    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
     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
    28
     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
    29
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    30
  int res = 0;
1086
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    31
  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
    32
    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
    33
    *fromC=CtoP;
1086
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    34
    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
    35
    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
    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
  printf("C code called by Python: toC %d fromC %d\n",toC,*fromC);
1457
ff7cfce737ca Added PLCID variable accessible from C side, set with binarie's MD5. Added retain init and cleanup calls. Extended tests/python to test PLCID
Edouard Tisserant
parents: 1401
diff changeset
    38
  printf("PLCID id %s\n",PLCID);
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
  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
    40
}
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    41
862
bb59865db6e6 Introduced FBID in tests/python example. Fixed type error leading to segfault
Edouard Tisserant
parents: 860
diff changeset
    42
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
    43
  /* 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
    44
     conflict with asynchronous python access */
1086
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    45
  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
    46
      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
    47
      *toPLC = PtoC;
1086
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    48
      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
    49
      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
    50
  }
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    51
  return 0;
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    52
}
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1125
diff changeset
    53
]]></xhtml:p>
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    54
  </globals>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    55
  <initFunction>
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1125
diff changeset
    56
    <xhtml:p><![CDATA[
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1125
diff changeset
    57
]]></xhtml:p>
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    58
  </initFunction>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    59
  <cleanUpFunction>
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1125
diff changeset
    60
    <xhtml:p><![CDATA[
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1125
diff changeset
    61
]]></xhtml:p>
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    62
  </cleanUpFunction>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    63
  <retrieveFunction>
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1125
diff changeset
    64
    <xhtml:p><![CDATA[
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1125
diff changeset
    65
]]></xhtml:p>
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    66
  </retrieveFunction>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    67
  <publishFunction>
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1125
diff changeset
    68
    <xhtml:p><![CDATA[
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    69
if(!AtomicCompareExchange((long*)&Lock, 0, 1)){
860
8a51046010d7 Even more pedagogical tests/python. Renaming will not help
Edouard Tisserant
parents: 859
diff changeset
    70
    TestInput = CtoP + PtoC + TestOutput;
1086
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    71
    AtomicCompareExchange((long*)&Lock, 1, 0);
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    72
}
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1125
diff changeset
    73
]]></xhtml:p>
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    74
  </publishFunction>
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    75
</CFile>