#include #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 0x0000-0xFFFE I Memory 16-bit signed integer */ #define QMEM (PAC_BASE_ADDR+0x1000) /* 2048 signed shorts 0x1000-0x1FFE Q Memory 16-bit signed integer */ #define CTRL_REG (PAC_BASE_ADDR+0x2000) /* 1 unsigned short 0x2000 Control Register */ #define DAC_DELAY (PAC_BASE_ADDR+0x2002) /* 1 unsigned short 0x2002 DAC Delay 16 bit unsigned*/ #define SSSB_DELAY (PAC_BASE_ADDR+0x2004) /* 1 unsigned short 0x2004 SSSB Delay 16 bit unsigned*/ #define SSSB_WIDTH (PAC_BASE_ADDR+0x2006) /* 1 unsigned short 0x2006 SSSB Width 16 bit unsigned*/ #define EXT_TRIGGER_DELAY (PAC_BASE_ADDR+0x2008) /* 1 unsigned short 0x2008 Ext Trigger Delay 16 bit unsigned*/ #define EXT_TRIGGER_WIDTH (PAC_BASE_ADDR+0x200A) /* 1 unsigned short 0x200A Ext Trigger Width 16 bit unsigned*/ #define INT_TRIGGER_RATE (PAC_BASE_ADDR+0x200C) /* 1 unsigned short 0x200C Int Trigger Rate 16 bit unsigned*/ #define CLOCK_SELECT (PAC_BASE_ADDR+0x200E) /* 1 unsigned short 0x200E Clock Select 16 bit unsigned*/ #define PAC_TEMP (PAC_BASE_ADDR+0x2010) /* 1 unsigned short 0x2010 PAC Temperature 16 bit unsigned*/ #define IQ_TEMP (PAC_BASE_ADDR+0x2012) /* 1 unsigned short 0x2012 IQ Temperature 16 bit unsigned*/ #define SSSB_TEMP (PAC_BASE_ADDR+0x2014) /* 1 unsigned short 0x2014 SSB Temperature 16 bit unsigned*/ #define SSSB_FWD (PAC_BASE_ADDR+0x2016) /* 1 unsigned short 0x2016 VFWD PWR 16 bit unsigned*/ #define SSSB_RFLD (PAC_BASE_ADDR+0x2018) /* 1 unsigned short 0x2018 VREFL PWR 16 bit unsigned*/ #define SSSB_PWR_SUP_V (PAC_BASE_ADDR+0x201A) /* 1 unsigned short 0x201A SSB_PWR 16 bit unsigned*/ #define PLUS_FIVE_V (PAC_BASE_ADDR+0x201C) /* 1 unsigned short 0x201C +5V 16 bit unsigned*/ #define MINUS_TWELVE_V (PAC_BASE_ADDR+0x201E) /* 1 unsigned short 0x201E -12V 16 bit unsigned*/ #define CPU_TRIG_ADDRESS (PAC_BASE_ADDR+0x2020) /* 1 short 0x2020 CPUTrig address */ /* new, for FPGA calc 9/2008 FPGA FW Version V08 */ #define I_OFFSET (PAC_BASE_ADDR+0x2022) /* 1 short 0x2022 I Offset 16 bit 2's Comp */ #define I_GAIN (PAC_BASE_ADDR+0x2024) /* 1 short 0x2024 I Gain 16 bit 2's Comp */ #define II_COEFFICIENT (PAC_BASE_ADDR+0x2026) /* 1 short 0x2026 II Coefficient 16 bit 2's Comp */ #define IQ_COEFFICIENT (PAC_BASE_ADDR+0x2028) /* 1 short 0x2028 IQ Coefficient 16 bit 2's Comp */ #define Q_OFFSET (PAC_BASE_ADDR+0x202A) /* 1 short 0x202A Q Offset 16 bit 2's Comp */ #define Q_GAIN (PAC_BASE_ADDR+0x202C) /* 1 short 0x202C Q Gain 16 bit 2's Comp */ #define QQ_COEFFICIENT (PAC_BASE_ADDR+0x202E) /* 1 short 0x202E QQ Coefficient 16 bit 2's Comp */ #define QI_COEFFICIENT (PAC_BASE_ADDR+0x2030) /* 1 short 0x2030 QI Coefficient 16 bit 2's Comp */ /* new, for FPGA calibration, 09/2013 FPGA FW Version V18 */ #define II_CALIBRATION (PAC_BASE_ADDR+0x2032) /* 1 short 0x2032 II Calibration 16 bit 2's Comp */ #define QI_CALIBRATION (PAC_BASE_ADDR+0x2034) /* 1 short 0x2034 QI Calibration 16 bit 2's Comp */ #define IQ_CALIBRATION (PAC_BASE_ADDR+0x2036) /* 1 short 0x2036 IQ Calibration 16 bit 2's Comp */ #define QQ_CALIBRATION (PAC_BASE_ADDR+0x2038) /* 1 short 0x2038 QQ Calibration 16 bit 2's Comp */ #define CTRL_REG2 (PAC_BASE_ADDR+0x203a) /* 1 unsigned short 0x203A Control Reg 2 16 bit unsigned */ /* new, scondam: 29-May-2015: For PAC Clock Phase Adjust FPGA FW Version V19 */ #define PHASE_ADJUST (PAC_BASE_ADDR+0x203c) /* 1 short 0x203C Phase Adjust 16 bit 2's Comp */ /* new, for FPGA Diagnostic Memory, 09/2013 FPGA FW Version V18 */ #define IDIAGMEM (PAC_BASE_ADDR+0x3000) /* 2048 0x3000-0x3FFE I Diagnostic Memory unsigned short */ #define QDIAGMEM (PAC_BASE_ADDR+0x4000) /* 2048 0x4000-0x4FFE Q Diagnostic Memory unsigned 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 0x2000 description HSB LSB xxxxxxxx xxxxxxxx |||||||| ||||||||---[1..0] R/W trigger mode: 00=Normal, external trigger |||||||| |||||| 01=Internal trigger |||||||| |||||| 10=CPU trigger |||||||| |||||+-----2 R/W ssb overtemp Latched Value 1 => Clears flag |||||||| ||||+------3 R/W ext trig missing - No transition on Ext Trig in 1 sec Latched Value 1 => Clears flag |||||||| |||+-------4 R/W 119Mhz missing - Check 119MHz clock for 9-150 MHz Latched Value 1 => Clears flag |||||||| ||+--------5 R/W Stby Trigger Missing - No transition on Stby Trig in 1 sec Latched Value 1 => Clears flag |||||||| ++---------[7..6] Trigger Source |||||||| source: 11=StandBy Trigger |||||||| 10=CPU Trigger |||||||| 01=Internal Trigger |||||||| 00=External Trigger ++++++++------------[11..8] Minor version number ++++++++------------[15..12] Major version number 1 => PAC Firmware with Calibration Matrix and Diagnostic Memory 0 => Original PAC Firmware Control Register 2 0x203A description HSB LSB xxxxxxxx xxxxxxxx |||||||| ||||||||---[1..0] R/W Diagnostic Memory Input Select 00=DAC I and Q - DAC output |||||||| |||||| 01=CAL I and Q - 2x2 matrix calibration |||||||| |||||| 10=I an Q Output - IQ rotation |||||||| ||||||||---[15..2] Unused */ #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 epicsMutexId regLock; 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 unsigned short *ctrlReg = (unsigned 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; LOCAL volatile short *ii_calibration = (short *) II_CALIBRATION; LOCAL volatile short *qi_calibration = (short *) QI_CALIBRATION; LOCAL volatile short *iq_calibration = (short *) IQ_CALIBRATION; LOCAL volatile short *qq_calibration = (short *) QQ_CALIBRATION; LOCAL volatile unsigned short *ctrlReg2 = (unsigned short *) CTRL_REG2; /* scondam: 29-May-2015: FPGA V19: Clock Phase Adjust Register */ LOCAL volatile unsigned short *phaseAdjust = (unsigned short *) PHASE_ADJUST; LOCAL volatile short *iDiagMem = (short *) IDIAGMEM; LOCAL volatile short *qDiagMem = (short *) QDIAGMEM; /* 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]; LOCAL short IDIAG[PAC_FPGA_SIZE]; LOCAL short QDIAG[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","0r150nsPulse", "1uSPulse","1r5uSPulse","2uSPulse","3uSPulse","3r5uSPulse","5mhzoff150ns","SLEDPulse","DSLEDPulse","3mhzoff","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; /* scondam: 28-Aug-2013: Flag below is set from ioc shell. It decides whether Ref Waveform is via file or CA input */ /* Default is 0 = Ref Wf via file 1 = Ref Wf via CA */ int pacSelectRefWfInputMethod=0; int pacFPGAver80 =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 if(inputType == PAC_I_DIAG) { if(pacFPGAver80) for(ii=0; ii < PAC_FPGA_SIZE; ii++) { IDIAG[ii] = *(iDiagMem + ii); } return IDIAG; } else if(inputType == PAC_Q_DIAG) { if(pacFPGAver80) for(ii=0; ii < PAC_FPGA_SIZE; ii++) { QDIAG[ii] = *(qDiagMem + ii); } return QDIAG; } 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 /* scondam: 27-Aug-2013: Kukhee's feature addition for updating Ref wf via caputs */ /* scondam: 28-Aug-2013: Ref WF updated via CAPUT */ if ((pacSelectRefWfInputMethod == 0) || (pacSelectRefWfInputMethod && (inputType==PAC_I_CALREF)) || (pacSelectRefWfInputMethod && (inputType==PAC_Q_CALREF))) { /* please, read file for calibration */ /* 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(void) { #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() { regLock = epicsMutexMustCreate(); epicsMutexLock(regLock); /* 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 */ epicsMutexUnlock(regLock); if((unsigned char) pacGetVersionNumber() >= (unsigned char) 0x10) pacFPGAver80 = 1; /* activate the calibration */ else pacFPGAver80 = 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() { unsigned short temp; epicsMutexLock(regLock); temp = *ctrlReg; epicsMutexUnlock(regLock); return (int) (temp>>=8); } int pacIsRFMissing() { unsigned short temp; epicsMutexLock(regLock); temp = *ctrlReg; epicsMutexUnlock(regLock); temp = (temp>>4) & 0x0001; return (int) temp; } int pacIsExtTrigMissing() { unsigned short temp; epicsMutexLock(regLock); temp = *ctrlReg; epicsMutexUnlock(regLock); temp = (temp>>3) & 0x0001; return (int) temp; } int pacIsSSBOverTemp() { unsigned short temp; epicsMutexLock(regLock); temp = *ctrlReg; epicsMutexUnlock(regLock); temp = (temp>>2) & 0x0001; return (int) temp; } int pacGetTriggerMode() { unsigned short mode; epicsMutexLock(regLock); mode = *ctrlReg; epicsMutexUnlock(regLock); mode &= 0x0003; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPacTrigFlag, ("pacGetTriggerMode: trigger mode is: %hd\n", mode)); #endif return (int) mode; } int pacGetDiagMode(void) { unsigned short mode; epicsMutexLock(regLock); mode = *ctrlReg; epicsMutexUnlock(regLock); mode >>= 6; mode &= 0x0003; return (int) mode; } /* Modes: 0x00 - 00 DAC 0x01 - 01 2x2 matrix calibration 0x02 - 10 IQ rotaton */ int pacSetDiagMode(int mode) { unsigned short temp1, temp2; if(!pacFPGAver80) return OK; temp2 = (unsigned short) mode; epicsMutexLock(regLock); temp1 = *ctrlReg2 & 0xfffc; temp1 |= (temp2 & 0x0003); *ctrlReg2 = temp1; epicsMutexUnlock(regLock); return OK; } /* Modes: 00 - External Trigger 01 - Internal Trigger 10 - CPU Trigger */ int pacSetTriggerMode(int mode) { unsigned short temp1, temp2; temp2 = (unsigned short) mode; epicsMutexLock(regLock); /* strip last two bits off control register */ temp1 = *ctrlReg & 0xfffc; /* replace the last two bits with what was passed in */ temp1 |= (temp2 & 0x0003); *ctrlReg = temp1; epicsMutexUnlock(regLock); #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; short Value; volatile short *pSrc; pSrc = ctrlReg + RegNum; Value = *pSrc; switch (RegNum) { case 0: if(pacFPGAver80) printf(" !!! 2x2 calibration matrix has been activated!!!\n Control Register 0x%4.4x, 0x%4.4x\n", Value, *ctrlReg2); else printf(" Control Register 0x%4.4x\n", Value); printf(" Version Number 0x%2.2x\n", (Value >> 8 & 0x00FF)); i = Value & 0x03; if (i == 0) { printf(" Normal External Trigger\n"); } if (i == 1) { printf(" Internal Trigger\n"); } if (i == 2) { printf(" Cpu Trigger\n"); } if (Value & 0x0004) { printf(" SSB Over Temp\n"); } if (Value & 0x0008) { printf(" External Trigger Missing\n"); } if (Value & 0x0010) { 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; }