/*----------------------------------------------------------------------------- mbv_vme.c Multiplexed serial readout of the Mother Board voltages. This version uses the VME Industry Packs for I/O. Started with /camac/mbvolt_mon.c. June, 1998, YG.KIM, April 3 2000 HvH compile and load with: cc68k -c -O -DCPU=MC68020 -I$VX_VW_BASE/h mbv_vme.c ld #include #include #include #include "vxWorks.h" #include "taskLib.h" STATUS mbv_vme(){ int idebug=0; /* debug switch, default off */ int i,j,k,m,n,ichan,index,imb; int imblo=1; int imbhi=4; int iomodule, iabcd, ipin; int data,ibit,go_on,power; int ival[12][8] = { 0*96 }; int icontrol[8] = { 1,0,0,0,1,1,1,1 }; int jcontrol[8][3] = { {0,0,0}, {1,0,0}, {0,0,1}, {1,0,1}, {0,1,0}, {1,1,0}, {0,1,1}, {1,1,1} }; char c,command[50],atmp[50]; int din_on = 16; /* 010000 */ int sclk_on = 32; /* 100000 */ int both_on = 48; /* 110000 */ int all_off = 0; /* 000000 */ int both_off = 15; /* 001111 */ int sclk_off = 31; /* 011111 */ int data_off =63; /* 111111 */ puts("\n ** Mother Board Voltage Monitoring **\n"); puts("\n You can monitor the variouse voltages including +5VD,+5VA,-5VA,+2.5VA and \n temperature sensor output of MCMs,power/comm boards and Mother boards \n using this program.\n"); puts("\n Press Enter to continue...\n\n\n"); while ((c = getchar()) != '\n') { } puts("\n To read out ADC, type read and press Enter."); puts("\n To quit the monitoring, type exit and press Enter.\n"); puts("\n The default is the external clock mode. You can change the clock mode by typing 'int' or 'ext'. \n"); go_on =1; while(go_on) { printf("\n MUX ADC>>"); gets(command); if ( strstr(command, "read") ) { for (imb=imblo; imb<=imbhi; imb++) { /* loop over 4 mother boards */ if (imb ==1) { iomodule = 1; /* This is the location of the first pin of */ iabcd = 1; /* this functional group on the I/O modules. */ ipin = 1; /* The pin mapping can be found on: */ } /* http://p25ext.lanl.gov/phenix/mvd/ ... */ else if (imb == 2) { iomodule = 1; /* ... /ancillary/logic/logic.html */ iabcd = 1; ipin = 17; } else if (imb == 3) { iomodule = 1; iabcd = 2; ipin = 9; } else if (imb == 4) { iomodule = 1; iabcd = 3; ipin = 1; } for ( i = 0 ; i <12 ; i++ ) /* clear the output array */ for ( j = 0 ; j < 8 ; j++ ) ival[i][j] = 0; puts("\n Start serial communication.\n"); data = all_off; vme_write(iomodule,iabcd,ipin,data,idebug); for ( i = 0; i < 12 ; i++ ){ /* loop over 12 chips */ data = data | i ; vme_write(iomodule,iabcd,ipin,data,idebug); for ( ichan = 0; ichan < 8 ; ichan++ ){ /* loop over 8 channels */ for ( j = 0 ; j < 3 ; j++ ) icontrol[j+1] = jcontrol[ichan][j]; if (idebug == 1) printf("Control word:"); /* for ( j= 0 ; j < 8 ; j++ ) printf("%d ",icontrol[j]); */ /* clock out the 8 control bits */ for ( k = 0 ; k < 8 ; k++ ){ if ( icontrol[k] == 0 ) { data = data & both_off; vme_write(iomodule,iabcd,ipin,data,idebug); } if ( icontrol[k] == 1 ) { data = data | din_on; data = data & sclk_off; vme_write(iomodule,iabcd,ipin,data,idebug); } data = data | sclk_on; vme_write(iomodule,iabcd,ipin,data,idebug); } /* end loop over control bits */ data = data & both_off; /* din; off, sclk; off */ vme_write(iomodule,iabcd,ipin,data,idebug); data = data | sclk_on; vme_write(iomodule,iabcd,ipin,data,idebug); /*clock 12 data bits out: */ if (idebug == 1) printf("\nclock data out; "); for ( j = 0 ; j < 12 ; j++) { data = data & sclk_off; vme_write(iomodule,iabcd,ipin,data,idebug); data = data | sclk_on; vme_write(iomodule,iabcd,ipin,data,idebug); vme_read(iomodule,iabcd,ipin,&ibit,idebug); if ( printf("ibit returned: %d", ibit);*/ ibit = ibit & 0x80; ibit = ibit >>7; index = 11 - j; k = 0; power = 1; while ( k < index ) { power = power << 1; k = k + 1; } /*printf("chip %d, chan %d, power %d, ibit %d,val %d \n", i, ichan, power, ibit, ival[i][ichan]);*/ ival[i][ichan] = ival[i][ichan] + ibit*power; } /* end loop for 12 return bits */ for ( j = 0 ; j < 4 ; j++ ) { data = data | sclk_on; vme_write(iomodule,iabcd,ipin,data,idebug); data = data & sclk_off; vme_write(iomodule,iabcd,ipin,data,idebug); } if (idebug == 1) printf("chip#,chan#,ival : %d %d %d\n", i+1,ichan,ival[i][ichan]); } /* loop over 8 channels */ data = all_off; } /* loop over 12 ADC chips */ printf("\n for mother board #%d:",imb); printf("\n --------------------------------------------------------\n"); printf(" chip# | CH0 CH1 CH2 CH3 CH4 CH5 CH6 CH7\n"); printf(" --------------------------------------------------------\n"); for ( i = 0 ; i < 12 ; i++ ) { printf(" %4d | %4d %4d %4d %4d %4d %4d %4d %4d\n", i+1, ival[i][0],ival[i][1],ival[i][2],ival[i][3], ival[i][4],ival[i][5],ival[i][6],ival[i][7]); } /* end print loop */ printf(" ------------------------------------------------------------\n"); } /* end loop over 4 MB's */ } /* end if 'read' */ else if ( strstr(command, "exit") | strstr(command,"q") ) { go_on = 0; puts("\n Goodbye...\n"); } else if ( strstr(command, "int") ) { puts("\n Set Internal clock mode. \n"); icontrol[7] = 0; } else if ( strstr(command, "ext") ) { puts("\n Set External clock mode. \n"); icontrol[7] = 1; } else if ( strstr(command,"debug") ) { sscanf(command,"%s %d",atmp,&idebug); printf(" idebug (0=off, 1=on): %d \n",idebug); } else if ( strstr(command,"mb") ) { sscanf(command,"%s %d",atmp,&imb); printf(" will do mother board #%d \n",imb); if (imb == 0) { imblo = 1; imbhi = 4; } else if(imb<=4 & imb>=1) { imblo = imb; imbhi = imb; } else { printf(" bad mother board number (1-4, 0=all)"); } } /* end mb command */ else { puts("\n Try other command (read, exit, mb, debug).\n"); } } /* while loop closed */ return(OK); } /*============================================================================*/ int vme_read(int iomodule,int iabcd,int ipin, int *ibit, int idebug) { #define BASE 0xffff6000 int readback, jdebug; unsigned int *address; char c; /*-- end declarations --------------------------------------------------------*/ jdebug=idebug; jdebug=0; if (jdebug==1) { puts("\n read: press enter to continue...\n\n\n"); while ((c = getchar()) != '\n') { } } if (jdebug==1) printf("read iomodule %d,iabcd %d,ipin %d,data(hex) %x\n", iomodule, iabcd, ipin); address = (unsigned int *)(BASE + (iomodule-1)*0x1000 + (iabcd -1)*0x100 ); if (ipin <= 16) { /* lower word, pin 1-16 */ readback = *address; /* read what's there */ if (jdebug==1) printf(" readback 4 %8x \n", readback); readback = readback >> (16+ipin-1); if (jdebug==1) printf(" readback 3 %8x \n", readback); } else { /* upper word, pin 17-24 */ readback = *address; /* read what's there */ if (jdebug==1) printf(" readback 4 %8x \n", readback); readback = readback >> (ipin-17); if (jdebug==1) printf(" readback 6 %8x \n", readback); } readback = readback & 0x000000ff; *ibit = readback; } /* end vme_read */ /*============================================================================*/ int vme_write(int iomodule,int iabcd,int ipin,int data, int idebug) { #define BASE 0xffff6000 int sevenbits, readback, jdebug; unsigned int *address; char c; /*-- end declarations --------------------------------------------------------*/ jdebug=idebug; jdebug = 0; if (jdebug==1) { puts("\n write: press enter to continue...\n\n\n"); while ((c = getchar()) != '\n') { } } if (jdebug>=2) printf("write iomodule %d,iabcd %d,ipin %d,data(hex) %x\n", iomodule, iabcd, ipin, data); /* calculate target address: */ address = (unsigned int *)(BASE + (iomodule-1)*0x1000 + (iabcd -1)*0x100 ); readback = *address; /* read what's there now */ sevenbits = 0x0000007f; /* 7-bit mask where data goes */ if (ipin <= 16) { /* lower word, pin 1-16 */ if (jdebug>=2) printf(" readback 1:%8x \n", readback); sevenbits = sevenbits << (16+ipin-1); /* shift mask into place */ readback = readback & ~sevenbits; /* clear 7-bit space */ if (jdebug>=2) printf(" readback 2:%8x \n", readback); data = data & 0x000000007f; /* only 7 bits, mask rest */ data = data << (16 +ipin-1); /* shift by 16, and ipin */ if (jdebug>=2) printf(" data 3:%8x \n", readback); data = data | readback; /* combine old and new */ if (jdebug>=2) printf(" data 4:%8x \n", data); } else { /* upper word, pin 17-24 */ if (jdebug>=2) printf(" readback 5:%8x \n", readback); readback = readback & ~sevenbits; /* clear 7-bit space */ if (jdebug>=2) printf(" readback 6:%8x \n", readback); data = data & 0x000000007f; /* only 7 bits, mask rest */ data = data << (ipin-17); /* shift by ipin-17 */ if (jdebug>=2) printf(" data 7:%8x \n", readback); data = data | readback; /* combine old and new */ } *address = data; /* load the bits */ readback = *address; /* read what's there */ if (jdebug>=2) printf(" readback 8:%8x \n", readback); } /* end vme_write */ /*============================================================================*/