etherlab/etherlab_ext.c
author Edouard Tisserant <edouard.tisserant@gmail.com>
Sat, 13 Jul 2019 10:57:25 +0200
changeset 2624 570cf07c3fd1
parent 2165 02a2b5dee5e3
permissions -rw-r--r--
Fix exception on exit in some case, sequel of an earlier cleanup commit I couldn't find back. Disconnecting the event is apparently the way to go. https://wiki.wxpython.org/Surviving%20with%20wxEVT%20KILL%20FOCUS%20under%20Microsoft%20Windows
/*

Template C code used to produce target Ethercat C code.

Copyright (C) 2011-2014: Laurent BESSARD, Edouard TISSERANT

Distributed under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

See COPYING file for copyrights details.

*/

#include "iec_types_all.h"

#define FREE 0
#define ACQUIRED 1
#define ANSWERED 2

long SDOLock = FREE;
extern long AtomicCompareExchange(long* atomicvar,long compared, long exchange);

int AcquireSDOLock() {
	return AtomicCompareExchange(&SDOLock, FREE, ACQUIRED) == FREE;
}

void SDOAnswered() {
	AtomicCompareExchange(&SDOLock, ACQUIRED, ANSWERED);
}

int HasAnswer() {
	return SDOLock == ANSWERED;
}

void ReleaseSDOLock() {
	AtomicCompareExchange(&SDOLock, ANSWERED, FREE);
}

int __init_etherlab_ext()
{
    SDOLock = FREE;
    return 0;
}

void __cleanup_etherlab_ext()
{
}

void __retrieve_etherlab_ext()
{
}

void __publish_etherlab_ext()
{
}