* This example does 3 instructions in one system call. It does
* a gettimeofday() call, then reads N_SAMPLES samples from an
* analog input, and the another gettimeofday() call.
+ *
+ * (Note: The gettimeofday() value is obtained using an INSN_GTOD
+ * instruction, which places the seconds value in data[0] and the
+ * microseconds in data[1], so the seconds value is limited to
+ * 32-bits even on 64-bit systems.)
*/
#define MAX_SAMPLES 128
int ret,i;
comedi_insn insn[3];
comedi_insnlist il;
- struct timeval t1,t2;
+ lsampl_t t1[2], t2[2];
lsampl_t data[MAX_SAMPLES];
struct parsed_options options;
/* Instruction 0: perform a gettimeofday() */
insn[0].insn=INSN_GTOD;
insn[0].n=2;
- insn[0].data=(void *)&t1;
+ insn[0].data=t1;
/* Instruction 1: do 10 analog input reads */
insn[1].insn=INSN_READ;
/* Instruction 2: perform a gettimeofday() */
insn[2].insn=INSN_GTOD;
insn[2].n=2;
- insn[2].data=(void *)&t2;
+ insn[2].data=t2;
ret=comedi_do_insnlist(device,&il);
if(ret<0){
exit(-1);
}
- printf("initial time: %ld.%06ld\n", t1.tv_sec, t1.tv_usec);
+ printf("initial time: %d.%06d\n", t1[0], t1[1]);
for(i = 0; i < options.n_scan; i++){
printf("%d\n", data[i]);
}
- printf("final time: %ld.%06ld\n", t2.tv_sec, t2.tv_usec);
+ printf("final time: %d.%06d\n", t2[0], t2[1]);
- printf("difference (us): %ld\n",(t2.tv_sec-t1.tv_sec) * 1000000 +
- (t2.tv_usec - t1.tv_usec));
+ printf("difference (us): %ld\n",(long)(t2[0]-t1[0]) * 1000000 +
+ (t2[1] - t1[1]));
return 0;
}
</term>
<listitem>
<para>
-read a timestamp, identical to gettimeofday()
+read a timestamp, identical to gettimeofday() except the seconds
+and microseconds values are of type <link linkend="ref-type-lsampl-t">lsampl_t</link>.
</para>
</listitem>
</varlistentry>
* This example does 3 instructions in one system call. It does
* a gettimeofday() call, then reads N_SAMPLES samples from an
* analog input, and the another gettimeofday() call.
+ *
+ * (Note: The gettimeofday() value is obtained using an INSN_GTOD
+ * instruction, which places the seconds value in data[0] and the
+ * microseconds in data[1], so the seconds value is limited to
+ * 32-bits even on 64-bit systems.)
*/
#define MAX_SAMPLES 128
int ret,i;
<link linkend="ref-type-comedi-insn">comedi_insn</link> insn[3];
<link linkend="ref-type-comedi-insnlist">comedi_insnlist</link> il;
- struct timeval t1,t2;
+ <link linkend="ref-type-lsampl-t">lsampl_t</link> t1[2], t2[2];
<link linkend="ref-type-lsampl-t">lsampl_t</link> data[MAX_SAMPLES];
parse_options(argc,argv);
/* Instruction 0: perform a gettimeofday() */
insn[0].insn=<link linkend="insn-gtod">INSN_GTOD</link>;
insn[0].n=2;
- insn[0].data=(void *)&t1;
+ insn[0].data=t1;
/* Instruction 1: do 10 analog input reads */
insn[1].insn=<link linkend="insn-read">INSN_READ</link>;
/* Instruction 2: perform a gettimeofday() */
insn[2].insn=<link linkend="insn-gtod">INSN_GTOD</link>;
insn[2].n=2;
- insn[2].data=(void *)&t2;
+ insn[2].data=t2;
ret=<link linkend="func-ref-comedi-do-insnlist">comedi_do_insnlist</link>(device,&il);
if(ret<![CDATA[<]]>0){
exit(0);
}
- printf("initial time: %ld.%06ld\n",t1.tv_sec,t1.tv_usec);
+ printf("initial time: %d.%06d\n",t1[0],t1[1]);
for(i=0;i<![CDATA[<]]>n_scan;i++){
printf("%d\n",data[i]);
}
- printf("final time: %ld.%06ld\n",t2.tv_sec,t2.tv_usec);
+ printf("final time: %d.%06d\n",t2[0],t2[1]);
- printf("difference (us): %ld\n",(t2.tv_sec-t1.tv_sec)*1000000+
- (t2.tv_usec-t1.tv_usec));
+ printf("difference (us): %ld\n",(long)(t2[0]-t1[0])*1000000+(t2[1]-t1[1]));
return 0;
}
{
comedi_insn insn[3];
comedi_insnlist il;
- struct timeval t1,t2;
+ lsampl_t t1[2],t2[2];
lsampl_t data;
int save_errno;
int ret;
insn[0].insn = INSN_GTOD;
insn[0].n=2;
- insn[0].data = (void *)&t1;
+ insn[0].data = t1;
insn[1].subdev = subdevice;
insn[1].insn = INSN_READ;
insn[2].insn = INSN_GTOD;
insn[2].n=2;
- insn[2].data = (void *)&t2;
+ insn[2].data = t2;
ret = comedi_do_insnlist(device,&il);
save_errno = errno;
}
printf("read time: %ld us\n",
- (t2.tv_sec-t1.tv_sec)*1000000+(t2.tv_usec-t1.tv_usec));
+ (long)(t2[0]-t1[0])*1000000+(t2[1]-t1[1]));
return 0;