This is Unofficial EPICS BASE Doxygen Site
mbbiDirectRecord.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * Copyright (c) 2002 Southeastern Universities Research Association, as
7 * Operator of Thomas Jefferson National Accelerator Facility.
8 * EPICS BASE is distributed subject to a Software License Agreement found
9 * in file LICENSE that is included with this distribution.
10 \*************************************************************************/
11 
12 /* mbbiDirectRecord.c - Record Support routines for mbbiDirect records */
13 /*
14  * Original Authors: Bob Dalesio and Matthew Needes
15  * Date: 10-07-93
16  */
17 
18 #include <stddef.h>
19 #include <stdlib.h>
20 #include <stdarg.h>
21 #include <stdio.h>
22 #include <string.h>
23 
24 #include "dbDefs.h"
25 #include "errlog.h"
26 #include "alarm.h"
27 #include "callback.h"
28 #include "dbAccess.h"
29 #include "dbEvent.h"
30 #include "dbFldTypes.h"
31 #include "devSup.h"
32 #include "errMdef.h"
33 #include "menuSimm.h"
34 #include "recSup.h"
35 #include "recGbl.h"
36 #include "special.h"
37 
38 #define GEN_SIZE_OFFSET
39 #include "mbbiDirectRecord.h"
40 #undef GEN_SIZE_OFFSET
41 #include "epicsExport.h"
42 
43 /* Create RSET - Record Support Entry Table*/
44 #define report NULL
45 #define initialize NULL
46 static long init_record(struct dbCommon *, int);
47 static long process(struct dbCommon *);
48 static long special(DBADDR *, int);
49 #define get_value NULL
50 #define cvt_dbaddr NULL
51 #define get_array_info NULL
52 #define put_array_info NULL
53 #define get_units NULL
54 static long get_precision(const DBADDR *, long *);
55 #define get_enum_str NULL
56 #define get_enum_strs NULL
57 #define put_enum_str NULL
58 #define get_graphic_double NULL
59 #define get_control_double NULL
60 #define get_alarm_double NULL
61 
63  RSETNUMBER,
64  report,
65  initialize,
67  process,
68  special,
69  get_value,
70  cvt_dbaddr,
73  get_units,
81 };
82 epicsExportAddress(rset,mbbiDirectRSET);
83 
84 static void monitor(mbbiDirectRecord *);
85 static long readValue(mbbiDirectRecord *);
86 
87 #define NUM_BITS 32
88 
89 static long init_record(struct dbCommon *pcommon, int pass)
90 {
91  struct mbbiDirectRecord *prec = (struct mbbiDirectRecord *)pcommon;
92  mbbidirectdset *pdset = (mbbidirectdset *) prec->dset;
93  long status = 0;
94 
95  if (pass == 0) return 0;
96 
97  if (!pdset) {
98  recGblRecordError(S_dev_noDSET, prec, "mbbiDirect: init_record");
99  return S_dev_noDSET;
100  }
101 
102  if ((pdset->common.number < 5) || (pdset->read_mbbi == NULL)) {
103  recGblRecordError(S_dev_missingSup, prec, "mbbiDirect: init_record");
104  return S_dev_missingSup;
105  }
106 
107  recGblInitSimm(pcommon, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
108  recGblInitConstantLink(&prec->siol, DBF_ULONG, &prec->sval);
109 
110  /* Initialize MASK if the user set NOBT instead */
111  if (prec->mask == 0 && prec->nobt <= 32)
112  prec->mask = ((epicsUInt64) 1u << prec->nobt) - 1;
113 
114  if (pdset->common.init_record) {
115  status = pdset->common.init_record(pcommon);
116  if (status == 0) {
117  epicsUInt32 val = prec->val;
118  epicsUInt8 *pBn = &prec->b0;
119  int i;
120 
121  /* Initialize B0 - B1F from VAL */
122  for (i = 0; i < NUM_BITS; i++, pBn++, val >>= 1)
123  *pBn = !! (val & 1);
124  }
125  }
126 
127  prec->mlst = prec->val;
128  prec->oraw = prec->rval;
129  return status;
130 }
131 
132 static long process(struct dbCommon *pcommon)
133 {
134  struct mbbiDirectRecord *prec = (struct mbbiDirectRecord *)pcommon;
135  mbbidirectdset *pdset = (mbbidirectdset *) prec->dset;
136  long status;
137  int pact = prec->pact;
138 
139  if ((pdset == NULL) || (pdset->read_mbbi == NULL)) {
140  prec->pact = TRUE;
141  recGblRecordError(S_dev_missingSup, prec, "read_mbbi");
142  return S_dev_missingSup;
143  }
144 
145  status = readValue(prec);
146 
147  /* Done if device support set PACT */
148  if (!pact && prec->pact)
149  return 0;
150 
151  prec->pact = TRUE;
152  recGblGetTimeStampSimm(prec, prec->simm, &prec->siol);
153 
154  if (status == 0) {
155  /* Convert RVAL to VAL */
156  epicsUInt32 rval = prec->rval;
157 
158  if (prec->shft > 0)
159  rval >>= prec->shft;
160 
161  prec->val = rval;
162  prec->udf = FALSE;
163  }
164  else if (status == 2)
165  status = 0;
166 
167  if (prec->udf)
168  recGblSetSevr(prec, UDF_ALARM, INVALID_ALARM);
169 
170  monitor(prec);
171 
172  /* Wrap up */
173  recGblFwdLink(prec);
174  prec->pact = FALSE;
175  return status;
176 }
177 
178 static long special(DBADDR *paddr, int after)
179 {
180  mbbiDirectRecord *prec = (mbbiDirectRecord *)(paddr->precord);
181  int special_type = paddr->special;
182 
183  switch(special_type) {
184  case(SPC_MOD):
185  if (dbGetFieldIndex(paddr) == mbbiDirectRecordSIMM) {
186  if (!after)
187  recGblSaveSimm(prec->sscn, &prec->oldsimm, prec->simm);
188  else
189  recGblCheckSimm((dbCommon *)prec, &prec->sscn, prec->oldsimm, prec->simm);
190  return(0);
191  }
192  default:
193  recGblDbaddrError(S_db_badChoice, paddr, "mbbiDirect: special");
194  return(S_db_badChoice);
195  }
196 }
197 
198 static long get_precision(const DBADDR *paddr,long *precision)
199 {
200  mbbiDirectRecord *prec=(mbbiDirectRecord *)paddr->precord;
201  if(dbGetFieldIndex(paddr)==mbbiDirectRecordVAL)
202  *precision = prec->nobt;
203  else
204  recGblGetPrec(paddr,precision);
205  return 0;
206 }
207 
208 static void monitor(mbbiDirectRecord *prec)
209 {
210  epicsUInt16 events = recGblResetAlarms(prec);
211  epicsUInt16 vl_events = events | DBE_VALUE | DBE_LOG;
212  epicsUInt32 val = prec->val;
213  epicsUInt8 *pBn = &prec->b0;
214  int i;
215 
216  /* Update B0 - BF from VAL and post monitors */
217  for (i = 0; i < NUM_BITS; i++, pBn++, val >>= 1) {
218  epicsUInt8 oBn = *pBn;
219 
220  *pBn = !! (val & 1);
221  if (oBn != *pBn)
222  db_post_events(prec, pBn, vl_events);
223  else if (events)
224  db_post_events(prec, pBn, events);
225  }
226 
227  if (prec->mlst != prec->val) {
228  events = vl_events;
229  prec->mlst = prec->val;
230  }
231  if (events)
232  db_post_events(prec, &prec->val, events);
233 
234  if (prec->oraw != prec->rval) {
235  db_post_events(prec, &prec->rval, vl_events);
236  prec->oraw = prec->rval;
237  }
238 }
239 
240 static long readValue(mbbiDirectRecord *prec)
241 {
242  mbbidirectdset *pdset = (mbbidirectdset *) prec->dset;
243  long status = 0;
244 
245  if (!prec->pact) {
246  status = recGblGetSimm((dbCommon *)prec, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
247  if (status) return status;
248  }
249 
250  switch (prec->simm) {
251  case menuSimmNO:
252  status = pdset->read_mbbi(prec);
253  break;
254 
255  case menuSimmYES:
256  case menuSimmRAW: {
257  recGblSetSevr(prec, SIMM_ALARM, prec->sims);
258  if (prec->pact || (prec->sdly < 0.)) {
259  status = dbGetLink(&prec->siol, DBR_ULONG, &prec->sval, 0, 0);
260  if (status == 0) {
261  if (prec->simm == menuSimmYES) {
262  prec->val = prec->sval;
263  status = 2; /* Don't convert */
264  } else {
265  prec->rval = prec->sval;
266  }
267  prec->udf = FALSE;
268  }
269  prec->pact = FALSE;
270  } else { /* !prec->pact && delay >= 0. */
271  epicsCallback *pvt = prec->simpvt;
272  if (!pvt) {
273  pvt = calloc(1, sizeof(epicsCallback)); /* very lazy allocation of callback structure */
274  prec->simpvt = pvt;
275  }
276  if (pvt) callbackRequestProcessCallbackDelayed(pvt, prec->prio, prec, prec->sdly);
277  prec->pact = TRUE;
278  }
279  break;
280  }
281 
282  default:
283  recGblSetSevr(prec, SOFT_ALARM, INVALID_ALARM);
284  status = -1;
285  }
286 
287  return status;
288 }
#define put_enum_str
#define RSETNUMBER
Definition: recSup.h:92
#define FALSE
Definition: dbDefs.h:32
pvd::Status status
rset mbbiDirectRSET
int i
Definition: scan.c:967
#define get_array_info
unsigned short epicsUInt16
Definition: epicsTypes.h:41
#define init_record
#define S_dev_missingSup
Definition: devSup.h:170
unsigned char epicsUInt8
Definition: epicsTypes.h:39
#define SOFT_ALARM
Definition: alarm.h:106
#define get_graphic_double
#define NULL
Definition: catime.c:38
#define get_control_double
#define get_units
unsigned int epicsUInt32
Definition: epicsTypes.h:43
Miscellaneous macro definitions.
#define initialize
unsigned long long epicsUInt64
Definition: epicsTypes.h:45
#define DBE_VALUE
Definition: caeventmask.h:38
#define get_enum_str
Device support routines.
#define DBE_LOG
Definition: caeventmask.h:40
#define SIMM_ALARM
Definition: alarm.h:110
#define put_array_info
#define get_alarm_double
#define get_precision
Definition: biRecord.c:53
#define TRUE
Definition: dbDefs.h:27
#define cvt_dbaddr
if(yy_init)
Definition: scan.c:972
Definition: recSup.h:67
#define report
#define SPC_MOD
Definition: special.h:33
#define get_enum_strs
int prec
Definition: reader.c:29
epicsExportAddress(rset, mbbiDirectRSET)
#define INVALID_ALARM
Definition: alarm.h:53
#define DBR_ULONG
Definition: dbFldTypes.h:82
#define special
Definition: dfanoutRecord.c:50
#define S_dev_noDSET
Definition: devSup.h:169
#define UDF_ALARM
Definition: alarm.h:108
#define get_value
Exporting IOC objects.