[LinuxPPS] assert/clear

Paul paul at lavender-fam.net
Tue Jul 20 10:21:38 CEST 2010


Ahha - so it was an oncore issue. I assumed that the two parts were very
separate and asserts and clears were written with no regard to what used
them.
Thanks
Paul

On Mon, 2010-07-19 at 14:15 -0600, clemens at dwf.com wrote:
> > I was recently asking for advice about using an oncore, progress is
> > being made, thanks to Reg and Remco.
> > But I see another more basic problem. I see asserts incrementing, but
> > not my clears (i.e. it stays the same). How can an asserts be seen
> > without a clear between each one?
> > 
> No problem.
> It has to do with the arguments to the time_pps_setparams call in your 
> piece of code.
> There are three possibilities, CAPTURECLEAR, CAPTUREASSERT and CAPTUREBOTH.
> The code you have is obviously setting CAPTUREASSERT, so you are not seeing the
> CLEAR events.
> 
> If this is NTP, then the ONCORE driver sets this option based on the ASSERT/CLEAR
> statement in your ntp.oncore.0.
> 
> If this is something like my ppsapitest8.c (which I include below) or Rodolfo's 
> equivalent, then the call sets this arg to both.  Give the code below a try.
> 
> ---
>                                         Reg.Clemens
>                                         reg at dwf.com
> 
> -------------
> 
> #include <stdio.h>
> #include <errno.h>
> #include <fcntl.h>
> #include <sys/stat.h>
> #include <err.h>
> #include <sys/types.h>
> #include <time.h>
> #include <timepps.h>
> #include <string.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <termios.h>
> #include <errno.h>
> #include <sys/ioctl.h>
> 
> /* PPSAPI test */
> 
> void exit();
> 
> int
> main(int argc, char **argv)
> {
>         int i, fd2, mode, fd1, ldisc;
>         char Msg[200];
>         struct stat stat1, stat2;
>         u_int olda, oldc;
>         pps_info_t pi;
>         pps_params_t pp;
>         pps_handle_t ph;
>         char    *serial, *pps;
> 
>         olda = oldc = 0;
>         if (argc != 3) {
>                 fprintf (stderr, "USAGE: <serial tty> <pps>\n");
>                 exit(1);
>         }
> 
>         serial = argv[1];
>         pps = argv[2];
> 
>         if ((fd1=open(serial, B9600, O_RDWR))< 0) {
>                 fprintf(stderr, "Cant open %s, error = %d\n", serial, fd1);
>                 perror("aa");
>                 exit(1);
>         }
> 
>         i = ioctl(fd1, TIOCGETD, &ldisc);
>         fprintf (stderr, "See TIOCGETD, i = %d, ldisc = %d\n", i, ldisc);
>         /* can I stat a N_PPS ??? */
> 
>         i = stat (serial, &stat1);
>         fprintf(stderr, "stat returns %d\n", i);
> 
> #define N_PPS 18
>         fprintf(stderr, ">>>> Inside ifdef\n");
>         /* linuxPPS specific Code */
> 
>         stat2.st_dev = stat2.st_ino = -1;
>         ldisc = N_PPS;
> fprintf(stderr, "Before IOCTL\n");
>         if (ioctl(fd1, TIOCSETD, &ldisc)) {
> 
>                 /* here could not set the line discipline, treat as tty */
> 
>                 sprintf(Msg, "unable to set line discipline \"%d\" for device %s\n", ldisc, serial);
>                 fprintf(stderr, Msg);
>                 fprintf(stderr, "hope it's ok\n");
>         }
> 
> fprintf(stderr, "After IOCTL\n");
>         sleep(5);
> 
>         if ((fd2=open(pps, O_RDWR)) < 0) {
>                 fprintf(stderr, "Can't open fd2 (%s)\n", pps);
>                 exit(1);
>         }
> 
> fprintf (stderr, "fd2 = %d\n", fd2);
>         if ((i = time_pps_create(fd2, &ph)) < 0) {
>                 fprintf(stderr, "create returns %d\n", i);
>                 fprintf(stderr, "FAIL: time_pps_create\n");
>                 exit(1);
>         }
> 
> /***************************************/
> 
>         if ((i = time_pps_getcap(ph, &mode)) < 0) {
>                 printf("FAIL: getcap %d\n", i);
>                 exit(1);
>         }
> 
>         printf("getcap says 0x%x\n", mode);
> 
> /***************************************/
>                 perror("getparams:");
>                 exit (1);
>         }
> 
>         printf("getparam is 0x%x\n", pp.mode);
> 
> /***************************************/
> 
>         mode =        PPS_CAPTURECLEAR ;     /* */
>         pp.mode = mode;
> 
>         printf("set mode to 0x%x\n", pp.mode);
> 
>         if ((i = time_pps_setparams(ph, &pp)) <0) {
>                 printf("time_pps_setparams\n");
>                 perror("setparams:");
>                 exit (1);
>         }
> 
>         if ((i = time_pps_getparams(ph, &pp)) <0) {
>                 printf("time_pps_getparams\n");
>                 perror("getparams:");
>                 exit (1);
>         }
> 
>         printf("getparam is 0x%x\n", pp.mode);
> 
> /***************************************/
> 
>         mode =        PPS_CAPTUREBOTH  ;     /* */
>         pp.mode = mode;
> 
>         printf("set mode to 0x%x\n", pp.mode);
> 
>         if ((i = time_pps_setparams(ph, &pp)) <0) {
>                 printf("time_pps_setparams\n");
>                 perror("setparams:");
>                 exit (1);
>         }
> 
>         if ((i = time_pps_getparams(ph, &pp)) <0) {
>                 printf("time_pps_getparams\n");
>                 perror("getparams:");
>                 exit (1);
>         }
> 
>         printf("getparam is 0x%x\n", pp.mode);
> 
> /***************************************/
>                 exit (1);
>         }
> 
>         if ((i = time_pps_getparams(ph, &pp)) <0) {
>                 printf("time_pps_getparams\n");
>                 perror("getparams:");
>                 exit (1);
>         }
> 
>         printf("getparam is 0x%x\n", pp.mode);
> 
> /***************************************/
>         printf("Enter loop\n\n");
> 
>         while (1) {
>                 i = time_pps_fetch(ph, PPS_TSFMT_TSPEC, &pi, NULL);
>                 if (i < 0) {
>                         err(1, "time_pps_fetch");
>                         perror("fetch:");
>                 }
> 
>                 if (olda != pi.assert_sequence || oldc != pi.clear_sequence) {
>                         if ((i = time_pps_getparams(ph, &pp)) <0) {
>                                 printf("time_pps_getparams\n");
>                                 perror("getparams:");
>                                 exit (1);
>                         }
>                         printf("getparam is 0x%x\n", pp.mode);
>                         printf("getparam assert is %ld  %07ld\n", pp.assert_offset.tv_sec, pp.assert
> _offset.tv_nsec);
>                         printf("getparam clear  is %ld  %07ld\n", pp.clear_offset.tv_sec, pp.clear_o
> ffset.tv_nsec);
> 
>                         printf("A: %lu.%09ld #%lu     C: %lu.%09ld #%lu\n",
>                             pi.assert_timestamp.tv_sec,
>                             pi.assert_timestamp.tv_nsec,
>                             pi.assert_sequence,
> 
>                             pi.clear_timestamp.tv_sec,
>                             pi.clear_timestamp.tv_nsec,
>                             pi.clear_sequence);
> 
>                         olda = pi.assert_sequence;
>                         oldc = pi.clear_sequence;
>                 }
>         }
> 
>         exit(0);
> }
> 
> 
> ---
> 





More information about the LinuxPPS mailing list