[LinuxPPS] setting an offset
James Boddington
boddingt at internode.on.net
Thu Mar 27 01:55:23 CET 2008
Rodolfo Giometti wrote:
> On Wed, Mar 26, 2008 at 10:35:16AM +1000, James Boddington wrote:
>> Is there any documentation for setting a static offset with linuxpps? Looking
>> at the code it seems to be supported.
>
> No. But you can take a look at RFC.
Had a look at the RFC. Was easy enough to do. If anyone else is interested this
is what I did as a quick test.
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/pps.h>
main()
{
int fd;
struct pps_kparams params;
fd = open("/dev/pps0", O_RDWR);
if (fd < 0) {
printf("Oh...\n");
exit(1);
}
/* show current offset */
ioctl(fd, PPS_GETPARAMS, ¶ms);
printf(" sec %ld\n", params.assert_off_tu.sec);
printf("nsec %d\n", params.assert_off_tu.nsec);
/* set a 1ms offset */
params.mode |= PPS_OFFSETASSERT;
params.assert_off_tu.sec = 0; /* offset seconds */
params.assert_off_tu.nsec = 1000000; /* offset nanoseconds */
ioctl(fd, PPS_SETPARAMS, ¶ms);
/* show offset again to verify change */
ioctl(fd, PPS_GETPARAMS, ¶ms);
printf(" sec %ld\n", params.assert_off_tu.sec);
printf("nsec %d\n", params.assert_off_tu.nsec);
close(fd);
}
--
James
More information about the LinuxPPS
mailing list