4 * @brief extest's command handlers for skel-based drivers
6 * @author Copyright (C) 2009 CERN CO/HT Emilio G. Cota
7 * <emilio.garcia.cota@cern.ch>
8 * @author Copyright (C) 2008 CERN CO/HT Yury Georgievskiy
9 * <yury.georgievskiy@cern.ch>
11 * @section license_sec License
12 * Released under the GPL v2. (and only v2, not any later version)
14 #include <sys/ioctl.h>
20 #include <general_usr.h> /* for handy definitions (mperr etc..) */
24 extern int get_free_user_handle(int);
25 extern void print_modules();
28 * hndl_swdeb - handler for software debugging
30 * @param cmdd - command description
31 * @param atoms - command atoms list
33 * @return >= 0 - on success
34 * @return tst_prg_err_t - on failure
36 int hndl_swdeb(struct cmd_desc
* cmdd
, struct atom
*atoms
)
41 if (atoms
== (struct atom
*)VERBOSE_HELP
) {
42 printf("%s - print current software debugging state\n"
43 "%s flag [pid] - set software debugging\n"
45 "\t0x00: disable debugging\n"
46 "\t0x01: assertion violations\n"
47 "\t0x02: trace all IOCTLS\n"
48 "\t0x04: warning messages\n"
49 "\t0x08: module specific debug warnings\n"
50 "\t0x10: verbose debugging information\n"
51 "\t0x100: driver emulation on NO hardware\n"
52 "pid is optional (current pid is the default)\n",
53 cmdd
->name
, cmdd
->name
);
57 if (is_last_atom(atoms
)) { /* no arguments --> GET debug */
58 if (ioctl(_DNFD
, SkelDrvrIoctlGET_DEBUG
, &db
) < 0) {
59 mperr("%s ioctl failed\n", "GET_DEBUG");
60 return -TST_ERR_IOCTL
;
63 printf("Software debug mask: 0x%x\n", flag
);
64 if (flag
& SkelDrvrDebugFlagASSERTION
)
65 printf("Flag set: assertion violations\n");
66 if (flag
& SkelDrvrDebugFlagTRACE
)
67 printf("Flag set: trace all IOCTL calls\n");
68 if (flag
& SkelDrvrDebugFlagWARNING
)
69 printf("Flag set: warning messages\n");
70 if (flag
& SkelDrvrDebugFlagMODULE
)
71 printf("Flag set: module specific debug warnings\n");
72 if (flag
& SkelDrvrDebugFlagINFORMATION
)
73 printf("Flag set: all debug information\n");
74 if (flag
& SkelDrvrDebugFlagEMULATION
)
75 printf("Flag set: emulation on NO hardware\n");
80 if (atoms
->type
!= Numeric
) {
81 printf("invalid argument\n");
82 return -TST_ERR_WRONG_ARG
;
84 db
.DebugFlag
= atoms
->val
;
85 printf("flag: %x\n", db
.DebugFlag
);
87 if (is_last_atom(atoms
) || !atoms
->val
)
88 db
.ClientPid
= getpid();
90 if (atoms
->type
== Numeric
)
91 db
.ClientPid
= atoms
->val
;
93 return -TST_ERR_WRONG_ARG
;
95 if (ioctl(_DNFD
, SkelDrvrIoctlSET_DEBUG
, &db
) < 0) {
96 mperr("%s ioctl failed\n", "SET_DEBUG");
97 return -TST_ERR_IOCTL
;
99 printf("%s ioctl: successfully set flag 0x%x for pid %d\n",
100 "SET_DEBUG", db
.DebugFlag
, db
.ClientPid
);
106 * hndl_getversion - handler for get driver/module version
108 * @param cmdd - command description
109 * @param atoms - command atoms list
111 * @return >= 0 - on success
112 * @return tst_prg_err_t - on failure
114 int hndl_getversion(struct cmd_desc
* cmdd
, struct atom
*atoms
)
116 SkelDrvrVersion vers
;
118 if (atoms
== (struct atom
*)VERBOSE_HELP
) {
119 printf("No further help available\n");
122 if (ioctl(_DNFD
, SkelDrvrIoctlGET_VERSION
, &vers
) < 0) {
123 mperr("GET_VERSION ioctl failed\n");
124 return -TST_ERR_IOCTL
;
127 "\tDriver compile date (human): %s"
128 "\tDriver compile date (EPOCH): %d\n"
129 "\tModule version: %s\n",
130 ctime((time_t *)&vers
.DriverVersion
), vers
.DriverVersion
,
137 * select_module - select a particular module
139 * @param modnr module number to select
141 * @return 0 - on success
142 * @return (negative) error code - on failure
144 int select_module(int modnr
)
146 if (modnr
== tst_glob_d
.mod
)
148 if (ioctl(_DNFD
, SkelDrvrIoctlSET_MODULE
, &modnr
) < 0) {
149 mperr("%s ioctl fails\n", "SET_MODULE");
150 return -TST_ERR_IOCTL
;
152 tst_glob_d
.mod
= modnr
;
153 printf("Controlling module #%d\n", tst_glob_d
.mod
);
158 * hndl_module - handle for 'module' -- used to manage devices
160 * @param cmdd - command description
161 * @param atoms - command atoms list
163 * @return >= 0 - on success
164 * @return tst_prg_err_t - on failure
166 int hndl_module(struct cmd_desc
*cmdd
, struct atom
*atoms
)
168 int sel
; /* keep ret. code from select_module */
170 if (atoms
== (struct atom
*)VERBOSE_HELP
) {
171 printf("select or show modules\n"
172 "%s - shows currently selected module\n"
173 "%s ? - prints all managed modules by the driver\n"
174 "%s x - select module x (where x ranges from 1 to n)\n"
175 "%s ++ - select next module\n"
176 "%s -- - select next module\n",
177 cmdd
->name
, cmdd
->name
, cmdd
->name
, cmdd
->name
,
181 if (ioctl(_DNFD
, SkelDrvrIoctlGET_MODULE_COUNT
, &tst_glob_d
.ma
) < 0) {
182 mperr("Can't get module count. %s ioctl fails\n",
186 if (!tst_glob_d
.ma
) {
187 printf("The driver does not control any modules\n");
192 if (atoms
->type
!= Numeric
) {
193 if (atoms
->type
== Operator
)
194 switch (atoms
->oid
) {
199 sel
= select_module(tst_glob_d
.mod
+ 1);
204 sel
= select_module(tst_glob_d
.mod
- 1);
212 printf("Controlling module #%d (out of %d)\n",
213 tst_glob_d
.mod
, tst_glob_d
.ma
);
215 printf("The driver manages %d device%s\n",
216 tst_glob_d
.ma
, tst_glob_d
.ma
> 1 ? "s" : "");
219 sel
= select_module(atoms
->val
);
227 * hndl_nextmodule - select next module handler
229 * @param cmdd - command description
230 * @param atoms - command atoms list
232 * @return >= 0 - on success
233 * @return tst_prg_err_t - on failure
235 int hndl_nextmodule(struct cmd_desc
*cmdd
, struct atom
*atoms
)
237 int sel
; /* keep ret. code from select_module */
239 if (atoms
== (struct atom
*)VERBOSE_HELP
) {
240 printf("%s - select next module\n"
241 "This command takes no arguments.\n", cmdd
->name
);
244 sel
= select_module(tst_glob_d
.mod
+ 1);
252 * print_rawio - print the 'RawIO' beginning of line
254 * @param rio - RawIo block
255 * @param radix - hex (16) or decimal
257 void print_rawio(SkelDrvrRawIoBlock
*rio
, int radix
)
259 printf("\n%08x@space#%02x: ", rio
->Offset
, rio
->SpaceNumber
);
261 printf("0x%-*x ", rio
->DataWidth
>> 2, rio
->Data
);
263 printf("%5d ", rio
->Data
);
268 * rawio_input - manage 'RawIO' command input
270 * @param ch - initial input character
271 * @param rio - RawIo block
272 * @param radix - hex (16) or decimal
274 * @return 0 - on success
275 * @return tst_prg_err_t - on failure
277 int rawio_input(char ch
, SkelDrvrRawIoBlock
*rio
, int *radix
)
285 bzero((void *)str
, 128);
288 while (c
!= '\n' && i
< 128) {
292 input
= strtoul(str
, &endptr
, *radix
);
293 if (endptr
!= str
) { /* caught something */
305 rio
->Offset
+= rio
->DataWidth
/ 8;
313 while (c
!= '\n' && i
< 128) {
317 input
= strtoul(str
, &endptr
, *radix
);
319 break; /* nothing caught */
321 if (ioctl(_DNFD
, SkelDrvrIoctlRAW_WRITE
, rio
) < 0) {
322 mperr("RAW_WRITE ioctl fails");
323 return -TST_ERR_IOCTL
;
331 * hndl_rawio - 'RawIO' handler
333 * @param cmdd - command description
334 * @param atoms - command atoms list
336 * @return >= 0 - on success
337 * @return tst_prg_err_t - on failure
339 int hndl_rawio(struct cmd_desc
* cmdd
, struct atom
*atoms
)
341 SkelDrvrRawIoBlock rio
;
346 if (atoms
== (struct atom
*)VERBOSE_HELP
) {
348 "%s spacenumber datawidth offset\n"
349 "\tspacenumber: VME->AddressModifier, PCI->BAR\n"
350 "\tdatawidth: 8, 16, 32.\n"
351 "\toffset: offset within the address space\n",
355 if (!compulsory_ok(cmdd
)) {
356 printf("Wrong parameter amount\n");
357 return -TST_ERR_ARG_O_S
;
359 if (((atoms
+ 1)->type
| (atoms
+ 2)->type
| (atoms
+ 3)->type
)
361 printf("Invalid argument (parameters have to be numeric.)\n");
362 return -TST_ERR_WRONG_ARG
;
364 rio
.SpaceNumber
= (++atoms
)->val
;
365 rio
.DataWidth
= (++atoms
)->val
;
366 rio
.DataWidth
&= (1 << 3) | (1 << 4) | (1 << 5);
367 if (!rio
.DataWidth
) {
368 printf("Invalid argument (DataWidth must be 8, 16 or 32.)\n");
369 return -TST_ERR_WRONG_ARG
;
371 rio
.Offset
= (++atoms
)->val
;
373 printf("RawIO: [/]: Open; [CR]: Next; [.]: Exit; [x]: Hex; [d]: Dec\n");
375 if (ioctl(_DNFD
, SkelDrvrIoctlRAW_READ
, &rio
) < 0) {
376 mperr("%s ioctl fails:\n"
377 "space #: %d; data width:%d, offset: %d\n",
378 "RAW_READ", rio
.SpaceNumber
, rio
.DataWidth
,
380 return -TST_ERR_IOCTL
;
382 print_rawio(&rio
, radix
);
384 if ((err
= rawio_input(c
, &rio
, &radix
)))
392 * hndl_maps - handler for showing the address mappings of the current device
394 * @param cmdd - command description
395 * @param atoms - command atoms list
397 * @return >= 0 - on success
398 * @return tst_prg_err_t - on failure
400 int hndl_maps(struct cmd_desc
*cmdd
, struct atom
*atoms
)
405 if (atoms
== (struct atom
*)VERBOSE_HELP
) {
406 printf("%s takes no parameters\n"
407 "\tjust select a module before issuing %s\n",
408 cmdd
->name
, cmdd
->name
);
411 if (ioctl(_DNFD
, SkelDrvrIoctlGET_MODULE_MAPS
, &maps
) < 0) {
412 mperr("%s ioctl fails\n", "GET_MODULE_MAPS");
413 return -TST_ERR_IOCTL
;
415 if (!maps
.Mappings
) {
416 printf("No mappings for module #%d\n", tst_glob_d
.mod
);
419 printf("Space#\t\tMapped\n"
420 "------\t\t------\n");
422 for (i
= 0; i
< maps
.Mappings
; i
++) {
423 printf("0x%x\t\t0x%lx\n", maps
.Maps
[i
].SpaceNumber
,
424 maps
.Maps
[i
].Mapped
);
431 * hndl_timeout - 'timeout' handler
433 * @param cmdd - command description
434 * @param atoms - command atoms list
436 * @return >= 0 - on success
437 * @return tst_prg_err_t - on failure
439 int hndl_timeout(struct cmd_desc
*cmdd
, struct atom
*atoms
)
443 if (atoms
== (struct atom
*)VERBOSE_HELP
) {
444 printf("get/set timeout\n"
445 "%s - shows current timeout [in 10ms chunks]\n"
446 "%s x - set timeout x [in 10ms chunks]\n",
447 cmdd
->name
, cmdd
->name
);
450 if (is_last_atom(atoms
)) {
451 if (ioctl(_DNFD
, SkelDrvrIoctlGET_TIMEOUT
, &timeout
) < 0) {
452 mperr("%s ioctl fails\n", "GET_TIMEOUT");
453 return -TST_ERR_IOCTL
;
455 printf("timeout: %d [10*ms]\n", timeout
);
459 if (atoms
->type
!= Numeric
) {
460 printf("Invalid argument (must be numeric.)\n");
461 return -TST_ERR_WRONG_ARG
;
463 timeout
= atoms
->val
;
464 if (ioctl(_DNFD
, SkelDrvrIoctlSET_TIMEOUT
, &timeout
) < 0) {
465 mperr("%s ioctl fails\n", "SET_TIMEOUT");
466 return -TST_ERR_IOCTL
;
468 printf("timeout set to %d [10*ms] == %d ms\n", timeout
, timeout
* 10);
475 * print_queue - display current device's queue information
479 unsigned int qflag
, qsize
, qover
;
481 if (ioctl(_DNFD
, SkelDrvrIoctlGET_QUEUE_FLAG
, &qflag
) < 0) {
482 mperr("%s ioctl fails\n", "GET_QUEUE_FLAG");
483 return -TST_ERR_IOCTL
;
485 if (ioctl(_DNFD
, SkelDrvrIoctlGET_QUEUE_SIZE
, &qsize
) < 0) {
486 mperr("%s ioctl fails\n", "GET_QUEUE_SIZE");
487 return -TST_ERR_IOCTL
;
489 if (ioctl(_DNFD
, SkelDrvrIoctlGET_QUEUE_OVERFLOW
, &qover
) < 0) {
490 mperr("%s ioctl fails\n", "GET_QUEUE_OVERFLOW");
491 return -TST_ERR_IOCTL
;
494 printf("Queueing is OFF\n");
496 printf("Queueing is ON\n"
498 "\tQueue overflow: %d\n", qsize
, qover
);
504 * hndl_queue - 'queue' handler
506 * @param cmdd - command description
507 * @param atoms - command atoms list
509 * @return >= 0 - on success
510 * @return tst_prg_err_t - on failure
512 int hndl_queue(struct cmd_desc
*cmdd
, struct atom
*atoms
)
517 if (atoms
== (struct atom
*)VERBOSE_HELP
) {
518 printf("get/set queue flag\n"
519 "%s - shows current state of the queue\n"
520 "%s 1 - Turn queueing OFF\n"
521 "%s 0 - Turn queueing ON\n",
522 cmdd
->name
, cmdd
->name
, cmdd
->name
);
525 if ((++atoms
)->type
== Numeric
) {
527 if (ioctl(_DNFD
, SkelDrvrIoctlSET_QUEUE_FLAG
, &qflag
) < 0) {
528 mperr("%s ioctl fails\n", "SET_QUEUE_FLAG");
529 return -TST_ERR_IOCTL
;
531 printf("Queue switched %s successfully\n",
532 !!qflag
? "OFF" : "ON");
544 * print_client_connections - show a client's list of connections
546 * @param pid - pid of the client
548 * @return number of connections of the client
550 int print_client_connections(int pid
)
553 int mypid
= getpid();
554 SkelDrvrConnection
*conn
;
555 SkelDrvrClientConnections conns
;
557 bzero((void *)&conns
, sizeof(SkelDrvrClientConnections
));
559 if (ioctl(_DNFD
, SkelDrvrIoctlGET_CLIENT_CONNECTIONS
, &conns
) < 0) {
560 mperr("%s ioctl fails\n", "GET_CLIENT_CONNECTIONS");
561 return -TST_ERR_IOCTL
;
563 printf("Pid: %d%s\n", pid
, pid
== mypid
? " (test program)" : "");
566 for (i
= 0; i
< conns
.Size
; i
++) {
567 conn
= &conns
.Connections
[i
];
568 printf("\tModule: %d, Mask: 0x%08x\n", conn
->Module
,
575 * hndl_clients - 'list of clients' handler
577 * @param cmdd - command description
578 * @param atoms - command atoms list
580 * @return >= 0 - on success
581 * @return tst_prg_err_t - on failure
583 int hndl_clients(struct cmd_desc
*cmdd
, struct atom
*atoms
)
587 SkelDrvrClientList clist
;
589 if (atoms
== (struct atom
*)VERBOSE_HELP
) {
590 printf("%s - shows connected clients\n", cmdd
->name
);
593 if (ioctl(_DNFD
, SkelDrvrIoctlGET_CLIENT_LIST
, &clist
) < 0) {
594 mperr("%s ioctl fails\n", "GET_CLIENT_LIST");
595 return -TST_ERR_IOCTL
;
597 for (i
= 0; i
< clist
.Size
; i
++)
598 if ((ccret
= print_client_connections(clist
.Pid
[i
])) < 0) {
599 printf("Can't get client's connections\n");
607 * hndl_connect - 'connect' handler
609 * @param cmdd - command description
610 * @param atoms - command atoms list
612 * @return >= 0 - on success
613 * @return tst_prg_err_t - on failure
615 int hndl_connect(struct cmd_desc
*cmdd
, struct atom
*atoms
)
618 SkelDrvrConnection conn
;
620 if (atoms
== (struct atom
*)VERBOSE_HELP
) {
621 printf("%s - shows connections of current pid\n"
622 "%s x - connect to mask on current module\n"
623 "%s x y - connect to mask x on module y\n",
624 cmdd
->name
, cmdd
->name
, cmdd
->name
);
627 if ((++atoms
)->type
!= Numeric
) {
628 if ((ccret
= print_client_connections(getpid())) < 0) {
629 printf("Could not get client's connections\n");
634 conn
.ConMask
= atoms
->val
;
636 if (!is_last_atom(atoms
)) {
637 if ((++atoms
)->type
!= Numeric
) {
638 printf("Invalid module number\n");
639 return -TST_ERR_WRONG_ARG
;
641 conn
.Module
= atoms
->val
;
643 /* 0 == current module */
644 if (!WITHIN_RANGE(0, conn
.Module
, tst_glob_d
.ma
)) {
645 printf("Invalid module number\n");
646 return -TST_ERR_WRONG_ARG
;
648 if (ioctl(_DNFD
, SkelDrvrIoctlCONNECT
, &conn
) < 0) {
649 mperr("%s ioctl fails\n", "CONNECT");
650 return -TST_ERR_IOCTL
;
653 printf("Connected to 0x%08x on module %d\n", conn
.ConMask
,
654 !conn
.Module
? tst_glob_d
.mod
: conn
.Module
);
656 printf("Disconnected from all the interrupts on %s module%s",
657 !conn
.Module
? "all the" : "", !conn
.Module
? "s" : "");
659 printf(" %d", conn
.Module
);
667 * hndl_enable - 'enable' handler
669 * @param cmdd - command description
670 * @param atoms - command atoms list
672 * @return >= 0 - on success
673 * @return tst_prg_err_t - on failure
675 int hndl_enable(struct cmd_desc
*cmdd
, struct atom
*atoms
)
679 if (atoms
== (struct atom
*)VERBOSE_HELP
) {
680 printf("%s [1]- enable current module ('1' is not required)\n"
681 "%s 0 - disable current module\n",
682 cmdd
->name
, cmdd
->name
);
685 if (is_last_atom(atoms
)) {
689 if ((++atoms
)->type
!= Numeric
) {
690 printf("Invalid argument (must be an integer)\n");
691 return -TST_ERR_WRONG_ARG
;
693 enable
= !!atoms
->val
;
695 if (ioctl(_DNFD
, SkelDrvrIoctlENABLE
, &enable
) < 0) {
696 mperr("%s ioctl fails\n", "ENABLE");
697 return -TST_ERR_IOCTL
;
699 printf("Module %d %s\n", tst_glob_d
.mod
,
700 enable
? "enabled" : "disabled");
706 * hndl_reset - 'reset' handler
708 * @param cmdd - command description
709 * @param atoms - command atoms list
711 * @return >= 0 - on success
712 * @return tst_prg_err_t - on failure
714 int hndl_reset(struct cmd_desc
* cmdd
, struct atom
*atoms
)
716 if (atoms
== (struct atom
*)VERBOSE_HELP
) {
717 printf("%s - reset current module\n", cmdd
->name
);
720 if (!do_yes_no("Reset the current module. Are you sure", NULL
))
722 if (ioctl(_DNFD
, SkelDrvrIoctlRESET
, NULL
) < 0) {
723 mperr("%s ioctl fails\n", "RESET");
724 return -TST_ERR_IOCTL
;
726 printf("Module %d reset correctly\n", tst_glob_d
.mod
);
732 * hndl_getstatus - 'status' handler
734 * @param cmdd - command description
735 * @param atoms - command atoms list
737 * @return >= 0 - on success
738 * @return tst_prg_err_t - on failure
740 int hndl_getstatus(struct cmd_desc
* cmdd
, struct atom
*atoms
)
742 SkelDrvrStatus status
;
744 if (atoms
== (struct atom
*)VERBOSE_HELP
) {
745 printf("%s - print current status\n"
746 "Standard status can be:\n"
748 "\t0x002: BUS_ERROR\n"
749 "\t0x004: DISABLED\n"
750 "\t0x008: HARDWARE_FAIL\n"
751 "\t0x010: WATCH_DOG\n"
752 "\t0x020: BUS_FAULT\n"
753 "\t0x040: FLASH_OPEN\n"
754 "\t0x080: EMULATION\n"
755 "\t0x100: NO_HARDWARE\n"
759 "\t0x1000: HARDWARE_DBUG\n",
763 if (ioctl(_DNFD
, SkelDrvrIoctlGET_STATUS
, &status
) < 0) {
764 mperr("%s ioctl failed\n", "GET_STATUS");
765 return -TST_ERR_IOCTL
;
767 printf("Hardware status: %d\n", status
.HardwareStatus
);
768 printf("Standard status flag: 0x%04x\n", status
.StandardStatus
);
774 * hndl_waitintr - connect to an interrupt via read()
776 * @param cmdd - command description
777 * @param atoms - command atoms list
779 * @return index of the next atom to parse in the current command
780 * @return -TST_ERR_IOCTL - IOCTL fails
782 int hndl_waitintr(struct cmd_desc
* cmdd
, struct atom
*atoms
)
784 SkelDrvrReadBuf rbuf
;
786 int nc
; /* number of connections */
788 if (atoms
== (struct atom
*)VERBOSE_HELP
) {
789 printf("%s - wait for any interrupts subscribed to\n",
793 nc
= print_client_connections(getpid());
795 printf("No connections for this client\n");
798 printf("Waiting...\n");
799 ret
= read(_DNFD
, &rbuf
, sizeof(SkelDrvrReadBuf
));
801 printf("Timeout or Interrupted call\n");
804 printf("\nWoken up: Module[%d] Mask[0x%08x]\n"
806 " @@ %dns (EPOCH: %d)\n\n",
807 rbuf
.Connection
.Module
, rbuf
.Connection
.ConMask
,
808 ctime((time_t *)&rbuf
.Time
.Second
), rbuf
.Time
.NanoSecond
,
818 * hndl_simintr - simulate an interrupt via write()
820 * @param cmdd - command description
821 * @param atoms - command atoms list
823 * @return index of the next atom to parse in the current command
824 * @return -TST_ERR_IOCTL - IOCTL fails
826 int hndl_simintr(struct cmd_desc
* cmdd
, struct atom
*atoms
)
828 SkelDrvrConnection wbuf
;
831 if (atoms
== (struct atom
*)VERBOSE_HELP
) {
832 printf("%s mask - simulate a mask interrupt on current module\n"
833 "%s mask n - simulate a mask interrupt on module n\n",
834 cmdd
->name
, cmdd
->name
);
838 if (atoms
->type
!= Numeric
) {
839 printf("Mask needed to simulate a certain interrupt\n");
842 wbuf
.ConMask
= atoms
->val
;
843 wbuf
.Module
= tst_glob_d
.mod
;
844 if ((++atoms
)->type
== Numeric
)
845 wbuf
.Module
= atoms
->val
;
846 ret
= write(_DNFD
, &wbuf
, sizeof(SkelDrvrConnection
));
848 printf("Interrupt NOT simulated; write() failed (%s)\n",
852 printf("Interrupt 0x%08x on module#%d sent\n",
853 wbuf
.ConMask
, wbuf
.Module
);
859 * @todo JTAG -- to be implemented
860 * The code below comes from old versions from extest; with it
861 * it should be relatively straight-forward to make it work
865 * hndl_jtag_vhdl - JTAG VHDL code
867 * @cmdd command description
868 * @atoms command atoms list
870 * @return index of the next atom to parse in the current command, or
871 * index of the @ref Terminator atom to finish parsing.
872 * @return -TST_ERR_NO_MODULE - active module not set
873 * @return -TST_ERR_ARG_O_S - argument overflow/shortcoming
874 * @return -TST_ERR_NO_VECTOR - user doesn't provide ioctl number to be able
875 * to use this vector.
876 * @return -TST_ERR_IOCTL - ioctl call fails
877 * @return -TST_ERR_WRONG_ARG - wrong command argument
881 int hndl_jtag_vhdl(struct cmd_desc
* cmdd
, struct atom
*atoms
)
883 char cwd
[MAXPATHLEN
] = { 0 };
886 if (atoms
== (struct atom
*)VERBOSE_HELP
) {
887 printf("%s filename - load VHDL from .xsvf file 'filename'\n",
891 getcwd(cwd
, sizeof(cwd
));
894 if ((atoms
++)->type
== Alpha
) /* user provides its own filename */
898 while ( (direntry
= readdir(dir
)) ) {
899 snprintf(fname
, sizeof(fname
), "/dev/%s", direntry
->d_name
);
901 if (majordev(fstat
.st_rdev
) == devID
) { /* bingo */
902 if ( nodeNm
&& (nodeCntr
< elAm
) )
903 strncpy(nodeNm
[nodeCntr
], fname
,
904 sizeof(nodeNm
[nodeCntr
]));
916 return cmdd
->pa
+ 1; /* set index to the last (Terminator atom) */
919 int JtagLoader(char *fname
) {
921 CtrDrvrVersion version
;
924 inp
= fopen(fname
,"r");
926 if (ioctl(ctr
,CtrDrvrJTAG_OPEN
,NULL
)) {
927 IErr("JTAG_OPEN",NULL
);
931 cc
= xsvfExecute(); /* Play the xsvf file */
933 if (cc
) printf("Jtag: xsvfExecute: ReturnCode: %d Error\n",cc
);
934 else printf("Jtag: xsvfExecute: ReturnCode: %d All OK\n",cc
);
937 if (ioctl(ctr
,CtrDrvrJTAG_CLOSE
,NULL
) < 0) {
938 IErr("JTAG_CLOSE",NULL
);
942 sleep(5); /* Wait for hardware to reconfigure */
944 bzero((void *) &version
, sizeof(CtrDrvrVersion
));
945 if (ioctl(ctr
,CtrDrvrGET_VERSION
,&version
) < 0) {
946 IErr("GET_VERSION",NULL
);
949 t
.Second
= version
.VhdlVersion
;
950 printf("New VHDL bit-stream loaded, Version: [%u] %s\n",
951 (int) version
.VhdlVersion
,
955 printf("Error: Could not open the file: %s for reading\n",fname
);