Re: [Linuxptp-users] Issue with initial high jitter(Path Delay Variation)
PTP IEEE 1588 stack for Linux
Brought to you by:
rcochran
From: Sujatha G. <suj...@gm...> - 2016-02-18 10:33:17
|
Hi Richard, to avoid the confusion, I am putting both the functions below here completely. Please have a look. static int xlnx_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) { struct xlnx_ptp_timer *timer = container_of(ptp, struct xlnx_ptp_timer, ptp_clock_info); int neg_adj = 0; u64 freq = 0; u32 diff = 0; u32 incval = 0; /* External clock source Frequency is 200MHz */ /* adjust the RTC Increment Control register by (1/200MHZ = 5ns) */ /* resolution of the increment register is 1/1048576 */ /* hence 5 * 1048576 = 0x500000 - value to be written to the register */ incval = 0x500000; if (ppb < 0) { neg_adj = 1; ppb = -ppb; } freq = incval; freq *= ppb; diff = div_u64(freq, 1000000000ULL); incval = neg_adj ? (incval - diff) : (incval + diff); /* Write the adjusted value to the RTC Increment Value Control Register */ /* Writing the adjustment value to this register intern adjusts the nanoseconds register value by the hw */ *out_be32((timer->baseaddr + XTIMER1588_RTC_INCREMENT), incval);* return 0; } static int xlnx_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) { unsigned long flags = 0; struct xlnx_ptp_timer *timer = container_of(ptp, struct xlnx_ptp_timer, ptp_clock_info); struct timespec offset, *then = ns_to_timespec(delta);* spin_lock_irqsave(&timer->reg_lock, flags); /* Read the seconds and nano seconds from the RTC Seconds and RTC Nano Seconds Registers */ xlnx_rtc_offset_read(timer, &offset); /* set the current offset values */ *offset = then;* /* Write the seconds and nano seconds to the RTC Seconds and RTC Nano Seconds Registers */ xlnx_rtc_offset_write(timer, (const struct timespec *)*&offset*); spin_unlock_irqrestore(&timer->reg_lock, flags); return 0; } Best Regards, Sujatha On Thu, Feb 18, 2016 at 3:33 PM, Sujatha Guguloth <suj...@gm...> wrote: > Hi Richard, > > I am writing the incval to the register in adjfreq after the calculation.I > had written that in the comments and actual code is below. > out_be32((timer->baseaddr + XTIMER1588_RTC_INCREMENT), incval); > > > In adjtime: delta is passed to ns_to_timespec > then = ns_to_timespec(delta) > offset = then; /* then is copied to offset */ > xlnx_rtc_offset_write(timer, (const struct timespec *)&offset); /* This > offset is written to the register */ > > > Best Regards, > Sujatha > > > On Thu, Feb 18, 2016 at 2:59 PM, Richard Cochran <ric...@gm... > > wrote: > >> Wow, your code is totally broken... >> >> On Thu, Feb 18, 2016 at 12:04:22PM +0530, Sujatha Guguloth wrote: >> > static int xlnx_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) >> > { >> > struct xlnx_ptp_timer *timer = container_of(ptp, struct >> > xlnx_ptp_timer, >> > ptp_clock_info); >> > >> > int neg_adj = 0; >> > u64 freq = 0; >> > u32 diff = 0; >> > u32 incval = 0; >> > >> > /* External clock source Frequency is 200MHz which is driving >> > the timer */ >> > /* adjust the RTC Increment Control register by (1/200MHZ = >> 5ns) */ >> > /* resolution of the increment register is 1/1048576 >> */ >> > /* hence 5 * 1048576 = 0x500000 - value to be written to the >> > register */ >> > incval = 0x500000; >> > >> > if (ppb < 0) { >> > neg_adj = 1; >> > ppb = -ppb; >> > } >> > >> > freq = incval; >> > freq *= ppb; >> > diff = div_u64(freq, 1000000000ULL); >> > >> > incval = neg_adj ? (incval - diff) : (incval + diff); >> > >> > /* Write the adjusted value to the *RTC Increment Value Control >> > Register* */ >> > /* Writing the adjustment value to this register intern adjusts >> the >> > nanoseconds register value by the hw */ >> >> You calculate 'incval' and then do nothing with it. >> >> > return 0; >> > } >> > >> > >> > static int xlnx_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) >> > { >> > unsigned long flags = 0; >> > struct xlnx_ptp_timer *timer = container_of(ptp, struct >> > xlnx_ptp_timer, >> > ptp_clock_info); >> > struct timespec offset, then = ns_to_timespec(delta); >> > >> > spin_lock_irqsave(&timer->reg_lock, flags); >> > >> > /* Read the seconds and nano seconds from the RTC Seconds and >> RTC >> > Nano Seconds Registers */ >> > xlnx_rtc_offset_read(timer, &offset); >> > >> > /* set the current offset values */ >> > offset = then; >> >> You are supposed to add the delta. >> >> > /* Write the seconds and nano seconds to the *RTC Seconds* and >> *RTC >> > Nano Seconds* Registers */ >> > xlnx_rtc_offset_write(timer, (const struct timespec *)&offset); >> > >> > spin_unlock_irqrestore(&timer->reg_lock, flags); >> > return 0; >> > } >> >> Good luck, >> Richard >> > > |