asyn 4-45
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 <asynParamSet.h>
13#include <asynParamType.h>
14#include <paramErrors.h>
15
16class paramList;
17
18ASYN_API void* findAsynPortDriver(const char *portName);
19typedef void (*userTimeStampFunction)(void *userPvt, epicsTimeStamp *pTimeStamp);
20
21#ifdef __cplusplus
22
24#define asynCommonMask 0x00000001
25#define asynDrvUserMask 0x00000002
26#define asynOptionMask 0x00000004
27#define asynInt32Mask 0x00000008
28#define asynUInt32DigitalMask 0x00000010
29#define asynFloat64Mask 0x00000020
30#define asynOctetMask 0x00000040
31#define asynInt8ArrayMask 0x00000080
32#define asynInt16ArrayMask 0x00000100
33#define asynInt32ArrayMask 0x00000200
34#define asynFloat32ArrayMask 0x00000400
35#define asynFloat64ArrayMask 0x00000800
36#define asynGenericPointerMask 0x00001000
37#define asynEnumMask 0x00002000
38#define asynInt64Mask 0x00004000
39#define asynInt64ArrayMask 0x00008000
40
41class callbackThread;
42
98class ASYN_API asynPortDriver {
99public:
100 asynPortDriver(asynParamSet* paramSet,
101 const char *portName, int maxAddr, int interfaceMask, int interruptMask,
102 int asynFlags, int autoConnect, int priority, int stackSize);
103 asynPortDriver(const char *portName, int maxAddr, int interfaceMask, int interruptMask,
104 int asynFlags, int autoConnect, int priority, int stackSize);
105 asynPortDriver(const char *portName, int maxAddr, int paramTableSize, int interfaceMask, int interruptMask,
106 int asynFlags, int autoConnect, int priority, int stackSize) EPICS_DEPRECATED;
107 virtual ~asynPortDriver();
108 virtual asynStatus lock();
109 virtual asynStatus unlock();
110 virtual asynStatus getAddress(asynUser *pasynUser, int *address);
111 virtual asynStatus parseAsynUser(asynUser *pasynUser, int *reason, int *address, const char **paramName);
112 virtual asynStatus readInt32(asynUser *pasynUser, epicsInt32 *value);
113 virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value);
114 virtual asynStatus readInt64(asynUser *pasynUser, epicsInt64 *value);
115 virtual asynStatus writeInt64(asynUser *pasynUser, epicsInt64 value);
116 virtual asynStatus readUInt32Digital(asynUser *pasynUser, epicsUInt32 *value, epicsUInt32 mask);
117 virtual asynStatus writeUInt32Digital(asynUser *pasynUser, epicsUInt32 value, epicsUInt32 mask);
118 virtual asynStatus setInterruptUInt32Digital(asynUser *pasynUser, epicsUInt32 mask, interruptReason reason);
119 virtual asynStatus clearInterruptUInt32Digital(asynUser *pasynUser, epicsUInt32 mask);
120 virtual asynStatus getInterruptUInt32Digital(asynUser *pasynUser, epicsUInt32 *mask, interruptReason reason);
121 virtual asynStatus getBounds(asynUser *pasynUser, epicsInt32 *low, epicsInt32 *high);
122 virtual asynStatus getBounds64(asynUser *pasynUser, epicsInt64 *low, epicsInt64 *high);
123 virtual asynStatus readFloat64(asynUser *pasynUser, epicsFloat64 *value);
124 virtual asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value);
125 virtual asynStatus readOctet(asynUser *pasynUser, char *value, size_t maxChars,
126 size_t *nActual, int *eomReason);
127 virtual asynStatus writeOctet(asynUser *pasynUser, const char *value, size_t maxChars,
128 size_t *nActual);
129 virtual asynStatus flushOctet(asynUser *pasynUser);
130 virtual asynStatus setInputEosOctet(asynUser *pasynUser, const char *eos, int eosLen);
131 virtual asynStatus getInputEosOctet(asynUser *pasynUser, char *eos, int eosSize, int *eosLen);
132 virtual asynStatus setOutputEosOctet(asynUser *pasynUser, const char *eos, int eosLen);
133 virtual asynStatus getOutputEosOctet(asynUser *pasynUser, char *eos, int eosSize, int *eosLen);
134 virtual asynStatus readInt8Array(asynUser *pasynUser, epicsInt8 *value,
135 size_t nElements, size_t *nIn);
136 virtual asynStatus writeInt8Array(asynUser *pasynUser, epicsInt8 *value,
137 size_t nElements);
138 virtual asynStatus doCallbacksInt8Array(epicsInt8 *value,
139 size_t nElements, int reason, int addr);
140 virtual asynStatus readInt16Array(asynUser *pasynUser, epicsInt16 *value,
141 size_t nElements, size_t *nIn);
142 virtual asynStatus writeInt16Array(asynUser *pasynUser, epicsInt16 *value,
143 size_t nElements);
144 virtual asynStatus doCallbacksInt16Array(epicsInt16 *value,
145 size_t nElements, int reason, int addr);
146 virtual asynStatus readInt32Array(asynUser *pasynUser, epicsInt32 *value,
147 size_t nElements, size_t *nIn);
148 virtual asynStatus writeInt32Array(asynUser *pasynUser, epicsInt32 *value,
149 size_t nElements);
150 virtual asynStatus doCallbacksInt32Array(epicsInt32 *value,
151 size_t nElements, int reason, int addr);
152 virtual asynStatus readInt64Array(asynUser *pasynUser, epicsInt64 *value,
153 size_t nElements, size_t *nIn);
154 virtual asynStatus writeInt64Array(asynUser *pasynUser, epicsInt64 *value,
155 size_t nElements);
156 virtual asynStatus doCallbacksInt64Array(epicsInt64 *value,
157 size_t nElements, int reason, int addr);
158 virtual asynStatus readFloat32Array(asynUser *pasynUser, epicsFloat32 *value,
159 size_t nElements, size_t *nIn);
160 virtual asynStatus writeFloat32Array(asynUser *pasynUser, epicsFloat32 *value,
161 size_t nElements);
162 virtual asynStatus doCallbacksFloat32Array(epicsFloat32 *value,
163 size_t nElements, int reason, int addr);
164 virtual asynStatus readFloat64Array(asynUser *pasynUser, epicsFloat64 *value,
165 size_t nElements, size_t *nIn);
166 virtual asynStatus writeFloat64Array(asynUser *pasynUser, epicsFloat64 *value,
167 size_t nElements);
168 virtual asynStatus doCallbacksFloat64Array(epicsFloat64 *value,
169 size_t nElements, int reason, int addr);
170 virtual asynStatus readGenericPointer(asynUser *pasynUser, void *pointer);
171 virtual asynStatus writeGenericPointer(asynUser *pasynUser, void *pointer);
172 virtual asynStatus doCallbacksGenericPointer(void *pointer, int reason, int addr);
173 virtual asynStatus readOption(asynUser *pasynUser, const char *key, char *value, int maxChars);
174 virtual asynStatus writeOption(asynUser *pasynUser, const char *key, const char *value);
175 virtual asynStatus readEnum(asynUser *pasynUser, char *strings[], int values[], int severities[], size_t nElements, size_t *nIn);
176 virtual asynStatus writeEnum(asynUser *pasynUser, char *strings[], int values[], int severities[], size_t nElements);
177 virtual asynStatus doCallbacksEnum(char *strings[], int values[], int severities[], size_t nElements, int reason, int addr);
178 virtual asynStatus drvUserCreate(asynUser *pasynUser, const char *drvInfo,
179 const char **pptypeName, size_t *psize);
180 virtual asynStatus drvUserGetType(asynUser *pasynUser,
181 const char **pptypeName, size_t *psize);
182 virtual asynStatus drvUserDestroy(asynUser *pasynUser);
183 virtual void report(FILE *fp, int details);
184 virtual asynStatus connect(asynUser *pasynUser);
185 virtual asynStatus disconnect(asynUser *pasynUser);
186
187 virtual asynStatus createParam( const char *name, asynParamType type, int *index);
188 virtual asynStatus createParam(int list, const char *name, asynParamType type, int *index);
189 virtual asynStatus createParams();
190 virtual asynStatus getNumParams( int *numParams);
191 virtual asynStatus getNumParams(int list, int *numParams);
192 virtual asynStatus findParam( const char *name, int *index);
193 virtual asynStatus findParam(int list, const char *name, int *index);
194 virtual asynStatus getParamName( int index, const char **name);
195 virtual asynStatus getParamName(int list, int index, const char **name);
196 virtual asynStatus getParamType( int index, asynParamType *type);
197 virtual asynStatus getParamType(int list, int index, asynParamType *type);
198 virtual asynStatus setParamStatus( int index, asynStatus status);
199 virtual asynStatus setParamStatus(int list, int index, asynStatus status);
200 virtual asynStatus getParamStatus( int index, asynStatus *status);
201 virtual asynStatus getParamStatus(int list, int index, asynStatus *status);
202 virtual asynStatus setParamAlarmStatus( int index, int status);
203 virtual asynStatus setParamAlarmStatus(int list, int index, int status);
204 virtual asynStatus getParamAlarmStatus( int index, int *status);
205 virtual asynStatus getParamAlarmStatus(int list, int index, int *status);
206 virtual asynStatus setParamAlarmSeverity( int index, int severity);
207 virtual asynStatus setParamAlarmSeverity(int list, int index, int severity);
208 virtual asynStatus getParamAlarmSeverity( int index, int *severity);
209 virtual asynStatus getParamAlarmSeverity(int list, int index, int *severity);
210 virtual void reportSetParamErrors(asynStatus status, int index, int list, const char *functionName);
211 virtual void reportGetParamErrors(asynStatus status, int index, int list, const char *functionName);
212 virtual asynStatus setIntegerParam( int index, int value);
213 virtual asynStatus setIntegerParam(int list, int index, int value);
214 virtual asynStatus setInteger64Param( int index, epicsInt64 value);
215 virtual asynStatus setInteger64Param(int list, int index, epicsInt64 value);
216 virtual asynStatus setUIntDigitalParam( int index, epicsUInt32 value, epicsUInt32 valueMask);
217 virtual asynStatus setUIntDigitalParam(int list, int index, epicsUInt32 value, epicsUInt32 valueMask);
218 virtual asynStatus setUIntDigitalParam( int index, epicsUInt32 value, epicsUInt32 valueMask, epicsUInt32 interruptMask);
219 virtual asynStatus setUIntDigitalParam(int list, int index, epicsUInt32 value, epicsUInt32 valueMask, epicsUInt32 interruptMask);
220 virtual asynStatus setUInt32DigitalInterrupt( int index, epicsUInt32 mask, interruptReason reason);
221 virtual asynStatus setUInt32DigitalInterrupt(int list, int index, epicsUInt32 mask, interruptReason reason);
222 virtual asynStatus clearUInt32DigitalInterrupt( int index, epicsUInt32 mask);
223 virtual asynStatus clearUInt32DigitalInterrupt(int list, int index, epicsUInt32 mask);
224 virtual asynStatus getUInt32DigitalInterrupt( int index, epicsUInt32 *mask, interruptReason reason);
225 virtual asynStatus getUInt32DigitalInterrupt(int list, int index, epicsUInt32 *mask, interruptReason reason);
226 virtual asynStatus setDoubleParam( int index, double value);
227 virtual asynStatus setDoubleParam(int list, int index, double value);
228 virtual asynStatus setStringParam( int index, const char *value);
229 virtual asynStatus setStringParam(int list, int index, const char *value);
230 virtual asynStatus setStringParam( int index, const std::string& value);
231 virtual asynStatus setStringParam(int list, int index, const std::string& value);
232 virtual asynStatus getIntegerParam( int index, epicsInt32 * value);
233 virtual asynStatus getIntegerParam(int list, int index, epicsInt32 * value);
234 virtual asynStatus getInteger64Param( int index, epicsInt64 * value);
235 virtual asynStatus getInteger64Param(int list, int index, epicsInt64 * value);
236 virtual asynStatus getUIntDigitalParam( int index, epicsUInt32 *value, epicsUInt32 mask);
237 virtual asynStatus getUIntDigitalParam(int list, int index, epicsUInt32 *value, epicsUInt32 mask);
238 virtual asynStatus getDoubleParam( int index, double * value);
239 virtual asynStatus getDoubleParam(int list, int index, double * value);
240 virtual asynStatus getStringParam( int index, int maxChars, char *value);
241 virtual asynStatus getStringParam(int list, int index, int maxChars, char *value);
242 virtual asynStatus getStringParam( int index, std::string& value);
243 virtual asynStatus getStringParam(int list, int index, std::string& value);
244 virtual asynStatus callParamCallbacks();
245 virtual asynStatus callParamCallbacks( int addr);
246 virtual asynStatus callParamCallbacks(int list, int addr);
247 virtual asynStatus updateTimeStamp();
248 virtual asynStatus updateTimeStamp(epicsTimeStamp *pTimeStamp);
249 virtual asynStatus getTimeStamp(epicsTimeStamp *pTimeStamp);
250 virtual asynStatus setTimeStamp(const epicsTimeStamp *pTimeStamp);
251 asynStandardInterfaces *getAsynStdInterfaces();
252 virtual void reportParams(FILE *fp, int details);
253 virtual void shutdownPortDriver();
254 bool needsShutdown();
255
256 char *portName;
260
261protected:
262 void initialize(const char *portNameIn, int maxAddrIn, int interfaceMask, int interruptMask, int asynFlags,
263 int autoConnect, int priority, int stackSize);
264
265 asynParamSet* paramSet;
266 asynUser *pasynUserSelf;
267 asynStandardInterfaces *pasynStdInterfaces;
268 asynStandardInterfaces &asynStdInterfaces;
270private:
271 static void exceptionHandler(asynUser *pasynUser, asynException exception);
272
273 std::vector<paramList*> params;
274 paramList *getParamList(int list);
275 epicsMutexId mutexId;
276 char *inputEosOctet;
277 int inputEosLenOctet;
278 char *outputEosOctet;
279 int outputEosLenOctet;
280 callbackThread *cbThread;
281 int shutdownNeeded; // atomic!
282 template <typename epicsType, typename interruptType>
283 asynStatus doCallbacksArray(epicsType *value, size_t nElements,
284 int reason, int address, void *interruptPvt);
285
286 friend class paramList;
287 friend class callbackThread;
288};
289
290class callbackThread: public epicsThreadRunable {
291public:
292 callbackThread(asynPortDriver *portDriver);
294 void run();
295private:
296 epicsThread *pThread;
297 asynPortDriver *pPortDriver;
298 epicsEvent shutdown;
299 epicsEvent doneEvent;
300};
301
303template <class T> T* findDerivedAsynPortDriver(const char* portName)
304{
305 // findAsynPortDriver returns a void pointer that was cast from an asynPortDriver pointer
307 if (!apd) return NULL;
308
309 // Downcast asynPortDriver pointer to T pointer - this requires pointer offsetting
310 T* pC = dynamic_cast<T*>(apd);
311 return pC;
312}
313
314#endif /* cplusplus */
315
316#endif
asynParamType
Parameter data types for the parameter library.
Definition asynParamType.h:12
T * findDerivedAsynPortDriver(const char *portName)
Utility function that returns a pointer to an asynPortDriver derived class object from its name.
Definition asynPortDriver.h:303
ASYN_API void * findAsynPortDriver(const char *portName)
Utility function that returns a pointer to an asynPortDriver object from its name.
Definition asynPortDriver.cpp:4193
void(* userTimeStampFunction)(void *userPvt, epicsTimeStamp *pTimeStamp)
Definition asynPortDriver.h:19
Base class for asyn port drivers; handles most of the bookkeeping for writing an asyn port driver wit...
Definition asynPortDriver.h:98
asynStandardInterfaces & asynStdInterfaces
Back-compat alias.
Definition asynPortDriver.h:268
int maxAddr
The maximum asyn address (addr) supported by this driver.
Definition asynPortDriver.h:258
asynUser * pasynUserSelf
asynUser connected to ourselves for asynTrace
Definition asynPortDriver.h:266
char * portName
The name of this asyn port.
Definition asynPortDriver.h:256
asynParamSet * paramSet
Definition asynPortDriver.h:265
void callbackTask()
asynStandardInterfaces * pasynStdInterfaces
The asyn interfaces this driver implements.
Definition asynPortDriver.h:267
Definition asynPortDriver.h:290
~callbackThread()
Definition asynPortDriver.cpp:913
void run()
Definition asynPortDriver.cpp:923
Class to support parameter library (also called parameter list); set and get values indexed by parame...
Definition asynPortDriver.cpp:45