/[VMELinux]/vmeutils/commands.cpp
ViewVC logotype

Contents of /vmeutils/commands.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Mon Jun 18 14:57:44 2001 UTC (18 years, 11 months ago) by astro
Branch: MAIN
CVS Tags: vmelinux-1_1_2, Linux2_4_x
Changes since 1.1: +2 -9 lines
Changed the device number from 70 to 221 as assigned by the Linux authorities.
1 //---------------------------------------------------------------------------
2 //title: VME Debugger for XVME-655
3 //programmer: Michael Wyrick
4 //project: VMELinux Project in association with Chesapeake Research
5 //------------------------------------------------------------------------------
6 // $Id: commands.cpp,v 1.2 2001/06/18 14:57:44 astro Exp $
7 //
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <fcntl.h>
11 #include <unistd.h>
12 #include <string.h>
13 #include <sys/ioctl.h>
14 #include <asm/io.h>
15 #include <malloc.h>
16
17 #include "unilib.h"
18 #include "commands.h"
19 #include "universe.h"
20 #include "vmeutils.h"
21
22 #define CMDT_NULL 0
23 #define CMDT_FUNC 1
24 #define CMDT_MODC 2
25 #define CMDT_MODI 3
26 #define CMDT_MODL 4
27 #define CMDT_MODB 5
28
29 #define DEFCNT 128
30
31 // Size of a DMA write file transfer
32 #define WRITEBUFSIZE 1024
33
34 int VMEspace = 1; // 1 = A16, 2 = A24, 3 = A32
35
36 char TestValueC = 0;
37 int TestValueI = 0;
38 long TestValueL = 0;
39
40 long FixedAdder = 0;
41 long VME_Valid_Base = 0;
42 long VME_Valid_Cnt = 0;
43
44 typedef void (*func)(char *,int);
45
46 typedef struct {
47 int CmdType;
48 char *command;
49 int NumParams;
50 void *pointer;
51 } COMMAND;
52
53 COMMAND cmdTable[] = {
54 {CMDT_FUNC,"QUIT",0,quit},
55 {CMDT_FUNC,"Q",0,quit},
56 {CMDT_FUNC,"EXIT",0,quit},
57 {CMDT_FUNC,"E",0,quit},
58 {CMDT_FUNC,"HELP",0,help},
59 {CMDT_FUNC,"?",0,help},
60 {CMDT_FUNC,"STATUS",0,status},
61 {CMDT_FUNC,"REGS",0,regs},
62 {CMDT_FUNC,"CLS",0,clear},
63
64 {CMDT_FUNC,"D",2,Display},
65 {CMDT_FUNC,"R",2,Display},
66 {CMDT_FUNC,"RB",2,Display},
67 {CMDT_FUNC,"T",2,DisplayMonitor},
68 {CMDT_FUNC,"DW",2,DisplayWord},
69 {CMDT_FUNC,"RW",2,DisplayWord},
70 {CMDT_FUNC,"DL",2,DisplayLong},
71 {CMDT_FUNC,"RL",2,DisplayLong},
72
73 {CMDT_FUNC,"W",2,Write},
74 {CMDT_FUNC,"WB",2,Write},
75 {CMDT_FUNC,"WW",2,WriteWord},
76 {CMDT_FUNC,"WL",2,WriteLong},
77
78 {CMDT_FUNC,"RF",2,ReadFile},
79 {CMDT_FUNC,"WF",2,WriteFile},
80 {CMDT_FUNC,"WSRF",2,WriteSRecordsFile},
81
82 {CMDT_FUNC,"SEEK",1,Seek},
83
84 {CMDT_FUNC,"REGR",1,ReadReg},
85 {CMDT_FUNC,"REGW",2,WriteReg},
86
87 {CMDT_FUNC,"MAP",1,vmemap1},
88
89 {CMDT_FUNC,"TESTWRITE",1,TestWrite},
90 {CMDT_FUNC,"TESTREAD",1,TestRead},
91 {CMDT_FUNC,"TESTDMA",1,TestDMA},
92 {CMDT_FUNC,"TESTPROGRAMMED",1,TestProgrammed},
93
94 {CMDT_FUNC,"WINT", 1, wint},
95
96 {CMDT_MODL,"FA",1,&FixedAdder},
97
98 {CMDT_NULL,"",0,NULL} // End of Table
99 };
100
101 unsigned long lastpnt = 0;
102 unsigned long VMEMapping = 0;
103
104 extern int quiet;
105 extern int default_mode;
106 extern int binary;
107
108 /*------------------------------------------------------------------------------
109 *
110 *
111 *------------------------------------------------------------------------mjw-*/
112 void clear(char *b,int l)
113 {
114 }
115
116 /*------------------------------------------------------------------------------
117 * ValidAddress
118 * return 1 if the ptr is in the current Mapping
119 *------------------------------------------------------------------------mjw-*/
120 int ValidAddress(long ptr)
121 {
122 if ((ptr >= VME_Valid_Base) &&
123 (ptr < VME_Valid_Base + VME_Valid_Cnt))
124 return(1);
125 else {
126 printf(" An attempt was made to access an invalid address. %0X",ptr);
127 return(0);
128 }
129 }
130
131 //----------------------SREC-------------
132 #define ERROR 1
133 #define BUFFER_SIZE 4096
134 #define BYT(cp) ((Asc2Hex(cp[0]) << 4) | Asc2Hex(cp[1]))
135
136 static FILE *infile;
137 static char *buffer;
138 static char *goffset;
139 /*-------------------------------------------------------------------------*/
140 /* Asc2Hex - convert a two byte ascii string to a byte */
141 /*-------------------------------------------------------------------------*/
142 static char Asc2Hex(char byt)
143 {
144 if ((byt < 0x3A) && (byt > 0x2F))
145 return(byt & 0x0F);
146 if ((byt < 'G') && (byt > '@'))
147 return((byt & 0x0F) + 9);
148 if ((byt < 'g') && (byt > 0x60))
149 return((byt & 0x0F) + 9);
150 return(0xEE); /* Return Error */
151 }
152
153 /*-------------------------------------------------------------------------*/
154 /* ComputeAddr - Get address from S Record */
155 /*-------------------------------------------------------------------------*/
156 static unsigned long ComputeAddr(char *cp, int siz)
157 {
158 unsigned long retval;
159
160 for (retval = 0L; siz > 0; siz--, cp += 2)
161 retval = (retval << 8) | BYT(cp);
162
163 return(retval);
164 }
165
166 /*-------------------------------------------------------------------------*/
167 /* checkwrite - Write a word to memory and read it back to check that it */
168 /* wrote correctly. */
169 /*---------------------------------------------------------------------mjw-*/
170 void checkwrite(unsigned long a,unsigned char val)
171 {
172 int error;
173 unsigned char hn,ln;
174
175 // hn = (val >> 8) & 0xFF; // Upper half
176 // ln = (val & 0xFF);
177 // val = (ln << 8) + hn;
178
179 wb(a,val,&error);
180 if (error)
181 printf("BUS Error during Write at address %08X\n",a);
182 }
183
184 /*-------------------------------------------------------------------------*/
185 /* DecodeS1 - Decode and place in memory S1 type records */
186 /* Checks for correct checksum value and will not write if incorrect */
187 /*---------------------------------------------------------------------mjw-*/
188 static void DecodeS1(char *cp, long offset,long skip)
189 {
190 long address;
191 unsigned short val;
192 unsigned char *datastart, cnt, cntr, chksum;
193 unsigned long addr;
194
195 cnt = BYT(cp) - 3; /* Get Length of Line */
196 chksum = BYT(cp);
197 cp += 2;
198
199 addr = ComputeAddr(cp,2) * skip;
200 printf("Address %X\n",addr);
201 address = (addr + (unsigned long) goffset);
202
203 chksum += BYT(cp); /* Checksum 1st address byte */
204 cp += 2;
205 chksum += BYT(cp); /* Checksum 2nd address byte */
206 cp += 2;
207
208 datastart = (unsigned char *)cp; /* Data starts here */
209
210 /* Calc rest of checksum please */
211 for (cntr = 0; cntr <= cnt; cntr++, cp += 2)
212 chksum += BYT(cp);
213
214 /* If checksum not valid, skip this line */
215 if (chksum != (unsigned char) 0xFF) {
216 printf("Checksum failed - Got %X\n",chksum);
217 return;
218 }
219
220 /* Every thing is cool, write data to memory */
221 for (cntr = 0; cntr < cnt; cntr++, datastart+=2, address+=skip) {
222 val = BYT(datastart);
223 checkwrite(address+offset,val);
224 }
225 }
226
227 /*-------------------------------------------------------------------------*/
228 /* dsp_srec */
229 /* int srec(char *filename, char *offset) */
230 /*---------------------------------------------------------------------mjw-*/
231 int dsp_srec(char *filename, long offset, long skip)
232 {
233 char *cp;
234 int flag, pcount;
235 int count = 0;
236 int errcount = 0;
237 int scount[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
238
239 buffer = (char *)malloc(BUFFER_SIZE);
240 if (buffer == (char *) 0) {
241 printf("\n\nLoad error: unable to get 4096 bytes of memory.\n\n\n");
242 return(ERROR);
243 }
244 infile = fopen(filename, "r");
245 if (infile == (FILE *) 0) {
246 printf("\n\nLoad error: unable to open file [%#X]\n\n\n");
247 free(buffer);
248 return(ERROR);
249 }
250
251 flag = pcount = 0;
252 while ((fgets(buffer, BUFFER_SIZE, infile) != (char *) 0) && (flag == 0)) {
253 cp = strtok(buffer, " \t\f\n");
254 if (cp == (char *) 0)
255 continue;
256
257 if (cp[0] != 'S') {
258 errcount++;
259 continue;
260 }
261
262 count++;
263 cp++; /* point to the record type */
264 switch (*cp) {
265 case '0': /* optional introduction record. */
266 scount[0]++;
267 break;
268 case '1': /* address count is 2 bytes long */
269 scount[1]++;
270 DecodeS1(++cp,offset,skip);
271 break;
272 case '2': /* address count is 3 bytes long */
273 scount[2]++;
274 break;
275 case '3': /* address is 4 bytes long */
276 scount[3]++;
277 break;
278 case '9': /* End-Of-File record */
279 scount[4]++;
280 flag = 1;
281 break;
282 } /* switch */
283 } /* while */
284
285 fclose(infile);
286 free(buffer);
287 printf("\n%d lines processed\n",count);
288 printf("S0 - %d\nS1 - %d\nS2 - %d\nS3 - %d\nS9 - %d\n\n\n",
289 scount[0], scount[1], scount[2], scount[3], scount[9]);
290 return(count);
291 }
292
293 //----------------------SREC-------------
294 void WriteSRecordsFile(char *b,int l)
295 {
296 unsigned char *addr;
297 int num,c;
298 long pnt,skip;
299 char fname[255];
300 FILE *fin;
301 int error,n,num_written;
302 unsigned int *dma_buffer;
303
304 num = sscanf(b,"%lx %s %lx",&pnt,&fname,&skip);
305
306 pnt += FixedAdder;
307
308 if((num < 2) || (num > 3)) {
309 printf("Usage: WriteSRecordFile address filename [skip]");
310 } else {
311 if (num == 2)
312 skip = 1;
313 if (ValidAddress(pnt)) {
314 dsp_srec(fname,pnt,skip);
315 }
316 }
317 }
318
319 /*------------------------------------------------------------------------------
320 * WriteFile
321 *
322 *------------------------------------------------------------------------mjw-*/
323 void WriteFile(char *b,int l)
324 {
325 unsigned char *addr;
326 int num,c;
327 long pnt;
328 char fname[255];
329 FILE *fin;
330 int error,n,num_written;
331 unsigned int *dma_buffer;
332
333 num = sscanf(b,"%lx %s",&pnt,&fname);
334
335 pnt += FixedAdder;
336
337 if(num != 2) {
338 printf("Usage: WriteFile address filename");
339 } else {
340 if (ValidAddress(pnt)) {
341 fin = fopen(fname,"rb");
342 if(!fin) {
343 printf("Can't open file %s\n",fname);
344 } else {
345 // Programmed IO
346 if (default_mode == MODE_PROGRAMMED) {
347 while((c = getc(fin)) != EOF) {
348 wb(pnt++,c,&error);
349 if (error) {
350 printf("Bus Error during Writefile.\n");
351 continue;
352 }
353 }
354 if (!quiet)
355 printf("Done Writing file to Memory");
356 } else {
357 // DMA
358 dma_buffer = (unsigned int *)malloc(WRITEBUFSIZE);
359 ioctl(vme_handle,IOCTL_SET_MODE,MODE_DMA);
360 lseek(vme_handle,pnt,SEEK_SET);
361
362 n = 1; // Start the while loop on a good note please
363 while(n) {
364 // get data from file
365 n = fread(dma_buffer,1,WRITEBUFSIZE,fin);
366 // Do The DMA Transfer
367 if (n > 0) {
368 num_written = write(vme_handle,dma_buffer,n);
369 if (num_written < 1) {
370 printf("BUS Error during Write file DMA Transfer\n");
371 }
372 }
373 }
374 free(dma_buffer);
375 ioctl(vme_handle,IOCTL_SET_MODE,MODE_PROGRAMMED);
376 }
377 }
378 }
379 }
380 }
381
382 /*------------------------------------------------------------------------------
383 * Display
384 * usage: display, addr, number of times
385 *------------------------------------------------------------------------jsh-*/
386 void DisplayMonitor(char *b, int l)
387 {
388 unsigned int x;
389 for (x=0;x<200;x++) {
390 Display(b, 1);
391 printf(" %02X\n",l);
392 }
393 }
394
395 /*------------------------------------------------------------------------------
396 * Display
397 * usage: display addr count
398 *------------------------------------------------------------------------mjw-*/
399 void Display(char *b,int l)
400 {
401 unsigned char *addr,*dma_buffer;
402 long pnt;
403 unsigned int count,x,num,n,a[16],y;
404 int error;
405 unsigned v;
406
407 num = sscanf(b,"%lx %x",&pnt,&count);
408
409 pnt += FixedAdder;
410
411 if (num < 1) {
412 pnt = lastpnt;
413 num = 1;
414 }
415
416 if (num == 1) {
417 count = DEFCNT;
418 num = 2;
419 }
420
421 if (num != 2) {
422 printf("Usage: d address [count]");
423 } else {
424 if (ValidAddress(pnt)) {
425 if (default_mode == MODE_PROGRAMMED) {
426 lastpnt = pnt + count;
427 for (x=0;x<count;x++) {
428 if (!binary) {
429 if (x % 16 == 0)
430 printf("%08lX: ",x+pnt);
431 if (x % 16 == 8)
432 printf("- ");
433
434 v = rb(pnt+x,&error);
435 if (!error) {
436 printf("%02X ",v);
437 a[x % 16] = v;
438 }
439 else {
440 printf("** ");
441 a[x % 16] = 0;
442 }
443
444 // Show the character values to the right.
445 if (x % 16 == 15) {
446 printf(": ");
447 for (y=0;y<16;y++) {
448 if ( (a[y] > 31) && (a[y] < 127) )
449 printf("%c",a[y]);
450 else
451 printf(".");
452 }
453 printf("\n");
454 }
455 } else {
456 v = rb(pnt+x,&error);
457 if (!error)
458 printf("%c",v);
459 else
460 printf("*");
461 }
462 }
463 } else { // end Mode Programmed
464 if (!quiet)
465 printf("--> Doing Read via DMA <--\n");
466 dma_buffer = (unsigned char *)malloc(count);
467 lastpnt = pnt + count;
468 // Do The DMA Transfer
469 ioctl(vme_handle,IOCTL_SET_MODE,MODE_DMA);
470 lseek(vme_handle,pnt,SEEK_SET);
471 n = read(vme_handle,dma_buffer,count);
472 ioctl(vme_handle,IOCTL_SET_MODE,MODE_PROGRAMMED);
473
474 if (n < 1) {
475 printf("BUS Error\n");
476 } else {
477 // Print the Results
478 for (x=0;x<n;x++) {
479 if (!binary) {
480 if (x % 16 == 0)
481 printf("%08lX: ",x+pnt);
482 if (x % 16 == 8)
483 printf("- ");
484 printf("%02X ",(unsigned char)dma_buffer[x]);
485 if (x % 16 == 15)
486 printf("\n");
487 } else {
488 printf("%c",(unsigned char)dma_buffer[x]);
489 }
490 }
491 }
492 free(dma_buffer);
493 } // end Mode DMA
494 }
495 }
496 }
497
498 /*------------------------------------------------------------------------------
499 * DisplayWord
500 * usage: display addr count
501 *------------------------------------------------------------------------mjw-*/
502 void DisplayWord(char *b,int l)
503 {
504 unsigned char *addr;
505 unsigned short *dma_buffer;
506 long pnt;
507 unsigned int count,x,num,n;
508 int error;
509 unsigned short v;
510
511 num = sscanf(b,"%lx %x",&pnt,&count);
512
513 pnt *= 2;
514 pnt += FixedAdder;
515
516 if (num < 1) {
517 pnt = lastpnt;
518 num = 1;
519 }
520
521 if (num == 1) {
522 count = DEFCNT;
523 num = 2;
524 }
525
526 if (num != 2) {
527 printf("Usage: dw address [count]");
528 } else {
529 // count /= 2;
530 if (ValidAddress(pnt)) {
531 if (default_mode == MODE_PROGRAMMED) {
532 lastpnt = pnt + count * 2;
533 for (x=0;x<count;x++) {
534 if (!binary) {
535 if (x % 8 == 0) {
536 printf("%08lX: ",(x*2)+pnt);
537 printf("%08X: ",(x+((pnt-FixedAdder)/2)));
538 }
539 if (x % 8 == 4)
540 printf("- ");
541
542 v = rw(x*2+pnt,&error);
543 if (!error)
544 printf("%04X ",v);
545 else
546 printf("**** ");
547
548 if (x % 8 == 7)
549 printf("\n");
550 } else {
551 v = rw(pnt+x*2,&error);
552 if (!error)
553 printf("%c%c",(v&0x00FF),((v&0xFF00)>>8));
554 else
555 printf("**");
556 }
557 }
558 } else { // end Mode Programmed
559 if (!quiet)
560 printf("--> Doing Read via DMA <--\n");
561 dma_buffer = (unsigned short *)malloc(count);
562 lastpnt = pnt + count * 2;
563 // Do The DMA Transfer
564 ioctl(vme_handle,IOCTL_SET_MODE,MODE_DMA);
565 lseek(vme_handle,pnt,SEEK_SET);
566 n = read(vme_handle,dma_buffer,count*2);
567 ioctl(vme_handle,IOCTL_SET_MODE,MODE_PROGRAMMED);
568
569 if (n < 1) {
570 printf("BUS Error\n");
571 } else {
572 // Print the Results
573 for (x=0;x<(n/2);x++) {
574 if (!binary) {
575 if (x % 8 == 0)
576 printf("%08X: ",(x+pnt));
577 if (x % 8 == 4)
578 printf("- ");
579 printf("%04X ",(unsigned short)dma_buffer[x]);
580 if (x % 8 == 7)
581 printf("\n");
582 } else {
583 v = dma_buffer[x];
584 printf("%c%c",(v&0x00FF),((v&0xFF00)>>8));
585 }
586 }
587 }
588 free(dma_buffer);
589 } // end Mode DMA
590 }
591 }
592 }
593
594 /*------------------------------------------------------------------------------
595 * DisplayLong
596 * usage: display addr count
597 *------------------------------------------------------------------------mjw-*/
598 void DisplayLong(char *b,int l)
599 {
600 unsigned char *addr;
601 unsigned int *dma_buffer;
602 long pnt;
603 unsigned int count,x,num,n;
604 int error;
605 unsigned long v;
606
607 num = sscanf(b,"%lx %x",&pnt,&count);
608
609 pnt += FixedAdder;
610
611 if (num < 1) {
612 pnt = lastpnt;
613 num = 1;
614 }
615
616 if (num == 1) {
617 count = DEFCNT;
618 num = 2;
619 }
620
621 if (num != 2) {
622 printf("Usage: dl address [count]");
623 } else {
624 count /= 4;
625 if (ValidAddress(pnt)) {
626 if (default_mode == MODE_PROGRAMMED) {
627 lastpnt = pnt + count*4;
628 for (x=0;x<count;x++) {
629 if (!binary) {
630 if (x % 4 == 0)
631 printf("%08X: ",(x*4+pnt));
632 if (x % 4 == 2)
633 printf("- ");
634 v = rl(x*4+pnt,&error);
635 if (!error)
636 printf("%08X ",v);
637 else
638 printf("******** ");
639 if (x % 4 == 3)
640 printf("\n");
641
642 } else {
643 v = rl(x*4+pnt,&error);
644 if (!error)
645 printf("%c%c%c%c",
646 (v&0x000000FF),
647 ((v&0x0000FF00)>>8),
648 ((v&0x00FF0000)>>16),
649 ((v&0xFF000000)>>24));
650 else
651 printf("****");
652 }
653 }
654 } else {
655 if (!quiet)
656 printf("--> Doing Read via DMA <--\n");
657 dma_buffer = (unsigned int *)malloc(count);
658 lastpnt = pnt + count * 4;
659 // Do The DMA Transfer
660 ioctl(vme_handle,IOCTL_SET_MODE,MODE_DMA);
661 lseek(vme_handle,pnt,SEEK_SET);
662 n = read(vme_handle,dma_buffer,count*4);
663 ioctl(vme_handle,IOCTL_SET_MODE,MODE_PROGRAMMED);
664
665 if (n < 1) {
666 printf("BUS Error\n");
667 } else {
668 for (x=0;x<(n/4);x++) {
669 if (!binary) {
670 if (x % 4 == 0)
671 printf("%08X: ",(x*4+pnt));
672 if (x % 4 == 2)
673 printf("- ");
674 printf("%08lX ",(unsigned int)dma_buffer[x]);
675 if (x % 4 == 3)
676 printf("\n");
677 } else {
678 v = dma_buffer[x];
679 printf("%c%c%c%c",
680 (v&0x000000FF),
681 ((v&0x0000FF00)>>8),
682 ((v&0x00FF0000)>>16),
683 ((v&0xFF000000)>>24));
684 }
685 }
686 }
687 }
688 }
689 }
690 }
691
692 /*------------------------------------------------------------------------------
693 * Write
694 * usage: Write addr value
695 *------------------------------------------------------------------------mjw-*/
696 void Write(char *b,int l)
697 {
698 long pnt,num,cnt,x;
699 unsigned char v;
700 int error;
701
702 num = sscanf(b,"%lx %x %lx",&pnt,&v,&cnt);
703
704 pnt += FixedAdder;
705
706 if (num < 2) {
707 printf("Usage: w address value [count]");
708 } else {
709 if (num < 3)
710 cnt = 1;
711 if (ValidAddress(pnt)) {
712 for(x=0;x<cnt;x++) {
713 wb(pnt++,v,&error);
714 if (error)
715 printf("BUS Error during Write at address %08X\n",pnt-1);
716 }
717 }
718 }
719 }
720
721 /*------------------------------------------------------------------------------
722 * WriteWord
723 * usage: Write addr value
724 *------------------------------------------------------------------------mjw-*/
725 void WriteWord(char *b,int l)
726 {
727 long pnt,num,cnt,x;
728 unsigned short v;
729 int error;
730
731 num = sscanf(b,"%lx %x %lx",&pnt,&v,&cnt);
732
733 pnt *= 2; // word addressing
734 pnt += FixedAdder;
735
736 if (num < 2) {
737 printf("Usage: ww address value [count]");
738 } else {
739 if (num < 3)
740 cnt = 1;
741 if (ValidAddress(pnt)) {
742 for(x=0;x<cnt;x++) {
743 ww(pnt,v,&error);
744 pnt += 2;
745 if (error)
746 printf("BUS Error during Write at address %08X\n",pnt-2);
747 }
748 }
749 }
750 }
751
752 /*------------------------------------------------------------------------------
753 * WriteLong
754 * usage: Write addr value
755 *------------------------------------------------------------------------mjw-*/
756 void WriteLong(char *b,int l)
757 {
758 long pnt,num,cnt,x;
759 unsigned long v;
760 int error;
761
762 num = sscanf(b,"%lx %lx %lx",&pnt,&v,&cnt);
763
764 pnt += FixedAdder;
765
766 if (num < 2) {
767 printf("Usage: wl address value [count]");
768 } else {
769 if (num < 3)
770 cnt = 1;
771 if (ValidAddress(pnt)) {
772 for(x=0;x<cnt;x++) {
773 wl(pnt,v,&error);
774 pnt += 4;
775 if (error)
776 printf("BUS Error during Write at address %08X\n",pnt-4);
777 }
778 }
779 }
780 }
781
782 /*------------------------------------------------------------------------------
783 * Seek
784 *
785 *------------------------------------------------------------------------mjw-*/
786 void Seek(char *b,int l)
787 {
788 unsigned char *addr;
789 unsigned int num,value;
790 long ptr;
791
792 num = sscanf(b,"%lx",&ptr);
793
794 ptr += FixedAdder;
795
796 if (ValidAddress(ptr)) {
797 if(num != 1) {
798 printf("Seek usage: SEEK address\n");
799 } else {
800 lseek(vme_handle,ptr,SEEK_SET);
801 }
802 }
803 }
804
805 /*------------------------------------------------------------------------------
806 * wint
807 * wait for VME interrupt
808 *------------------------------------------------------------------------mjw-*/
809 void wint(char *b, int l)
810 {
811 unsigned int a,num;
812 num = sscanf(b, "%lx", &a);
813
814 if (num != 1) {
815 printf("wint usage: wint v\n");
816 printf(" where v = 0 is don't wait for ints\n");
817 printf(" v = n (vme interrupt) is wait for ints before read\n");
818 } else {
819 ioctl(vme_handle,IOCTL_SET_WINT,a); // Set WINT flag
820 }
821 }
822
823 /*------------------------------------------------------------------------------
824 * WriteReg
825 *
826 *------------------------------------------------------------------------mjw-*/
827 void WriteReg(char *b,int l)
828 {
829 unsigned char *addr;
830 unsigned int num,value;
831 long reg;
832
833 num = sscanf(b,"%lx %lx",&reg,&value);
834
835 if(num != 2) {
836 printf("REGW usage: REGW register value\n");
837 } else {
838 printf("Universe Reg Assigned %04X = %08X\n",reg,value);
839 WriteUniReg(reg,value);
840 }
841 }
842
843 /*------------------------------------------------------------------------------
844 * ReadReg
845 *
846 *------------------------------------------------------------------------mjw-*/
847 void ReadReg(char *b,int l)
848 {
849 unsigned char *addr;
850 unsigned int num,value;
851 long reg;
852
853 num = sscanf(b,"%lx",&reg);
854
855 if(num != 1) {
856 printf("REGR usage: REGW register\n");
857 } else {
858 value = ReadUniReg(reg);
859 printf("Universe Reg %04X = %08X\n",reg,value);
860 }
861 }
862
863 /*------------------------------------------------------------------------------
864 * ReadFile
865 *
866 *------------------------------------------------------------------------mjw-*/
867 void ReadFile(char *b,int l)
868 {
869 unsigned char *addr;
870 int num,c,n;
871 long pnt,len,i = 0;
872 char fname[255];
873 FILE *fout;
874 int error;
875 unsigned int *dma_buffer;
876
877 num = sscanf(b,"%lx %li %s",&pnt,&len,&fname);
878
879 pnt += FixedAdder;
880
881 if(num != 3) {
882 printf("Usage: ReadFile address len filename");
883 } else {
884 if (ValidAddress(pnt)) {
885 fout = fopen(fname,"wb");
886 if(!fout) {
887 printf("Can't open file %s\n",fname);
888 } else {
889 if (default_mode == MODE_PROGRAMMED) {
890 // Do it via PROGRAMMED IO
891 while(i++ < len) {
892 c = rb(pnt++,&error);
893 if (error) {
894 printf("Bus Error during Readfile. File may be truncated.\n");
895 len = 0;
896 } else
897 putc(c,fout);
898 }
899 // VIA DMA
900 } else {
901 if (!quiet)
902 printf("--> Doing ReadFile via DMA <--\n");
903 dma_buffer = (unsigned int *)malloc(len);
904 // Do The DMA Transfer
905 ioctl(vme_handle,IOCTL_SET_MODE,MODE_DMA);
906 lseek(vme_handle,pnt,SEEK_SET);
907 n = read(vme_handle,dma_buffer,len);
908 ioctl(vme_handle,IOCTL_SET_MODE,MODE_PROGRAMMED);
909 if (n < 1) {
910 printf("BUS Error during DMA Transfer\n");
911 } else {
912 while(i++ < len)
913 putc(dma_buffer[i],fout);
914 }
915 free(dma_buffer);
916 }
917
918 fclose(fout);
919 if (!quiet)
920 printf("Done Reading Memory to a File\n");
921 }
922 }
923 }
924 }
925
926 /*------------------------------------------------------------------------------
927 * TestDMA
928 *
929 *------------------------------------------------------------------------mjw-*/
930 /*
931 void TestDMA(char *b,int l)
932 {
933 int num;
934 unsigned int pci_pnt,vme_pnt,len, val, temp;
935 char testme[] = 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,
936 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27;
937
938 num = sscanf(b,"%lx %lx %lx",&pci_pnt,&vme_pnt,&len);
939
940 if (num == 0) {
941 pci_pnt = 0;
942 vme_pnt = 0xa5000000;
943 len = 16;
944 num = 3;
945 }
946
947 if (num != 3) {
948 printf("Usage: TestDMA pciaddr vmeaddr len");
949 } else {
950
951 val = ReadUniReg(PCI_CSR); // Lets Clear any error flags
952 WriteUniReg(PCI_CSR,val | 0xF8000000);
953
954 WriteUniReg(DCTL,0x80820100); // Setup Control Reg
955 WriteUniReg(DTBC,len); // Setup Length
956 WriteUniReg(DLA,pci_pnt); // Setup PCI Address
957 WriteUniReg(DVA,vme_pnt); // Setup VME Address
958 WriteUniReg(DGCS,0x80006F00); // GO
959
960 val = ReadUniReg(DGCS);
961
962 printf("DMA General Control Reg Value = %08X\n",val);
963 temp = val & 0x00008000;
964 if (temp)
965 printf(" Active\n");
966 temp = val & 0x00004000;
967 if (temp)
968 printf(" Stopped Flag\n");
969 temp = val & 0x00002000;
970 if (temp)
971 printf(" Halted Flag\n");
972 temp = val & 0x00000800;
973 if (temp)
974 printf(" Transfers Complete\n");
975 temp = val & 0x00000400;
976 if (temp)
977 printf(" PCI Bus Error\n");
978 temp = val & 0x00000200;
979 if (temp)
980 printf(" VME Bus Error\n");
981 temp = val & 0x00000100;
982 if (temp)
983 printf(" Protocol Error\n");
984
985 val = ReadUniReg(PCI_CSR);
986
987 printf("PCI Configuration Space Control = %08X\n",val);
988 temp = val & 0x80000000;
989 if (temp)
990 printf(" Parity Error\n");
991 temp = val & 0x40000000;
992 if (temp)
993 printf(" Signalled SERR#\n");
994 temp = val & 0x20000000;
995 if (temp)
996 printf(" Received Master-Abort\n");
997 temp = val & 0x10000000;
998 if (temp)
999 printf(" Reveiced Target-Abort\n");
1000 temp = val & 0x08000000;
1001 if (temp)
1002 printf(" Signalled Target-Abort\n");
1003 }
1004 }
1005 */
1006
1007 /*------------------------------------------------------------------------------
1008 * TestDMA
1009 *
1010 *------------------------------------------------------------------------mjw-*/
1011 void TestDMA(char *b,int l)
1012 {
1013 int num;
1014 unsigned int vme_pnt,len, val, temp, n, x;
1015 char testme[] = "ABCDEFGHIJKLMNOP";
1016 char buf[16];
1017
1018 num = sscanf(b,"%lx %lx",&vme_pnt,&len);
1019
1020 if (num == 0) {
1021 vme_pnt = 0x8000;
1022 len = 16;
1023 num = 2;
1024 }
1025
1026 if (num != 2) {
1027 printf("Usage: TestDMA offset len");
1028 printf(" This will read len bytes via DMA from address offset");
1029 } else {
1030
1031 printf("Read Test.");
1032 ioctl(vme_handle,IOCTL_SET_MODE,MODE_DMA);
1033 lseek(vme_handle,vme_pnt,SEEK_SET);
1034 n = read(vme_handle,buf,len);
1035 ioctl(vme_handle,IOCTL_SET_MODE,MODE_PROGRAMMED);
1036
1037 for (x=0;x<n;x++) {
1038 if (x % 16 == 0)
1039 printf("%08lX: ",x);
1040 if (x % 16 == 8)
1041 printf("- ");
1042 printf("%02X ",(unsigned char)buf[x]);
1043 if (x % 16 == 15)
1044 printf("\n");
1045 }
1046
1047 // printf("Write Test.");
1048 // ioctl(vme_handle,IOCTL_SET_MODE,MODE_DMA);
1049 // lseek(vme_handle,vme_pnt,SEEK_SET);
1050 // write(vme_handle,buf,len);
1051 // ioctl(vme_handle,IOCTL_SET_MODE,MODE_PROGRAMMED);
1052 }
1053 }
1054
1055 /*------------------------------------------------------------------------------
1056 * TestProgrammed
1057 *
1058 *------------------------------------------------------------------------mjw-*/
1059 void TestProgrammed(char *b,int l)
1060 {
1061 int num;
1062 unsigned int vme_pnt,len, val, temp, n, x;
1063 char testme[] = "ABCDEFGHIJKLMNOP";
1064 char buf[16];
1065
1066 num = sscanf(b,"%lx %lx",&vme_pnt,&len);
1067
1068 if (num == 0) {
1069 vme_pnt = 0x8000;
1070 len = 16;
1071 num = 2;
1072 }
1073
1074 if (num != 2) {
1075 printf("Usage: TestDMA offset len");
1076 printf(" This will read len bytes via DMA from address offset");
1077 } else {
1078
1079 printf("Read Test.");
1080 ioctl(vme_handle,IOCTL_SET_MODE,MODE_PROGRAMMED);
1081 lseek(vme_handle,vme_pnt,SEEK_SET);
1082 n = read(vme_handle,buf,len);
1083
1084 for (x=0;x<n;x++) {
1085 if (x % 16 == 0)
1086 printf("%08lX: ",x);
1087 if (x % 16 == 8)
1088 printf("- ");
1089 printf("%02X ",(unsigned char)buf[x]);
1090 if (x % 16 == 15)
1091 printf("\n");
1092 }
1093
1094 printf("Write Test.");
1095 ioctl(vme_handle,IOCTL_SET_MODE,MODE_PROGRAMMED);
1096 lseek(vme_handle,vme_pnt,SEEK_SET);
1097 write(vme_handle,buf,len);
1098 }
1099 }
1100
1101 /*------------------------------------------------------------------------------
1102 * TestRead
1103 *
1104 *------------------------------------------------------------------------mjw-*/
1105 void TestRead(char *b,int l)
1106 {
1107 unsigned int pnt,len,x,n,num;
1108 unsigned char block[1024];
1109
1110 num = sscanf(b,"%lx %lx",&pnt,&len);
1111
1112 if (num != 2) {
1113 len = 16;
1114 pnt = 0;
1115 }
1116
1117 pnt += FixedAdder;
1118
1119 if (ValidAddress(pnt)) {
1120 lseek(vme_handle,pnt,SEEK_SET);
1121 n = read(vme_handle,block,len);
1122
1123 if (n) {
1124 for (x=0;x<n;x++) {
1125 if (x % 16 == 0)
1126 printf("%08lX: ",x+pnt);
1127 if (x % 16 == 8)
1128 printf("- ");
1129 printf("%02X ",block[x]);
1130 if (x % 16 == 15)
1131 printf("\n");
1132 }
1133 } else {
1134 printf(" Read Failed.\n");
1135 }
1136
1137 printf("Test Read Done..\n");
1138 }
1139 }
1140
1141 /*------------------------------------------------------------------------------
1142 * TestWrite
1143 *
1144 *------------------------------------------------------------------------mjw-*/
1145 void TestWrite(char *b,int l)
1146 {
1147 long pnt,num,x;
1148 int error;
1149
1150 num = sscanf(b,"%lx",&pnt);
1151
1152 if (num != 1) {
1153 pnt = 0;
1154 }
1155
1156 pnt += FixedAdder;
1157
1158 if (ValidAddress(pnt)) {
1159 for(x=0;x<16;x++) {
1160 wb(pnt+x,0xAB,&error);
1161 }
1162
1163 printf("Test Write Done..\n");
1164 }
1165 }
1166
1167 /*-----------------------------------------------------------------------------
1168 * regs
1169 *
1170 *------------------------------------------------------------------------mjw-*/
1171 void regs(char *b,int l)
1172 {
1173 unsigned int val;
1174 unsigned int temp;
1175
1176 printf("Registers:\n");
1177
1178 val = ReadUniReg(LMISC);
1179 printf(" LMISC = %08lX\n",val);
1180 temp = (val & 0xF0000000) >> 28;
1181 if (temp == 0)
1182 printf(" CRT = Disabled\n");
1183 else if (temp == 1)
1184 printf(" CRT = 128us\n");
1185 else if (temp == 2)
1186 printf(" CRT = 256us\n");
1187 else if (temp == 3)
1188 printf(" CRT = 512us\n");
1189 else if (temp == 4)
1190 printf(" CRT = 1024us\n");
1191 else if (temp == 5)
1192 printf(" CRT = 2048us\n");
1193 else if (temp == 6)
1194 printf(" CRT = 4096us\n");
1195 else if (temp == 7)
1196 printf(" CRT = Reserved\n");
1197
1198 temp = (val & 0x0F000000) >> 24;
1199 if (temp == 0)
1200 printf(" CWT = Disabled\n");
1201 else if (temp == 1)
1202 printf(" CWT = 16 PCI Clocks\n");
1203 else if (temp == 2)
1204 printf(" CWT = 32 PCI Clocks\n");
1205 else if (temp == 3)
1206 printf(" CWT = 64 PCI Clocks\n");
1207 else if (temp == 4)
1208 printf(" CWT = 128 PCI Clocks\n");
1209 else if (temp == 5)
1210 printf(" CWT = 256 PCI Clocks\n");
1211 else if (temp == 6)
1212 printf(" CWT = 512 PCI Clocks\n");
1213 else if (temp == 7)
1214 printf(" CWT = Reserved\n");
1215
1216 val = ReadUniReg(LSI0_CTL);
1217 printf(" LSIO_CTL = %08lX\n",val);
1218 temp = (val & 0x80000000) >> 31;
1219 if (temp == 0)
1220 printf(" EN = Disabled\n");
1221 else if (temp == 1)
1222 printf(" EN = Enabled\n");
1223
1224 temp = val & 0x40000000;
1225 if (temp)
1226 printf(" PWEN = Enabled\n");
1227 else
1228 printf(" PWEN = Disabled\n");
1229 temp = (val & 0x00C00000) >> 22;
1230 if (temp == 0)
1231 printf(" VDW = 8 bit\n");
1232 else if (temp == 1)
1233 printf(" VDW = 16 Bit\n");
1234 else if (temp == 2)
1235 printf(" VDW = 32 Bit\n");
1236 else if (temp == 3)
1237 printf(" VDW = 64 Bit\n");
1238
1239 temp = (val & 0x70000) >> 16;
1240 if (temp == 0)
1241 printf(" VAS = A16\n");
1242 else if (temp == 1)
1243 printf(" VAS = A24\n");
1244 else if (temp == 2)
1245 printf(" VAS = A32\n");
1246 else if (temp == 3)
1247 printf(" VAS = Reserved\n");
1248 else if (temp == 4)
1249 printf(" VAS = Reserved\n");
1250 else if (temp == 5)
1251 printf(" VAS = CR/CSR\n");
1252 else if (temp == 6)
1253 printf(" VAS = User 1\n");
1254 else if (temp == 7)
1255 printf(" VAS = User 2\n");
1256
1257 temp = (val & 0xC000) >> 14;
1258 if (temp == 0)
1259 printf(" PGM = Data\n");
1260 else if (temp == 1)
1261 printf(" PGM = Program\n");
1262 else if (temp == 2)
1263 printf(" PGM = Reserved\n");
1264 else if (temp == 3)
1265 printf(" PGM = Reserved\n");
1266
1267 temp = (val & 0x3000) >> 12;
1268 if (temp == 0)
1269 printf(" SUPER = Non-Privileged\n");
1270 else if (temp == 1)
1271 printf(" SUPER = Supervisor\n");
1272
1273 temp = (val & 0x0100) >> 8;
1274 if (temp == 0)
1275 printf(" VCT = Single Cycles Only\n");
1276 else if (temp == 1)
1277 printf(" VCT = Block Transfers OK\n");
1278
1279 temp = (val & 0x03);
1280 if (temp == 0)
1281 printf(" LAS = PCI Bus Memory Space\n");
1282 else if (temp == 1)
1283 printf(" LAS = PCI Bus I/O Space\n");
1284 else if (temp == 2)
1285 printf(" LAS = PCI Bus Type 1 Config Space\n");
1286 else if (temp == 3)
1287 printf(" LAS = Reserved\n");
1288
1289 printf(" LSIO_BS = %08lX\n",ReadUniReg(LSI0_BS));
1290 printf(" LSIO_BD = %08lX\n",ReadUniReg(LSI0_BD));
1291 printf(" LSIO_TO = %08lX\n",ReadUniReg(LSI0_TO));
1292 }
1293
1294 /*------------------------------------------------------------------------------
1295 * vmespace1
1296 *
1297 *------------------------------------------------------------------------mjw-*/
1298 void vmespace1(char *b,int l)
1299 {
1300 int num,temp;
1301 long reg;
1302
1303 num = sscanf(b,"%x",&temp);
1304
1305 if (num == 0) {
1306 printf(" VME Address Space: ");
1307 if (VMEspace == 1) {
1308 printf("A16\n");
1309 } else if (VMEspace == 2) {
1310 printf("A24\n");
1311 } else if (VMEspace == 3) {
1312 printf("A32\n");
1313 }
1314 } else if (num == 1) {
1315 if (temp == 1) {
1316 printf("Setting to A16\n");
1317 // vmespace(VME_A16);
1318 } else if (temp == 2) {
1319 printf("Setting to A24\n");
1320 // vmespace(VME_A24);
1321 } else if (temp == 3) {
1322 printf("Setting to A32\n");
1323 // vmespace(VME_A32);
1324 } else
1325 printf("Invalid Value for VMEspace\n");
1326 } else {
1327 printf("\nUsage: vmespace space\n");
1328 printf(" where if space = 1, VME Address Space = A16\n");
1329 printf(" where if space = 2, VME Address Space = A24\n");
1330 printf(" where if space = 3, VME Address Space = A32\n");
1331 }
1332 }
1333
1334 /*------------------------------------------------------------------------------
1335 * vmemap1
1336 *
1337 *------------------------------------------------------------------------mjw-*/
1338 void vmemap1(char *b,int l)
1339 {
1340 int num;
1341 long temp,count,space,size,type;
1342 char vmespc;
1343
1344 num = sscanf(b,"%lx %lx %lx %lx %lx",&temp,&count,&space,&size,&type);
1345
1346 if (num != 5) {
1347 printf("Usage: map address count space size type\n");
1348 printf(" where address is VME Address to set Universe image to\n");
1349 printf(" Space = 0 CR/CSR Space = 1 A16\n");
1350 printf(" Space = 2 A24 Space = 3 A32\n\n");
1351 printf(" Size = 1 8 bit Size = 2 16 bit\n");
1352 printf(" Size = 3 32 bit Size = 4 64 bit\n\n");
1353 printf(" Type = 0 USR/DATA Type = 1 USR/PRG\n");
1354 printf(" Type = 2 SUP/DATA Type = 3 SUP/PRG\n");
1355 } else {
1356 if (!quiet)
1357 printf("Setting PCI Slave Image to address %08lX\n",temp);
1358
1359 // VME Size
1360 if (size == 1) {
1361 vmespc = VME_SIZE_8;
1362 } else if (size == 2) {
1363 vmespc = VME_SIZE_16;
1364 } else if (size == 3) {
1365 vmespc = VME_SIZE_32;
1366 } else if (size == 4) {
1367 vmespc = VME_SIZE_64;
1368 } else
1369 printf(" Bad Size\n");
1370 FixedAdder = temp;
1371
1372 vmespc |= space;
1373
1374 switch (type) {
1375 case 0:
1376 vmespc &= ~VME_SUP_USR;
1377 vmespc &= ~VME_PRG_DATA;
1378 break;
1379 case 1:
1380 vmespc &= ~VME_SUP_USR;
1381 vmespc |= VME_PRG_DATA;
1382 break;
1383 case 2:
1384 vmespc |= VME_SUP_USR;
1385 vmespc &= ~VME_PRG_DATA;
1386 break;
1387 case 3:
1388 vmespc |= VME_SUP_USR;
1389 vmespc |= VME_PRG_DATA;
1390 break;
1391 }
1392 VME_Valid_Base = temp;
1393 VME_Valid_Cnt = count;
1394 vmemap(temp,count,vmespc);
1395 }
1396 }
1397
1398 /*------------------------------------------------------------------------------
1399 * quit
1400 *
1401 *------------------------------------------------------------------------mjw-*/
1402 void quit(char *b,int l)
1403 {
1404 shutdown_vmelib();
1405 if (!quiet)
1406 printf("Exiting\n\n");
1407 exit(0);
1408 }
1409
1410 /*------------------------------------------------------------------------------
1411 * help
1412 *
1413 *------------------------------------------------------------------------mjw-*/
1414 void help(char *b,int l)
1415 {
1416 int x = 0;
1417 int done = 0;
1418
1419 printf("Commands:\n");
1420 while (!done) {
1421 printf("%10s ",cmdTable[x].command);
1422 if ((x+1) % 6 == 0)
1423 printf("\n");
1424 if (cmdTable[x++].CmdType == CMDT_NULL)
1425 done = 1;
1426 } // While
1427 }
1428
1429 /*------------------------------------------------------------------------------
1430 * status
1431 *
1432 *------------------------------------------------------------------------mjw-*/
1433 void status(char *b,int l)
1434 {
1435 printf("Program Status:\n");
1436 printf(" Fixed Adder: %08X\n",FixedAdder);
1437 }
1438
1439 /*-----------------------------------------------------------------------------
1440 * ProcessCommand
1441 *
1442 *------------------------------------------------------------------------mjw-*/
1443 void ProcessCommand(char *buffer,int len)
1444 {
1445 int done = 0;
1446 int cmdi = 0;
1447 COMMAND *cpnt;
1448 char *cmd;
1449 char *params;
1450 int x,plen;
1451 long temp;
1452
1453 cmd = buffer;
1454 for(x=0;x < len;x++) {
1455 if (buffer[x] == ' ') {
1456 buffer[x] = 0; // NULL Term the string
1457 params = &buffer[x+ 1];
1458 plen = len - x;
1459 break;
1460 }
1461 }
1462
1463 while (!done) {
1464 if (!strcmp(cmd,cmdTable[cmdi].command)) {
1465 done = 1;
1466 cpnt = &cmdTable[cmdi];
1467 switch (cpnt->CmdType) {
1468 case CMDT_NULL:
1469 break;
1470 case CMDT_FUNC:
1471 func(cpnt->pointer)(params,plen);
1472 break;
1473 case CMDT_MODC:
1474 sscanf(params,"%i",&temp);
1475 *(char*)(cpnt->pointer) = temp;
1476 break;
1477 case CMDT_MODI:
1478 sscanf(params,"%i",&temp);
1479 *(int*)(cpnt->pointer) = temp;
1480 break;
1481 case CMDT_MODL:
1482 sscanf(params,"%lx",&temp);
1483 *(long*)(cpnt->pointer) = temp;
1484 break;
1485 case CMDT_MODB:
1486 if (!strcmp(params,"ON")) {
1487 *(int*)(cpnt->pointer) = 1;
1488 } else if (!strcmp(params,"TRUE")) {
1489 *(int*)(cpnt->pointer) = 1;
1490 } else if (!strcmp(params,"OFF")) {
1491 *(int*)(cpnt->pointer) = 0;
1492 } else if (!strcmp(params,"FALSE")) {
1493 *(int*)(cpnt->pointer) = 0;
1494 } else {
1495 sscanf(params,"%i",&temp);
1496 *(int*)(cpnt->pointer) = temp;
1497 }
1498 break;
1499 } // switch
1500 }
1501 if (cmdTable[cmdi++].CmdType == CMDT_NULL) {
1502 done = 1;
1503 printf("Unknown Command\n");
1504 }
1505 } // While
1506 }
1507
1508

  ViewVC Help
Powered by ViewVC 1.2-dev