author | Florian Pose <fp@igh-essen.com> |
Mon, 27 Jul 2009 10:48:52 +0000 | |
changeset 1509 | a864688e7de5 |
parent 1508 | 60a116ed3897 |
child 1510 | 88b608a1a7f3 |
permissions | -rw-r--r-- |
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
/****************************************************************************** |
1266
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
2 |
* |
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
3 |
* $Id$ |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
4 |
* |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
5 |
* Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
6 |
* |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT master userspace library. |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
8 |
* |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
9 |
* The IgH EtherCAT master userspace library is free software; you can |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
10 |
* redistribute it and/or modify it under the terms of the GNU Lesser General |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
11 |
* Public License as published by the Free Software Foundation; version 2.1 |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
12 |
* of the License. |
1287 | 13 |
* |
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
14 |
* The IgH EtherCAT master userspace library is distributed in the hope that |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
15 |
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
16 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
17 |
* GNU Lesser General Public License for more details. |
1287 | 18 |
* |
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
19 |
* You should have received a copy of the GNU Lesser General Public License |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
20 |
* along with the IgH EtherCAT master userspace library. If not, see |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
21 |
* <http://www.gnu.org/licenses/>. |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
22 |
* |
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1341
diff
changeset
|
23 |
* --- |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1341
diff
changeset
|
24 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1341
diff
changeset
|
25 |
* The license mentioned above concerns the source code only. Using the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1341
diff
changeset
|
26 |
* EtherCAT technology and brand is only permitted in compliance with the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1341
diff
changeset
|
27 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
28 |
* |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
29 |
*****************************************************************************/ |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
30 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
31 |
#include <stdlib.h> |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
#include <sys/ioctl.h> |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
#include <stdio.h> |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
34 |
#include <errno.h> |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
35 |
#include <string.h> |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
36 |
#include <sys/mman.h> |
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
38 |
#include "master.h" |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
39 |
#include "domain.h" |
1246
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
40 |
#include "slave_config.h" |
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
#include "master/ioctl.h" |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
43 |
/*****************************************************************************/ |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
44 |
|
1497
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
45 |
int ecrt_master_reserve(ec_master_t *master) |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
46 |
{ |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
47 |
if (ioctl(master->fd, EC_IOCTL_REQUEST, NULL) == -1) { |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
48 |
fprintf(stderr, "Failed to reserve master: %s\n", |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
49 |
strerror(errno)); |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
50 |
return -1; |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
51 |
} |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
52 |
} |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
53 |
|
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
54 |
/*****************************************************************************/ |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
55 |
|
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
56 |
ec_domain_t *ecrt_master_create_domain(ec_master_t *master) |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
57 |
{ |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
58 |
ec_domain_t *domain; |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
59 |
int index; |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
60 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
61 |
domain = malloc(sizeof(ec_domain_t)); |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
62 |
if (!domain) { |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
63 |
fprintf(stderr, "Failed to allocate memory.\n"); |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
64 |
return 0; |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
65 |
} |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
66 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
67 |
index = ioctl(master->fd, EC_IOCTL_CREATE_DOMAIN, NULL); |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
68 |
if (index == -1) { |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
69 |
fprintf(stderr, "Failed to create domain: %s\n", strerror(errno)); |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
70 |
free(domain); |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
71 |
return 0; |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
72 |
} |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
73 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
74 |
domain->index = (unsigned int) index; |
1255
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
1247
diff
changeset
|
75 |
domain->master = master; |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
76 |
domain->process_data = NULL; |
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
77 |
return domain; |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
78 |
} |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
79 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
80 |
/*****************************************************************************/ |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
81 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
82 |
ec_slave_config_t *ecrt_master_slave_config(ec_master_t *master, |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
83 |
uint16_t alias, uint16_t position, uint32_t vendor_id, |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
84 |
uint32_t product_code) |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
85 |
{ |
1246
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
86 |
ec_ioctl_config_t data; |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
87 |
ec_slave_config_t *sc; |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
88 |
int index; |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
89 |
|
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
90 |
sc = malloc(sizeof(ec_slave_config_t)); |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
91 |
if (!sc) { |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
92 |
fprintf(stderr, "Failed to allocate memory.\n"); |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
93 |
return 0; |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
94 |
} |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
95 |
|
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
96 |
data.alias = alias; |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
97 |
data.position = position; |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
98 |
data.vendor_id = vendor_id; |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
99 |
data.product_code = product_code; |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
100 |
|
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
101 |
if (ioctl(master->fd, EC_IOCTL_CREATE_SLAVE_CONFIG, &data) == -1) { |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
102 |
fprintf(stderr, "Failed to create slave config: %s\n", |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
103 |
strerror(errno)); |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
104 |
free(sc); |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
105 |
return 0; |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
106 |
} |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
107 |
|
1255
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
1247
diff
changeset
|
108 |
sc->master = master; |
1246
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
109 |
sc->index = data.config_index; |
1255
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
1247
diff
changeset
|
110 |
sc->alias = alias; |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
1247
diff
changeset
|
111 |
sc->position = position; |
1246
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
112 |
return sc; |
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
113 |
} |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
114 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
115 |
/*****************************************************************************/ |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
116 |
|
1497
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
117 |
int ecrt_master(ec_master_t* master, ec_master_info_t *master_info) |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
118 |
{ |
1508 | 119 |
ec_ioctl_master_t data; |
120 |
||
121 |
if (ioctl(master->fd, EC_IOCTL_MASTER, &data) < 0) { |
|
1497
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
122 |
fprintf(stderr, "Failed to get master info: %s\n", strerror(errno)); |
1508 | 123 |
return -1; |
124 |
} |
|
125 |
||
126 |
master_info->slave_count = data.slave_count; |
|
127 |
master_info->link_up = data.devices[0].link_state; |
|
128 |
master_info->app_time = data.app_time; |
|
129 |
return 0; |
|
1497
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
130 |
} |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
131 |
|
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
132 |
/*****************************************************************************/ |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
133 |
|
1341
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
134 |
int ecrt_master_slave(ec_master_t *master, uint16_t position, |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
135 |
ec_slave_info_t *slave_info) |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
136 |
{ |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
137 |
ec_ioctl_slave_t data; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
138 |
int index; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
139 |
|
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
140 |
data.position = position; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
141 |
|
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
142 |
if (ioctl(master->fd, EC_IOCTL_SLAVE, &data) == -1) { |
1497
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
143 |
fprintf(stderr, "Failed to get slave info: %s\n", strerror(errno)); |
1341
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
144 |
return -1; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
145 |
} |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
146 |
|
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
147 |
slave_info->position = data.position; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
148 |
slave_info->vendor_id = data.vendor_id; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
149 |
slave_info->product_code = data.product_code; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
150 |
slave_info->revision_number = data.revision_number; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
151 |
slave_info->serial_number = data.serial_number; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
152 |
slave_info->alias = data.alias; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
153 |
slave_info->current_on_ebus = data.current_on_ebus; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
154 |
slave_info->al_state = data.al_state; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
155 |
slave_info->error_flag = data.error_flag; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
156 |
slave_info->sync_count = data.sync_count; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
157 |
slave_info->sdo_count = data.sdo_count; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
158 |
strncpy(slave_info->name, data.name, EC_IOCTL_STRING_SIZE); |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
159 |
return 0; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
160 |
} |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
161 |
|
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
162 |
/*****************************************************************************/ |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
163 |
|
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
164 |
int ecrt_master_activate(ec_master_t *master) |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
165 |
{ |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
166 |
if (ioctl(master->fd, EC_IOCTL_ACTIVATE, |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
167 |
&master->process_data_size) == -1) { |
1247
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
168 |
fprintf(stderr, "Failed to activate master: %s\n", |
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
169 |
strerror(errno)); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1287
diff
changeset
|
170 |
return -1; // FIXME |
1247
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
171 |
} |
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
172 |
|
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
173 |
if (master->process_data_size) { |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
174 |
master->process_data = mmap(0, master->process_data_size, |
1259
5f9d1abbee71
Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents:
1258
diff
changeset
|
175 |
PROT_READ | PROT_WRITE, MAP_SHARED, master->fd, 0); |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
176 |
if (master->process_data == MAP_FAILED) { |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
177 |
fprintf(stderr, "Failed to map process data: %s", strerror(errno)); |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
178 |
master->process_data = NULL; |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
179 |
master->process_data_size = 0; |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1287
diff
changeset
|
180 |
return -1; // FIXME |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
181 |
} |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
182 |
|
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
183 |
// Access the mapped region to cause the initial page fault |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
184 |
printf("pd: %x\n", master->process_data[0]); |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
185 |
} |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
186 |
|
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
187 |
return 0; |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
188 |
} |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
189 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
190 |
/*****************************************************************************/ |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
191 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
192 |
void ecrt_master_send(ec_master_t *master) |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
193 |
{ |
1247
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
194 |
if (ioctl(master->fd, EC_IOCTL_SEND, NULL) == -1) { |
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
195 |
fprintf(stderr, "Failed to send: %s\n", strerror(errno)); |
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
196 |
} |
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
197 |
} |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
198 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
199 |
/*****************************************************************************/ |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
200 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
201 |
void ecrt_master_receive(ec_master_t *master) |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
202 |
{ |
1247
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
203 |
if (ioctl(master->fd, EC_IOCTL_RECEIVE, NULL) == -1) { |
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
204 |
fprintf(stderr, "Failed to receive: %s\n", strerror(errno)); |
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
205 |
} |
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
206 |
} |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
207 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
208 |
/*****************************************************************************/ |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
209 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
210 |
void ecrt_master_state(const ec_master_t *master, ec_master_state_t *state) |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
211 |
{ |
1259
5f9d1abbee71
Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents:
1258
diff
changeset
|
212 |
if (ioctl(master->fd, EC_IOCTL_MASTER_STATE, state) == -1) { |
5f9d1abbee71
Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents:
1258
diff
changeset
|
213 |
fprintf(stderr, "Failed to get master state: %s\n", strerror(errno)); |
5f9d1abbee71
Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents:
1258
diff
changeset
|
214 |
} |
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
215 |
} |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
216 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
217 |
/*****************************************************************************/ |
1413
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
218 |
|
1434
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
219 |
void ecrt_master_application_time(ec_master_t *master, uint64_t app_time) |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
220 |
{ |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
221 |
ec_ioctl_app_time_t data; |
1413
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
222 |
|
1417
7c2d5d69134c
Replaced timeval by 64-bit EtherCAT time.
Florian Pose <fp@igh-essen.com>
parents:
1413
diff
changeset
|
223 |
data.app_time = app_time; |
1413
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
224 |
|
1434
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
225 |
if (ioctl(master->fd, EC_IOCTL_APP_TIME, &data) == -1) { |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
226 |
fprintf(stderr, "Failed to set application time: %s\n", |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
227 |
strerror(errno)); |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
228 |
} |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
229 |
} |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
230 |
|
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
231 |
/*****************************************************************************/ |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
232 |
|
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
233 |
void ecrt_master_sync_reference_clock(ec_master_t *master) |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
234 |
{ |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
235 |
if (ioctl(master->fd, EC_IOCTL_SYNC_REF, NULL) == -1) { |
1413
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
236 |
fprintf(stderr, "Failed to sync reference clock: %s\n", |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
237 |
strerror(errno)); |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
238 |
} |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
239 |
} |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
240 |
|
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
241 |
/*****************************************************************************/ |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
242 |
|
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
243 |
void ecrt_master_sync_slave_clocks(ec_master_t *master) |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
244 |
{ |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
245 |
if (ioctl(master->fd, EC_IOCTL_SYNC_SLAVES, NULL) == -1) { |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
246 |
fprintf(stderr, "Failed to sync slave clocks: %s\n", strerror(errno)); |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
247 |
} |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
248 |
} |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
249 |
|
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
250 |
/*****************************************************************************/ |
1441
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
251 |
|
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
252 |
int ecrt_slave_sdo_download(ec_master_t* master, uint16_t slave_position, |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
253 |
uint16_t index, uint8_t subindex, uint8_t *data, |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
254 |
size_t data_size, uint32_t *abort_code) |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
255 |
{ |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
256 |
ec_ioctl_slave_sdo_download_t download; |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
257 |
|
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
258 |
download.slave_position = slave_position; |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
259 |
download.sdo_index = index; |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
260 |
download.sdo_entry_subindex = subindex; |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
261 |
download.data_size = data_size; |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
262 |
download.data = data; |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
263 |
|
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
264 |
if (ioctl(master->fd, EC_IOCTL_SLAVE_SDO_DOWNLOAD, &download) == -1) { |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
265 |
if (errno == -EIO) { |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
266 |
if (abort_code) { |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
267 |
*abort_code = download.abort_code; |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
268 |
} |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
269 |
} |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
270 |
fprintf(stderr, "Failed to execute SDO download: %s\n", |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
271 |
strerror(errno)); |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
272 |
return -1; |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
273 |
} |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
274 |
|
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
275 |
return 0; |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
276 |
} |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
277 |
|
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
278 |
/*****************************************************************************/ |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
279 |
|
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
280 |
int ecrt_slave_sdo_upload(ec_master_t* master, uint16_t slave_position, |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
281 |
uint16_t index, uint8_t subindex, uint8_t *target, |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
282 |
size_t target_size, size_t *result_size, uint32_t *abort_code) |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
283 |
{ |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
284 |
ec_ioctl_slave_sdo_upload_t upload; |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
285 |
|
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
286 |
upload.slave_position = slave_position; |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
287 |
upload.sdo_index = index; |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
288 |
upload.sdo_entry_subindex = subindex; |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
289 |
upload.target_size = target_size; |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
290 |
upload.target = target; |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
291 |
|
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
292 |
if (ioctl(master->fd, EC_IOCTL_SLAVE_SDO_UPLOAD, &upload) == -1) { |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
293 |
if (errno == -EIO) { |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
294 |
if (abort_code) { |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
295 |
*abort_code = upload.abort_code; |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
296 |
} |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
297 |
} |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
298 |
fprintf(stderr, "Failed to execute SDO upload: %s\n", |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
299 |
strerror(errno)); |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
300 |
return -1; |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
301 |
} |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
302 |
|
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
303 |
*result_size = upload.data_size; |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
304 |
return 0; |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
305 |
} |
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
306 |
|
27a8d6f97a95
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
Florian Pose <fp@igh-essen.com>
parents:
1434
diff
changeset
|
307 |
/*****************************************************************************/ |