F´ Flight Software - C/C++ Documentation
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 
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_FwIndexType "]",
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_FwIndexType "]",
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_FwIndexType "]",
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  (0 <= portNum) && (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  (0 <= portNum) && (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  (0 <= portNum) && (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  // Port handler base-class functions for typed input ports
155  //
156  // Call these functions directly to bypass the corresponding ports
157  // ----------------------------------------------------------------------
158 
161  FwIndexType portNum,
162  U32 addr,
163  Fw::Buffer& serBuffer
164  )
165  {
166  // Make sure port number is valid
167  FW_ASSERT(
168  (0 <= portNum) && (portNum < this->getNum_read_InputPorts()),
169  static_cast<FwAssertArgType>(portNum)
170  );
171 
172  Drv::I2cStatus retVal;
173 
174  // Lock guard mutex before calling
175  this->lock();
176 
177  // Call handler function
178  retVal = this->read_handler(
179  portNum,
180  addr,
181  serBuffer
182  );
183 
184  // Unlock guard mutex
185  this->unLock();
186 
187  return retVal;
188  }
189 
192  FwIndexType portNum,
193  U32 addr,
194  Fw::Buffer& serBuffer
195  )
196  {
197  // Make sure port number is valid
198  FW_ASSERT(
199  (0 <= portNum) && (portNum < this->getNum_write_InputPorts()),
200  static_cast<FwAssertArgType>(portNum)
201  );
202 
203  Drv::I2cStatus retVal;
204 
205  // Lock guard mutex before calling
206  this->lock();
207 
208  // Call handler function
209  retVal = this->write_handler(
210  portNum,
211  addr,
212  serBuffer
213  );
214 
215  // Unlock guard mutex
216  this->unLock();
217 
218  return retVal;
219  }
220 
223  FwIndexType portNum,
224  U32 addr,
225  Fw::Buffer& writeBuffer,
226  Fw::Buffer& readBuffer
227  )
228  {
229  // Make sure port number is valid
230  FW_ASSERT(
231  (0 <= portNum) && (portNum < this->getNum_writeRead_InputPorts()),
232  static_cast<FwAssertArgType>(portNum)
233  );
234 
235  Drv::I2cStatus retVal;
236 
237  // Lock guard mutex before calling
238  this->lock();
239 
240  // Call handler function
241  retVal = this->writeRead_handler(
242  portNum,
243  addr,
244  writeBuffer,
245  readBuffer
246  );
247 
248  // Unlock guard mutex
249  this->unLock();
250 
251  return retVal;
252  }
253 
254  // ----------------------------------------------------------------------
255  // Mutex operations for guarded ports
256  //
257  // You can override these operations to provide more sophisticated
258  // synchronization
259  // ----------------------------------------------------------------------
260 
263  {
264  this->m_guardedPortMutex.lock();
265  }
266 
269  {
270  this->m_guardedPortMutex.unLock();
271  }
272 
273  // ----------------------------------------------------------------------
274  // Calls for messages received on typed input ports
275  // ----------------------------------------------------------------------
276 
277  Drv::I2cStatus LinuxI2cDriverComponentBase ::
278  m_p_read_in(
279  Fw::PassiveComponentBase* callComp,
280  FwIndexType portNum,
281  U32 addr,
282  Fw::Buffer& serBuffer
283  )
284  {
285  FW_ASSERT(callComp);
286  LinuxI2cDriverComponentBase* compPtr = static_cast<LinuxI2cDriverComponentBase*>(callComp);
287  return compPtr->read_handlerBase(
288  portNum,
289  addr,
290  serBuffer
291  );
292  }
293 
294  Drv::I2cStatus LinuxI2cDriverComponentBase ::
295  m_p_write_in(
296  Fw::PassiveComponentBase* callComp,
297  FwIndexType portNum,
298  U32 addr,
299  Fw::Buffer& serBuffer
300  )
301  {
302  FW_ASSERT(callComp);
303  LinuxI2cDriverComponentBase* compPtr = static_cast<LinuxI2cDriverComponentBase*>(callComp);
304  return compPtr->write_handlerBase(
305  portNum,
306  addr,
307  serBuffer
308  );
309  }
310 
311  Drv::I2cStatus LinuxI2cDriverComponentBase ::
312  m_p_writeRead_in(
313  Fw::PassiveComponentBase* callComp,
314  FwIndexType portNum,
315  U32 addr,
316  Fw::Buffer& writeBuffer,
317  Fw::Buffer& readBuffer
318  )
319  {
320  FW_ASSERT(callComp);
321  LinuxI2cDriverComponentBase* compPtr = static_cast<LinuxI2cDriverComponentBase*>(callComp);
322  return compPtr->writeRead_handlerBase(
323  portNum,
324  addr,
325  writeBuffer,
326  readBuffer
327  );
328  }
329 
330 }
virtual void lock()
Lock the guarded mutex.
Drv::InputI2cPort * get_write_InputPort(FwIndexType portNum)
Drv::I2cStatus read_handlerBase(FwIndexType portNum, U32 addr, Fw::Buffer &serBuffer)
Handler base-class function for input port read.
I32 FwEnumStoreType
Drv::InputI2cPort * get_read_InputPort(FwIndexType portNum)
void unLock()
unlock the mutex and assert success
Definition: Mutex.cpp:41
static constexpr FwIndexType getNum_writeRead_InputPorts()
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
void init()
Object initializer.
Definition: ObjBase.cpp:24
virtual void unLock()
Unlock the guarded mutex.
void init()
Initialization function.
const char * toChar() const
Convert to a C-style char*.
Definition: ObjectName.hpp:50
Drv::I2cStatus write_handlerBase(FwIndexType portNum, U32 addr, Fw::Buffer &serBuffer)
Handler base-class function for input port write.
LinuxI2cDriverComponentBase(const char *compName="")
Construct LinuxI2cDriverComponentBase object.
virtual Drv::I2cStatus writeRead_handler(FwIndexType portNum, U32 addr, Fw::Buffer &writeBuffer, Fw::Buffer &readBuffer)=0
Handler for input port writeRead.
Drv::InputI2cWriteReadPort * get_writeRead_InputPort(FwIndexType portNum)
#define PRI_FwIndexType
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:39
void setPortNum(FwIndexType portNum)
Auto-generated base for LinuxI2cDriver component.
Drv::I2cStatus writeRead_handlerBase(FwIndexType portNum, U32 addr, Fw::Buffer &writeBuffer, Fw::Buffer &readBuffer)
Handler base-class function for input port writeRead.
void init()
Initialization function.
Definition: I2cPortAc.cpp:26
virtual Drv::I2cStatus read_handler(FwIndexType portNum, U32 addr, Fw::Buffer &serBuffer)=0
Handler for input port read.
PlatformIndexType FwIndexType
static constexpr FwIndexType getNum_write_InputPorts()
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
Definition: I2cPortAc.cpp:32
static constexpr FwIndexType getNum_read_InputPorts()
Implementation of malloc based allocator.
virtual Drv::I2cStatus write_handler(FwIndexType portNum, U32 addr, Fw::Buffer &serBuffer)=0
Handler for input port write.
virtual ~LinuxI2cDriverComponentBase()
Destroy LinuxI2cDriverComponentBase object.
Input I2c port.
Definition: I2cPortAc.hpp:24
#define FW_ASSERT(...)
Definition: Assert.hpp:14
void lock()
lock the mutex and assert success
Definition: Mutex.cpp:34