mrfioc2  2.3.0
seqnsls2.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2013 Brookhaven Science Associates, as Operator of
3 * Brookhaven National Laboratory.
4 * mrfioc2 is distributed subject to a Software License Agreement found
5 * in file LICENSE that is included with this distribution.
6 \*************************************************************************/
7 /*
8  * Author: Michael Davidsaver <mdavidsaver@gmail.com>
9  */
10 
11 #include <math.h>
12 #include <stdio.h>
13 #include <string.h>
14 
15 #include <dbDefs.h>
16 #include <errlog.h>
17 #include <recGbl.h>
18 #include <alarm.h>
19 
20 #include <registryFunction.h>
21 
22 #include <menuFtype.h>
23 #include <aSubRecord.h>
24 
54 long seq_select(aSubRecord *prec)
55 {
56  int fail = 0;
57  epicsUInt32 LNMode, BRMode, LNMask, BRMask;
58  epicsUInt32 *BRAllow = prec->vala,
59  *InjMask = prec->valb,
60  *LNRepMask = prec->valc,
61  *BR1HzRepMask = prec->vald,
62  *BR2HzRepMask = prec->vale,
63  *BRStkRepMask = prec->valf;
64 
65  if(prec->fta!=menuFtypeULONG ||
66  prec->ftb!=menuFtypeULONG ||
67  prec->ftc!=menuFtypeULONG ||
68  prec->ftd!=menuFtypeULONG ||
69  prec->ftva!=menuFtypeULONG ||
70  prec->ftvb!=menuFtypeULONG ||
71  prec->ftvc!=menuFtypeULONG ||
72  prec->ftvd!=menuFtypeULONG ||
73  prec->ftve!=menuFtypeULONG ||
74  prec->ftvf!=menuFtypeULONG)
75  {
76  errlogPrintf("%s: Invalid field types!\n", prec->name);
77  (void)recGblSetSevr(prec, READ_ALARM, INVALID_ALARM);
78  return 0;
79  }
80 
81  LNMode = *(epicsUInt32*)prec->a;
82  BRMode = *(epicsUInt32*)prec->b;
83  LNMask = *(epicsUInt32*)prec->c;
84  BRMask = *(epicsUInt32*)prec->d;
85 
86  /* Allow only permitted slots to be filled */
87  LNMode &= LNMask;
88  BRMode &= BRMask;
89 
90  if(LNMode&~0x3ff) {
91  errlogPrintf("%s: Invalid LN Mode Mask\n", prec->name);
92  fail = 1;
93  }
94  if(BRMode&~0xf) {
95  errlogPrintf("%s: Invalid BR Mode Mask\n", prec->name);
96  fail = 1;
97  }
98 
99  if(fail) {
100  (void)recGblSetSevr(prec, UDF_ALARM, INVALID_ALARM);
101  LNMode = BRMode = 0;
102  }
103 
104  *InjMask = (LNMode<<4)|BRMode;
105 
106  switch(*InjMask) {
107  case 0x011: /* 1Hz in both */
108  case 0x032: /* Stacking in both */
109  case 0x21C: /* 2 Hz in both */
110  *BRAllow = 1;
111  break;
112  default: /* All others prohibit injection into BR */
113  *BRAllow = 0;
114  }
115 
116  *LNRepMask = LNMode;
117  *BR1HzRepMask = BRMode & 1;
118  *BR2HzRepMask = (BRMode>>2) & 3;
119  *BRStkRepMask = (BRMode>>1) & 1;
120 
121  return 0;
122 }
123 
124 static registryFunctionRef asub_seq[] = {
125  {"NSLS2SeqMask", (REGISTRYFUNCTION) seq_select},
126 };
127 
128 static
129 void asub_nsls2_evg(void) {
130  registryFunctionRefAdd(asub_seq, NELEMENTS(asub_seq));
131 }
132 
133 #include <epicsExport.h>
134 
135 epicsExportRegistrar(asub_nsls2_evg);
epicsExportRegistrar(asub_nsls2_evg)
long seq_select(aSubRecord *prec)
NSLS2 sequence selector.
Definition: seqnsls2.c:54