/*****************************************************************************/ /* $Log: fermi.c,v $ * Revision 1.12 96/06/28 22:26:38 galli * use select() * (synchronous I/O multiplexing) * * Revision 1.11 96/06/28 17:45:17 galli * separate starhist function * * Revision 1.10 96/06/05 16:49:23 galli * write sampling data to fermi.dat file * * Revision 1.9 96/06/04 14:46:31 galli * scale factor * * Revision 1.8 96/06/04 10:57:57 galli * corrected bug in data reading * * Revision 1.7 96/06/03 23:14:45 galli * some aesthetics * * Revision 1.6 96/06/03 21:01:37 galli * print pulse graphic * * Revision 1.5 96/06/03 17:42:03 galli * print read data * * Revision 1.4 96/06/03 15:35:40 galli * some esthetics * * Revision 1.3 96/06/03 15:01:16 galli * this is the 1st version working * * Revision 1.2 96/06/01 09:56:52 galli * shorter syntax * * revision 1.1 96/06/01 09:52:15 galli * Initial revision * */ /*****************************************************************************/ /* compile with: * gcc -m -Wall -I/usr/mizzi -o fermi fermi.c /usr/mizzi/vme.a * * The function: vmea24d16init() [in the library vme.a], * and the macro: vmea24d16() [in the header vme.h], * are part of MIZZI VME library. */ /*****************************************************************************/ #include <stdio.h> #include <time.h> #include <limits.h> #include "vme.h" #define NSAM (vmeword)80 #define DELAYREG (vmeword)10 #define NROW 21 #define EXIT_SUCCESS 0 #define EXIT_FAILURE 1 /**** global variables *******************************************************/ vmeword *adc; vmeaddress vme_adr=0xb40010; vmeaddress vme_len=0xc; /**** function prototype *****************************************************/ void starhist(int *datum); /**** start code *************************************************************/ int main(int argc,char **argv) { unsigned long count,count_max=ULONG_MAX; int busy,dataready,i,iadc,status; int dummy,datum[NSAM]; char ch; char *out_file="/dev/null"; FILE *out; char *line="---------------------------------------------------------------"; fd_set readfds; struct timeval tv; extern char *optarg; int flag; /* Wait up to 1000 microseconds. */ tv.tv_sec = 0; tv.tv_usec = 1000; while((flag=getopt(argc,argv,"hf:n:"))!=EOF) { switch(flag) { case 'f': out_file=optarg; break; case 'n': count_max=atol(optarg); break; case 'h': printf("\nUsage: fermi [-n number_of_pulse] [-f output_file]\n\n"); exit(EXIT_SUCCESS); default: printf("\nunrecognized option\n") ; printf("\nUsage: fermi [-n number_of_pulse] [-f output_file]\n\n"); exit(EXIT_FAILURE); } } printf("\n\n\n\n\n"); printf("%s\n",line); printf("Output file = %s\n",out_file); printf("Number of pulse to be digitalized = %u\n",count_max); if(!(out=fopen(out_file,"w"))) { printf("error opening file output file"); exit(EXIT_FAILURE); } if(!(adc=vmea24d16init(vme_adr,vme_len))) { printf("error initializing VME bus"); exit(EXIT_FAILURE); } printf("%s\n",line); printf("address for init \t %x\n",vme_adr); printf("length for init \t %x\n",vme_len); printf("return adress pointer\t %x\n",(int)adc); printf("%s\n",line); printf("\n\n\nDAQ started:\n"); printf("Press <return> to print another pulse\n",count); printf("Press <q><return> to stop\n"); iadc=0; /* select channel to be read */ vmea24d16(adc+8)=NSAM; /* set the number of sampling stored in FIFO */ vmea24d16(adc+7)=DELAYREG; /* set the number of wait clock after trigger */ for(count=0;count<count_max;count++) { vmea24d16(adc+10)=(vmeword)0; /* clear the BUSY & DATAREADY bits */ for(i=1;;i++) { status=(vmea24d16(adc+9)); /* read the STATUS register */ busy=status & 0x2; /* find the BUSY bit */ dataready=status & 0x4; /* find the DATAREADY bit */ /*printf("check n. %d\tstatus = %x\tdataready = %x\tbusy = %x\n", i,status,dataready,busy);*/ if(dataready==0x4) break; } dummy=vmea24d16(adc+iadc); for(i=1;i<NSAM;i++) { datum[i]=vmea24d16(adc+iadc) & 0x3ff; /* read channel iadc+1 */ /* print pulse sampling */ fprintf(out,"%3d\t%4d\n",i,datum[i]); } FD_ZERO(&readfds); FD_SET(0,&readfds); if (select(1,&readfds,NULL,NULL,&tv)) { ch=getchar(); if(ch=='\n') { fflush(stdin); /* print pulse graphics */ starhist(datum); printf("Pulse n. %10u. Press <return> to print another pulse\n",count); printf(" Press <q><return> to stop\n"); } else { while(getchar()!='\n'); if(toupper(ch)=='Q') { close(out); exit(EXIT_SUCCESS); } } } } } /**** print histogram ********************************************************/ void starhist(int *datum) { int irow,icol; float cutlo,cuthi; char character; printf("\n"); for(irow=0;irow<NROW;irow++) { cuthi=512./(NROW-1)*(NROW-irow); cutlo=512./(NROW-1)*(NROW-irow-1); for(icol=0;icol<NSAM;icol++) { if(datum[icol]>=cutlo && datum[icol]<cuthi)character='*'; else character='.'; if(irow==(NROW-1)) { if(datum[icol]<cutlo)character='v'; } if(irow==0) { if(datum[icol]>=cuthi)character='^'; } printf("%c",character); } printf("\n"); } } /*****************************************************************************/