Added some slave configuration methods.

This commit is contained in:
Florian Pose 2008-10-09 13:31:50 +00:00
parent 0c998363fb
commit 95e60a2fec
9 changed files with 971 additions and 8 deletions

View File

@ -1,6 +1,33 @@
/*****************************************************************************
*
* $Id$
* $Id$
*
* Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH
*
* This file is part of the IgH EtherCAT Master.
*
* The IgH EtherCAT Master 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 2 of the
* License, or (at your option) any later version.
*
* The IgH EtherCAT Master 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 the IgH EtherCAT Master; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* The right to use EtherCAT Technology is granted and comes free of
* charge under condition of compatibility of product made by
* Licensee. People intending to distribute/sell products based on the
* code, have to sign an agreement to guarantee that products using
* software based on IgH EtherCAT master stay compatible with the actual
* EtherCAT specification (which are released themselves as an open
* standard) as the (only) precondition to have the right to use EtherCAT
* Technology, IP and trade marks.
*
****************************************************************************/
@ -13,15 +40,132 @@
#include <sys/types.h>
#include <unistd.h>
/****************************************************************************/
#include "ecrt.h"
/****************************************************************************/
// Optional features
#define CONFIGURE_PDOS 1
#define EL3152_ALT_PDOS 0
#define SDO_ACCESS 0
#define VOE_ACCESS 0
#define PRIORITY 1
#define BusCouplerPos 0, 0
#define AnaOutSlavePos 0, 1
#define AnaInSlavePos 0, 2
#define DigOutSlavePos 0, 3
#define Beckhoff_EK1100 0x00000002, 0x044C2C52
#define Beckhoff_EL2004 0x00000002, 0x07D43052
#define Beckhoff_EL3152 0x00000002, 0x0c503052
#define Beckhoff_EL4102 0x00000002, 0x10063052
/****************************************************************************/
static unsigned int sig_alarms = 0;
static unsigned int user_alarms = 0;
// offsets for Pdo entries
static unsigned int off_ana_in;
static unsigned int off_ana_out;
static unsigned int off_dig_out;
const static ec_pdo_entry_reg_t domain1_regs[] = {
#if EL3152_ALT_PDOS
{AnaInSlavePos, Beckhoff_EL3152, 0x6401, 1, &off_ana_in},
#else
{AnaInSlavePos, Beckhoff_EL3152, 0x3101, 2, &off_ana_in},
#endif
{AnaOutSlavePos, Beckhoff_EL4102, 0x3001, 1, &off_ana_out},
{DigOutSlavePos, Beckhoff_EL2004, 0x3001, 1, &off_dig_out},
{}
};
static ec_slave_config_t *sc_ana_in = NULL;
/*****************************************************************************/
#if CONFIGURE_PDOS
// Analog in --------------------------
static ec_pdo_entry_info_t el3152_pdo_entries[] = {
{0x3101, 1, 8}, // channel 1 status
{0x3101, 2, 16}, // channel 1 value
{0x3102, 1, 8}, // channel 2 status
{0x3102, 2, 16}, // channel 2 value
{0x6401, 1, 16}, // channel 1 value (alt.)
{0x6401, 2, 16} // channel 2 value (alt.)
};
#if EL3152_ALT_PDOS
static ec_pdo_info_t el3152_pdos[] = {
{0x1A10, 2, el3152_pdo_entries + 4},
};
static ec_sync_info_t el3152_syncs[] = {
{2, EC_DIR_OUTPUT},
{3, EC_DIR_INPUT, 1, el3152_pdos},
{0xff}
};
#else
static ec_pdo_info_t el3152_pdos[] = {
{0x1A00, 2, el3152_pdo_entries},
{0x1A01, 2, el3152_pdo_entries + 2}
};
static ec_sync_info_t el3152_syncs[] = {
{2, EC_DIR_OUTPUT},
{3, EC_DIR_INPUT, 2, el3152_pdos},
{0xff}
};
#endif
// Analog out -------------------------
static ec_pdo_entry_info_t el4102_pdo_entries[] = {
{0x3001, 1, 16}, // channel 1 value
{0x3002, 1, 16}, // channel 2 value
};
static ec_pdo_info_t el4102_pdos[] = {
{0x1600, 1, el4102_pdo_entries},
{0x1601, 1, el4102_pdo_entries + 1}
};
static ec_sync_info_t el4102_syncs[] = {
{2, EC_DIR_OUTPUT, 2, el4102_pdos},
{3, EC_DIR_INPUT},
{0xff}
};
// Digital out ------------------------
static ec_pdo_entry_info_t el2004_channels[] = {
{0x3001, 1, 1}, // Value 1
{0x3001, 2, 1}, // Value 2
{0x3001, 3, 1}, // Value 3
{0x3001, 4, 1} // Value 4
};
static ec_pdo_info_t el2004_pdos[] = {
{0x1600, 1, &el2004_channels[0]},
{0x1601, 1, &el2004_channels[1]},
{0x1602, 1, &el2004_channels[2]},
{0x1603, 1, &el2004_channels[3]}
};
static ec_sync_info_t el2004_syncs[] = {
{0, EC_DIR_OUTPUT, 4, el2004_pdos},
{1, EC_DIR_INPUT},
{0xff}
};
#endif
/****************************************************************************/
void signal_handler(int signum) {
@ -37,7 +181,7 @@ void signal_handler(int signum) {
int main(int argc, char **argv)
{
ec_master_t *master;
ec_domain_t *domain;
ec_domain_t *domain1;
ec_slave_config_t *sc;
struct sigaction sa;
struct itimerval tv;
@ -46,14 +190,56 @@ int main(int argc, char **argv)
if (!master)
return -1;
domain = ecrt_master_create_domain(master);
if (!domain)
domain1 = ecrt_master_create_domain(master);
if (!domain1)
return -1;
sc = ecrt_master_slave_config(master, 0, 0, 0x00000002, 0x044C2C52);
if (!(sc_ana_in = ecrt_master_slave_config(
master, AnaInSlavePos, Beckhoff_EL3152))) {
fprintf(stderr, "Failed to get slave configuration.\n");
return -1;
}
#if CONFIGURE_PDOS
printf("Configuring Pdos...\n");
if (ecrt_slave_config_pdos(sc_ana_in, EC_END, el3152_syncs)) {
fprintf(stderr, "Failed to configure Pdos.\n");
return -1;
}
if (!(sc = ecrt_master_slave_config(
master, AnaOutSlavePos, Beckhoff_EL4102))) {
fprintf(stderr, "Failed to get slave configuration.\n");
return -1;
}
if (ecrt_slave_config_pdos(sc, EC_END, el4102_syncs)) {
fprintf(stderr, "Failed to configure Pdos.\n");
return -1;
}
if (!(sc = ecrt_master_slave_config(
master, DigOutSlavePos, Beckhoff_EL2004))) {
fprintf(stderr, "Failed to get slave configuration.\n");
return -1;
}
if (ecrt_slave_config_pdos(sc, EC_END, el2004_syncs)) {
fprintf(stderr, "Failed to configure Pdos.\n");
return -1;
}
#endif
// Create configuration for bus coupler
sc = ecrt_master_slave_config(master, BusCouplerPos, Beckhoff_EK1100);
if (!sc)
return -1;
if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) {
fprintf(stderr, "Pdo entry registration failed!\n");
return -1;
}
printf("Activating master...\n");
if (ecrt_master_activate(master))
return -1;
@ -75,7 +261,7 @@ int main(int argc, char **argv)
printf("Starting timer...\n");
tv.it_interval.tv_sec = 0;
tv.it_interval.tv_usec = 100000;
tv.it_interval.tv_usec = 10000;
tv.it_value.tv_sec = 0;
tv.it_value.tv_usec = 1000;
if (setitimer(ITIMER_REAL, &tv, NULL)) {
@ -87,7 +273,7 @@ int main(int argc, char **argv)
while (1) {
sleep(1);
#if 1
#if 0
struct timeval t;
gettimeofday(&t, NULL);
printf("%u.%06u\n", t.tv_sec, t.tv_usec);

View File

@ -41,7 +41,9 @@ libethercat_la_LDFLAGS = -version-info 1:0:0
libethercat_la_CFLAGS = -I$(srcdir)/..
libethercat_la_SOURCES = \
common.c \
master.c
domain.c \
master.c \
slave_config.c
noinst_HEADERS = \
domain.h \

99
lib/domain.c Normal file
View File

@ -0,0 +1,99 @@
/******************************************************************************
*
* $Id$
*
* Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH
*
* This file is part of the IgH EtherCAT Master.
*
* The IgH EtherCAT Master 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 2 of the
* License, or (at your option) any later version.
*
* The IgH EtherCAT Master 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 the IgH EtherCAT Master; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* The right to use EtherCAT Technology is granted and comes free of
* charge under condition of compatibility of product made by
* Licensee. People intending to distribute/sell products based on the
* code, have to sign an agreement to guarantee that products using
* software based on IgH EtherCAT master stay compatible with the actual
* EtherCAT specification (which are released themselves as an open
* standard) as the (only) precondition to have the right to use EtherCAT
* Technology, IP and trade marks.
*
*****************************************************************************/
/**
\file
EtherCAT domain methods.
*/
/*****************************************************************************/
#include "domain.h"
/*****************************************************************************/
int ecrt_domain_reg_pdo_entry_list(ec_domain_t *domain,
const ec_pdo_entry_reg_t *regs)
{
const ec_pdo_entry_reg_t *reg;
ec_slave_config_t *sc;
int ret;
for (reg = regs; reg->index; reg++) {
if (!(sc = ecrt_master_slave_config(domain->master, reg->alias,
reg->position, reg->vendor_id, reg->product_code)))
return -1;
if ((ret = ecrt_slave_config_reg_pdo_entry(sc, reg->index,
reg->subindex, domain, reg->bit_position)) < 0)
return -1;
*reg->offset = ret;
}
return 0;
}
/*****************************************************************************/
size_t ecrt_domain_size(ec_domain_t *domain)
{
return 0;
}
/*****************************************************************************/
uint8_t *ecrt_domain_data(ec_domain_t *domain)
{
return 0;
}
/*****************************************************************************/
void ecrt_domain_process(ec_domain_t *domain)
{
}
/*****************************************************************************/
void ecrt_domain_queue(ec_domain_t *domain)
{
}
/*****************************************************************************/
void ecrt_domain_state(const ec_domain_t *domain, ec_domain_state_t *state)
{
}
/*****************************************************************************/

View File

@ -37,6 +37,7 @@
struct ec_domain {
unsigned int index;
ec_master_t *master;
};
/*****************************************************************************/

View File

@ -63,6 +63,7 @@ ec_domain_t *ecrt_master_create_domain(ec_master_t *master)
}
domain->index = (unsigned int) index;
domain->master = master;
return domain;
}
@ -94,7 +95,10 @@ ec_slave_config_t *ecrt_master_slave_config(ec_master_t *master,
return 0;
}
sc->master = master;
sc->index = data.config_index;
sc->alias = alias;
sc->position = position;
return sc;
}

319
lib/slave_config.c Normal file
View File

@ -0,0 +1,319 @@
/******************************************************************************
*
* $Id$
*
* Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH
*
* This file is part of the IgH EtherCAT Master.
*
* The IgH EtherCAT Master 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 2 of the
* License, or (at your option) any later version.
*
* The IgH EtherCAT Master 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 the IgH EtherCAT Master; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* The right to use EtherCAT Technology is granted and comes free of
* charge under condition of compatibility of product made by
* Licensee. People intending to distribute/sell products based on the
* code, have to sign an agreement to guarantee that products using
* software based on IgH EtherCAT master stay compatible with the actual
* EtherCAT specification (which are released themselves as an open
* standard) as the (only) precondition to have the right to use EtherCAT
* Technology, IP and trade marks.
*
*****************************************************************************/
#include <stdlib.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "slave_config.h"
#include "domain.h"
#include "master.h"
#include "master/ioctl.h"
/*****************************************************************************/
int ecrt_slave_config_sync_manager(ec_slave_config_t *sc, uint8_t sync_index,
ec_direction_t dir)
{
ec_ioctl_config_t data;
unsigned int i;
if (sync_index >= EC_MAX_SYNC_MANAGERS)
return -1;
memset(&data, 0x00, sizeof(ec_ioctl_config_t));
data.config_index = sc->index;
data.syncs[sync_index].dir = dir;
if (ioctl(sc->master->fd, EC_IOCTL_SC_SYNC, &data) == -1) {
fprintf(stderr, "Failed to config sync manager: %s\n",
strerror(errno));
return -1;
}
return 0;
}
/*****************************************************************************/
int ecrt_slave_config_pdo_assign_add(ec_slave_config_t *sc,
uint8_t sync_index, uint16_t pdo_index)
{
ec_ioctl_config_pdo_t data;
data.config_index = sc->index;
data.sync_index = sync_index;
data.index = pdo_index;
if (ioctl(sc->master->fd, EC_IOCTL_SC_ADD_PDO, &data) == -1) {
fprintf(stderr, "Failed to add Pdo: %s\n",
strerror(errno));
return -1;
}
return 0;
}
/*****************************************************************************/
void ecrt_slave_config_pdo_assign_clear(ec_slave_config_t *sc,
uint8_t sync_index)
{
ec_ioctl_config_pdo_t data;
data.config_index = sc->index;
data.sync_index = sync_index;
if (ioctl(sc->master->fd, EC_IOCTL_SC_CLEAR_PDOS, &data) == -1) {
fprintf(stderr, "Failed to clear Pdos: %s\n",
strerror(errno));
}
}
/*****************************************************************************/
int ecrt_slave_config_pdo_mapping_add(ec_slave_config_t *sc,
uint16_t pdo_index, uint16_t entry_index, uint8_t entry_subindex,
uint8_t entry_bit_length)
{
ec_ioctl_add_pdo_entry_t data;
data.config_index = sc->index;
data.pdo_index = pdo_index;
data.entry_index = entry_index;
data.entry_subindex = entry_subindex;
data.entry_bit_length = entry_bit_length;
if (ioctl(sc->master->fd, EC_IOCTL_SC_ADD_ENTRY, &data) == -1) {
fprintf(stderr, "Failed to add Pdo entry: %s\n",
strerror(errno));
return -1;
}
return 0;
}
/*****************************************************************************/
void ecrt_slave_config_pdo_mapping_clear(ec_slave_config_t *sc,
uint16_t pdo_index)
{
ec_ioctl_config_pdo_t data;
data.config_index = sc->index;
data.index = pdo_index;
if (ioctl(sc->master->fd, EC_IOCTL_SC_CLEAR_ENTRIES, &data) == -1) {
fprintf(stderr, "Failed to clear Pdo entries: %s\n",
strerror(errno));
}
}
/*****************************************************************************/
int ecrt_slave_config_pdos(ec_slave_config_t *sc,
unsigned int n_syncs, const ec_sync_info_t syncs[])
{
unsigned int i, j, k;
const ec_sync_info_t *sync_info;
const ec_pdo_info_t *pdo_info;
const ec_pdo_entry_info_t *entry_info;
if (!syncs)
return 0;
for (i = 0; i < n_syncs; i++) {
sync_info = &syncs[i];
if (sync_info->index == (uint8_t) EC_END)
break;
if (sync_info->index >= EC_MAX_SYNC_MANAGERS) {
fprintf(stderr, "Invalid sync manager index %u!\n",
sync_info->index);
return -1;
}
if (ecrt_slave_config_sync_manager(
sc, sync_info->index, sync_info->dir))
return -1;
if (sync_info->n_pdos && sync_info->pdos) {
ecrt_slave_config_pdo_assign_clear(sc, sync_info->index);
for (j = 0; j < sync_info->n_pdos; j++) {
pdo_info = &sync_info->pdos[j];
if (ecrt_slave_config_pdo_assign_add(
sc, sync_info->index, pdo_info->index))
return -1;
if (pdo_info->n_entries && pdo_info->entries) {
ecrt_slave_config_pdo_mapping_clear(sc, pdo_info->index);
for (k = 0; k < pdo_info->n_entries; k++) {
entry_info = &pdo_info->entries[k];
if (ecrt_slave_config_pdo_mapping_add(sc,
pdo_info->index, entry_info->index,
entry_info->subindex,
entry_info->bit_length))
return -1;
}
}
}
}
}
return 0;
}
/*****************************************************************************/
int ecrt_slave_config_reg_pdo_entry(
ec_slave_config_t *sc,
uint16_t index,
uint8_t subindex,
ec_domain_t *domain,
unsigned int *bit_position
)
{
ec_ioctl_reg_pdo_entry_t data;
int ret;
data.config_index = sc->index;
data.entry_index = index;
data.entry_subindex = subindex;
data.domain_index = domain->index;
ret = ioctl(sc->master->fd, EC_IOCTL_SC_REG_PDO_ENTRY, &data);
if (ret == -1) {
fprintf(stderr, "Failed to register Pdo entry: %s\n",
strerror(errno));
return -2;
}
if (bit_position) {
*bit_position = data.bit_position;
} else {
if (data.bit_position) {
fprintf(stderr, "Pdo entry 0x%04X:%02X does not byte-align "
"in config %u:%u.\n", index, subindex,
sc->alias, sc->position);
return -3;
}
}
return ret;
}
/*****************************************************************************/
int ecrt_slave_config_sdo(ec_slave_config_t *sc, uint16_t index,
uint8_t subindex, const uint8_t *sdo_data, size_t size)
{
ec_ioctl_sc_sdo_t data;
data.config_index = sc->index;
data.index = index;
data.subindex = subindex;
data.data = sdo_data;
data.size = size;
if (ioctl(sc->master->fd, EC_IOCTL_SC_REG_PDO_ENTRY, &data) == -1) {
fprintf(stderr, "Failed to configure Sdo.\n");
return -1;
}
return 0;
}
/*****************************************************************************/
int ecrt_slave_config_sdo8(ec_slave_config_t *sc, uint16_t index,
uint8_t subindex, uint8_t value)
{
uint8_t data[1];
EC_WRITE_U8(data, value);
return ecrt_slave_config_sdo(sc, index, subindex, data, 1);
}
/*****************************************************************************/
int ecrt_slave_config_sdo16(ec_slave_config_t *sc, uint16_t index,
uint8_t subindex, uint16_t value)
{
uint8_t data[2];
EC_WRITE_U16(data, value);
return ecrt_slave_config_sdo(sc, index, subindex, data, 2);
}
/*****************************************************************************/
int ecrt_slave_config_sdo32(ec_slave_config_t *sc, uint16_t index,
uint8_t subindex, uint32_t value)
{
uint8_t data[4];
EC_WRITE_U32(data, value);
return ecrt_slave_config_sdo(sc, index, subindex, data, 4);
}
/*****************************************************************************/
ec_sdo_request_t *ecrt_slave_config_create_sdo_request(ec_slave_config_t *sc,
uint16_t index, uint8_t subindex, size_t size)
{
return 0;
}
/*****************************************************************************/
ec_voe_handler_t *ecrt_slave_config_create_voe_handler(ec_slave_config_t *sc,
size_t size)
{
return 0;
}
/*****************************************************************************/
void ecrt_slave_config_state(const ec_slave_config_t *sc,
ec_slave_config_state_t *state)
{
}
/*****************************************************************************/

View File

@ -36,7 +36,10 @@
/*****************************************************************************/
struct ec_slave_config {
ec_master_t *master;
unsigned int index;
uint16_t alias;
uint16_t position;
};
/*****************************************************************************/

View File

@ -1509,6 +1509,285 @@ int ec_cdev_ioctl_receive(
return 0;
}
/*****************************************************************************/
/** Set the direction of a sync manager.
*/
int ec_cdev_ioctl_sc_sync(
ec_master_t *master, /**< EtherCAT master. */
unsigned long arg, /**< ioctl() argument. */
ec_cdev_priv_t *priv /**< Private data structure of file handle. */
)
{
ec_ioctl_config_t data;
ec_slave_config_t *sc;
unsigned int i;
int ret = 0;
if (unlikely(!priv->requested)) {
ret = -EPERM;
goto out_return;
}
if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ret = -EFAULT;
goto out_return;
}
if (down_interruptible(&master->master_sem)) {
ret = -EINTR;
goto out_return;
}
if (!(sc = ec_master_get_config(master, data.config_index))) {
ret = -ESRCH;
goto out_up;
}
for (i = 0; i < EC_MAX_SYNC_MANAGERS; i++) {
ec_direction_t dir = data.syncs[i].dir;
if (dir == EC_DIR_INPUT || dir == EC_DIR_OUTPUT) {
if (ecrt_slave_config_sync_manager(sc, i, dir)) {
ret = -EINVAL;
goto out_up;
}
}
}
out_up:
up(&master->master_sem);
out_return:
return ret;
}
/*****************************************************************************/
/** Add a Pdo to the assignment.
*/
int ec_cdev_ioctl_sc_add_pdo(
ec_master_t *master, /**< EtherCAT master. */
unsigned long arg, /**< ioctl() argument. */
ec_cdev_priv_t *priv /**< Private data structure of file handle. */
)
{
ec_ioctl_config_pdo_t data;
ec_slave_config_t *sc;
if (unlikely(!priv->requested))
return -EPERM;
if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
return -EFAULT;
if (down_interruptible(&master->master_sem))
return -EINTR;
if (!(sc = ec_master_get_config(master, data.config_index))) {
up(&master->master_sem);
return -ESRCH;
}
up(&master->master_sem); // FIXME
return ecrt_slave_config_pdo_assign_add(sc, data.sync_index, data.index);
}
/*****************************************************************************/
/** Clears the Pdo assignment.
*/
int ec_cdev_ioctl_sc_clear_pdos(
ec_master_t *master, /**< EtherCAT master. */
unsigned long arg, /**< ioctl() argument. */
ec_cdev_priv_t *priv /**< Private data structure of file handle. */
)
{
ec_ioctl_config_pdo_t data;
ec_slave_config_t *sc;
if (unlikely(!priv->requested))
return -EPERM;
if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
return -EFAULT;
if (down_interruptible(&master->master_sem))
return -EINTR;
if (!(sc = ec_master_get_config(master, data.config_index))) {
up(&master->master_sem);
return -ESRCH;
}
up(&master->master_sem); // FIXME
ecrt_slave_config_pdo_assign_clear(sc, data.sync_index);
return 0;
}
/*****************************************************************************/
/** Add an entry to a Pdo's mapping.
*/
int ec_cdev_ioctl_sc_add_entry(
ec_master_t *master, /**< EtherCAT master. */
unsigned long arg, /**< ioctl() argument. */
ec_cdev_priv_t *priv /**< Private data structure of file handle. */
)
{
ec_ioctl_add_pdo_entry_t data;
ec_slave_config_t *sc;
if (unlikely(!priv->requested))
return -EPERM;
if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
return -EFAULT;
if (down_interruptible(&master->master_sem))
return -EINTR;
if (!(sc = ec_master_get_config(master, data.config_index))) {
up(&master->master_sem);
return -ESRCH;
}
up(&master->master_sem); // FIXME
return ecrt_slave_config_pdo_mapping_add(sc, data.pdo_index,
data.entry_index, data.entry_subindex, data.entry_bit_length);
}
/*****************************************************************************/
/** Clears the mapping of a Pdo.
*/
int ec_cdev_ioctl_sc_clear_entries(
ec_master_t *master, /**< EtherCAT master. */
unsigned long arg, /**< ioctl() argument. */
ec_cdev_priv_t *priv /**< Private data structure of file handle. */
)
{
ec_ioctl_config_pdo_t data;
ec_slave_config_t *sc;
if (unlikely(!priv->requested))
return -EPERM;
if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
return -EFAULT;
if (down_interruptible(&master->master_sem))
return -EINTR;
if (!(sc = ec_master_get_config(master, data.config_index))) {
up(&master->master_sem);
return -ESRCH;
}
up(&master->master_sem); // FIXME
ecrt_slave_config_pdo_mapping_clear(sc, data.index);
return 0;
}
/*****************************************************************************/
/** Registers a Pdo entry.
*/
int ec_cdev_ioctl_sc_reg_pdo_entry(
ec_master_t *master, /**< EtherCAT master. */
unsigned long arg, /**< ioctl() argument. */
ec_cdev_priv_t *priv /**< Private data structure of file handle. */
)
{
ec_ioctl_reg_pdo_entry_t data;
ec_slave_config_t *sc;
ec_domain_t *domain;
int ret;
if (unlikely(!priv->requested))
return -EPERM;
if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
return -EFAULT;
if (down_interruptible(&master->master_sem))
return -EINTR;
if (!(sc = ec_master_get_config(master, data.config_index))) {
up(&master->master_sem);
return -ESRCH;
}
if (!(domain = ec_master_find_domain(master, data.domain_index))) {
up(&master->master_sem);
return -ESRCH;
}
up(&master->master_sem); // FIXME
ret = ecrt_slave_config_reg_pdo_entry(sc, data.entry_index,
data.entry_subindex, domain, &data.bit_position);
if (copy_to_user((void __user *) arg, &data, sizeof(data)))
return -EFAULT;
return ret;
}
/*****************************************************************************/
/** Configures an Sdo.
*/
int ec_cdev_ioctl_sc_sdo(
ec_master_t *master, /**< EtherCAT master. */
unsigned long arg, /**< ioctl() argument. */
ec_cdev_priv_t *priv /**< Private data structure of file handle. */
)
{
ec_ioctl_sc_sdo_t data;
ec_slave_config_t *sc;
uint8_t *sdo_data = NULL;
int ret;
if (unlikely(!priv->requested))
return -EPERM;
if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
return -EFAULT;
if (!data.size)
return -EINVAL;
if (!(sdo_data = kmalloc(data.size, GFP_KERNEL))) {
return -ENOMEM;
}
if (copy_from_user(sdo_data, (void __user *) data.data, data.size)) {
kfree(sdo_data);
return -EFAULT;
}
if (down_interruptible(&master->master_sem)) {
kfree(sdo_data);
return -EINTR;
}
if (!(sc = ec_master_get_config(master, data.config_index))) {
up(&master->master_sem);
kfree(sdo_data);
return -ESRCH;
}
up(&master->master_sem); // FIXME
ret = ecrt_slave_config_sdo(sc, data.index, data.subindex, sdo_data,
data.size);
kfree(sdo_data);
return ret;
}
/******************************************************************************
* File operations
*****************************************************************************/
@ -1646,6 +1925,34 @@ long eccdev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
if (!(filp->f_mode & FMODE_WRITE))
return -EPERM;
return ec_cdev_ioctl_receive(master, arg, priv);
case EC_IOCTL_SC_SYNC:
if (!(filp->f_mode & FMODE_WRITE))
return -EPERM;
return ec_cdev_ioctl_sc_sync(master, arg, priv);
case EC_IOCTL_SC_ADD_PDO:
if (!(filp->f_mode & FMODE_WRITE))
return -EPERM;
return ec_cdev_ioctl_sc_add_pdo(master, arg, priv);
case EC_IOCTL_SC_CLEAR_PDOS:
if (!(filp->f_mode & FMODE_WRITE))
return -EPERM;
return ec_cdev_ioctl_sc_clear_pdos(master, arg, priv);
case EC_IOCTL_SC_ADD_ENTRY:
if (!(filp->f_mode & FMODE_WRITE))
return -EPERM;
return ec_cdev_ioctl_sc_add_entry(master, arg, priv);
case EC_IOCTL_SC_CLEAR_ENTRIES:
if (!(filp->f_mode & FMODE_WRITE))
return -EPERM;
return ec_cdev_ioctl_sc_clear_entries(master, arg, priv);
case EC_IOCTL_SC_REG_PDO_ENTRY:
if (!(filp->f_mode & FMODE_WRITE))
return -EPERM;
return ec_cdev_ioctl_sc_reg_pdo_entry(master, arg, priv);
case EC_IOCTL_SC_SDO:
if (!(filp->f_mode & FMODE_WRITE))
return -EPERM;
return ec_cdev_ioctl_sc_sdo(master, arg, priv);
default:
return -ENOTTY;
}

View File

@ -85,6 +85,13 @@
#define EC_IOCTL_ACTIVATE EC_IO(0x19)
#define EC_IOCTL_SEND EC_IO(0x1a)
#define EC_IOCTL_RECEIVE EC_IO(0x1b)
#define EC_IOCTL_SC_SYNC EC_IOW(0x1c, ec_ioctl_config_t)
#define EC_IOCTL_SC_ADD_PDO EC_IOW(0x1c, ec_ioctl_config_pdo_t)
#define EC_IOCTL_SC_CLEAR_PDOS EC_IOW(0x1d, ec_ioctl_config_pdo_t)
#define EC_IOCTL_SC_ADD_ENTRY EC_IOW(0x1e, ec_ioctl_add_pdo_entry_t)
#define EC_IOCTL_SC_CLEAR_ENTRIES EC_IOW(0x1f, ec_ioctl_config_pdo_t)
#define EC_IOCTL_SC_REG_PDO_ENTRY EC_IOWR(0x20, ec_ioctl_reg_pdo_entry_t)
#define EC_IOCTL_SC_SDO EC_IOW(0x21, ec_ioctl_sc_sdo_t)
#define EC_IOCTL_STRING_SIZE 64
@ -368,6 +375,41 @@ typedef struct {
/*****************************************************************************/
typedef struct {
// inputs
uint32_t config_index;
uint16_t pdo_index;
uint16_t entry_index;
uint8_t entry_subindex;
uint8_t entry_bit_length;
} ec_ioctl_add_pdo_entry_t;
/*****************************************************************************/
typedef struct {
// inputs
uint32_t config_index;
uint16_t entry_index;
uint8_t entry_subindex;
uint32_t domain_index;
// outputs
unsigned int bit_position;
} ec_ioctl_reg_pdo_entry_t;
/*****************************************************************************/
typedef struct {
// inputs
uint32_t config_index;
uint16_t index;
uint8_t subindex;
const uint8_t *data;
size_t size;
} ec_ioctl_sc_sdo_t;
/*****************************************************************************/
/** \endcond */
#endif