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 
8 #include "Fw/Types/Assert.hpp"
10 #if FW_ENABLE_TEXT_LOGGING
11 #include "Fw/Types/String.hpp"
12 #endif
13 
14 namespace Drv {
15 
16  // ----------------------------------------------------------------------
17  // Component initialization
18  // ----------------------------------------------------------------------
19 
21  init(FwEnumStoreType instance)
22  {
23  // Initialize base class
25 
26  // Connect input port read
27  for (
28  FwIndexType port = 0;
29  port < static_cast<FwIndexType>(this->getNum_read_InputPorts());
30  port++
31  ) {
32  this->m_read_InputPort[port].init();
33  this->m_read_InputPort[port].addCallComp(
34  this,
35  m_p_read_in
36  );
37  this->m_read_InputPort[port].setPortNum(port);
38 
39 #if FW_OBJECT_NAMES == 1
40  Fw::ObjectName portName;
41  portName.format(
42  "%s_read_InputPort[%" PRI_PlatformIntType "]",
43  this->m_objName.toChar(),
44  port
45  );
46  this->m_read_InputPort[port].setObjName(portName.toChar());
47 #endif
48  }
49 
50  // Connect input port write
51  for (
52  FwIndexType port = 0;
53  port < static_cast<FwIndexType>(this->getNum_write_InputPorts());
54  port++
55  ) {
56  this->m_write_InputPort[port].init();
57  this->m_write_InputPort[port].addCallComp(
58  this,
59  m_p_write_in
60  );
61  this->m_write_InputPort[port].setPortNum(port);
62 
63 #if FW_OBJECT_NAMES == 1
64  Fw::ObjectName portName;
65  portName.format(
66  "%s_write_InputPort[%" PRI_PlatformIntType "]",
67  this->m_objName.toChar(),
68  port
69  );
70  this->m_write_InputPort[port].setObjName(portName.toChar());
71 #endif
72  }
73 
74  // Connect input port writeRead
75  for (
76  FwIndexType port = 0;
77  port < static_cast<FwIndexType>(this->getNum_writeRead_InputPorts());
78  port++
79  ) {
80  this->m_writeRead_InputPort[port].init();
81  this->m_writeRead_InputPort[port].addCallComp(
82  this,
83  m_p_writeRead_in
84  );
85  this->m_writeRead_InputPort[port].setPortNum(port);
86 
87 #if FW_OBJECT_NAMES == 1
88  Fw::ObjectName portName;
89  portName.format(
90  "%s_writeRead_InputPort[%" PRI_PlatformIntType "]",
91  this->m_objName.toChar(),
92  port
93  );
94  this->m_writeRead_InputPort[port].setObjName(portName.toChar());
95 #endif
96  }
97  }
98 
99  // ----------------------------------------------------------------------
100  // Getters for typed input ports
101  // ----------------------------------------------------------------------
102 
105  {
106  FW_ASSERT(
107  portNum < this->getNum_read_InputPorts(),
108  static_cast<FwAssertArgType>(portNum)
109  );
110 
111  return &this->m_read_InputPort[portNum];
112  }
113 
116  {
117  FW_ASSERT(
118  portNum < this->getNum_write_InputPorts(),
119  static_cast<FwAssertArgType>(portNum)
120  );
121 
122  return &this->m_write_InputPort[portNum];
123  }
124 
127  {
128  FW_ASSERT(
129  portNum < this->getNum_writeRead_InputPorts(),
130  static_cast<FwAssertArgType>(portNum)
131  );
132 
133  return &this->m_writeRead_InputPort[portNum];
134  }
135 
136  // ----------------------------------------------------------------------
137  // Component construction and destruction
138  // ----------------------------------------------------------------------
139 
141  LinuxI2cDriverComponentBase(const char* compName) :
142  Fw::PassiveComponentBase(compName)
143  {
144 
145  }
146 
149  {
150 
151  }
152 
153  // ----------------------------------------------------------------------
154  // Getters for numbers of typed input ports
155  // ----------------------------------------------------------------------
156 
159  {
160  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_read_InputPort));
161  }
162 
165  {
166  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_write_InputPort));
167  }
168 
171  {
172  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_writeRead_InputPort));
173  }
174 
175  // ----------------------------------------------------------------------
176  // Port handler base-class functions for typed input ports
177  //
178  // Call these functions directly to bypass the corresponding ports
179  // ----------------------------------------------------------------------
180 
183  FwIndexType portNum,
184  U32 addr,
185  Fw::Buffer& serBuffer
186  )
187  {
188  // Make sure port number is valid
189  FW_ASSERT(
190  portNum < this->getNum_read_InputPorts(),
191  static_cast<FwAssertArgType>(portNum)
192  );
193 
194  Drv::I2cStatus retVal;
195 
196  // Lock guard mutex before calling
197  this->lock();
198 
199  // Call handler function
200  retVal = this->read_handler(
201  portNum,
202  addr,
203  serBuffer
204  );
205 
206  // Unlock guard mutex
207  this->unLock();
208 
209  return retVal;
210  }
211 
214  FwIndexType portNum,
215  U32 addr,
216  Fw::Buffer& serBuffer
217  )
218  {
219  // Make sure port number is valid
220  FW_ASSERT(
221  portNum < this->getNum_write_InputPorts(),
222  static_cast<FwAssertArgType>(portNum)
223  );
224 
225  Drv::I2cStatus retVal;
226 
227  // Lock guard mutex before calling
228  this->lock();
229 
230  // Call handler function
231  retVal = this->write_handler(
232  portNum,
233  addr,
234  serBuffer
235  );
236 
237  // Unlock guard mutex
238  this->unLock();
239 
240  return retVal;
241  }
242 
245  FwIndexType portNum,
246  U32 addr,
247  Fw::Buffer& writeBuffer,
248  Fw::Buffer& readBuffer
249  )
250  {
251  // Make sure port number is valid
252  FW_ASSERT(
253  portNum < this->getNum_writeRead_InputPorts(),
254  static_cast<FwAssertArgType>(portNum)
255  );
256 
257  Drv::I2cStatus retVal;
258 
259  // Lock guard mutex before calling
260  this->lock();
261 
262  // Call handler function
263  retVal = this->writeRead_handler(
264  portNum,
265  addr,
266  writeBuffer,
267  readBuffer
268  );
269 
270  // Unlock guard mutex
271  this->unLock();
272 
273  return retVal;
274  }
275 
276  // ----------------------------------------------------------------------
277  // Mutex operations for guarded ports
278  //
279  // You can override these operations to provide more sophisticated
280  // synchronization
281  // ----------------------------------------------------------------------
282 
284  lock()
285  {
286  this->m_guardedPortMutex.lock();
287  }
288 
290  unLock()
291  {
292  this->m_guardedPortMutex.unLock();
293  }
294 
295  // ----------------------------------------------------------------------
296  // Calls for messages received on typed input ports
297  // ----------------------------------------------------------------------
298 
299  Drv::I2cStatus LinuxI2cDriverComponentBase ::
300  m_p_read_in(
301  Fw::PassiveComponentBase* callComp,
302  FwIndexType portNum,
303  U32 addr,
304  Fw::Buffer& serBuffer
305  )
306  {
307  FW_ASSERT(callComp);
308  LinuxI2cDriverComponentBase* compPtr = static_cast<LinuxI2cDriverComponentBase*>(callComp);
309  return compPtr->read_handlerBase(
310  portNum,
311  addr,
312  serBuffer
313  );
314  }
315 
316  Drv::I2cStatus LinuxI2cDriverComponentBase ::
317  m_p_write_in(
318  Fw::PassiveComponentBase* callComp,
319  FwIndexType portNum,
320  U32 addr,
321  Fw::Buffer& serBuffer
322  )
323  {
324  FW_ASSERT(callComp);
325  LinuxI2cDriverComponentBase* compPtr = static_cast<LinuxI2cDriverComponentBase*>(callComp);
326  return compPtr->write_handlerBase(
327  portNum,
328  addr,
329  serBuffer
330  );
331  }
332 
333  Drv::I2cStatus LinuxI2cDriverComponentBase ::
334  m_p_writeRead_in(
335  Fw::PassiveComponentBase* callComp,
336  FwIndexType portNum,
337  U32 addr,
338  Fw::Buffer& writeBuffer,
339  Fw::Buffer& readBuffer
340  )
341  {
342  FW_ASSERT(callComp);
343  LinuxI2cDriverComponentBase* compPtr = static_cast<LinuxI2cDriverComponentBase*>(callComp);
344  return compPtr->writeRead_handlerBase(
345  portNum,
346  addr,
347  writeBuffer,
348  readBuffer
349  );
350  }
351 
352 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:70
#define PRI_PlatformIntType
I32 FwEnumStoreType
Definition: FpConfig.h:64
PlatformAssertArgType FwAssertArgType
Definition: FpConfig.h:39
PlatformIndexType FwIndexType
Definition: FpConfig.h:25
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::I2cStatus read_handlerBase(FwIndexType portNum, U32 addr, Fw::Buffer &serBuffer)
Handler base-class function for input port read.
Drv::InputI2cPort * get_read_InputPort(FwIndexType portNum)
Drv::InputI2cWriteReadPort * get_writeRead_InputPort(FwIndexType portNum)
LinuxI2cDriverComponentBase(const char *compName="")
Construct LinuxI2cDriverComponentBase object.
virtual void lock()
Lock the guarded mutex.
virtual Drv::I2cStatus writeRead_handler(FwIndexType portNum, U32 addr, Fw::Buffer &writeBuffer, Fw::Buffer &readBuffer)=0
Handler for input port writeRead.
Drv::I2cStatus write_handlerBase(FwIndexType portNum, U32 addr, Fw::Buffer &serBuffer)
Handler base-class function for input port write.
virtual void unLock()
Unlock the guarded mutex.
virtual Drv::I2cStatus write_handler(FwIndexType portNum, U32 addr, Fw::Buffer &serBuffer)=0
Handler for input port write.
Drv::I2cStatus writeRead_handlerBase(FwIndexType portNum, U32 addr, Fw::Buffer &writeBuffer, Fw::Buffer &readBuffer)
Handler base-class function for input port writeRead.
Drv::InputI2cPort * get_write_InputPort(FwIndexType portNum)
virtual Drv::I2cStatus read_handler(FwIndexType portNum, U32 addr, Fw::Buffer &serBuffer)=0
Handler for input port read.
virtual ~LinuxI2cDriverComponentBase()
Destroy LinuxI2cDriverComponentBase object.
void setPortNum(NATIVE_INT_TYPE portNum)
void init()
Object initializer.
Definition: ObjBase.cpp:27
const char * toChar() const
Definition: ObjectName.hpp:50
void format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:56
void unLock()
unlock the mutex and assert success
Definition: Mutex.cpp:40
void lock()
lock the mutex and assert success
Definition: Mutex.cpp:34