/* SDSU ASTRONOMY SBUS INTERFACE BOARD TESTING MODULE RELEASE 1.1 8/15/95 This testing module was developed from Dawn VME products DPS-1 platform. It allows specific functions to be executed that transmit and receive data using the SBUS interface board device driver to communicate with the SBUS interface board. This testing module was developed by Greg Moore 2/10/95. */ #define sun4c #include #include #include #include #include #include /* need for stackavail() */ #include "tdefs.h" #include "menuequ.h" #include "astroio.h" #ifndef NULL #define NULL '\0' #endif #define DEVNAME "/dev/astro0\0" #define ZEROSPTN 0 #define ONESPTN 1 #define INCREMPTN 2 #define DECREMPTN 3 #define DEVICE_CLOSED 99 /*------------- IOCTL() request codes -----*/ #define WRTDMACSR 0x80040000 #define WRTDMAAR 0x80040001 #define WRTDMABCR 0x80040002 #define WRTDMAUNU 0x80000003 #define WRTDMAWW 0x80040004 #define WRTDCHAN 0x80000005 #define WRTECHAN 0x80020006 #define RDDMACSR 0x40040000 #define RDDMAAR 0x40040001 #define RDDMABCR 0x40040002 /*----------- declare external variables -------*/ extern int errno ; /*----------- local workspace */ union cvtbfr { char ch[65536] ; u_char uch[65536] ; int in[256] ; u_int uin[256] ; long lg[256] ; u_long ulg[256] ; short sh[512] ; u_short ush[512] ; } ; static long comp[256] ; static int xwrtdmaunu ; static union cvtbfr dat ; static char *arg ; static char *Sunbfr ; static int filedes ; /* device file descriptor */ static char devicename[32] ; /* device name string */ static int rtncode, request ; static u_long adr_of_arg ; static u_long numbytes = 0xfc, Run ; static int openflag = DEVICE_CLOSED ; static char filediff[32] ; static char card[81] ; static int diff_fd ; static int diff_flg ; /* differences found flag */ static int opt_flg = 0; /* menu option flag */ static int errstop = 0; /* MENU 5 stop on errors flag */ /*================ DATA STRUCTURES ===================================*/ struct dmaio_regs { u_long Dmacsr ; /* control and status register */ u_long Dmaar ; /* address register */ u_long Dmabcr ; /* byte count register */ u_long dma_unused ; /* unused register */ }; /* ------------ DMAIO CSR Register bit assignments 31-28 R Device Id 1000 27-16 R Reserved FFF 15 RW ILAC. Write this bit to 0. 14 R TC 13 RW Enable Byte Counter = 1 12-11 R D Channel Pack Register Byte Address 10 R D Channel DMA Cycle Request 9 RW D Channel DMA Enable 1= Respond to D Chan requests 8 RW D Channel Write Operation 1 = Write memory 0 = Read memory 7 RW Reset 1 = Reset state 6 RW Drain Buffer 1 = Write D Chan Pack reg to SBus memory and clear the Pack Count (Bits 3,2). This bit clears automatically. 5 W Flush Buffer. 1 = Reset Pack Count, Err Pending and TC bits. 4 RW Interrupt Enable. 1 = Pass interrupt requests to SBus INTREQ Interrupt sources are D_IRQ*, Error Pending and TC reached. 3-2 R D Channel Pack Count. The number of valid bytes destined to be written to the SBus. 1 R Error Pending. Set if an error during a D Channel operation. Parity, protection or timeout. 0 R Interrupt Pending (1 = Asserted.). Latched OR of D_IRQ* or TC -------*/ /* ----------------------------------- Function: openastro() Calls the open() function to test if device astro0 can be opened. --------------------- */ openastro() { int rtncode ; /* Open the device */ rtncode = 0; strcpy(devicename, DEVNAME) ; filedes = open(devicename, O_RDWR) ; if (filedes == -1) { perror(devicename) ; printf("File was NOT opened: errno 0x%x\n",errno) ; printf("Use 'modstat' to see if the device was installed\n") ; rtncode = -1 ; } else { printf("File was opened with filedes 0x%x\n",filedes) ; openflag = OK ; } return (rtncode) ; } /* ----------------------------------- Function: closeastro() Calls the close() function to test if device astro0 can be closed. --------------------- */ closeastro() { int rtncode ; /* Open the device */ rtncode = 0; strcpy(devicename, DEVNAME) ; rtncode = close(filedes) ; printf("File was closed with rtncode 0x%x\n",rtncode) ; if (rtncode == -1) { printf(" Returned errno 0x%x\n",errno) ; } openflag = DEVICE_CLOSED ; return (rtncode) ; } /* ----------------------------------- Function: opendiff() Calls the open() function to test if diff file can be opened. --------------------- */ opendiff() { int rtncode ; /* Open the file */ rtncode = 0; sprintf(filediff, "%s", "scratch") ; diff_fd = open(filediff, O_RDWR | O_CREAT | O_APPEND, 0666) ; if (diff_fd == -1) { perror(filediff) ; printf("\nDiff File was NOT opened: errno 0x%x\n",errno) ; rtncode = -1 ; } return (rtncode) ; } /* ----------------------------------- Function: closediff() Calls the close() function to test if diff file can be closed. --------------------- */ closediff() { int rtncode ; /* Close the file */ rtncode = 0; rtncode = close(diff_fd) ; return (rtncode) ; } /* ----------------------------------- Function: clrscrn() --------------------- */ void clrscrn() { printf("\n") ; /*printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n") ; printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n") ; printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n") ;*/ } /* ----------------------------------- Function: file2bfr (input, buffer) --------------------- */ void file2bfr(input, buffer) FILE *input ; char *buffer ; { int i; int c ; /* get characters until EOF */ i = 0 ; while ((c = getc (input)) != EOF){ buffer[i] = (char) c ; i++ ; } buffer[i] = '\0'; return ; } /* ----------------------------------- Function: read_file(buffer) --------------------- */ WORD read_file (buffer) char *buffer ; { FILE *fopen(), *fp_in, *fp_out; char fn_in[12], fn_out[12]; /* allow room for filename.ext */ printf ("Enter name of input file: "); scanf ("%s", fn_in); fp_in = fopen (fn_in,"r"); /* check for nonexistent input file and exit if fopen failed */ if (fp_in == NULL) { printf ("No input file %s\n",fn_in); return(BAD); } /* if fopen is OK then execute the rest of the program */ file2bfr(fp_in,buffer); printf("At point 23: %s", buffer) ; fclose (fp_in); return(OK); } /* ------------------local function --------- */ void ErrorMessage(ptr, erloc) /* --------------------------- */ char *ptr ; int erloc; { printf ("ERROR from %d: %s \n",erloc, ptr); getchar() ; return ; } /*_______________________ Function: fillbfr(ptntype) Establishes a data pattern in our test buffer. Returns: None _____________________________ */ fillbfr(ptntype) int ptntype ; { int i ; switch(ptntype) { case 0: /* All zeros pattern */ for (i=0; i<65536;i++) dat.uch[i] = 0 ; break ; case 1: /* All ones pattern */ for (i=0; i<256;i++) dat.uch[i] = 0xff ; break ; case 2: /* incrementing pattern */ for (i=0; i<256;i++) dat.uch[i] = i ; break ; default: case 3: /* decrementing pattern */ for (i=0; i<256;i++) dat.uch[255-i] = i ; break ; } return ; } /* --------------------------------- dsp_Sunbfr() Displays the data to or from the DDPS --------------------------------- */ dsp_Sunbfr() { int i,j, wordcnt ; LONG sunadr; BYTE *bfrptr ; LONG *datptr ; sunadr = 0; bfrptr = (BYTE *)Sunbfr ; datptr = (LONG *)Sunbfr ; /* Dump 252 bytes at bfrptr */ printf("\n") ; j = 0; wordcnt = numbytes/4; for(j=0; j astro_open() \n") ; printf (" 2 ---> Transmit data / DMA Read (No Compare) \n") ; printf (" 3 ---> Transmit word \n") ; printf (" 4 ---> Transmit data / DMA Read (Compare) \n") ; printf (" 5 ---> Continuous Transmit data / DMA Read / Compare\n") ; printf (" 6 ---> Reset DMA & SBUS board FIFO \n") ; printf (" 7 ---> DMA Read \n") ; printf (" 8 ---> astro_close() \n") ; printf (" 9 ---> Reset CSR \n") ; printf (" 10 ---> Test control registers (W/R) \n") ; printf (" 11 ---> Display control registers \n") ; printf (" 12 ---> Modify CSR register \n") ; printf (" 13 ---> Modify Addr Count register \n") ; printf (" 14 ---> Modify Byte Count register \n") ; printf (" 15 ---> Display data buffer \n") ; printf (" 16 ---> Stop physio() \n") ; printf (" 17 ---> Transmit data \n") ; printf (" 18 ---> Set Word Width \n") ; printf (" 19 ---> Transmit data over D Channel \n") ; printf ("\n") ; printf (" 30 ---> EXIT \n") ; printf ("\n ** Compare diffs can be found in file: 'scratch' **\n") ; printf ("---------------------------------------------------------\n") ; opt = 0 ; opt_flg = 0; errstop = 0; printf("\n\n"); printf(" OPTION ? "); scanf("%d", &opt); if (opt>=30) /* selections 1 thru 30 are valid */ { closeastro() ; clrscrn() ; return; } if (opt<1) goto MENU ; /* clear the screen before leaving */ clrscrn() ; switch (opt) { /* -------------------------- */ case MENU99: break ; case MENU1: /* --- open the device -------------------- */ openastro() ; printf("\n\n"); getchar() ; EXITU1: break ; case MENU2: /* ---------------- DMA Read SBUS FIFO ---------- */ fillbfr(ZEROSPTN) ; numflag = 0; printf ("\nDo you want to enter a specific number to transmit? (y/n):\n"); scanf ("%c", &yn); scanf ("%c", &yn); if((yn == 'y') || (yn == 'Y')) { numflag = 1; printf ("\nEnter the number you wish to transmit (hex):\n "); scanf ("%X", &bcr); printf ("\n\nNumber entered was 0x%x\n", bcr); } else if ((yn == 'n') || (yn == 'N')) bcr = 0; else goto U8EXIT; U8CONT: printf ("\nEnter the number of bytes to transmit (4 to fc) (hex):\n "); scanf ("%X", &numbytes); if (numbytes == 0) { printf("\n\nOK. No data will be sent!\n") ; goto U8EXIT ; } if ((numbytes < 0x4) || (numbytes > 0xfc)) { printf("\n\nNumber must be between 4 and fc (inclusive)! Try again!\n") ; goto U8CONT ; } if ((numbytes%4) != 0) { printf("\n\nNumber must be multiple of 4 for word size only! Try again!\n") ; goto U8CONT ; } printf ("\n\nNumber of bytes entered was 0x%x. Continue? (y/n):\n", numbytes); scanf ("%c", &yn); scanf ("%c", &yn); if((yn == 'y') || (yn == 'Y')) { csr = 0x00000180 ; dat.ulg[0] = csr ; wrtcsr() ; csr = 0x00000000 ; dat.ulg[0] = csr ; wrtcsr() ; num = 0 ; cnt = (numbytes/4) ; byteshft = numbytes ; byteshft <<= 16 ; xwrtdmaunu = (byteshft | WRTDMAUNU) ; for (i=0 ; i 0xfc)) { printf("\n\nNumber must be between 4 and fc (inclusive)! Try again!\n") ; goto U8CONT ; } if ((numbytes%4) != 0) { printf("\n\nNumber must be multiple of 4 for word size only! Try again!\n") ; goto U8CONT2 ; } printf ("\n\nNumber of bytes entered was 0x%x. Continue? (y/n):\n", numbytes); scanf ("%c", &yn); scanf ("%c", &yn); if((yn == 'y') || (yn == 'Y')) { U4RPT: diff_flg = 0 ; csr = 0x00000180 ; dat.ulg[0] = csr ; wrtcsr() ; csr = 0x00000000 ; dat.ulg[0] = csr ; wrtcsr() ; num = 0 ; cnt = (numbytes/4) ; byteshft = numbytes ; byteshft <<= 16 ; xwrtdmaunu = (byteshft | WRTDMAUNU) ; for (i=0 ; i 0xfc)) { printf("\n\nNumber must be between 4 and fc (inclusive)! Try again!\n") ; goto U5CONT1 ; } if ((numbytes%4) != 0) { printf("\n\nNumber must be multiple of 4 for word size only! Try again!\n") ; goto U5CONT1 ; } printf ("\n\nNumber of bytes entered was 0x%x. Continue? (y/n):\n", numbytes); scanf ("%c", &yn); scanf ("%c", &yn); if((yn == 'y') || (yn == 'Y')) { printf("Transmitting %d bytes in each run\n", numbytes) ; printf("Type control-C to stop\n\n", numbytes) ; if (numflag) { cnt = (numbytes/4) ; for (i=0 ; i 0xfc)) { printf("\n\nNumber must be between 4 and fc (inclusive)! Try again!\n") ; goto U8CONT3 ; } if ((numbytes%4) != 0) { printf("\n\nNumber must be a multiple of 4 for word size only! Try again!\n") ; goto U8CONT3 ; } printf ("\n\nNumber of bytes entered was 0x%x. Continue? (y/n):\n", numbytes); scanf ("%c", &yn); scanf ("%c", &yn); if((yn == 'y') || (yn == 'Y')) { fillbfr(ZEROSPTN) ; dmarddchan() ; if (openflag != OK) goto U8EXIT ; /*quit if device not connected */ printf("The SBUS FIFO was read back, using DMA ops, as :\n") ; dsp_Sunbfr() ; } else printf ("yn is %x, %c\n", yn,yn) ; printf("\n\n"); getchar() ; break ; case MENU8: /* --- close the device -------------------- */ closeastro() ; printf("\n\n"); getchar() ; break ; case MENU9: /* ------Reset CSR -------------------- */ dat.ulg[0] = DMAIO_DEV_RESET ; wrtcsr() ; if (openflag != OK) goto U8EXIT ; printf("Reading back the reset command:\n") ; dat.ulg[0] = 0xffffffff ; rdcsr(); if (dat.ulg[0] == 0xffffffff) { printf("CSR does not echo properly. Hardware OK?\n") ; } rstcsr() ; /* Clear the CSR reg */ printf("\n\n"); getchar() ; break ; case MENU10: /* --- Test Control Regs ----------- */ testval = 0x12345678 ; dat.ulg[0] = testval ; wrtar() ; /* write the Dmaar */ if (openflag != OK) goto U8EXIT ; /*quit if device not connected */ dat.ulg[0] = 0 ; rdar() ; /* read the Dmaar */ if (dat.ulg[0] == testval) printf("Returned register is OK\n") ; else printf("Returned register value is not as written!\n") ; testval = 0x87654321 ; dat.ulg[0] = testval ; wrtbcr() ; /* write the Dmabcr */ if (openflag != OK) goto U8EXIT ; /*quit if device not connected */ dat.ulg[0] = 0 ; rdbcr() ; testval &= 0x00ffffff ; /* byte count is 24 bits only */ if (dat.ulg[0] == testval) printf("Returned register is OK\n") ; else printf("Returned register value is not as written!\n") ; printf("\n\n"); getchar() ; break ; /* end MENU 4 */ case MENU11: /* --------------------------- */ /* --- Read and Display Control Regs ----------- */ if (openflag != OK) goto U8EXIT ; /*quit if device not connected */ rdcsr() ; /* read the Dmacsr */ rdar() ; /* read the Dmaar */ rdbcr() ; /* read the Dmabcr */ printf("\n\n"); getchar() ; break ; case MENU12: /* --------------Modify CSR------- */ if (openflag != OK) goto U8EXIT ; /*quit if device not connected */ rdcsr() ; /* read the Dmacsr */ printf ("\nEnter the new CSR value (hex):\n "); scanf ("%X", &csr); printf ("\n\nCSR value entered was 0x%x. Send it out? (y/n):\n", csr); scanf ("%c", &yn); scanf ("%c", &yn); if((yn == 'y') || (yn == 'Y')) { printf (" Sending it out\n"); dat.ulg[0] = csr ; wrtcsr() ; } else printf ("yn is %x, %c\n", yn,yn) ; printf("\n\n"); getchar() ; break ; case MENU13: /* ---------------Modify AR------------ */ if (openflag != OK) goto U8EXIT ; /*quit if device not connected */ rdar() ; /* read the Dmaar */ printf ("\nEnter the new AR value (hex):\n "); scanf ("%X", &ar); printf ("\n\nAR value entered was 0x%x. Send it out? (y/n):\n", ar); scanf ("%c", &yn); scanf ("%c", &yn); if((yn == 'y') || (yn == 'Y')) { printf (" Sending it out\n"); dat.ulg[0] = ar ; wrtar() ; } else printf ("yn is %x, %c\n", yn,yn) ; printf("\n\n"); getchar(); break ; case MENU14: /* ---------------Modify BCR------------ */ if (openflag != OK) goto U8EXIT ; /*quit if device not connected */ rdbcr() ; /* read the Dmabcr */ printf ("\nEnter the new BCR value (hex):\n "); scanf ("%X", &bcr); printf ("\n\nBCR value entered was 0x%x. Send it out? (y/n):\n", bcr); scanf ("%c", &yn); scanf ("%c", &yn); if((yn == 'y') || (yn == 'Y')) { printf (" Sending it out\n"); dat.ulg[0] = bcr ; wrtbcr() ; } else printf ("yn is %x, %c\n", yn,yn) ; printf("\n\n"); getchar() ; break ; case MENU15: /* --------------------------- */ dsp_Sunbfr() ; printf("\n\n"); getchar() ; break ; case MENU16: /* -------------------------- */ if (openflag != OK) goto U8EXIT ; /*quit if device not connected */ dmawrtdchan() ; printf("\nPhysio() stopped!\n"); printf("\n\n"); getchar() ; break ; case MENU17: /* ---------------- Transmit data ---------- */ fillbfr(ZEROSPTN) ; numflag = 0; printf ("\nDo you want to enter a specific number to transmit? (y/n):\n"); scanf ("%c", &yn); scanf ("%c", &yn); if((yn == 'y') || (yn == 'Y')) { numflag = 1; printf ("\nEnter the number you wish to transmit (hex):\n "); scanf ("%X", &bcr); printf ("\n\nNumber entered was 0x%x\n", bcr); } else if ((yn == 'n') || (yn == 'N')) bcr = 0; else goto U8EXIT; U17CONT: printf ("\nEnter the number of bytes to transmit (4 to fc) (hex):\n "); scanf ("%X", &numbytes); if (numbytes == 0) { printf("\n\nOK. No data will be sent!\n") ; goto U8EXIT ; } if ((numbytes < 0x4) || (numbytes > 0xfc)) { printf("\n\nNumber must be between 4 and fc (inclusive)! Try again!\n") ; goto U17CONT ; } if ((numbytes%4) != 0) { printf("\n\nNumber must be multiple of 4 for word size only! Try again!\n") ; goto U17CONT ; } printf ("\n\nNumber of bytes entered was 0x%x. Continue? (y/n):\n", numbytes); scanf ("%c", &yn); scanf ("%c", &yn); if((yn == 'y') || (yn == 'Y')) { csr = 0x00000180 ; dat.ulg[0] = csr ; wrtcsr() ; csr = 0x00000000 ; dat.ulg[0] = csr ; wrtcsr() ; num = 0 ; cnt = (numbytes/4) ; byteshft = numbytes ; byteshft <<= 16 ; xwrtdmaunu = (byteshft | WRTDMAUNU) ; for (i=0 ; i 2)) { printf("\n\nNumber must be between 0 and 2 (inclusive)! Try again!\n"); goto U18CONT; } printf("\n\nNumber entered was 0x%x. Send it out? (y/n):\n", bcr); scanf ("%c", &yn); scanf ("%c", &yn); if((yn == 'y') || (yn == 'Y')) { dat.ulg[0] = bcr ; wrtdmaww() ; if (openflag != OK) goto U8EXIT ; /*quit if device not connected */ printf("The data was transmitted using DMA ops, as :\n") ; numbytes = 0x4; dsp_Sunbfr() ; numbytes = 0xfc; } else printf ("yn is %x, %c\n", yn,yn) ; printf("\n\n"); getchar(); break ; case MENU19: /* ---------------- Transmit data ---------- */ fillbfr(ZEROSPTN) ; numflag = 0; printf ("\nDo you want to enter a specific number to transmit? (y/n):\n"); scanf ("%c", &yn); scanf ("%c", &yn); if((yn == 'y') || (yn == 'Y')) { numflag = 1; printf ("\nEnter the number you wish to transmit (hex):\n "); scanf ("%X", &bcr); printf ("\n\nNumber entered was 0x%x\n", bcr); } else if ((yn == 'n') || (yn == 'N')) bcr = 0; else goto U8EXIT; U19CONT: printf ("\nEnter the number of bytes to transmit (4 to fc) (hex):\n "); scanf ("%X", &numbytes); if (numbytes == 0) { printf("\n\nOK. No data will be sent!\n") ; goto U8EXIT ; } if ((numbytes < 0x4) || (numbytes > 0xfc)) { printf("\n\nNumber must be between 4 and fc (inclusive)! Try again!\n") ; goto U19CONT ; } if ((numbytes%4) != 0) { printf("\n\nNumber must be multiple of 4 for word size only! Try again!\n") ; goto U19CONT ; } printf ("\n\nNumber of bytes entered was 0x%x. Continue? (y/n):\n", numbytes); scanf ("%c", &yn); scanf ("%c", &yn); if((yn == 'y') || (yn == 'Y')) { csr = 0x00000180 ; dat.ulg[0] = csr ; wrtcsr() ; csr = 0x00000000 ; dat.ulg[0] = csr ; wrtcsr() ; num = 0 ; cnt = (numbytes/4) ; byteshft = numbytes ; byteshft <<= 16 ; xwrtdmaunu = (byteshft | WRTDCHAN) ; for (i=0 ; i