F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
LinuxGpioDriverComponentAc.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title LinuxGpioDriverComponentAc.cpp
3 // \author Generated by fpp-to-cpp
4 // \brief cpp file for LinuxGpioDriver 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 gpioRead
28  for (
29  PlatformIntType port = 0;
30  port < static_cast<PlatformIntType>(this->getNum_gpioRead_InputPorts());
31  port++
32  ) {
33  this->m_gpioRead_InputPort[port].init();
34  this->m_gpioRead_InputPort[port].addCallComp(
35  this,
36  m_p_gpioRead_in
37  );
38  this->m_gpioRead_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_gpioRead_InputPort[%" PRI_PlatformIntType "]",
52  this->m_objName,
53  port
54  );
55  this->m_gpioRead_InputPort[port].setObjName(portName);
56 #endif
57  }
58 
59  // Connect input port gpioWrite
60  for (
61  PlatformIntType port = 0;
62  port < static_cast<PlatformIntType>(this->getNum_gpioWrite_InputPorts());
63  port++
64  ) {
65  this->m_gpioWrite_InputPort[port].init();
66  this->m_gpioWrite_InputPort[port].addCallComp(
67  this,
68  m_p_gpioWrite_in
69  );
70  this->m_gpioWrite_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_gpioWrite_InputPort[%" PRI_PlatformIntType "]",
84  this->m_objName,
85  port
86  );
87  this->m_gpioWrite_InputPort[port].setObjName(portName);
88 #endif
89  }
90 
91  // Connect output port Log
92  for (
93  PlatformIntType port = 0;
94  port < static_cast<PlatformIntType>(this->getNum_Log_OutputPorts());
95  port++
96  ) {
97  this->m_Log_OutputPort[port].init();
98 
99 #if FW_OBJECT_NAMES == 1
100  // The port name consists of this->m_objName and some extra info.
101  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
102  // However, the compiler may assume that this->m_objName fills
103  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
104  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
105  // bytes to cover the extra info.
106  char portName[2*FW_OBJ_NAME_MAX_SIZE];
107  (void) snprintf(
108  portName,
109  sizeof(portName),
110  "%s_Log_OutputPort[%" PRI_PlatformIntType "]",
111  this->m_objName,
112  port
113  );
114  this->m_Log_OutputPort[port].setObjName(portName);
115 #endif
116  }
117 
118 #if FW_ENABLE_TEXT_LOGGING == 1
119  // Connect output port LogText
120  for (
121  PlatformIntType port = 0;
122  port < static_cast<PlatformIntType>(this->getNum_LogText_OutputPorts());
123  port++
124  ) {
125  this->m_LogText_OutputPort[port].init();
126 
127 #if FW_OBJECT_NAMES == 1
128  // The port name consists of this->m_objName and some extra info.
129  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
130  // However, the compiler may assume that this->m_objName fills
131  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
132  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
133  // bytes to cover the extra info.
134  char portName[2*FW_OBJ_NAME_MAX_SIZE];
135  (void) snprintf(
136  portName,
137  sizeof(portName),
138  "%s_LogText_OutputPort[%" PRI_PlatformIntType "]",
139  this->m_objName,
140  port
141  );
142  this->m_LogText_OutputPort[port].setObjName(portName);
143 #endif
144  }
145 #endif
146 
147  // Connect output port Time
148  for (
149  PlatformIntType port = 0;
150  port < static_cast<PlatformIntType>(this->getNum_Time_OutputPorts());
151  port++
152  ) {
153  this->m_Time_OutputPort[port].init();
154 
155 #if FW_OBJECT_NAMES == 1
156  // The port name consists of this->m_objName and some extra info.
157  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
158  // However, the compiler may assume that this->m_objName fills
159  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
160  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
161  // bytes to cover the extra info.
162  char portName[2*FW_OBJ_NAME_MAX_SIZE];
163  (void) snprintf(
164  portName,
165  sizeof(portName),
166  "%s_Time_OutputPort[%" PRI_PlatformIntType "]",
167  this->m_objName,
168  port
169  );
170  this->m_Time_OutputPort[port].setObjName(portName);
171 #endif
172  }
173 
174  // Connect output port intOut
175  for (
176  PlatformIntType port = 0;
177  port < static_cast<PlatformIntType>(this->getNum_intOut_OutputPorts());
178  port++
179  ) {
180  this->m_intOut_OutputPort[port].init();
181 
182 #if FW_OBJECT_NAMES == 1
183  // The port name consists of this->m_objName and some extra info.
184  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
185  // However, the compiler may assume that this->m_objName fills
186  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
187  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
188  // bytes to cover the extra info.
189  char portName[2*FW_OBJ_NAME_MAX_SIZE];
190  (void) snprintf(
191  portName,
192  sizeof(portName),
193  "%s_intOut_OutputPort[%" PRI_PlatformIntType "]",
194  this->m_objName,
195  port
196  );
197  this->m_intOut_OutputPort[port].setObjName(portName);
198 #endif
199  }
200  }
201 
202  // ----------------------------------------------------------------------
203  // Getters for typed input ports
204  // ----------------------------------------------------------------------
205 
208  {
209  FW_ASSERT(
210  portNum < this->getNum_gpioRead_InputPorts(),
211  static_cast<FwAssertArgType>(portNum)
212  );
213 
214  return &this->m_gpioRead_InputPort[portNum];
215  }
216 
219  {
220  FW_ASSERT(
221  portNum < this->getNum_gpioWrite_InputPorts(),
222  static_cast<FwAssertArgType>(portNum)
223  );
224 
225  return &this->m_gpioWrite_InputPort[portNum];
226  }
227 
228  // ----------------------------------------------------------------------
229  // Connect input ports to special output ports
230  // ----------------------------------------------------------------------
231 
234  NATIVE_INT_TYPE portNum,
235  Fw::InputLogPort* port
236  )
237  {
238  FW_ASSERT(
239  portNum < this->getNum_Log_OutputPorts(),
240  static_cast<FwAssertArgType>(portNum)
241  );
242 
243  this->m_Log_OutputPort[portNum].addCallPort(port);
244  }
245 
246 #if FW_ENABLE_TEXT_LOGGING == 1
247 
248  void LinuxGpioDriverComponentBase ::
249  set_LogText_OutputPort(
250  NATIVE_INT_TYPE portNum,
252  )
253  {
254  FW_ASSERT(
255  portNum < this->getNum_LogText_OutputPorts(),
256  static_cast<FwAssertArgType>(portNum)
257  );
258 
259  this->m_LogText_OutputPort[portNum].addCallPort(port);
260  }
261 
262 #endif
263 
266  NATIVE_INT_TYPE portNum,
267  Fw::InputTimePort* port
268  )
269  {
270  FW_ASSERT(
271  portNum < this->getNum_Time_OutputPorts(),
272  static_cast<FwAssertArgType>(portNum)
273  );
274 
275  this->m_Time_OutputPort[portNum].addCallPort(port);
276  }
277 
278  // ----------------------------------------------------------------------
279  // Connect typed input ports to typed output ports
280  // ----------------------------------------------------------------------
281 
284  NATIVE_INT_TYPE portNum,
285  Svc::InputCyclePort* port
286  )
287  {
288  FW_ASSERT(
289  portNum < this->getNum_intOut_OutputPorts(),
290  static_cast<FwAssertArgType>(portNum)
291  );
292 
293  this->m_intOut_OutputPort[portNum].addCallPort(port);
294  }
295 
296 #if FW_PORT_SERIALIZATION
297 
298  // ----------------------------------------------------------------------
299  // Connect serial input ports to special output ports
300  // ----------------------------------------------------------------------
301 
304  NATIVE_INT_TYPE portNum,
305  Fw::InputSerializePort* port
306  )
307  {
308  FW_ASSERT(
309  portNum < this->getNum_Log_OutputPorts(),
310  static_cast<FwAssertArgType>(portNum)
311  );
312 
313  this->m_Log_OutputPort[portNum].registerSerialPort(port);
314  }
315 
316 #if FW_ENABLE_TEXT_LOGGING == 1
317 
318  void LinuxGpioDriverComponentBase ::
319  set_LogText_OutputPort(
320  NATIVE_INT_TYPE portNum,
321  Fw::InputSerializePort* port
322  )
323  {
324  FW_ASSERT(
325  portNum < this->getNum_LogText_OutputPorts(),
326  static_cast<FwAssertArgType>(portNum)
327  );
328 
329  this->m_LogText_OutputPort[portNum].registerSerialPort(port);
330  }
331 
332 #endif
333 
336  NATIVE_INT_TYPE portNum,
337  Fw::InputSerializePort* port
338  )
339  {
340  FW_ASSERT(
341  portNum < this->getNum_Time_OutputPorts(),
342  static_cast<FwAssertArgType>(portNum)
343  );
344 
345  this->m_Time_OutputPort[portNum].registerSerialPort(port);
346  }
347 
348 #endif
349 
350 #if FW_PORT_SERIALIZATION
351 
352  // ----------------------------------------------------------------------
353  // Connect serial input ports to typed output ports
354  // ----------------------------------------------------------------------
355 
358  NATIVE_INT_TYPE portNum,
359  Fw::InputSerializePort* port
360  )
361  {
362  FW_ASSERT(
363  portNum < this->getNum_intOut_OutputPorts(),
364  static_cast<FwAssertArgType>(portNum)
365  );
366 
367  this->m_intOut_OutputPort[portNum].registerSerialPort(port);
368  }
369 
370 #endif
371 
372  // ----------------------------------------------------------------------
373  // Component construction and destruction
374  // ----------------------------------------------------------------------
375 
377  LinuxGpioDriverComponentBase(const char* compName) :
378  Fw::PassiveComponentBase(compName)
379  {
380  this->m_GP_WriteErrorThrottle = 0;
381  this->m_GP_ReadErrorThrottle = 0;
382  }
383 
386  {
387 
388  }
389 
390  // ----------------------------------------------------------------------
391  // Getters for numbers of typed input ports
392  // ----------------------------------------------------------------------
393 
396  {
397  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_gpioRead_InputPort));
398  }
399 
402  {
403  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_gpioWrite_InputPort));
404  }
405 
406  // ----------------------------------------------------------------------
407  // Getters for numbers of special output ports
408  // ----------------------------------------------------------------------
409 
412  {
413  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_Log_OutputPort));
414  }
415 
416 #if FW_ENABLE_TEXT_LOGGING == 1
417 
418  NATIVE_INT_TYPE LinuxGpioDriverComponentBase ::
419  getNum_LogText_OutputPorts() const
420  {
421  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_LogText_OutputPort));
422  }
423 
424 #endif
425 
428  {
429  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_Time_OutputPort));
430  }
431 
432  // ----------------------------------------------------------------------
433  // Getters for numbers of typed output ports
434  // ----------------------------------------------------------------------
435 
438  {
439  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_intOut_OutputPort));
440  }
441 
442  // ----------------------------------------------------------------------
443  // Connection status queries for special output ports
444  // ----------------------------------------------------------------------
445 
448  {
449  FW_ASSERT(
450  portNum < this->getNum_Log_OutputPorts(),
451  static_cast<FwAssertArgType>(portNum)
452  );
453 
454  return this->m_Log_OutputPort[portNum].isConnected();
455  }
456 
457 #if FW_ENABLE_TEXT_LOGGING == 1
458 
459  bool LinuxGpioDriverComponentBase ::
460  isConnected_LogText_OutputPort(NATIVE_INT_TYPE portNum)
461  {
462  FW_ASSERT(
463  portNum < this->getNum_LogText_OutputPorts(),
464  static_cast<FwAssertArgType>(portNum)
465  );
466 
467  return this->m_LogText_OutputPort[portNum].isConnected();
468  }
469 
470 #endif
471 
474  {
475  FW_ASSERT(
476  portNum < this->getNum_Time_OutputPorts(),
477  static_cast<FwAssertArgType>(portNum)
478  );
479 
480  return this->m_Time_OutputPort[portNum].isConnected();
481  }
482 
483  // ----------------------------------------------------------------------
484  // Connection status queries for typed output ports
485  // ----------------------------------------------------------------------
486 
489  {
490  FW_ASSERT(
491  portNum < this->getNum_intOut_OutputPorts(),
492  static_cast<FwAssertArgType>(portNum)
493  );
494 
495  return this->m_intOut_OutputPort[portNum].isConnected();
496  }
497 
498  // ----------------------------------------------------------------------
499  // Port handler base-class functions for typed input ports
500  //
501  // Call these functions directly to bypass the corresponding ports
502  // ----------------------------------------------------------------------
503 
506  NATIVE_INT_TYPE portNum,
507  Fw::Logic& state
508  )
509  {
510  // Make sure port number is valid
511  FW_ASSERT(
512  portNum < this->getNum_gpioRead_InputPorts(),
513  static_cast<FwAssertArgType>(portNum)
514  );
515 
516  // Call handler function
517  this->gpioRead_handler(
518  portNum,
519  state
520  );
521  }
522 
525  NATIVE_INT_TYPE portNum,
526  const Fw::Logic& state
527  )
528  {
529  // Make sure port number is valid
530  FW_ASSERT(
531  portNum < this->getNum_gpioWrite_InputPorts(),
532  static_cast<FwAssertArgType>(portNum)
533  );
534 
535  // Call handler function
536  this->gpioWrite_handler(
537  portNum,
538  state
539  );
540  }
541 
542  // ----------------------------------------------------------------------
543  // Invocation functions for typed output ports
544  // ----------------------------------------------------------------------
545 
548  NATIVE_INT_TYPE portNum,
549  Svc::TimerVal& cycleStart
550  )
551  {
552  FW_ASSERT(
553  portNum < this->getNum_intOut_OutputPorts(),
554  static_cast<FwAssertArgType>(portNum)
555  );
556  this->m_intOut_OutputPort[portNum].invoke(
557  cycleStart
558  );
559  }
560 
561  // ----------------------------------------------------------------------
562  // Event logging functions
563  // ----------------------------------------------------------------------
564 
567  I32 gpio,
568  I32 error,
569  const Fw::LogStringArg& msg
570  )
571  {
572  // Get the time
573  Fw::Time _logTime;
574  if (this->m_Time_OutputPort[0].isConnected()) {
575  this->m_Time_OutputPort[0].invoke(_logTime);
576  }
577 
578  FwEventIdType _id = static_cast<FwEventIdType>(0);
579 
580  _id = this->getIdBase() + EVENTID_GP_OPENERROR;
581 
582  // Emit the event on the log port
583  if (this->m_Log_OutputPort[0].isConnected()) {
584  Fw::LogBuffer _logBuff;
586 
587 #if FW_AMPCS_COMPATIBLE
588  // Serialize the number of arguments
589  _status = _logBuff.serialize(static_cast<U8>(3));
590  FW_ASSERT(
591  _status == Fw::FW_SERIALIZE_OK,
592  static_cast<FwAssertArgType>(_status)
593  );
594 #endif
595 
596 #if FW_AMPCS_COMPATIBLE
597  // Serialize the argument size
598  _status = _logBuff.serialize(
599  static_cast<U8>(sizeof(I32))
600  );
601  FW_ASSERT(
602  _status == Fw::FW_SERIALIZE_OK,
603  static_cast<FwAssertArgType>(_status)
604  );
605 #endif
606  _status = _logBuff.serialize(gpio);
607  FW_ASSERT(
608  _status == Fw::FW_SERIALIZE_OK,
609  static_cast<FwAssertArgType>(_status)
610  );
611 
612 #if FW_AMPCS_COMPATIBLE
613  // Serialize the argument size
614  _status = _logBuff.serialize(
615  static_cast<U8>(sizeof(I32))
616  );
617  FW_ASSERT(
618  _status == Fw::FW_SERIALIZE_OK,
619  static_cast<FwAssertArgType>(_status)
620  );
621 #endif
622  _status = _logBuff.serialize(error);
623  FW_ASSERT(
624  _status == Fw::FW_SERIALIZE_OK,
625  static_cast<FwAssertArgType>(_status)
626  );
627 
628  _status = msg.serialize(_logBuff, 40);
629  FW_ASSERT(
630  _status == Fw::FW_SERIALIZE_OK,
631  static_cast<FwAssertArgType>(_status)
632  );
633 
634  this->m_Log_OutputPort[0].invoke(
635  _id,
636  _logTime,
638  _logBuff
639  );
640  }
641 
642  // Emit the event on the text log port
643 #if FW_ENABLE_TEXT_LOGGING
644  if (this->m_LogText_OutputPort[0].isConnected()) {
645 #if FW_OBJECT_NAMES == 1
646  const char* _formatString =
647  "(%s) %s: Error opening GPIO device %" PRIi32 ": %" PRIi32 " (%s)";
648 #else
649  const char* _formatString =
650  "%s: Error opening GPIO device %" PRIi32 ": %" PRIi32 " (%s)";
651 #endif
652 
653  char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
654 
655  (void) snprintf(
656  _textBuffer,
658  _formatString,
659 #if FW_OBJECT_NAMES == 1
660  this->m_objName,
661 #endif
662  "GP_OpenError ",
663  gpio,
664  error,
665  msg.toChar()
666  );
667 
668  // Null terminate
669  _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
670  Fw::TextLogString _logString = _textBuffer;
671  this->m_LogText_OutputPort[0].invoke(
672  _id,
673  _logTime,
675  _logString
676  );
677  }
678 #endif
679  }
680 
683  I32 gpio,
684  I32 error
685  )
686  {
687  // Get the time
688  Fw::Time _logTime;
689  if (this->m_Time_OutputPort[0].isConnected()) {
690  this->m_Time_OutputPort[0].invoke(_logTime);
691  }
692 
693  FwEventIdType _id = static_cast<FwEventIdType>(0);
694 
695  _id = this->getIdBase() + EVENTID_GP_CONFIGERROR;
696 
697  // Emit the event on the log port
698  if (this->m_Log_OutputPort[0].isConnected()) {
699  Fw::LogBuffer _logBuff;
701 
702 #if FW_AMPCS_COMPATIBLE
703  // Serialize the number of arguments
704  _status = _logBuff.serialize(static_cast<U8>(2));
705  FW_ASSERT(
706  _status == Fw::FW_SERIALIZE_OK,
707  static_cast<FwAssertArgType>(_status)
708  );
709 #endif
710 
711 #if FW_AMPCS_COMPATIBLE
712  // Serialize the argument size
713  _status = _logBuff.serialize(
714  static_cast<U8>(sizeof(I32))
715  );
716  FW_ASSERT(
717  _status == Fw::FW_SERIALIZE_OK,
718  static_cast<FwAssertArgType>(_status)
719  );
720 #endif
721  _status = _logBuff.serialize(gpio);
722  FW_ASSERT(
723  _status == Fw::FW_SERIALIZE_OK,
724  static_cast<FwAssertArgType>(_status)
725  );
726 
727 #if FW_AMPCS_COMPATIBLE
728  // Serialize the argument size
729  _status = _logBuff.serialize(
730  static_cast<U8>(sizeof(I32))
731  );
732  FW_ASSERT(
733  _status == Fw::FW_SERIALIZE_OK,
734  static_cast<FwAssertArgType>(_status)
735  );
736 #endif
737  _status = _logBuff.serialize(error);
738  FW_ASSERT(
739  _status == Fw::FW_SERIALIZE_OK,
740  static_cast<FwAssertArgType>(_status)
741  );
742 
743  this->m_Log_OutputPort[0].invoke(
744  _id,
745  _logTime,
747  _logBuff
748  );
749  }
750 
751  // Emit the event on the text log port
752 #if FW_ENABLE_TEXT_LOGGING
753  if (this->m_LogText_OutputPort[0].isConnected()) {
754 #if FW_OBJECT_NAMES == 1
755  const char* _formatString =
756  "(%s) %s: Error configuring GPIO device %" PRIi32 ": %" PRIi32 "";
757 #else
758  const char* _formatString =
759  "%s: Error configuring GPIO device %" PRIi32 ": %" PRIi32 "";
760 #endif
761 
762  char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
763 
764  (void) snprintf(
765  _textBuffer,
767  _formatString,
768 #if FW_OBJECT_NAMES == 1
769  this->m_objName,
770 #endif
771  "GP_ConfigError ",
772  gpio,
773  error
774  );
775 
776  // Null terminate
777  _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
778  Fw::TextLogString _logString = _textBuffer;
779  this->m_LogText_OutputPort[0].invoke(
780  _id,
781  _logTime,
783  _logString
784  );
785  }
786 #endif
787  }
788 
791  I32 gpio,
792  I32 error
793  )
794  {
795  // Check throttle value
796  if (this->m_GP_WriteErrorThrottle >= EVENTID_GP_WRITEERROR_THROTTLE) {
797  return;
798  }
799  else {
800  this->m_GP_WriteErrorThrottle++;
801  }
802 
803  // Get the time
804  Fw::Time _logTime;
805  if (this->m_Time_OutputPort[0].isConnected()) {
806  this->m_Time_OutputPort[0].invoke(_logTime);
807  }
808 
809  FwEventIdType _id = static_cast<FwEventIdType>(0);
810 
811  _id = this->getIdBase() + EVENTID_GP_WRITEERROR;
812 
813  // Emit the event on the log port
814  if (this->m_Log_OutputPort[0].isConnected()) {
815  Fw::LogBuffer _logBuff;
817 
818 #if FW_AMPCS_COMPATIBLE
819  // Serialize the number of arguments
820  _status = _logBuff.serialize(static_cast<U8>(2));
821  FW_ASSERT(
822  _status == Fw::FW_SERIALIZE_OK,
823  static_cast<FwAssertArgType>(_status)
824  );
825 #endif
826 
827 #if FW_AMPCS_COMPATIBLE
828  // Serialize the argument size
829  _status = _logBuff.serialize(
830  static_cast<U8>(sizeof(I32))
831  );
832  FW_ASSERT(
833  _status == Fw::FW_SERIALIZE_OK,
834  static_cast<FwAssertArgType>(_status)
835  );
836 #endif
837  _status = _logBuff.serialize(gpio);
838  FW_ASSERT(
839  _status == Fw::FW_SERIALIZE_OK,
840  static_cast<FwAssertArgType>(_status)
841  );
842 
843 #if FW_AMPCS_COMPATIBLE
844  // Serialize the argument size
845  _status = _logBuff.serialize(
846  static_cast<U8>(sizeof(I32))
847  );
848  FW_ASSERT(
849  _status == Fw::FW_SERIALIZE_OK,
850  static_cast<FwAssertArgType>(_status)
851  );
852 #endif
853  _status = _logBuff.serialize(error);
854  FW_ASSERT(
855  _status == Fw::FW_SERIALIZE_OK,
856  static_cast<FwAssertArgType>(_status)
857  );
858 
859  this->m_Log_OutputPort[0].invoke(
860  _id,
861  _logTime,
863  _logBuff
864  );
865  }
866 
867  // Emit the event on the text log port
868 #if FW_ENABLE_TEXT_LOGGING
869  if (this->m_LogText_OutputPort[0].isConnected()) {
870 #if FW_OBJECT_NAMES == 1
871  const char* _formatString =
872  "(%s) %s: Error writing GPIO device %" PRIi32 ": %" PRIi32 "";
873 #else
874  const char* _formatString =
875  "%s: Error writing GPIO device %" PRIi32 ": %" PRIi32 "";
876 #endif
877 
878  char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
879 
880  (void) snprintf(
881  _textBuffer,
883  _formatString,
884 #if FW_OBJECT_NAMES == 1
885  this->m_objName,
886 #endif
887  "GP_WriteError ",
888  gpio,
889  error
890  );
891 
892  // Null terminate
893  _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
894  Fw::TextLogString _logString = _textBuffer;
895  this->m_LogText_OutputPort[0].invoke(
896  _id,
897  _logTime,
899  _logString
900  );
901  }
902 #endif
903  }
904 
907  I32 gpio,
908  I32 error
909  )
910  {
911  // Check throttle value
912  if (this->m_GP_ReadErrorThrottle >= EVENTID_GP_READERROR_THROTTLE) {
913  return;
914  }
915  else {
916  this->m_GP_ReadErrorThrottle++;
917  }
918 
919  // Get the time
920  Fw::Time _logTime;
921  if (this->m_Time_OutputPort[0].isConnected()) {
922  this->m_Time_OutputPort[0].invoke(_logTime);
923  }
924 
925  FwEventIdType _id = static_cast<FwEventIdType>(0);
926 
927  _id = this->getIdBase() + EVENTID_GP_READERROR;
928 
929  // Emit the event on the log port
930  if (this->m_Log_OutputPort[0].isConnected()) {
931  Fw::LogBuffer _logBuff;
933 
934 #if FW_AMPCS_COMPATIBLE
935  // Serialize the number of arguments
936  _status = _logBuff.serialize(static_cast<U8>(2));
937  FW_ASSERT(
938  _status == Fw::FW_SERIALIZE_OK,
939  static_cast<FwAssertArgType>(_status)
940  );
941 #endif
942 
943 #if FW_AMPCS_COMPATIBLE
944  // Serialize the argument size
945  _status = _logBuff.serialize(
946  static_cast<U8>(sizeof(I32))
947  );
948  FW_ASSERT(
949  _status == Fw::FW_SERIALIZE_OK,
950  static_cast<FwAssertArgType>(_status)
951  );
952 #endif
953  _status = _logBuff.serialize(gpio);
954  FW_ASSERT(
955  _status == Fw::FW_SERIALIZE_OK,
956  static_cast<FwAssertArgType>(_status)
957  );
958 
959 #if FW_AMPCS_COMPATIBLE
960  // Serialize the argument size
961  _status = _logBuff.serialize(
962  static_cast<U8>(sizeof(I32))
963  );
964  FW_ASSERT(
965  _status == Fw::FW_SERIALIZE_OK,
966  static_cast<FwAssertArgType>(_status)
967  );
968 #endif
969  _status = _logBuff.serialize(error);
970  FW_ASSERT(
971  _status == Fw::FW_SERIALIZE_OK,
972  static_cast<FwAssertArgType>(_status)
973  );
974 
975  this->m_Log_OutputPort[0].invoke(
976  _id,
977  _logTime,
979  _logBuff
980  );
981  }
982 
983  // Emit the event on the text log port
984 #if FW_ENABLE_TEXT_LOGGING
985  if (this->m_LogText_OutputPort[0].isConnected()) {
986 #if FW_OBJECT_NAMES == 1
987  const char* _formatString =
988  "(%s) %s: Error reading GPIO device %" PRIi32 ": %" PRIi32 "";
989 #else
990  const char* _formatString =
991  "%s: Error reading GPIO device %" PRIi32 ": %" PRIi32 "";
992 #endif
993 
994  char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
995 
996  (void) snprintf(
997  _textBuffer,
999  _formatString,
1000 #if FW_OBJECT_NAMES == 1
1001  this->m_objName,
1002 #endif
1003  "GP_ReadError ",
1004  gpio,
1005  error
1006  );
1007 
1008  // Null terminate
1009  _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
1010  Fw::TextLogString _logString = _textBuffer;
1011  this->m_LogText_OutputPort[0].invoke(
1012  _id,
1013  _logTime,
1015  _logString
1016  );
1017  }
1018 #endif
1019  }
1020 
1023  {
1024  // Get the time
1025  Fw::Time _logTime;
1026  if (this->m_Time_OutputPort[0].isConnected()) {
1027  this->m_Time_OutputPort[0].invoke(_logTime);
1028  }
1029 
1030  FwEventIdType _id = static_cast<FwEventIdType>(0);
1031 
1032  _id = this->getIdBase() + EVENTID_GP_PORTOPENED;
1033 
1034  // Emit the event on the log port
1035  if (this->m_Log_OutputPort[0].isConnected()) {
1036  Fw::LogBuffer _logBuff;
1038 
1039 #if FW_AMPCS_COMPATIBLE
1040  // Serialize the number of arguments
1041  _status = _logBuff.serialize(static_cast<U8>(1));
1042  FW_ASSERT(
1043  _status == Fw::FW_SERIALIZE_OK,
1044  static_cast<FwAssertArgType>(_status)
1045  );
1046 #endif
1047 
1048 #if FW_AMPCS_COMPATIBLE
1049  // Serialize the argument size
1050  _status = _logBuff.serialize(
1051  static_cast<U8>(sizeof(I32))
1052  );
1053  FW_ASSERT(
1054  _status == Fw::FW_SERIALIZE_OK,
1055  static_cast<FwAssertArgType>(_status)
1056  );
1057 #endif
1058  _status = _logBuff.serialize(gpio);
1059  FW_ASSERT(
1060  _status == Fw::FW_SERIALIZE_OK,
1061  static_cast<FwAssertArgType>(_status)
1062  );
1063 
1064  this->m_Log_OutputPort[0].invoke(
1065  _id,
1066  _logTime,
1068  _logBuff
1069  );
1070  }
1071 
1072  // Emit the event on the text log port
1073 #if FW_ENABLE_TEXT_LOGGING
1074  if (this->m_LogText_OutputPort[0].isConnected()) {
1075 #if FW_OBJECT_NAMES == 1
1076  const char* _formatString =
1077  "(%s) %s: GPIO Device %" PRIi32 " configured";
1078 #else
1079  const char* _formatString =
1080  "%s: GPIO Device %" PRIi32 " configured";
1081 #endif
1082 
1083  char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
1084 
1085  (void) snprintf(
1086  _textBuffer,
1088  _formatString,
1089 #if FW_OBJECT_NAMES == 1
1090  this->m_objName,
1091 #endif
1092  "GP_PortOpened ",
1093  gpio
1094  );
1095 
1096  // Null terminate
1097  _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
1098  Fw::TextLogString _logString = _textBuffer;
1099  this->m_LogText_OutputPort[0].invoke(
1100  _id,
1101  _logTime,
1103  _logString
1104  );
1105  }
1106 #endif
1107  }
1108 
1111  {
1112  // Get the time
1113  Fw::Time _logTime;
1114  if (this->m_Time_OutputPort[0].isConnected()) {
1115  this->m_Time_OutputPort[0].invoke(_logTime);
1116  }
1117 
1118  FwEventIdType _id = static_cast<FwEventIdType>(0);
1119 
1120  _id = this->getIdBase() + EVENTID_GP_INTSTARTERROR;
1121 
1122  // Emit the event on the log port
1123  if (this->m_Log_OutputPort[0].isConnected()) {
1124  Fw::LogBuffer _logBuff;
1126 
1127 #if FW_AMPCS_COMPATIBLE
1128  // Serialize the number of arguments
1129  _status = _logBuff.serialize(static_cast<U8>(1));
1130  FW_ASSERT(
1131  _status == Fw::FW_SERIALIZE_OK,
1132  static_cast<FwAssertArgType>(_status)
1133  );
1134 #endif
1135 
1136 #if FW_AMPCS_COMPATIBLE
1137  // Serialize the argument size
1138  _status = _logBuff.serialize(
1139  static_cast<U8>(sizeof(I32))
1140  );
1141  FW_ASSERT(
1142  _status == Fw::FW_SERIALIZE_OK,
1143  static_cast<FwAssertArgType>(_status)
1144  );
1145 #endif
1146  _status = _logBuff.serialize(gpio);
1147  FW_ASSERT(
1148  _status == Fw::FW_SERIALIZE_OK,
1149  static_cast<FwAssertArgType>(_status)
1150  );
1151 
1152  this->m_Log_OutputPort[0].invoke(
1153  _id,
1154  _logTime,
1156  _logBuff
1157  );
1158  }
1159 
1160  // Emit the event on the text log port
1161 #if FW_ENABLE_TEXT_LOGGING
1162  if (this->m_LogText_OutputPort[0].isConnected()) {
1163 #if FW_OBJECT_NAMES == 1
1164  const char* _formatString =
1165  "(%s) %s: GPIO Device %" PRIi32 " interrupt start error";
1166 #else
1167  const char* _formatString =
1168  "%s: GPIO Device %" PRIi32 " interrupt start error";
1169 #endif
1170 
1171  char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
1172 
1173  (void) snprintf(
1174  _textBuffer,
1176  _formatString,
1177 #if FW_OBJECT_NAMES == 1
1178  this->m_objName,
1179 #endif
1180  "GP_IntStartError ",
1181  gpio
1182  );
1183 
1184  // Null terminate
1185  _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
1186  Fw::TextLogString _logString = _textBuffer;
1187  this->m_LogText_OutputPort[0].invoke(
1188  _id,
1189  _logTime,
1191  _logString
1192  );
1193  }
1194 #endif
1195  }
1196 
1199  {
1200  // Get the time
1201  Fw::Time _logTime;
1202  if (this->m_Time_OutputPort[0].isConnected()) {
1203  this->m_Time_OutputPort[0].invoke(_logTime);
1204  }
1205 
1206  FwEventIdType _id = static_cast<FwEventIdType>(0);
1207 
1208  _id = this->getIdBase() + EVENTID_GP_INTWAITERROR;
1209 
1210  // Emit the event on the log port
1211  if (this->m_Log_OutputPort[0].isConnected()) {
1212  Fw::LogBuffer _logBuff;
1214 
1215 #if FW_AMPCS_COMPATIBLE
1216  // Serialize the number of arguments
1217  _status = _logBuff.serialize(static_cast<U8>(1));
1218  FW_ASSERT(
1219  _status == Fw::FW_SERIALIZE_OK,
1220  static_cast<FwAssertArgType>(_status)
1221  );
1222 #endif
1223 
1224 #if FW_AMPCS_COMPATIBLE
1225  // Serialize the argument size
1226  _status = _logBuff.serialize(
1227  static_cast<U8>(sizeof(I32))
1228  );
1229  FW_ASSERT(
1230  _status == Fw::FW_SERIALIZE_OK,
1231  static_cast<FwAssertArgType>(_status)
1232  );
1233 #endif
1234  _status = _logBuff.serialize(gpio);
1235  FW_ASSERT(
1236  _status == Fw::FW_SERIALIZE_OK,
1237  static_cast<FwAssertArgType>(_status)
1238  );
1239 
1240  this->m_Log_OutputPort[0].invoke(
1241  _id,
1242  _logTime,
1244  _logBuff
1245  );
1246  }
1247 
1248  // Emit the event on the text log port
1249 #if FW_ENABLE_TEXT_LOGGING
1250  if (this->m_LogText_OutputPort[0].isConnected()) {
1251 #if FW_OBJECT_NAMES == 1
1252  const char* _formatString =
1253  "(%s) %s: GPIO Device %" PRIi32 " interrupt wait error";
1254 #else
1255  const char* _formatString =
1256  "%s: GPIO Device %" PRIi32 " interrupt wait error";
1257 #endif
1258 
1259  char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
1260 
1261  (void) snprintf(
1262  _textBuffer,
1264  _formatString,
1265 #if FW_OBJECT_NAMES == 1
1266  this->m_objName,
1267 #endif
1268  "GP_IntWaitError ",
1269  gpio
1270  );
1271 
1272  // Null terminate
1273  _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
1274  Fw::TextLogString _logString = _textBuffer;
1275  this->m_LogText_OutputPort[0].invoke(
1276  _id,
1277  _logTime,
1279  _logString
1280  );
1281  }
1282 #endif
1283  }
1284 
1285  // ----------------------------------------------------------------------
1286  // Event throttle reset functions
1287  // ----------------------------------------------------------------------
1288 
1291  {
1292  // Reset throttle counter
1293  this->m_GP_WriteErrorThrottle = 0;
1294  }
1295 
1298  {
1299  // Reset throttle counter
1300  this->m_GP_ReadErrorThrottle = 0;
1301  }
1302 
1303  // ----------------------------------------------------------------------
1304  // Time
1305  // ----------------------------------------------------------------------
1306 
1308  getTime()
1309  {
1310  if (this->m_Time_OutputPort[0].isConnected()) {
1311  Fw::Time _time;
1312  this->m_Time_OutputPort[0].invoke(_time);
1313  return _time;
1314  }
1315  else {
1316  return Fw::Time(TB_NONE, 0, 0);
1317  }
1318  }
1319 
1320  // ----------------------------------------------------------------------
1321  // Calls for messages received on typed input ports
1322  // ----------------------------------------------------------------------
1323 
1324  void LinuxGpioDriverComponentBase ::
1325  m_p_gpioRead_in(
1326  Fw::PassiveComponentBase* callComp,
1327  NATIVE_INT_TYPE portNum,
1328  Fw::Logic& state
1329  )
1330  {
1331  FW_ASSERT(callComp);
1332  LinuxGpioDriverComponentBase* compPtr = static_cast<LinuxGpioDriverComponentBase*>(callComp);
1333  compPtr->gpioRead_handlerBase(
1334  portNum,
1335  state
1336  );
1337  }
1338 
1339  void LinuxGpioDriverComponentBase ::
1340  m_p_gpioWrite_in(
1341  Fw::PassiveComponentBase* callComp,
1342  NATIVE_INT_TYPE portNum,
1343  const Fw::Logic& state
1344  )
1345  {
1346  FW_ASSERT(callComp);
1347  LinuxGpioDriverComponentBase* compPtr = static_cast<LinuxGpioDriverComponentBase*>(callComp);
1348  compPtr->gpioWrite_handlerBase(
1349  portNum,
1350  state
1351  );
1352  }
1353 
1354 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:51
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:26
#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
@ TB_NONE
No time base has been established.
Definition: FpConfig.h:39
PlatformAssertArgType FwAssertArgType
Definition: FpConfig.h:21
U32 FwEventIdType
Definition: FpConfig.h:62
#define FW_LOG_TEXT_BUFFER_SIZE
Max size of string for text log message.
Definition: FpConfig.h:299
#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
#define FW_OBJECT_NAMES
Indicates whether or not object names are stored (more memory, can be used for tracking objects)
Definition: FpConfig.h:88
Input GpioRead port.
void init()
Initialization function.
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
Input GpioWrite port.
void init()
Initialization function.
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
Auto-generated base for LinuxGpioDriver component.
@ EVENTID_GP_READERROR_THROTTLE
Throttle reset count for GP_ReadError.
@ EVENTID_GP_WRITEERROR_THROTTLE
Throttle reset count for GP_WriteError.
void set_Log_OutputPort(NATIVE_INT_TYPE portNum, Fw::InputLogPort *port)
Connect port to Log[portNum].
virtual ~LinuxGpioDriverComponentBase()
Destroy LinuxGpioDriverComponentBase object.
void gpioWrite_handlerBase(NATIVE_INT_TYPE portNum, const Fw::Logic &state)
Handler base-class function for input port gpioWrite.
bool isConnected_Log_OutputPort(NATIVE_INT_TYPE portNum)
virtual void gpioRead_handler(NATIVE_INT_TYPE portNum, Fw::Logic &state)=0
Handler for input port gpioRead.
void log_WARNING_HI_GP_ReadError(I32 gpio, I32 error)
void set_intOut_OutputPort(NATIVE_INT_TYPE portNum, Svc::InputCyclePort *port)
Connect port to intOut[portNum].
bool isConnected_intOut_OutputPort(NATIVE_INT_TYPE portNum)
@ EVENTID_GP_INTSTARTERROR
GPIO interrupt start error notification.
@ EVENTID_GP_INTWAITERROR
GPIO interrupt wait error notification.
@ EVENTID_GP_PORTOPENED
GPIO opened notification.
void log_WARNING_HI_GP_ReadError_ThrottleClear()
Reset throttle value for GP_ReadError.
void set_Time_OutputPort(NATIVE_INT_TYPE portNum, Fw::InputTimePort *port)
Connect port to Time[portNum].
void gpioRead_handlerBase(NATIVE_INT_TYPE portNum, Fw::Logic &state)
Handler base-class function for input port gpioRead.
void log_WARNING_HI_GP_WriteError(I32 gpio, I32 error)
Drv::InputGpioWritePort * get_gpioWrite_InputPort(NATIVE_INT_TYPE portNum)
void log_WARNING_HI_GP_WriteError_ThrottleClear()
Reset throttle value for GP_WriteError.
virtual void gpioWrite_handler(NATIVE_INT_TYPE portNum, const Fw::Logic &state)=0
Handler for input port gpioWrite.
bool isConnected_Time_OutputPort(NATIVE_INT_TYPE portNum)
void intOut_out(NATIVE_INT_TYPE portNum, Svc::TimerVal &cycleStart)
Invoke output port intOut.
void log_WARNING_HI_GP_OpenError(I32 gpio, I32 error, const Fw::LogStringArg &msg)
void log_WARNING_HI_GP_ConfigError(I32 gpio, I32 error)
Drv::InputGpioReadPort * get_gpioRead_InputPort(NATIVE_INT_TYPE portNum)
LinuxGpioDriverComponentBase(const char *compName="")
Construct LinuxGpioDriverComponentBase object.
void setPortNum(NATIVE_INT_TYPE portNum)
@ WARNING_HI
A serious but recoverable event.
@ ACTIVITY_HI
Important informational events.
const char * toChar() const override
Definition: LogString.cpp:49
SerializeStatus serialize(SerializeBufferBase &buffer) const override
serialization function
Definition: LogString.cpp:57
Logic states.
Definition: LogicEnumAc.hpp:19
void init()
Object initializer.
Definition: ObjBase.cpp:27
void init()
Initialization function.
Definition: LogPortAc.cpp:151
void invoke(FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity &severity, Fw::LogBuffer &args)
Invoke a port interface.
Definition: LogPortAc.cpp:170
void addCallPort(InputLogPort *callPort)
Register an input port.
Definition: LogPortAc.cpp:157
void addCallPort(InputTimePort *callPort)
Register an input port.
Definition: TimePortAc.cpp:134
void invoke(Fw::Time &time)
Invoke a port interface.
Definition: TimePortAc.cpp:147
void init()
Initialization function.
Definition: TimePortAc.cpp:128
bool isConnected()
Definition: PortBase.cpp:41
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
Definition: Time.hpp:9
void init()
Initialization function.
void addCallPort(InputCyclePort *callPort)
Register an input port.
void invoke(Svc::TimerVal &cycleStart)
Invoke a port interface.
Serializable class for carrying timer values.
Definition: TimerVal.hpp:22
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.