/* lv.c started from analog_spy.c March 2000 HvH This program is to address the control lines the LV distribution boards. http://p25ext.lanl.gov/phenix/mvd/ancillary/logic/logic.html for the pin assignments (I/O module 2, connector A, pin pair 1-24, B: pin 1-8) Note that on the LV dist modules, the top pin pair controls the bottom LV cable, and the bottom pin pair controls the top LV cable. The middle pin is unused. This program is compiled with cc68k -c -O -DCPU=MC68020 -I$VX_VW_BASE/h lv.c ld #include #include #include #include "taskLib.h" STATUS lv() { #define BASE 0xffff6000 int iomodule, iabcd, ipin, index, idata; int ilv[5][9]; /* mb 1-4, igrp 1-8 */ int go_on, lok; int imb, igrp; int ieast_west, ibit; char command[50],atmp[50],view[5]; int bit_out, readback; int status; unsigned int *data; /*----------------------------------------------------------------------------*/ imb = 0; iomodule = 2; iabcd = 1; ipin = 1; go_on = 1 ; strcpy(command , "help"); while(go_on){ if ( strstr(command, "help") | strstr(command,"menu") ) { printf(" +---------------------------------------------------+ | mb n choose mother board n (n=1-4) | | on/off m turn group m on/off (m=1-8) | | view mvd/crate changes display of 'show' | | show show current status | | exit, quit,x,q exit the program | +---------------------------------------------------+ "); } else if (strstr(command,"view")) { sscanf(command,"%s %s",atmp,view); if (strstr(view,"mvd")){ printf(" mvd view \n"); } else if (strstr(view,"crate")){ printf(" crate view \n"); } else printf(" 'view mvd' shows LV by motherboard, group \n" " 'view crate shows LV on the front of the distribution crate \n" " current view is: %s", view ); } else if ( strstr(command,"mb") ) { sscanf(command,"%s %d",atmp,&imb); if (imb>0 && imb<5) { printf(" will do mother board #%d \n",imb); } else { printf("\n mb must be between 1 and 4 \n"); } } else if ( strstr(command,"on") | strstr(command,"off") ) { sscanf(command,"%s %d",atmp,&igrp); if (imb>0 && imb<5 && igrp>0 && igrp<9) { if (strstr(command,"on") ) { ibit = -1; } else { ibit = 1; } printf(" will turn on mb #%d group %d \n",imb,igrp); index = (imb-1)*8 + igrp; if (index<25){ iabcd = 1; ipin = index; } else { iabcd = 2; ipin = index-24; } relay_write(iomodule,iabcd,ipin,ibit); /* set the bit */ strcpy(command,"show"); /* force a 'show' */ } /* end all OK */ else if (imb<1 | imb>4) { printf("\n mb out of range, should be 1-4 \n"); } else { printf("\n group out of range, should be 1-8 \n"); } } /* end onn/off */ else if (strstr(command,"show")){ strcpy(command,"xxxxx"); /* prevent inf loop */ io_read(iomodule,1,&idata); printf("\n connector A: "); for (ibit=1; ibit<=8; ibit++){ /* for MB 1 */ index = idata & 0x1; printf("%d",index); idata = idata >> 1; ilv[1][ibit] = 1-index; } for (ibit=9; ibit<=16; ibit++){ /* for MB 2 */ index = idata & 0x1; printf("%d",index); idata = idata >> 1; ilv[2][ibit-8] = 1-index; } for (ibit=17; ibit<=24; ibit++){ /* for MB 3 */ index = idata & 0x1; printf("%d",index); idata = idata >> 1; ilv[3][ibit-16] = 1-index; } io_read(iomodule,2,&idata); /* for MB 4 */ printf("\n connector B: "); for (ibit=1; ibit<=8; ibit++){ index = idata & 0x1; printf("%d",index); idata = idata >> 1; ilv[4][ibit] = 1-index; } if (strstr(view,"mvd")){ /* display MVD view */ printf("\n\n MB1 MB2 MB3 MB4 \n" "--------------------------------\n"); printf(" group 1 IT %d %d %d %d \n", ilv[1][1], ilv[2][1], ilv[3][1], ilv[4][1]); printf(" group 2 IM %d %d %d %d \n", ilv[1][2], ilv[2][2], ilv[3][2], ilv[4][2]); printf(" group 3 IB %d %d %d %d \n", ilv[1][3], ilv[2][3], ilv[3][3], ilv[4][3]); printf(" group 4 OB %d %d %d %d \n", ilv[1][4], ilv[2][4], ilv[3][4], ilv[4][4]); printf(" group 5 OM %d %d %d %d \n", ilv[1][5], ilv[2][5], ilv[3][5], ilv[4][5]); printf(" group 6 OT %d %d %d %d \n", ilv[1][6], ilv[2][6], ilv[3][6], ilv[4][6]); printf(" group 7 PAD %d %d %d %d \n", ilv[1][7], ilv[2][7], ilv[3][7], ilv[4][7]); printf(" group 8 MB %d %d %d %d \n", ilv[1][8], ilv[2][8], ilv[3][8], ilv[4][8]); } else { /* display crate view */ printf("\n\n" " slot in the distribution board vme crate \n" " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 \n" " --------------- ------------ ------------ ------------ \n" " TOP 1:%d 3:%d 5:%d 7:%d %d %d %d %d %d %d %d %d %d %d %d %d\n", ilv[1][1],ilv[1][3],ilv[1][5],ilv[1][7], ilv[2][1],ilv[2][3],ilv[2][5],ilv[2][7], ilv[3][1],ilv[3][3],ilv[3][5],ilv[3][7], ilv[4][1],ilv[4][3],ilv[4][5],ilv[4][7]); printf( " BOTTOM 2:%d 4:%d 6:%d 8:%d %d %d %d %d %d %d %d %d %d %d %d %d\n", ilv[1][2],ilv[1][4],ilv[1][6],ilv[1][8], ilv[2][2],ilv[2][4],ilv[2][6],ilv[2][8], ilv[3][2],ilv[3][4],ilv[3][6],ilv[3][8], ilv[4][2],ilv[4][4],ilv[4][6],ilv[4][8]); printf( " -------------^- ----------^- ----------^- ----------^- cards present\n" " <-----MB1-----> <---MB2--> <---MB3--> <---MB4--> \n"); } /* end mvd/crate view */ } /* end show */ else if ( strstr(command,"exit") | strstr(command,"x") | strstr(command,"quit") | strstr(command,"q") ) { go_on=0; } else { printf("\n Wrong command - to see menu, type help.\n"); } if (go_on == 1) { printf("\n MVD LV>>"); if (!strstr(command,"show")) gets(command); } } /* end command loop */ printf(" LV done \n"); return(OK); } /*============================================================================*/ int relay_write(int iomodule,int iabcd,int ipin, int ibit) { #define BASE 0xffff6000 int onebit=1, readback, jdebug, data; unsigned int *address; char c; /*-- end declarations --------------------------------------------------------*/ data = 0; if (ibit > 0) data = 1; jdebug=0; /* calculate target address: */ address = (unsigned int *)(BASE + (iomodule-1)*0x1000 + (iabcd -1)*0x100 ); readback = *address; /* read what's there now */ if (ipin >=1 & ipin <= 16) { /* lower word, pin 1-16 */ if (jdebug>=2) printf(" readback 1:%8x \n", readback); onebit = onebit << (16+ipin-1); /* shift mask into place */ readback = readback & ~onebit; /* clear 1-bit space */ if (jdebug>=2) printf(" readback 2:%8x \n", readback); data = data << (16 +ipin-1); /* shift by 16 and ipin */ if (jdebug>=2) printf(" data 3:%8x \n", data); data = data | readback; /* combine old and new */ if (jdebug>=2) printf(" data 4:%8x \n", data); } else if (ipin>=17 && ipin <=24){ /* upper word, pin 17-24 */ if (jdebug>=2) printf(" readback 5:%8x \n", readback); onebit = onebit << (ipin-17); /* shift mask into place */ readback = readback & ~onebit; /* clear 1-bit space */ if (jdebug>=2) printf(" readback 6:%8x \n", readback); data = data << (ipin-17); /* shift by ipin-17 */ if (jdebug>=2) printf(" data 7:%8x \n", readback); data = data | readback; /* combine old and new */ } else { /* ipin=0 means 'all' */ if (data == 0){ data = readback & 0x0000ff00; /* turn 16+8 bits off */ } else { data = readback | 0xffff00ff; /* turn 16+8 bits on */ } } *address = data; /* load the bits */ readback = *address; /* read what's there */ if (jdebug>=2) printf(" readback 8:%8x \n", readback); } /* end vme_write */ /*============================================================================*/ int io_read(int iomodule,int iabcd,int *idata) { /* */ /* This routine passes back a 24-bit word *idata which contains the status */ /* of the pins of module 'iomodule', connector 'iabcd'. */ /* * /* June 2000 Hubert van Hecke */ /*----------------------------------------------------------------------------*/ #define BASE 0xffff6000 int onebit=1, readback, itemp; unsigned int *address; /*-- end declarations --------------------------------------------------------*/ /* calculate target address: */ address = (unsigned int *)(BASE + (iomodule-1)*0x1000 + (iabcd -1)*0x100 ); readback = *address; /* read what's there now */ itemp = readback; /* make a copy */ readback = readback >> 16; /* shift 16 bits to the front */ readback = readback & 0xffff; /* mask off the rest */ itemp = itemp << 16; /* shift first 8 bits to the */ itemp = itemp & 0xff0000; /* back, and mask off the rest*/ readback = readback | itemp; /* combine them again */ *idata = readback; /* copy to output argument */ } /* end io_read */ /*============================================================================*/