/*============================================================ Filename: tmSub.c Abs: This file contains all TMATRIX access routines Device Support Routines: Initlaization --------------- tmInit Gerneric Initalization tmBootInit Initialidation for tmBoot tmDelayInit Initialization for tmDelay tmRuleInit Initialization for tmRule and tmRuleType tmRuleDefInit Initialization for tmRuleDef tmRuleMskInit Initialization for tmRuleMsk Functions --------------- tmBoot Initalize rules and beamcode arrays on boot or mode chg. tmDelay Calc total dealy w/o deactivte flag (nsec) tmDelayDeact Calc total delay with deactivate flag (ticks) tmModeLimits Set the trigger mode read back severity tmPttLimits Set PTT limits based on mode tmRule Trigger channel rule processing tmRuleDef Get default or conditional rule for a specified beamcode tmRuleMsk Trigger rule 32-bit mask or 16-bit beamcode tmGetTmva Calcualte timing value tmRuleType Determinet the rule type tmBoot Initalization waveforms on boot. tmGetDelay Get rule total delay w/o deactivate flag (nsec) tmGetStat Set trigger status summary bitmask tmGetTmsk Set timing delay for Modulo-36 mode tmTmva Set tmva waveform Utilities --------- tmCheckDbLink tmRuleCopy tmRuleOk tmRuleTypeGet tmRuleTypeSetUnassigned Rem: All functions called by a subroutine record that is passed one argument, a pointer to the record type structure. Within this file there are three types of subroutine records used: subRecord,longSubRecord and genSubRecord. Below is an example of the input argument for a longSubRecord. rec_ps Pointer to the subroutine record data. Use: pointer Type: struct longSubRecord * Acc: read/write Mech: reference All functions return a long integer. 0 = OK, -1 = ERROR. The subroutine record ignores the status returned by the Init routines. For the calculation routines, the record status (STAT) is set to SOFT_ALARM (unless it is already set to LINK_ALARM due to severity maximization) and the severity (SEVR) is set to rec_ps->brsv (BRSV - set by the user in the database though it is expected to be invalid). Auth: 06-Dec-2010, Kristi Luchini (LUCHINI) Rev: dd-mmm-yyyy, Reviewer's Name (USERNAME --------------------------------------------------------------*/ #include "copyright_SLAC.h" /* SLAC copyright comments */ /*------------------------------------------------------------- Mod: 23-Mar-2023, K. Luchini (LUCHINI): epics V7 upgradereplace dbAccess.h with dbAccessDefs.h replace genSubRecord with aSubRecord add basicIoOps.h chg some "long" to int32_t chg some "unsigned long" to uint32_t 29-May-2012, K. Luchini (LUCHINI): fix warnings seen when upgrading to EPICSR3.14.12 14-Nov-2011, K. Luchini (LUCHINI): added tmPttLimits() ==============================================================*/ /* Header files */ #include "stdio.h" #include "stdlib.h" #include "string.h" #include #if EPICS_VERSION>3 || (EPICS_VERSION==3 && EPICS_REVISION>=14) #include "registryFunction.h" /* for epicsExport */ #include "epicsExport.h" /* for epicsRegisterFunction */ #endif #include "debugPrint.h" /* for DEBUGPRINT,EDEF_MAX */ #include "devLib.h" /* S_dev_noDevice */ #include "dbAccess.h" /* for DBADDR */ #include "recSup.h" /* for S_rec_outMem */ #include "recGbl.h" /* for recGblRecordError() */ #include "devSup.h" /* for S_dev_noDeviceFound */ #include "dbFldTypes.h" /* for DBF_USHORT */ #include "epicsTypes.h" /* epicsBoolean,MAX_STRING_SIZE */ #include "alarm.h" /* NO_ALARM, MAJOR_ALARM */ #include "aoRecord.h" /* for aoRecord */ #include "subRecord.h" /* for subRecord */ #include "aSubRecord.h" /* for aSubRecord */ #include "waveformRecord.h" /* for waveformRecord */ #include "longSubRecord.h" /* for struct longSubRecord */ #include "evrPattern.h" #include "tmSub.h" /* for tmGetInfo_ts,tmRuleDef */ #include "basicIoOps.h" /* for int32_t, uint32_t */ /* Global varaible */ volatile int TM_SUB_DEBUG = 0; /* Debug flag */ #if EPICS_VERSION>3 || (EPICS_VERSION==3 && EPICS_REVISION>=14) epicsExportAddress(int, TM_SUB_DEBUG); #endif // mdunning 8/3/17: define macro dbGetPdbAddrFromLink below, due to its removal in base 3.15 #define dbGetPdbAddrFromLink(PLNK) \ ( ( (PLNK)->type != DB_LINK ) \ ? 0 \ : ( ( (struct dbAddr *)( (PLNK)->value.pv_link.pvt) ) ) ) #define min(x, y) (((x) < (y)) ? (x) : (y)) /* Local prototypes */ static long tmInit(aSubRecord *rec_ps); static long tmBootInit(aSubRecord *rec_ps); static long tmDelayInit(aSubRecord *rec_ps); static long tmRuleInit(aSubRecord *rec_ps); static long tmRuleDefInit(longSubRecord *rec_ps); static long tmRuleMskInit(longSubRecord *rec_ps); static long tmBoot(aSubRecord *rec_ps); static long tmDelay(struct aSubRecord *rec_ps); static long tmDelayDeact(struct longSubRecord *rec_ps); static long tmModeLimits(struct aSubRecord *rec_ps); static long tmPttLimits(struct aSubRecord *rec_ps); static long tmRule(aSubRecord *rec_ps); static long tmRuleDef(struct longSubRecord *rec_ps); static long tmRuleMsk(longSubRecord *rec_ps); static long tmRuleTmva(struct aSubRecord *rec_ps); static long tmRuleType(struct aSubRecord *rec_ps); static long tmGetDelay(struct aSubRecord *rec_ps); static long tmGetStat(longSubRecord *rec_ps); static long tmGetTmsk(longSubRecord *rec_ps); static long tmTmva(aSubRecord *rec_ps); static uint32_t tmRuleCopy(unsigned short *idata_a, unsigned short *odata_a ); static uint32_t tmRuleTypeSetUnassigned(char *desc_c, unsigned short *data_a); static long tmCheckDbLink( const struct link *link_ps, short type, int32_t nelem, waveformRecord **wf_pps ); static long tmRuleTypeGet( uint32_t beamcode, uint32_t num, const unsigned short *data_a, const char *desc_c, unsigned short *type_p ); /*============================================================================= Name: tmDelayInit Abs: Inialize record that calculates total time delay without deactivate request Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- aSubRecord * rec__ps read point to subroutine record Rem: Init subroutine for _TDLYCALC :BEAMCODE_TDLYCALC Input: -------- A = Trigger mode :MODE.RVAL B = Module delay w.r.t. fidicual :TREF C = Delta delay w.r.t. TREF :RULE_TDES or :BEAMCODE_TDES D = Channel delay w.r.t. TDEF :TDEF E = TNOM (used if K0) TRIG::1:BEAMCODE_TNOM F = Use TNOM flag (used if K=0) TRIG:SYS0:1:BEAMCODE_USE_TNOM.RVAL G = Beamcode :RULE_BEAMCODE H = Default rule (0-7 or 65535 for none) :RULE_DEF I = Array of default rule delays indexed by beamcode :BEAMCODE_TDLY J = K = rule fllag. If set to 1, then :RULE_TDLYCALC Otherise, we have :BEAMCODE_TDLYCALC L = debug flag Output: -------- DPVT = Pointer to private device information structure (for k==0 only) VALA = total delay without deactivate flag VALB = array of default rules total delay. Array indexed by beamcode (used if K=0) Side: None Ret: long OK - Successful ERROR - Failed initalization ==============================================================================*/ static long tmDelayInit(aSubRecord *rec_ps) { long status = ERROR; waveformRecord *in_wf_ps = NULL; waveformRecord *out_wf_ps = NULL; tmDelay_ts *dpvt_ps = NULL; /* Check that this pv has not already been initialized */ if (rec_ps->dpvt) return(status); rec_ps->dpvt = 0; /* * Get the pointer to the output array of default rule delays. * Do we have a DB_LINK? If so, then verify the data type and * it has the correct number of elements expected. */ status = tmCheckDbLink( &rec_ps->inpi,DBF_DOUBLE,N_BEAMCODES+1,&in_wf_ps); if (status) recGblRecordError(S_dev_badInpType,(void *)rec_ps,"tmDelayInit: bad INPI field"); /* * If we are calculating the total delay for the default * rule then proceed. Otherwise, exit successfully. */ else if ( *(int32_t *)rec_ps->k==0 ) { /* * Is this for a beamcode related pv :BEAMCODE_TDLYCALC * If yes, then we should have an output link pointing to an array of doubles. * Verify that the array is of the expected size and data type. */ status = tmCheckDbLink( &rec_ps->outb,DBF_DOUBLE,N_BEAMCODES+1,&out_wf_ps); if (status) recGblRecordError(S_dev_badOutType,(void *)rec_ps,"tmDelayInit: bad OUTB field"); else { /* Create pointer for private device information to be used when record is processed */ dpvt_ps = (tmDelay_ts *)calloc(sizeof(tmDelay_ts),1); if (!dpvt_ps) recGblRecordError(S_rec_outMem,(void *)rec_ps,"tmDelayInit: failed"); else { /* Set the private data information */ dpvt_ps->in_s.data_a = (double *)rec_ps->i; /* ptr to :BEAMCODE_TDLY */ dpvt_ps->in_s.nord_p = (uint32_t *)(&in_wf_ps->nord); /* ptr to num or waveform items */ dpvt_ps->in_s.nelem = rec_ps->noi; /* max waveform items in record */ if (*(int32_t *)rec_ps->k==0) { dpvt_ps->out_s.data_a = (double *)rec_ps->valb; /* ptr to :BEAMCODE_TDLY */ dpvt_ps->out_s.nord_p = (uint32_t *)(&out_wf_ps->nord); /* ptr to num or waveform items */ dpvt_ps->out_s.nelem = rec_ps->novb; /* max waveform items in record */ } rec_ps->dpvt = dpvt_ps; } } } if (status) status = ERROR; return( status ); } /*============================================================================= Name: tmRuleMskInit Abs: Inialize record for extracting an element from an array Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- longSubRecord * rec__ps read point to subroutine record Rem: Init subroutine for :RULE_INCL :RULE_EXCL :RULE_BEAMCODE Input: -------- A = Array B = index into wavform record (based on INPC) C = Data type extracting (2=short,4=long) Output: -------- DPVT = Pointer to private device information structure Side: None Ret: long OK - Successful ERROR - Failed initalization ==============================================================================*/ static long tmRuleMskInit(longSubRecord *rec_ps) { long status = ERROR; uint32_t wf_nbytes = 0; uint32_t nbytes = 0; DBADDR *addr_ps = NULL; waveformRecord *wf_ps = NULL; tmGetInfo_ts *dpvt_ps = NULL; /* Check that this pv has not already been initialized */ if (rec_ps->dpvt) return(status); rec_ps->dpvt = 0; /* Get the pointer to the array that will be indexed. * Verify that we have a DB_LINK. */ addr_ps = dbGetPdbAddrFromLink(&rec_ps->inpa); if (!addr_ps) recGblRecordError(S_dev_noDeviceFound,(void *)rec_ps,"tmRuleMskInit: array not found"); else { wf_nbytes = addr_ps->field_size * addr_ps->no_elements; /* array bytes */ nbytes = rec_ps->c * (rec_ps->b+1); if (nbytes > wf_nbytes ) recGblRecordError(S_dev_lowValue,(void *)rec_ps,"tmRuleMskInit: array is too short"); else { status = OK; /* Create pointer for private device information to be used when record is processed */ dpvt_ps = (tmGetInfo_ts *)calloc(sizeof(tmGetInfo_ts),1); if (!dpvt_ps) recGblRecordError(S_rec_outMem,(void *)rec_ps,"tmRuleMskInit: failed"); else { /* Set the private data information */ rec_ps->dpvt = dpvt_ps; wf_ps = (waveformRecord *)addr_ps->precord; dpvt_ps->data_p = (unsigned short *)wf_ps->bptr; /* ptr to data :RULE */ dpvt_ps->nord_p = (uint32_t *)(&wf_ps->nord); /* ptr to num or waveform items */ dpvt_ps->nelem = addr_ps->no_elements; /* max waveform items in record */ dpvt_ps->nbytes = wf_nbytes; } } } return(status); } /*============================================================================= Name: tmRuleInit Abs: Process a rule change and determine rule type Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- aSubRecord * rec_ps read point to subroutine record Rem: Subroutine for TRIG:SYS0:1:RULE_PROC TRIG:::RULE_PROC Input: -------- A = :RULE_NUM Rule number (0-7) B = MODE_SET.RVAL Channel Mode (1=pp0,3=pp1,6-modulo-36,7-reuse) C = :RULE Trigger Rule This is a waveformm with 21 unsigned shorts 10 inclusive masks (16-bit words) 10 exclusive masks (16-bit words) 1 beam code. (16-bit words) D = E = :RULE.DESC Rule description Note: pv found in sioc-sys0-cv01 F = :TRIG_DEVNAME Trigger device name G = :BEAMCODE_DEF Array of default rules indexed by beamcode G = :BEAMCODE_COND Array. Each element is a bitmask of conditional rules assigned to that beam code. For example, if rule0 and 7 use beamcode 1, then bits 0 and 7 would be set in element 1 of the array. I = :BEAMCODE_TDLY Array of default rule delays, indexed by Beamcode. The delay does not include the deactivate flag. Note: beamcode 0 is a wildcard for all beamcodes, and it is not currently allowed. Currently, only beamcodes 1-4 are used. J = K = L = M = :DEBUG.RVAL Debug flag Output: -------- DPVT = Pointer to private device information structure Side: None Ret: long OK - Success ERROR - Failed ==============================================================================*/ static long tmRuleInit(aSubRecord *rec_ps) { long status = ERROR; DBADDR *addr_ps = NULL; waveformRecord *wf_ps = NULL; tmGetInfo_ts *dpvt_ps = NULL; char errmsg_c[80]; /* Check that this pv has not already been initialized */ if (rec_ps->dpvt) return(status); rec_ps->dpvt = 0; /* Get the pointer to the record in INPB * Is this a valid pv? If so, then verify that data type shorts. * Later need to verify that this is a wavefore record... */ addr_ps = dbGetPdbAddrFromLink(&rec_ps->inpc); if (!addr_ps) recGblRecordError(S_dev_noDeviceFound,(void *)rec_ps,"tmRuleInit: bad DB_LINK"); else if (addr_ps->field_type != DBF_USHORT) recGblRecordError(S_dev_badInpType,(void *)rec_ps,"tmRuleInit: bad field, expect USHORT"); else if (addr_ps->no_elements < PDU_RULE_WF_SIZE) { sprintf(errmsg_c, "tmRuleInit: array is too short (%ld)",addr_ps->no_elements); recGblRecordError(S_dev_lowValue,(void *)rec_ps,errmsg_c); } else { /* Create pointer for private device information to be used when record is processed */ dpvt_ps = (tmGetInfo_ts *)calloc(sizeof(tmGetInfo_ts),1); if (!dpvt_ps) recGblRecordError(S_rec_outMem,(void *)rec_ps,"tmRuleInit: failed"); else { /* Set the private data information */ wf_ps = (waveformRecord *)addr_ps->precord; dpvt_ps->data_p = (unsigned short *)wf_ps->bptr; /* ptr to data :RULE */ dpvt_ps->nord_p = (uint32_t *)(&wf_ps->nord); /* ptr to num or waveform items */ dpvt_ps->nelem = addr_ps->no_elements; /* max waveform items in record */ dpvt_ps->desc_c = wf_ps->desc; /* description of pv record */ rec_ps->dpvt = dpvt_ps; status = OK; } } return(status); } /*============================================================================= Name: tmRuleDefInit Abs: Inialize record that extracts default rule or conditional rules from an array Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- longSubRecord * rec_ps read point to subroutine record Rem: Init subroutine for :BEAMCODE_COND :BEAMCODE_DEF :RULE_DEF Input: -------- INPA = array of default or bitmask of conditional rules INPB = beamcode (1-255) INPC = INPD = trigger channel mode (1=pp0,3=pp1,6=modulo36,7=reuse) INPE = default value if rules do not apply. Output: -------- DPVT = Pointer to private device information structure Side: None Ret: long OK - Successful ERROR - Failed initalization ==============================================================================*/ static long tmRuleDefInit(longSubRecord *rec_ps) { long status = ERROR; DBADDR *addr_ps = NULL; waveformRecord *wf_ps = NULL; tmRuleDef_ts *dpvt_ps = NULL; /* Check that this pv has not already been initialized */ if (rec_ps->dpvt) return(status); rec_ps->dpvt = 0; /* * Get the pointer to the record in INPA. * Is this a DB_LINK? If so, then verify that data type. */ addr_ps = dbGetPdbAddrFromLink(&rec_ps->inpa); if (!addr_ps) recGblRecordError(S_dev_noDeviceFound,(void *)rec_ps,"tmRuleDefInit: bad field, INPA is not a DB_LINK"); else if (addr_ps->field_type != DBF_ULONG) recGblRecordError(S_dev_badInpType,(void *)rec_ps,"tmRuleDefInit: bad field, array must be of type ULONG"); else if (addr_ps->no_elements <= N_BEAMCODES ) recGblRecordError(S_dev_lowValue,(void *)rec_ps,"tmRuleDefInit: array is too short"); else { /* Create pointer for private device information to be used when record is processed */ dpvt_ps = (tmRuleDef_ts *)calloc(sizeof(tmRuleDef_ts),1); if (!dpvt_ps) recGblRecordError(S_rec_outMem,(void *)rec_ps,"tmRuleDeftInit: failed"); else { rec_ps->dpvt = dpvt_ps; wf_ps = (waveformRecord *)addr_ps->precord; dpvt_ps->data_a = (uint32_t *)wf_ps->bptr; /* ptr to data :RULE */ dpvt_ps->nord_p = (uint32_t *)(&wf_ps->nord); /* ptr to num or waveform items */ dpvt_ps->nelem = addr_ps->no_elements; /* max waveform items in record */ status = OK; } } return(status); } /*============================================================================= Name: tmBootInit Abs: Initalization subroutine for pv tmBoot Args: Type Name Access Description ------------- ----------- ---------- ---------------------------- aSubRecord * rec_ps read/write ptr to subroutine record Rem: Subroutine for TRIG:::INIT Input: -------- A = Trigger channnel mode (1=pp0,3=pp1,6=modulo-36,7=reuse B = maximum beam code C = trigger device name D = Rule0 E = Rule1 F = Rule2 G = Rule3 H = Rule4 I = Rule5 J = Rule6 K = Rule7 Output: -------- DPVT = private device information - initalized by tmBootInit VALA = Default rule array of conditiona rules. Array indexed by beamcode VALB = Default rule array of default rules. Array indexed by beamcode VALC = Default rule array of total delays. Array indexed by beamcode VALD = Beamcode fanout record proc field (process after default array init) VALE = Rule0 VALF = Rule1 VALG = Rule2 VALH = Rule3 VALI = Rule4 VALJ = Rule5 VALK = Rule6 VALL = Rule7 Side: None Ret: long OK - Success ERROR - Failed to index into input array =============================================================================*/ static long tmBootInit(aSubRecord *rec_ps) { long status= ERROR; /* status return */ unsigned short i=0; /* input rules index counter */ unsigned short j=0; /* output rules index counter */ char msg_c[128]; /* error message string */ tmBoot_ts *dpvt_ps = NULL; /* ptr to private device info */ void **ival_pp = NULL; /* ptr to ptr to input data */ void **oval_pp = NULL; /* ptr to ptr to output data */ waveformRecord *inp_wf_aps[MAX_CHANNEL_RULES]={0,0,0,0,0,0,0,0}; waveformRecord *out_wf_aps[MAX_CHANNEL_RULES+3]={0,0,0,0,0,0,0,0,0,0,0}; char *inp_c[MAX_CHANNEL_RULES] = {"INPE","INPF","INPG","INPH","INPI","INPJ","INPK","INPL"}; char *out_c[MAX_CHANNEL_RULES+3] = {"OUTE","OUTF","OUTG","OUTH","OUTI","OUTJ","OUTK","OUTL","OUTA","OUTB","OUTC"}; /* Check that this pv has not already been initialized */ if (rec_ps->dpvt) return(status); rec_ps->dpvt = 0; status = tmCheckDbLink( &rec_ps->inpe,DBF_USHORT,PDU_RULE_WF_SIZE,&inp_wf_aps[i++] ); if (!status) status = tmCheckDbLink( &rec_ps->inpf,DBF_USHORT,PDU_RULE_WF_SIZE,&inp_wf_aps[i++] ); if (!status) status = tmCheckDbLink( &rec_ps->inpg,DBF_USHORT,PDU_RULE_WF_SIZE,&inp_wf_aps[i++] ); if (!status) status = tmCheckDbLink( &rec_ps->inph,DBF_USHORT,PDU_RULE_WF_SIZE,&inp_wf_aps[i++] ); if (!status) status = tmCheckDbLink( &rec_ps->inpi,DBF_USHORT,PDU_RULE_WF_SIZE,&inp_wf_aps[i++] ); if (!status) status = tmCheckDbLink( &rec_ps->inpj,DBF_USHORT,PDU_RULE_WF_SIZE,&inp_wf_aps[i++] ); if (!status) status = tmCheckDbLink( &rec_ps->inpk,DBF_USHORT,PDU_RULE_WF_SIZE,&inp_wf_aps[i++] ); if (!status) status = tmCheckDbLink( &rec_ps->inpl,DBF_USHORT,PDU_RULE_WF_SIZE,&inp_wf_aps[i++] ); if (status) { sprintf(msg_c,"tmBootInit: failed, bad field %s\n",inp_c[i-1]); recGblRecordError(S_dev_noDeviceFound,(void *)rec_ps,msg_c); return(ERROR); } if (!status) status = tmCheckDbLink( &rec_ps->oute,DBF_USHORT,PDU_RULE_WF_SIZE,&out_wf_aps[j++] ); if (!status) status = tmCheckDbLink( &rec_ps->outf,DBF_USHORT,PDU_RULE_WF_SIZE,&out_wf_aps[j++] ); if (!status) status = tmCheckDbLink( &rec_ps->outg,DBF_USHORT,PDU_RULE_WF_SIZE,&out_wf_aps[j++] ); if (!status) status = tmCheckDbLink( &rec_ps->outh,DBF_USHORT,PDU_RULE_WF_SIZE,&out_wf_aps[j++] ); if (!status) status = tmCheckDbLink( &rec_ps->outi,DBF_USHORT,PDU_RULE_WF_SIZE,&out_wf_aps[j++] ); if (!status) status = tmCheckDbLink( &rec_ps->outj,DBF_USHORT,PDU_RULE_WF_SIZE,&out_wf_aps[j++] ); if (!status) status = tmCheckDbLink( &rec_ps->outk,DBF_USHORT,PDU_RULE_WF_SIZE,&out_wf_aps[j++] ); if (!status) status = tmCheckDbLink( &rec_ps->outl,DBF_USHORT,PDU_RULE_WF_SIZE,&out_wf_aps[j++] ); if (!status) status = tmCheckDbLink( &rec_ps->outa,DBF_ULONG,N_BEAMCODES+1, &out_wf_aps[j++] ); if (!status) status = tmCheckDbLink( &rec_ps->outb,DBF_ULONG,N_BEAMCODES+1, &out_wf_aps[j++] ); if (!status) status = tmCheckDbLink( &rec_ps->outc,DBF_DOUBLE,N_BEAMCODES+1,&out_wf_aps[j++] ); if (status) { sprintf(msg_c,"tmBootInit: failed, bad field %s\n",out_c[j-1]); recGblRecordError(S_dev_noDeviceFound,(void *)rec_ps,msg_c); return(ERROR); } /* Create pointer for private device information to be used when record is processed */ dpvt_ps = (tmBoot_ts *)calloc(sizeof(tmBoot_ts),1); if (!dpvt_ps) { recGblRecordError(S_rec_outMem,(void *)rec_ps,"tmBootInit: failed"); return(ERROR); } /* Setup rule0 through rule7 info */ for ( i=0, ival_pp=&rec_ps->e, oval_pp=&rec_ps->vale; irule_as[i].data_p = (unsigned short *)*oval_pp; /* ptr to array */ dpvt_ps->rule_as[i].nord_p = (uint32_t *)(&out_wf_aps[i]->nord); /* no current elements */ dpvt_ps->rule_as[i].nelem = out_wf_aps[i]->nelm; /* max elements */ dpvt_ps->rule_as[i].nbytes = sizeof(short)*out_wf_aps[i]->nelm; dpvt_ps->rule_as[i].desc_c = out_wf_aps[i]->desc; dpvt_ps->in_rule_as[i].data_p = (unsigned short *)*ival_pp; dpvt_ps->in_rule_as[i].nord_p = (uint32_t *)(&inp_wf_aps[i]->nord); /* no current elements */ dpvt_ps->in_rule_as[i].nelem = inp_wf_aps[i]->nelm; /* max elements */ dpvt_ps->in_rule_as[i].nbytes = sizeof(short)*inp_wf_aps[i]->nelm; dpvt_ps->in_rule_as[i].desc_c = inp_wf_aps[i]->desc; }/* End of FOR loop */ /* Array of default rules conditional rules indexed by beam code */ dpvt_ps->rule_cond_s.data_a = (uint32_t *)rec_ps->vala; dpvt_ps->rule_cond_s.nord_p = (uint32_t *)(&out_wf_aps[8]->nord); dpvt_ps->rule_cond_s.nelem = rec_ps->nova; /* Array of default rules indexed by beam code */ dpvt_ps->rule_def_s.data_a = (uint32_t *)rec_ps->valb; dpvt_ps->rule_def_s.nord_p = (uint32_t *)(&out_wf_aps[9]->nord); dpvt_ps->rule_def_s.nelem = rec_ps->novb; /* Array of default rules total delay indexed by beam code */ dpvt_ps->rule_tdly_s.data_a = (double *)rec_ps->valc; dpvt_ps->rule_tdly_s.nord_p = (uint32_t *)(&out_wf_aps[10]->nord); dpvt_ps->rule_tdly_s.nelem = rec_ps->novc; rec_ps->dpvt = dpvt_ps; return(status); } /*============================================================================= Name: tmRuleMsk Abs: Extract and element from the specified array Args: Type Name Access Description ------------- ----------- ---------- ---------------------------- longSubRecord * rec_ps read/write ptr to subroutine record Rem: Subroutine for :RULE_INCL :RULE_EXCL :RULE_BEAMCODE Input: -------- A = Input array B = Index into array (based on INPC ) C = Data type (CHAR,UCHAR,SHORT,USHORT,LONG,ULONG) D = Max. number of elements in array. DPVT = Pointer to private device information structure Outputs: -------- VAL - mask or beam code from rule Side: long OK - Successful ERROR - Failed operation ==============================================================================*/ static long tmRuleMsk(longSubRecord *rec_ps) { long status = ERROR; size_t nbytes = 0; unsigned short i = rec_ps->b; tmGetInfo_ts *dpvt_ps = (tmGetInfo_ts *)rec_ps->dpvt; rec_ps->val = 0; nbytes = (rec_ps->b+1) * rec_ps->c; /* Get the address of waveform record, and pointer to the data */ if (!dpvt_ps || (nbytes>dpvt_ps->nbytes)) { if (TM_SUB_DEBUG) printf("tmRuleMsk: %s failed\n",rec_ps->name); } else if ((rec_ps->c==sizeof(int32_t)) || (rec_ps->c=sizeof(short))) { status = OK; if ( rec_ps->c == sizeof(short) ) rec_ps->val |= dpvt_ps->data_p[i]; else if ( rec_ps->c == sizeof(int32_t) ) { i *= 2; rec_ps->val = dpvt_ps->data_p[i+1] <<16; rec_ps->val |= dpvt_ps->data_p[i]; } } return(status); } /*============================================================================= Name: tmRuleDef Abs: Get the default or conditional rule(s) for the specified beam code Args: Type Name Access Description ------------- ----------- ---------- ---------------------------- longSubRecord * rec_ps read/write ptr to subroutine record Rem: Subroutine for TRIG:::BEAMCODE_DEF TRIG:::BEAMCODE_COND Input: -------- A = input array B = beamcode (0-255) C = D = Trigger channnel mode (1=pp0,3=pp1,6=modulo-36,7=reuse) E = default value for REUSE and Modulo-36 modes. Output: -------- VAL = default rule number (0-7). If not default rule set to 65535 Side: None Ret: long OK - Success (always) =============================================================================*/ static long tmRuleDef(longSubRecord *rec_ps) { long status = OK; /* return status */ uint32_t beamcode = 0; /* beam code */ tmRuleDef_ts *dpvt_ps = NULL; /* ptr to private device info */ dpvt_ps = (tmRuleDef_ts *)rec_ps->dpvt; if ((rec_ps->d==CHNL_MODE_RUSE) || (rec_ps->d==CHNL_MODE_M36)) rec_ps->val = rec_ps->e; else if ( dpvt_ps ) { /* * We have a channel that's set to PP0 or PP1 mode, * which are the only modes that are concerned about rules and beam codes */ beamcode = rec_ps->b & MAX_BEAMCODE; if ( BEAMCODE_OK(beamcode) ) { rec_ps->val = dpvt_ps->data_a[beamcode]; /* * If this is for a conditional rule * then make sure to mask of the vaule * so we never get a number larger than * expected. */ if (!rec_ps->e) rec_ps->val &= RULE_COND_BIT_MASK; } else rec_ps->val = rec_ps->e; }else rec_ps->val = rec_ps->e; return(status); } /*============================================================================= Name: tmBoot Abs: Initalize array based trigger mode Args: Type Name Access Description ------------- ----------- ---------- ---------------------------- aSubRecord * rec_ps read/write ptr to subroutine record Rem: Subroutine for TRIG:::INIT Input: -------- A = Trigger channnel mode (1=pp0,3=pp1,6=modulo-36,7=reuse B = trigger device name C = Debug flag (1=On,0=Off) D = E = Rule0 F = Rule1 G = Rule2 H = Rule3 I = Rule4 J = Rule5 K = Rule6 L = Rule7 M = array conditional rules indexed by beam code N = array default rules indexed by beam code O = array default rule total delays indexed by beam code P = debug flag (0=Off, 1=On) Output: -------- DPVT = private device information - initalized by tmBootInit VALA = Default rule array of conditiona rules. Array indexed by beamcode VALB = Default rule array of default rules. Array indexed by beamcode VALC = Default rule array of total delays. Array indexed by beamcode VALD = Beamcode fanout record proc field (process after default array init) VALE = Rule0 VALF = Rule1 VALG = Rule2 VALH = Rule3 VALI = Rule4 VALJ = Rule5 VALK = Rule6 VALL = Rule7 Side: None Ret: long OK - Success ERROR - Failed to index into input array =============================================================================*/ static long tmBoot(aSubRecord *rec_ps) { long status = ERROR; /* return status */ uint32_t debug_flag; /* debug flag, 0=off, 1=on */ uint32_t mode; /* trigger channel mode */ uint32_t i; /* index counter */ uint32_t beamcode; /* beam code (1-4) */ unsigned short type; /* type of rule */ uint32_t *def_odata_a = NULL; uint32_t *cond_odata_a = NULL; double *tdly_odata_a = NULL; tmBoot_ts *dpvt_ps = (tmBoot_ts *)rec_ps->dpvt; if (!dpvt_ps) return(ERROR); status = OK; debug_flag = *(uint32_t *)rec_ps->p; /* * Initialize the output array buffers * for the conditional rules, default rules * and total delays */ def_odata_a = (uint32_t *)rec_ps->vala; cond_odata_a = (uint32_t *)rec_ps->valb; tdly_odata_a = (double *)rec_ps->valc; for (i=0; inova; i++) { def_odata_a[i] = INVALID_RULE; cond_odata_a[i] = 0; tdly_odata_a[i] = TM_DEACT; } *dpvt_ps->rule_cond_s.nord_p = rec_ps->nova; *dpvt_ps->rule_def_s.nord_p = rec_ps->novb; *dpvt_ps->rule_tdly_s.nord_p = rec_ps->novc; if (debug_flag) { printf("%s: Init default rule array\n",rec_ps->name); for (i=0; inovb; i++) printf("(%d) %d ",i,def_odata_a[i]); printf("\n%s: Init conditional rule array\n",rec_ps->name); for (i=0; inova; i++) printf("(%d) %d ",i,cond_odata_a[i]); printf("\n%s: Init total delay rule array\n",rec_ps->name); for (i=0; inovc; i++) printf("(%d) %g ",i,tdly_odata_a[i]); printf("\n"); } /* * OK, before we initalize the rules we want to process the * PVs :BEAMCODE_TCTL, to set the total delay. * This MUST be done prior to the rules processing becasue * the :BEAMCODE_TCTL is used as input to * :RULE_TCTL. In addition, processing the * beamcode control will update the arrays indexed * by beamcodes which we initialized above. */ *(unsigned char *)rec_ps->vald = 1; /* Initalize rules * * Only pp0 and pp1 modes care about beam codes or rules. * So, if this device is set to modulo-36 or reuse mode * initalize the rules to rule type UNASSIGNED. * If the rule is pp0 or pp1 and the rule is invalid * then set to unassigned. */ mode = *(uint32_t *)rec_ps->a; for ( i=0; iin_rule_as[i].data_p); status = tmRuleTypeGet( beamcode, dpvt_ps->in_rule_as[i].nelem, dpvt_ps->in_rule_as[i].data_p, dpvt_ps->in_rule_as[i].desc_c, &type ); /* * We should NEVER see an invalid rule or an unused rule for a device. * So if we see this here on boot, we want to initalized the rule to * type UNASSIGNED. We also should never see a rule description set to * UNASSIGNED but the rule type is not Unassigned. This can occur in * the case of a globa rule, but not a trigger rule. */ if ((type==RULE_TYPE_INVALID) || (type==RULE_TYPE_UNUSED) || ((type==RULE_TYPE_CONDITIONAL) && !strcmp("UNASSIGNED",dpvt_ps->in_rule_as[i].desc_c))) *dpvt_ps->rule_as[i].nord_p = tmRuleTypeSetUnassigned(dpvt_ps->rule_as[i].desc_c, dpvt_ps->rule_as[i].data_p ); /* * Copy input rule to record output buffer for rule. * What we should do here is get the global rule assigned * to the rule id and compare that the rule is what we * expect on boot. */ else *dpvt_ps->rule_as[i].nord_p = tmRuleCopy(dpvt_ps->in_rule_as[i].data_p, dpvt_ps->rule_as[i].data_p ); } /* * OK, we must be set to mode REUSE or Modulo-36, and neither * care about rules. So initalize the rules to type UNASSIGNED. */ else *dpvt_ps->rule_as[i].nord_p = tmRuleTypeSetUnassigned(dpvt_ps->rule_as[i].desc_c, dpvt_ps->rule_as[i].data_p ); }/* End of FOR loop */ if (debug_flag) { printf("%s: Init default rule array\n",rec_ps->name); for (i=0; inovb; i++) printf("(%d) %d ",i,def_odata_a[i]); printf("\n%s: Init conditional rule array\n",rec_ps->name); for (i=0; inova; i++) printf("(%d) %d ",i,cond_odata_a[i]); printf("\n%s: Init total delay rule array\n",rec_ps->name); for (i=0; inovc; i++) printf("(%d) %g ",i,tdly_odata_a[i]); printf("\n"); } return(status); } /*============================================================================= Name: tmRuleCopy Abs: Copy the input array to the output array Args: Type Name Access Description -------- ----------- ---------- ---------------------------- unsigned * * idata_a read/write ptr to input data array unsigned short * * odata_a read/write ptr to output data array Rem: This function is used to copy 21 elements of an input array or rule to another. Side: None Ret: unsigned long number of elements written array =============================================================================*/ static uint32_t tmRuleCopy(unsigned short *idata_a, unsigned short *odata_a) { uint32_t i = 0; uint32_t num = 0; if (idata_a && odata_a) { num = PDU_RULE_WF_SIZE; for (i=0; i::RULE_PROC Input: -------- A = Rule number (0-7) :RULE_NUM B = Trigger channel mode (1=pp0,3=pp1,6=modulo-36,7=reuse) :MODE.RVAL C = Trigger rule (array of 21 ushorts) :RULE D = E = Trigger rule description :RULE.DESC F = Trigger device name :: :TRIG_DEVNAME G = array of default rules indexed by beam code :BEAMCODE_DEF H = array of conditional rules indexed by beam code :BEAMCODE_COND I = array of delays for default rules indexed by beam code :BEAMCODE_TDLY Output: -------- VALA = :RULE_TYPE where 0=Unassiged, 1=Default, 2=Conditional, 3=Unused, 4=Invalid VALB = :BEAMCODE_DEF set default rule in array :BEAMCODE_DEF VALC = :BEAMCODE_COND set conditional rules bitmask in array :BEAMCODE_COND VALD = :BEAMCODE_TDLY clear default rule delay if no loner a default rule VALE = :RULE_TCTL.DOL if default rule set to :BEAMCODE_TCTL VALF = :RULE_TCTL.OMSL if default rule set to closed loop, otherwise supervisory VALG = :RULE_TDES.DOL if default rule set to :BEAMCODE_TDES. VALH = :RULE_TDES.OMSL if default rule set to closed loop, otherwise supervisory VALI = :RULE_TSTAT.OUT if default rule set :BEAMCODE_TSTAT.OUT VALL = RULE PDU channel rule (pdu driver uses) Side: None Ret: long OK - Successful S_dev_noDeviceFound - not a DB_LINK S_dev_badInpType - Bad field S_dev_lowValue - Array is too short ERROR - Failed =============================================================================*/ static long tmRule(aSubRecord *rec_ps) { long status = ERROR; /* status return */ uint32_t debug_flag; /* debug flag, 0=Off, 1=On */ uint32_t bit=0; /* bit number (0-7) */ uint32_t i=0; /* index counter */ uint32_t beamcode = 0; /* beam code selected in rule */ uint32_t ruleNo = 0; /* rule number */ unsigned short ruleType = 0; /* type of rule */ epicsEnum16 omsl_e; /* closed_loop=1supervisory=0 */ char tdes_str_c[80]; /* for DOL field string */ char tctl_str_c[80]; /* for DOL field string */ char tsta_str_c[80]; size_t num=0; /* for OUT field string */ uint32_t *def_odata_a = NULL; uint32_t *def_idata_a = NULL; uint32_t *cond_odata_a = NULL; uint32_t *cond_idata_a = NULL; double *tdly_odata_a = NULL; double *tdly_idata_a = NULL; waveformRecord *rule_wf_ps = NULL; /* trigger rule */ waveformRecord *def_wf_ps = NULL; /* default rule array */ waveformRecord *cond_wf_ps = NULL; /* conditional rule array */ waveformRecord *tdly_wf_ps = NULL; /* total delay array */ status = tmCheckDbLink(&rec_ps->inpc,DBF_USHORT,PDU_RULE_WF_SIZE,&rule_wf_ps); if (!status) status = tmCheckDbLink(&rec_ps->inpg,DBF_ULONG,N_BEAMCODES+1,&def_wf_ps); if (!status) status = tmCheckDbLink(&rec_ps->inph,DBF_ULONG,N_BEAMCODES+1,&cond_wf_ps); if (!status) status = tmCheckDbLink(&rec_ps->inpi,DBF_DOUBLE,N_BEAMCODES+1,&tdly_wf_ps); if (!status) status = tmCheckDbLink(&rec_ps->outl,DBF_USHORT,PDU_RULE_WF_SIZE,&rule_wf_ps); if (!status) status = tmCheckDbLink(&rec_ps->outb,DBF_ULONG,N_BEAMCODES+1,&def_wf_ps); if (!status) status = tmCheckDbLink(&rec_ps->outc,DBF_ULONG,N_BEAMCODES+1,&cond_wf_ps); if (!status) status = tmCheckDbLink(&rec_ps->outd,DBF_DOUBLE,N_BEAMCODES+1,&tdly_wf_ps); if (status) return(ERROR); /* Get rule type */ status = tmRuleType(rec_ps); if (status) return(status); /* Get rule number */ ruleType = *(unsigned short *)rec_ps->vala; ruleNo = *(uint32_t *)rec_ps->a & RULE_BIT_MASK; debug_flag = *(uint32_t *)rec_ps->m; /* * Copy trigger channel rule to the pdu channel rule. * Note: the function dbPutField does the lock out for you. */ num=sizeof(unsigned short)*min(rec_ps->noc,rec_ps->novl); /* replace rec_ps->tovl in memcpy with num */ memcpy((unsigned char *)rec_ps->vall,(unsigned char *)rec_ps->c,num); rule_wf_ps->nord = rec_ps->novl; /* get beam code */ beamcode = PDU_BEAMCODE((unsigned short *)rec_ps->c); /* * First copy the input arrays for default rules * conditional rules and total delay to the output * buffers for these arrays. */ def_odata_a = (uint32_t *)rec_ps->valb; def_idata_a = (uint32_t *)rec_ps->g; cond_odata_a = (uint32_t *)rec_ps->valc; cond_idata_a = (uint32_t *)rec_ps->h; tdly_odata_a = (double *)rec_ps->vald; tdly_idata_a = (double *)rec_ps->i; for (i=0; inovb; i++) { def_odata_a[i] = def_idata_a[i]; cond_odata_a[i] = cond_idata_a[i]; tdly_odata_a[i] = tdly_idata_a[i]; } def_wf_ps->nord = rec_ps->novb; cond_wf_ps->nord = rec_ps->novc; tdly_wf_ps->nord = rec_ps->novd; /* REUSE and MODULO-36 Mode: * Is this channel set to reuse or modulo-36 mode? * If yes, then initalize the default rule ararys * beacause rule are not used. for these modes. */ if ( (*(uint32_t *)rec_ps->b==CHNL_MODE_RUSE) || (*(uint32_t *)rec_ps->b==CHNL_MODE_M36)) { if (debug_flag) printf("%s: Init delay array\n",rec_ps->name); for (i=0; i<=rec_ps->novb; ++i) { def_odata_a[i] = INVALID_RULE; cond_odata_a[i] = 0; tdly_odata_a[i] = TM_DEACT; } if (debug_flag) { printf("%s: Init default rule array\n",rec_ps->name); for (i=0; inovb; i++) printf("(%d) %d ",i,def_odata_a[i]); printf("\n%s: Init conditional rule array\n",rec_ps->name); for (i=0; inovc; i++) printf("(%d) %d ",i,cond_odata_a[i]); printf("\n%s: Init total delay rule array\n",rec_ps->name); for (i=0; inovd; i++) printf("(%d) %g ",i,tdly_odata_a[i]); printf("\n"); } } /* PP0 and PP1 Mode: * Determine if we have a default rule and * setup the links to the rule TDES,TCTL and TSTAT * appropriately. If this is a default rule then * control of TDES and TCTL should be from the * :BEAMCODE_TDES * :BEAMCODE_TCTL * The status of the TCTL for a default rule should * originate frome the rule itself * :RULE_TSTAT * Please note that this is only the case for PP0 and PP1 modes. * * Note: * OUT links in :RULE_PROC * to DOL fields must be set to CA. If they * are not set to CA, the dbPut() to the DOL * field will fail. * * :RULE_TCTL.OMSL/DOL (MUST SET CP) * :RULE_TDES.OMSL/DOL (MUST SET CP) * :RULE_TSTAT.OUT */ else if ( ruleType != RULE_TYPE_DEFAULT ) { /* If this rule was previously a default rule for another beam code, clear it */ for(i=1;i<=rec_ps->novb; i++) { if (def_odata_a[i]==ruleNo) { def_odata_a[i] = INVALID_RULE; /* clear default rule */ if (debug_flag) printf("%s: default rule %ld (clr) on beamcode=%ld\n",rec_ps->name,ruleNo,i); } } /* sprintf(str_c,"%s:RULE%ld_TMVAB15 CP NMS",(char *)rec_ps->f,*(int32_t *)rec_ps->a); */ omsl_e = 0; /* supervisory */ sprintf(tctl_str_c," "); sprintf(tdes_str_c," "); sprintf(tsta_str_c," "); strcpy((char *)rec_ps->vale,tctl_str_c); /* TCTL.DOL */ strcpy((char *)rec_ps->valf,tdes_str_c); /* TDES.DOL */ strcpy((char *)rec_ps->valg,tsta_str_c); /* TSTAT.OUT */ } else { /* * Verify that the default rule array of conditional rules is of the * expected size and data type. */ if (debug_flag) printf("%s: default rule %ld (set) on beamcode=%ld\n",rec_ps->name,ruleNo,beamcode); /* set default rule */ if (BEAMCODE_OK(beamcode)) def_odata_a[beamcode] = ruleNo; omsl_e = 1; /* closed_loop */ sprintf(tctl_str_c,"%s:BEAMCODE%ld_TCTL CP NMS",(char *)rec_ps->f,beamcode); sprintf(tdes_str_c,"%s:BEAMCODE%ld_TDES CP NMS",(char *)rec_ps->f,beamcode); sprintf(tsta_str_c,"%s:BEAMCODE%ld_TSTAT.RVAL PP MS",(char *)rec_ps->f,beamcode); strcpy((char *)rec_ps->vale,tctl_str_c); strcpy((char *)rec_ps->valf,tdes_str_c); strcpy((char *)rec_ps->valg,tsta_str_c); } *(short *)rec_ps->valh = omsl_e; /* :RULE_TCTL.OMSL */ *(short *)rec_ps->vali = omsl_e; /* :RULE_TDES.OMSL */ /* Set conditional rule in array of conditional rule bitmasks indexed by beam code */ bit = 1 << ruleNo; for (i=1; i<=N_BEAMCODES; i++) { if ((i==beamcode) && (ruleType==RULE_TYPE_CONDITIONAL)) { cond_odata_a[i] |= bit; /* set bit */ if (debug_flag) printf("%s: conditional rule %ld (set) on beamcode=%ld cond=0x%lx\n", rec_ps->name,ruleNo,i,cond_odata_a[i]); } /* Ok, this is not a conditional rule, so clear this rule bit if set for any beamcode */ else if (cond_odata_a[i] && bit) { cond_odata_a[i] &= ~bit; /* clear bit */ if (debug_flag) printf("%s: conditional rule %d (clr) on beamcode=%ld cond=0x%lx\n", rec_ps->name,ruleNo,i,cond_odata_a[i]); } }/* End of FOR loop */ return(status); } /*============================================================================= Name: tmDelay Abs: Calcuate the default rule total delay without deactivate Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- aSubRecord * psub read point to subroutine record Rem: Subroutine for :BEAMCODE_TDLYCALC This function calculates the timing value for a specific beam code. This function is only used for PP0 and PP1 mode. delay = TREF + TDES + TNOM(optional) + TMVA Inputs: -------- A - MODE pdu channel mode (1=pp0,3=pp1,6=modulo-36,7=reuse) B - TREF pdu module offset w.r.t. fidicual in nsec C - TDES pdu delta delay D - TDEF E - TNOM value in nsec F - USE_TNOM flag G - beam code H - Default rule for this beam code (65535 if no default rule) I - array default rule TDLYs indexed by beam code J - K - 0, flag used by tmDelayInit M - debug flag (0=Off, 1=On) N - bitmask of conditional rules Output: -------- VALA - total delay without deactivate VALB - array of total delays indexed by beamcode. VALC - bitmask of conditional rules and default rules. Ret: long OK - Successful (always) ==============================================================================*/ static long tmDelay(struct aSubRecord *rec_ps) { long status = OK; /* return status */ int32_t default_ruleNo; /* default rule number */ uint32_t i; /* index counter */ uint32_t beamcode; /* beam code */ uint32_t mode; /* pdu channel mode */ uint32_t debug_flag; /* debug flag */ uint32_t bitmask = 0; /* bitmask of def and cond rules */ double val = TM_DEACT; /* total dealy */ double *idata_a = NULL; double *odata_a = NULL; if (!rec_ps->dpvt) return(ERROR); mode = *(uint32_t *)rec_ps->a; /* pdu channel mode */ beamcode = *(uint32_t *)rec_ps->g; /* get beam code (0-4) */ debug_flag = *(uint32_t *)rec_ps->m; /* get the debug flag */ default_ruleNo = *(int32_t *)rec_ps->h; /* get the default rule */ /* First copy the current delay (input) array to the output */ idata_a = (double *)rec_ps->i; odata_a = (double *)rec_ps->valb; for (i=0; inovb; i++) odata_a[i] = idata_a[i]; /* * Calculate the default rule total delay * :BEAMCODE_TDLYCALC */ if ((mode==CHNL_MODE_PP0) || (mode==CHNL_MODE_PP1)) { if (RULE_OK(default_ruleNo)) { val = *(double *)rec_ps->b + *(double *)rec_ps->c; /* tref + tdes */ /* Comment out INPE and this section that references it; we have not used TNOMs to date and suspect this link may be affecting processing of this record, as it is hosted on a remote server if ( *(uint32_t *)rec_ps->f ) val += *(double *)rec_ps->e; */ /* add tnom */ bitmask = 1 << default_ruleNo; bitmask |= *(uint32_t *)rec_ps->n; } /* update array with new delay calculation */ if (BEAMCODE_OK(beamcode)) odata_a[beamcode] = val; } if (debug_flag) { printf("%s: mode=%ld beamcode=%ld total=%g\n",rec_ps->name,mode,beamcode,val); printf("Input: "); for (i=0; inoi; i++) printf(" (%d) %g",i,idata_a[i]); printf("\n"); printf("Output: "); for (i=0; inovb; i++) printf(" (%d) %g",i,odata_a[i]); printf("\n"); } *(uint32_t *)rec_ps->valc = bitmask; *(double *)rec_ps->vala = val; return(status); } /*============================================================================= Name: tmGetDelay Abs: Get the total delay for a rule Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- aSubRecord * psub read point to subroutine record Rem: Subroutine for :RULE_TDLYCALC This function will calculate the total delay for a rule based on the trigger mode. For PP0 and PP1 mode: If the rule type is conditional or default get default rule delay calculated from :BEAMCODE_TDLYCALC. Otherwise, set the total delay to 0xffff For Reuse mode: calcuate the total delay for rule0 only. total = tref + tdef For Modulo-36 mode: calculate the total delay for rule0 only. total = tref + tdes Inputs: -------- A - MODE pdu channel mode (1=pp0,3=pp1,6=modulo-36,7=reuse) B - TREF pdu module offset w.r.t. fidicual in nsec C - TDES pdu delta delay D - TDEF E - F - G - beam code H - Default rule for this beam code (65535 if no default rule) I - array default rule TDLYs indexed by beam code J - K - 1 (indicates rule) L - Rule number (0-7) M - debug flag (0=Off, 1=On) Output: -------- VALA - total delay without deactivate Ret: long OK - Successful (always) ==============================================================================*/ static long tmGetDelay(struct aSubRecord *rec_ps) { long status = OK; /* return status */ int32_t default_ruleNo; /* default rule number */ int32_t ruleNo; /* rule number */ uint32_t i; /* index counter */ uint32_t beamcode; /* beam code */ uint32_t mode; /* pdu channel mode */ uint32_t debug_flag; /* debug flag */ double val=TM_DEACT; /* total dealy */ double *tdly_a = NULL; mode = *(uint32_t *)rec_ps->a; /* pdu channel mode */ ruleNo = *(int32_t *)rec_ps->l; /* rule number */ debug_flag = *(uint32_t *)rec_ps->m; /* get the debug flag */ /* Get delays */ tdly_a = (double *)rec_ps->i; if (debug_flag) { printf("%s: \n",rec_ps->name); printf("Input: "); for (i=0; inoi; i++) printf(" (%d) %g",i,tdly_a[i]); printf("\n"); } /* perform action based on mode */ switch(mode) { /* * reuse mode doesn't use rules and therefore is not * concerned with the default rule or the beam code, * which is defined in the last element of the rule. * * reuse mode delay offset (tdes) very rarely changes * and so the TDEF vaule is used as the offset to TREF * when calculating the total time delay. * * In addition, reuse mode is not allowed to deactivate. * Channels that are set reuse mode expect the triggers * to fire on every fidicual. * * The reuse channels are used for hardware that should * always have a trigger, such as the modular standby * (where the PIOP decides which pulse should trigger * the modulator, but always has a 360Hz trigger to * choose from), or for some diagnostic devices that * should always trigger at 360Hz. * * History: * In the SLC Control System, the only way to * change the reuse delay was to a dbedit. A * TDES did not exist for a reuse channel, as it * does now for the EPICS Control of pdu triggers. * In adddition, there was no Deactivate or Activate. * If a channel was defined as reuse it was ALWAYS * Activated. */ case CHNL_MODE_RUSE: if ( ruleNo==0 ) { val = *(double *)rec_ps->b + *(double *)rec_ps->d; /* tref + tdef */ if (debug_flag) printf("Rule%ld tref:%g tdef:%g \n",ruleNo,*(double *)rec_ps->b,*(double *)rec_ps->d); } break; /* * modulo-36 mode doesn't use rules, and therefore * is not concerned with the default rule or the * beam codes. Uses rule0 only as a place holder * for the delay. */ case CHNL_MODE_M36: if ( ruleNo==0 ) { val = *(double *)rec_ps->b + *(double *)rec_ps->c; /* tref + tdes */ if (debug_flag) printf("Rule%d tref:%g tdes:%g \n",ruleNo,*(double *)rec_ps->b,*(double *)rec_ps->c); } break; /* * Get the total delay of the default * rule calculated eariler * * Note: a conditional will have a valid default * rule :RULE_DEF as will the default * rule itself. All other rules, will have an invlide * default rule (65535) and for those rule the * delay will be set to deactivate (0xfffff) */ case CHNL_MODE_PP0: /* pp0 mode, we look at rule0-7 */ case CHNL_MODE_PP1: /* pp1 mode, we look at rule0-7 */ default_ruleNo = *(int32_t *)rec_ps->h; /* get the default rule */ beamcode = *(uint32_t *)rec_ps->g; /* get beam code (0-4) */ if (RULE_OK(default_ruleNo) && BEAMCODE_OK(beamcode)) val = tdly_a[beamcode]; if (debug_flag) printf("Default Rule%ld beamcode: %d\n",default_ruleNo,beamcode); break; default: /* mode not supported */ break; } /* End of switch statement */ if (debug_flag) printf("Rule%d total delay:%g\n",ruleNo,val); *(double *)rec_ps->vala = val; return(status); } /*============================================================================= Name: tmDelayDeact Abs: Calculate the total time delay including deactivate bit Args: Type Name Access Description ------------- ----------- ---------- ---------------------------- longSubRecord * rec_ps read/write ptr to subroutine record Rem: Subroutine for TRIG:::RULE_TDLY2 Input: -------- A = Trigger channel mode B = Rule Total time delay w/o deactivate bit C = Rule Control function (deactivate,reactivate) D = Default rule control function (deactivate=0,reactivate=1) E = Rule number F = Default Rule number G = :RULE_TYPE.RVAL Rule type 0=unassigned,1=Default, 2=Conditional,3=Unused,4=Invalid Output: -------- H = deactivate flag (0=deactivate, 1=activate) I = Mode, except for unused rules this is set to 0. VAL = total time delay including deactivate bit in pdu ticks Side: None Ret: long OK - Success (always) =============================================================================*/ static long tmDelayDeact(struct longSubRecord *rec_ps) { long status = OK; /* return status */ rec_ps->val = TM_DEACT; switch(rec_ps->a) { /* * reuse mode doesn't use rules and therefore is not * concerned with the default rule or the beam code, * which is defined in the last element of the rule. * * reuse mode delay offset (tdes) very rarely changes * and so the TDEF vaule is used as the offset to TREF * when calculating the total time delay. * * In addition, reuse mode is not allowed to deactivate. * Channels that are set reuse mode expect the triggers * to fire on every fidicual. * * The reuse channels are used for hardware that should * always have a trigger, such as the modular standby * (where the PIOP decides which pulse should trigger * the modulator, but always has a 360Hz trigger to * choose from), or for some diagnostic devices that * should always trigger at 360Hz. * * History: * In the SLC Control System, the only way to * change the reuse delay was to a dbedit. A * TDES did not exist for a reuse channel, as it * does now for the EPICS Control of pdu triggers. * In adddition, there was no Deactivate or Activate. * If a channel was defined as reuse it was ALWAYS * Activated. */ case CHNL_MODE_RUSE: /* reuse mode */ if (rec_ps->e==0) /* only interested in rule0 */ { rec_ps->val = rec_ps->b; /* always fire on fidicual */ rec_ps->i = rec_ps->a; } else rec_ps->i = 0; break; /* * modulo-36 mode doesn't use rules and therefore * is not concerned with the default rule or the * beam code, which is defined in last element of the rule. * However, modulo-36 is concerned with the beam rate, * which is defined in the the upper 16-bits of a * 64-bit definition in the TMSK (ie :TMSK ). * Please refer to the PV :BEAM_RATE * for more detail. */ case CHNL_MODE_M36: /* modulo-36 mode, we look at rule0 only */ if (rec_ps->e==0) /* Only intrested in rule0 */ { if (!rec_ps->c) rec_ps->val = rec_ps->b | TM_DEACT_B20; else rec_ps->val = rec_ps->b; rec_ps->i = rec_ps->a; } else rec_ps->i = 0; break; case CHNL_MODE_PP0: /* pp0 mode, we look at rule0-7 */ case CHNL_MODE_PP1: /* pp1 mode, we look at rule0-7 */ /* If this is a default rule then look at the * rule :RULE_TCTL to determine the function * because the DOL and OMSL for that pv have already been * set to the default rule for that beamcode. */ if (rec_ps->g==RULE_TYPE_DEFAULT) { if (!rec_ps->c) rec_ps->val = rec_ps->b | TM_DEACT_B20; else rec_ps->val = rec_ps->b; rec_ps->i = rec_ps->a; } /* * Otherwise, if this is a condition rule then * you need to consider the default rule TCTRL * status as well as your own, if the default rule * is set to deactivate. */ else if (rec_ps->g==RULE_TYPE_CONDITIONAL) { /* * If the default rule control function is set to deactivate * or the conditional rule is set to deactivate, then deactivate * the conditional rule. Otherwise, activate */ if (!rec_ps->d || !rec_ps->c) rec_ps->val = rec_ps->b | TM_DEACT_B20; else rec_ps->val = rec_ps->b; rec_ps->i = rec_ps->a; } else rec_ps->i = 0; break; default: rec_ps->i = 0; rec_ps->val = TM_DEACT; break; } if (rec_ps->val & TM_DEACT_B20) rec_ps->h = 0; /* Deactivated */ else rec_ps->h = 1; /* Reactivated */ return(status); } /*============================================================================= Name: tmRuleTmva Abs: Calculate the timing value offset for a trigger channel rule based on a bit-mask of the selected timing values. Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- aSubRecord * sub_ps read/write pointer to subroutine record Rem: Subroutine for :RULE_TMVACALC Input: -------- A = bit-mask of selected timing values (bit 15 is deactivate) B = Number of timing value C = Array of TMVAs (NELEM should equal B) D = TMVA0 Description E = TMVA1 Description F = TMVA2 Description ... R = TMVA14 Description Output: -------- DPVT = private device information VALA = :RULE_TMVA total timing values in nsec VALB = :RULE_TMVA_STR string description of Side: None Ret: int 0 - Successful -1 - for invalid INPA or invalid INPB ==============================================================================*/ static long tmRuleTmva(struct aSubRecord *rec_ps) { long status = OK; /* return status */ uint32_t len = 0; /* string length */ unsigned short i; /* index counter */ unsigned short mask = 1; /* bit mask */ unsigned short bitmask = 0; /* bit mask of selected TMVAs */ uint32_t num = 0; /* number of TMVAs */ char **desc_ap = NULL; /* timing values TMVAn */ double *tmva_a = NULL; /* tmva waveform */ tmTmva_ts *dpvt_ps = (tmTmva_ts *)rec_ps->dpvt; if (!dpvt_ps ) return(ERROR); bitmask = *(unsigned short *)rec_ps->a; /* bit-mask of selecte tmva's */ num = MIN(MAX_TMVA-1,*(int32_t *)rec_ps->b); num = MIN(rec_ps->noa,num); dpvt_ps->desc_c[0] = '\0'; dpvt_ps->total = 0.0; if (num && bitmask && (rec_ps->ftc==DBF_DOUBLE)) { /* Get tmva's and their respective descriptions */ desc_ap = (char **)&rec_ps->d; /* tmva descriptions */ tmva_a = (double *)rec_ps->c; /* tmva waveform */ /* Determine which TMVA's have been selected */ for (i=0; itotal += tmva_a[i]; /* add timing value to total delay */ /* * If we've added more than one TMVA then include * indicate that we are adding another by using the * plus sign. */ if (len) strcpy(&dpvt_ps->desc_c[len]," + "); len = strlen(dpvt_ps->desc_c); /* * Are we using one of the spare TMVA's. If yes, and * the description for this TMVA says Spare, then * at least specify the timing value added. */ if (!strcmp("Spare",desc_ap[i]) || !strlen(desc_ap[i])) sprintf(&dpvt_ps->desc_c[len],"TMVA%hd",i); /* * Otherwise, add the TMVA description to the list of * those already selected. */ else { sprintf(&dpvt_ps->desc_c[len],"%s",desc_ap[i] ); len = strlen(dpvt_ps->desc_c); } } }/* End of FOR loop */ if (bitmask & TMVA_DEACT_MASK) strcpy(dpvt_ps->desc_c,"Deact"); } *(double *)rec_ps->vala = dpvt_ps->total; /* set total timing value */ len = MAX_STRING_SIZE; strncpy((char *)rec_ps->valb,dpvt_ps->desc_c,len); return(status); } /*============================================================================= Name: tmRuleType Abs: Determine the rule type based on the rule Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- aSubRecord * psub read point to subroutine record Rem: Subroutine for TRIG:SYS0:1:RULE_PROC This function determines the type of rule based on the contents of the rule, which include: 1) inclusion masks 2) exclusion masks 3) beam code The rule types are defined as: 0 - Unassigned all masks set to 1 and beam code 255 1 - Default all masks set to 0 and vaid beam code (1-255) 2 - Conditional valid beam code and masks non-zero. 3 - Unused rule description set to UNUSED 4 - Invalid invalid beam code or whatever remains. The "Unassigned" rule type is what the EPICS pdu driver initalize the rules on boot. Inputs: -------- A = Rule number B = C = Rule (21 element array of unsigned shorts) E = Rule description field Outputs: -------- VALA - Rule type where, 0=Unassigned 1=Default 2=Conditional 3=Unused 4=Invalid Side: long OK - Successful ERROR - Failed, initialization was not successful ==============================================================================*/ static long tmRuleType(struct aSubRecord *rec_ps) { long status = ERROR; /* return status */ uint32_t num; /* number of elements */ unsigned short beamcode = 0; /* beam code */ const char *desc_c = NULL; tmGetInfo_ts *dpvt_ps = (tmGetInfo_ts *)rec_ps->dpvt; if (!dpvt_ps) *(unsigned short *)rec_ps->vala = RULE_TYPE_INVALID; else { desc_c = (char *)rec_ps->e; num = dpvt_ps->nelem; beamcode = PDU_BEAMCODE(dpvt_ps->data_p); /* * Independent of the content of the rule, if the global rule * description is set to UNUSED, it will not be written * to a device trigger rule, */ status = tmRuleTypeGet(beamcode,num,dpvt_ps->data_p,desc_c,(unsigned short *)rec_ps->vala); } return(status); } /*============================================================================= Name: tmRuleType Abs: Determine the rule type based on the rule Args: Type Name Access Description -------------------- ----------- ---------- ---------------------------- uint32_t beamcode read beamcode (1-4) uint32_t num read number of items in array const unsigned short * data_a read data array (rule) const char * desc_c read NULL terminated description unsigned short * type_p write rule type Rem: This function determines the rule type based on the contents of the input data array and the description field. The input data array contains 21 unsigned shorts including: 10 inclusion masks 10 exclusion masks 1 beam code The rule types are defined as: 0 - Unassigned all masks set to 1 and beam code 255 1 - Default all masks set to 0 and vaid beam code (1-255) 2 - Conditional valid beam code and masks non-zero. 3 - Unused rule description set to UNUSED 4 - Invalid invalid beam code or whatever remains. The "Unassigned" rule type is what the EPICS pdu driver initalize the rules on boot. It contains inclusion and exclusion masks set to 0xffff and a beam code set to 0xff. In addition, the description fiels is also set to "UNASSIGNED". If the description field is not set to "UNASSIGNED" but all other criteria has been met the rule type is set to "Invalid". The "Default" rule type contains inclusion and exclusion masks set to 0 and a beamcode set to a valid number, which is currently 1-4. The "Conditional" rule type contains a valid beam code (1-4) with some inclusion and exclusion masks settings. Note, that default rule is required for all conditional rules. The "Unused" rule type contains inclusion and exclusion masks as well the beam code set to 0. The "Invalid" rule type is all other conditions. Side: long OK - Successful ERROR - Failed, due to null pointer or insufficient size array. ==============================================================================*/ static long tmRuleTypeGet( uint32_t beamcode, uint32_t num, const unsigned short *data_a, const char *desc_c, unsigned short *type_p ) { long status = ERROR; /* return status */ uint32_t i = 0; /* index counter */ uint32_t total = 0; /* total of incl & excl masks */ if (!type_p || (numMAX_BEAMCODE)) *type_p = RULE_TYPE_INVALID; /* Ok, we have a valid beamcode. Now, do we * have all inclusion and exclusion masks set to 1's. * This means that no match can be made. */ else if (total==TYPE_UNASSIGNED) { /* * Ok, all masks are set to 1's. If the beam code * is set to 255 then this rule is unassigned. * This is the state that the rule is set by the * EPICS pdu driver during initialization. This will * cause the trigger to be disabled. * * If the beamcode is not 255, then the rule is invalid. * because exclusion and inclusion bit both set is invalid. */ if (beamcode == MAX_BEAMCODE) *type_p = RULE_TYPE_UNASSIGNED; else *type_p = RULE_TYPE_INVALID; } /* * Valid beamcode (1-255) and masks are all 0's * and the rule description is not set to UNUSED. */ else if (!total) *type_p = RULE_TYPE_DEFAULT; /* * Valid beamcode (1-255) and masks neither all zeros or all 1's * and the rule description is not set to UNUSED. */ else *type_p = RULE_TYPE_CONDITIONAL; return(status); } /*============================================================================= Name: tmGetTmsk Abs: Process TMSK bit-mask into timing delay bits0-35 and beam rate Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- longSubRecord * sub_ps read point to subroutine record Rem: Subroutine for TRIG:::TMSK Inputs: -------- A = Timing bit-mask first 4-byte longword B = Timing bit-mask second 4-byte longword Outputs: -------- C - lower 16-bits of A D - upper 16-bits of A E - lower 4-bits of B F - beam rate Side: long OK - Successful (always) ==============================================================================*/ static long tmGetTmsk(longSubRecord *rec_ps) { long status = OK; static uint32_t mask = 0xffffffff; rec_ps->c = rec_ps->a & mask; rec_ps->d = rec_ps->a & mask; rec_ps->e = rec_ps->b & 0xf; rec_ps->f = ((rec_ps->b) >> 24)/10; return(status); } /*============================================================================= Name: tmGetStat Abs: Formulate a summary status given relevent inputs Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- longSubRecord * sub_ps read point to subroutine record Rem: Subroutine for TRIG:::STAT_SUMY Inputs: -------- A = PDU module status B = PDU Channel mode C = PDU Rule Type Outputs: -------- VAL - Bitmask of summar status Side: long OK - Successful (always) ==============================================================================*/ static long tmGetStat(longSubRecord *rec_ps) { long status = OK; rec_ps->val = status; return(status); } /*============================================================================= Name: tmModeLimits Abs: Set the PDU mode readback alarm severity Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- aSubRecord * rec_ps read/write pointer to subroutine record Input: -------- A = :MODE_SET PDU channel mode set point Outputs: --------- VALA = :MODE.ZRSV PP0 mode alarm severity VALB = :MODE.ORSV PP1 mode alarm severity VALC = :MODE.TWSV Modul0-36 mode alarm severity VALD = :MODE.THSV REUSE mode alarm severity Rem: Set the alarm severity of the mode input PV that matches the mode set point to NO_ALARM, and all other modes set to MAJOR. For example, if the mode set point is Module-36, then severity for PP0,PP1 and REUSE are set to MAJOR and the severity for Modulo-36 is set to NO_ALARM. Side: None Ret: long 0 - Successful (always) ==============================================================================*/ static long tmModeLimits(struct aSubRecord *rec_ps) { long status = OK; switch( *(unsigned short *)rec_ps->a ) { case MODE_PP0: *(uint32_t *)rec_ps->vala = NO_ALARM; *(uint32_t *)rec_ps->valb = MAJOR_ALARM; *(uint32_t *)rec_ps->valc = MAJOR_ALARM; *(uint32_t *)rec_ps->vald = MAJOR_ALARM; break; case MODE_PP1: *(uint32_t *)rec_ps->vala = MAJOR_ALARM; *(uint32_t *)rec_ps->valb = NO_ALARM; *(uint32_t *)rec_ps->valc = MAJOR_ALARM; *(uint32_t *)rec_ps->vald = MAJOR_ALARM; break; case MODE_M36: *(uint32_t *)rec_ps->vala = MAJOR_ALARM; *(uint32_t *)rec_ps->valb = MAJOR_ALARM; *(uint32_t *)rec_ps->valc = NO_ALARM; *(uint32_t *)rec_ps->vald = MAJOR_ALARM; break; case MODE_REUSE: *(uint32_t *)rec_ps->vala = MAJOR_ALARM; *(uint32_t *)rec_ps->valb = MAJOR_ALARM; *(uint32_t *)rec_ps->valc = MAJOR_ALARM; *(uint32_t *)rec_ps->vald = NO_ALARM; break; } return(status); } /*============================================================================= Name: tmPttLimits Abs: Set the PDU PTT readback alarm severity Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- aSubRecord * rec_ps read/write pointer to subroutine record Input: -------- A = :MODE_SET PDU channel mode set point B = :PTT_SET PTT Set point C = loc PTT number (0-35,255) Outputs: --------- VALA = :PTT.HIHI.SEVR PTT upper alarm limit severity VALB = :PTT.HIGH.SEVR PTT upper warnning limit severity VALC = :PTT.LOLO.SEVR PTT lower alarm limit severity VALD = :PTT.LOW.SEVR PTT lower warning limit severity VALE = :PTT.HIHI Upper alarm limit VALF = :PTT.HIGH Upper warning limit VALG = :PTT.LOLO Lower alarm limit VALH = :PTT.LOW Lower warning limit Rem: Set the alarm severity of the mode input PV that matches the mode set point to NO_ALARM, and all other modes set to MAJOR. For example, if the mode set point is Module-36, then severity for PP0,PP1 and REUSE are set to MAJOR and the severity for Modulo-36 is set to NO_ALARM. Side: None Ret: long 0 - Successful (always) ==============================================================================*/ static long tmPttLimits(struct aSubRecord *rec_ps) { long status = OK; unsigned short sev = NO_ALARM; int32_t hihi = 0; int32_t lolo = 0; switch( *(int32_t *)rec_ps->a ) { case CHNL_MODE_M36: if ( *(uint32_t *)rec_ps->c<255 ) { sev = MAJOR_ALARM; hihi = *(int32_t *)rec_ps->b + 1; lolo = *(int32_t *)rec_ps->b - 1; } break; case CHNL_MODE_PP0: case CHNL_MODE_PP1: break; case CHNL_MODE_RUSE: if ( *(uint32_t *)rec_ps->c==255 ) { sev = MAJOR_ALARM; hihi = *(int32_t *)rec_ps->b + 1; lolo = *(int32_t *)rec_ps->b - 1; } break; } /* Set ptt rbk severity */ *(unsigned short *)rec_ps->vala = sev; *(unsigned short *)rec_ps->valb = sev; *(unsigned short *)rec_ps->valc = sev; *(unsigned short *)rec_ps->vald = sev; /* Set ptt rbk upper alarm and warning limits */ *(int32_t *)rec_ps->vale = hihi; *(int32_t *)rec_ps->valf = hihi; *(int32_t *)rec_ps->valg = lolo; *(int32_t *)rec_ps->valh = lolo; return(status); } /*============================================================================= Name: tmInit Abs: Initialization subroutine record Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- aSubRecord * sub_ps read/write pointer to subroutine record Rem: Subroutine for generic initialization. Side: None Ret: long OK - Successful (always) ==============================================================================*/ static long tmInit(struct aSubRecord *rec_ps) { long status=OK; /* * General purpose initialization required since all subroutine records * require a non-NULL init routine even if no initialization is required. * Note that most subroutines in this file use this routine as an init * routine. If init logic is needed for a specific subroutine, create a * new routine for it - don't modify this one. */ return(status); } /*============================================================================= Name: tmCheckDbLink Abs: Check the DB_LINK for type and size, returing a ptr to the waveform. Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- struct link * link_ps read pointer to db link structure short type read type of data long nelm read number of elements in array waveformRecord ** wf_pps read/write pointer to ponter to waveform record Rem: Check database linke for size and data type. Side: None Ret: long OK - Successful S_dev_noDeviceFound - not a DB_LINK S_dev_badInpType - Bad field S_dev_lowValue - Array is too short ==============================================================================*/ static long tmCheckDbLink( const struct link *link_ps, short type, int32_t nelm, waveformRecord **wf_pps ) { long status = OK; DBADDR *addr_ps = NULL; addr_ps = dbGetPdbAddrFromLink(link_ps); if (!addr_ps) status = S_dev_noDeviceFound; else { if (addr_ps->field_type!=type) status = S_dev_badInpType; else if (addr_ps->no_elementsprecord; } return(status); } /*============================================================================= Name: tmTmva Abs: Set global time value array :TMVA Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- aSubRecord * rec_ps read point to subroutine record Rem: Init subroutine for :RULE_TMVACALC Input: -------- A = number of TMVAs B-P = TMVA0 through TMVA14 Note: TMVA15 is the deactivate bit, 1=deactivate,0=otherwise. Output: -------- VALA = TMVA waveform, where TMVA0 is element 0 of the array, etc... Side: None. Ret: long OK - Successful ERROR - Failed initalization ==============================================================================*/ static long tmTmva(aSubRecord *rec_ps) { long status = OK; /* return status */ int32_t ntmva = 0; /* number of timing values */ short i=0; /* index counter */ unsigned short *type_p = NULL; /* type of timing data */ double *val_p = NULL; /* TMVAn value */ double **tmva_idata_pp = NULL; /* timing value (INPB-INPP) */ double *tmva_odata_a = NULL; /* TMVA waveform */ waveformRecord *tmva_wf_ps = NULL; /* array of timing values */ char errmsg_c[80]; /* error message string */ ntmva = MIN(MAX_TMVA,*(int32_t *)rec_ps->a); if (ntmva <= 0) { sprintf(errmsg_c,"tmTmva: Invalid number of global TMVAs (%ld)\n",ntmva); recGblRecordError(S_dev_lowValue,(void *)rec_ps,errmsg_c); return(status); } if ( tmCheckDbLink(&rec_ps->outa,DBF_DOUBLE,MAX_TMVA,&tmva_wf_ps) ) { sprintf(errmsg_c,"tmTmva: Invalid link OUTA\n"); recGblRecordError(S_dev_badOutType,(void *)rec_ps,errmsg_c); return(status); } type_p = &rec_ps->ftb; /* ptr to TMVA0 data type */ tmva_idata_pp = (double **)&rec_ps->b; /* ptr to TMVA0 */ tmva_odata_a = (double *)rec_ps->vala; for (i=0; (inord = rec_ps->nova; return(status); } /* Register these symbols for use by IOC code: */ #if EPICS_VERSION>3 || (EPICS_VERSION==3 && EPICS_REVISION>=14) epicsRegisterFunction(tmInit); epicsRegisterFunction(tmBootInit); epicsRegisterFunction(tmDelayInit); epicsRegisterFunction(tmRuleInit); epicsRegisterFunction(tmRuleDefInit); epicsRegisterFunction(tmRuleMskInit); epicsRegisterFunction(tmBoot); epicsRegisterFunction(tmDelay); epicsRegisterFunction(tmDelayDeact); epicsRegisterFunction(tmModeLimits); epicsRegisterFunction(tmPttLimits); epicsRegisterFunction(tmRuleDef); epicsRegisterFunction(tmRule); epicsRegisterFunction(tmTmva); epicsRegisterFunction(tmRuleMsk); epicsRegisterFunction(tmGetDelay); epicsRegisterFunction(tmGetStat); epicsRegisterFunction(tmGetTmsk); epicsRegisterFunction(tmRuleTmva); epicsRegisterFunction(tmRuleType); #endif /* End of file */