diff --git a/TODO b/TODO index daef2f42..5aeff333 100644 --- a/TODO +++ b/TODO @@ -46,7 +46,6 @@ Version 1.5.0: - Implement ranges for slaves and domains. * Output send errors in frame statistics. * Output tx rate [bytes/s] in frame statistics. -* Fix clearing statistics on link down. Future issues: diff --git a/master/device.c b/master/device.c index c1a2c398..9e195727 100644 --- a/master/device.c +++ b/master/device.c @@ -324,37 +324,22 @@ void ec_device_send( // frame statistics if (unlikely(jiffies - device->stats_jiffies >= HZ)) { unsigned int i; - if (device->link_state) { - unsigned int tx_rate = - (device->tx_count - device->last_tx_count) * 1000; - int loss = device->tx_count - device->rx_count; - int loss_rate = (loss - device->last_loss) * 1000; - for (i = 0; i < EC_RATE_COUNT; i++) { - unsigned int n = rate_intervals[i]; - device->tx_rates[i] = - (device->tx_rates[i] * (n - 1) + tx_rate) / n; - device->loss_rates[i] = - (device->loss_rates[i] * (n - 1) + loss_rate) / n; - } - device->last_tx_count = device->tx_count; - device->last_loss = loss; - } else { - // zero frame statistics - device->tx_count = 0; - device->rx_count = 0; - device->last_tx_count = 0; - device->last_loss = 0; - for (i = 0; i < EC_RATE_COUNT; i++) { - device->tx_rates[i] = 0; - device->loss_rates[i] = 0; - } + unsigned int tx_rate = + (device->tx_count - device->last_tx_count) * 1000; + int loss = device->tx_count - device->rx_count; + int loss_rate = (loss - device->last_loss) * 1000; + for (i = 0; i < EC_RATE_COUNT; i++) { + unsigned int n = rate_intervals[i]; + device->tx_rates[i] = + (device->tx_rates[i] * (n - 1) + tx_rate) / n; + device->loss_rates[i] = + (device->loss_rates[i] * (n - 1) + loss_rate) / n; } + device->last_tx_count = device->tx_count; + device->last_loss = loss; device->stats_jiffies = jiffies; } - if (unlikely(!device->link_state)) // Link down - return; - // set the right length for the data skb->len = ETH_HLEN + size; @@ -384,6 +369,27 @@ void ec_device_send( /*****************************************************************************/ +/** Clears the frame statistics. + */ +void ec_device_clear_stats( + ec_device_t *device /**< EtherCAT device */ + ) +{ + unsigned int i; + + // zero frame statistics + device->tx_count = 0; + device->rx_count = 0; + device->last_tx_count = 0; + device->last_loss = 0; + for (i = 0; i < EC_RATE_COUNT; i++) { + device->tx_rates[i] = 0; + device->loss_rates[i] = 0; + } +} + +/*****************************************************************************/ + #ifdef EC_DEBUG_RING /** Appends frame data to the debug ring. */ diff --git a/master/device.h b/master/device.h index 17e6bae8..fed949b2 100644 --- a/master/device.h +++ b/master/device.h @@ -134,6 +134,7 @@ int ec_device_close(ec_device_t *); void ec_device_poll(ec_device_t *); uint8_t *ec_device_tx_data(ec_device_t *); void ec_device_send(ec_device_t *, size_t); +void ec_device_clear_stats(ec_device_t *); #ifdef EC_DEBUG_RING void ec_device_debug_ring_append(ec_device_t *, ec_debug_frame_dir_t, diff --git a/master/master.c b/master/master.c index 9365accc..3b38af0e 100644 --- a/master/master.c +++ b/master/master.c @@ -2084,6 +2084,9 @@ void ecrt_master_send(ec_master_t *master) // query link state ec_device_poll(&master->main_device); + + // clear frame statistics + ec_device_clear_stats(&master->main_device); return; }