1 /****************************************************************************** |
1 /****************************************************************************** |
2 * |
2 * |
3 * $Id$ |
3 * $Id$ |
4 * |
4 * |
5 * Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH |
5 * Copyright (C) 2006-2012 Florian Pose, Ingenieurgemeinschaft IgH |
6 * |
6 * |
7 * This file is part of the IgH EtherCAT master userspace library. |
7 * This file is part of the IgH EtherCAT master userspace library. |
8 * |
8 * |
9 * The IgH EtherCAT master userspace library is free software; you can |
9 * The IgH EtherCAT master userspace library is free software; you can |
10 * redistribute it and/or modify it under the terms of the GNU Lesser General |
10 * redistribute it and/or modify it under the terms of the GNU Lesser General |
33 */ |
33 */ |
34 |
34 |
35 /*****************************************************************************/ |
35 /*****************************************************************************/ |
36 |
36 |
37 #include <stdio.h> |
37 #include <stdio.h> |
38 #include <errno.h> |
|
39 #include <string.h> |
38 #include <string.h> |
40 #include <sys/ioctl.h> |
|
41 |
39 |
|
40 #include "ioctl.h" |
42 #include "sdo_request.h" |
41 #include "sdo_request.h" |
43 #include "master/ioctl.h" |
|
44 #include "slave_config.h" |
42 #include "slave_config.h" |
45 #include "master.h" |
43 #include "master.h" |
46 |
44 |
47 /*****************************************************************************/ |
45 /*****************************************************************************/ |
48 |
46 |
58 ****************************************************************************/ |
56 ****************************************************************************/ |
59 |
57 |
60 void ecrt_sdo_request_timeout(ec_sdo_request_t *req, uint32_t timeout) |
58 void ecrt_sdo_request_timeout(ec_sdo_request_t *req, uint32_t timeout) |
61 { |
59 { |
62 ec_ioctl_sdo_request_t data; |
60 ec_ioctl_sdo_request_t data; |
|
61 int ret; |
63 |
62 |
64 data.config_index = req->config->index; |
63 data.config_index = req->config->index; |
65 data.request_index = req->index; |
64 data.request_index = req->index; |
66 data.timeout = timeout; |
65 data.timeout = timeout; |
67 |
66 |
68 if (ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_TIMEOUT, |
67 ret = ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_TIMEOUT, &data); |
69 &data) == -1) |
68 if (EC_IOCTL_IS_ERROR(ret)) { |
70 fprintf(stderr, "Failed to set SDO request timeout: %s\n", |
69 fprintf(stderr, "Failed to set SDO request timeout: %s\n", |
71 strerror(errno)); |
70 strerror(EC_IOCTL_ERRNO(ret))); |
|
71 } |
72 } |
72 } |
73 |
73 |
74 /*****************************************************************************/ |
74 /*****************************************************************************/ |
75 |
75 |
76 uint8_t *ecrt_sdo_request_data(ec_sdo_request_t *req) |
76 uint8_t *ecrt_sdo_request_data(ec_sdo_request_t *req) |
88 /*****************************************************************************/ |
88 /*****************************************************************************/ |
89 |
89 |
90 ec_request_state_t ecrt_sdo_request_state(ec_sdo_request_t *req) |
90 ec_request_state_t ecrt_sdo_request_state(ec_sdo_request_t *req) |
91 { |
91 { |
92 ec_ioctl_sdo_request_t data; |
92 ec_ioctl_sdo_request_t data; |
|
93 int ret; |
93 |
94 |
94 data.config_index = req->config->index; |
95 data.config_index = req->config->index; |
95 data.request_index = req->index; |
96 data.request_index = req->index; |
96 |
97 |
97 if (ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_STATE, |
98 ret = ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_STATE, &data); |
98 &data) == -1) |
99 if (EC_IOCTL_IS_ERROR(ret)) { |
99 fprintf(stderr, "Failed to get SDO request state: %s\n", |
100 fprintf(stderr, "Failed to get SDO request state: %s\n", |
100 strerror(errno)); |
101 strerror(EC_IOCTL_ERRNO(ret))); |
|
102 return EC_REQUEST_ERROR; |
|
103 } |
101 |
104 |
102 if (data.size) { // new data waiting to be copied |
105 if (data.size) { // new data waiting to be copied |
103 if (req->mem_size < data.size) { |
106 if (req->mem_size < data.size) { |
104 fprintf(stderr, "Received %u bytes do not fit info SDO data" |
107 fprintf(stderr, "Received %u bytes do not fit info SDO data" |
105 " memory (%u bytes)!\n", data.size, req->mem_size); |
108 " memory (%u bytes)!\n", data.size, req->mem_size); |
106 return EC_REQUEST_ERROR; |
109 return EC_REQUEST_ERROR; |
107 } |
110 } |
108 |
111 |
109 data.data = req->data; |
112 data.data = req->data; |
110 |
113 |
111 if (ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_DATA, |
114 ret = ioctl(req->config->master->fd, |
112 &data) == -1) { |
115 EC_IOCTL_SDO_REQUEST_DATA, &data); |
113 fprintf(stderr, "Failed to get SDO data: %s\n", strerror(errno)); |
116 if (EC_IOCTL_IS_ERROR(ret)) { |
|
117 fprintf(stderr, "Failed to get SDO data: %s\n", |
|
118 strerror(EC_IOCTL_ERRNO(ret))); |
114 return EC_REQUEST_ERROR; |
119 return EC_REQUEST_ERROR; |
115 } |
120 } |
116 req->data_size = data.size; |
121 req->data_size = data.size; |
117 } |
122 } |
118 |
123 |
122 /*****************************************************************************/ |
127 /*****************************************************************************/ |
123 |
128 |
124 void ecrt_sdo_request_read(ec_sdo_request_t *req) |
129 void ecrt_sdo_request_read(ec_sdo_request_t *req) |
125 { |
130 { |
126 ec_ioctl_sdo_request_t data; |
131 ec_ioctl_sdo_request_t data; |
|
132 int ret; |
127 |
133 |
128 data.config_index = req->config->index; |
134 data.config_index = req->config->index; |
129 data.request_index = req->index; |
135 data.request_index = req->index; |
130 |
136 |
131 if (ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_READ, |
137 ret = ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_READ, &data); |
132 &data) == -1) |
138 if (EC_IOCTL_IS_ERROR(ret)) { |
133 fprintf(stderr, "Failed to command an SDO read operation : %s\n", |
139 fprintf(stderr, "Failed to command an SDO read operation : %s\n", |
134 strerror(errno)); |
140 strerror(EC_IOCTL_ERRNO(ret))); |
|
141 } |
135 } |
142 } |
136 |
143 |
137 /*****************************************************************************/ |
144 /*****************************************************************************/ |
138 |
145 |
139 void ecrt_sdo_request_write(ec_sdo_request_t *req) |
146 void ecrt_sdo_request_write(ec_sdo_request_t *req) |
140 { |
147 { |
141 ec_ioctl_sdo_request_t data; |
148 ec_ioctl_sdo_request_t data; |
|
149 int ret; |
142 |
150 |
143 data.config_index = req->config->index; |
151 data.config_index = req->config->index; |
144 data.request_index = req->index; |
152 data.request_index = req->index; |
145 data.data = req->data; |
153 data.data = req->data; |
146 data.size = req->data_size; |
154 data.size = req->data_size; |
147 |
155 |
148 if (ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_WRITE, |
156 ret = ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_WRITE, &data); |
149 &data) == -1) |
157 if (EC_IOCTL_IS_ERROR(ret)) { |
150 fprintf(stderr, "Failed to command an SDO write operation : %s\n", |
158 fprintf(stderr, "Failed to command an SDO write operation : %s\n", |
151 strerror(errno)); |
159 strerror(EC_IOCTL_ERRNO(ret))); |
|
160 } |
152 } |
161 } |
153 |
162 |
154 /*****************************************************************************/ |
163 /*****************************************************************************/ |