Commit 7624c501 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Make ethercat datagram sending by non sample code thread safe.

(Even when not fully initialized).
Also add some headers to .c files.
parent 5d4b5b4a
......@@ -17,6 +17,15 @@
*/
/*
ec.c
Low level ethercat bus handling.
Higher level functions like ESC or application can use these.
- Send/Receive PDOs
- Send/Receive datagrams
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -652,19 +661,23 @@ ssize_t ec_datagram_read(struct ec_dgram_addr *addr,
{
ssize_t ret;
if (!sample_running || controller_sample_context())
if (controller_sample_context())
return ec_datagram_read_real(addr, buffer, len);
pthread_mutex_lock(&datagram_lock);
if (!sample_running) {
ret = ec_datagram_read_real(addr, buffer, len);
} else {
datagram_addr = addr;
datagram_buffer = buffer;
datagram_len = len;
datagram_read = true;
datagram_addr = addr;
datagram_buffer = buffer;
datagram_len = len;
datagram_read = true;
sem_wait(&datagram_sync_sem);
sem_wait(&datagram_sync_sem);
ret = datagram_ret;
ret = datagram_ret;
}
pthread_mutex_unlock(&datagram_lock);
......@@ -736,19 +749,23 @@ ssize_t ec_datagram_write(struct ec_dgram_addr *addr,
{
ssize_t ret;
if (!sample_running || controller_sample_context())
if (controller_sample_context())
return ec_datagram_write_real(addr, buffer, len);
pthread_mutex_lock(&datagram_lock);
if (!sample_running || controller_sample_context()) {
ret = ec_datagram_write_real(addr, buffer, len);
} else {
datagram_addr = addr;
datagram_buffer = buffer;
datagram_len = len;
datagram_write = true;
datagram_addr = addr;
datagram_buffer = buffer;
datagram_len = len;
datagram_write = true;
sem_wait(&datagram_sync_sem);
sem_wait(&datagram_sync_sem);
ret = datagram_ret;
ret = datagram_ret;
}
pthread_mutex_unlock(&datagram_lock);
......
......@@ -16,6 +16,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Simple tool to enumerate all Ethercat devices on the bus.
*/
#include <stdio.h>
#include <stdlib.h>
......
/*
Ethernet device access for use on a BSD based OS.
*/
#include <err.h>
#include <stdio.h>
......
/*
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2013
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Ethernet device access for Linux.
*/
#include "eth.h"
#include "ec_int.h"
#include "log.h"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment