F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
LinuxI2cDriverComponentAc.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title LinuxI2cDriverComponentAc.cpp
3 // \author Generated by fpp-to-cpp
4 // \brief cpp file for LinuxI2cDriver component base class
5 // ======================================================================
6 
7 #include <cstdio>
8 
10 #include "Fw/Types/Assert.hpp"
11 #if FW_ENABLE_TEXT_LOGGING
12 #include "Fw/Types/String.hpp"
13 #endif
14 
15 namespace Drv {
16 
17  // ----------------------------------------------------------------------
18  // Component initialization
19  // ----------------------------------------------------------------------
20 
22  init(NATIVE_INT_TYPE instance)
23  {
24  // Initialize base class
26 
27  // Connect input port read
28  for (
29  PlatformIntType port = 0;
30  port < static_cast<PlatformIntType>(this->getNum_read_InputPorts());
31  port++
32  ) {
33  this->m_read_InputPort[port].init();
34  this->m_read_InputPort[port].addCallComp(
35  this,
36  m_p_read_in
37  );
38  this->m_read_InputPort[port].setPortNum(port);
39 
40 #if FW_OBJECT_NAMES == 1
41  // The port name consists of this->m_objName and some extra info.
42  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
43  // However, the compiler may assume that this->m_objName fills
44  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
45  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
46  // bytes to cover the extra info.
47  char portName[2*FW_OBJ_NAME_MAX_SIZE];
48  (void) snprintf(
49  portName,
50  sizeof(portName),
51  "%s_read_InputPort[%" PRI_PlatformIntType "]",
52  this->m_objName,
53  port
54  );
55  this->m_read_InputPort[port].setObjName(portName);
56 #endif
57  }
58 
59  // Connect input port write
60  for (
61  PlatformIntType port = 0;
62  port < static_cast<PlatformIntType>(this->getNum_write_InputPorts());
63  port++
64  ) {
65  this->m_write_InputPort[port].init();
66  this->m_write_InputPort[port].addCallComp(
67  this,
68  m_p_write_in
69  );
70  this->m_write_InputPort[port].setPortNum(port);
71 
72 #if FW_OBJECT_NAMES == 1
73  // The port name consists of this->m_objName and some extra info.
74  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
75  // However, the compiler may assume that this->m_objName fills
76  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
77  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
78  // bytes to cover the extra info.
79  char portName[2*FW_OBJ_NAME_MAX_SIZE];
80  (void) snprintf(
81  portName,
82  sizeof(portName),
83  "%s_write_InputPort[%" PRI_PlatformIntType "]",
84  this->m_objName,
85  port
86  );
87  this->m_write_InputPort[port].setObjName(portName);
88 #endif
89  }
90 
91  // Connect input port writeRead
92  for (
93  PlatformIntType port = 0;
94  port < static_cast<PlatformIntType>(this->getNum_writeRead_InputPorts());
95  port++
96  ) {
97  this->m_writeRead_InputPort[port].init();
98  this->m_writeRead_InputPort[port].addCallComp(
99  this,
100  m_p_writeRead_in
101  );
102  this->m_writeRead_InputPort[port].setPortNum(port);
103 
104 #if FW_OBJECT_NAMES == 1
105  // The port name consists of this->m_objName and some extra info.
106  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
107  // However, the compiler may assume that this->m_objName fills
108  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
109  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
110  // bytes to cover the extra info.
111  char portName[2*FW_OBJ_NAME_MAX_SIZE];
112  (void) snprintf(
113  portName,
114  sizeof(portName),
115  "%s_writeRead_InputPort[%" PRI_PlatformIntType "]",
116  this->m_objName,
117  port
118  );
119  this->m_writeRead_InputPort[port].setObjName(portName);
120 #endif
121  }
122  }
123 
124  // ----------------------------------------------------------------------
125  // Getters for typed input ports
126  // ----------------------------------------------------------------------
127 
130  {
131  FW_ASSERT(
132  portNum < this->getNum_read_InputPorts(),
133  static_cast<FwAssertArgType>(portNum)
134  );
135 
136  return &this->m_read_InputPort[portNum];
137  }
138 
141  {
142  FW_ASSERT(
143  portNum < this->getNum_write_InputPorts(),
144  static_cast<FwAssertArgType>(portNum)
145  );
146 
147  return &this->m_write_InputPort[portNum];
148  }
149 
152  {
153  FW_ASSERT(
154  portNum < this->getNum_writeRead_InputPorts(),
155  static_cast<FwAssertArgType>(portNum)
156  );
157 
158  return &this->m_writeRead_InputPort[portNum];
159  }
160 
161  // ----------------------------------------------------------------------
162  // Component construction and destruction
163  // ----------------------------------------------------------------------
164 
166  LinuxI2cDriverComponentBase(const char* compName) :
167  Fw::PassiveComponentBase(compName)
168  {
169 
170  }
171 
174  {
175 
176  }
177 
178  // ----------------------------------------------------------------------
179  // Getters for numbers of typed input ports
180  // ----------------------------------------------------------------------
181 
184  {
185  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_read_InputPort));
186  }
187 
190  {
191  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_write_InputPort));
192  }
193 
196  {
197  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_writeRead_InputPort));
198  }
199 
200  // ----------------------------------------------------------------------
201  // Port handler base-class functions for typed input ports
202  //
203  // Call these functions directly to bypass the corresponding ports
204  // ----------------------------------------------------------------------
205 
208  NATIVE_INT_TYPE portNum,
209  U32 addr,
210  Fw::Buffer& serBuffer
211  )
212  {
213  // Make sure port number is valid
214  FW_ASSERT(
215  portNum < this->getNum_read_InputPorts(),
216  static_cast<FwAssertArgType>(portNum)
217  );
218 
219  Drv::I2cStatus retVal;
220 
221  // Lock guard mutex before calling
222  this->lock();
223 
224  // Call handler function
225  retVal = this->read_handler(
226  portNum,
227  addr,
228  serBuffer
229  );
230 
231  // Unlock guard mutex
232  this->unLock();
233 
234  return retVal;
235  }
236 
239  NATIVE_INT_TYPE portNum,
240  U32 addr,
241  Fw::Buffer& serBuffer
242  )
243  {
244  // Make sure port number is valid
245  FW_ASSERT(
246  portNum < this->getNum_write_InputPorts(),
247  static_cast<FwAssertArgType>(portNum)
248  );
249 
250  Drv::I2cStatus retVal;
251 
252  // Lock guard mutex before calling
253  this->lock();
254 
255  // Call handler function
256  retVal = this->write_handler(
257  portNum,
258  addr,
259  serBuffer
260  );
261 
262  // Unlock guard mutex
263  this->unLock();
264 
265  return retVal;
266  }
267 
270  NATIVE_INT_TYPE portNum,
271  U32 addr,
272  Fw::Buffer& writeBuffer,
273  Fw::Buffer& readBuffer
274  )
275  {
276  // Make sure port number is valid
277  FW_ASSERT(
278  portNum < this->getNum_writeRead_InputPorts(),
279  static_cast<FwAssertArgType>(portNum)
280  );
281 
282  Drv::I2cStatus retVal;
283 
284  // Lock guard mutex before calling
285  this->lock();
286 
287  // Call handler function
288  retVal = this->writeRead_handler(
289  portNum,
290  addr,
291  writeBuffer,
292  readBuffer
293  );
294 
295  // Unlock guard mutex
296  this->unLock();
297 
298  return retVal;
299  }
300 
301  // ----------------------------------------------------------------------
302  // Mutex operations for guarded ports
303  //
304  // You can override these operations to provide more sophisticated
305  // synchronization
306  // ----------------------------------------------------------------------
307 
309  lock()
310  {
311  this->m_guardedPortMutex.lock();
312  }
313 
315  unLock()
316  {
317  this->m_guardedPortMutex.unLock();
318  }
319 
320  // ----------------------------------------------------------------------
321  // Calls for messages received on typed input ports
322  // ----------------------------------------------------------------------
323 
324  Drv::I2cStatus LinuxI2cDriverComponentBase ::
325  m_p_read_in(
326  Fw::PassiveComponentBase* callComp,
327  NATIVE_INT_TYPE portNum,
328  U32 addr,
329  Fw::Buffer& serBuffer
330  )
331  {
332  FW_ASSERT(callComp);
333  LinuxI2cDriverComponentBase* compPtr = static_cast<LinuxI2cDriverComponentBase*>(callComp);
334  return compPtr->read_handlerBase(
335  portNum,
336  addr,
337  serBuffer
338  );
339  }
340 
341  Drv::I2cStatus LinuxI2cDriverComponentBase ::
342  m_p_write_in(
343  Fw::PassiveComponentBase* callComp,
344  NATIVE_INT_TYPE portNum,
345  U32 addr,
346  Fw::Buffer& serBuffer
347  )
348  {
349  FW_ASSERT(callComp);
350  LinuxI2cDriverComponentBase* compPtr = static_cast<LinuxI2cDriverComponentBase*>(callComp);
351  return compPtr->write_handlerBase(
352  portNum,
353  addr,
354  serBuffer
355  );
356  }
357 
358  Drv::I2cStatus LinuxI2cDriverComponentBase ::
359  m_p_writeRead_in(
360  Fw::PassiveComponentBase* callComp,
361  NATIVE_INT_TYPE portNum,
362  U32 addr,
363  Fw::Buffer& writeBuffer,
364  Fw::Buffer& readBuffer
365  )
366  {
367  FW_ASSERT(callComp);
368  LinuxI2cDriverComponentBase* compPtr = static_cast<LinuxI2cDriverComponentBase*>(callComp);
369  return compPtr->writeRead_handlerBase(
370  portNum,
371  addr,
372  writeBuffer,
373  readBuffer
374  );
375  }
376 
377 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:51
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:66
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
#define PRI_PlatformIntType
PlatformAssertArgType FwAssertArgType
Definition: FpConfig.h:21
#define FW_OBJ_NAME_MAX_SIZE
Size of object name (if object names enabled). AC Limits to 80, truncation occurs above 80.
Definition: FpConfig.h:184
Input I2c port.
Definition: I2cPortAc.hpp:26
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
Definition: I2cPortAc.cpp:32
void init()
Initialization function.
Definition: I2cPortAc.cpp:26
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
void init()
Initialization function.
Auto-generated base for LinuxI2cDriver component.
Drv::InputI2cPort * get_read_InputPort(NATIVE_INT_TYPE portNum)
virtual Drv::I2cStatus read_handler(NATIVE_INT_TYPE portNum, U32 addr, Fw::Buffer &serBuffer)=0
Handler for input port read.
virtual Drv::I2cStatus write_handler(NATIVE_INT_TYPE portNum, U32 addr, Fw::Buffer &serBuffer)=0
Handler for input port write.
Drv::I2cStatus read_handlerBase(NATIVE_INT_TYPE portNum, U32 addr, Fw::Buffer &serBuffer)
Handler base-class function for input port read.
Drv::InputI2cWriteReadPort * get_writeRead_InputPort(NATIVE_INT_TYPE portNum)
LinuxI2cDriverComponentBase(const char *compName="")
Construct LinuxI2cDriverComponentBase object.
virtual void lock()
Lock the guarded mutex.
Drv::InputI2cPort * get_write_InputPort(NATIVE_INT_TYPE portNum)
NATIVE_INT_TYPE getNum_writeRead_InputPorts() const
Drv::I2cStatus write_handlerBase(NATIVE_INT_TYPE portNum, U32 addr, Fw::Buffer &serBuffer)
Handler base-class function for input port write.
virtual void unLock()
Unlock the guarded mutex.
Drv::I2cStatus writeRead_handlerBase(NATIVE_INT_TYPE portNum, U32 addr, Fw::Buffer &writeBuffer, Fw::Buffer &readBuffer)
Handler base-class function for input port writeRead.
virtual Drv::I2cStatus writeRead_handler(NATIVE_INT_TYPE portNum, U32 addr, Fw::Buffer &writeBuffer, Fw::Buffer &readBuffer)=0
Handler for input port writeRead.
virtual ~LinuxI2cDriverComponentBase()
Destroy LinuxI2cDriverComponentBase object.
void setPortNum(NATIVE_INT_TYPE portNum)
void init()
Object initializer.
Definition: ObjBase.cpp:27
void unLock()
unlock the mutex
Definition: Mutex.cpp:13
void lock()
lock the mutex
Definition: Mutex.cpp:12