[etherlab-users] system_time_base
xiaoliang.li at scbd.com.cn
xiaoliang.li at scbd.com.cn
Wed Apr 20 11:27:27 CEST 2016
When I run the /example/rtai_rtdm_dc. Why the system_time_base is less than
zero for sometimes. Than the master will report error message
""Synchronization error"" ,the AL status code is 0x001A.
The code is following:
void update_master_clock(void)
{
#if SYNC_MASTER_TO_REF
// calc drift (via un-normalised time diff)
int32_t delta = dc_diff_ns - prev_dc_diff_ns;
prev_dc_diff_ns = dc_diff_ns;
// normalise the time diff
dc_diff_ns =
((dc_diff_ns + (cycle_ns / 2)) % cycle_ns) - (cycle_ns / 2);
// only update if primary master
if (dc_started) {
// add to totals
dc_diff_total_ns += dc_diff_ns;
dc_delta_total_ns += delta;
dc_filter_idx++;
if (dc_filter_idx >= DC_FILTER_CNT) {
// add rounded delta average
dc_adjust_ns +=
((dc_delta_total_ns + (DC_FILTER_CNT / 2)) / DC_FILTER_CNT);
// and add adjustment for general diff (to pull in drift)
dc_adjust_ns += sign(dc_diff_total_ns / DC_FILTER_CNT);
// limit crazy numbers (0.1% of std cycle time)
if (dc_adjust_ns < -1000) {
dc_adjust_ns = -1000;
}
if (dc_adjust_ns > 1000) {
dc_adjust_ns = 1000;
}
// reset
dc_diff_total_ns = 0LL;
dc_delta_total_ns = 0LL;
dc_filter_idx = 0;
}
// add cycles adjustment to time base (including a spot adjustment)
system_time_base += dc_adjust_ns + sign(dc_diff_ns);
}
else {
dc_started = (dc_diff_ns != 0);
if (dc_started) {
// output first diff
rt_printk("First master diff: %d.\n", dc_diff_ns);
// record the time of this initial cycle
dc_start_time_ns = dc_time_ns;
}
}
When system_time_base is less than zero ,the master can not be sync
to the ref clock slave.
But I do not know ,why the system_time_base can be less than zero?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.etherlab.org/pipermail/etherlab-users/attachments/20160420/937a55bb/attachment-0002.htm>
More information about the Etherlab-users
mailing list