INOS
cinosbits.h
Go to the documentation of this file.
1 //******************************************************************************
27 //******************************************************************************
28 
29 #ifndef INC_CINOSBITS_H
30 #define INC_CINOSBITS_H
31 
32 //------------------------------------------------------------------------------
33 // defines
34 //------------------------------------------------------------------------------
35 //
36 #define DF_PROCESS_IMAGE_DIGITAL_INPUTS_NUMBER DF_INOS_PROCESSIMAGE_DIGITAL_INPUTS_NUMBER // def. number of dig inputs
37 #define DF_PROCESS_IMAGE_DIGITAL_OUTPUTS_NUMBER DF_INOS_PROCESSIMAGE_DIGITAL_OUTPUTS_NUMBER // def. number of dig outputs
38 #define DF_PROCESS_IMAGE_DIGITAL_FLAGS_NUMBER 16384 // def. number of dig flags
39 //
40 #define DF_INOS_FLAG_DBT "INOS-FLAG" // INOS-FLAG db table name
41 //
42 //------------------------------------------------------------------------------
43 // includes
44 //------------------------------------------------------------------------------
45 //
46 // system
47 //
48 // C++
49 //
50 // project
51 //
52 //------------------------------------------------------------------------------
53 // Database structures
54 //------------------------------------------------------------------------------
55 //
57 struct SINOSFlag
58 {
60  inosName32 m_cName;
62  uint16 m_uNumber;
64  uint8 m_uOverwrite;
67 };
68 //------------------------------------------------------------------------------
69 // class definition
70 //------------------------------------------------------------------------------
71 //
73 {
74  //--- user interface ---------------------------------------------------
75 
76  // public member functions
77  public :
78  ICACHE virtual void Set(uint16 auNumber, real64 arValue) override;
79  //; set channel 'auNumber' to arValue
80  ICACHE virtual real64 Get(uint16 auNumber) override;
81  //; get value of channel 'auNumber'
82  #if defined(INOS_PROCESSIMAGE_OVERWRITE)
83  bool Set(uint16 auNumber, bool abOverwrite = false);
84  //; set bit 'auNumber' and return the value before ('Test and Set')
85  //; (abOverwrite=true -> bit always set, abOverwrite=false -> bit set
86  //; if channel is NOT in overwrite mode)
87  bool Clear(uint16 auNumber, bool abOverwrite = false);
88  //; clear bit 'auNumber' and return the value before
89  //; (abOverwrite=true -> bit always cleared, abOverwrite=false ->
90  //; bit cleared if channel is NOT in overwrite mode)
91  #else
92  bool Set(uint16 auNumber);
93  //; set bit 'auNumber' and return the value before ('Test and Set')
94  bool Clear(uint16 auNumber);
95  //; clear bit 'auNumber' and return the value before
96  #endif
97  bool SetEx(uint16 auNumber, uint16 auIndex);
98  //; set array based bit 'auNumber' and return the value before
99  bool SetLatched(uint16 auNumber);
100  //; set latched bit 'auNumber' and return the value before ('Test and Set')
101  bool ClearEx(uint16 auNumber, uint16 auIndex);
102  //; clear array based bit 'auNumber' and return the value before
103  bool ClearLatched(uint16 auNumber);
104  //; clear latched bit 'auNumber' and return the value before ('Test and Set')
105  bool Test(uint16 auNumber);
106  //; test bit 'auNumber'
107  bool TestEx(uint16 auNumber, uint16 auIndex);
108  //; test array based bit 'auNumber'
109  bool TestLatched(uint16 auNumber);
110  //; test latched bit 'auNumber'
111  uint32 WaitForSet(uint16 auNumber, uint32 aTimeout=INOS_WAIT_FOREVER);
112  //; wait max. aTimeout usec for bit 'auNumber' set
113  //; return value == 0 -> timeout, != 0 -> time waited for bit (in usec)
114  uint32 WaitForCleared(uint16 auNumber, uint32 aTimeout=INOS_WAIT_FOREVER);
115  //; wait max. aTimeout usec for bit 'auNumber' cleared
116  //; return value == 0 -> timeout, != 0 -> time waited for bit (in usec)
117  #if defined(INOS_PROCESSIMAGE_OVERWRITE)
118  virtual void SetOverwrite(bool abValue) override;
119  //; change the whole process image from real to overwrite mode if
120  //; abValue = true or vice versa
121  virtual bool GetOverwrite() override;
122  //; get actual overwrite mode of the whole process image
123  virtual void SetOverwrite(uint16 auNumber, bool abValue) override;
124  //; change the bit 'auNumber' from real to overwrite mode if
125  //; abValue = true or vice versa
126  virtual bool GetOverwrite(uint16 auNumber) override;
127  //; get actual overwrite mode of bit 'auNumber'
128  #endif
129  virtual void SetSimulated(uint16 auNumber, bool abValue) override;
130  //; set bit simulated
131  virtual bool GetSimulated(uint16 auNumber) override;
132  //; get bit simulated
133  void ConvertToReal(uint16 auOldNumber, uint16 auNewNumber);
134  //; get bit simulated
135  CINOSBit* Find(const char* apName,
136  uint32 auSimulate = DF_INOS_IMAGE_CHN_SIM_DEF);
137  //; return pointer to bit with apName or NULL if not found
138  CINOSBit* Find(uint16 auNumber,
139  uint32 auSimulate = DF_INOS_IMAGE_CHN_SIM_DEF);
140  //; return pointer to bit with auNumber or NULL if not found
141  virtual void SetConfig(uint16 auNumber, uint32 auConfig, uint32 auMask,
142  uint32 auOffset=0) override;
143  //; set config of channel 'auNumber' to auConfig (only bits set in
144  //; auMask are affected)
145  virtual uint32 GetConfig(uint16 auNumber, uint32 auOffset=0) override;
146  //; get config of channel 'auNumber'
147 
148  virtual void UpdateCycleId(uint16 auNumber, uint16 auCycleId) override;
149  //; update cycle id the channel is updated (this method is usually called
150  //; from axis controllers to inform about downsampled controlling and possible
151  //; other cores)
152 
153  virtual void* GetRealAddress(uint16 auNumber) const;
154  //; Get address to 'real image'
155 
156  virtual void* GetLatchedBaseAddress();
157  //; get base address of latched process image
158 
159  // only digital inputs
160 
161  void SetFilter(uint16 auNumber, uint16 auFilter);
162  //; set filter value (ticks)
163  uint16 GetFilter(uint16 auNumber);
164  //; get filter value (ticks)
165  void SetInverted(uint16 auNumber, bool abInverted);
166  //; set bit inverted
167  bool GetInverted(uint16 auNumber);
168  //; get bit inverted
169  void* GetInvertedBaseAddress();
170  //; get address of inverted-mask
171  #if defined(INOS_PROCESSIMAGE_OVERWRITE)
172  void* GetOverwrite0BaseAddress();
173  //; get address of overwrite0
174  void* GetOverwrite1BaseAddress();
175  //; get address of overwrite1
176  #endif
177 
178  CINOSBit* CreateVirtual(const char* apName);
179  //; creates a new digital Input/Output that does not directly translate to hardware
180  //; useful to add custom channels to the process image
181 
182  virtual void Remove(uint32 auChannel) override;
183  //; remove process image channel from image
184 
185  //--- internals --------------------------------------------------------
186 
187  friend class CINOSBit;
188  friend class CINOSBitSetEvent;
189  friend class CINOSBitClearedEvent;
190 
191  // constructor / destructor
192  public :
193  #if defined(INOS_PROCESSIMAGE_OVERWRITE)
194  CINOSBits (char* apName, uint32 auNumber, void* apImage,
195  bool abSupportOverwrite = true);
196  #else
197  CINOSBits (char* apName, uint32 auNumber, void* apImage);
198  #endif
199 
200  // public member functions but just for internal use
201  public :
202  #if defined(INOS_PROCESSIMAGE_OVERWRITE)
203  virtual void Set(uint16 auChannel, void* apValue,
204  bool abOverwrite = false) override;
205  //; set channel to apValue
206  //; (abOverwrite=true -> value always set, abOverwrite=false -> value
207  //; set if channel is NOT in overwrite mode)
208  #else
209  virtual void Set(uint16 auChannel, void* apValue) override;
210  //; set channel to apValue
211  #endif
212  ICACHE virtual void Set(uint16 auChannel, void* apValue, uint32 auMask) override;
213  //; set real channel to apValue (only bits set in auMask are
214  //; affected)
215  ICACHE void Update(uint32 auChannel, uint32 auOldBits);
216  //; update 'image' area according to actual overwrite state
217  //; (image = real & overwrite_0 | overwrite_1)
218  static CINOSBits* Create(uint32 auImageNumber);
219  //; check if process image already exists, if no create one
220  virtual void MoveChannel(uint16 auOldNumber, uint16 auNewNumber) override;
221  //; move channel auOldNumber to auNewNumber
222 
223  // private members
224  private :
226  void CreateArray(uint16 auChannel, uint16 auArrayLength);
227 
228  // protected members
229  protected:
230  uint32 m_uLatchMode;
231  //; 0 -> 0's are latched, 1 -> 1's are latched
232  uint32 m_uNumberUnits;
233  //; number of uint32 units this image occupies
234  uint32* m_pReal;
235  //; pointer to real part of process image
236  uint32* m_pLatched;
237  //; pointer to latched data (latched = latched &/| image
238  #if defined(INOS_PROCESSIMAGE_OVERWRITE)
239  bool m_bSupportOverwrite;
240  //; true/false -> overwrite mode supported/not supported
241  uint32* m_pOverwrite_0;
242  //; pointer to overwrite 0 data
243  uint32* m_pOverwrite_1;
244  //; pointer to overwrite 1 data
245  #endif
246  uint32* m_pSimulated;
247  //; pointer to simulated data
248  uint32* m_pFilter;
249  //; pointer to filter bit field (bit=1 -> channel wants to be filtered)
250  //; only valid for inputs
251  uint32* m_pInverted;
252  //; pointer to inverted bit field (bit=1 -> channel is inverted)
253  //; only valid for inputs
254 
255  #ifndef INOS_NO_BIT_EVENT_SUPPORT
256  uint32* m_pWaitSet;
257  //; pointer to bit field of set events
258  uint32* m_pWaitClr;
259  //; pointer to bit field of clear events
260  #endif
261 };
262 
263 //
264 //------------------------------------------------------------------------------
265 // global variables
266 //------------------------------------------------------------------------------
267 //
268 #define g_pInputs ((CINOSBits *) g_pImage[DF_PROCESS_IMAGE_DIGITAL_INPUTS])
269 #define g_pOutputs ((CINOSBits *) g_pImage[DF_PROCESS_IMAGE_DIGITAL_OUTPUTS])
270 #define g_pFlags ((CINOSBits *) g_pImage[DF_PROCESS_IMAGE_DIGITAL_FLAGS])
271 
272 // some defines for compatibility
273 #define pInputs g_pInputs
274 #define pOutputs g_pOutputs
275 #define pFlags g_pFlags
276 
277 
278 //------------------------------------------------------------------------------
279 // end of file
280 //------------------------------------------------------------------------------
281 
282 #endif // INC_CINOSBITS_H
CINOSBitClearedEvent
Definition: inos_syn.h:765
SINOSFlag
Structure of INFO-16P-CHN-I database tables.
Definition: cinosbits.h:57
CINOSProcessImage
Definition: cinosprocessimage.h:70
SINOSFlag::m_cName
inosName32 m_cName
flag name
Definition: cinosbits.h:60
CINOSBit
Definition: cinosbit.h:53
SINOSFlag::m_uNumber
uint16 m_uNumber
flag number
Definition: cinosbits.h:62
CINOSBits
Definition: cinosbits.h:72
SINOSFlag::m_uOverwriteValue
uint8 m_uOverwriteValue
Initial overwrite value (only valid if overwrite = true)
Definition: cinosbits.h:66
CINOSBitSetEvent
Definition: inos_syn.h:708
SINOSFlag::m_uOverwrite
uint8 m_uOverwrite
0 -> not in overwrite mode, 1 -> in overwrite mode
Definition: cinosbits.h:64