tests/python/c_code@c_ext/cfile.xml
author Laurent Bessard
Wed, 08 May 2013 22:56:31 +0200
changeset 1099 d9c28879e55b
parent 1086 b566ab5556ab
child 1125 1b1472e76f07
permissions -rw-r--r--
Updated python test
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
     1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
1099
d9c28879e55b Updated python test
Laurent Bessard
parents: 1086
diff changeset
     2
<CodeFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="codefile.xsd">
734
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>
1099
d9c28879e55b Updated python test
Laurent Bessard
parents: 1086
diff changeset
     7
    <variable name="TestInput" type="SINT" initial="0"/>
d9c28879e55b Updated python test
Laurent Bessard
parents: 1086
diff changeset
     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
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
1086
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    14
extern long AtomicCompareExchange(long*,long, long);
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    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
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
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
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
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    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
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    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
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    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
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    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
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    49
  </globals>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    50
  <initFunction>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    51
<![CDATA[]]>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    52
  </initFunction>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    53
  <cleanUpFunction>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    54
<![CDATA[]]>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    55
  </cleanUpFunction>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    56
  <retrieveFunction>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    57
<![CDATA[]]>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    58
  </retrieveFunction>
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    59
  <publishFunction>
1086
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    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
b566ab5556ab Fixed warnings in python test
Laurent Bessard
parents: 953
diff changeset
    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
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents:
diff changeset
    64
  </publishFunction>
1099
d9c28879e55b Updated python test
Laurent Bessard
parents: 1086
diff changeset
    65
</CodeFile>