asyn  4-39
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 
16 class paramList;
17 
18 epicsShareFunc void* findAsynPortDriver(const char *portName);
19 typedef 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 
41 class callbackThread;
42 
45 class epicsShareClass asynPortDriver {
46 public:
47  asynPortDriver(asynParamSet* paramSet,
48  const char *portName, int maxAddr, int interfaceMask, int interruptMask,
49  int asynFlags, int autoConnect, int priority, int stackSize);
50  asynPortDriver(const char *portName, int maxAddr, int interfaceMask, int interruptMask,
51  int asynFlags, int autoConnect, int priority, int stackSize);
52  asynPortDriver(const char *portName, int maxAddr, int paramTableSize, int interfaceMask, int interruptMask,
53  int asynFlags, int autoConnect, int priority, int stackSize) EPICS_DEPRECATED;
54  virtual ~asynPortDriver();
55  virtual asynStatus lock();
56  virtual asynStatus unlock();
57  virtual asynStatus getAddress(asynUser *pasynUser, int *address);
58  virtual asynStatus parseAsynUser(asynUser *pasynUser, int *reason, int *address, const char **paramName);
59  virtual asynStatus readInt32(asynUser *pasynUser, epicsInt32 *value);
60  virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value);
61  virtual asynStatus readInt64(asynUser *pasynUser, epicsInt64 *value);
62  virtual asynStatus writeInt64(asynUser *pasynUser, epicsInt64 value);
63  virtual asynStatus readUInt32Digital(asynUser *pasynUser, epicsUInt32 *value, epicsUInt32 mask);
64  virtual asynStatus writeUInt32Digital(asynUser *pasynUser, epicsUInt32 value, epicsUInt32 mask);
65  virtual asynStatus setInterruptUInt32Digital(asynUser *pasynUser, epicsUInt32 mask, interruptReason reason);
66  virtual asynStatus clearInterruptUInt32Digital(asynUser *pasynUser, epicsUInt32 mask);
67  virtual asynStatus getInterruptUInt32Digital(asynUser *pasynUser, epicsUInt32 *mask, interruptReason reason);
68  virtual asynStatus getBounds(asynUser *pasynUser, epicsInt32 *low, epicsInt32 *high);
69  virtual asynStatus getBounds64(asynUser *pasynUser, epicsInt64 *low, epicsInt64 *high);
70  virtual asynStatus readFloat64(asynUser *pasynUser, epicsFloat64 *value);
71  virtual asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value);
72  virtual asynStatus readOctet(asynUser *pasynUser, char *value, size_t maxChars,
73  size_t *nActual, int *eomReason);
74  virtual asynStatus writeOctet(asynUser *pasynUser, const char *value, size_t maxChars,
75  size_t *nActual);
76  virtual asynStatus flushOctet(asynUser *pasynUser);
77  virtual asynStatus setInputEosOctet(asynUser *pasynUser, const char *eos, int eosLen);
78  virtual asynStatus getInputEosOctet(asynUser *pasynUser, char *eos, int eosSize, int *eosLen);
79  virtual asynStatus setOutputEosOctet(asynUser *pasynUser, const char *eos, int eosLen);
80  virtual asynStatus getOutputEosOctet(asynUser *pasynUser, char *eos, int eosSize, int *eosLen);
81  virtual asynStatus readInt8Array(asynUser *pasynUser, epicsInt8 *value,
82  size_t nElements, size_t *nIn);
83  virtual asynStatus writeInt8Array(asynUser *pasynUser, epicsInt8 *value,
84  size_t nElements);
85  virtual asynStatus doCallbacksInt8Array(epicsInt8 *value,
86  size_t nElements, int reason, int addr);
87  virtual asynStatus readInt16Array(asynUser *pasynUser, epicsInt16 *value,
88  size_t nElements, size_t *nIn);
89  virtual asynStatus writeInt16Array(asynUser *pasynUser, epicsInt16 *value,
90  size_t nElements);
91  virtual asynStatus doCallbacksInt16Array(epicsInt16 *value,
92  size_t nElements, int reason, int addr);
93  virtual asynStatus readInt32Array(asynUser *pasynUser, epicsInt32 *value,
94  size_t nElements, size_t *nIn);
95  virtual asynStatus writeInt32Array(asynUser *pasynUser, epicsInt32 *value,
96  size_t nElements);
97  virtual asynStatus doCallbacksInt32Array(epicsInt32 *value,
98  size_t nElements, int reason, int addr);
99  virtual asynStatus readInt64Array(asynUser *pasynUser, epicsInt64 *value,
100  size_t nElements, size_t *nIn);
101  virtual asynStatus writeInt64Array(asynUser *pasynUser, epicsInt64 *value,
102  size_t nElements);
103  virtual asynStatus doCallbacksInt64Array(epicsInt64 *value,
104  size_t nElements, int reason, int addr);
105  virtual asynStatus readFloat32Array(asynUser *pasynUser, epicsFloat32 *value,
106  size_t nElements, size_t *nIn);
107  virtual asynStatus writeFloat32Array(asynUser *pasynUser, epicsFloat32 *value,
108  size_t nElements);
109  virtual asynStatus doCallbacksFloat32Array(epicsFloat32 *value,
110  size_t nElements, int reason, int addr);
111  virtual asynStatus readFloat64Array(asynUser *pasynUser, epicsFloat64 *value,
112  size_t nElements, size_t *nIn);
113  virtual asynStatus writeFloat64Array(asynUser *pasynUser, epicsFloat64 *value,
114  size_t nElements);
115  virtual asynStatus doCallbacksFloat64Array(epicsFloat64 *value,
116  size_t nElements, int reason, int addr);
117  virtual asynStatus readGenericPointer(asynUser *pasynUser, void *pointer);
118  virtual asynStatus writeGenericPointer(asynUser *pasynUser, void *pointer);
119  virtual asynStatus doCallbacksGenericPointer(void *pointer, int reason, int addr);
120  virtual asynStatus readOption(asynUser *pasynUser, const char *key, char *value, int maxChars);
121  virtual asynStatus writeOption(asynUser *pasynUser, const char *key, const char *value);
122  virtual asynStatus readEnum(asynUser *pasynUser, char *strings[], int values[], int severities[], size_t nElements, size_t *nIn);
123  virtual asynStatus writeEnum(asynUser *pasynUser, char *strings[], int values[], int severities[], size_t nElements);
124  virtual asynStatus doCallbacksEnum(char *strings[], int values[], int severities[], size_t nElements, int reason, int addr);
125  virtual asynStatus drvUserCreate(asynUser *pasynUser, const char *drvInfo,
126  const char **pptypeName, size_t *psize);
127  virtual asynStatus drvUserGetType(asynUser *pasynUser,
128  const char **pptypeName, size_t *psize);
129  virtual asynStatus drvUserDestroy(asynUser *pasynUser);
130  virtual void report(FILE *fp, int details);
131  virtual asynStatus connect(asynUser *pasynUser);
132  virtual asynStatus disconnect(asynUser *pasynUser);
133 
134  virtual asynStatus createParam( const char *name, asynParamType type, int *index);
135  virtual asynStatus createParam(int list, const char *name, asynParamType type, int *index);
136  virtual asynStatus createParams();
137  virtual asynStatus getNumParams( int *numParams);
138  virtual asynStatus getNumParams(int list, int *numParams);
139  virtual asynStatus findParam( const char *name, int *index);
140  virtual asynStatus findParam(int list, const char *name, int *index);
141  virtual asynStatus getParamName( int index, const char **name);
142  virtual asynStatus getParamName(int list, int index, const char **name);
143  virtual asynStatus getParamType( int index, asynParamType *type);
144  virtual asynStatus getParamType(int list, int index, asynParamType *type);
145  virtual asynStatus setParamStatus( int index, asynStatus status);
146  virtual asynStatus setParamStatus(int list, int index, asynStatus status);
147  virtual asynStatus getParamStatus( int index, asynStatus *status);
148  virtual asynStatus getParamStatus(int list, int index, asynStatus *status);
149  virtual asynStatus setParamAlarmStatus( int index, int status);
150  virtual asynStatus setParamAlarmStatus(int list, int index, int status);
151  virtual asynStatus getParamAlarmStatus( int index, int *status);
152  virtual asynStatus getParamAlarmStatus(int list, int index, int *status);
153  virtual asynStatus setParamAlarmSeverity( int index, int severity);
154  virtual asynStatus setParamAlarmSeverity(int list, int index, int severity);
155  virtual asynStatus getParamAlarmSeverity( int index, int *severity);
156  virtual asynStatus getParamAlarmSeverity(int list, int index, int *severity);
157  virtual void reportSetParamErrors(asynStatus status, int index, int list, const char *functionName);
158  virtual void reportGetParamErrors(asynStatus status, int index, int list, const char *functionName);
159  virtual asynStatus setIntegerParam( int index, int value);
160  virtual asynStatus setIntegerParam(int list, int index, int value);
161  virtual asynStatus setInteger64Param( int index, epicsInt64 value);
162  virtual asynStatus setInteger64Param(int list, int index, epicsInt64 value);
163  virtual asynStatus setUIntDigitalParam( int index, epicsUInt32 value, epicsUInt32 valueMask);
164  virtual asynStatus setUIntDigitalParam(int list, int index, epicsUInt32 value, epicsUInt32 valueMask);
165  virtual asynStatus setUIntDigitalParam( int index, epicsUInt32 value, epicsUInt32 valueMask, epicsUInt32 interruptMask);
166  virtual asynStatus setUIntDigitalParam(int list, int index, epicsUInt32 value, epicsUInt32 valueMask, epicsUInt32 interruptMask);
167  virtual asynStatus setUInt32DigitalInterrupt( int index, epicsUInt32 mask, interruptReason reason);
168  virtual asynStatus setUInt32DigitalInterrupt(int list, int index, epicsUInt32 mask, interruptReason reason);
169  virtual asynStatus clearUInt32DigitalInterrupt( int index, epicsUInt32 mask);
170  virtual asynStatus clearUInt32DigitalInterrupt(int list, int index, epicsUInt32 mask);
171  virtual asynStatus getUInt32DigitalInterrupt( int index, epicsUInt32 *mask, interruptReason reason);
172  virtual asynStatus getUInt32DigitalInterrupt(int list, int index, epicsUInt32 *mask, interruptReason reason);
173  virtual asynStatus setDoubleParam( int index, double value);
174  virtual asynStatus setDoubleParam(int list, int index, double value);
175  virtual asynStatus setStringParam( int index, const char *value);
176  virtual asynStatus setStringParam(int list, int index, const char *value);
177  virtual asynStatus setStringParam( int index, const std::string& value);
178  virtual asynStatus setStringParam(int list, int index, const std::string& value);
179  virtual asynStatus getIntegerParam( int index, epicsInt32 * value);
180  virtual asynStatus getIntegerParam(int list, int index, epicsInt32 * value);
181  virtual asynStatus getInteger64Param( int index, epicsInt64 * value);
182  virtual asynStatus getInteger64Param(int list, int index, epicsInt64 * value);
183  virtual asynStatus getUIntDigitalParam( int index, epicsUInt32 *value, epicsUInt32 mask);
184  virtual asynStatus getUIntDigitalParam(int list, int index, epicsUInt32 *value, epicsUInt32 mask);
185  virtual asynStatus getDoubleParam( int index, double * value);
186  virtual asynStatus getDoubleParam(int list, int index, double * value);
187  virtual asynStatus getStringParam( int index, int maxChars, char *value);
188  virtual asynStatus getStringParam(int list, int index, int maxChars, char *value);
189  virtual asynStatus getStringParam( int index, std::string& value);
190  virtual asynStatus getStringParam(int list, int index, std::string& value);
191  virtual asynStatus callParamCallbacks();
192  virtual asynStatus callParamCallbacks( int addr);
193  virtual asynStatus callParamCallbacks(int list, int addr);
194  virtual asynStatus updateTimeStamp();
195  virtual asynStatus updateTimeStamp(epicsTimeStamp *pTimeStamp);
196  virtual asynStatus getTimeStamp(epicsTimeStamp *pTimeStamp);
197  virtual asynStatus setTimeStamp(const epicsTimeStamp *pTimeStamp);
198  asynStandardInterfaces *getAsynStdInterfaces();
199  virtual void reportParams(FILE *fp, int details);
200 
201  char *portName;
203  int maxAddr;
204  void callbackTask();
205 
206 protected:
207  asynParamSet* paramSet;
208  void initialize(const char *portNameIn, int maxAddrIn, int interfaceMask, int interruptMask, int asynFlags,
209  int autoConnect, int priority, int stackSize);
210  asynUser *pasynUserSelf;
211  asynStandardInterfaces asynStdInterfaces;
213 private:
214  std::vector<paramList*> params;
215  epicsMutexId mutexId;
216  char *inputEosOctet;
217  int inputEosLenOctet;
218  char *outputEosOctet;
219  int outputEosLenOctet;
220  callbackThread *cbThread;
221  template <typename epicsType, typename interruptType>
222  asynStatus doCallbacksArray(epicsType *value, size_t nElements,
223  int reason, int address, void *interruptPvt);
224 
225  friend class paramList;
226  friend class callbackThread;
227 };
228 
229 class callbackThread: public epicsThreadRunable {
230 public:
231  callbackThread(asynPortDriver *portDriver);
232  ~callbackThread();
233  void run();
234 private:
235  epicsThread *pThread;
236  asynPortDriver *pPortDriver;
237  epicsEvent shutdown;
238  epicsEvent doneEvent;
239 };
240 
242 template <class T> T* findDerivedAsynPortDriver(const char* portName)
243 {
244  // findAsynPortDriver returns a void pointer that was cast from an asynPortDriver pointer
246  if (!apd) return NULL;
247 
248  // Downcast asynPortDriver pointer to T pointer - this requires pointer offsetting
249  T* pC = dynamic_cast<T*>(apd);
250  return pC;
251 }
252 
253 #endif /* cplusplus */
254 
255 #endif
epicsShareFunc void * findAsynPortDriver(const char *portName)
Utility function that returns a pointer to an asynPortDriver object from its name.
Definition: asynPortDriver.cpp:3834
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:19
Definition: asynPortDriver.h:229
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:45
T * findDerivedAsynPortDriver(const char *portName)
Utility function that returns a pointer to an asynPortDriver derived class object from its name.
Definition: asynPortDriver.h:242
asynParamSet * paramSet
Definition: asynPortDriver.h:207
char * portName
The name of this asyn port.
Definition: asynPortDriver.h:201
void run()
Definition: asynPortDriver.cpp:926
callbackThread(asynPortDriver *portDriver)
Definition: asynPortDriver.cpp:909
asynStandardInterfaces asynStdInterfaces
The asyn interfaces this driver implements.
Definition: asynPortDriver.h:211
~callbackThread()
Definition: asynPortDriver.cpp:916
asynUser * pasynUserSelf
asynUser connected to ourselves for asynTrace
Definition: asynPortDriver.h:210
int maxAddr
The maximum asyn address (addr) supported by this driver.
Definition: asynPortDriver.h:203