The VisAO Camera
EDTutils.c
Go to the documentation of this file.
1 /************************************************************
2 * EDTutils.c
3 *
4 * Author: Jared R. Males (jrmales@email.arizona.edu)
5 *
6 * Definitions for some utility functions pertaining to the EDT framegrabber PCI card.
7 *
8 * Developed as part of the Magellan Adaptive Optics system.
9 ************************************************************/
10 
11 /** \file EDTutils.c
12  * \author Jared R. Males
13  * \brief Definitions for some utility functions pertaining to the EDT framegrabber PCI card.
14  *
15  *
16 */
17 
18 #include "EDTutils.h"
19 
20 #define NO_MAIN
21 
22 
23 /*
24  * initcam.c -- initialize the device driver, camera and
25  * PCI DV board for the camera (or simulator) in use
26  *
27  * (C) 1997-2000 Engineering Design Team, Inc.
28  */
29 
30 
31 //static void usage(char *progname);
32 
33 /*
34 #ifdef NO_MAIN
35 #include "opt_util.h"
36 char *argument ;
37 int option ;
38 int
39 initcam(char *command_line)
40 #else
41 int
42 main(int argc, char *argv[])
43 #endif
44 */
45 
46 int initcam(const char * fname, const char *bdir)
47 {
48  int unit = 0;
49  int verbose = 1;
50  int no_bitload = 0;
51  char cfgname[256];
52  char bitdir[256];
53  char edt_devname[256];
54  char errstr[64];
55 // char *progname = "initcam" ;
56  char logname[256];
57  EdtDev *edt_p = NULL;
58  Edtinfo edtinfo;
59  char *unitstr = "0";
60  int channel = 0 ;
61  static char *debug_env = NULL;
62  Dependent *dd_p;
63  int pdv_debug = 0;
64 #ifdef NO_FS
65  int nofs_cfg = 0;
66 #endif
67  int level;
68 
69  /*#ifdef NO_MAIN
70  char **argv = 0 ;
71  int argc = 0 ;
72  opt_create_argv("initcam",command_line,&argc,&argv);
73 #endif*/
74 
75  *cfgname = '\0';
76  *edt_devname = '\0';
77  *bitdir = '\0';
78  *logname = '\0';
79 
80 
81  strcpy(cfgname, fname);
82  strcpy(bitdir, bdir);
83  /* process arguments
84  --argc;
85  ++argv;
86  while (argc && argv[0][0] == '-')
87  {
88  switch (argv[0][1])
89  {
90  case 'u': // unit (board) number
91  ++argv;
92  --argc;
93  if (argc < 1) {
94  fprintf(stderr, "Error: option 'u' requires argument\n");
95  usage(progname);
96  exit(1);
97  }
98  unitstr = argv[0];
99  break;
100 
101  case 'c': // channel number for multi-channel devices
102  ++argv;
103  --argc;
104  if (argc < 1) {
105  fprintf(stderr, "Error: option 'c' requires argument\n");
106  usage(progname);
107  exit(1);
108  }
109  channel = atoi(argv[0]);
110  break;
111 
112  case 'O': // logfile name
113  ++argv;
114  --argc;
115  if (argc < 1) {
116  fprintf(stderr, "Error: option 'O' requires file argument\n");
117  usage(progname);
118  exit(1);
119  }
120  strcpy(logname, argv[0]);
121  break;
122 
123  case 'q': // quiet mode
124  verbose = 0;
125  break;
126 
127  case 'v': // verbose mode
128  verbose = 1;
129  break;
130 
131  case 'V': // really verbose mode
132  verbose = 2;
133  break;
134 
135  case 'f': // config filename
136  ++argv;
137  --argc;
138  if (argc < 1) {
139  fprintf(stderr, "Error: option 'f' requires argument\n");
140  usage(progname);
141  exit(1);
142  }
143  strcpy(cfgname, argv[0]);
144 #ifdef NO_FS
145  strcpy(bitdir, "_NOFS_");
146  nofs_cfg = 1;
147 #endif
148  break;
149 
150  case 'e': // no file system embedded bitfile name
151 #ifdef NO_FS
152  ++argv;
153  --argc;
154  if (argc < 1) {
155  fprintf(stderr, "Error: option 'e' requires argument\n");
156  usage(progname);
157  exit(1);
158  }
159  strcpy(cfgname, argv[0]);
160  strcpy(bitdir, "_NOFS_");
161  nofs_cfg = 1;
162 #else
163  fprintf(stdout, "\n-e specified but not compiled with nofs configs.\nrecompile with -DNO_FS and try again\n\n");
164  usage(progname);
165  exit(1);
166 #endif
167  break;
168 
169  case 'B': // don't load bitfile
170  no_bitload = 1;
171  break;
172 
173  case 'b':
174  case 'd': // compat
175  ++argv;
176  --argc;
177  if (argc < 1) {
178  fprintf(stderr, "Error: options 'b' or 'd' require argument\n");
179  usage(progname);
180  exit(1);
181  }
182  strcpy(bitdir, argv[0]);
183  break;
184 
185  case 'h': // help
186  usage(progname);
187  exit(0);
188  break;
189 
190  case '-':
191  if (strcmp(argv[0], "--help") == 0) {
192  usage(progname);
193  exit(0);
194  } else {
195  fprintf(stderr, "unknown option: %s\n", argv[0]);
196  usage(progname);
197  exit(1);
198  }
199  break;
200 
201  default:
202  fprintf(stdout, "unknown flag -'%c'\n", argv[0][1]);
203  usage(progname);
204  exit(1);
205  }
206  argc--;
207  argv++;
208  }//while (argc && argv[0][0] == '-')
209 
210  if (!(*cfgname))
211  {
212  usage(progname);
213  exit(1);
214  }
215 */
216  /*
217  * not using pdv_open to open, but still using pdvlib calls, so force
218  * debug if -v or -V or PDVDEBUG envvar
219  */
220  if (debug_env == NULL
221  && ((debug_env = (char *) getenv("PDVDEBUG")) != NULL)
222  && *debug_env != '0')
223  pdv_debug = atoi(debug_env);
224 
225  /*
226  * normally the pdvlib error handle gets initialized in pdv_open, but
227  * initcam is a special case since it calls edt_open but also uses
228  * pdvlib calls -- see edt_msg library.
229  */
230  level = edt_msg_default_level();
231 
232  if ((verbose > 1) && (pdv_debug < verbose))
233  pdv_debug = verbose;
234 
235  if ((!verbose) && (!pdv_debug))
236  level = 0;
237  else
238  {
239  if (verbose > 0)
240  {
241  level |= EDTAPP_MSG_INFO_1;
242  level |= PDVLIB_MSG_INFO_1;
243  level |= PDVLIB_MSG_WARNING;
244  level |= PDVLIB_MSG_FATAL;
245  }
246  if (verbose > 1)
247  level |= EDTAPP_MSG_INFO_2;
248  if (pdv_debug > 1)
249  level |= PDVLIB_MSG_INFO_2;
250  }
251 
252  edt_msg_set_level(edt_msg_default_handle(), level);
253  if (*logname)
254  edt_msg_set_name(edt_msg_default_handle(), logname);
255 
256  /* kind of kludgy... since pdv_setdebug doesn't actually USE edt_p,
257  * its okay that it hasn't been opened yet , hence the NULL pointer
258  */
259  if (pdv_debug)
260  pdv_setdebug(NULL, pdv_debug);
261 
262  /*
263  * if porting this code to an application, be sure to free this
264  * and reallocate if you call pdv_initcam multiple times.
265  */
266  if ((dd_p = pdv_alloc_dependent()) == NULL)
267  {
268  edt_msg(PDVLIB_MSG_FATAL, "alloc_dependent FAILED -- exiting\n");
269  exit(1);
270  }
271 
272 #ifdef NO_FS
273  if (nofs_cfg)
274  {
275  int ret ; /* randall how should we deal with this? */
276  ret = pdv_readcfg_emb(cfgname, dd_p, &edtinfo);
277  }
278  else
279 #endif
280  if (pdv_readcfg(cfgname, dd_p, &edtinfo) != 0)
281  {
282  edt_msg(PDVLIB_MSG_FATAL, "readcfg FAILED -- exiting\n");
283  exit(1);
284  }
285 
286  if (no_bitload)
287  strcpy(dd_p->rbtfile, "_SKIPPED_");
288 
289  /*
290  * open the device
291  */
292  unit = edt_parse_unit_channel(unitstr, edt_devname, "pdv", &channel);
293  edt_msg(EDTAPP_MSG_INFO_1, "opening %s unit %d....\n", edt_devname, unit);
294  if ((edt_p = edt_open_channel(edt_devname, unit, channel)) == NULL)
295  {
296  sprintf(errstr, "edt_open(%s%d)", edt_devname, unit);
297  edt_perror(errstr);
298  return (1);
299  }
300 
301  if (edt_p->devid == PDVFOI_ID)
302  {
303 #ifdef _FOI_SUPPORTED
304  pdv_initcam_set_rci(edt_p, channel) ;
305 #else
306  edt_msg(EDTAPP_MSG_FATAL,"FOI not supported after pkg v4.1.5.9\n");
307  edt_close(edt_p);
308  exit(1);
309 #endif
310  }
311 
312  if (pdv_initcam(edt_p, dd_p, unit, &edtinfo, cfgname, bitdir,
313  pdv_debug) != 0)
314  {
315  edt_msg(EDTAPP_MSG_FATAL,"initcam failed. Run with '-V' to see complete debugging output\n");
316  edt_close(edt_p);
317  exit(1);
318  }
319 
320  edt_close(edt_p);
321  edt_msg(EDTAPP_MSG_FATAL, "done\n");
322 #ifdef NO_MAIN
323  return(0) ;
324 #else
325  exit(0);
326 #endif
327 }
328 
329 
330 
331 #define edt_swab32(x) \
332  (\
333  ((u_int)( \
334  (((u_int)(x) & (u_int)0x000000ffUL) << 24) | \
335  (((u_int)(x) & (u_int)0x0000ff00UL) << 8) | \
336  (((u_int)(x) & (u_int)0x00ff0000UL) >> 8) | \
337  (((u_int)(x) & (u_int)0xff000000UL) >> 24) )) \
338  )
339 
340 EdtDev *edt_p;
341 
342 u_int tracebuf[EDT_TRACESIZE];
343 
344 int curcount;
345 
346 void print_hex(u_char *buf, int count);
347 void print_ascii(char *buf);
348 
349 
350 int setdebug(const char * kbuff)
351 {
352  int i, unit = 0, report = 0, debug = -1, quiet = 0;
353  int channel = 0;
354  char *unitstr = "0";
355  char edt_devname[100];
356  int do_channel = 0;
357  int test_timestamp = 0 ;
358  int get_trace = 0;
359  int wait_trace = 0;
360  int get_sglist = 0;
361  int set_sglist = 0;
362  int set_solaris_dma_mode = 0;
363  int solaris_dma_mode = 0;
364  int set_umem_lock_mode = 0;
365  int umem_lock_mode = 0;
366  int do_timeout = 0;
367  int clock_fifo = 0;
368  int do_loop = 0;
369 
370  int mstimeout = -1;
371  int sgbuf = -1;
372  int version = 0;
373 
374  int process_isr = -1;
375  int do_process_isr = 0;
376 
377  int multi_done = 0x1234;
378  int check_openmask = 0 ;
379 
380  int use_kernel_buffers = -1;
381  int do_kernel_buffers = 0;
382  int use_persistent_buffers = 0;
383 
384  int max_buffers = 0;
385  int set_fv_done = -1;
386 
387  int lock_on = 0;
388  int lock_on_value = 0;
389 
390  u_int set_trace = 0;
391  u_int trace_reg = 0;
392  u_int trace_state = 0;
393  u_int trace_regs_enable = 0;
394 
395 /*
396 #ifdef NO_MAIN
397  char **argv = 0 ;
398  int argc = 0 ;
399  opt_create_argv("setdebug",command_line,&argc,&argv);
400 #endif
401 */
402 
403 #ifdef P53B
404  int soft_reset = 0;
405  int hard_reset = 0;
406  int set_coupled = 0;
407  int direct_coupled = 0;
408  int arg;
409 
410 #endif
411 
412 
413  if (kbuff[0] == 'q')
414  use_kernel_buffers = -1;
415  else if (kbuff[0] == 'c')
416  use_kernel_buffers = EDT_COPY_KBUFS;
417  else if (kbuff[0] == 'm')
418  use_kernel_buffers = EDT_MMAP_KBUFS;
419  else
420  use_kernel_buffers = 0;
421 
422  if (isdigit(kbuff[0]))
423  use_kernel_buffers = strtol(kbuff,0,0);
424 
425  if (kbuff[0] && (kbuff[1] == 'p'))
426  {
427  use_persistent_buffers = 1;
428  use_kernel_buffers |= EDT_PERSISTENT_KBUFS;
429  }
430  do_kernel_buffers = 1;
431 
432 
433 /* --argc;
434  ++argv;
435  while (argc && argv[0][0] == '-')
436  {
437  switch (argv[0][1])
438  {
439  case 'u':
440  ++argv;
441  --argc;
442  unitstr = argv[0];
443  break;
444 
445  case 'c':
446  ++argv;
447  --argc;
448  channel = atoi(argv[0]);
449  do_channel = 1;
450  break;
451 
452  case 't':
453  ++argv;
454  --argc;
455  mstimeout = atoi(argv[0]);
456  do_timeout = 1;
457  break;
458 
459  case 'i':
460  ++argv;
461  --argc;
462  process_isr = atoi(argv[0]);
463  do_process_isr = 1;
464  break;
465 
466  case 'k':
467 
468  if (argc > 1)
469  {
470  ++argv;
471  --argc;
472  if (argv[0][0] == 'q')
473  use_kernel_buffers = -1;
474  else if (argv[0][0] == 'c')
475  use_kernel_buffers = EDT_COPY_KBUFS;
476  else if (argv[0][0] == 'm')
477  use_kernel_buffers = EDT_MMAP_KBUFS;
478  else
479  use_kernel_buffers = 0;
480  if (isdigit(argv[0][0]))
481  use_kernel_buffers = strtol(argv[0],0,0);
482 
483  if (argv[0][0] && (argv[0][1] == 'p'))
484  {
485  use_persistent_buffers = 1;
486  use_kernel_buffers |= EDT_PERSISTENT_KBUFS;
487  }
488 
489  }
490  do_kernel_buffers = 1;
491  break;
492 
493 
494  case 'r':
495  report = 1;
496  break;
497 
498  case 'v':
499  version = 1;
500  break;
501 
502  case 'T':
503  set_trace = 1;
504  if (argv[0][2] == '+')
505  trace_state = 1;
506  else if (argv[0][2] == '-')
507  trace_state = 0;
508  else
509  {
510  trace_regs_enable = 1;
511  }
512  if (argc > 1)
513  {
514  ++argv;
515  --argc;
516  trace_reg = strtol(argv[0],0,0);
517  if (!trace_regs_enable)
518  {
519  if (strlen(argv[0]) < 7 && trace_reg < 0x10000)
520  {
521  trace_reg |= 0x01010000;
522  }
523  }
524  }
525 
526  break;
527 
528  case 'l':
529  do_loop = 1;
530  break;
531 
532  case 'L':
533  lock_on = 1;
534  ++argv;
535  --argc;
536  lock_on_value = atoi(argv[0]);
537  printf("lock_on_value = %d\n", lock_on_value);
538  break;
539 
540  case 'V':
541  ++argv;
542  --argc;
543  set_fv_done = atoi(argv[0]);
544  break;
545 
546  case 'd':
547  ++argv;
548  --argc;
549  debug = strtol(argv[0], 0, 0);
550  break;
551 
552  case 'g':
553  get_trace = 1;
554  break;
555 
556  case 'G':
557  get_trace = 1;
558  wait_trace = 1;
559  break;
560 
561 #ifdef P53B
562  case 'D':
563  soft_reset = 1;
564  break;
565 
566  case 'C':
567  set_coupled = 1;
568  ++argv;
569  --argc;
570  direct_coupled = atoi(argv[0]);
571  break;
572 
573  case 'R':
574  hard_reset = 1;
575  break;
576 #else
577  case 'f':
578  ++argv;
579  --argc;
580  clock_fifo = atoi(argv[0]);
581  break;
582  case 's':
583  get_sglist = 1;
584  ++argv;
585  --argc;
586  sgbuf = atoi(argv[0]);
587  break;
588 
589  case 'S':
590  set_solaris_dma_mode = 1;
591  ++argv;
592  --argc;
593  solaris_dma_mode = atoi(argv[0]);
594  break;
595 
596  case 'U':
597  set_umem_lock_mode = 1;
598  ++argv;
599  --argc;
600  umem_lock_mode = atoi(argv[0]);
601  break;
602 
603  case 'b':
604  ++argv;
605  --argc;
606  max_buffers = atoi(argv[0]);
607  break;
608 
609  case 'm':
610  ++argv;
611  --argc;
612  multi_done = atoi(argv[0]);
613  break;
614 
615  case 'o':
616  check_openmask = 1 ;
617  break;
618 
619  case 'q':
620  quiet = 1;
621  break;
622  case 'x':
623  set_sglist = 1;
624  break;
625 #endif
626  default:
627 #ifdef P53B
628  puts(
629  "Usage: setdebug [-u unit_no] [-c chan] [-R] [-D] [-r] [-d N] [-i N]");
630 #else
631  puts("Usage: setdebug [-u unit_no] [-c chan] [-r] [-d N] [-i N]");
632 #endif
633  exit(0);
634  }
635  argc--;
636  argv++;
637  }*/
638 
639  unit = edt_parse_unit(unitstr, edt_devname, EDT_INTERFACE);
640 
641  if (do_channel)
642  {
643  if ((edt_p = edt_open_channel(edt_devname, unit, channel)) == NULL)
644  {
645  char str[64];
646 
647  sprintf(str, "%s%d_%d", edt_devname, unit, channel);
648  perror(str);
649  exit(1);
650  }
651  }
652  else if ((edt_p = edt_open(edt_devname, unit)) == NULL)
653  {
654  char str[64];
655 
656  sprintf(str, "%s%d", edt_devname, unit);
657  perror(str);
658  exit(1);
659  }
660 
661  if (trace_regs_enable)
662  {
663  edt_trace_regs_enable(edt_p, trace_reg);
664  }
665  else if (set_trace)
666  {
667  edt_set_trace_regs(edt_p, trace_reg, trace_state);
668  }
669 
670  if (check_openmask)
671  {
672  u_int tmpmask ;
673  edt_dma_info tmpinfo ;
674  tmpmask = edt_get_dma_info(edt_p, &tmpinfo) ;
675  printf("dma info mask %08x used %08x alloc %08x active %08x\n",
676  tmpmask,
677  tmpinfo.used_dma,
678  tmpinfo.alloc_dma,
679  tmpinfo.active_dma) ;
680  exit(0) ;
681  }
682 
683  if (lock_on)
684  {
685 
686  edt_ioctl(edt_p, EDTS_TEST_LOCK_ON, &lock_on_value);
687 
688  }
689 
690 #ifdef P53B
691  if (hard_reset)
692  {
693  arg = 1;
694  if (edt_ioctl(edt_p, P53S_RESET, &arg) == -1)
695  perror("edt_ioctl(P53S_RESET)");
696  }
697  if (soft_reset)
698  {
699  arg = 0;
700  if (edt_ioctl(edt_p, P53S_RESET, &arg) == -1)
701  perror("edt_ioctl(P53S_RESET)");
702  }
703  if (set_coupled)
704  {
705  if (direct_coupled)
706  printf("setting direct_coupled\n");
707  else
708  printf("setting transformer_coupled\n");
709  if (edt_ioctl(edt_p, P53S_COUPLED, &direct_coupled) == -1)
710  perror("edt_ioctl(P53S_DIRECT)");
711  }
712 #endif /* P53B */
713 
714 
715  if (do_timeout)
716  {
717  printf("setting read timeout to %d ms\n", mstimeout);
718  edt_set_rtimeout(edt_p, mstimeout);
719  edt_set_wtimeout(edt_p, mstimeout);
720  }
721 
722  if (do_process_isr)
723  {
724  edt_ioctl(edt_p, EDTS_PROCESS_ISR, &process_isr);
725  printf("Process ISR state = %d\n", process_isr);
726 
727  }
728 
729  if (multi_done != 0x1234)
730  {
731 
732  if (multi_done < 0)
733  {
734  edt_ioctl(edt_p, EDTG_MULTI_DONE,&multi_done);
735  printf("multi done = %d\n", multi_done);
736  } else {
737  printf("setting multi done = %d\n", multi_done);
738  edt_ioctl(edt_p, EDTS_MULTI_DONE, &multi_done);
739  }
740  }
741 
742  if (do_kernel_buffers)
743  {
744  int old_state;
745 
746  if (use_kernel_buffers != -1)
747  {
748  printf("Setting to %d\n",
749  use_kernel_buffers);
750  old_state = edt_set_kernel_buffers(edt_p,use_kernel_buffers);
751  printf("old_state = %d\n", old_state);
752  }
753 
754  old_state = edt_get_kernel_buffers(edt_p);
755  use_persistent_buffers = edt_get_persistent_buffers(edt_p);
756 
757  printf("Use Kernel buffers is %s %s\n", (old_state == 0)?
758  "off":(old_state == 2)?"mmapped":"copy",
759  (use_persistent_buffers)?"(persistent)":"");
760 
761  }
762 
763  if (max_buffers > 0)
764  {
765  edt_set_max_buffers(edt_p,max_buffers);
766  printf("Max Buffers = %d\n", edt_get_max_buffers(edt_p));
767 
768  }
769 
770  if (version)
771  {
772 
773  edt_version_string version;
774  edt_version_string build;
775 
776  edt_get_driver_version(edt_p,version,sizeof(version));
777  edt_get_driver_buildid(edt_p,build,sizeof(version));
778 
779  printf("\n%s%d: Driver version %s \n Build %s\n",
780  edt_devname,
781  unit,
782  version,
783  build);
784  }
785 
786  if (report)
787  {
788 
789  i = edt_get_debug(edt_p);
790 
791  printf("\n%s%d: current debug %d type %d\n", edt_devname, unit, i,
792  edt_get_drivertype(edt_p));
793  }
794  if (test_timestamp)
795  {
796  for(i = 0 ; i < 4 ; i++)
797  {
798  edt_ref_tmstamp(edt_p,i) ;
799  edt_msleep (1000) ;
800  }
801  }
802 
803  if (set_fv_done != -1)
804  {
805  int i;
806  i = (set_fv_done)?1:0;
807  edt_ioctl(edt_p,EDTS_FVAL_DONE,&i);
808  if (set_fv_done == 1)
809  edt_reg_and(edt_p,PDV_UTIL3,~PDV_TRIGINT);
810  }
811 
812  if (debug != -1)
813  {
814  (void) edt_set_debug(edt_p, debug);
815  if (report)
816  printf("%s%d: new debug %d\n", edt_devname, unit, debug);
817 
818  if (!quiet)
819  edt_dump_registers(edt_p, debug);
820 
821  printf("xfer %d bytes\n", edt_get_bytecount(edt_p));
822 
823  {
824  u_int mapsize;
825 
826  mapsize = edt_get_mappable_size(edt_p);
827 
828  if (mapsize != 0)
829  {
830  printf("Second memory space size = 0x%x bytes\n", mapsize);
831 
832  }
833  }
834  }
835 
836  if (get_trace)
837  {
838  edt_trace(edt_p, stdout, FALSE, (wait_trace)?0:1, NULL, 0);
839 
840  }
841  if (get_sglist)
842  {
843  edt_buf sg_args;
844  u_int todo_size;
845  u_int sg_size;
846  u_int *todo_list;
847  u_int *sg_list;
848  u_int *log_list;
849  u_int sg_virtual;
850  u_int sg_physical;
851  u_int todo_virtual;
852  u_int first_sg;
853  u_int *ptr;
854  u_int ii;
855 
856  sg_args.desc = EDT_SGLIST_SIZE;
857  sg_args.value = sgbuf;
858  edt_ioctl(edt_p, EDTG_SGINFO, &sg_args);
859  sg_size = (u_int) sg_args.value;
860 
861  sg_args.desc = EDT_SGLIST_VIRTUAL;
862  sg_args.value = sgbuf;
863  edt_ioctl(edt_p, EDTG_SGINFO, &sg_args);
864  sg_virtual = (u_int) sg_args.value;
865 
866  sg_args.desc = EDT_SGLIST_PHYSICAL;
867  sg_args.value = sgbuf;
868  edt_ioctl(edt_p, EDTG_SGINFO, &sg_args);
869  sg_physical = (u_int) sg_args.value;
870 
871  sg_args.desc = EDT_SGTODO_SIZE;
872  sg_args.value = sgbuf;
873  edt_ioctl(edt_p, EDTG_SGINFO, &sg_args);
874  todo_size = (u_int) sg_args.value;
875 
876  sg_args.desc = EDT_SGTODO_VIRTUAL;
877  sg_args.value = sgbuf;
878  edt_ioctl(edt_p, EDTG_SGINFO, &sg_args);
879  todo_virtual = (u_int) sg_args.value;
880 
881  sg_args.desc = EDT_SGTODO_FIRST_SG;
882  sg_args.value = sgbuf;
883  edt_ioctl(edt_p, EDTG_SGINFO, &sg_args);
884  first_sg = (u_int) sg_args.value;
885 
886  printf("todo size 0x%x addr %x\n", todo_size, todo_virtual);
887  printf("sg size 0x%x viraddr %x physaddr %x first_sg %x\n",
888  sg_size, sg_virtual, sg_physical, first_sg);
889 
890 
891  todo_list = (u_int *) malloc(todo_size);
892  sg_list = (u_int *) malloc(sg_size);
893 
894  if (todo_size)
895  {
896  printf("return to read todo list: ");
897  getchar();
898  printf("todo list %p\n", todo_list);
899  edt_ioctl(edt_p, EDTG_SGTODO, todo_list);
900  ptr = todo_list;
901  printf("todo_list:\n");
902  printf("todo size %x\n", todo_size);
903  printf("return to continue");
904  getchar();
905  for (ii = 0; ii < todo_size / 8; ii++)
906  {
907  printf("%08x %08x\n", *ptr, *(ptr + 1));
908  ptr += 2;
909  }
910  }
911  if (sg_size)
912  {
913  buf_args sg_getargs ;
914  sg_getargs.addr = (uint64_t) ((unsigned long) sg_list) ;
915  sg_getargs.size = sg_size ;
916  sg_getargs.index = sgbuf ;
917  printf("return to read sg list: %x at %p",sg_size,sg_list);
918  getchar();
919  edt_ioctl(edt_p, EDTG_SGLIST, &sg_getargs);
920  ptr = sg_list;
921  printf("sg list:\n");
922  if (edt_little_endian())
923  for (ii = 0; ii < sg_size / 8; ii++)
924  {
925  printf("%08x %08x\n", *ptr, *(ptr + 1));
926  ptr += 2;
927  }
928  else
929  for (ii = 0; ii < sg_size / 8; ii++)
930  {
931  printf("%08x %08x\n", edt_swab32(*ptr), edt_swab32(*(ptr + 1)));
932  ptr += 2;
933  }
934  }
935  if (set_sglist)
936  {
937 
938  printf("return to test sg list: ");
939  getchar();
940  log_list = (u_int *) malloc(1024 * 8);
941  for (i = 7; i >= 0; i--)
942  {
943  log_list[i * 2] = 1024 * (1024 / 8) * i ;
944  log_list[i * 2 + 1] = 1024 * (1024 / 8) ;
945  }
946  edt_set_sglist(edt_p, 0, log_list, 8) ;
947  }
948  }
949  if (clock_fifo)
950  {
951  /* tmp test code for ssdio(1) and pcd(2) */
952  for (;;)
953  {
954  if (clock_fifo == 1)
955  {
956  u_int stat;
957  u_int tmp;
958  u_int bytenum;
959 
960  stat = edt_reg_read(edt_p, PCD_STAT);
961  bytenum = (stat & (SSDIO_BYTECNT_MSK)) >> SSDIO_BYTECNT_SHFT;
962  printf("stat %02x next strobe ", stat);
963  if (stat & SSDIO_LAST_BIT)
964  printf("will fill byte to start filling %d\n", bytenum);
965  else
966  printf("filling byte %d\n", bytenum);
967  tmp = edt_reg_read(edt_p, PCD_FUNCT);
968  printf("return to strobe: ");
969  getchar();
970  edt_reg_write(edt_p, PCD_FUNCT, tmp & ~SSDIO_STROBE);
971  edt_reg_write(edt_p, PCD_FUNCT, tmp | SSDIO_STROBE);
972  }
973  else
974  {
975  u_int cfg;
976  u_int cnt;
977 
978  cnt = edt_get_bytecount(edt_p);
979  cfg = edt_reg_read(edt_p, EDT_DMA_CFG);
980  printf("0x%x tranferred fifo %d cfg %08x\n",
981  cnt, (cfg & EDT_FIFO_CNT) >> EDT_FIFO_SHIFT, cfg);
982  printf("return to clock fifo: ");
983  getchar();
984  edt_reg_write(edt_p, EDT_DMA_INTCFG, cfg | EDT_WRITE_STROBE);
985  }
986  }
987  }
988  if (do_loop)
989  {
990  u_int bcount;
991  u_int buf ;
992 
993  for (;;)
994  {
995  edt_msleep(1000);
996  bcount = edt_get_bytecount(edt_p);
997  printf("xfer %d (0x%x) bytes\n", bcount, bcount);
998  bcount = edt_get_bufbytecount(edt_p,&buf);
999  printf("xfer %d (0x%x) bytes buf %x\n", bcount, bcount,buf);
1000  }
1001  }
1002  if (set_solaris_dma_mode)
1003  {
1004  edt_ioctl(edt_p, EDTS_SOLARIS_DMA_MODE, &solaris_dma_mode);
1005  }
1006  if (set_umem_lock_mode)
1007  {
1008  edt_ioctl(edt_p, EDTS_UMEM_LOCK, &umem_lock_mode);
1009  }
1010 
1011 
1012 #ifndef NO_MAIN
1013  exit(0);
1014 #endif
1015  return (0);
1016 }
1017 
1018 
1019 void
1020 print_hex(u_char *buf, int count)
1021 {
1022  int i;
1023 
1024  printf("<");
1025  for (i=0; i<count; i++)
1026  printf("%02x%s", buf[i], i == count-1?">":" ");
1027  printf("\n");
1028 }
1029 
1030 void
1031 print_ascii(char *buf)
1032 {
1033  unsigned int i;
1034 
1035  printf("<");
1036  for (i=0; i<strlen(buf); i++)
1037  {
1038  if (buf[i] >= ' ' && buf[i] <= '~')
1039  printf("%c", buf[i]);
1040  else if (buf[i] == '\t')
1041  printf("\\t");
1042  else if (buf[i] == '\n')
1043  printf("\\n");
1044  else if (buf[i] == '\r')
1045  printf("\\r");
1046  }
1047  printf(">\n");
1048 }
int setdebug(const char *kbuff)
A local version of setdebug.
Definition: EDTutils.c:350
Declarations for some utility functions pertaining to the EDT framegrabber PCI card.
int initcam(const char *fname, const char *bdir)
A local version of initcam.
Definition: EDTutils.c:46