etherlab/etherlab_ext.c
author Edouard Tisserant
Wed, 01 Jul 2020 10:36:20 +0200
changeset 2686 703ebf57508a
parent 2165 02a2b5dee5e3
permissions -rw-r--r--
Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.

Websettings for modbus and bacnet are now passed to runtime as python files loaded (execfile) at init of PLCObject with the same globals.
Because if this, same names used in previously different modules now colide.
2165
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2086
diff changeset
     1
/*
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2086
diff changeset
     2
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2086
diff changeset
     3
Template C code used to produce target Ethercat C code.
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2086
diff changeset
     4
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2086
diff changeset
     5
Copyright (C) 2011-2014: Laurent BESSARD, Edouard TISSERANT
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2086
diff changeset
     6
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2086
diff changeset
     7
Distributed under the terms of the GNU Lesser General Public License as
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2086
diff changeset
     8
published by the Free Software Foundation; either version 2 of the License, or
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2086
diff changeset
     9
(at your option) any later version.
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2086
diff changeset
    10
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2086
diff changeset
    11
See COPYING file for copyrights details.
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2086
diff changeset
    12
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2086
diff changeset
    13
*/
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2086
diff changeset
    14
2086
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    15
#include "iec_types_all.h"
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    16
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    17
#define FREE 0
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    18
#define ACQUIRED 1
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    19
#define ANSWERED 2
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    20
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    21
long SDOLock = FREE;
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    22
extern long AtomicCompareExchange(long* atomicvar,long compared, long exchange);
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    23
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    24
int AcquireSDOLock() {
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    25
	return AtomicCompareExchange(&SDOLock, FREE, ACQUIRED) == FREE;
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    26
}
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    27
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    28
void SDOAnswered() {
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    29
	AtomicCompareExchange(&SDOLock, ACQUIRED, ANSWERED);
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    30
}
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    31
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    32
int HasAnswer() {
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    33
	return SDOLock == ANSWERED;
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    34
}
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    35
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    36
void ReleaseSDOLock() {
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    37
	AtomicCompareExchange(&SDOLock, ANSWERED, FREE);
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    38
}
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    39
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    40
int __init_etherlab_ext()
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    41
{
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    42
    SDOLock = FREE;
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    43
    return 0;
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    44
}
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    45
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    46
void __cleanup_etherlab_ext()
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    47
{
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    48
}
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    49
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    50
void __retrieve_etherlab_ext()
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    51
{
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    52
}
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    53
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    54
void __publish_etherlab_ext()
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    55
{
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents:
diff changeset
    56
}