/* ****************************************************************************** * Modification history * Mod: Shantha Condamoor 11-Nov-2013 * Changed LLRF_KLY21_1 to LLRF_LSRDIAG as this slot (20) is now used * for Coherent 2 Laser Diagnostics PAD * Added LLRF_LSRDIAG related variables * Added lsrDiagSetDesiredPhase() and lsrDiagSetInputSource() * Mod: Shantha Condamoor 10-Jan-2014 * Added LLRF_IN20REF related code for IN20 Reference PAD * LLRF_IN20REF (slot 19) in MC group ioc-in20-rf01-padg * LLRF_S24REF (slot 19) in MC group ioc-li24-rf01-padg * 06-Mar-2014 - Added FCOM processing functions * 07-Mar-2014 - per Kukhee's recommendation removed FCOM processing from drvLlrfPad.c * and added it inside a subroutine record processing * 18-Jul-2014 - Added support for LLRF_KLY24_5 (slot 22) for ASTA Kly Diag PAD @ TS01 * 9-Nov-16: Moved Klystron Diagnostics for DGN,GUN and TC0 to the newly added ioc-in20-rf03 **************************************************************************** */ #include #include #include #include #include /* for atan2 */ #include /* for DEBUGPRINT */ #include #include #include #include #include "llrfMacros.h" #ifdef FCOM_BLOB #include "fcomLlrf.h" #endif #include "drvLlrfPad.h" #ifdef __rtems__ #include #endif #define LLRF_EVENT 0x7a extern int padLlrfInit(void); int llrfPadReport(int station); int llrfPadInitialise(void); struct drvet drvLlrfPad = { 2, (DRVSUPFUN) llrfPadReport, /* subroutine defined in this file */ (DRVSUPFUN) llrfPadInitialise /* subroutine defined in this file */ }; epicsExportAddress(drvet, drvLlrfPad); #ifdef DEBUG_PRINT int drvLlrfPadFlag = 2; #endif int drvLlrfPadFlagDebug = 0; static LlrfStation llrf_stations[LLRF_STATION_NUM_TYPES] = { 0 }; /* scondam: 19-Mar-2014: Station numbers 13-19 as defined in llrfMacros.h are currently used only by PACs. - there are no PADs that use these station numbers currently; may be for future. */ static const char * llrf_station_names[LLRF_STATION_NUM_TYPES] = { [0] = "SPARE_STN0", #ifdef LLRF_KLY_PAD [LLRF_KLY_L1S] = "LLRF_KLY_L1S", /* Station 1 Multicasting group ioc-in20-rf03-padg (eioc-in20-rd12 KLYS:LI21:K1:L1S) */ [LLRF_KLY_L0A] = "LLRF_KLY_L0A", /* Station 2 Multicasting group ioc-in20-rf03-padg (eioc-in20-rd07 KLYS:LI20:K7:L0A) */ [LLRF_KLY_L0B] = "LLRF_KLY_L0B", /* Station 3 Multicasting group ioc-in20-rf03-padg (eioc-in20-rd08 KLYS:LI20:K8:L0B) */ [LLRF_KLY_L1X] = "LLRF_KLY_L1X", /* Station 4 Multicasting group ioc-in20-rf03-padg (eioc-in20-rd15 KLYS:LI21:K2:L1X) */ #elif defined LLRF_KLY_PAD2 [LLRF_KLY_DGN] = "LLRF_KLY_DGN", /* Station 1 Multicasting group ioc-in20-rf05-padg (eioc-in20-rd17 LLRF:IN20:RH:DGN) */ [LLRF_KLY_TC0] = "LLRF_KLY_TC0", /* Station 2 Multicasting group ioc-in20-rf05-padg (eioc-in20-rd10 KLYS:LI20:K5:TC0) */ [LLRF_KLY_GUN] = "LLRF_KLY_GUN", /* Station 3 Multicasting group ioc-in20-rf05-padg (eioc-in20-rd05 KLYS:LI20:K6:GUN) */ /* scondam: 18-Mar-2014: LLRF_KLY_L2 unused as of date */ /* [LLRF_KLY_L2] = "LLRF_KLY_L2" */ #elif defined LLRF_XTCAV [LLRF_XTCAVA] = "LLRF_XTCAVA", /* Station 1 Multicasting group ioc-dmp1-rf01-padg (eioc-dmp1-rd01 TCAV:DMP1:360:TCA) or ioc-li20-rf01-padg (eioc-li20-rf11 TCAV:LI20:2400:TCA) */ [LLRF_XTCAVB] = "LLRF_XTCAVB", /* Station 2 Multicasting group ioc-dmp1-rf01-padg (eioc-dmp1-rd02 TCAV:DMP1:360:TCB) */ [LLRF_KLY_XTCAV] = "LLRF_KLY_XTCAV", /* Station 3 Multicasting group ioc-dmp1-rf01-padg (eioc-dmp1-rd03 KLYS:DMP1:K1:TCA) or ioc-li20-rf01-padg (eioc-li20-rf12 KLYS:LI20:K4:TCA) */ #else [LLRF_LSR] = "LLRF_LSR", /* Station 1 Multicasting group ioc-in20-rf02-padg (eioc-in20-rd16 LASR:IN20:2:LSR) or ioc-as01-rf01-padg (eioc-as01-rf11 LASR:AS01:1:LSR) */ [LLRF_GUN] = "LLRF_GUN", /* Station 2 Multicasting group ioc-in20-rf04-padg (eioc-in20-rd03 GUN:IN20:1:GN1) or ioc-as01-rf01-padg (eioc-as01-rf12 GUN:AS01:1:GN1) */ [LLRF_L0A] = "LLRF_L0A", /* Station 3 Multicasting group ioc-in20-rf04-padg (eioc-in20-rd06 ACCL:IN20:350:L0) */ [LLRF_L0B] = "LLRF_L0B", /* Station 4 Multicasting group ioc-in20-rf04-padg */ [LLRF_L1S] = "LLRF_L1S", /* Station 5 Multicasting group ioc-in20-rf01-padg (eioc-in20-rd11 ACCL:LI21:1:L1S) */ [LLRF_L1X] = "LLRF_L1X", /* Station 6 Multicasting group ioc-in20-rf01-padg (eioc-in20-rd14 ACCL:LI21:180:L1X) */ [LLRF_TCAV0] = "LLRF_TCAV0", /* Station 7 Multicasting group ioc-in20-rf06-padg (eioc-in20-rd09 TCAV:IN20:490:TC0) */ [LLRF_TCAV3] = "LLRF_TCAV3", /* Station 8 Multicasting group ioc-li24-rf01-padg (eioc-li24-rd01 TCAV:LI24:800:TC3) */ [LLRF_PCAV1] = "LLRF_PCAV1", /* Station 9 Multicasting group ioc-li24-rf02-padg (eioc-in20-rd13 PCAV:IN20:365:PH1) */ [LLRF_PCAV2] = "LLRF_PCAV2", /* Station 10 Multicasting group ioc-li24-rf02-padg */ [LLRF_PCAV3] = "LLRF_PCAV3", /* Station 11 Multicasting group ioc-li24-rf03-padg (eioc-li24-rd02 PCAV:LI25:300:PH3) */ [LLRF_PCAV4] = "LLRF_PCAV4", /* Station 12 Multicasting group ioc-li24-rf02-padg (eioc-li29-rd01 PCAV:LI29:100:PH4) */ [LLRF_KLY24_1] = "LLRF_KLY24_1", /* Station 13:Multicasting group: ioc-li24-rf01-pacg; Used by 24-1 PAC */ [LLRF_KLY24_2] = "LLRF_KLY24_2", /* Station 14:Multicasting group: ioc-li24-rf01-pacg; Used by 24-2 PAC */ [LLRF_KLY24_3] = "LLRF_KLY24_3", /* Station 15:Multicasting group: ioc-li24-rf01-pacg; Used by 24-3 PAC */ [LLRF_S29] = "LLRF_S29", /* Station 16:Multicasting group: ioc-li24-rf01-pacg; Used by S29 PAC */ [LLRF_S30] = "LLRF_S30", /* Station 17:Multicasting group: ioc-li24-rf01-pacg; Used by S30 PAC */ [LLRF_L2REF] = "LLRF_L2REF", /* Station 18:Multicasting group: ioc-li24-rf01-pacg; Used by L2 Ref PAC */ /* [LLRF_S24REF] = "LLRF_S24REF", */ /* Station 19:Multicasting group: ioc-li24-rf01-pacg; Used by L2 Ref PAC */ [LLRF_IN20REF] = "LLRF_IN20REF", /* Station 19:Multicasting group: ioc-in20-rf01-pacg (eioc-in20-rd01 LLRF:IN20:RH:REF) */ [LLRF_LSRDIAG] = "LLRF_LSRDIAG", /* Station 20 Multicasting group ioc-in20-rf02-padg (eioc-in20-rd02 LASR:IN20:1:LSR) */ [LLRF_GN2] = "LLRF_GN2", /* Station 21 Multicasting group ioc-in20-rf06-padg (eioc-in20-rd04 GUN:IN20:1:GN2) or ioc-as01-rf01-padg (eioc-as01-rf13 GUN:AS01:1:GN2) */ [LLRF_KLY24_5] = "LLRF_KLY24_5", /* Station 22 Multicasting group ioc-li24-rf02-padg (eioc-li24-rd03 KLYS:LI24:K5:L2 )*/ #endif }; static LlrfStation llrfStationInitialize(int sta_idx) { int i,j; LlrfStation sta_p; printf("Initializing Station %s\n",llrf_station_names[sta_idx]); /* station index is 1-based (everywhere, for sake of consistency) */ sta_idx--; /* invalid index */ /* if ( sta_idx < 0 || sta_idx >= sizeof(llrf_stations)/sizeof(llrf_stations[0]) ) { */ if ( sta_idx < 0 || sta_idx >= LLRF_STATION_NUM_TYPES) { return 0; } if ( llrf_stations[sta_idx] ) { errlogPrintf("llrfStationInitialize(): station %i already initialized\n", sta_idx+1); return 0; } sta_p = llrf_stations[sta_idx] = callocMustSucceed( 1, sizeof(*sta_p), "llrfStationInitialize(): no memory"); sta_p->index = sta_idx+1; /* for ( i=0; ichnls)/sizeof(sta_p->chnls[0]); i++ ) { */ for ( i=0; ichnls[i].frags = 0; sta_p->chnls[i].I = (LlrfOutNumber)0; sta_p->chnls[i].Q = (LlrfOutNumber)0; sta_p->chnls[i].Phase = (LlrfOutNumber)0; sta_p->chnls[i].Amplitude = (LlrfOutNumber)0; sta_p->chnls[i].Power = (LlrfOutNumber)0; sta_p->chnls[i].ofst = (LlrfOutNumber)0; sta_p->chnls[i].size = (LlrfOutNumber)0; sta_p->chnls[i].poc = (double)0.; sta_p->chnls[i].avc = (double)0.; sta_p->chnls[i].apc = (double)0.; sta_p->chnls[i].freq = (LlrfOutNumber)0; sta_p->chnls[i].x = (LlrfInNumber)0; sta_p->chnls[i].Samples = (LlrfChannelSample *) NULL; sta_p->chnls[i].stn = sta_p->index; /* station number same for all 4 channels */ for (j=0; j < LLRF_PHASE_ANGLES; j++) { sta_p->chnls[i].sum[j]=(LlrfOutNumber)0; sta_p->chnls[i].num[j]=(LlrfOutNumber)0; sta_p->chnls[i].sum_acc[j]=(LlrfOutNumber)0; sta_p->chnls[i].num_acc[j]=(LlrfOutNumber)0; } } sta_p->xid = 0; sta_p->chnlsDone = 0; sta_p->timedout = LLRF_TIMEDOUT_ALL; sta_p->tsSum.nsec = 0; sta_p->tsSum.secPastEpoch = 0; switch (sta_idx+1) { #ifdef LLRF_KLY_PAD case LLRF_KLY_L1S: case LLRF_KLY_L0A: case LLRF_KLY_L0B: case LLRF_KLY_L1X: sta_p->chnls[0].freq = (LlrfOutNumber)2856; sta_p->chnls[1].freq = (LlrfOutNumber)2856; sta_p->chnls[2].freq = (LlrfOutNumber)0; sta_p->chnls[3].freq = (LlrfOutNumber)2856; break; #elif defined LLRF_KLY_PAD2 case LLRF_KLY_DGN: case LLRF_KLY_GUN: case LLRF_KLY_TC0: sta_p->chnls[0].freq = (LlrfOutNumber)2856; sta_p->chnls[1].freq = (LlrfOutNumber)2856; sta_p->chnls[2].freq = (LlrfOutNumber)0; sta_p->chnls[3].freq = (LlrfOutNumber)2856; break; /* scondam: 18-Mar-2014: LLRF_KLY_L2 unused as of date */ /*#elif defined LLRF_KLY_PAD2 case LLRF_KLY_L2: sta_p->chnls[0].freq = (LlrfOutNumber)2856; sta_p->chnls[1].freq = (LlrfOutNumber)2856; sta_p->chnls[2].freq = (LlrfOutNumber)0; sta_p->chnls[3].freq = (LlrfOutNumber)2856; break; */ #elif defined LLRF_XTCAV case LLRF_XTCAVA: case LLRF_XTCAVB: sta_p->chnls[0].freq = (LlrfOutNumber)2856; sta_p->chnls[1].freq = (LlrfOutNumber)2856; sta_p->chnls[2].freq = (LlrfOutNumber)2856; sta_p->chnls[3].freq = (LlrfOutNumber)2856; break; case LLRF_KLY_XTCAV: sta_p->chnls[0].freq = (LlrfOutNumber)2856; sta_p->chnls[1].freq = (LlrfOutNumber)2856; sta_p->chnls[2].freq = (LlrfOutNumber)0; sta_p->chnls[3].freq = (LlrfOutNumber)2856; break; #else case LLRF_LSR: sta_p->chnls[0].freq = (LlrfOutNumber)2856; sta_p->chnls[1].freq = (LlrfOutNumber)0; sta_p->chnls[2].freq = (LlrfOutNumber)68; sta_p->chnls[3].freq = (LlrfOutNumber)68; break; case LLRF_LSRDIAG: sta_p->chnls[0].freq = (LlrfOutNumber)2856; sta_p->chnls[1].freq = (LlrfOutNumber)0; sta_p->chnls[2].freq = (LlrfOutNumber)68; sta_p->chnls[3].freq = (LlrfOutNumber)119; break; case LLRF_GUN: case LLRF_L0A: case LLRF_L0B: case LLRF_L1S: case LLRF_L1X: case LLRF_TCAV0: case LLRF_TCAV3: sta_p->chnls[0].freq = (LlrfOutNumber)2856; sta_p->chnls[1].freq = (LlrfOutNumber)2856; sta_p->chnls[2].freq = (LlrfOutNumber)2856; sta_p->chnls[3].freq = (LlrfOutNumber)2856; break; case LLRF_PCAV1: /* PCAV1 on CH0 and CH1 and PCAV2 on CH2 and CH3 of BPH1 PAD */ case LLRF_PCAV2: sta_p->chnls[0].Samples=callocMustSucceed( 1, sizeof(*sta_p->chnls[0].Samples), "llrfStationInitialize(): no memory"); /* PCAV1 1A Sample0 and Sample1 on CH0 */ sta_p->chnls[1].Samples=callocMustSucceed( 1, sizeof(*sta_p->chnls[1].Samples), "llrfStationInitialize(): no memory"); /* PCAV1 1B Sample0 and Sample1 on CH1 */ sta_p->chnls[2].Samples=callocMustSucceed( 1, sizeof(*sta_p->chnls[2].Samples), "llrfStationInitialize(): no memory"); /* PCAV2 2A Sample0 and Sample1 on CH2 */ sta_p->chnls[3].Samples=callocMustSucceed( 1, sizeof(*sta_p->chnls[3].Samples), "llrfStationInitialize(): no memory"); /* PCAV2 2B Sample0 and Sample1 on CH3 */ sta_p->chnls[0].freq = (LlrfOutNumber)2856; sta_p->chnls[1].freq = (LlrfOutNumber)2856; sta_p->chnls[2].freq = (LlrfOutNumber)2856; sta_p->chnls[3].freq = (LlrfOutNumber)2856; break; case LLRF_PCAV3: sta_p->chnls[3].Samples=callocMustSucceed( 1, sizeof(*sta_p->chnls[3].Samples), "llrfStationInitialize(): no memory"); /* PCAV3 Sample0 and Sample1 on CH3 of KLYS 24-8 PAD */ sta_p->chnls[0].freq = (LlrfOutNumber)2856; /* PAC Out */ sta_p->chnls[1].freq = (LlrfOutNumber)2856; /* Kly Drive */ sta_p->chnls[2].freq = (LlrfOutNumber)0; /* Kly Beam Voltage */ sta_p->chnls[3].freq = (LlrfOutNumber)2856; /* Beam PCAV3 Sample (0 and 1) */ break; case LLRF_PCAV4: sta_p->chnls[3].Samples=callocMustSucceed( 1, sizeof(*sta_p->chnls[3].Samples), "llrfStationInitialize(): no memory"); /* PCAV4 Sample0 and Sample1 on CH3 of BPH4 PAD */ sta_p->chnls[0].freq = (LlrfOutNumber)2856; /* S29 PRL */ sta_p->chnls[1].freq = (LlrfOutNumber)2856; /* S28 PRL */ sta_p->chnls[2].freq = (LlrfOutNumber)2856; /* Spare */ sta_p->chnls[3].freq = (LlrfOutNumber)2856; /* Beam PCAV4 Sample (0 and 1) */ break; /* scondam: 19-Mar-2014: The following station numbers are currently used only for PACs - there are no PAD stations for the following 7 cases */ /* case LLRF_KLY24_1: case LLRF_KLY24_2: case LLRF_KLY24_3: case LLRF_S29: case LLRF_S30: case LLRF_L2REF: case LLRF_S24REF: break; */ case LLRF_IN20REF: sta_p->chnls[0].freq = (LlrfOutNumber)2856; /* 2856 MHz Ref */ sta_p->chnls[1].freq = (LlrfOutNumber)2856; /* S21 2856 MHz */ sta_p->chnls[2].freq = (LlrfOutNumber)119; /* 119 MHz EVG */ sta_p->chnls[3].freq = (LlrfOutNumber)2856; /* 25.5 MHz */ break; case LLRF_GN2: sta_p->chnls[0].freq = (LlrfOutNumber)2856; sta_p->chnls[1].freq = (LlrfOutNumber)2856; sta_p->chnls[2].freq = (LlrfOutNumber)2856; sta_p->chnls[3].freq = (LlrfOutNumber)2856; break; /* LLRF_KLY24_5 is PADSLOT 22 which is for both LCLS 24-5 Kly PAD as well as ASTA TS01 Kly Diag PAD */ case LLRF_KLY24_5: sta_p->chnls[0].freq = (LlrfOutNumber)2856; /* PAC Out */ sta_p->chnls[1].freq = (LlrfOutNumber)2856; /* Kly Drive */ sta_p->chnls[2].freq = (LlrfOutNumber)0; /* Kly Beam Voltage */ sta_p->chnls[3].freq = (LlrfOutNumber)2856; /* Beam PCAV3 Sample (0 and 1) */ break; #endif default: break; } for ( i=0; ichnls[i].Samples) { sta_p->chnls[i].Samples->I = (LlrfOutNumber)0; sta_p->chnls[i].Samples->Q = (LlrfOutNumber)0; sta_p->chnls[i].Samples->Phase = (LlrfOutNumber)0; sta_p->chnls[i].Samples->Amplitude = (LlrfOutNumber)0; sta_p->chnls[i].Samples->Power = (LlrfOutNumber)0; sta_p->chnls[i].Samples->ofst = (LlrfOutNumber)0; sta_p->chnls[i].Samples->size = (LlrfOutNumber)0; sta_p->chnls[i].Samples->x = (LlrfInNumber)0; for (j=0; j < LLRF_PHASE_ANGLES; j++) { sta_p->chnls[i].Samples->sum[j]=(LlrfOutNumber)0; sta_p->chnls[i].Samples->num[j]=(LlrfOutNumber)0; sta_p->chnls[i].Samples->sum_acc[j]=(LlrfOutNumber)0; sta_p->chnls[i].Samples->num_acc[j]=(LlrfOutNumber)0; } } } sta_p->mutex = epicsMutexMustCreate(); sta_p->epics_event_no = LLRF_EVENT + sta_idx; sta_p->rawDataReady = epicsEventMustCreate(epicsEventEmpty); /* sta_p->padProcessThread = epicsThreadMustCreate(llrf_station_names[sta_idx+1], epicsThreadPriorityMax, epicsThreadGetStackSize(epicsThreadStackMedium), llrfPadTask, sta_p); */ /* PadDataProc for Local Feedback stations as defined in stationDataProc.c */ #ifdef DATAPROC_BLOB switch (sta_idx+1) { #ifdef LLRF_XTCAV case LLRF_XTCAVA: #else case LLRF_LSR: #endif case LLRF_GUN: case LLRF_L0A: /* share with L0B */ case LLRF_L0B: case LLRF_PCAV1: /* share with PCAV2 */ case LLRF_PCAV2: case LLRF_TCAV0: case LLRF_L1S: case LLRF_L1X: case LLRF_TCAV3: case LLRF_PCAV3: case LLRF_PCAV4: /* scondam: 11-Nov-2013: Klys Diag PAD for L1S (21-1) must not be included here */ /* case LLRF_KLY21_1: scanIoRequest(pdrvData->scanlist[LLRF_KLY21_1]); break; */ sta_p->padData_p = callocMustSucceed( 1, sizeof(*(sta_p->padData_p)), "genericPadData_p: no memory"); epicsMutexMustLock( sta_p->mutex ); if (sta_p->padData_p) { for (i = 0; i < 24; i++) { sta_p->padData_p->data[i] = (short) 0x0; } } epicsMutexUnlock( sta_p->mutex ); break; default: break; } #endif /****************************************************************************** * Comment: scondam: 6-Mar-2014 * Description: llrfFcomTask task and llrfFcomTaskResumeAll() is currently * unused and untested. It is left in source code for possible future inclusion * to setup and process fcom activities in a separate task for each station. * Currently, fcomLlrfProc() is directly called at the end * of llrf_cook() in drvLlrfUdpComm.c * * Inputs: LlrfStation * Returns: *****************************************************************************/ #ifdef FCOM_BLOB /* sta_p->fcomProcessThread = epicsThreadMustCreate(llrf_station_names[sta_idx+1], epicsThreadPriorityMax, epicsThreadGetStackSize(epicsThreadStackMedium), llrfFcomTask, sta_p); */ #endif return sta_p; } #ifdef FCOM_BLOB void llrfFcomTaskResumeAll(void) { int i; for ( i=0; ifcomProcessThread ); #else rtems_task_resume( (rtems_id)llrf_stations[i]->fcomProcessThread ); #endif } } } #endif /*============================================================================= Name: llrfPadReport(int station) Abs: =============================================================================*/ int llrfPadReport(int station) { return 0; } /*============================================================================= Name: llrfPadInitialise(void) Abs: =============================================================================*/ int llrfPadInitialise(void) { int rc; if ( (rc = padLlrfInit()) ) return rc; /****************************************************************************** * Comment: scondam: 7-Mar-2014 * Description: fcomLlrfInit() moved to subroutines - in dbSubLlrf.c * It is left here in source code for possible future inclusion * to setup and process fcom activities in a separate task for each station. * Or fcomLlrfProc() can also be called directly at the end * of llrf_cook() in drvLlrfUdpComm.c * * Inputs: LlrfStation * Returns: *****************************************************************************/ #ifdef FCOM_BLOB /* if ( (rc = fcomLlrfInit()) ) return rc; */ #endif #ifdef LLRF_KLY_PAD /* Station 1 Multicasting group ioc-in20-rf03-padg (eioc-in20-rd12 KLYS:LI21:K1:L1S) */ #ifdef LLRF_KLY_L1S_NG if ( ! llrfStationInitialize( LLRF_KLY_L1S ) ) rc = -1; #endif /* Station 2 Multicasting group ioc-in20-rf03-padg (eioc-in20-rd07 KLYS:LI20:K7:L0A) */ #ifdef LLRF_KLY_L0A_NG if ( ! llrfStationInitialize( LLRF_KLY_L0A ) ) rc = -1; #endif /* Station 3 Multicasting group ioc-in20-rf03-padg (eioc-in20-rd08 KLYS:LI20:K8:L0B) */ #ifdef LLRF_KLY_L0B_NG if ( ! llrfStationInitialize( LLRF_KLY_L0B ) ) rc = -1; #endif /* Station 4 Multicasting group ioc-in20-rf03-padg (eioc-in20-rd15 KLYS:LI21:K2:L1X) */ #ifdef LLRF_KLY_L1X_NG if ( ! llrfStationInitialize( LLRF_KLY_L1X ) ) rc = -1; #endif #elif defined LLRF_KLY_PAD2 /* Station 1 Multicasting group ioc-in20-rf05-padg (eioc-in20-rd17 LLRF:IN20:RH:DGN) */ #ifdef LLRF_KLY_DGN_NG if ( ! llrfStationInitialize( LLRF_KLY_DGN ) ) rc = -1; #endif /* Station 2 Multicasting group ioc-in20-rf05-padg (eioc-in20-rd10 KLYS:LI20:K5:TC0) */ #ifdef LLRF_KLY_TC0_NG if ( ! llrfStationInitialize( LLRF_KLY_TC0 ) ) rc = -1; #endif /* Station 3 Multicasting group ioc-in20-rf05-padg (eioc-in20-rd05 KLYS:LI20:K6:GUN) */ #ifdef LLRF_KLY_GUN_NG if ( ! llrfStationInitialize( LLRF_KLY_GUN ) ) rc = -1; #endif #elif defined LLRF_XTCAV /* Station 1 Multicasting group ioc-dmp1-rf01-padg (eioc-dmp1-rd01 TCAV:DMP1:360:TCA) or ioc-li20-rf01-padg (eioc-li20-rf11 TCAV:LI20:2400:TCA) */ #ifdef LLRF_XTCAVA_NG if ( ! llrfStationInitialize( LLRF_XTCAVA ) ) rc = -1; #endif /* Station 2 Multicasting group ioc-dmp1-rf01-padg (eioc-dmp1-rd02 TCAV:DMP1:360:TCB) */ #ifdef LLRF_XTCAVB_NG if ( ! llrfStationInitialize( LLRF_XTCAVB ) ) rc = -1; #endif /* Station 3 Multicasting group ioc-dmp1-rf01-padg (eioc-dmp1-rd03 KLYS:DMP1:K1:TCA) or ioc-li20-rf01-padg (eioc-li20-rf12 KLYS:LI20:K4:TCA) */ #ifdef LLRF_KLY_XTCAV_NG if ( ! llrfStationInitialize( LLRF_KLY_XTCAV ) ) rc = -1; #endif #else /* Station 1 Multicasting group ioc-in20-rf02-padg (eioc-in20-rd16 LASR:IN20:2:LSR) or ioc-as01-rf01-padg (eioc-as01-rf11 LASR:AS01:1:LSR) */ #ifdef LLRF_LSR_NG if ( ! llrfStationInitialize( LLRF_LSR ) ) rc = -1; /* scondam: 18-Mar-2014: LLRF_KLY_L2 unused as of date */ /* Station 1 Multicasting group ioc-li24-rf02-padg (eioc-li24-rd03 KLYS:LI24:K5:L2) */ /* #elif defined LLRF_KLY_L2_NG if ( ! llrfStationInitialize( LLRF_KLY_L2 ) ) rc = -1; */ #endif /* Station 2 Multicasting group ioc-in20-rf04-padg (eioc-in20-rd03 GUN:IN20:1:GN1) or ioc-as01-rf01-padg (eioc-as01-rf12 GUN:AS01:1:GN1) */ #ifdef LLRF_GUN_NG if ( ! llrfStationInitialize( LLRF_GUN ) ) rc = -1; #endif /* Station 21 Multicasting group ioc-in20-rf06-padg (eioc-in20-rd04 GUN:IN20:1:GN2) or ioc-as01-rf01-padg (eioc-as01-rf13 GUN:AS01:1:GN2) */ #ifdef LLRF_GN2_NG if ( ! llrfStationInitialize( LLRF_GN2 ) ) rc = -1; #endif /* Station 3 Multicasting group ioc-in20-rf04-padg (eioc-in20-rd06 ACCL:IN20:350:L0) */ #ifdef LLRF_L0A_NG if ( ! llrfStationInitialize( LLRF_L0A ) ) rc = -1; #endif /* Station 4 Multicasting group ioc-in20-rf04-padg */ #ifdef LLRF_L0B_NG if ( ! llrfStationInitialize( LLRF_L0B ) ) rc = -1; #endif /* Station 5 Multicasting group ioc-in20-rf01-padg (eioc-in20-rd11 ACCL:LI21:1:L1S) */ #ifdef LLRF_L1S_NG if ( ! llrfStationInitialize( LLRF_L1S ) ) rc = -1; #endif /* Station 6 Multicasting group ioc-in20-rf01-padg (eioc-in20-rd14 ACCL:LI21:180:L1X) */ #ifdef LLRF_L1X_NG if ( ! llrfStationInitialize( LLRF_L1X ) ) rc = -1; #endif /* Station 7 Multicasting group ioc-in20-rf06-padg (eioc-in20-rd09 TCAV:IN20:490:TC0) */ #ifdef LLRF_TCAV0_NG if ( ! llrfStationInitialize( LLRF_TCAV0 ) ) rc = -1; #endif /* Station 8 Multicasting group ioc-li24-rf01-padg (eioc-li24-rd01 TCAV:LI24:800:TC3) */ #ifdef LLRF_TCAV3_NG if ( ! llrfStationInitialize( LLRF_TCAV3 ) ) rc = -1; #endif /* Station 9 Multicasting group ioc-li24-rf02-padg (eioc-in20-rd13 PCAV:IN20:365:PH1) */ #ifdef LLRF_PCAV1_NG if ( ! llrfStationInitialize( LLRF_PCAV1 ) ) rc = -1; #endif /* Station 10 Multicasting group ioc-li24-rf02-padg */ #ifdef LLRF_PCAV2_NG if ( ! llrfStationInitialize( LLRF_PCAV2 ) ) rc = -1; #endif /* Station 11 Multicasting group ioc-li24-rf03-padg (eioc-li24-rd02 PCAV:LI25:300:PH3) */ #ifdef LLRF_PCAV3_NG if ( ! llrfStationInitialize( LLRF_PCAV3 ) ) rc = -1; #endif /* Station 12 Multicasting group ioc-li24-rf02-padg (eioc-li29-rd01 PCAV:LI29:100:PH4) */ #ifdef LLRF_PCAV4_NG if ( ! llrfStationInitialize( LLRF_PCAV4 ) ) rc = -1; #endif /* Station 19 Multicasting group ioc-in20-rf01-padg (eioc-in20-rd01 LLRF:IN20:RH:REF) */ #ifdef LLRF_IN20REF_NG if ( ! llrfStationInitialize( LLRF_IN20REF ) ) rc = -1; #endif /* Station 20 Multicasting group ioc-in20-rf02-padg (eioc-in20-rd02 LASR:IN20:1:LSR) */ #ifdef LLRF_LSRDIAG_NG if ( ! llrfStationInitialize( LLRF_LSRDIAG ) ) rc = -1; /* Station 20 Multicasting group ioc-dmp1-rf01-padg (eioc-dmp1-rd04 KLYS:DMP1:K1:INTR) or ioc-li20-rf01-padg (eioc-li20-rf21 KLYS:LI20:K1:INTR) or ioc-as01-rf01-padg (eioc-as01-rf14 KLYS:AS01:K1:INTR) */ /* #elif defined LLRF_INTRLK_NG if ( ! llrfStationInitialize( LLRF_INTRLK ) ) rc = -1; */ #endif /* Station 22 Multicasting group ioc-li24-rf03-padg () or ioc-as01-rf01 (eioc-as01-rf14 KLYS:AS01:K1:TS1 */ #ifdef LLRF_KLY24_5_NG if ( ! llrfStationInitialize( LLRF_KLY24_5 ) ) rc = -1; #endif #endif return rc; } /*============================================================================= Name: llrfGetStation(int station) Abs: =============================================================================*/ LlrfStation llrfGetStation(int station) { if ( station < 1 || station > LLRF_STATION_NUM_TYPES ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPadFlag, ("llrfGetStation: unrecognized station: %d\n", station)); #endif return 0; } /* station is one-based */ return llrf_stations[station - 1]; } int drvllrf_debug=0; /*=============================================================================*/ void llrfDumpVec(int s, int c) { LlrfStation sta_p = llrfGetStation(s); int i; if ( !sta_p || c < 0 || c >= sizeof(sta_p->chnls)/sizeof(sta_p->chnls[0]) ) return; for ( i = 0; i < sizeof(sta_p->chnls[0].vec)/sizeof(sta_p->chnls[0].vec[0]); i++ ) { errlogPrintf("%li ", (long)sta_p->chnls[c].vec[i]); } errlogPrintf("\n"); } /*============================================================================= Name: llrfGetPadDoubleValue Abs: =============================================================================*/ double llrfGetPadDoubleValue(unsigned station, unsigned channel, unsigned sample, epicsTimeStamp *ts_p, unsigned attr) { double rval; LlrfStation sta_p; unsigned tout; if ( station < 1 || station > LLRF_STATION_NUM_TYPES ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPadFlag, ("llrfGetPadDoubleValue: unrecognized station: %d\n", station)); #endif return 0./0. /* NaN */; } if ( channel < 0 || channel >= PAD_NUM_CHANNELS_ON_BOARD ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPadFlag, ("llrfGetPadDoubleValue: unrecognized channel: %d\n", channel)); #endif return 0./0. /* NaN */; } /* station is one-based */ station--; if ( ! (sta_p = llrf_stations[station]) ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPadFlag, ("llrfGetPadDoubleValue: station: %d not configured/initialized\n", station+1)); #endif return 0./0. /* NaN */; } epicsMutexMustLock( sta_p->mutex ); if ((sample) && (sta_p->chnls[channel].Samples)) { /* sample 1 ? */ switch (attr) { case PHASE: rval = sta_p->chnls[channel].Samples->Phase; break; case AMPLITUDE: rval = sta_p->chnls[channel].Samples->Amplitude; break; case POWER: rval = sta_p->chnls[channel].Samples->Power; break; default:errlogPrintf("llrfGetPadDoubleValue: Sample: invalid attribute: %d\n", attr); break; } } else { switch (attr) { case PHASE: rval = sta_p->chnls[channel].Phase; break; case AMPLITUDE: rval = sta_p->chnls[channel].Amplitude; break; case POWER: rval = sta_p->chnls[channel].Power; break; case ROTATEDI: rval = sta_p->chnls[channel].rotatedI; break; case ROTATEDQ: rval = sta_p->chnls[channel].rotatedQ; break; case ROTPHASE: rval = sta_p->chnls[channel].rotatedPhase; break; case NONROTPHASE: rval = sta_p->chnls[channel].nonRotatedPhase; break; case PACT: rval = sta_p->actual_phase; break; case AACT: rval = sta_p->actual_ampl; break; case PDES: rval = sta_p->desired_phase; break; case PDES2856: rval = sta_p->desired_phase2856; break; case PDES68: rval = sta_p->desired_phase68; break; /* case PDES119: rval = (double) sta_p->desired_phase119; break; */ default:errlogPrintf("llrfGetPadDoubleValue: invalid attribute: %d\n", attr); break; } } if ( ts_p ) *ts_p = sta_p->tsSum; tout = sta_p->timedout; epicsMutexUnlock( sta_p->mutex ); /* return NaN if this channel is timed out */ if ( (tout & LLRF_TIMEDOUT(channel)) ) { rval = 0./0.; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPadFlag, ("llrfGetPadDoubleValue: Attr: %d %s for %s ch%d: %g\n", attr, channel < PAD_NUM_CHANNELS_ON_BOARD ? "Value" : "Error", llrf_station_names[station+1], channel, rval)); #endif return rval; } /*============================================================================= Name: llrfGetPadIntegerValue Abs: =============================================================================*/ LlrfOutNumber llrfGetPadIntegerValue(unsigned station, unsigned channel, unsigned sample, epicsTimeStamp *ts_p, unsigned attr) { LlrfOutNumber rval; LlrfStation sta_p; unsigned tout; if ( station < 1 || station > LLRF_STATION_NUM_TYPES ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPadFlag, ("llrfGetPadIntegerValue: unrecognized station: %d\n", station)); #endif return 0./0. /* NaN */; } if ( channel < 0 || channel >= PAD_NUM_CHANNELS_ON_BOARD ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPadFlag, ("llrfGetPadIntegerValue: unrecognized channel: %d\n", channel)); #endif return 0./0. /* NaN */; } /* station is one-based */ station--; if ( ! (sta_p = llrf_stations[station]) ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPadFlag, ("llrfGetPadIntegerValue: station: %d not configured/initialized\n", station+1)); #endif return 0./0. /* NaN */; } epicsMutexMustLock( sta_p->mutex ); if ((sample) && (sta_p->chnls[channel].Samples)) { /* sample 1 ? */ switch (attr) { case IAVG: rval = (LlrfOutNumber) sta_p->chnls[channel].Samples->I; break; /* same as SAVG */ case QAVG: rval = (LlrfOutNumber) sta_p->chnls[channel].Samples->Q; break; case OVRFLOW: rval = sta_p->chnls[channel].Overflow; break; case ALIGN_START: rval = (LlrfOutNumber) sta_p->chnls[channel].Samples->aligned_start; break; case ALIGN_END: rval = (LlrfOutNumber) sta_p->chnls[channel].Samples->aligned_end; break; case MIDPOINT: rval = (LlrfOutNumber) sta_p->chnls[channel].Samples->x; break; default:errlogPrintf("llrfGetPadIntegerValue: Sample: invalid attribute: %d\n", attr); break; } } else { switch (attr) { case IAVG: rval = (LlrfOutNumber) sta_p->chnls[channel].I; break; /* same as SAVG */ case QAVG: rval = (LlrfOutNumber) sta_p->chnls[channel].Q; break; case OVRFLOW: rval = sta_p->chnls[channel].Overflow; break; case ALIGN_START: rval = (LlrfOutNumber) sta_p->chnls[channel].aligned_start; break; case ALIGN_END: rval = (LlrfOutNumber) sta_p->chnls[channel].aligned_end; break; case MIDPOINT: rval = (LlrfOutNumber) sta_p->chnls[channel].x; break; default:errlogPrintf("llrfGetPadIntegerValue: invalid attribute: %d\n", attr); break; } } if ( ts_p ) *ts_p = sta_p->tsSum; tout = sta_p->timedout; epicsMutexUnlock( sta_p->mutex ); /* return NaN if this channel is timed out */ if ( (tout & LLRF_TIMEDOUT(channel)) ) { rval = 0./0.; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPadFlag, ("llrfGetPadIntegerValue: %s for %s ch%d: %d\n", channel < PAD_NUM_CHANNELS_ON_BOARD ? "Value" : "Error", llrf_station_names[station+1], channel, rval)); #endif return rval; } /*============================================================================= Name: llrfSetPadValue Abs: =============================================================================*/ int llrfSetPadValue(int station, int channel, unsigned sample, double val, unsigned attr) { LlrfStation sta_p; if ( station < 1 || station > LLRF_STATION_NUM_TYPES ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPadFlag, ("llrfSetPadValue: unrecognized station: %d\n", station)); #endif return 0./0. /* NaN */; } if ( channel < 0 || channel >= PAD_NUM_CHANNELS_ON_BOARD ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPadFlag, ("llrfSetPadValue: unrecognized channel: %d\n", channel)); #endif return 0./0. /* NaN */; } /* station is one-based */ station--; if ( ! (sta_p = llrf_stations[station]) ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPadFlag, ("llrfSetPadValue: station: %d not configured/initialized\n", station+1)); #endif return 0./0. /* NaN */; } epicsMutexMustLock( sta_p->mutex ); if ((sample) && (sta_p->chnls[channel].Samples)) { /* sample 1 ? */ switch (attr) { case OFST: sta_p->chnls[channel].Samples->ofst = (LlrfOutNumber) val; break; case SIZE: sta_p->chnls[channel].Samples->size = (LlrfOutNumber) val; break; case FREQ: sta_p->chnls[channel].freq = (LlrfOutNumber) val; break; case POC: sta_p->chnls[channel].poc = val; break; case AVC: sta_p->chnls[channel].avc = val; break; case APC: sta_p->chnls[channel].apc = val; break; default:errlogPrintf("llrfSetPadValue: Sample: invalid attribute: %d\n", attr); break; } } else { switch (attr) { case OFST: sta_p->chnls[channel].ofst = (LlrfOutNumber) val; break; case SIZE: sta_p->chnls[channel].size = (LlrfOutNumber) val; break; case FREQ: sta_p->chnls[channel].freq = (LlrfOutNumber) val; break; case POC: sta_p->chnls[channel].poc = val; break; case AVC: sta_p->chnls[channel].avc = val; break; case APC: sta_p->chnls[channel].apc = val; break; case MON_PDES: sta_p->mon_desired_phase = val; break; case MON_IADJ: sta_p->mon_iadjust = val; break; case MON_QADJ: sta_p->mon_qadjust = val; break; case MON_POC: sta_p->mon_poc = val; break; default:errlogPrintf("llrfSetPadValue: invalid attribute: %d\n", attr); break; } } epicsMutexUnlock( sta_p->mutex ); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPadFlag, ("llrfSetPadValue: %s for %s ch%d: %d\n", channel < PAD_NUM_CHANNELS_ON_BOARD ? "Value" : "Error", llrf_station_names[station+1], channel, val)); #endif return 0; } /* Laser Subsytem PV OSC:LR20:xyz:PDES set point (or the laser desired phase) is in 2856 degress */ int lsrDiagSetDesiredPhase(int station, double phase) { LlrfStation sta_p; if ( station < 1 || station > LLRF_STATION_NUM_TYPES ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPadFlag, ("lsrDiagSetDesiredPhase: unrecognized station: %d\n", station)); #endif return 0./0. /* NaN */; } /* station is one-based */ station--; if ( ! (sta_p = llrf_stations[station]) ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPadFlag, ("lsrDiagSetDesiredPhase: station: %d not configured/initialized\n", station+1)); #endif return 0./0. /* NaN */; } epicsMutexMustLock( sta_p->mutex ); switch (sta_p->index) { case LLRF_LSRDIAG: case LLRF_LSR: sta_p->desired_phase2856 = phase; switch (sta_p->input_source) { case LSR_2856_MHZ_SOURCE: /* Use Laser PAD channel 0: 2856 MHz for input. With Laser SPAC output: 476 MHz, conversion factor is 1/6 */ sta_p->desired_phase = (phase/6.0); /* the rotated-by-PDES2856 phase */ break; #ifdef LLRF_LSR68_NG case LSR_68_MHZ_SOURCE: /* Use Laser PAD channel 2: 68 MHz for input. With Laser SPAC output: 476 MHz, conversion factor is 7 */ sta_p->desired_phase68 = (phase/6.)*7.0; /* the rotated-by-PDES68 phase */ break; #elif LLRF_LSR119_NG case LSR_119_MHZ_SOURCE: /* Use Laser PAD channel 2: 119 MHz for input. With Laser SPAC output: 476 MHz, conversion factor is 4 */ sta_p->desired_phase119 = (phase/6.)*4.0; /* the rotated-by-PDES119 phase */ break; #endif default: errlogPrintf("invalid input source\n"); break; } break; default:errlogPrintf("invalid station\n"); break; } epicsMutexUnlock( sta_p->mutex ); return 0; } /* Laser Subsytem PV OSC:LR20:xyz:POC phase offset is in 2856 degress */ int lsrDiagSetDesiredPhaseOffset(int station, double poc) { LlrfStation sta_p; if ( station < 1 || station > LLRF_STATION_NUM_TYPES ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPadFlag, ("lsrDiagSetDesiredPhase: unrecognized station: %d\n", station)); #endif return 0./0. /* NaN */; } /* station is one-based */ station--; if ( ! (sta_p = llrf_stations[station]) ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPadFlag, ("lsrDiagSetDesiredPhase: station: %d not configured/initialized\n", station+1)); #endif return 0./0. /* NaN */; } epicsMutexMustLock( sta_p->mutex ); switch (sta_p->index) { case LLRF_LSRDIAG: case LLRF_LSR: switch (sta_p->input_source) { case LSR_2856_MHZ_SOURCE: /* Use Laser PAD channel 0: 2856 MHz for input.*/ sta_p->chnls[0].poc = poc; break; #ifdef LLRF_LSR68_NG case LSR_68_MHZ_SOURCE: /* Use Laser PAD channel 2: 68 MHz for input.*/ sta_p->chnls[2].poc = poc; break; #elif LLRF_LSR119_NG case LSR_119_MHZ_SOURCE: /* Use Laser PAD channel 2: 119 MHz for input.*/ sta_p->chnls[2].poc = poc; break; #endif default: errlogPrintf("invalid input source\n"); break; } break; default:errlogPrintf("invalid station\n"); break; } epicsMutexUnlock( sta_p->mutex ); return 0; } int lsrDiagSetInputSource(int station, LlrfOutNumber source) { LlrfStation sta_p; if ( station < 1 || station > LLRF_STATION_NUM_TYPES ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPadFlag, ("lsrDiagSetInputSource: unrecognized station: %d\n", station)); #endif return 0./0. /* NaN */; } if ( source < 0 || source > LLRF_LSR_SOURCE_TYPES ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPadFlag, ("lsrDiagSetInputSource: unrecognized source: %d\n", source)); #endif return 0./0. /* NaN */; } /* station is one-based */ station--; if ( ! (sta_p = llrf_stations[station]) ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPadFlag, ("lsrDiagSetInputSource: station: %d not configured/initialized\n", station+1)); #endif return 0./0. /* NaN */; } epicsMutexMustLock( sta_p->mutex ); switch (sta_p->index) { case LLRF_LSRDIAG: case LLRF_LSR: /* Set new value of desired phase */ /* When the source changes, calculate desired phase from selected source */ switch (source) { case LSR_2856_MHZ_SOURCE: sta_p->desired_phase = sta_p->desired_phase2856/6.; break; #ifdef LLRF_LSR68_NG case LSR_68_MHZ_SOURCE: sta_p->desired_phase = sta_p->desired_phase68*7.; break; #elif LLRF_LSR119_NG case LSR_119_MHZ_SOURCE: sta_p->desired_phase = sta_p->desired_phase119*4.; break; #endif default:errlogPrintf("invalid source: %d\n",source); break; } break; default:errlogPrintf("invalid station\n"); break; } epicsMutexUnlock( sta_p->mutex ); return 0; } /*============================================================================= */ /* Estimate system clock freq */ double sysClkPeriodGet() { epicsTimeStamp then,now; struct timespec slp; int st,i; slp.tv_sec = 0; slp.tv_nsec = 1; /* try a few times if nanosleep() fails */ for ( i=0; i<10; i++ ) { if ( epicsTimeGetCurrent( &then ) ) break; st = nanosleep( &slp, 0 ); if ( epicsTimeGetCurrent( &now ) ) break; if ( 0 == st ) return epicsTimeDiffInSeconds( &now, &then ); } /* Infinity */ return 1.0/0.0; } /*============================================================================= */ /*============================================================================= Name: padGetYIntercept(y1, y2) Abs: from a pair of y-values (and globally-available, corresponding x-values) calculate first the slope, m=(y2-y1)/(x2-x1), and then the y-intercept, b=y-mx. Ret: y-intercept =============================================================================*/ long padGetYIntercept(int x1, long y1, int x2, long y2) { long m; long b; if (x2 != x1) { m = (y2 - y1)/(long)(x2 - x1); b = y2 - m*x2; } else { /* padGetYIntercept: vertical lines. slopes are infinite */ return 0./0. /* NaN */; } return b; } /*=============================================================================*/