/* --------------------------------------------------------------------------- * VME access test program * * Author : J.B.Lane UCL March 1998 po.c * --------------------------------------------------------------------------- */ #include "ask.h" #include "vme.h" /* default VME BASE ADDRESS is here */ #include "timlet.h" /* for memory_ptr */ #include static unsigned int vmeWindowSize = 0x10000 ; volatile unsigned short *memory_ptr ; volatile unsigned int *memory_D32 ; volatile int scope_loop ; int po (void) ; int main (void) { #ifdef _NT int r ; r = askyn ("Select VME window size MIN ? [MAX]", 'N') ; if (r == ASK_YES) vmeWindowSize = 0x1000 ; #endif (void) tim_vme (vmeWindowSize) ; memory_D32 = (unsigned int *) memory_ptr ; if (memory_ptr != NULL) (void) po () ; else printf ("Error opening VME window\n") ; vme_end () ; return (0) ; } void sigint_handler (int sig) { /* scope_loop flag cleared when Control-C is pressed */ scope_loop = 0 ; printf ("\nExit loop\n") ; } int po (void) { int D32_Mode = ASK_NO ; int Scope_Mode = ASK_NO ; int Scope_Loop = ASK_NO ; int Scope_Zero = ASK_NO ; int Scope_Read = ASK_NO ; int Scope_Mess = ASK_NO ; int bytes, r ; unsigned int last_offset, offset, word, read ; D32_Mode = askyn ("Select D32 mode? [D16]", 'N') ; Scope_Mode = askyn ("Select scope mode option?", 'N') ; if (D32_Mode == ASK_YES) { bytes = sizeof(int) ; if (bytes != 4) printf ("ERROR: D32 is %d bytes\n", bytes) ; } else { bytes = sizeof(short) ; if (bytes != 2) printf ("ERROR: D16 is %d bytes\n", bytes) ; } last_offset = 0 ; for ( ; ; ) { r = ask ("Enter byte address offset", last_offset, &offset) ; r = ask ("Enter write data or CR for read", 0xDEFA, &word) ; printf ("offset 0x%x data 0x%x\n", offset, word) ; if (offset >= vmeWindowSize) /* check = */ { printf ("ERROR: offset exceeds vmeWindowSize %x\n", vmeWindowSize) ; } else last_offset = offset ; offset = offset / bytes ; /* bytes to words */ if (r == ASK_DEFAULT) { printf ("reading...\n") ; if (D32_Mode == ASK_YES) printf ("read %08x\n", memory_D32[offset]) ; else printf ("read %04x\n", memory_ptr[offset]) ; if (Scope_Mode == ASK_YES) { Scope_Loop = askyn ("Begin scope mode loop?", 'N') ; if (Scope_Loop == ASK_YES) { printf ("Exit loop by Control-C\n") ; /* Trap the next Control-C in signal handler * to interrupt the loop without an error */ if (signal (SIGINT, sigint_handler) == SIG_ERR) printf ("signal error\n") ; for (scope_loop = 1 ; scope_loop ; ) { if (D32_Mode == ASK_YES) read = memory_D32[offset] ; else read = memory_ptr[offset] ; } /* Treat the next Control-C in default way (not needed on NT) */ if (signal (SIGINT, SIG_DFL) == SIG_ERR) printf ("signal error\n") ; } } } else { if (D32_Mode == ASK_YES) printf ("write %08x writing...\n", word) ; else printf ("write %04x writing...\n", word) ; if (D32_Mode == ASK_YES) memory_D32[offset] = word ; else memory_ptr[offset] = word & 0xFFFF ; if (Scope_Mode == ASK_YES) { Scope_Loop = askyn ("Begin scope mode loop?", 'N') ; if (Scope_Loop == ASK_YES) { Scope_Zero = askyn ("Zero register each loop?", 'N') ; Scope_Read = askyn ("Read register each loop?", 'N') ; if (Scope_Read == ASK_YES) { Scope_Mess = askyn ("Error message each loop?", 'N') ; if (D32_Mode == ASK_YES) printf ("read %08x\n", memory_D32[offset]) ; else printf ("read %04x\n", memory_ptr[offset]) ; } printf ("Exit loop by Control-C\n") ; /* Trap the next Control-C in signal handler * to interrupt the loop without an error */ if (signal (SIGINT, sigint_handler) == SIG_ERR) printf ("signal error\n") ; for (scope_loop = 1 ; scope_loop ; ) { if (Scope_Zero == ASK_YES) { if (D32_Mode == ASK_YES) memory_D32[offset] = 0 ; else memory_ptr[offset] = 0 ; } if (D32_Mode == ASK_YES) memory_D32[offset] = word ; else memory_ptr[offset] = word & 0xFFFF ; if (Scope_Read == ASK_YES) { if (D32_Mode == ASK_YES) read = memory_D32[offset] ; else read = memory_ptr[offset] ; if (Scope_Mess == ASK_YES && read != word) { if (D32_Mode == ASK_YES) printf ("read %08x wrote %08x\n", read, word) ; else printf ("read %04x wrote %04x\n", read, word) ; } } } /* Treat the next Control-C in default way (not needed on NT) */ if (signal (SIGINT, SIG_DFL) == SIG_ERR) printf ("signal error\n") ; } } } } return (0) ; }