F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
LinuxSpiDriverComponentAc.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title LinuxSpiDriverComponentAc.cpp
3 // \author Generated by fpp-to-cpp
4 // \brief cpp file for LinuxSpiDriver 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 SpiReadWrite
28  for (
29  PlatformIntType port = 0;
30  port < static_cast<PlatformIntType>(this->getNum_SpiReadWrite_InputPorts());
31  port++
32  ) {
33  this->m_SpiReadWrite_InputPort[port].init();
34  this->m_SpiReadWrite_InputPort[port].addCallComp(
35  this,
36  m_p_SpiReadWrite_in
37  );
38  this->m_SpiReadWrite_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_SpiReadWrite_InputPort[%" PRI_PlatformIntType "]",
52  this->m_objName,
53  port
54  );
55  this->m_SpiReadWrite_InputPort[port].setObjName(portName);
56 #endif
57  }
58 
59  // Connect output port Log
60  for (
61  PlatformIntType port = 0;
62  port < static_cast<PlatformIntType>(this->getNum_Log_OutputPorts());
63  port++
64  ) {
65  this->m_Log_OutputPort[port].init();
66 
67 #if FW_OBJECT_NAMES == 1
68  // The port name consists of this->m_objName and some extra info.
69  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
70  // However, the compiler may assume that this->m_objName fills
71  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
72  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
73  // bytes to cover the extra info.
74  char portName[2*FW_OBJ_NAME_MAX_SIZE];
75  (void) snprintf(
76  portName,
77  sizeof(portName),
78  "%s_Log_OutputPort[%" PRI_PlatformIntType "]",
79  this->m_objName,
80  port
81  );
82  this->m_Log_OutputPort[port].setObjName(portName);
83 #endif
84  }
85 
86 #if FW_ENABLE_TEXT_LOGGING == 1
87  // Connect output port LogText
88  for (
89  PlatformIntType port = 0;
90  port < static_cast<PlatformIntType>(this->getNum_LogText_OutputPorts());
91  port++
92  ) {
93  this->m_LogText_OutputPort[port].init();
94 
95 #if FW_OBJECT_NAMES == 1
96  // The port name consists of this->m_objName and some extra info.
97  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
98  // However, the compiler may assume that this->m_objName fills
99  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
100  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
101  // bytes to cover the extra info.
102  char portName[2*FW_OBJ_NAME_MAX_SIZE];
103  (void) snprintf(
104  portName,
105  sizeof(portName),
106  "%s_LogText_OutputPort[%" PRI_PlatformIntType "]",
107  this->m_objName,
108  port
109  );
110  this->m_LogText_OutputPort[port].setObjName(portName);
111 #endif
112  }
113 #endif
114 
115  // Connect output port Time
116  for (
117  PlatformIntType port = 0;
118  port < static_cast<PlatformIntType>(this->getNum_Time_OutputPorts());
119  port++
120  ) {
121  this->m_Time_OutputPort[port].init();
122 
123 #if FW_OBJECT_NAMES == 1
124  // The port name consists of this->m_objName and some extra info.
125  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
126  // However, the compiler may assume that this->m_objName fills
127  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
128  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
129  // bytes to cover the extra info.
130  char portName[2*FW_OBJ_NAME_MAX_SIZE];
131  (void) snprintf(
132  portName,
133  sizeof(portName),
134  "%s_Time_OutputPort[%" PRI_PlatformIntType "]",
135  this->m_objName,
136  port
137  );
138  this->m_Time_OutputPort[port].setObjName(portName);
139 #endif
140  }
141 
142  // Connect output port Tlm
143  for (
144  PlatformIntType port = 0;
145  port < static_cast<PlatformIntType>(this->getNum_Tlm_OutputPorts());
146  port++
147  ) {
148  this->m_Tlm_OutputPort[port].init();
149 
150 #if FW_OBJECT_NAMES == 1
151  // The port name consists of this->m_objName and some extra info.
152  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
153  // However, the compiler may assume that this->m_objName fills
154  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
155  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
156  // bytes to cover the extra info.
157  char portName[2*FW_OBJ_NAME_MAX_SIZE];
158  (void) snprintf(
159  portName,
160  sizeof(portName),
161  "%s_Tlm_OutputPort[%" PRI_PlatformIntType "]",
162  this->m_objName,
163  port
164  );
165  this->m_Tlm_OutputPort[port].setObjName(portName);
166 #endif
167  }
168  }
169 
170  // ----------------------------------------------------------------------
171  // Getters for typed input ports
172  // ----------------------------------------------------------------------
173 
176  {
177  FW_ASSERT(
178  portNum < this->getNum_SpiReadWrite_InputPorts(),
179  static_cast<FwAssertArgType>(portNum)
180  );
181 
182  return &this->m_SpiReadWrite_InputPort[portNum];
183  }
184 
185  // ----------------------------------------------------------------------
186  // Connect input ports to special output ports
187  // ----------------------------------------------------------------------
188 
191  NATIVE_INT_TYPE portNum,
192  Fw::InputLogPort* port
193  )
194  {
195  FW_ASSERT(
196  portNum < this->getNum_Log_OutputPorts(),
197  static_cast<FwAssertArgType>(portNum)
198  );
199 
200  this->m_Log_OutputPort[portNum].addCallPort(port);
201  }
202 
203 #if FW_ENABLE_TEXT_LOGGING == 1
204 
205  void LinuxSpiDriverComponentBase ::
206  set_LogText_OutputPort(
207  NATIVE_INT_TYPE portNum,
209  )
210  {
211  FW_ASSERT(
212  portNum < this->getNum_LogText_OutputPorts(),
213  static_cast<FwAssertArgType>(portNum)
214  );
215 
216  this->m_LogText_OutputPort[portNum].addCallPort(port);
217  }
218 
219 #endif
220 
223  NATIVE_INT_TYPE portNum,
224  Fw::InputTimePort* port
225  )
226  {
227  FW_ASSERT(
228  portNum < this->getNum_Time_OutputPorts(),
229  static_cast<FwAssertArgType>(portNum)
230  );
231 
232  this->m_Time_OutputPort[portNum].addCallPort(port);
233  }
234 
237  NATIVE_INT_TYPE portNum,
238  Fw::InputTlmPort* port
239  )
240  {
241  FW_ASSERT(
242  portNum < this->getNum_Tlm_OutputPorts(),
243  static_cast<FwAssertArgType>(portNum)
244  );
245 
246  this->m_Tlm_OutputPort[portNum].addCallPort(port);
247  }
248 
249 #if FW_PORT_SERIALIZATION
250 
251  // ----------------------------------------------------------------------
252  // Connect serial input ports to special output ports
253  // ----------------------------------------------------------------------
254 
257  NATIVE_INT_TYPE portNum,
258  Fw::InputSerializePort* port
259  )
260  {
261  FW_ASSERT(
262  portNum < this->getNum_Log_OutputPorts(),
263  static_cast<FwAssertArgType>(portNum)
264  );
265 
266  this->m_Log_OutputPort[portNum].registerSerialPort(port);
267  }
268 
269 #if FW_ENABLE_TEXT_LOGGING == 1
270 
271  void LinuxSpiDriverComponentBase ::
272  set_LogText_OutputPort(
273  NATIVE_INT_TYPE portNum,
274  Fw::InputSerializePort* port
275  )
276  {
277  FW_ASSERT(
278  portNum < this->getNum_LogText_OutputPorts(),
279  static_cast<FwAssertArgType>(portNum)
280  );
281 
282  this->m_LogText_OutputPort[portNum].registerSerialPort(port);
283  }
284 
285 #endif
286 
289  NATIVE_INT_TYPE portNum,
290  Fw::InputSerializePort* port
291  )
292  {
293  FW_ASSERT(
294  portNum < this->getNum_Time_OutputPorts(),
295  static_cast<FwAssertArgType>(portNum)
296  );
297 
298  this->m_Time_OutputPort[portNum].registerSerialPort(port);
299  }
300 
303  NATIVE_INT_TYPE portNum,
304  Fw::InputSerializePort* port
305  )
306  {
307  FW_ASSERT(
308  portNum < this->getNum_Tlm_OutputPorts(),
309  static_cast<FwAssertArgType>(portNum)
310  );
311 
312  this->m_Tlm_OutputPort[portNum].registerSerialPort(port);
313  }
314 
315 #endif
316 
317  // ----------------------------------------------------------------------
318  // Component construction and destruction
319  // ----------------------------------------------------------------------
320 
322  LinuxSpiDriverComponentBase(const char* compName) :
323  Fw::PassiveComponentBase(compName)
324  {
325  this->m_SPI_WriteErrorThrottle = 0;
326  }
327 
330  {
331 
332  }
333 
334  // ----------------------------------------------------------------------
335  // Getters for numbers of typed input ports
336  // ----------------------------------------------------------------------
337 
340  {
341  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_SpiReadWrite_InputPort));
342  }
343 
344  // ----------------------------------------------------------------------
345  // Getters for numbers of special output ports
346  // ----------------------------------------------------------------------
347 
350  {
351  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_Log_OutputPort));
352  }
353 
354 #if FW_ENABLE_TEXT_LOGGING == 1
355 
356  NATIVE_INT_TYPE LinuxSpiDriverComponentBase ::
357  getNum_LogText_OutputPorts() const
358  {
359  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_LogText_OutputPort));
360  }
361 
362 #endif
363 
366  {
367  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_Time_OutputPort));
368  }
369 
372  {
373  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_Tlm_OutputPort));
374  }
375 
376  // ----------------------------------------------------------------------
377  // Connection status queries for special output ports
378  // ----------------------------------------------------------------------
379 
382  {
383  FW_ASSERT(
384  portNum < this->getNum_Log_OutputPorts(),
385  static_cast<FwAssertArgType>(portNum)
386  );
387 
388  return this->m_Log_OutputPort[portNum].isConnected();
389  }
390 
391 #if FW_ENABLE_TEXT_LOGGING == 1
392 
393  bool LinuxSpiDriverComponentBase ::
394  isConnected_LogText_OutputPort(NATIVE_INT_TYPE portNum)
395  {
396  FW_ASSERT(
397  portNum < this->getNum_LogText_OutputPorts(),
398  static_cast<FwAssertArgType>(portNum)
399  );
400 
401  return this->m_LogText_OutputPort[portNum].isConnected();
402  }
403 
404 #endif
405 
408  {
409  FW_ASSERT(
410  portNum < this->getNum_Time_OutputPorts(),
411  static_cast<FwAssertArgType>(portNum)
412  );
413 
414  return this->m_Time_OutputPort[portNum].isConnected();
415  }
416 
419  {
420  FW_ASSERT(
421  portNum < this->getNum_Tlm_OutputPorts(),
422  static_cast<FwAssertArgType>(portNum)
423  );
424 
425  return this->m_Tlm_OutputPort[portNum].isConnected();
426  }
427 
428  // ----------------------------------------------------------------------
429  // Port handler base-class functions for typed input ports
430  //
431  // Call these functions directly to bypass the corresponding ports
432  // ----------------------------------------------------------------------
433 
436  NATIVE_INT_TYPE portNum,
437  Fw::Buffer& writeBuffer,
438  Fw::Buffer& readBuffer
439  )
440  {
441  // Make sure port number is valid
442  FW_ASSERT(
443  portNum < this->getNum_SpiReadWrite_InputPorts(),
444  static_cast<FwAssertArgType>(portNum)
445  );
446 
447  // Call handler function
448  this->SpiReadWrite_handler(
449  portNum,
450  writeBuffer,
451  readBuffer
452  );
453  }
454 
455  // ----------------------------------------------------------------------
456  // Event logging functions
457  // ----------------------------------------------------------------------
458 
461  I32 device,
462  I32 select,
463  I32 error
464  )
465  {
466  // Get the time
467  Fw::Time _logTime;
468  if (this->m_Time_OutputPort[0].isConnected()) {
469  this->m_Time_OutputPort[0].invoke(_logTime);
470  }
471 
472  FwEventIdType _id = static_cast<FwEventIdType>(0);
473 
474  _id = this->getIdBase() + EVENTID_SPI_OPENERROR;
475 
476  // Emit the event on the log port
477  if (this->m_Log_OutputPort[0].isConnected()) {
478  Fw::LogBuffer _logBuff;
480 
481 #if FW_AMPCS_COMPATIBLE
482  // Serialize the number of arguments
483  _status = _logBuff.serialize(static_cast<U8>(3));
484  FW_ASSERT(
485  _status == Fw::FW_SERIALIZE_OK,
486  static_cast<FwAssertArgType>(_status)
487  );
488 #endif
489 
490 #if FW_AMPCS_COMPATIBLE
491  // Serialize the argument size
492  _status = _logBuff.serialize(
493  static_cast<U8>(sizeof(I32))
494  );
495  FW_ASSERT(
496  _status == Fw::FW_SERIALIZE_OK,
497  static_cast<FwAssertArgType>(_status)
498  );
499 #endif
500  _status = _logBuff.serialize(device);
501  FW_ASSERT(
502  _status == Fw::FW_SERIALIZE_OK,
503  static_cast<FwAssertArgType>(_status)
504  );
505 
506 #if FW_AMPCS_COMPATIBLE
507  // Serialize the argument size
508  _status = _logBuff.serialize(
509  static_cast<U8>(sizeof(I32))
510  );
511  FW_ASSERT(
512  _status == Fw::FW_SERIALIZE_OK,
513  static_cast<FwAssertArgType>(_status)
514  );
515 #endif
516  _status = _logBuff.serialize(select);
517  FW_ASSERT(
518  _status == Fw::FW_SERIALIZE_OK,
519  static_cast<FwAssertArgType>(_status)
520  );
521 
522 #if FW_AMPCS_COMPATIBLE
523  // Serialize the argument size
524  _status = _logBuff.serialize(
525  static_cast<U8>(sizeof(I32))
526  );
527  FW_ASSERT(
528  _status == Fw::FW_SERIALIZE_OK,
529  static_cast<FwAssertArgType>(_status)
530  );
531 #endif
532  _status = _logBuff.serialize(error);
533  FW_ASSERT(
534  _status == Fw::FW_SERIALIZE_OK,
535  static_cast<FwAssertArgType>(_status)
536  );
537 
538  this->m_Log_OutputPort[0].invoke(
539  _id,
540  _logTime,
542  _logBuff
543  );
544  }
545 
546  // Emit the event on the text log port
547 #if FW_ENABLE_TEXT_LOGGING
548  if (this->m_LogText_OutputPort[0].isConnected()) {
549 #if FW_OBJECT_NAMES == 1
550  const char* _formatString =
551  "(%s) %s: Error opening SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
552 #else
553  const char* _formatString =
554  "%s: Error opening SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
555 #endif
556 
557  char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
558 
559  (void) snprintf(
560  _textBuffer,
562  _formatString,
563 #if FW_OBJECT_NAMES == 1
564  this->m_objName,
565 #endif
566  "SPI_OpenError ",
567  device,
568  select,
569  error
570  );
571 
572  // Null terminate
573  _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
574  Fw::TextLogString _logString = _textBuffer;
575  this->m_LogText_OutputPort[0].invoke(
576  _id,
577  _logTime,
579  _logString
580  );
581  }
582 #endif
583  }
584 
587  I32 device,
588  I32 select,
589  I32 error
590  )
591  {
592  // Get the time
593  Fw::Time _logTime;
594  if (this->m_Time_OutputPort[0].isConnected()) {
595  this->m_Time_OutputPort[0].invoke(_logTime);
596  }
597 
598  FwEventIdType _id = static_cast<FwEventIdType>(0);
599 
600  _id = this->getIdBase() + EVENTID_SPI_CONFIGERROR;
601 
602  // Emit the event on the log port
603  if (this->m_Log_OutputPort[0].isConnected()) {
604  Fw::LogBuffer _logBuff;
606 
607 #if FW_AMPCS_COMPATIBLE
608  // Serialize the number of arguments
609  _status = _logBuff.serialize(static_cast<U8>(3));
610  FW_ASSERT(
611  _status == Fw::FW_SERIALIZE_OK,
612  static_cast<FwAssertArgType>(_status)
613  );
614 #endif
615 
616 #if FW_AMPCS_COMPATIBLE
617  // Serialize the argument size
618  _status = _logBuff.serialize(
619  static_cast<U8>(sizeof(I32))
620  );
621  FW_ASSERT(
622  _status == Fw::FW_SERIALIZE_OK,
623  static_cast<FwAssertArgType>(_status)
624  );
625 #endif
626  _status = _logBuff.serialize(device);
627  FW_ASSERT(
628  _status == Fw::FW_SERIALIZE_OK,
629  static_cast<FwAssertArgType>(_status)
630  );
631 
632 #if FW_AMPCS_COMPATIBLE
633  // Serialize the argument size
634  _status = _logBuff.serialize(
635  static_cast<U8>(sizeof(I32))
636  );
637  FW_ASSERT(
638  _status == Fw::FW_SERIALIZE_OK,
639  static_cast<FwAssertArgType>(_status)
640  );
641 #endif
642  _status = _logBuff.serialize(select);
643  FW_ASSERT(
644  _status == Fw::FW_SERIALIZE_OK,
645  static_cast<FwAssertArgType>(_status)
646  );
647 
648 #if FW_AMPCS_COMPATIBLE
649  // Serialize the argument size
650  _status = _logBuff.serialize(
651  static_cast<U8>(sizeof(I32))
652  );
653  FW_ASSERT(
654  _status == Fw::FW_SERIALIZE_OK,
655  static_cast<FwAssertArgType>(_status)
656  );
657 #endif
658  _status = _logBuff.serialize(error);
659  FW_ASSERT(
660  _status == Fw::FW_SERIALIZE_OK,
661  static_cast<FwAssertArgType>(_status)
662  );
663 
664  this->m_Log_OutputPort[0].invoke(
665  _id,
666  _logTime,
668  _logBuff
669  );
670  }
671 
672  // Emit the event on the text log port
673 #if FW_ENABLE_TEXT_LOGGING
674  if (this->m_LogText_OutputPort[0].isConnected()) {
675 #if FW_OBJECT_NAMES == 1
676  const char* _formatString =
677  "(%s) %s: Error configuring SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
678 #else
679  const char* _formatString =
680  "%s: Error configuring SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
681 #endif
682 
683  char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
684 
685  (void) snprintf(
686  _textBuffer,
688  _formatString,
689 #if FW_OBJECT_NAMES == 1
690  this->m_objName,
691 #endif
692  "SPI_ConfigError ",
693  device,
694  select,
695  error
696  );
697 
698  // Null terminate
699  _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
700  Fw::TextLogString _logString = _textBuffer;
701  this->m_LogText_OutputPort[0].invoke(
702  _id,
703  _logTime,
705  _logString
706  );
707  }
708 #endif
709  }
710 
713  I32 device,
714  I32 select,
715  I32 error
716  )
717  {
718  // Check throttle value
719  if (this->m_SPI_WriteErrorThrottle >= EVENTID_SPI_WRITEERROR_THROTTLE) {
720  return;
721  }
722  else {
723  this->m_SPI_WriteErrorThrottle++;
724  }
725 
726  // Get the time
727  Fw::Time _logTime;
728  if (this->m_Time_OutputPort[0].isConnected()) {
729  this->m_Time_OutputPort[0].invoke(_logTime);
730  }
731 
732  FwEventIdType _id = static_cast<FwEventIdType>(0);
733 
734  _id = this->getIdBase() + EVENTID_SPI_WRITEERROR;
735 
736  // Emit the event on the log port
737  if (this->m_Log_OutputPort[0].isConnected()) {
738  Fw::LogBuffer _logBuff;
740 
741 #if FW_AMPCS_COMPATIBLE
742  // Serialize the number of arguments
743  _status = _logBuff.serialize(static_cast<U8>(3));
744  FW_ASSERT(
745  _status == Fw::FW_SERIALIZE_OK,
746  static_cast<FwAssertArgType>(_status)
747  );
748 #endif
749 
750 #if FW_AMPCS_COMPATIBLE
751  // Serialize the argument size
752  _status = _logBuff.serialize(
753  static_cast<U8>(sizeof(I32))
754  );
755  FW_ASSERT(
756  _status == Fw::FW_SERIALIZE_OK,
757  static_cast<FwAssertArgType>(_status)
758  );
759 #endif
760  _status = _logBuff.serialize(device);
761  FW_ASSERT(
762  _status == Fw::FW_SERIALIZE_OK,
763  static_cast<FwAssertArgType>(_status)
764  );
765 
766 #if FW_AMPCS_COMPATIBLE
767  // Serialize the argument size
768  _status = _logBuff.serialize(
769  static_cast<U8>(sizeof(I32))
770  );
771  FW_ASSERT(
772  _status == Fw::FW_SERIALIZE_OK,
773  static_cast<FwAssertArgType>(_status)
774  );
775 #endif
776  _status = _logBuff.serialize(select);
777  FW_ASSERT(
778  _status == Fw::FW_SERIALIZE_OK,
779  static_cast<FwAssertArgType>(_status)
780  );
781 
782 #if FW_AMPCS_COMPATIBLE
783  // Serialize the argument size
784  _status = _logBuff.serialize(
785  static_cast<U8>(sizeof(I32))
786  );
787  FW_ASSERT(
788  _status == Fw::FW_SERIALIZE_OK,
789  static_cast<FwAssertArgType>(_status)
790  );
791 #endif
792  _status = _logBuff.serialize(error);
793  FW_ASSERT(
794  _status == Fw::FW_SERIALIZE_OK,
795  static_cast<FwAssertArgType>(_status)
796  );
797 
798  this->m_Log_OutputPort[0].invoke(
799  _id,
800  _logTime,
802  _logBuff
803  );
804  }
805 
806  // Emit the event on the text log port
807 #if FW_ENABLE_TEXT_LOGGING
808  if (this->m_LogText_OutputPort[0].isConnected()) {
809 #if FW_OBJECT_NAMES == 1
810  const char* _formatString =
811  "(%s) %s: Error writing/reading SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
812 #else
813  const char* _formatString =
814  "%s: Error writing/reading SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
815 #endif
816 
817  char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
818 
819  (void) snprintf(
820  _textBuffer,
822  _formatString,
823 #if FW_OBJECT_NAMES == 1
824  this->m_objName,
825 #endif
826  "SPI_WriteError ",
827  device,
828  select,
829  error
830  );
831 
832  // Null terminate
833  _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
834  Fw::TextLogString _logString = _textBuffer;
835  this->m_LogText_OutputPort[0].invoke(
836  _id,
837  _logTime,
839  _logString
840  );
841  }
842 #endif
843  }
844 
847  I32 device,
848  I32 select
849  )
850  {
851  // Get the time
852  Fw::Time _logTime;
853  if (this->m_Time_OutputPort[0].isConnected()) {
854  this->m_Time_OutputPort[0].invoke(_logTime);
855  }
856 
857  FwEventIdType _id = static_cast<FwEventIdType>(0);
858 
859  _id = this->getIdBase() + EVENTID_SPI_PORTOPENED;
860 
861  // Emit the event on the log port
862  if (this->m_Log_OutputPort[0].isConnected()) {
863  Fw::LogBuffer _logBuff;
865 
866 #if FW_AMPCS_COMPATIBLE
867  // Serialize the number of arguments
868  _status = _logBuff.serialize(static_cast<U8>(2));
869  FW_ASSERT(
870  _status == Fw::FW_SERIALIZE_OK,
871  static_cast<FwAssertArgType>(_status)
872  );
873 #endif
874 
875 #if FW_AMPCS_COMPATIBLE
876  // Serialize the argument size
877  _status = _logBuff.serialize(
878  static_cast<U8>(sizeof(I32))
879  );
880  FW_ASSERT(
881  _status == Fw::FW_SERIALIZE_OK,
882  static_cast<FwAssertArgType>(_status)
883  );
884 #endif
885  _status = _logBuff.serialize(device);
886  FW_ASSERT(
887  _status == Fw::FW_SERIALIZE_OK,
888  static_cast<FwAssertArgType>(_status)
889  );
890 
891 #if FW_AMPCS_COMPATIBLE
892  // Serialize the argument size
893  _status = _logBuff.serialize(
894  static_cast<U8>(sizeof(I32))
895  );
896  FW_ASSERT(
897  _status == Fw::FW_SERIALIZE_OK,
898  static_cast<FwAssertArgType>(_status)
899  );
900 #endif
901  _status = _logBuff.serialize(select);
902  FW_ASSERT(
903  _status == Fw::FW_SERIALIZE_OK,
904  static_cast<FwAssertArgType>(_status)
905  );
906 
907  this->m_Log_OutputPort[0].invoke(
908  _id,
909  _logTime,
911  _logBuff
912  );
913  }
914 
915  // Emit the event on the text log port
916 #if FW_ENABLE_TEXT_LOGGING
917  if (this->m_LogText_OutputPort[0].isConnected()) {
918 #if FW_OBJECT_NAMES == 1
919  const char* _formatString =
920  "(%s) %s: SPI Device %" PRIi32 ".%" PRIi32 " configured";
921 #else
922  const char* _formatString =
923  "%s: SPI Device %" PRIi32 ".%" PRIi32 " configured";
924 #endif
925 
926  char _textBuffer[FW_LOG_TEXT_BUFFER_SIZE];
927 
928  (void) snprintf(
929  _textBuffer,
931  _formatString,
932 #if FW_OBJECT_NAMES == 1
933  this->m_objName,
934 #endif
935  "SPI_PortOpened ",
936  device,
937  select
938  );
939 
940  // Null terminate
941  _textBuffer[FW_LOG_TEXT_BUFFER_SIZE-1] = 0;
942  Fw::TextLogString _logString = _textBuffer;
943  this->m_LogText_OutputPort[0].invoke(
944  _id,
945  _logTime,
947  _logString
948  );
949  }
950 #endif
951  }
952 
953  // ----------------------------------------------------------------------
954  // Event throttle reset functions
955  // ----------------------------------------------------------------------
956 
959  {
960  // Reset throttle counter
961  this->m_SPI_WriteErrorThrottle = 0;
962  }
963 
964  // ----------------------------------------------------------------------
965  // Telemetry write functions
966  // ----------------------------------------------------------------------
967 
970  U32 arg,
971  Fw::Time _tlmTime
972  )
973  {
974  if (this->m_Tlm_OutputPort[0].isConnected()) {
975  if (
976  this->m_Time_OutputPort[0].isConnected() &&
977  (_tlmTime == Fw::ZERO_TIME)
978  ) {
979  this->m_Time_OutputPort[0].invoke(_tlmTime);
980  }
981 
982  Fw::TlmBuffer _tlmBuff;
983  Fw::SerializeStatus _stat = _tlmBuff.serialize(arg);
984  FW_ASSERT(
985  _stat == Fw::FW_SERIALIZE_OK,
986  static_cast<FwAssertArgType>(_stat)
987  );
988 
989  FwChanIdType _id;
990 
991  _id = this->getIdBase() + CHANNELID_SPI_BYTES;
992 
993  this->m_Tlm_OutputPort[0].invoke(
994  _id,
995  _tlmTime,
996  _tlmBuff
997  );
998  }
999  }
1000 
1001  // ----------------------------------------------------------------------
1002  // Time
1003  // ----------------------------------------------------------------------
1004 
1006  getTime()
1007  {
1008  if (this->m_Time_OutputPort[0].isConnected()) {
1009  Fw::Time _time;
1010  this->m_Time_OutputPort[0].invoke(_time);
1011  return _time;
1012  }
1013  else {
1014  return Fw::Time(TB_NONE, 0, 0);
1015  }
1016  }
1017 
1018  // ----------------------------------------------------------------------
1019  // Calls for messages received on typed input ports
1020  // ----------------------------------------------------------------------
1021 
1022  void LinuxSpiDriverComponentBase ::
1023  m_p_SpiReadWrite_in(
1024  Fw::PassiveComponentBase* callComp,
1025  NATIVE_INT_TYPE portNum,
1026  Fw::Buffer& writeBuffer,
1027  Fw::Buffer& readBuffer
1028  )
1029  {
1030  FW_ASSERT(callComp);
1031  LinuxSpiDriverComponentBase* compPtr = static_cast<LinuxSpiDriverComponentBase*>(callComp);
1032  compPtr->SpiReadWrite_handlerBase(
1033  portNum,
1034  writeBuffer,
1035  readBuffer
1036  );
1037  }
1038 
1039 }
#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 FwChanIdType
Definition: FpConfig.h:59
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 SpiReadWrite port.
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
void init()
Initialization function.
Auto-generated base for LinuxSpiDriver component.
void log_WARNING_HI_SPI_WriteError(I32 device, I32 select, I32 error)
LinuxSpiDriverComponentBase(const char *compName="")
Construct LinuxSpiDriverComponentBase object.
virtual void SpiReadWrite_handler(NATIVE_INT_TYPE portNum, Fw::Buffer &writeBuffer, Fw::Buffer &readBuffer)=0
Handler for input port SpiReadWrite.
void tlmWrite_SPI_Bytes(U32 arg, Fw::Time _tlmTime=Fw::Time())
@ CHANNELID_SPI_BYTES
Channel ID for SPI_Bytes.
void log_WARNING_HI_SPI_WriteError_ThrottleClear()
Reset throttle value for SPI_WriteError.
bool isConnected_Tlm_OutputPort(NATIVE_INT_TYPE portNum)
void log_WARNING_HI_SPI_ConfigError(I32 device, I32 select, I32 error)
bool isConnected_Time_OutputPort(NATIVE_INT_TYPE portNum)
void set_Log_OutputPort(NATIVE_INT_TYPE portNum, Fw::InputLogPort *port)
Connect port to Log[portNum].
@ EVENTID_SPI_WRITEERROR_THROTTLE
Throttle reset count for SPI_WriteError.
NATIVE_INT_TYPE getNum_SpiReadWrite_InputPorts() const
bool isConnected_Log_OutputPort(NATIVE_INT_TYPE portNum)
void log_ACTIVITY_HI_SPI_PortOpened(I32 device, I32 select)
void set_Time_OutputPort(NATIVE_INT_TYPE portNum, Fw::InputTimePort *port)
Connect port to Time[portNum].
void SpiReadWrite_handlerBase(NATIVE_INT_TYPE portNum, Fw::Buffer &writeBuffer, Fw::Buffer &readBuffer)
Handler base-class function for input port SpiReadWrite.
virtual ~LinuxSpiDriverComponentBase()
Destroy LinuxSpiDriverComponentBase object.
Drv::InputSpiReadWritePort * get_SpiReadWrite_InputPort(NATIVE_INT_TYPE portNum)
void set_Tlm_OutputPort(NATIVE_INT_TYPE portNum, Fw::InputTlmPort *port)
Connect port to Tlm[portNum].
void log_WARNING_HI_SPI_OpenError(I32 device, I32 select, I32 error)
void setPortNum(NATIVE_INT_TYPE portNum)
@ WARNING_HI
A serious but recoverable event.
@ ACTIVITY_HI
Important informational events.
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
void addCallPort(InputTlmPort *callPort)
Register an input port.
Definition: TlmPortAc.cpp:150
void init()
Initialization function.
Definition: TlmPortAc.cpp:144
void invoke(FwChanIdType id, Fw::Time &timeTag, Fw::TlmBuffer &val)
Invoke a port interface.
Definition: TlmPortAc.cpp:163
bool isConnected()
Definition: PortBase.cpp:41
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
Definition: Time.hpp:9
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
const Time ZERO_TIME
Definition: Time.cpp:5