/*----------------------------------------------------------------------------- temps_mon.c This is a stripped-down version of temps.c, which only does a read of the adc's and returns the raw values to STDOUT 12 Feb 2003 Hubert an Hecke read mvd internal temperatures and voltages. This version uses the VME Industry Packs for I/O. Started with /vme/temps.c June, 1998, YG.KIM, April 3 2000 HvH , Feb 3 2001 HvH 20-Nov-2002 setup to work on phoncs0 (i.e. change file names in open statements and comments (JPSullivan). If we have this cross compiler on phenix14, I do not know where it is. It can be compiled on phenix14. Feb 2003: replace these commands 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_mon(){ int i,j,k,m,n,ichip,ichan,index,imb, invert; int imblo=1; /* starting mb */ int imbhi=4; /* ending mb */ int iomodule, iabcd, ipin, ipin_read, ibit; int data,idata,go_on,power; int ival[5][13][8] = { 0*520 }; /* mb 1-4, chip 1-12, chan 0-7 */ int jval[5][8][8] = { 0*320 }; /* mb 1-4, group 1-7, chip 1-6 */ 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} }; int igrp, imcm; 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; int idummy; int ilo[5][8][8], ihi[5][8][8]; /* upper and lower limits */ int jgrp[7] = {0,3,4,2,5,1,6}; /* display ordering */ char *ib[7] = {"00","IB","OB","IM","OM","IT","OT"}; /*-------------------------------------------------------------------*/ 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; } ipin_read = ipin +2; 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 */ io_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) */ io_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]; for ( k = 0 ; k < 8 ; k++ ){ /* clock out the 8 control bits */ if ( icontrol[k] == 0 ) { data = data & ~din_on; io_write(iomodule,iabcd,ipin,data); } else if ( icontrol[k] == 1 ) { data = data | din_on; io_write(iomodule,iabcd,ipin,data); } data = data | sclk_on; io_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*/ io_write(iomodule,iabcd,ipin,data); waits(nloop); /*clock 12 data bits out: */ for ( j = 0 ; j < 12 ; j++) { data = data & ~sclk_on; io_write(iomodule,iabcd,ipin,data); data = data | sclk_on; io_write(iomodule,iabcd,ipin,data); waits(nloop); io_read(iomodule,iabcd,ipin_read,&ibit); index = 11 - j; k = 0; power = 1; while ( k < index ) { power = power << 1; k = k + 1; } ival[imb][i][ichan] = ival[imb][i][ichan] + ibit*power; } /* end loop 12 return bits */ for ( j = 0 ; j < 4 ; j++ ) { /* wiggle the clock a few */ data = data | sclk_on; /* times for good measure */ io_write(iomodule,iabcd,ipin,data); waits(nloop); data = data & ~sclk_on; io_write(iomodule,iabcd,ipin,data); } /* end wiggle */ } /* end loop over 8 channels */ } /* end loop over 12 ADC chips */ } /* end loop over 4 MB's */ /* now translate to mb, group and chip ------------------------------*/ for (imb=imblo; imb<=imbhi; imb++){ for (i=1; i<=42; i++){ igrp = (i-1) / 6 + 1; /* mcms cycle in groups of 6 */ imcm = (i-1) % 6 + 1; /* starting at 1,1 */ ichip = (i+5) / 8 + 5; /* adcs cycle in groups of 8 */ ichan = (i+5) % 8 ; /* starting at U5, ch6 */ jval[imb][igrp][imcm] = ival[imb][ichip][ichan]; /* copy */ } /* loop over 6x7 mcms */ } /* loop over mb=1-4 */ /* now display: -----------------------------------------------------*/ for (imb=imblo; imb<=imbhi; imb++) { /* loop over 4 mother boards */ 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 print loop 4 MB's */ return(OK); } /*============================================================================*/ 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); } /*=======================================================================*/ int io_write(int iomodule,int iabcd,int ipin,int data) { /*--------------------------------------------------------------------------*/ /* This one does the write-part of the ADC protocol. 8 bits are written, */ /* - 4 bits to address a particular chip */ /* - a serial clock */ /* - serial data */ /* two additional bits return SSTRB and DOUT, and are safeguarded in */ /* the calling program by being set high, and also in this routine. */ /*-------------------------------------------------------------------*/ #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} }; /*-- end declarations --------------------------------------------------------*/ waits(5); address = (unsigned int *)(BASE + (iomodule-1)*0x1000 + (iabcd -1)*0x100 ); readback = *address; /* read what's there now, and */ 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]; /* safeguard output lines */ eightbits = 0x000000ff; /* 8-bit mask where data goes */ eightbits = eightbits << (ipin-1); /* shift mask into place */ readback = readback & ~eightbits; /* clear 8-bit space */ data = data & 0x00000000ff; /* only 8 bits, mask rest */ data = data << (ipin-1); /* shift to ipin */ data = data | readback; /* combine old and new */ /* 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 */ *address = data; /* load the bits */ /* printf(" (end of write) ready? "); while ((c = getchar()) != '\n') { } */ } /* end io_write */ /*============================================================================*/ int io_read(int iomodule,int iabcd,int ipin, int *ibit) { /*----------------------------------------------------------------------------*/ /* Do a 'direct read' of one bit from a given connector. This is done from */ /* a word in memory 1 higher than where you do a 'write'. Also, for this */ /* work, the bit in the 'write' register must be kept high (=passive). */ /* June 2000 Hubert van Hecke LANL */ /*-----------------------------------------------------------------------*/ #define BASE 0xffff6000 int readback, itemp; unsigned int *address; /*-- end declarations --------------------------------------------------------*/ waits(5); 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 */ readback = readback >> (ipin-1); /* shift bit to position 1 */ readback = readback & 0x1; /* mask off the rest */ *ibit = readback; /* copy to output argument */ } /* end of io_read */ /*============================================================================*/ STATUS window(int ilo[5][8][8], int ihi[5][8][8]){ /*---------------------------------------------------------------------------*/ /* bla */ /* */ /*------------------------------------------------------------------------*/ char mychar; char line[132]; char char_temp; int istart; char aval[] = "xxxx"; int ival; int i,jmcm, ioff; /*int ilo[5][8][8] = { 0*320 }; */ /* mb 1-4, group 1-7, mcm 1-6 */ /*int ihi[5][8][8] = { 0*320 }; */ /* mb 1-4, group 1-7, mcm 1-6 */ int igrp[6] = {6,1,5,2,4,3}; int imb, igroup, imcm, ihilo; FILE *fp1; /* pointer to first file name */ char *filenam1 = "/home/phoncs/mvd/vme/windows.dat"; if (( fp1 = fopen( filenam1,"r")) == NULL ) { printf( "Error opening file, %s!", filenam1); } else { printf( " Opened file %s ...\n", filenam1); } /* Skip the header stuff by looking for the string 'pads' */ while( ( fgets(line, 132, fp1)) != NULL){ istart = strstr(line,"pads"); if (istart != 0) { fgets(line, 132, fp1); /* one more dummy read */ break; } }/* -------------------------------- end find the beginning of the table */ for (i=1; i<=6; i++){ /* loop over 6 pads, 6 strip groups MB2,4 */ fgets(line, 132, fp1); strncpy(aval,line+4,4); /* low limits */ ilo[2][7][7-i] = atoi(aval); /* pads go 6 -> 1 */ for (jmcm=1; jmcm<=6; jmcm++){ /* loop over 6 strip MCMs MB2 */ ioff = 6 + jmcm*5; strncpy(aval,line+ioff,4); ilo[2] [igrp[i-1]] [jmcm] = atoi(aval); } for (jmcm=1; jmcm<=6; jmcm++){ /* loop over 6 strip MCMs MB4 */ ioff = 43 + jmcm*5; strncpy(aval,line+ioff,4); ilo[4] [igrp[i-1]] [7-jmcm] = atoi(aval); } strncpy(aval,line+82,4); /* MB4 pads */ ilo[4][7][7-i] = atoi(aval); /* pads go 6 -> 1 */ fgets(line, 132, fp1); /* now the upper limits, */ strncpy(aval,line+4,4); /* same thing */ ihi[2][7][7-i] = atoi(aval); for (jmcm=1; jmcm<=6; jmcm++){ /* loop over 6 strip MCMs MB2 */ ioff = 6 + jmcm*5; strncpy(aval,line+ioff,4); ihi[2] [igrp[i-1]] [jmcm] = atoi(aval); } for (jmcm=1; jmcm<=6; jmcm++){ /* loop over 6 strip MCMs MB4 */ ioff = 43 + jmcm*5; strncpy(aval,line+ioff,4); ihi[4] [igrp[i-1]] [7-jmcm] = atoi(aval); } strncpy(aval,line+82,4); /* MB4 pads */ ihi[4][7][7-i] = atoi(aval); /* pads go 6 -> 1 */ }/* end loop mb 2 and 4 */ /*------------------------------------------------ now the same for MB1,3 */ fgets(line, 132, fp1); /* reead over the dummy line */ for (i=1; i<=6; i++){ /* loop over 6 pads, 6 strip groups MB2,4 */ fgets(line, 132, fp1); strncpy(aval,line+4,4); /* low limits */ ilo[1][7][i] = atoi(aval); /* pads go 1 -> 6 */ for (jmcm=1; jmcm<=6; jmcm++){ /* loop over 6 strip MCMs MB1 */ ioff = 6 + jmcm*5; strncpy(aval,line+ioff,4); ilo[1] [igrp[6-i]] [jmcm] = atoi(aval); } for (jmcm=1; jmcm<=6; jmcm++){ /* loop over 6 strip MCMs MB3 */ ioff = 43 + jmcm*5; strncpy(aval,line+ioff,4); ilo[3] [igrp[6-i]] [7-jmcm] = atoi(aval); } strncpy(aval,line+82,4); /* MB3 pads */ ilo[3][7][i] = atoi(aval); /* pads go 1 -> 6 */ fgets(line, 132, fp1); /* now the upper limits */ strncpy(aval,line+4,4); ihi[1][7][i] = atoi(aval); for (jmcm=1; jmcm<=6; jmcm++){ /* loop over 6 strip MCMs MB1 */ ioff = 6 + jmcm*5; strncpy(aval,line+ioff,4); ihi[1] [igrp[6-i]] [jmcm] = atoi(aval); } for (jmcm=1; jmcm<=6; jmcm++){ /* loop over 6 strip MCMs MB3 */ ioff = 43 + jmcm*5; strncpy(aval,line+ioff,4); ihi[3] [igrp[6-i]] [7-jmcm] = atoi(aval); } strncpy(aval,line+82,4); /* MB4 pads */ ihi[3][7][i] = atoi(aval); /* pads go 1 -> 6 */ }/* end loop mb 1 and 3 */ printf(" ... Function window done \n"); fclose(fp1); /* close the input file */ } /* end of function window */ /*==========================================================================*/