/*----------------------------------------------------------------------------- temps.c read mvd internal temperatures and 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 , June 200 hvh compile and load with: cc68k -c -O -DCPU=MC68020 -I$VX_VW_BASE/h temps.c ld #include #include #include #include "vxWorks.h" #include "taskLib.h" STATUS temps(){ int i,j,k,m,n,ichip,ichan,index,imb, invert; int imblo=1; /* starting mb */ int imbhi=1; /* ending mb */ int iomodule, iabcd, ipin; int data,idata,go_on,power; int ival[5][13][8] = { 0*520 }; /* mb 1-4, chip 1-12, chan 0-7 */ 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 sclk_on = 0x01; /* 0000 0001 */ int din_on = 0x02; /* 0000 0010 */ int output_on = 0x0c; /* 0000 1100 */ int nloop = 1; puts("\n ** Mother Board Voltage Monitoring **\n"); puts("\n You can monitor the various voltages \n including +5VD,+5VA,-5VA,+2.5VA and \n temperature sensor output of MCMs,power/comm boards \n and Mother boards using this program.\n"); go_on = 1 ; strcpy(command , "help"); while(go_on){ if ( strstr(command, "read") | strstr(command,"r") | strstr(command, "show") ) { 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 = 1 ; i <=12 ; i++ ) /* clear the output array */ for ( j = 0 ; j <=7 ; j++ ) ival[imb][i][j] = 0; /* puts("\n Start serial communication.\n"); */ data = output_on; /* +5 is passive, enable read */ vme_write(iomodule,iabcd,ipin,data); /*----------------------------------------------------------------------------*/ for ( i = 1; i <= 12 ; i++ ){ /* loop over 12 chips */ ichip = i-1; /* don't mess with loop var. */ ichip = ichip << 4 ; /* now shift them to bits 5-8 */ data = output_on; /* +5 is passive, enable read */ data = data | ichip; /* set the cs bar line using A0 - A3 */ /* write the address (=csbar) */ vme_write(iomodule,iabcd,ipin,data); waits(nloop); for ( ichan = 0; ichan <=7 ; ichan++ ){ /* loop over 8 chan */ for ( j = 0 ; j < 3 ; j++ ) icontrol[j+1] = jcontrol[ichan][j]; /* clock out the 8 control bits */ for ( k = 0 ; k < 8 ; k++ ){ if ( icontrol[k] == 0 ) { data = data & ~din_on; vme_write(iomodule,iabcd,ipin,data); } else if ( icontrol[k] == 1 ) { data = data | din_on; vme_write(iomodule,iabcd,ipin,data); } data = data | sclk_on; vme_write(iomodule,iabcd,ipin,data); waits(nloop); data = data & ~sclk_on; } /* end loop over control bits */ data = data & ~din_on; /* din; off, sclk; off i*/ data = data & ~sclk_on; /* din; off, sclk; off i*/ vme_write(iomodule,iabcd,ipin,data); waits(nloop); /*clock 12 data bits out: */ for ( j = 0 ; j < 12 ; j++) { data = data & ~sclk_on; vme_write(iomodule,iabcd,ipin,data); data = data | sclk_on; vme_write(iomodule,iabcd,ipin,data); waits(nloop); vme_read(iomodule,iabcd,&idata); idata = (idata>>2) &1; /* fish out bit 3 */ index = 11 - j; k = 0; power = 1; while ( k < index ) { power = power << 1; k = k + 1; } ival[imb][i][ichan] = ival[imb][i][ichan] + idata*power; } /* end loop for 12 return bits */ printf("imb %d ichip %d ichan %d idata% d \n", imb, i, ichan, idata); for ( j = 0 ; j < 4 ; j++ ) { /* wiggle the clock a few */ data = data | sclk_on; /* times for good measure */ vme_write(iomodule,iabcd,ipin,data); waits(nloop); data = data & ~sclk_on; vme_write(iomodule,iabcd,ipin,data); } } /* end loop over 8 channels */ } /* end 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 = 1; i <=12 ; i++ ) { printf(" %4d | %4d %4d %4d %4d %4d %4d %4d %4d\n", i, ival[imb][i][0],ival[imb][i][1],ival[imb][i][2],ival[imb][i][3], ival[imb][i][4],ival[imb][i][5],ival[imb][i][6],ival[imb][i][7]); } /* end print loop */ printf(" ------------------------------------------------------------\n"); } /* end loop over 4 MB's */ /* printf("\n" " +-------------------+------------------------------------+----------------+\n" " | | MCM | |\n" " | group where| 6 5 4 3 2 1 | pads |\n" " -----------+------------------------------------+--------- \n" " 6 OT | - - - - - - | 6 %4d \n", ival[1][10][7]); printf( " 1 IT | %04d %04d %04d - - - | 5 %4d \n", ival[1][6][3],ival[1][6][2],ival[1][6][1], ival[1][10][6]); printf( " WEST 5 OM | - - - - - - | 4 %4d \n", ival[1][10][5]); printf( " (MB1) 2 IM | %04d %04d %04d - - - | 3 %4d \n", ival[1][7][1],ival[1][7][0],ival[1][6][7], ival[1][10][4]); printf( " 4 OB | %04d %04d %04d %04d %04d - | 2 %4d \n", ival[1][8][5],ival[1][8][4],ival[1][8][3],ival[1][8][2],ival[1][8][1], ival[1][10][3]); printf( " 3 IB | %04d %04d %04d %04d %04d - | 1 %4d \n", ival[1][7][7],ival[1][7][6],ival[1][7][5],ival[1][7][4],ival[1][7][3], ival[1][10][2]); printf( " \n" " 3 IB | %04d %04d %04d %04d - - | 1 %4d \n", ival[2][7][7],ival[2][7][6],ival[2][7][5],ival[2][7][4], ival[2][10][2]); printf( " 4 OB | %04d %04d %04d %04d - - | 2 %4d \n", ival[2][8][5],ival[2][8][4],ival[2][8][3],ival[2][8][2], ival[2][10][3]); printf( " 2 IM | %04d %04d %04d - - - | 3 %4d \n", ival[2][7][1],ival[2][7][0],ival[2][6][7], ival[2][10][4]); printf( " EAST 5 OM | - - - - - - | 4 %4d \n", ival[2][10][5]); printf( " (MB2) 1 IT | %04d %04d - - - - | 5 %4d \n", ival[2][6][3],ival[2][6][2], ival[2][10][6]); printf( " 6 OT | - - - - - - | 6 %4d \n", ival[2][10][7]); printf( " ------------+------------------------------------+--------- \n" " group where| 6 5 4 3 2 1 | pads \n"); */ } /* end of '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,"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, int,ext).\n"); } if (go_on == 1) { printf("\n MVD temps>>"); gets(command); } } /* while loop closed */ return(OK); } /*============================================================================*/ int vme_write(int iomodule,int iabcd,int ipin,int data) { /*--------------------------------------------------------------------------*/ /* This one does the write-part of the relay board controls. */ /*-------------------------------------------------------------------*/ #define BASE 0xffff6000 int eightbits, readback, index, ibit, itemp; unsigned int *address; char c; /* see http://p25ext.lanl.gov/phenix/mvd/ancillary/logic/logic.html: */ /* int dout_mask[2][4] = { {0xc000c0, 0x00c000, 0xc000c0, 0xa0} , {0xb0, 0xc0, 0xd0, 0xe0} };*/ int dout_mask[2][4] = { {0x000000, 0x000000, 0x000000, 0x00} , {0x00, 0x00, 0x00, 0x00} }; /*-- end declarations --------------------------------------------------------*/ address = (unsigned int *)(BASE + (iomodule-1)*0x1000 + (iabcd -1)*0x100 ); readback = *address; /* read what's there now, and */ /*printf(" 1: readback %8x \n", readback);*/ itemp = readback; /* unshuffle bytes cdab->abcd */ readback = readback >> 16; /* shift 16 bits to the front */ readback = readback & 0x0000ffff; /* 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 halves again */ readback = readback | dout_mask[iomodule-1][iabcd-1]; /*printf(" 2: swapped %8x \n", readback);*/ /* safeguard output lines */ eightbits = 0x00ff; /* 8-bit mask for data */ eightbits = eightbits << (ipin-1); /* shift mask into place */ readback = readback & ~eightbits; /* clear 8-bit space */ /*printf(" 3: 10b mask %8x \n", readback);*/ /*printf(" 4: data %8x \n", data);*/ data = data & 0x00000003ff; /* only 10 bits, mask rest */ data = data << (ipin-1); /* shift to ipin */ /*printf(" 4: msk+shft %8x \n", data);*/ data = data | readback; /* combine old and new */ /*printf(" 5: data+rdb %8x \n", data);*/ /* itemp = data; printf(" on C: (1-24) "); for (ibit=1; ibit<=24; ibit++){ index = data & 0x1; printf("%d",index); data = data >> 1; } data = itemp; */ itemp = data; /* reshuffle bytes abcd->cdab */ data = data << 16; /* shift 16 bits to the back */ data = data & 0xffff0000; /* mask off the rest */ itemp = itemp >> 16; /* shift 8 bits to the front, */ itemp = itemp & 0x000000ff; /* and mask off the rest */ data = data | itemp; /* combine them again */ /*printf(" 6: reswap'd %8x \n", data);*/ *address = data; /* load the bits */ /* printf(" (end of write) ready? "); while ((c = getchar()) != '\n') { } */ } /* end relay_write */ /*============================================================================*/ int vme_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; char c; /*-- end declarations --------------------------------------------------------*/ /* calculate target address: */ address = (unsigned int *)(BASE + (iomodule-1)*0x1000 + (iabcd -1)*0x100 ); address = address + 1; /* 'direct read' see pgs 3,15 */ 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 */ /*printf("readback: %4x \n",readback); printf(" (end of read) ready? "); while ((c = getchar()) != '\n') { } */ } /* end io_read */ /*============================================================================*/ STATUS waits(int nloop) { /* This subroutine is used to waste computer time! */ /* This is needed because when the program sends commands */ /* to the xilink chips too quickly, the code fails to load */ /* properly. This code was written to waste enough time */ /* between commands to make sure the code loads properly. */ /* JPSullivan, 30 Oct 1997 */ int i; /* counter for loop up to nloop */ int j; /* counter for loop up to mloop */ int k; /* dummy variable */ int mloop=2; /* maximum on internal loop */ /* There are two loops here, the outer loop is done nloop */ /* times where nloop is the arguement of this routine. */ /* The inner loop is done mloop times, where mloop is an */ /* internal variable in this routine. */ for ( i=0 ; i < nloop ; i++ ) { for ( j=0 ; j < mloop ; j++ ) { k=1; } } return (OK); }