equal
deleted
inserted
replaced
979 /*****************************************************************************/ |
979 /*****************************************************************************/ |
980 |
980 |
981 /** Sends the datagrams in the queue for a certain device. |
981 /** Sends the datagrams in the queue for a certain device. |
982 * |
982 * |
983 */ |
983 */ |
984 void ec_master_send_datagrams( |
984 size_t ec_master_send_datagrams( |
985 ec_master_t *master, /**< EtherCAT master */ |
985 ec_master_t *master, /**< EtherCAT master */ |
986 ec_device_index_t device_index /**< Device index. */ |
986 ec_device_index_t device_index /**< Device index. */ |
987 ) |
987 ) |
988 { |
988 { |
989 ec_datagram_t *datagram, *next; |
989 ec_datagram_t *datagram, *next; |
994 cycles_t cycles_start, cycles_sent, cycles_end; |
994 cycles_t cycles_start, cycles_sent, cycles_end; |
995 #endif |
995 #endif |
996 unsigned long jiffies_sent; |
996 unsigned long jiffies_sent; |
997 unsigned int frame_count, more_datagrams_waiting; |
997 unsigned int frame_count, more_datagrams_waiting; |
998 struct list_head sent_datagrams; |
998 struct list_head sent_datagrams; |
|
999 size_t sent_bytes = 0; |
999 |
1000 |
1000 #ifdef EC_HAVE_CYCLES |
1001 #ifdef EC_HAVE_CYCLES |
1001 cycles_start = get_cycles(); |
1002 cycles_start = get_cycles(); |
1002 #endif |
1003 #endif |
1003 frame_count = 0; |
1004 frame_count = 0; |
1079 EC_MASTER_DBG(master, 2, "frame size: %zu\n", cur_data - frame_data); |
1080 EC_MASTER_DBG(master, 2, "frame size: %zu\n", cur_data - frame_data); |
1080 |
1081 |
1081 // send frame |
1082 // send frame |
1082 ec_device_send(&master->devices[device_index], |
1083 ec_device_send(&master->devices[device_index], |
1083 cur_data - frame_data); |
1084 cur_data - frame_data); |
|
1085 /* preamble and inter-frame gap */ |
|
1086 sent_bytes += ETH_HLEN + cur_data - frame_data + ETH_FCS_LEN + 20; |
1084 #ifdef EC_HAVE_CYCLES |
1087 #ifdef EC_HAVE_CYCLES |
1085 cycles_sent = get_cycles(); |
1088 cycles_sent = get_cycles(); |
1086 #endif |
1089 #endif |
1087 jiffies_sent = jiffies; |
1090 jiffies_sent = jiffies; |
1088 |
1091 |
1096 list_del_init(&datagram->sent); // empty list of sent datagrams |
1099 list_del_init(&datagram->sent); // empty list of sent datagrams |
1097 } |
1100 } |
1098 |
1101 |
1099 frame_count++; |
1102 frame_count++; |
1100 } |
1103 } |
1101 while (more_datagrams_waiting); |
1104 while (more_datagrams_waiting && frame_count < EC_TX_RING_SIZE); |
1102 |
1105 |
1103 #ifdef EC_HAVE_CYCLES |
1106 #ifdef EC_HAVE_CYCLES |
1104 if (unlikely(master->debug_level > 1)) { |
1107 if (unlikely(master->debug_level > 1)) { |
1105 cycles_end = get_cycles(); |
1108 cycles_end = get_cycles(); |
1106 EC_MASTER_DBG(master, 0, "%s()" |
1109 EC_MASTER_DBG(master, 0, "%s()" |
1107 " sent %u frames in %uus.\n", __func__, frame_count, |
1110 " sent %u frames in %uus.\n", __func__, frame_count, |
1108 (unsigned int) (cycles_end - cycles_start) * 1000 / cpu_khz); |
1111 (unsigned int) (cycles_end - cycles_start) * 1000 / cpu_khz); |
1109 } |
1112 } |
1110 #endif |
1113 #endif |
|
1114 return sent_bytes; |
1111 } |
1115 } |
1112 |
1116 |
1113 /*****************************************************************************/ |
1117 /*****************************************************************************/ |
1114 |
1118 |
1115 /** Processes a received frame. |
1119 /** Processes a received frame. |
1533 */ |
1537 */ |
1534 static int ec_master_idle_thread(void *priv_data) |
1538 static int ec_master_idle_thread(void *priv_data) |
1535 { |
1539 { |
1536 ec_master_t *master = (ec_master_t *) priv_data; |
1540 ec_master_t *master = (ec_master_t *) priv_data; |
1537 int fsm_exec; |
1541 int fsm_exec; |
1538 #ifdef EC_USE_HRTIMER |
|
1539 size_t sent_bytes; |
1542 size_t sent_bytes; |
1540 #endif |
|
1541 |
1543 |
1542 // send interval in IDLE phase |
1544 // send interval in IDLE phase |
1543 ec_master_set_send_interval(master, 1000000 / HZ); |
1545 ec_master_set_send_interval(master, 1000000 / HZ); |
1544 |
1546 |
1545 EC_MASTER_DBG(master, 1, "Idle thread running with send interval = %u us," |
1547 EC_MASTER_DBG(master, 1, "Idle thread running with send interval = %u us," |
1568 // queue and send |
1570 // queue and send |
1569 down(&master->io_sem); |
1571 down(&master->io_sem); |
1570 if (fsm_exec) { |
1572 if (fsm_exec) { |
1571 ec_master_queue_datagram(master, &master->fsm_datagram); |
1573 ec_master_queue_datagram(master, &master->fsm_datagram); |
1572 } |
1574 } |
1573 ecrt_master_send(master); |
1575 sent_bytes = ecrt_master_send(master); |
1574 #ifdef EC_USE_HRTIMER |
|
1575 sent_bytes = master->devices[EC_DEVICE_MAIN].tx_skb[ |
|
1576 master->devices[EC_DEVICE_MAIN].tx_ring_index]->len; |
|
1577 #endif |
|
1578 up(&master->io_sem); |
1576 up(&master->io_sem); |
1579 |
1577 |
1580 if (ec_fsm_master_idle(&master->fsm)) { |
1578 if (ec_fsm_master_idle(&master->fsm)) { |
1581 #ifdef EC_USE_HRTIMER |
1579 #ifdef EC_USE_HRTIMER |
1582 ec_master_nanosleep(master->send_interval * 1000); |
1580 ec_master_nanosleep(master->send_interval * 1000); |
1584 set_current_state(TASK_INTERRUPTIBLE); |
1582 set_current_state(TASK_INTERRUPTIBLE); |
1585 schedule_timeout(1); |
1583 schedule_timeout(1); |
1586 #endif |
1584 #endif |
1587 } else { |
1585 } else { |
1588 #ifdef EC_USE_HRTIMER |
1586 #ifdef EC_USE_HRTIMER |
1589 ec_master_nanosleep(sent_bytes * EC_BYTE_TRANSMISSION_TIME_NS); |
1587 ec_master_nanosleep( |
|
1588 sent_bytes * EC_BYTE_TRANSMISSION_TIME_NS * 6 / 5); |
1590 #else |
1589 #else |
1591 schedule(); |
1590 schedule(); |
1592 #endif |
1591 #endif |
1593 } |
1592 } |
1594 } |
1593 } |
2445 master->active = 0; |
2444 master->active = 0; |
2446 } |
2445 } |
2447 |
2446 |
2448 /*****************************************************************************/ |
2447 /*****************************************************************************/ |
2449 |
2448 |
2450 void ecrt_master_send(ec_master_t *master) |
2449 size_t ecrt_master_send(ec_master_t *master) |
2451 { |
2450 { |
2452 ec_datagram_t *datagram, *n; |
2451 ec_datagram_t *datagram, *n; |
2453 ec_device_index_t dev_idx; |
2452 ec_device_index_t dev_idx; |
|
2453 size_t sent_bytes = 0; |
|
2454 |
2454 |
2455 |
2455 if (master->injection_seq_rt != master->injection_seq_fsm) { |
2456 if (master->injection_seq_rt != master->injection_seq_fsm) { |
2456 // inject datagram produced by master FSM |
2457 // inject datagram produced by master FSM |
2457 ec_master_queue_datagram(master, &master->fsm_datagram); |
2458 ec_master_queue_datagram(master, &master->fsm_datagram); |
2458 master->injection_seq_rt = master->injection_seq_fsm; |
2459 master->injection_seq_rt = master->injection_seq_fsm; |
2483 ec_device_clear_stats(&master->devices[dev_idx]); |
2484 ec_device_clear_stats(&master->devices[dev_idx]); |
2484 continue; |
2485 continue; |
2485 } |
2486 } |
2486 |
2487 |
2487 // send frames |
2488 // send frames |
2488 ec_master_send_datagrams(master, dev_idx); |
2489 sent_bytes = max(sent_bytes, |
2489 } |
2490 ec_master_send_datagrams(master, dev_idx)); |
|
2491 } |
|
2492 |
|
2493 return sent_bytes; |
2490 } |
2494 } |
2491 |
2495 |
2492 /*****************************************************************************/ |
2496 /*****************************************************************************/ |
2493 |
2497 |
2494 void ecrt_master_receive(ec_master_t *master) |
2498 void ecrt_master_receive(ec_master_t *master) |