62 static int ec_master_operation_thread(ec_master_t *); |
62 static int ec_master_operation_thread(ec_master_t *); |
63 #ifdef EC_EOE |
63 #ifdef EC_EOE |
64 void ec_master_eoe_run(unsigned long); |
64 void ec_master_eoe_run(unsigned long); |
65 #endif |
65 #endif |
66 void ec_master_check_sdo(unsigned long); |
66 void ec_master_check_sdo(unsigned long); |
67 int ec_master_measure_bus_time(ec_master_t *); |
|
68 ssize_t ec_show_master_attribute(struct kobject *, struct attribute *, char *); |
67 ssize_t ec_show_master_attribute(struct kobject *, struct attribute *, char *); |
69 ssize_t ec_store_master_attribute(struct kobject *, struct attribute *, |
68 ssize_t ec_store_master_attribute(struct kobject *, struct attribute *, |
70 const char *, size_t); |
69 const char *, size_t); |
71 |
70 |
72 /*****************************************************************************/ |
71 /*****************************************************************************/ |
1204 #endif |
1203 #endif |
1205 |
1204 |
1206 /*****************************************************************************/ |
1205 /*****************************************************************************/ |
1207 |
1206 |
1208 /** |
1207 /** |
1209 Measures the time, a frame is on the bus. |
|
1210 \return 0 in case of success, else < 0 |
|
1211 */ |
|
1212 |
|
1213 int ec_master_measure_bus_time(ec_master_t *master) |
|
1214 { |
|
1215 ec_datagram_t datagram; |
|
1216 uint32_t cur, sum, min, max, i; |
|
1217 |
|
1218 ec_datagram_init(&datagram); |
|
1219 |
|
1220 if (ec_datagram_brd(&datagram, 0x0130, 2)) { |
|
1221 EC_ERR("Failed to allocate datagram for bus time measuring.\n"); |
|
1222 ec_datagram_clear(&datagram); |
|
1223 return -1; |
|
1224 } |
|
1225 |
|
1226 ecrt_master_receive(master); |
|
1227 |
|
1228 sum = 0; |
|
1229 min = 0xFFFFFFFF; |
|
1230 max = 0; |
|
1231 |
|
1232 for (i = 0; i < 100; i++) { |
|
1233 ec_master_queue_datagram(master, &datagram); |
|
1234 ecrt_master_send(master); |
|
1235 |
|
1236 while (1) { |
|
1237 ecrt_master_receive(master); |
|
1238 |
|
1239 if (datagram.state == EC_DATAGRAM_RECEIVED) { |
|
1240 break; |
|
1241 } |
|
1242 else if (datagram.state == EC_DATAGRAM_ERROR) { |
|
1243 EC_WARN("Failed to measure bus time.\n"); |
|
1244 goto error; |
|
1245 } |
|
1246 else if (datagram.state == EC_DATAGRAM_TIMED_OUT) { |
|
1247 EC_WARN("Timeout while measuring bus time.\n"); |
|
1248 goto error; |
|
1249 } |
|
1250 } |
|
1251 |
|
1252 cur = (unsigned int) (datagram.cycles_received |
|
1253 - datagram.cycles_sent) * 1000 / cpu_khz; |
|
1254 sum += cur; |
|
1255 if (cur > max) max = cur; |
|
1256 if (cur < min) min = cur; |
|
1257 } |
|
1258 |
|
1259 EC_DBG("Bus time is (min/avg/max) %u / %u.%u / %u us.\n", |
|
1260 min, sum / 100, sum % 100, max); |
|
1261 ec_datagram_clear(&datagram); |
|
1262 return 0; |
|
1263 |
|
1264 error: |
|
1265 ec_datagram_clear(&datagram); |
|
1266 return -1; |
|
1267 } |
|
1268 |
|
1269 /*****************************************************************************/ |
|
1270 |
|
1271 /** |
|
1272 Prepares synchronous IO. |
1208 Prepares synchronous IO. |
1273 Queues all domain datagrams and sends them. Then waits a certain time, so |
1209 Queues all domain datagrams and sends them. Then waits a certain time, so |
1274 that ecrt_master_receive() can be called securely. |
1210 that ecrt_master_receive() can be called securely. |
1275 */ |
1211 */ |
1276 |
1212 |