//****************************************************************** // vxworks example: // >install_board (0x18000000) // >start_loop (0,0) board 0, setup 0 // >end_loop // // >start_loopall (1,0) setup 1, all boards 0 versus first n boards // >end_loopall //****************************************************************** #include #include #include #include #include #include #include #include #include "ecdr814gcDrv.h" #define DEBUG(x) printf(#x"\n");x; #define DUMPU32(x) printf(#x" 0x%08X 0x%08X %ld\n",(unsigned)&x,x,x) #define DUMPL(x) printf(#x" 0x%08X 0x%08X %ld\n",(unsigned)&x,(unsigned)x,x) #define N_CHANNELS 8 long* dataBuffer[N_CHANNELS*12]; volatile int display_tag; static int logDataFlag = FALSE; static int logAllFlag = FALSE; #define DRIVER_NAME "ECDR-814-Brd0" char driver_name[]="ECDR-814-Brd0"; int loopall_brdcnt=0; static long ecdr814fd = (long)NULL; static long bytecount; static long dataMode; static long transferType; static long status; extern "C" { int DemoStart(int brd,int setup); int DemoRead(int board); int DemoStartAll(int setup,int cnt); int DemoReadAll(); int DemoEnd(void); int locate_data(float* intensity, float* position); void analysis(float* position, float* amplitude, float* phase, float* frequency); void set_log(void) { logDataFlag = TRUE; } void set_log_all(void) { logAllFlag = TRUE; } void set_no_log_all(void) { logAllFlag = FALSE; } /* install driver for each board */ void install_board(unsigned bus_address) { unsigned local_address; int ecode; int valid; long contents; STATUS status; valid = sysBusToLocalAdrs(0x0D,(char*)bus_address,(char**)&local_address); ecode = vxMemProbe((char*)local_address,VX_READ,4,(char*)&contents); printf("Bus Address:0x%08X; Local Address:0x%08X valid:%d vxMemProbe:%d\n", bus_address,local_address,valid,ecode); sprintf (&driver_name[0],"ECDR-814-Brd%d",loopall_brdcnt); status=ecdr814gcInstall(&driver_name[0],bus_address); printf ("\r\n ecdr814gcInstall status=%d",status); if((ecdr814fd = open(&driver_name[0], O_RDONLY, 0)) == -1) { printf("ECDR-814 could not be opened"); return; } else { DEBUG(/* Driver Opened*/); } printf("fd=%ld\n",ecdr814fd); loopall_brdcnt++; } /* utility to search for possible boards */ void locate_board(void) { unsigned bus_address; unsigned local_address; int ecode; int valid; long contents; for (bus_address = 0x08000000;bus_address < 0x30000000; bus_address += 0x01000000) { valid= sysBusToLocalAdrs(0x0D,(char*)bus_address,(char**)&local_address); ecode = vxMemProbe((char*)local_address,VX_READ,4,(char*)&contents); if (valid == 0 && ecode == 0) { printf("Candidate Board @Bus Address:0x%08X; Local Address:0x%08X \n, bus_address,local_address); } } } /* write file of results for analysis on pc */ void dump_ddcdata(char* filename,long int bytecount) { int file; int nbytes; printf("DUMPLng %ld bytes of DDC data to %s\n",bytecount,filename); file = open(filename,O_CREAT|O_WRONLY,0777); nbytes = write(file,(char*)dataBuffer,bytecount); close(file); return; } // test a single board /* main - spawned task to generate the data */ static int loop_continue; void loop_function(int brd, int setup) { long bytecount; long dataCount = 0; char logfilename[256]; printf("\nData loop starting\n"); DEBUG(DemoStart(brd,setup);); /* initialize board */ loop_continue = TRUE; while(loop_continue) { DEBUG(bytecount = DemoRead(brd);); /* setup acquisition and read */ DUMPL(bytecount); dataCount++; printf("Data Block %ld \n",dataCount); if ( logDataFlag || logAllFlag ) { sprintf(logfilename,"/write/bltdata_%ld.dat",dataCount); dump_ddcdata(logfilename,bytecount); printf("Logging data to %s\n",logfilename); logDataFlag = FALSE; } taskDelay(60*4); } printf("\nData loop ended\n"); } /* start the single board data acquisition with assigned board setup */ void start_loop(int brd,int setup) { sp((FUNCPTR)loop_function,brd,setup,0,0,0,0,0,0,0); } /* stop the single board data acquisition */ void end_loop(void) { loop_continue = FALSE; } /* initialize the board and the setups for the board */ int DemoStart(int brd,int setup) { int dataBufferSize = (4*128*1024+1); int i; int j; DEBUG(bytecount = 0;) ecdr814gcInitSetup(); ecdr814gcReadSetup("warren.ini", 0); ecdr814gcReadSetup("wsxlstest.ini", 1); ecdr814gcReadSetup("rawDmaD64.ini", 2); ecdr814gcReadSetup("2.5MHz_cbcar_pbcar.ini", 3); for (i = ECDR814_SET_BUFFER_0,j=0; i<=ECDR814_SET_BUFFER_7; i++,j++) { dataBuffer[j] = (long*)memalign(256,dataBufferSize*sizeof(long)); ecdr814gcSetBufferBrd(brd,i,(long)dataBuffer[j]); } ecdr814gcCopySetupBrd(brd, setup); ecdr814gcProgramGrayBrd(brd); bytecount=ecdr814gcGetByteCountBrd(brd); DUMPL(bytecount); transferType=ecdr814gcGetTransferTypeBrd(brd); DUMPL(transferType); dataMode=ecdr814gcGetDataModeBrd(brd,0); DUMPL(dataMode); ecdr814gcIoctlClearBrd (brd); return 0; } /* setup the acquisition and read a single board */ int DemoRead(int board) { long int poll = 0; long num_trigs = 1; bytecount=ecdr814gcGetByteCountBrd(board); DUMPL(bytecount); bytecount = bytecount>>2; ecdr814gcSetNumTrigsBrd(board,(long)num_trigs); DUMPL(num_trigs); printf ("\r\n bytecount=%ld, num_trigs=%ld, total bytes=%ld", bytecount,num_trigs,bytecount*num_trigs); DEBUG( status = ecdr814gcRdSetupBrd(board, &poll, bytecount*num_trigs); ) DEBUG( status = ecdr814gcReadBrd(board, &poll, bytecount*num_trigs,WAIT_FOREVER); ) if (status == EC_ERROR) { bytecount = 0; printf("Error reading ECDR-814\n"); } DUMPL(bytecount); return bytecount; } /* closes the driver */ int DemoEnd(void) { DEBUG(close(ecdr814fd);) ecdr814fd = (long)NULL; return 0; } //similar test as above except test all boards /* main - spawned task to generate the data */ static int loopall_continue; void loopall_function(int setup,int cnt) { long bytecount; long dataCount = 0; int i; printf("\nData loop starting\n"); for (i=0;i>2; ecdr814gcSetNumTrigsAll((long)num_trigs); status = ecdr814gcRdSetupAll(&poll, bytecount*num_trigs); status = ecdr814gcReadAll(&poll, bytecount*num_trigs,WAIT_FOREVER); if (status == EC_ERROR) { bytecount = 0; printf("Error reading ECDR-814\n"); } return bytecount; } }