vmod/vmodttl: fixed bug related to luns not ordered and/or not starting from zero.
[ht-drivers.git] / vd80 / lib / vd80lib.c
blob4028f48844232685bb6c6145353721a71ca1de5d
1 /* ==================================================================== */
2 /* Implement Vd80 sampler library */
3 /* Julian Lewis Wed 15th April 2009 */
4 /* ==================================================================== */
6 /* ==================================================================== */
7 /* ==================================================================== */
8 /* I very strongly recomend that this library is used in its ".so" form */
9 /* where it is loaded from the STUB library. The stub library has many */
10 /* extra routines and generic features, and calls any version of this */
11 /* library. If you insist on a static link with this library, at least */
12 /* take a look at the stub library for examples on how to use this one. */
13 /* The test program calls this library via a dynamic link and can call */
14 /* any of these functions. */
15 /* ==================================================================== */
16 /* ==================================================================== */
18 #include <unistd.h>
19 #include <signal.h>
20 #include <sys/types.h>
21 #include <sched.h>
22 #include <fcntl.h>
23 #include <string.h>
24 #include <sys/ioctl.h>
25 #include <sys/file.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <math.h>
29 #include <time.h>
30 #include <dlfcn.h>
31 #include <unistd.h>
32 #include <errno.h>
34 #include <skeluser.h>
35 #include <skeluser_ioctl.h>
36 #include <skel.h>
37 #include <vd80Drvr.h>
38 #include <vd80hard.h>
39 #include <Vd80Lib.h>
41 /* ==================================================================== */
42 /* ==================================================================== */
43 /* Static private non exported routines for local use only. */
44 /* ==================================================================== */
45 /* ==================================================================== */
47 /* ==================================================================== */
48 /* Internal routine to select module */
50 static int SetModule(int fd, int mod) {
52 int cnt;
54 if (ioctl(fd, SkelDrvrIoctlGET_MODULE_COUNT,&cnt) < 0) return Vd80ErrIO;
55 if ((mod < 1) || (mod > cnt)) return Vd80ErrMODULE;
56 if (ioctl(fd,SkelDrvrIoctlSET_MODULE,&mod) < 0) return Vd80ErrIO;
57 return Vd80ErrSUCCESS;
60 /* ==================================================================== */
62 static int DoCommand(int fd, int mod, int chn, int cmd) {
64 Vd80Err err;
65 int val;
67 err = SetModule(fd,mod);
68 if (err != Vd80ErrSUCCESS) return err;
70 val = cmd;
71 if (cmd == VD80_COMMAND_READ) {
72 val |= (VD80_OPERANT_MASK & ((chn -1) << VD80_OPERANT_SHIFT));
75 if (ioctl(fd,Vd80IoctlSET_COMMAND,&val) < 0) return Vd80ErrIO;
77 return Vd80ErrSUCCESS;
80 /* ==================================================================== */
81 /* ==================================================================== */
82 /* Exported routines */
83 /* ==================================================================== */
84 /* ==================================================================== */
86 /* ==================================================================== */
87 /* Open driver handle */
89 int vd80OpenHandle() {
91 char fnm[32];
92 int i, fd;
94 for (i = 1; i <=SkelDrvrCLIENT_CONTEXTS; i++) {
95 sprintf(fnm,"/dev/vd80.%1d",i);
96 if ((fd = open(fnm,O_RDWR,0)) > 0) return fd;
98 return 0;
101 /* ==================================================================== */
102 /* Close driver handle */
104 void vd80CloseHandle(int fd) {
106 close(fd);
109 /* ==================================================================== */
110 /* Reset module */
112 Vd80Err vd80ResetMod(int fd, int mod) {
114 Vd80Err err;
116 err = SetModule(fd,mod);
117 if (err != Vd80ErrSUCCESS) return err;
118 if (ioctl(fd,SkelDrvrIoctlRESET,NULL) < 0) return Vd80ErrIO;
119 return Vd80ErrSUCCESS;
122 /* ==================================================================== */
123 /* Set debug mask options */
125 Vd80Err vd80SetDebug(int fd, Vd80Debug *deb) {
127 if (ioctl(fd,SkelDrvrIoctlSET_DEBUG,deb) < 0) return Vd80ErrIO;
128 return Vd80ErrSUCCESS;
131 /* ==================================================================== */
132 /* Get debug mask options */
134 Vd80Err vd80GetDebug(int fd, Vd80Debug *deb) {
136 if (ioctl(fd,SkelDrvrIoctlGET_DEBUG,deb) < 0) return Vd80ErrIO;
137 return Vd80ErrSUCCESS;
140 /* ==================================================================== */
141 /* Get instantaneous ADC value for a given channel and module */
143 Vd80Err vd80GetAdcValue(int fd, int mod, int chn, int *adc) {
145 Vd80Err err;
146 int val;
147 short sval;
149 err = SetModule(fd,mod);
150 if (err != Vd80ErrSUCCESS) return err;
152 val = chn;
153 if (ioctl(fd,Vd80IoctlREAD_ADC,&val) < 0) return Vd80ErrIO;
154 sval = val & 0xFFFF;
155 *adc = sval;
156 return Vd80ErrSUCCESS;
159 /* ==================================================================== */
160 /* Get State, the chn parameter is ignored, the state is for the module */
162 Vd80Err vd80GetState(int fd, int mod, int chn, Vd80State *ste) {
164 Vd80Err err;
165 int val;
167 err = SetModule(fd,mod);
168 if (err != Vd80ErrSUCCESS) return err;
170 if (ioctl(fd,Vd80IoctlGET_STATE,&val) < 0) return Vd80ErrIO;
171 *ste = (Vd80State) val;
172 return Vd80ErrSUCCESS;
175 /* ==================================================================== */
176 /* Get Status */
178 Vd80Err vd80GetStatus(int fd, int mod, Vd80Status *sts) {
180 Vd80Err err;
181 int val;
183 err = SetModule(fd,mod);
184 if (err != Vd80ErrSUCCESS) return err;
186 if (ioctl(fd, SkelDrvrIoctlGET_STATUS, &val) < 0) return Vd80ErrIO;
187 *sts = (Vd80Status) val;
188 return Vd80ErrSUCCESS;
191 /* ==================================================================== */
192 /* Get datum size */
194 Vd80Err vd80GetDatumSize(int fd, Vd80DatumSize *dsz) {
196 *dsz = Vd80DatumSize16;
197 return Vd80ErrSUCCESS;
200 /* ==================================================================== */
201 /* Get installed module count */
203 Vd80Err vd80GetModuleCount(int fd, int *cnt) {
205 if (ioctl(fd, SkelDrvrIoctlGET_MODULE_COUNT,cnt) < 0) return Vd80ErrIO;
206 return Vd80ErrSUCCESS;
209 /* ==================================================================== */
210 /* Get number of channels */
212 Vd80Err vd80GetChannelCount(int fd, int *cnt) {
214 *cnt = VD80_CHANNELS;
215 return Vd80ErrSUCCESS;
218 /* ==================================================================== */
219 /* Get driver and hardware version */
221 #ifndef COMPILE_TIME
222 #define COMPILE_TIME 0
223 #endif
225 Vd80Err vd80GetVersion(int fd, int mod, Vd80Version *ver) {
227 Vd80Err err;
228 SkelDrvrVersion skver;
230 err = SetModule(fd,mod);
231 if (err != Vd80ErrSUCCESS) return err;
233 if (ioctl(fd,SkelDrvrIoctlGET_VERSION,&skver) < 0) return Vd80ErrIO;
235 ver->LibraryVersion = COMPILE_TIME;
236 ver->DriverVersion = skver.DriverVersion;
237 strncpy(ver->ModVersion,skver.ModuleVersion,Vd80VERSION_SIZE);
238 return Vd80ErrSUCCESS;
241 /* ==================================================================== */
242 /* Actually there is one trigger setting per module only, not for each */
243 /* channel !!! chns is ignored. */
245 Vd80Err vd80SetTrigger(int fd, unsigned int mods, unsigned int chns, Vd80Input *inp) {
247 Vd80Err err;
248 int i, mod;
249 unsigned int mski;
250 int val;
252 for (i=0; i<Vd80MODULES; i++) {
253 mski = 1 << i;
255 if (mods & mski) {
256 mod = i+1;
257 err = SetModule(fd,mod);
258 if (err != Vd80ErrSUCCESS) return err;
260 val = inp->Edge;
261 if (ioctl(fd,Vd80IoctlSET_TRIGGER_EDGE ,&val) < 0) return Vd80ErrIO;
262 val = inp->Termination;
263 if (ioctl(fd,Vd80IoctlSET_TRIGGER_TERMINATION,&val) < 0) return Vd80ErrIO;
264 val = inp->Source;
265 if (ioctl(fd,Vd80IoctlSET_TRIGGER ,&val) < 0) return Vd80ErrIO;
268 return Vd80ErrSUCCESS;
271 /* ==================================================================== */
272 /* Get trigger input options. chn is ignored */
274 Vd80Err vd80GetTrigger(int fd, int mod, int chn, Vd80Input *inp) {
276 Vd80Err err;
277 int val;
279 err = SetModule(fd,mod);
280 if (err != Vd80ErrSUCCESS) return err;
282 if (ioctl(fd,Vd80IoctlGET_TRIGGER_EDGE ,&val) < 0) return Vd80ErrIO;
283 inp->Edge = val;
284 if (ioctl(fd,Vd80IoctlGET_TRIGGER_TERMINATION,&val) < 0) return Vd80ErrIO;
285 inp->Termination = val;
286 if (ioctl(fd,Vd80IoctlGET_TRIGGER ,&val) < 0) return Vd80ErrIO;
287 inp->Source = val;
289 return Vd80ErrSUCCESS;
292 /* ==================================================================== */
293 /* Set clock input settings. chns are ignored */
295 Vd80Err vd80SetClock(int fd, unsigned int mods, unsigned int chns, Vd80Input *inp) {
297 Vd80Err err;
298 int i, mod;
299 unsigned int mski;
300 int val;
302 for (i=0; i<Vd80MODULES; i++) {
303 mski = 1 << i;
305 if (mods & mski) {
306 mod = i+1;
307 err = SetModule(fd,mod);
308 if (err != Vd80ErrSUCCESS) return err;
310 val = inp->Edge;
311 if (ioctl(fd,Vd80IoctlSET_CLOCK_EDGE ,&val) < 0) return Vd80ErrIO;
312 val = inp->Termination;
313 if (ioctl(fd,Vd80IoctlSET_CLOCK_TERMINATION,&val) < 0) return Vd80ErrIO;
314 val = inp->Source;
315 if (ioctl(fd,Vd80IoctlSET_CLOCK ,&val) < 0) return Vd80ErrIO;
318 return Vd80ErrSUCCESS;
321 /* ==================================================================== */
322 /* Get clock input settings */
324 Vd80Err vd80GetClock(int fd, int mod, int chn, Vd80Input *inp) {
326 Vd80Err err;
327 int val;
329 err = SetModule(fd,mod);
330 if (err != Vd80ErrSUCCESS) return err;
332 if (ioctl(fd,Vd80IoctlGET_CLOCK_EDGE ,&val) < 0) return Vd80ErrIO;
333 inp->Edge = val;
334 if (ioctl(fd,Vd80IoctlGET_CLOCK_TERMINATION,&val) < 0) return Vd80ErrIO;
335 inp->Termination = val;
336 if (ioctl(fd,Vd80IoctlGET_CLOCK ,&val) < 0) return Vd80ErrIO;
337 inp->Source = val;
339 return Vd80ErrSUCCESS;
342 /* ==================================================================== */
343 /* Set clock sample rate */
345 Vd80Err vd80SetClockDivide(int fd, unsigned int mods, unsigned int chns, unsigned int dvd) {
347 int i, mod;
348 unsigned int mski;
349 int val;
350 Vd80Err err;
352 for (i=0; i<Vd80MODULES; i++) {
353 mski = 1 << i;
355 if (mods & mski) {
356 mod = i+1;
357 err = SetModule(fd,mod);
358 if (err != Vd80ErrSUCCESS) return err;
360 val = VD80_CLKDIVMODE_DIVIDE;
361 if (ioctl(fd,Vd80IoctlSET_CLOCK_DIVIDE_MODE,&val) < 0) return Vd80ErrIO;
363 val = dvd;
364 if (ioctl(fd,Vd80IoctlSET_CLOCK_DIVISOR,&val) < 0) return Vd80ErrIO;
367 return Vd80ErrSUCCESS;
370 /* ==================================================================== */
371 /* Get clock sample rate */
373 Vd80Err vd80GetClockDivide(int fd, int mod, int chn, unsigned int *dvd) {
375 Vd80Err err;
376 int val;
378 err = SetModule(fd,mod);
379 if (err != Vd80ErrSUCCESS) return err;
381 if (ioctl(fd,Vd80IoctlGET_CLOCK_DIVISOR,&val) < 0) return Vd80ErrIO;
382 *dvd = val;
383 return Vd80ErrSUCCESS;
386 /* ==================================================================== */
387 /* Start acquisition, state will be pretrigger */
389 Vd80Err vd80StrtAcquisition(int fd, unsigned int mods, unsigned int chns) {
391 int i, mod;
392 unsigned int mski;
393 Vd80Err err;
395 for (i=0; i<Vd80MODULES; i++) {
396 mski = 1 << i;
398 if (mods & mski) {
399 mod = i+1;
400 err = DoCommand(fd,mod,0,Vd80DrvrCommandSTART);
401 if (err != Vd80ErrSUCCESS) return err;
404 return Vd80ErrSUCCESS;
407 /* ==================================================================== */
408 /* Trigger acquisition, state will be posttrigger */
410 Vd80Err vd80TrigAcquisition(int fd, unsigned int mods, unsigned int chns) {
412 int i, mod;
413 unsigned int mski;
414 Vd80Err err;
416 for (i=0; i<Vd80MODULES; i++) {
417 mski = 1 << i;
419 if (mods & mski) {
420 mod = i+1;
421 err = DoCommand(fd,mod,0,Vd80DrvrCommandTRIGGER);
422 if (err != Vd80ErrSUCCESS) return err;
425 return Vd80ErrSUCCESS;
428 /* ==================================================================== */
429 /* Stop acquisition, state will be idle */
431 Vd80Err vd80StopAcquisition(int fd, unsigned int mods, unsigned int chns) {
433 int i, mod;
434 unsigned int mski;
435 Vd80Err err;
437 for (i=0; i<Vd80MODULES; i++) {
438 mski = 1 << i;
440 if (mods & mski) {
441 mod = i+1;
442 err = DoCommand(fd,mod,0,Vd80DrvrCommandSTOP);
443 if (err != Vd80ErrSUCCESS) return err;
446 return Vd80ErrSUCCESS;
449 /* ==================================================================== */
450 /* Connect to module interrupt */
452 Vd80Err vd80Connect(int fd, unsigned int mods, unsigned int chns, unsigned int imsk) {
454 SkelDrvrConnection conn;
456 int i, mod;
457 unsigned int mski;
458 Vd80Err err;
460 for (i=0; i<Vd80MODULES; i++) {
461 mski = 1 << i;
463 if (mods & mski) {
464 mod = i+1;
465 err = SetModule(fd,mod);
466 if (err != Vd80ErrSUCCESS) return err;
468 conn.Module = mod;
469 conn.ConMask = imsk;
470 if (ioctl(fd,SkelDrvrIoctlCONNECT, &conn) < 0) return Vd80ErrIO;
474 return Vd80ErrSUCCESS;
477 /* ==================================================================== */
478 /* Set wait timeout, 0 means wait for ever */
480 Vd80Err vd80SetTimeout(int fd, int tmo) {
482 if (ioctl(fd,SkelDrvrIoctlSET_TIMEOUT,&tmo) < 0) return Vd80ErrIO;
483 return Vd80ErrSUCCESS;
486 /* ==================================================================== */
487 /* Get wait timeout, 0 means wait for ever */
489 Vd80Err vd80GetTimeout(int fd, int *tmo) {
491 if (ioctl(fd,SkelDrvrIoctlGET_TIMEOUT,tmo) < 0) return Vd80ErrIO;
492 return Vd80ErrSUCCESS;
495 /* ==================================================================== */
496 /* Set interrupt queueing on or off */
498 Vd80Err vd80SetQueueFlag(int fd, Vd80QueueFlag qfl) {
500 if (ioctl(fd,SkelDrvrIoctlSET_QUEUE_FLAG,&qfl) < 0) return Vd80ErrIO;
501 return Vd80ErrSUCCESS;
504 /* ==================================================================== */
505 /* Get interrupt queueing on or off */
507 Vd80Err vd80GetQueueFlag(int fd, Vd80QueueFlag *qfl) {
509 if (ioctl(fd,SkelDrvrIoctlGET_QUEUE_FLAG,qfl) < 0) return Vd80ErrIO;
510 return Vd80ErrSUCCESS;
513 /* ==================================================================== */
514 /* Wait for an interrupt */
516 Vd80Err vd80Wait(int fd, Vd80Intr *intr) {
518 SkelDrvrReadBuf rbuf;
519 int ret, qsz, qov;
521 bzero((void *) intr, sizeof(Vd80Intr));
523 ret = read(fd,&rbuf,sizeof(SkelDrvrReadBuf));
524 if (ret == 0) return Vd80ErrTIMEOUT;
526 if (ioctl(fd,SkelDrvrIoctlGET_QUEUE_SIZE,&qsz) < 0) return Vd80ErrIO;
527 if (ioctl(fd,SkelDrvrIoctlGET_QUEUE_OVERFLOW,&qov) < 0) return Vd80ErrIO;
529 intr->Mask = rbuf.Connection.ConMask;
530 intr->Time.tv_sec = rbuf.Time.Second;
531 intr->Time.tv_nsec = rbuf.Time.NanoSecond;
532 intr->Module = rbuf.Connection.Module;
533 intr->Channel = 0;
534 intr->QueueSize = qsz;
535 intr->Missed = qov;
537 return Vd80ErrSUCCESS;
540 /* ==================================================================== */
541 /* Simulate an interrupt */
543 Vd80Err vd80SimulateInterrupt(int fd, Vd80Intr *intr) {
545 SkelDrvrReadBuf rbuf;
546 int ret;
548 rbuf.Connection.ConMask = intr->Mask;
549 rbuf.Connection.Module = intr->Module;
551 ret = write(fd,&rbuf,sizeof(SkelDrvrReadBuf));
552 if (ret == 0) return Vd80ErrTIMEOUT;
554 return Vd80ErrSUCCESS;
557 /* ==================================================================== */
558 /* Set module buffer size and post sample count */
560 Vd80Err vd80SetBufferSize(int fd, unsigned int mods, unsigned int chns, int bsze, int post) {
562 int i, mod;
563 unsigned int mski;
564 Vd80Err err;
566 for (i=0; i<Vd80MODULES; i++) {
567 mski = 1 << i;
569 if (mods & mski) {
570 mod = i+1;
571 err = SetModule(fd,mod);
572 if (err != Vd80ErrSUCCESS) return err;
574 if (ioctl(fd,Vd80IoctlSET_POSTSAMPLES,&post) < 0) return Vd80ErrIO;
577 return Vd80ErrSUCCESS;
580 /* ==================================================================== */
581 /* Get requested number of post samples */
583 Vd80Err vd80GetBufferSize(int fd, unsigned int mod, int *post) {
585 Vd80Err err;
587 err = SetModule(fd,mod);
588 if (err != Vd80ErrSUCCESS) return err;
589 if (ioctl(fd,Vd80IoctlGET_POSTSAMPLES,&post) < 0) return Vd80ErrIO;
590 return Vd80ErrSUCCESS;
593 /* ==================================================================== */
594 /* Need to know if bytes must be swapped */
596 #if 0
597 static int little_endian() {
598 int i = 1;
599 char *p = (char *) &i;
601 return *p;
603 #endif
605 /* ==================================================================== */
606 /* Transfer module data by DMA to users buffer */
608 Vd80Err vd80GetBuffer(int fd, int mod, int chn, Vd80Buffer *buf) {
610 Vd80SampleBuf sbuf;
611 Vd80Err err;
612 int tps;
614 err = DoCommand(fd,mod,chn,Vd80DrvrCommandREAD);
615 if (err != Vd80ErrSUCCESS) return err;
617 tps = buf->BSze - buf->Post -1;
618 if (tps < 0) tps = 0;
620 sbuf.SampleBuf = buf->Addr;
621 sbuf.BufSizeSamples = buf->BSze;
622 sbuf.Channel = chn;
623 sbuf.TrigPosition = tps;
624 sbuf.Samples = 0;
626 if (ioctl(fd,Vd80IoctlREAD_SAMPLE,&sbuf) < 0) return Vd80ErrIO;
628 buf->Tpos = sbuf.TrigPosition;
629 buf->ASze = sbuf.Samples;
630 buf->Ptsr = sbuf.PreTrigStat;
632 return Vd80ErrSUCCESS;
635 /* ==================================================================== */
636 /* Set the trigger analogue levels */
638 Vd80Err vd80SetTriggerLevels(int fd, unsigned int mods, unsigned int chns, Vd80AnalogTrig *atrg) {
640 int i, j, mod, chn;
641 unsigned int mski, mskj;
642 Vd80Err err;
643 Vd80DrvrAnalogTrig adtrg;
645 if (mods == Vd80ModNONE) mods = Vd80Mod01;
646 if (chns == Vd80ChnNONE) chns = Vd80Chn01;
648 for (i=0; i<Vd80MODULES; i++) {
649 mski = 1 << i;
651 if (mods & mski) {
652 mod = i+1;
653 err = SetModule(fd,mod);
654 if (err != Vd80ErrSUCCESS) return err;
656 for (j=0; j<Vd80CHANNELS; j++) {
657 mskj = 1 << j;
659 if (chns & mskj) {
660 chn = j+1;
662 adtrg.Channel = chn;
663 adtrg.Control = atrg->AboveBelow;
664 adtrg.Level = atrg->TrigLevel;
666 if (ioctl(fd,Vd80IoctlSET_ANALOGUE_TRIGGER,&adtrg) < 0) return Vd80ErrIO;
671 return Vd80ErrSUCCESS;
674 /* ==================================================================== */
675 /* Get the trigger analogue level */
677 Vd80Err vd80GetTriggerLevels(int fd, int mod, int chn, Vd80AnalogTrig *atrg) {
679 Vd80Err err;
680 Vd80DrvrAnalogTrig adtrg;
682 if (mod == Vd80ModNONE) mod = Vd80Mod01;
683 if (chn == Vd80ChnNONE) chn = Vd80Chn01;
685 err = SetModule(fd,mod);
686 if (err != Vd80ErrSUCCESS) return err;
688 adtrg.Channel = chn;
690 if (ioctl(fd,Vd80IoctlGET_ANALOGUE_TRIGGER,&adtrg) < 0) return Vd80ErrIO;
692 atrg->AboveBelow = adtrg.Control;
693 atrg->TrigLevel = adtrg.Level;
695 return Vd80ErrSUCCESS;
698 /* ==================================================================== */
699 /* Set trigger configuration params, delay and min pretrig samples */
701 Vd80Err vd80SetTriggerConfig(int fd, unsigned int mods, unsigned int chns, Vd80TrigConfig *ctrg) {
703 int i, j, mod, chn;
704 unsigned int mski, mskj;
705 Vd80Err err;
706 Vd80DrvrTrigConfig cdtrg;
708 if (mods == Vd80ModNONE) mods = Vd80Mod01;
709 if (chns == Vd80ChnNONE) chns = Vd80Chn01;
711 for (i=0; i<Vd80MODULES; i++) {
712 mski = 1 << i;
714 if (mods & mski) {
715 mod = i+1;
716 err = SetModule(fd,mod);
717 if (err != Vd80ErrSUCCESS) return err;
719 for (j=0; j<Vd80CHANNELS; j++) {
720 mskj = 1 << j;
722 if (chns & mskj) {
723 chn = j+1;
725 cdtrg.TrigDelay = ctrg->TrigDelay;
726 cdtrg.MinPreTrig = ctrg->MinPreTrig;
728 if (ioctl(fd,Vd80IoctlSET_TRIGGER_CONFIG,&cdtrg) < 0)
729 return Vd80ErrIO;
730 break;
735 return Vd80ErrSUCCESS;
738 /* ==================================================================== */
739 /* Get trigger configuration params, delay and min pretrig samples */
741 Vd80Err vd80GetTriggerConfig(int fd, int mod, int chn, Vd80TrigConfig *ctrg) {
743 Vd80Err err;
744 Vd80DrvrTrigConfig cdtrg;
746 if (mod == Vd80ModNONE) mod = Vd80Mod01;
747 if (chn == Vd80ChnNONE) chn = Vd80Chn01;
749 err = SetModule(fd,mod);
750 if (err != Vd80ErrSUCCESS) return err;
752 if (ioctl(fd,Vd80IoctlGET_TRIGGER_CONFIG,&cdtrg) < 0) return Vd80ErrIO;
754 ctrg->TrigDelay = cdtrg.TrigDelay;
755 ctrg->MinPreTrig = cdtrg.MinPreTrig;
757 return Vd80ErrSUCCESS;
760 /* ==================================================================== */
761 /* Convert an error to a string */
763 static char *ErrTexts[Vd80ERRORS] = {
764 "All went OK, No error ", // Vd80ErrSUCCESS,
765 "Function is not implemented on this device ", // Vd80ErrNOT_IMP,
766 "Invalid Start value for this device ", // Vd80ErrSTART,
767 "Invalid Mode value for this device ", // Vd80ErrMODE,
768 "Invalid Clock value for this device ", // Vd80ErrCLOCK,
769 "Can't open a driver file handle, fatal ", // Vd80ErrOPEN,
770 "Can't connect to that interrupt ", // Vd80ErrCONNECT,
771 "No connections to wait for ", // Vd80ErrWAIT,
772 "Timeout in wait ", // Vd80ErrTIMEOUT,
773 "Queue flag must be set 0 queueing is needed", // Vd80ErrQFLAG,
774 "IO or BUS error ", // Vd80ErrIO,
775 "Module is not enabled ", // Vd80ErrNOT_ENAB
776 "Not available for INTERNAL sources ", // Vd80ErrSOURCE,
777 "Value out of range ", // Vd80ErrVOR,
778 "Bad device type ", // Vd80ErrDEVICE,
779 "Bad address ", // Vd80ErrADDRESS,
780 "Can not allocate memory ", // Vd80ErrMEMORY,
781 "Shared library error, can't open object ", // Vd80ErrDLOPEN,
782 "Shared library error, can't find symbol ", // Vd80ErrDLSYM,
783 "Can't open sampler device driver ", // Vd80ErrDROPEN,
784 "Invalid handle ", // Vd80ErrHANDLE,
785 "Invalid module number, not installed ", // Vd80ErrMODULE,
786 "Invalid channel number for this module " // Vd80ErrCHANNEL,
789 char *vd80ErrToStr(int fd, Vd80Err error) {
791 char *cp; /* Char pointer */
792 unsigned int i;
793 static char err[Vd80ErrSTRING_SIZE]; /* Static text area when null handle */
795 bzero((void *) err, Vd80ErrSTRING_SIZE);
797 i = (unsigned int) error;
798 if (i >= Vd80ERRORS) {
799 sprintf(err,"Vd80Lib:Invalid error code:%d Not in[0..%d]\n",i,Vd80ERRORS);
800 return err;
803 sprintf(err,"Vd80Lib:%s",ErrTexts[i]);
805 /* Extra info available from errno */
807 if ((error == Vd80ErrIO)
808 || (error == Vd80ErrDROPEN)
809 || (error == Vd80ErrMEMORY)) {
810 cp = strerror(errno);
811 if (cp) {
812 strcat(err,":");
813 i = Vd80ErrSTRING_SIZE - strlen(err) -1; /* -1 is 0 terminator byte */
814 strncat(err,cp,i);
818 return err;