This is Unofficial EPICS BASE Doxygen Site
devAaiSoft.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2008 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 * EPICS BASE is distributed subject to a Software License Agreement found
7 * in file LICENSE that is included with this distribution.
8 \*************************************************************************/
9 
10 /*
11  * devAaiSoft.c - Device Support Routines for soft Waveform Records
12  *
13  * Original Author: Bob Dalesio
14  * Current Author: Dirk Zimoch
15  * Date: 27-MAY-2010
16  */
17 
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <string.h>
21 
22 #include "alarm.h"
23 #include "dbDefs.h"
24 #include "dbAccess.h"
25 #include "dbConstLink.h"
26 #include "dbEvent.h"
27 #include "recGbl.h"
28 #include "devSup.h"
29 #include "cantProceed.h"
30 #include "menuYesNo.h"
31 #include "aaiRecord.h"
32 #include "epicsExport.h"
33 
34 /* Create the dset for devAaiSoft */
35 static long init_record(dbCommon *pcommon);
36 static long read_aai(aaiRecord *prec);
37 
38 aaidset devAaiSoft = {
39  {5, NULL, NULL, init_record, NULL},
40  read_aai
41 };
43 
44 static long init_record(dbCommon *pcommon)
45 {
46  aaiRecord *prec = (aaiRecord *)pcommon;
47  DBLINK *plink = &prec->inp;
48 
49  /* This is pass 0, link hasn't been initialized yet */
50  dbInitLink(plink, DBF_INLINK);
51 
52  if (dbLinkIsConstant(plink)) {
53  long nRequest = prec->nelm;
54  long status;
55 
56  /* Allocate a buffer, record support hasn't done that yet */
57  if (!prec->bptr) {
58  prec->bptr = callocMustSucceed(nRequest, dbValueSize(prec->ftvl),
59  "devAaiSoft: buffer calloc failed");
60  }
61 
62  status = dbLoadLinkArray(plink, prec->ftvl, prec->bptr, &nRequest);
63  if (!status && nRequest > 0) {
64  prec->nord = nRequest;
65  prec->udf = FALSE;
66  }
67  }
68  return 0;
69 }
70 
71 static long readLocked(struct link *pinp, void *dummy)
72 {
73  aaiRecord *prec = (aaiRecord *) pinp->precord;
74  long nRequest = prec->nelm;
75  long status = dbGetLink(pinp, prec->ftvl, prec->bptr, 0, &nRequest);
76 
77  if (!status && nRequest > 0) {
78  prec->nord = nRequest;
79  prec->udf = FALSE;
80 
81  if (dbLinkIsConstant(&prec->tsel) &&
82  prec->tse == epicsTimeEventDeviceTime)
83  dbGetTimeStamp(pinp, &prec->time);
84  }
85  return status;
86 }
87 
88 static long read_aai(aaiRecord *prec)
89 {
90  epicsUInt32 nord = prec->nord;
91  struct link *pinp = prec->simm == menuYesNoYES ? &prec->siol : &prec->inp;
92  long status = dbLinkDoLocked(pinp, readLocked, NULL);
93 
94  if (status == S_db_noLSET)
95  status = readLocked(pinp, NULL);
96 
97  if (!status && nord != prec->nord)
98  db_post_events(prec, &prec->nord, DBE_VALUE | DBE_LOG);
99 
100  return status;
101 }
#define FALSE
Definition: dbDefs.h:32
pvd::Status status
#define init_record
#define NULL
Definition: catime.c:38
unsigned int epicsUInt32
Definition: epicsTypes.h:43
Miscellaneous macro definitions.
epicsExportAddress(dset, devAaiSoft)
aaidset devAaiSoft
Definition: devAaiSoft.c:38
#define DBE_VALUE
Definition: caeventmask.h:38
Device support routines.
Definition: devSup.h:140
#define epicsTimeEventDeviceTime
Definition: epicsTime.h:362
#define DBE_LOG
Definition: caeventmask.h:40
LIBCOM_API void * callocMustSucceed(size_t count, size_t size, const char *msg)
A calloc() that never returns NULL.
Definition: cantProceed.c:22
epics::pvData::PVStructurePtr dummy
Definition: pvAccess.cpp:72
Routines for code that can&#39;t continue or return after an error.
int prec
Definition: reader.c:29
Exporting IOC objects.