asyn  4-36
asynPortDriver.h
Go to the documentation of this file.
1 #ifndef asynPortDriver_H
2 #define asynPortDriver_H
3 
4 #include <vector>
5 #include <string>
6 
7 #include <epicsTypes.h>
8 #include <epicsMutex.h>
9 #include <epicsThread.h>
10 
11 #include <asynStandardInterfaces.h>
12 #include <asynParamType.h>
13 #include <paramErrors.h>
14 
15 class paramList;
16 
17 epicsShareFunc void* findAsynPortDriver(const char *portName);
18 typedef void (*userTimeStampFunction)(void *userPvt, epicsTimeStamp *pTimeStamp);
19 
20 #ifdef __cplusplus
21 
23 #define asynCommonMask 0x00000001
24 #define asynDrvUserMask 0x00000002
25 #define asynOptionMask 0x00000004
26 #define asynInt32Mask 0x00000008
27 #define asynUInt32DigitalMask 0x00000010
28 #define asynFloat64Mask 0x00000020
29 #define asynOctetMask 0x00000040
30 #define asynInt8ArrayMask 0x00000080
31 #define asynInt16ArrayMask 0x00000100
32 #define asynInt32ArrayMask 0x00000200
33 #define asynFloat32ArrayMask 0x00000400
34 #define asynFloat64ArrayMask 0x00000800
35 #define asynGenericPointerMask 0x00001000
36 #define asynEnumMask 0x00002000
37 
38 class callbackThread;
39 
42 class epicsShareClass asynPortDriver {
43 public:
44  asynPortDriver(const char *portName, int maxAddr, int interfaceMask, int interruptMask,
45  int asynFlags, int autoConnect, int priority, int stackSize);
46  asynPortDriver(const char *portName, int maxAddr, int paramTableSize, int interfaceMask, int interruptMask,
47  int asynFlags, int autoConnect, int priority, int stackSize) EPICS_DEPRECATED;
48  virtual ~asynPortDriver();
49  virtual asynStatus lock();
50  virtual asynStatus unlock();
51  virtual asynStatus getAddress(asynUser *pasynUser, int *address);
52  virtual asynStatus parseAsynUser(asynUser *pasynUser, int *reason, int *address, const char **paramName);
53  virtual asynStatus readInt32(asynUser *pasynUser, epicsInt32 *value);
54  virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value);
55  virtual asynStatus readUInt32Digital(asynUser *pasynUser, epicsUInt32 *value, epicsUInt32 mask);
56  virtual asynStatus writeUInt32Digital(asynUser *pasynUser, epicsUInt32 value, epicsUInt32 mask);
57  virtual asynStatus setInterruptUInt32Digital(asynUser *pasynUser, epicsUInt32 mask, interruptReason reason);
58  virtual asynStatus clearInterruptUInt32Digital(asynUser *pasynUser, epicsUInt32 mask);
59  virtual asynStatus getInterruptUInt32Digital(asynUser *pasynUser, epicsUInt32 *mask, interruptReason reason);
60  virtual asynStatus getBounds(asynUser *pasynUser, epicsInt32 *low, epicsInt32 *high);
61  virtual asynStatus readFloat64(asynUser *pasynUser, epicsFloat64 *value);
62  virtual asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value);
63  virtual asynStatus readOctet(asynUser *pasynUser, char *value, size_t maxChars,
64  size_t *nActual, int *eomReason);
65  virtual asynStatus writeOctet(asynUser *pasynUser, const char *value, size_t maxChars,
66  size_t *nActual);
67  virtual asynStatus flushOctet(asynUser *pasynUser);
68  virtual asynStatus setInputEosOctet(asynUser *pasynUser, const char *eos, int eosLen);
69  virtual asynStatus getInputEosOctet(asynUser *pasynUser, char *eos, int eosSize, int *eosLen);
70  virtual asynStatus setOutputEosOctet(asynUser *pasynUser, const char *eos, int eosLen);
71  virtual asynStatus getOutputEosOctet(asynUser *pasynUser, char *eos, int eosSize, int *eosLen);
72  virtual asynStatus readInt8Array(asynUser *pasynUser, epicsInt8 *value,
73  size_t nElements, size_t *nIn);
74  virtual asynStatus writeInt8Array(asynUser *pasynUser, epicsInt8 *value,
75  size_t nElements);
76  virtual asynStatus doCallbacksInt8Array(epicsInt8 *value,
77  size_t nElements, int reason, int addr);
78  virtual asynStatus readInt16Array(asynUser *pasynUser, epicsInt16 *value,
79  size_t nElements, size_t *nIn);
80  virtual asynStatus writeInt16Array(asynUser *pasynUser, epicsInt16 *value,
81  size_t nElements);
82  virtual asynStatus doCallbacksInt16Array(epicsInt16 *value,
83  size_t nElements, int reason, int addr);
84  virtual asynStatus readInt32Array(asynUser *pasynUser, epicsInt32 *value,
85  size_t nElements, size_t *nIn);
86  virtual asynStatus writeInt32Array(asynUser *pasynUser, epicsInt32 *value,
87  size_t nElements);
88  virtual asynStatus doCallbacksInt32Array(epicsInt32 *value,
89  size_t nElements, int reason, int addr);
90  virtual asynStatus readFloat32Array(asynUser *pasynUser, epicsFloat32 *value,
91  size_t nElements, size_t *nIn);
92  virtual asynStatus writeFloat32Array(asynUser *pasynUser, epicsFloat32 *value,
93  size_t nElements);
94  virtual asynStatus doCallbacksFloat32Array(epicsFloat32 *value,
95  size_t nElements, int reason, int addr);
96  virtual asynStatus readFloat64Array(asynUser *pasynUser, epicsFloat64 *value,
97  size_t nElements, size_t *nIn);
98  virtual asynStatus writeFloat64Array(asynUser *pasynUser, epicsFloat64 *value,
99  size_t nElements);
100  virtual asynStatus doCallbacksFloat64Array(epicsFloat64 *value,
101  size_t nElements, int reason, int addr);
102  virtual asynStatus readGenericPointer(asynUser *pasynUser, void *pointer);
103  virtual asynStatus writeGenericPointer(asynUser *pasynUser, void *pointer);
104  virtual asynStatus doCallbacksGenericPointer(void *pointer, int reason, int addr);
105  virtual asynStatus readOption(asynUser *pasynUser, const char *key, char *value, int maxChars);
106  virtual asynStatus writeOption(asynUser *pasynUser, const char *key, const char *value);
107  virtual asynStatus readEnum(asynUser *pasynUser, char *strings[], int values[], int severities[], size_t nElements, size_t *nIn);
108  virtual asynStatus writeEnum(asynUser *pasynUser, char *strings[], int values[], int severities[], size_t nElements);
109  virtual asynStatus doCallbacksEnum(char *strings[], int values[], int severities[], size_t nElements, int reason, int addr);
110  virtual asynStatus drvUserCreate(asynUser *pasynUser, const char *drvInfo,
111  const char **pptypeName, size_t *psize);
112  virtual asynStatus drvUserGetType(asynUser *pasynUser,
113  const char **pptypeName, size_t *psize);
114  virtual asynStatus drvUserDestroy(asynUser *pasynUser);
115  virtual void report(FILE *fp, int details);
116  virtual asynStatus connect(asynUser *pasynUser);
117  virtual asynStatus disconnect(asynUser *pasynUser);
118 
119  virtual asynStatus createParam( const char *name, asynParamType type, int *index);
120  virtual asynStatus createParam(int list, const char *name, asynParamType type, int *index);
121  virtual asynStatus getNumParams( int *numParams);
122  virtual asynStatus getNumParams(int list, int *numParams);
123  virtual asynStatus findParam( const char *name, int *index);
124  virtual asynStatus findParam(int list, const char *name, int *index);
125  virtual asynStatus getParamName( int index, const char **name);
126  virtual asynStatus getParamName(int list, int index, const char **name);
127  virtual asynStatus getParamType( int index, asynParamType *type);
128  virtual asynStatus getParamType(int list, int index, asynParamType *type);
129  virtual asynStatus setParamStatus( int index, asynStatus status);
130  virtual asynStatus setParamStatus(int list, int index, asynStatus status);
131  virtual asynStatus getParamStatus( int index, asynStatus *status);
132  virtual asynStatus getParamStatus(int list, int index, asynStatus *status);
133  virtual asynStatus setParamAlarmStatus( int index, int status);
134  virtual asynStatus setParamAlarmStatus(int list, int index, int status);
135  virtual asynStatus getParamAlarmStatus( int index, int *status);
136  virtual asynStatus getParamAlarmStatus(int list, int index, int *status);
137  virtual asynStatus setParamAlarmSeverity( int index, int severity);
138  virtual asynStatus setParamAlarmSeverity(int list, int index, int severity);
139  virtual asynStatus getParamAlarmSeverity( int index, int *severity);
140  virtual asynStatus getParamAlarmSeverity(int list, int index, int *severity);
141  virtual void reportSetParamErrors(asynStatus status, int index, int list, const char *functionName);
142  virtual void reportGetParamErrors(asynStatus status, int index, int list, const char *functionName);
143  virtual asynStatus setIntegerParam( int index, int value);
144  virtual asynStatus setIntegerParam(int list, int index, int value);
145  virtual asynStatus setUIntDigitalParam( int index, epicsUInt32 value, epicsUInt32 valueMask);
146  virtual asynStatus setUIntDigitalParam(int list, int index, epicsUInt32 value, epicsUInt32 valueMask);
147  virtual asynStatus setUIntDigitalParam( int index, epicsUInt32 value, epicsUInt32 valueMask, epicsUInt32 interruptMask);
148  virtual asynStatus setUIntDigitalParam(int list, int index, epicsUInt32 value, epicsUInt32 valueMask, epicsUInt32 interruptMask);
149  virtual asynStatus setUInt32DigitalInterrupt( int index, epicsUInt32 mask, interruptReason reason);
150  virtual asynStatus setUInt32DigitalInterrupt(int list, int index, epicsUInt32 mask, interruptReason reason);
151  virtual asynStatus clearUInt32DigitalInterrupt( int index, epicsUInt32 mask);
152  virtual asynStatus clearUInt32DigitalInterrupt(int list, int index, epicsUInt32 mask);
153  virtual asynStatus getUInt32DigitalInterrupt( int index, epicsUInt32 *mask, interruptReason reason);
154  virtual asynStatus getUInt32DigitalInterrupt(int list, int index, epicsUInt32 *mask, interruptReason reason);
155  virtual asynStatus setDoubleParam( int index, double value);
156  virtual asynStatus setDoubleParam(int list, int index, double value);
157  virtual asynStatus setStringParam( int index, const char *value);
158  virtual asynStatus setStringParam(int list, int index, const char *value);
159  virtual asynStatus setStringParam( int index, const std::string& value);
160  virtual asynStatus setStringParam(int list, int index, const std::string& value);
161  virtual asynStatus getIntegerParam( int index, epicsInt32 * value);
162  virtual asynStatus getIntegerParam(int list, int index, epicsInt32 * value);
163  virtual asynStatus getUIntDigitalParam( int index, epicsUInt32 *value, epicsUInt32 mask);
164  virtual asynStatus getUIntDigitalParam(int list, int index, epicsUInt32 *value, epicsUInt32 mask);
165  virtual asynStatus getDoubleParam( int index, double * value);
166  virtual asynStatus getDoubleParam(int list, int index, double * value);
167  virtual asynStatus getStringParam( int index, int maxChars, char *value);
168  virtual asynStatus getStringParam(int list, int index, int maxChars, char *value);
169  virtual asynStatus getStringParam( int index, std::string& value);
170  virtual asynStatus getStringParam(int list, int index, std::string& value);
171  virtual asynStatus callParamCallbacks();
172  virtual asynStatus callParamCallbacks( int addr);
173  virtual asynStatus callParamCallbacks(int list, int addr);
174  virtual asynStatus updateTimeStamp();
175  virtual asynStatus updateTimeStamp(epicsTimeStamp *pTimeStamp);
176  virtual asynStatus getTimeStamp(epicsTimeStamp *pTimeStamp);
177  virtual asynStatus setTimeStamp(const epicsTimeStamp *pTimeStamp);
178  asynStandardInterfaces *getAsynStdInterfaces();
179  virtual void reportParams(FILE *fp, int details);
180 
181  char *portName;
183  int maxAddr;
184  void callbackTask();
185 
186 protected:
187  void initialize(const char *portNameIn, int maxAddrIn, int interfaceMask, int interruptMask, int asynFlags,
188  int autoConnect, int priority, int stackSize);
189  asynUser *pasynUserSelf;
190  asynStandardInterfaces asynStdInterfaces;
192 private:
193  std::vector<paramList*> params;
194  epicsMutexId mutexId;
195  char *inputEosOctet;
196  int inputEosLenOctet;
197  char *outputEosOctet;
198  int outputEosLenOctet;
199  callbackThread *cbThread;
200  template <typename epicsType, typename interruptType>
201  asynStatus doCallbacksArray(epicsType *value, size_t nElements,
202  int reason, int address, void *interruptPvt);
203 
204  friend class paramList;
205  friend class callbackThread;
206 };
207 
208 class callbackThread: public epicsThreadRunable {
209 public:
210  callbackThread(asynPortDriver *portDriver);
211  ~callbackThread();
212  void run();
213 private:
214  epicsThread thread;
215  asynPortDriver *pPortDriver;
216  epicsEvent shutdown;
217 };
218 
219 #endif /* cplusplus */
220 
221 #endif
epicsShareFunc void * findAsynPortDriver(const char *portName)
Utility function that returns a pointer to an asynPortDriver object from its name.
Definition: asynPortDriver.cpp:3458
Class to support parameter library (also called parameter list); set and get values indexed by parame...
Definition: asynPortDriver.cpp:47
void(* userTimeStampFunction)(void *userPvt, epicsTimeStamp *pTimeStamp)
Definition: asynPortDriver.h:18
Definition: asynPortDriver.h:208
asynParamType
Parameter data types for the parameter library.
Definition: asynParamType.h:12
Base class for asyn port drivers; handles most of the bookkeeping for writing an asyn port driver wit...
Definition: asynPortDriver.h:42
char * portName
The name of this asyn port.
Definition: asynPortDriver.h:181
void run()
Definition: asynPortDriver.cpp:829
callbackThread(asynPortDriver *portDriver)
Definition: asynPortDriver.cpp:812
asynStandardInterfaces asynStdInterfaces
The asyn interfaces this driver implements.
Definition: asynPortDriver.h:190
~callbackThread()
Definition: asynPortDriver.cpp:819
asynUser * pasynUserSelf
asynUser connected to ourselves for asynTrace
Definition: asynPortDriver.h:189
int maxAddr
The maximum asyn address (addr) supported by this driver.
Definition: asynPortDriver.h:183