/* lv_mon.c started from lv.c January 2003 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: make -f lv_mon.makefile load with ld #include #include #include #include "taskLib.h" STATUS lv_mon(int imb, int igrp, int ibit) { /* imb = motherboard, 1-4 igrp = group, 1-6, 7=pads, 8=mb, 0=all ibit = -1=on, +1=off */ #define BASE 0xffff6000 int iomodule, iabcd, ipin, index, idata, ibit_input; int ilv[5][9]; /* mb 1-4, igrp 1-8 */ int bit_out, readback; int status; unsigned int *data; /*----------------------------------------------------------------------------*/ iomodule = 2; iabcd = 1; ipin = 1; ibit_input = ibit; if (imb>0 && imb<5 && igrp>0 && igrp>0 && igrp>0 && igrp<9) { 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 */ } /* end all OK for grp 1-8 */ else if (imb>0 && imb<5 && igrp == 0){ /* all groups on */ index = (imb-1)*8 + 8; if (index<25){ iabcd = 1; } else { iabcd = 2; index = index-24; } for (ipin = index-7; ipin <= index; ipin++){ relay_write(iomodule,iabcd,ipin,ibit); /* set the bits */ } } /* end onn/off */ 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; } printf(" 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]); printf(" arguments seen mb: %d group: %d bit: %d\n",imb,igrp,ibit_input); return(OK); } /* end of lv_mon */ /*============================================================================*/ 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 */ /*============================================================================*/