163
203
msyslog(LOG_ERR, "vme_start: failed open of %s: %m", vmedev);
166
else { /* Release capture lockout in case it was set from before. */
167
if( ioctl( fd_vme, RUNLOCK, &dummy ) )
168
msyslog(LOG_ERR, "vme_start: RUNLOCK failed %m");
211
/* Release capture lockout in case it was set before. */
212
if( ioctl( fd_vme, RUNLOCK, &dummy ) )
213
msyslog(LOG_ERR, "vme_start: RUNLOCK failed %m");
170
regvalue = 0; /* More esoteric stuff to do... */
171
if( ioctl( fd_vme, WCR0, ®value ) )
172
msyslog(LOG_ERR, "vme_start: WCR0 failed %m");
215
regvalue = 0; /* More esoteric stuff to do... */
216
if( ioctl( fd_vme, WCR0, ®value ) )
217
msyslog(LOG_ERR, "vme_start: WCR0 failed %m");
326
373
get_datumtime(struct vmedate *time_vme)
328
unsigned short status;
330
376
struct btfp_time vts;
332
380
if ( time_vme == (struct vmedate *)NULL) {
333
381
time_vme = (struct vmedate *)malloc(sizeof(struct vmedate ));
336
if( ioctl(fd_vme, READTIME, &vts))
337
msyslog(LOG_ERR, "get_datumtime error: %m");
339
/* if you want to actually check the validity of these registers, do a
340
define of CHECK above this. I didn't find it necessary. - RES
346
sprintf(cbuf,"%3.3x", ((vts.btfp_time[ 0 ] & 0x000f) <<8) +
347
((vts.btfp_time[ 1 ] & 0xff00) >> 8));
349
if (isdigit(cbuf[0]) && isdigit(cbuf[1]) && isdigit(cbuf[2]) )
350
time_vme->day = (unsigned short)atoi(cbuf);
352
time_vme->day = (unsigned short) 0;
355
sprintf(cbuf,"%2.2x", vts.btfp_time[ 1 ] & 0x00ff);
357
if (isdigit(cbuf[0]) && isdigit(cbuf[1]))
358
time_vme->hr = (unsigned short)atoi(cbuf);
360
time_vme->hr = (unsigned short) 0;
363
sprintf(cbuf,"%2.2x", (vts.btfp_time[ 2 ] & 0xff00) >>8);
364
if (isdigit(cbuf[0]) && isdigit(cbuf[1]))
365
time_vme->mn = (unsigned short)atoi(cbuf);
367
time_vme->mn = (unsigned short) 0;
370
sprintf(cbuf,"%2.2x", vts.btfp_time[ 2 ] & 0x00ff);
372
if (isdigit(cbuf[0]) && isdigit(cbuf[1]))
373
time_vme->sec = (unsigned short)atoi(cbuf);
375
time_vme->sec = (unsigned short) 0;
377
/* Get microseconds. Yes, we ignore the 0.1 microsecond digit so we can
378
use the TVTOTSF function later on...*/
380
sprintf(cbuf,"%4.4x%2.2x", vts.btfp_time[ 3 ],
381
vts.btfp_time[ 4 ]>>8);
383
if (isdigit(cbuf[0]) && isdigit(cbuf[1]) && isdigit(cbuf[2])
384
&& isdigit(cbuf[3]) && isdigit(cbuf[4]) && isdigit(cbuf[5]))
385
time_vme->frac = (u_long) atoi(cbuf);
387
time_vme->frac = (u_long) 0;
390
/* DONT CHECK just trust the card */
393
sprintf(cbuf,"%3.3x", ((vts.btfp_time[ 0 ] & 0x000f) <<8) +
394
((vts.btfp_time[ 1 ] & 0xff00) >> 8));
395
time_vme->day = (unsigned short)atoi(cbuf);
398
sprintf(cbuf,"%2.2x", vts.btfp_time[ 1 ] & 0x00ff);
400
time_vme->hr = (unsigned short)atoi(cbuf);
403
sprintf(cbuf,"%2.2x", (vts.btfp_time[ 2 ] & 0xff00) >>8);
404
time_vme->mn = (unsigned short)atoi(cbuf);
407
sprintf(cbuf,"%2.2x", vts.btfp_time[ 2 ] & 0x00ff);
408
time_vme->sec = (unsigned short)atoi(cbuf);
410
/* Get microseconds. Yes, we ignore the 0.1 microsecond digit so we can
411
use the TVTOTSF function later on...*/
413
sprintf(cbuf,"%4.4x%2.2x", vts.btfp_time[ 3 ],
414
vts.btfp_time[ 4 ]>>8);
416
time_vme->frac = (u_long) atoi(cbuf);
421
status = (vts.btfp_time[0] & 0x0010) >>4;
422
time_vme->status = status; /* Status=0 if locked to ref. */
423
/* Status=1 if flywheeling */
424
if (status) { /* lost lock ? */
385
case 1: /* BSD, PCI, 2 32bit time words */
386
if (ioctl(fd_vme, READTIME, &btm)) {
387
msyslog(LOG_ERR, "get_bc63x error: %m");
390
tvme_fill(time_vme, btm);
393
case 2: /* Linux/Windows, PCI, 2 32bit time words */
394
if (bcReadBinTime(stfp_handle, &btm[1], &btm[0], &dmy) == 0) {
395
msyslog(LOG_ERR, "get_datumtime error: %m");
398
tvme_fill(time_vme, btm);
401
default: /* legacy bancomm card */
403
if (ioctl(fd_vme, READTIME, &vts)) {
404
msyslog(LOG_ERR, "get_datumtime error: %m");
408
sprintf(cbuf,"%3.3x", ((vts.btfp_time[ 0 ] & 0x000f) <<8) +
409
((vts.btfp_time[ 1 ] & 0xff00) >> 8));
410
time_vme->day = (unsigned short)atoi(cbuf);
413
sprintf(cbuf,"%2.2x", vts.btfp_time[ 1 ] & 0x00ff);
415
time_vme->hr = (unsigned short)atoi(cbuf);
418
sprintf(cbuf,"%2.2x", (vts.btfp_time[ 2 ] & 0xff00) >>8);
419
time_vme->mn = (unsigned short)atoi(cbuf);
422
sprintf(cbuf,"%2.2x", vts.btfp_time[ 2 ] & 0x00ff);
423
time_vme->sec = (unsigned short)atoi(cbuf);
425
/* Get microseconds. Yes, we ignore the 0.1 microsecond digit so
426
we can use the TVTOTSF function later on...*/
428
sprintf(cbuf,"%4.4x%2.2x", vts.btfp_time[ 3 ],
429
vts.btfp_time[ 4 ]>>8);
431
time_vme->frac = (u_long) atoi(cbuf);
434
time_vme->status = (vts.btfp_time[0] & 0x0010) >>4;
439
if (time_vme->status)
425
440
return ((void *)NULL);
428
442
return (time_vme);
444
/* Assign values to time_vme struct. Mostly for readability */
446
tvme_fill(struct vmedate *time_vme, uint32_t btm[2])
451
dmaj = btm[1]; /* syntax sugar */
454
gmtime_r(&dmaj, &maj);
455
time_vme->day = maj.tm_yday+1;
456
time_vme->hr = maj.tm_hour;
457
time_vme->mn = maj.tm_min;
458
time_vme->sec = maj.tm_sec;
459
time_vme->frac = (dmin & 0x000fffff) * 1000;
460
time_vme->frac += ((dmin & 0x00f00000) >> 20) * 100;
461
time_vme->status = (dmin & 0x01000000) >> 24;
432
466
int refclock_bancomm_bs;