tests/python/c_code@c_ext/cfile.xml
author Edouard Tisserant
Tue, 26 Mar 2013 12:44:44 +0900
changeset 1002 15c05ba95df4
parent 953 1fb6cf5a4c4d
child 1086 b566ab5556ab
permissions -rw-r--r--
LogMessage string pointer now char* instead of uint8_t*
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
     1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
     2
<CFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="cext_xsd.xsd">
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
     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
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
     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>
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
     7
    <variable name="TestInput" type="SINT" class="input"/>
860
8a51046010d7 Even more pedagogical tests/python. Renaming will not help
Edouard Tisserant
parents: 859
diff changeset
     8
    <variable name="TestOutput" type="SINT" class="output"/>
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
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    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
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    14
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
    15
  return val+1;
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    16
}
859
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    17
862
bb59865db6e6 Introduced FBID in tests/python example. Fixed type error leading to segfault
Edouard Tisserant
parents: 860
diff changeset
    18
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
    19
  /* 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
    20
     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
    21
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    22
     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
    23
     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
    24
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    25
  int res = 0;
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    26
  if(!AtomicCompareExchange(&Lock, 0, 1)){
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    27
    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
    28
    *fromC=CtoP;
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    29
    AtomicCompareExchange(&Lock, 1, 0);
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    30
    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
    31
  }
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    32
  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
    33
  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
    34
}
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    35
862
bb59865db6e6 Introduced FBID in tests/python example. Fixed type error leading to segfault
Edouard Tisserant
parents: 860
diff changeset
    36
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
    37
  /* 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
    38
     conflict with asynchronous python access */
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    39
  int 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
  if(!AtomicCompareExchange(&Lock, 0, 1)){
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    41
      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
    42
      *toPLC = PtoC;
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    43
      AtomicCompareExchange(&Lock, 1, 0);
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    44
      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
    45
  }
dbf82971f09d More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something
Edouard Tisserant
parents: 734
diff changeset
    46
  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
    47
}]]>
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    48
  </globals>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    49
  <initFunction>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    50
<![CDATA[]]>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    51
  </initFunction>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    52
  <cleanUpFunction>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    53
<![CDATA[]]>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    54
  </cleanUpFunction>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    55
  <retrieveFunction>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    56
<![CDATA[]]>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    57
  </retrieveFunction>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    58
  <publishFunction>
860
8a51046010d7 Even more pedagogical tests/python. Renaming will not help
Edouard Tisserant
parents: 859
diff changeset
    59
<![CDATA[if(!AtomicCompareExchange(&Lock, 0, 1)){
8a51046010d7 Even more pedagogical tests/python. Renaming will not help
Edouard Tisserant
parents: 859
diff changeset
    60
    TestInput = CtoP + PtoC + TestOutput;
8a51046010d7 Even more pedagogical tests/python. Renaming will not help
Edouard Tisserant
parents: 859
diff changeset
    61
    AtomicCompareExchange(&Lock, 1, 0);
8a51046010d7 Even more pedagogical tests/python. Renaming will not help
Edouard Tisserant
parents: 859
diff changeset
    62
}]]>
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    63
  </publishFunction>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    64
</CFile>