#include #include #include #include #include #include #include /* for DEBUGPRINT */ #include #include #include "drvPac.h" #define IPSBAR (0x40000000) /* Default base address for the Edgeport and the Chip Select Module */ /* For the Chip Select Module */ #define CSAR1 (IPSBAR+0x00008C) /* 2 bytes */ #define CSMR1 (IPSBAR+0x000090) /* 4 bytes */ #define CSCR1 (IPSBAR+0x000096) /* 2 bytes */ /* Memory Mapped I/O Registers */ #define PAC_BASE_ADDR (0x80000000) #define IMEM (PAC_BASE_ADDR) /* 2048 signed shorts */ #define QMEM (PAC_BASE_ADDR+0x1000) /* 2048 signed shorts */ #define CTRL_REG (PAC_BASE_ADDR+0x2000) /* 1 unsigned short */ #define DAC_DELAY (PAC_BASE_ADDR+0x2002) /* 1 unsigned short */ #define SSSB_DELAY (PAC_BASE_ADDR+0x2004) /* 1 unsigned short */ #define SSSB_WIDTH (PAC_BASE_ADDR+0x2006) /* 1 unsigned short */ #define EXT_TRIGGER_DELAY (PAC_BASE_ADDR+0x2008) /* 1 unsigned short */ #define EXT_TRIGGER_WIDTH (PAC_BASE_ADDR+0x200A) /* 1 unsigned short */ #define INT_TRIGGER_RATE (PAC_BASE_ADDR+0x200C) /* 1 unsigned short */ #define CLOCK_SELECT (PAC_BASE_ADDR+0x200E) /* 1 unsigned short */ #define PAC_TEMP (PAC_BASE_ADDR+0x2010) /* 1 unsigned short */ #define IQ_TEMP (PAC_BASE_ADDR+0x2012) /* 1 unsigned short */ #define SSSB_TEMP (PAC_BASE_ADDR+0x2014) /* 1 unsigned short */ #define SSSB_FWD (PAC_BASE_ADDR+0x2016) /* 1 unsigned short V? PWR? */ #define SSSB_RFLD (PAC_BASE_ADDR+0x2018) /* 1 unsigned short V? PWR? */ #define SSSB_PWR_SUP_V (PAC_BASE_ADDR+0x201A) /* 1 unsigned short */ #define PLUS_FIVE_V (PAC_BASE_ADDR+0x201C) /* 1 unsigned short */ #define MINUS_TWELVE_V (PAC_BASE_ADDR+0x201E) /* 1 unsigned short */ #define CPU_TRIG_ADDRESS (PAC_BASE_ADDR+0x2020) /* 1 short */ /* new, for FPGA calc 9/2008 */ #define I_OFFSET (PAC_BASE_ADDR+0x2022) /* 1 short */ #define I_GAIN (PAC_BASE_ADDR+0x2024) /* 1 short */ #define II_COEFFICIENT (PAC_BASE_ADDR+0x2026) /* 1 short */ #define IQ_COEFFICIENT (PAC_BASE_ADDR+0x2028) /* 1 short */ #define Q_OFFSET (PAC_BASE_ADDR+0x202A) /* 1 short */ #define Q_GAIN (PAC_BASE_ADDR+0x202C) /* 1 short */ #define QQ_COEFFICIENT (PAC_BASE_ADDR+0x202E) /* 1 short */ #define QI_COEFFICIENT (PAC_BASE_ADDR+0x2030) /* 1 short */ #define PI (3.141592654) #define CONVERSION_TO_DEGREES_C (50.0/16384.0) #define OFFSET_TO_DEGREES_C (20.0) #define CONVERSION_TO_VOLTS (20.0/16384.0) #define PAC_GAIN_NORMALIZATION (32768) #define PAC_AMPL_NORMALIZATION (32768) #define PAC_FIT_FPGA (65536) #define PAC_FIT_CAL_FPGA (32768) /* Control Register description HSB LSB xxxxxxxx xxxxxxxx |||||||| |||||---[1..0] trigger mode: 00=Normal, external trigger |||||||| ||| 01=Internal trigger |||||||| ||| 10=CPU trigger |||||||| |||-----2 ssb overtemp |||||||| ||------3 ext trig missing |||||||| |-------4 119Mhz missing ||||||||------------[15..8] version number */ #define USE_EXTERNAL_TRIGGER (0) #define USE_INTERNAL_TRIGGER (1) #define USE_CPU_TRIGGER (2) struct drvet drvPac = { 2, (DRVSUPFUN) pacReport, /* subroutine defined in this file */ (DRVSUPFUN) pacInitialise /* subroutine defined in this file */ }; epicsExportAddress(drvet, drvPac); int drvPacFlag = 2; int drvPacLoadFileFlag = 2; int drvPacScaleWfFlag = 2; int drvPacScaleCalWfFlag = 2; int drvPacTrigFlag = 2; int drvPacFpgaFlag = 2; int drvPacFpgaCopyFlag = 2; LOCAL volatile short *csar1 = (short *)CSAR1; LOCAL volatile unsigned short *cscr1 = (unsigned short *)CSCR1; LOCAL volatile unsigned long *csmr1 = (unsigned long *)CSMR1; LOCAL volatile short *iMem = (short *) IMEM; LOCAL volatile short *qMem = (short *) QMEM; LOCAL volatile short *ctrlReg = (short *) CTRL_REG; LOCAL volatile short *dacDelay = (short *) DAC_DELAY; LOCAL volatile short *sssbDelay = (short *) SSSB_DELAY; LOCAL volatile short *sssbWidth = (short *) SSSB_WIDTH; LOCAL volatile short *extTriggerDelay = (short *) EXT_TRIGGER_DELAY; LOCAL volatile short *extTriggerWidth = (short *) EXT_TRIGGER_WIDTH; LOCAL volatile short *intTrigRate = (short *) INT_TRIGGER_RATE; LOCAL volatile short *clockSelect = (short *) CLOCK_SELECT; LOCAL volatile short *pac_temp = (short *) PAC_TEMP; LOCAL volatile short *iq_temp = (short *) IQ_TEMP; LOCAL volatile short *sssb_temp = (short *) SSSB_TEMP; LOCAL volatile short *sssb_fwd = (short *) SSSB_FWD; LOCAL volatile short *sssb_rfld = (short *) SSSB_RFLD; LOCAL volatile short *sssb_pwr_sup_v = (short *) SSSB_PWR_SUP_V; LOCAL volatile short *plus_five_v = (short *) PLUS_FIVE_V; LOCAL volatile short *minus_twelve_v = (short *) MINUS_TWELVE_V; /* new, for FPGA calc 9/2008 */ LOCAL volatile short *i_offset = (short *) I_OFFSET; LOCAL volatile short *i_gain = (short *) I_GAIN; LOCAL volatile short *ii_coefficient = (short *) II_COEFFICIENT; LOCAL volatile short *iq_coefficient = (short *) IQ_COEFFICIENT; LOCAL volatile short *q_offset = (short *) Q_OFFSET; LOCAL volatile short *q_gain = (short *) Q_GAIN; LOCAL volatile short *qq_coefficient = (short *) QQ_COEFFICIENT; LOCAL volatile short *qi_coefficient = (short *) QI_COEFFICIENT; /* The waveforms. Waveform records have their bptrs pointing to these. They are mem-mapped to the FPGA, so that FPGA is updated at the same time as when calculation is done. ICal and QCal are used for calibrating the module */ LOCAL short ICal[PAC_FPGA_SIZE]; LOCAL short QCal[PAC_FPGA_SIZE]; /* New 12feb2007 Keep the reference waveform separately, so that it can be changed at the whim of the operator. Before, the ref wf was loaded via init_ waveform, now it must be a write_waveform activity. */ LOCAL short IRef[PAC_FPGA_SIZE]; LOCAL short QRef[PAC_FPGA_SIZE]; LOCAL short ICalRef[PAC_FPGA_SIZE]; LOCAL short QCalRef[PAC_FPGA_SIZE]; LOCAL short IFPGA[PAC_FPGA_SIZE]; /* Used for slow update display of FPGA contents */ LOCAL short QFPGA[PAC_FPGA_SIZE]; /* Other globals */ LOCAL int pacSelectedWf=0; LOCAL int pacSelectedCwf=0; LOCAL int pacOperationMode; /* Current operational state of the PAC */ LOCAL int pacCalibrationControl; /* state of calibration control in the PAC */ LOCAL short amplitude=0; LOCAL short iGain=0; /* Allowed range: 0 to 32767 (2^15-1) */ LOCAL short iAdjust=0; /* Allowed range: 0 to 32767 (2^15-1) */ LOCAL short iOffset=0; /* Allowed range: +/- 2048 */ LOCAL short qGain=0; /* Allowed range: 0 to 32767 (2^15-1) */ LOCAL short qAdjust=0; /* Allowed range: 0 to 32767 (2^15-1) */ LOCAL short qOffset=0; /* Allowed range: +/- 2048 */ LOCAL char pac_filenames[16][100]={"Sample1","Sample2","0r2uSPulse","1uSPulse","1r5uSPulse","2uSPulse","2r5uSPulse","3uSPulse","3r5uSPulse","5uSPulse","SLEDPulse","DSLEDPulse","n500kHz","p500kHz","CecileN85","CecileP85"}; LOCAL char spac_filenames[16][100]={"SLOWPAC","","","","","","","","","","","","","","",""}; LOCAL char cal_filenames[16][100]={"sincos","sincos2","","","","","","","","","","","","","",""}; /* Globals related to writing out contents of FPGA to file when drvPacFpgaFlag is DP_DEBUG */ LOCAL char FPGADebugFile[PAC_MAX_FILENAME_LENGTH]; LOCAL FILE *fpFPGADebugFile; LOCAL int fpgaDebugRequested=0; /*============================================================================= Name: pacGetADC Abs: =============================================================================*/ short pacGetADC(int num) { short val; switch (num) { case 0: val = *pac_temp; break; case 1: val = *iq_temp; break; case 2: val = *sssb_temp; break; case 3: val = *sssb_fwd; break; case 4: val = *sssb_rfld; break; case 5: val = *sssb_pwr_sup_v; break; case 6: val = *plus_five_v; break; case 7: val = *minus_twelve_v; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvPacFlag, ("pacGetADC: bad input num: %d\n", num)); #endif } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPacFlag, ("pacGetADC: got adc[%d]: %hd\n", num, val)); #endif return val; } /*============================================================================= Name: pacCopyFPGAContents Abs: return ptr to FPGA copy for either I or Q =============================================================================*/ short* pacCopyFPGAContents(int inputType) { int ii; if (inputType == PAC_I_FPGA) { for (ii = 0; ii < PAC_FPGA_SIZE; ii++) { IFPGA[ii] = *(iMem + ii); } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPacFpgaCopyFlag, ("pacCopyFPGAContents: copying %d points from I FPGA\n", PAC_FPGA_SIZE)); #endif return IFPGA; } else { if (inputType == PAC_Q_FPGA) { for (ii = 0; ii < PAC_FPGA_SIZE; ii++) { QFPGA[ii] = *(qMem + ii); } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPacFpgaCopyFlag, ("pacCopyFPGAContents: copying %d points from Q FPGA\n", PAC_FPGA_SIZE)); #endif return QFPGA; } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvPacFpgaCopyFlag, ("pacGetFPGAContents: unrecognized input type: %d\n", inputType)); #endif } } return (short*) NULL; } /*============================================================================= Name: pacLoadWaveformFromFile Abs: This routine is unconcerned with the number of actual points that will be used (and hence the offset to the points). At this point (initialization of the waveform records), what is needed is to get all the stored waveforms (I, Q, Ical and Qcal) into memory, specifically, into the arrays global to this file: I, Q, Ical and Qcal. Question: better to avoid passing in nelm and just loop to PAC_FPGA_SIZE? Alt if /nfs/slac/g/lcls ... unavail sprintf(filename, "/home/g/lcls/vol5/3.14.8.2-epics/ioc/iocBoot/iocpac/Q.cal"); =============================================================================*/ short* pacLoadWaveformFromFile(int inputType, long nelm) { int ii; short *wf = 0; short *dataValue; char filename[150]; FILE *fp; switch (inputType) { case PAC_I_REF: wf = IRef; sprintf(filename, "/data/iocInfo/%sI.dat", pac_filenames[pacGetSelectedWf()]); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPacLoadFileFlag, ("pacLoadWaveformFromFile: loading new selected I waveform from %s\n", filename)); #endif break; case PAC_Q_REF: wf = QRef; sprintf(filename, "/data/iocInfo/%sQ.dat", pac_filenames[pacGetSelectedWf()]); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPacLoadFileFlag, ("pacLoadWaveformFromFile: loading new selected Q waveform from %s\n", filename)); #endif break; case PAC_I_CALREF: wf = ICalRef; sprintf(filename, "/data/iocInfo/%sI.cal", cal_filenames[pacGetSelectedCwf()]); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPacLoadFileFlag, ("pacLoadWaveformFromFile: loading I cal waveform from %s\n", filename)); #endif break; case PAC_Q_CALREF: wf = QCalRef; sprintf(filename, "/data/iocInfo/%sQ.cal", cal_filenames[pacGetSelectedCwf()]); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPacLoadFileFlag, ("pacLoadWaveformFromFile: loading Q cal waveform from %s\n", filename)); #endif break; case SPAC_I_REF: wf = IRef; sprintf(filename, "/data/iocInfo/%sI.dat", spac_filenames[pacGetSelectedWf()]); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPacLoadFileFlag, ("pacLoadWaveformFromFile: loading SLOWPAC I waveform from %s\n", filename)); #endif break; case SPAC_Q_REF: wf = QRef; sprintf(filename, "/data/iocInfo/%sQ.dat", spac_filenames[pacGetSelectedWf()]); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPacLoadFileFlag, ("pacLoadWaveformFromFile: loading SLOWPAC Q waveform from %s\n", filename)); #endif break; default: DEBUGPRINT(DP_ERROR, drvPacLoadFileFlag, ("pacLoadWaveformFromFile: unrecognized input type: %d\n", inputType)); } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPacLoadFileFlag, ("pacLoadWaveformFromFile: inputType: %hd\n", inputType)); DEBUGPRINT(DP_INFO, drvPacLoadFileFlag, ("pacLoadWaveformFromFile: nelm: %d\n", (int) nelm)); #endif /* Open the file containing the waveform */ fp = fopen(filename, "r"); if (fp==NULL) { #ifdef DEBUG_PRINT perror("fopen"); #endif DEBUGPRINT(DP_ERROR, drvPacLoadFileFlag, ("pacLoadWaveformFromFile: unable to open file: '%s'\n", filename)); return (short*) NULL; } /* Read the data into the waveform */ dataValue = wf; /* set the current data point to start of the waveform */ for (ii=0; !feof(fp) && ii PAC_NUM_OP_MODES)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvPacFlag, ("pacSetOperationMode: mode %d is out of range [0,%d]\n", mode, PAC_NUM_OP_MODES)); #endif return ERROR; } pacOperationMode = mode; return OK; } /*============================================================================= Name: pacGetCalibrationControl Abs: return mode of operation =============================================================================*/ int pacGetCalibrationControl() { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPacFlag, ("pacGetCalibrationControl: %d\n", pacCalibrationControl)); #endif return pacCalibrationControl; } /*============================================================================= Name: pacSetCalibrationControl Abs: set calibration control =============================================================================*/ int pacSetCalibrationControl(int calibrationControl) { /* range check on calibrationControl */ if ((calibrationControl < 0) || (calibrationControl > PAC_NUM_CAL_MODES)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvPacFlag, ("pacSetCalibrationControl: calibrationControl %d is out of range [0,%d]\n", calibrationControl, PAC_NUM_CAL_MODES)); #endif return ERROR; } pacCalibrationControl = calibrationControl; return OK; } /*============================================================================= Name: pacInitialise Abs: Sets up the CSCR CSAR1 CSMR1 for chip select register 1. Sets up and opens the unique filename for debugging FPGA. =============================================================================*/ int pacInitialise() { /* Set up the chip select register */ *csar1 = 0x8000; /* bit 15: 1000 0000 0000 0000: bit 0 */ *cscr1 = 0x00A0; /* bit 15: 0000 0000 1010 0000: bit 0 */ /* x 16-bit port size. Valid data sampled and driven on D[31:16] */ /* x Assert BS strobes */ /* NB: set csmr1 up LAST. It sets the chip select to valid. */ *csmr1 = 0x01; /* bit 31: 0000 0000 0000 0000 0000 0000 0000 0001: bit 0 */ /* Set up the file in case the drvPacFpgaFlag ever gets set to DP_DEBUG */ pacSetUniqueFPGADebugFileName(); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPacFlag, ("pacInitialise: pacGetUniqueFPGADebugFileName() returns: '%s'\n", pacGetUniqueFPGADebugFileName())); #endif fpFPGADebugFile = fopen(FPGADebugFile,"w"); if (fpFPGADebugFile == NULL) { perror("fopen"); #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvPacFlag, ("pacInitialise: unable to open debug file for FPGA contents\n")); #endif /* Note: this is not serious enough to return ERROR, since it is not guaranteed that we will want to write FPGA contents this run */ } return OK; } /* 11/26/2007: new. clock select register, 200Eh, setting bit 0 high causes the PAC to use the clock from the Arcturus module. It means we don't need either an external clock in or a trigger anymore! In general, we are going to use this clock for all the Slow PACs, i.e. MDL-SPAC, RFR-SPAC, LCL-SPAC, CLK-SPAC and S24-SPAC. The debate is still out on LSR-SPAC, though. For now, leave it alone. */ short pacGetClock() { return *clockSelect; } int pacSetClock() { *clockSelect |= 0x01; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPacFlag, ("pacSetClock: clockSelect is: %hd\n", *clockSelect)); #endif return OK; } int pacClrClock() { *clockSelect &= 0xFE; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPacFlag, ("pacClrClock: clockSelect is: %hd\n", *clockSelect)); #endif return OK; } int pacCloseFPGADebugFile() { if (fpFPGADebugFile != NULL) { fclose(fpFPGADebugFile); } return OK; } int pacGetVersionNumber() { return *ctrlReg >> 8; } int pacIsRFMissing() { return (*ctrlReg >> 4) & 1; } int pacIsExtTrigMissing() { return (*ctrlReg >> 3) & 1; } int pacIsSSBOverTemp() { return (*ctrlReg >> 2) & 1; } int pacGetTriggerMode() { short mode; mode = ((*ctrlReg) & 3); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPacTrigFlag, ("pacGetTriggerMode: trigger mode is: %hd\n", mode)); #endif return (int) mode; } /* Modes: 00 - External Trigger 01 - Internal Trigger 10 - CPU Trigger */ int pacSetTriggerMode(int mode) { short temp1 = *ctrlReg; short temp2 = (short) mode; /* strip last two bits off control register */ temp1 = temp1 >> 2; /* replace the last two bits with what was passed in */ temp1 = temp1 << 2 | (temp2 & 3); *ctrlReg = temp1; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPacTrigFlag, ("pacSetTriggerMode: setting trigger mode to: %hd\n", ((*ctrlReg) & 3))); #endif return OK; } int pacReport() { /* ADD MORE!!!!!!!!!!!!!!!!!! */ int ii; for (ii=0; ii<6; ii++) { pacDisplayReg(ii); } #ifdef NEVER printf("Status of the PAC\n"); printf("Control Status Register contents:\n"); printf(" Version number: %d\n", pacGetVersionNumber()); printf(" 119Mhz missing: %d\n", pacIsRFMissing()); printf(" Ext Trig missing: %d\n", pacIsExtTrigMissing()); printf(" SSBOverTemp: %d\n", pacIsSSBOverTemp()); printf(" Trigger mode: %d\n", pacTriggerMode()); #endif return OK; } /*============================================================================= Name: pacSetXXXTrg, XXX = Ext, Int or Cpu Abs: Set the type of trigger you want =============================================================================*/ int pacSetExtTrg() { *ctrlReg = *ctrlReg & ~3; *ctrlReg |= USE_EXTERNAL_TRIGGER; printf("Setting trigger mode to %d\n", USE_EXTERNAL_TRIGGER); return OK; } int pacSetIntTrg() { *ctrlReg = *ctrlReg & ~3; *ctrlReg |= USE_INTERNAL_TRIGGER; printf("Setting trigger mode to %d\n", USE_INTERNAL_TRIGGER); return OK; } int pacSetCpuTrg() { *ctrlReg = *ctrlReg & ~3; *ctrlReg |= USE_CPU_TRIGGER; printf("Setting trigger mode to %d\n", USE_CPU_TRIGGER); return OK; } /*============================================================================= Name: pacSetIntTrgRate Abs: Set PAC internal trigger rate =============================================================================*/ int pacSetIntTrgRate(int rate) { *intTrigRate = rate; printf("pacSetIntTrgRate: internal trigger rate is set to: %d\n", *intTrigRate); return OK; } /*============================================================================= Name: pacReadReg Abs: Read PAC Registers and display them =============================================================================*/ int pacReadReg() { int i; short *pSrc; volatile short pacReg[20]; printf("\n"); pSrc = (short*) ctrlReg; for (i=0; i<16; i++) { pacReg[i] = *pSrc; pSrc++; } printf("PAC Register: CONVERSION_TO_DEGREES_C: %f\n", CONVERSION_TO_DEGREES_C); printf("PAC Register: OFFSET_TO_DEGREES_C: %f\n", OFFSET_TO_DEGREES_C); printf("PAC Register: CONVERSION_TO_VOLTS: %f\n", CONVERSION_TO_VOLTS); for (i = 0; i < 16; i++) { if (i==8 || i==9 || i==10) { printf("PAC Register: %2d = %d converted to %4.2f Deg. C\n", i,pacReg[i],(float)pacReg[i]*CONVERSION_TO_DEGREES_C + OFFSET_TO_DEGREES_C); } else { if (i>10) { printf("PAC Register: %2d = %d converted to %4.2f Volts\n", i,pacReg[i],(float)pacReg[i]*CONVERSION_TO_VOLTS); } else { printf("PAC Register: %2d = %4.4X\n", i,pacReg[i]); } } } return OK; } /*============================================================================= Name: pacWriteReg Abs: =============================================================================*/ int pacWriteReg(int RegNum, short Value) { volatile short *pDest; pDest = ctrlReg + RegNum; *pDest = Value; return OK; } /*============================================================================= Name: pacLoadRamp Abs: =============================================================================*/ int pacLoadRamp(volatile short *startAddr1, volatile short *startAddr2) { int i; volatile short *pDest1; volatile short *pDest2; pDest1 = startAddr1; pDest2 = startAddr2; if (amplitude == 0) { printf("amplitude is zero!\n"); } for (i= 0; i < 2048; i++) { *pDest1 = amplitude * cos(i * 2 * PI/2048); *pDest2 = amplitude * sin(i * 2 * PI/2048); printf("cos %d sin %d\n", *pDest1, *pDest2); pDest1++; pDest2++; } return OK; } /*============================================================================= Name: pacLoadIQRamp Abs: =============================================================================*/ int pacLoadIQRamp() { int rc; rc = pacLoadRamp(iMem,qMem); return rc; } /*============================================================================= Name: pacTestRamp Abs: =============================================================================*/ int pacTestRamp(volatile short *startAddr, int Times) { int i; int nLoop; short x; volatile short y; volatile short *pSrc; int ErrCount; ErrCount = 0; for (nLoop=0; nLoop< Times; nLoop++) { printf("Test Pass: %d\n",nLoop); pSrc = startAddr; for (i= 0; i < 2048; i++) { x = i * 32767/2048; y= *pSrc; pSrc++; if (x != y) { ErrCount++; printf(" Error at %4d Read %4.4X Wrote %4.4X\n", i, x, y); } } } return ErrCount; } /*============================================================================= Name: pacTestIRamp Abs: =============================================================================*/ int pacTestIRamp(int Times) { int rc; rc = pacTestRamp(iMem, Times); return rc; } /*============================================================================= Name: pacTestQRamp Abs: =============================================================================*/ int pacTestQRamp(int Times) { int rc; rc = pacTestRamp(qMem, Times); return rc; } /*============================================================================= Name: pacDisplayReg Abs: =============================================================================*/ int pacDisplayReg(int RegNum) { int i; int Value; volatile short *pSrc; pSrc = ctrlReg + RegNum; Value = *pSrc; switch (RegNum) { case 0: printf(" Control Register %4.4X \n", Value); printf(" Version Number %2d.%d\n", (Value >>12), (Value >> 8 & 0xFF)); i = Value & 0x3; if (i == 0) { printf(" Normal External Trigger\n"); } if (i == 1) { printf(" Internal Trigger\n"); } if (i == 2) { printf(" Cpu Trigger\n"); } if (Value & 0x04) { printf(" SSB Over Temp\n"); } if (Value & 0x08) { printf(" External Trigger Missing\n"); } if (Value & 0x10) { printf(" 119Mhz Clock Missing\n"); } break; case 1: printf(" DAC Delay Register %5d (0X%4.4X) = %10.2fns \n", Value, Value, Value * 8.403); break; case 2: printf(" SSSB Delay Register %5d (0X%4.4X) = %10.2fns \n", Value, Value, Value * 8.403); break; case 3: printf(" SSSB Width Register %5d (0X%4.4X) = %10.2fns \n", Value, Value, Value * 8.403); break; case 4: printf(" External Delay Register %5d (0X%4.4X) = %10.2fns \n", Value, Value, Value * 8.403); break; case 5: printf(" External Width Register %5d (0X%4.4X) = %10.2fns \n", Value, Value, Value * 8.403); break; case 6: printf(" Internal Trigger Rate %5d (0X%4.4X) = %10.2fns \n", Value, Value, Value * 8.403); break; } return OK; } int pacDumpReg() { int i; for (i=0; i<16; i++) { pacDisplayReg(i); } return OK; }