463 ec_device_t *device /**< EtherCAT device */ |
463 ec_device_t *device /**< EtherCAT device */ |
464 ) |
464 ) |
465 { |
465 { |
466 unsigned int i; |
466 unsigned int i; |
467 |
467 |
468 u32 tx_frame_rate = |
468 s32 tx_frame_rate = (device->tx_count - device->last_tx_count) * 1000; |
469 (u32) (device->tx_count - device->last_tx_count) * 1000; |
469 s32 rx_frame_rate = (device->rx_count - device->last_rx_count) * 1000; |
470 u32 rx_frame_rate = |
470 s32 tx_byte_rate = (device->tx_bytes - device->last_tx_bytes); |
471 (u32) (device->rx_count - device->last_rx_count) * 1000; |
471 s32 rx_byte_rate = (device->rx_bytes - device->last_rx_bytes); |
472 u32 tx_byte_rate = |
472 |
473 (device->tx_bytes - device->last_tx_bytes); |
473 /* Low-pass filter: |
474 u32 rx_byte_rate = |
474 * Y_n = y_(n - 1) + T / tau * (x - y_(n - 1)) | T = 1 |
475 (device->rx_bytes - device->last_rx_bytes); |
475 * -> Y_n += (x - y_(n - 1)) / tau |
476 |
476 */ |
477 for (i = 0; i < EC_RATE_COUNT; i++) { |
477 for (i = 0; i < EC_RATE_COUNT; i++) { |
478 unsigned int n = rate_intervals[i]; |
478 s32 n = rate_intervals[i]; |
479 device->tx_frame_rates[i] = |
479 device->tx_frame_rates[i] += |
480 (device->tx_frame_rates[i] * (n - 1) + tx_frame_rate) / n; |
480 (tx_frame_rate - device->tx_frame_rates[i]) / n; |
481 device->rx_frame_rates[i] = |
481 device->rx_frame_rates[i] += |
482 (device->rx_frame_rates[i] * (n - 1) + rx_frame_rate) / n; |
482 (rx_frame_rate - device->rx_frame_rates[i]) / n; |
483 device->tx_byte_rates[i] = |
483 device->tx_byte_rates[i] += |
484 (device->tx_byte_rates[i] * (n - 1) + tx_byte_rate) / n; |
484 (tx_byte_rate - device->tx_byte_rates[i]) / n; |
485 device->rx_byte_rates[i] = |
485 device->rx_byte_rates[i] += |
486 (device->rx_byte_rates[i] * (n - 1) + rx_byte_rate) / n; |
486 (rx_byte_rate - device->rx_byte_rates[i]) / n; |
487 } |
487 } |
488 |
488 |
489 device->last_tx_count = device->tx_count; |
489 device->last_tx_count = device->tx_count; |
490 device->last_rx_count = device->rx_count; |
490 device->last_rx_count = device->rx_count; |
491 device->last_tx_bytes = device->tx_bytes; |
491 device->last_tx_bytes = device->tx_bytes; |