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 #if !FW_DIRECT_PORT_CALLS
27  // Connect input port read
28  for (
29  FwIndexType port = 0;
30  port < static_cast<FwIndexType>(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  Fw::ObjectName portName;
42  portName.format(
43  "%s_read_InputPort[%" PRI_FwIndexType "]",
44  this->m_objName.toChar(),
45  port
46  );
47  this->m_read_InputPort[port].setObjName(portName.toChar());
48 #endif
49  }
50 #endif
51 
52 #if !FW_DIRECT_PORT_CALLS
53  // Connect input port write
54  for (
55  FwIndexType port = 0;
56  port < static_cast<FwIndexType>(this->getNum_write_InputPorts());
57  port++
58  ) {
59  this->m_write_InputPort[port].init();
60  this->m_write_InputPort[port].addCallComp(
61  this,
62  m_p_write_in
63  );
64  this->m_write_InputPort[port].setPortNum(port);
65 
66 #if FW_OBJECT_NAMES == 1
67  Fw::ObjectName portName;
68  portName.format(
69  "%s_write_InputPort[%" PRI_FwIndexType "]",
70  this->m_objName.toChar(),
71  port
72  );
73  this->m_write_InputPort[port].setObjName(portName.toChar());
74 #endif
75  }
76 #endif
77 
78 #if !FW_DIRECT_PORT_CALLS
79  // Connect input port writeRead
80  for (
81  FwIndexType port = 0;
82  port < static_cast<FwIndexType>(this->getNum_writeRead_InputPorts());
83  port++
84  ) {
85  this->m_writeRead_InputPort[port].init();
86  this->m_writeRead_InputPort[port].addCallComp(
87  this,
88  m_p_writeRead_in
89  );
90  this->m_writeRead_InputPort[port].setPortNum(port);
91 
92 #if FW_OBJECT_NAMES == 1
93  Fw::ObjectName portName;
94  portName.format(
95  "%s_writeRead_InputPort[%" PRI_FwIndexType "]",
96  this->m_objName.toChar(),
97  port
98  );
99  this->m_writeRead_InputPort[port].setObjName(portName.toChar());
100 #endif
101  }
102 #endif
103  }
104 
105 #if !FW_DIRECT_PORT_CALLS
106 
107  // ----------------------------------------------------------------------
108  // Getters for typed input ports
109  // ----------------------------------------------------------------------
110 
113  {
114  FW_ASSERT(
115  (0 <= portNum) && (portNum < this->getNum_read_InputPorts()),
116  static_cast<FwAssertArgType>(portNum)
117  );
118 
119  return &this->m_read_InputPort[portNum];
120  }
121 
124  {
125  FW_ASSERT(
126  (0 <= portNum) && (portNum < this->getNum_write_InputPorts()),
127  static_cast<FwAssertArgType>(portNum)
128  );
129 
130  return &this->m_write_InputPort[portNum];
131  }
132 
135  {
136  FW_ASSERT(
137  (0 <= portNum) && (portNum < this->getNum_writeRead_InputPorts()),
138  static_cast<FwAssertArgType>(portNum)
139  );
140 
141  return &this->m_writeRead_InputPort[portNum];
142  }
143 
144 #endif
145 
146  // ----------------------------------------------------------------------
147  // Component construction and destruction
148  // ----------------------------------------------------------------------
149 
151  LinuxI2cDriverComponentBase(const char* compName) :
152  Fw::PassiveComponentBase(compName)
153  {
154 
155  }
156 
159  {
160 
161  }
162 
163  // ----------------------------------------------------------------------
164  // Port handler base-class functions for typed input ports
165  //
166  // Call these functions directly to bypass the corresponding ports
167  // ----------------------------------------------------------------------
168 
171  FwIndexType portNum,
172  U32 addr,
173  Fw::Buffer& serBuffer
174  )
175  {
176  // Make sure port number is valid
177  FW_ASSERT(
178  (0 <= portNum) && (portNum < this->getNum_read_InputPorts()),
179  static_cast<FwAssertArgType>(portNum)
180  );
181 
182  Drv::I2cStatus retVal;
183 
184  // Lock guard mutex before calling
185  this->lock();
186 
187  // Call handler function
188  retVal = this->read_handler(
189  portNum,
190  addr,
191  serBuffer
192  );
193 
194  // Unlock guard mutex
195  this->unLock();
196 
197  return retVal;
198  }
199 
202  FwIndexType portNum,
203  U32 addr,
204  Fw::Buffer& serBuffer
205  )
206  {
207  // Make sure port number is valid
208  FW_ASSERT(
209  (0 <= portNum) && (portNum < this->getNum_write_InputPorts()),
210  static_cast<FwAssertArgType>(portNum)
211  );
212 
213  Drv::I2cStatus retVal;
214 
215  // Lock guard mutex before calling
216  this->lock();
217 
218  // Call handler function
219  retVal = this->write_handler(
220  portNum,
221  addr,
222  serBuffer
223  );
224 
225  // Unlock guard mutex
226  this->unLock();
227 
228  return retVal;
229  }
230 
233  FwIndexType portNum,
234  U32 addr,
235  Fw::Buffer& writeBuffer,
236  Fw::Buffer& readBuffer
237  )
238  {
239  // Make sure port number is valid
240  FW_ASSERT(
241  (0 <= portNum) && (portNum < this->getNum_writeRead_InputPorts()),
242  static_cast<FwAssertArgType>(portNum)
243  );
244 
245  Drv::I2cStatus retVal;
246 
247  // Lock guard mutex before calling
248  this->lock();
249 
250  // Call handler function
251  retVal = this->writeRead_handler(
252  portNum,
253  addr,
254  writeBuffer,
255  readBuffer
256  );
257 
258  // Unlock guard mutex
259  this->unLock();
260 
261  return retVal;
262  }
263 
264  // ----------------------------------------------------------------------
265  // Mutex operations for guarded ports
266  //
267  // You can override these operations to provide more sophisticated
268  // synchronization
269  // ----------------------------------------------------------------------
270 
273  {
274  this->m_guardedPortMutex.lock();
275  }
276 
279  {
280  this->m_guardedPortMutex.unLock();
281  }
282 
283  // ----------------------------------------------------------------------
284  // Calls for messages received on typed input ports
285  // ----------------------------------------------------------------------
286 
287  Drv::I2cStatus LinuxI2cDriverComponentBase ::
288  m_p_read_in(
289  Fw::PassiveComponentBase* callComp,
290  FwIndexType portNum,
291  U32 addr,
292  Fw::Buffer& serBuffer
293  )
294  {
295  FW_ASSERT(callComp);
296  LinuxI2cDriverComponentBase* compPtr = static_cast<LinuxI2cDriverComponentBase*>(callComp);
297  return compPtr->read_handlerBase(
298  portNum,
299  addr,
300  serBuffer
301  );
302  }
303 
304  Drv::I2cStatus LinuxI2cDriverComponentBase ::
305  m_p_write_in(
306  Fw::PassiveComponentBase* callComp,
307  FwIndexType portNum,
308  U32 addr,
309  Fw::Buffer& serBuffer
310  )
311  {
312  FW_ASSERT(callComp);
313  LinuxI2cDriverComponentBase* compPtr = static_cast<LinuxI2cDriverComponentBase*>(callComp);
314  return compPtr->write_handlerBase(
315  portNum,
316  addr,
317  serBuffer
318  );
319  }
320 
321  Drv::I2cStatus LinuxI2cDriverComponentBase ::
322  m_p_writeRead_in(
323  Fw::PassiveComponentBase* callComp,
324  FwIndexType portNum,
325  U32 addr,
326  Fw::Buffer& writeBuffer,
327  Fw::Buffer& readBuffer
328  )
329  {
330  FW_ASSERT(callComp);
331  LinuxI2cDriverComponentBase* compPtr = static_cast<LinuxI2cDriverComponentBase*>(callComp);
332  return compPtr->writeRead_handlerBase(
333  portNum,
334  addr,
335  writeBuffer,
336  readBuffer
337  );
338  }
339 
340 }
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:31
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:37
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