1049 |
1049 |
1050 /*****************************************************************************/ |
1050 /*****************************************************************************/ |
1051 |
1051 |
1052 /** |
1052 /** |
1053 Measures the time, a frame is on the bus. |
1053 Measures the time, a frame is on the bus. |
1054 */ |
1054 \return 0 in case of success, else < 0 |
1055 |
1055 */ |
1056 void ec_master_measure_bus_time(ec_master_t *master) |
1056 |
|
1057 int ec_master_measure_bus_time(ec_master_t *master) |
1057 { |
1058 { |
1058 ec_datagram_t datagram; |
1059 ec_datagram_t datagram; |
1059 cycles_t cycles_start, cycles_end, cycles_timeout; |
1060 cycles_t cycles_start, cycles_end, cycles_timeout; |
1060 uint32_t times[100], sum, min, max, i; |
1061 uint32_t times[100], sum, min, max, i; |
1061 |
1062 |
1062 ec_datagram_init(&datagram); |
1063 ec_datagram_init(&datagram); |
1063 |
1064 |
1064 if (ec_datagram_brd(&datagram, 0x130, 2)) { |
1065 if (ec_datagram_brd(&datagram, 0x130, 2)) { |
1065 EC_ERR("Failed to allocate datagram for bus time measuring.\n"); |
1066 EC_ERR("Failed to allocate datagram for bus time measuring.\n"); |
1066 ec_datagram_clear(&datagram); |
1067 ec_datagram_clear(&datagram); |
1067 return; |
1068 return -1; |
1068 } |
1069 } |
1069 |
1070 |
1070 cycles_timeout = (cycles_t) EC_IO_TIMEOUT * (cpu_khz / 1000); |
1071 cycles_timeout = (cycles_t) EC_IO_TIMEOUT * (cpu_khz / 1000); |
1071 |
1072 |
1072 sum = 0; |
1073 sum = 0; |
1101 if (times[i] < min) min = times[i]; |
1102 if (times[i] < min) min = times[i]; |
1102 } |
1103 } |
1103 |
1104 |
1104 EC_INFO("Bus time is (min/avg/max) %u/%u.%u/%u us.\n", |
1105 EC_INFO("Bus time is (min/avg/max) %u/%u.%u/%u us.\n", |
1105 min, sum / 100, sum % 100, max); |
1106 min, sum / 100, sum % 100, max); |
|
1107 return 0; |
1106 |
1108 |
1107 error: |
1109 error: |
1108 // Dequeue and free datagram |
1110 // Dequeue and free datagram |
1109 list_del(&datagram.queue); |
1111 list_del(&datagram.queue); |
1110 ec_datagram_clear(&datagram); |
1112 ec_datagram_clear(&datagram); |
|
1113 return -1; |
1111 } |
1114 } |
1112 |
1115 |
1113 /****************************************************************************** |
1116 /****************************************************************************** |
1114 * Realtime interface |
1117 * Realtime interface |
1115 *****************************************************************************/ |
1118 *****************************************************************************/ |