F´ Flight Software - C/C++ Documentation
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 
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 SpiReadWrite
27  for (
28  FwIndexType port = 0;
29  port < static_cast<FwIndexType>(this->getNum_SpiReadWrite_InputPorts());
30  port++
31  ) {
32  this->m_SpiReadWrite_InputPort[port].init();
33  this->m_SpiReadWrite_InputPort[port].addCallComp(
34  this,
35  m_p_SpiReadWrite_in
36  );
37  this->m_SpiReadWrite_InputPort[port].setPortNum(port);
38 
39 #if FW_OBJECT_NAMES == 1
40  Fw::ObjectName portName;
41  portName.format(
42  "%s_SpiReadWrite_InputPort[%" PRI_FwIndexType "]",
43  this->m_objName.toChar(),
44  port
45  );
46  this->m_SpiReadWrite_InputPort[port].setObjName(portName.toChar());
47 #endif
48  }
49 
50  // Connect output port Log
51  for (
52  FwIndexType port = 0;
53  port < static_cast<FwIndexType>(this->getNum_Log_OutputPorts());
54  port++
55  ) {
56  this->m_Log_OutputPort[port].init();
57 
58 #if FW_OBJECT_NAMES == 1
59  Fw::ObjectName portName;
60  portName.format(
61  "%s_Log_OutputPort[%" PRI_FwIndexType "]",
62  this->m_objName.toChar(),
63  port
64  );
65  this->m_Log_OutputPort[port].setObjName(portName.toChar());
66 #endif
67  }
68 
69 #if FW_ENABLE_TEXT_LOGGING == 1
70  // Connect output port LogText
71  for (
72  FwIndexType port = 0;
73  port < static_cast<FwIndexType>(this->getNum_LogText_OutputPorts());
74  port++
75  ) {
76  this->m_LogText_OutputPort[port].init();
77 
78 #if FW_OBJECT_NAMES == 1
79  Fw::ObjectName portName;
80  portName.format(
81  "%s_LogText_OutputPort[%" PRI_FwIndexType "]",
82  this->m_objName.toChar(),
83  port
84  );
85  this->m_LogText_OutputPort[port].setObjName(portName.toChar());
86 #endif
87  }
88 #endif
89 
90  // Connect output port Time
91  for (
92  FwIndexType port = 0;
93  port < static_cast<FwIndexType>(this->getNum_Time_OutputPorts());
94  port++
95  ) {
96  this->m_Time_OutputPort[port].init();
97 
98 #if FW_OBJECT_NAMES == 1
99  Fw::ObjectName portName;
100  portName.format(
101  "%s_Time_OutputPort[%" PRI_FwIndexType "]",
102  this->m_objName.toChar(),
103  port
104  );
105  this->m_Time_OutputPort[port].setObjName(portName.toChar());
106 #endif
107  }
108 
109  // Connect output port Tlm
110  for (
111  FwIndexType port = 0;
112  port < static_cast<FwIndexType>(this->getNum_Tlm_OutputPorts());
113  port++
114  ) {
115  this->m_Tlm_OutputPort[port].init();
116 
117 #if FW_OBJECT_NAMES == 1
118  Fw::ObjectName portName;
119  portName.format(
120  "%s_Tlm_OutputPort[%" PRI_FwIndexType "]",
121  this->m_objName.toChar(),
122  port
123  );
124  this->m_Tlm_OutputPort[port].setObjName(portName.toChar());
125 #endif
126  }
127  }
128 
129  // ----------------------------------------------------------------------
130  // Getters for typed input ports
131  // ----------------------------------------------------------------------
132 
135  {
136  FW_ASSERT(
137  (0 <= portNum) && (portNum < this->getNum_SpiReadWrite_InputPorts()),
138  static_cast<FwAssertArgType>(portNum)
139  );
140 
141  return &this->m_SpiReadWrite_InputPort[portNum];
142  }
143 
144  // ----------------------------------------------------------------------
145  // Connect input ports to special output ports
146  // ----------------------------------------------------------------------
147 
150  FwIndexType portNum,
151  Fw::InputLogPort* port
152  )
153  {
154  FW_ASSERT(
155  (0 <= portNum) && (portNum < this->getNum_Log_OutputPorts()),
156  static_cast<FwAssertArgType>(portNum)
157  );
158 
159  this->m_Log_OutputPort[portNum].addCallPort(port);
160  }
161 
162 #if FW_ENABLE_TEXT_LOGGING == 1
163 
164  void LinuxSpiDriverComponentBase ::
165  set_LogText_OutputPort(
166  FwIndexType portNum,
168  )
169  {
170  FW_ASSERT(
171  (0 <= portNum) && (portNum < this->getNum_LogText_OutputPorts()),
172  static_cast<FwAssertArgType>(portNum)
173  );
174 
175  this->m_LogText_OutputPort[portNum].addCallPort(port);
176  }
177 
178 #endif
179 
182  FwIndexType portNum,
183  Fw::InputTimePort* port
184  )
185  {
186  FW_ASSERT(
187  (0 <= portNum) && (portNum < this->getNum_Time_OutputPorts()),
188  static_cast<FwAssertArgType>(portNum)
189  );
190 
191  this->m_Time_OutputPort[portNum].addCallPort(port);
192  }
193 
196  FwIndexType portNum,
197  Fw::InputTlmPort* port
198  )
199  {
200  FW_ASSERT(
201  (0 <= portNum) && (portNum < this->getNum_Tlm_OutputPorts()),
202  static_cast<FwAssertArgType>(portNum)
203  );
204 
205  this->m_Tlm_OutputPort[portNum].addCallPort(port);
206  }
207 
208 #if FW_PORT_SERIALIZATION
209 
210  // ----------------------------------------------------------------------
211  // Connect serial input ports to special output ports
212  // ----------------------------------------------------------------------
213 
216  FwIndexType portNum,
217  Fw::InputSerializePort* port
218  )
219  {
220  FW_ASSERT(
221  (0 <= portNum) && (portNum < this->getNum_Log_OutputPorts()),
222  static_cast<FwAssertArgType>(portNum)
223  );
224 
225  this->m_Log_OutputPort[portNum].registerSerialPort(port);
226  }
227 
228 #if FW_ENABLE_TEXT_LOGGING == 1
229 
230  void LinuxSpiDriverComponentBase ::
231  set_LogText_OutputPort(
232  FwIndexType portNum,
233  Fw::InputSerializePort* port
234  )
235  {
236  FW_ASSERT(
237  (0 <= portNum) && (portNum < this->getNum_LogText_OutputPorts()),
238  static_cast<FwAssertArgType>(portNum)
239  );
240 
241  this->m_LogText_OutputPort[portNum].registerSerialPort(port);
242  }
243 
244 #endif
245 
248  FwIndexType portNum,
249  Fw::InputSerializePort* port
250  )
251  {
252  FW_ASSERT(
253  (0 <= portNum) && (portNum < this->getNum_Time_OutputPorts()),
254  static_cast<FwAssertArgType>(portNum)
255  );
256 
257  this->m_Time_OutputPort[portNum].registerSerialPort(port);
258  }
259 
262  FwIndexType portNum,
263  Fw::InputSerializePort* port
264  )
265  {
266  FW_ASSERT(
267  (0 <= portNum) && (portNum < this->getNum_Tlm_OutputPorts()),
268  static_cast<FwAssertArgType>(portNum)
269  );
270 
271  this->m_Tlm_OutputPort[portNum].registerSerialPort(port);
272  }
273 
274 #endif
275 
276  // ----------------------------------------------------------------------
277  // Component construction and destruction
278  // ----------------------------------------------------------------------
279 
281  LinuxSpiDriverComponentBase(const char* compName) :
282  Fw::PassiveComponentBase(compName)
283  {
284  this->m_SPI_WriteErrorThrottle = 0;
285  }
286 
289  {
290 
291  }
292 
293  // ----------------------------------------------------------------------
294  // Connection status queries for special output ports
295  // ----------------------------------------------------------------------
296 
299  {
300  FW_ASSERT(
301  (0 <= portNum) && (portNum < this->getNum_Log_OutputPorts()),
302  static_cast<FwAssertArgType>(portNum)
303  );
304 
305  return this->m_Log_OutputPort[portNum].isConnected();
306  }
307 
308 #if FW_ENABLE_TEXT_LOGGING == 1
309 
310  bool LinuxSpiDriverComponentBase ::
311  isConnected_LogText_OutputPort(FwIndexType portNum)
312  {
313  FW_ASSERT(
314  (0 <= portNum) && (portNum < this->getNum_LogText_OutputPorts()),
315  static_cast<FwAssertArgType>(portNum)
316  );
317 
318  return this->m_LogText_OutputPort[portNum].isConnected();
319  }
320 
321 #endif
322 
325  {
326  FW_ASSERT(
327  (0 <= portNum) && (portNum < this->getNum_Time_OutputPorts()),
328  static_cast<FwAssertArgType>(portNum)
329  );
330 
331  return this->m_Time_OutputPort[portNum].isConnected();
332  }
333 
336  {
337  FW_ASSERT(
338  (0 <= portNum) && (portNum < this->getNum_Tlm_OutputPorts()),
339  static_cast<FwAssertArgType>(portNum)
340  );
341 
342  return this->m_Tlm_OutputPort[portNum].isConnected();
343  }
344 
345  // ----------------------------------------------------------------------
346  // Port handler base-class functions for typed input ports
347  //
348  // Call these functions directly to bypass the corresponding ports
349  // ----------------------------------------------------------------------
350 
353  FwIndexType portNum,
354  Fw::Buffer& writeBuffer,
355  Fw::Buffer& readBuffer
356  )
357  {
358  // Make sure port number is valid
359  FW_ASSERT(
360  (0 <= portNum) && (portNum < this->getNum_SpiReadWrite_InputPorts()),
361  static_cast<FwAssertArgType>(portNum)
362  );
363 
364  // Call handler function
365  this->SpiReadWrite_handler(
366  portNum,
367  writeBuffer,
368  readBuffer
369  );
370  }
371 
372  // ----------------------------------------------------------------------
373  // Event logging functions
374  // ----------------------------------------------------------------------
375 
378  I32 device,
379  I32 select,
380  I32 error
381  ) const
382  {
383  // Get the time
384  Fw::Time _logTime;
385  if (this->m_Time_OutputPort[0].isConnected()) {
386  this->m_Time_OutputPort[0].invoke(_logTime);
387  }
388 
389  FwEventIdType _id = static_cast<FwEventIdType>(0);
390 
391  _id = this->getIdBase() + EVENTID_SPI_OPENERROR;
392 
393  // Emit the event on the log port
394  if (this->m_Log_OutputPort[0].isConnected()) {
395  Fw::LogBuffer _logBuff;
397 
398 #if FW_AMPCS_COMPATIBLE
399  // Serialize the number of arguments
400  _status = _logBuff.serializeFrom(static_cast<U8>(3));
401  FW_ASSERT(
402  _status == Fw::FW_SERIALIZE_OK,
403  static_cast<FwAssertArgType>(_status)
404  );
405 #endif
406 
407 #if FW_AMPCS_COMPATIBLE
408  // Serialize the argument size
409  _status = _logBuff.serializeFrom(
410  static_cast<U8>(sizeof(I32))
411  );
412  FW_ASSERT(
413  _status == Fw::FW_SERIALIZE_OK,
414  static_cast<FwAssertArgType>(_status)
415  );
416 #endif
417  _status = _logBuff.serializeFrom(device);
418  FW_ASSERT(
419  _status == Fw::FW_SERIALIZE_OK,
420  static_cast<FwAssertArgType>(_status)
421  );
422 
423 #if FW_AMPCS_COMPATIBLE
424  // Serialize the argument size
425  _status = _logBuff.serializeFrom(
426  static_cast<U8>(sizeof(I32))
427  );
428  FW_ASSERT(
429  _status == Fw::FW_SERIALIZE_OK,
430  static_cast<FwAssertArgType>(_status)
431  );
432 #endif
433  _status = _logBuff.serializeFrom(select);
434  FW_ASSERT(
435  _status == Fw::FW_SERIALIZE_OK,
436  static_cast<FwAssertArgType>(_status)
437  );
438 
439 #if FW_AMPCS_COMPATIBLE
440  // Serialize the argument size
441  _status = _logBuff.serializeFrom(
442  static_cast<U8>(sizeof(I32))
443  );
444  FW_ASSERT(
445  _status == Fw::FW_SERIALIZE_OK,
446  static_cast<FwAssertArgType>(_status)
447  );
448 #endif
449  _status = _logBuff.serializeFrom(error);
450  FW_ASSERT(
451  _status == Fw::FW_SERIALIZE_OK,
452  static_cast<FwAssertArgType>(_status)
453  );
454 
455  this->m_Log_OutputPort[0].invoke(
456  _id,
457  _logTime,
459  _logBuff
460  );
461  }
462 
463  // Emit the event on the text log port
464 #if FW_ENABLE_TEXT_LOGGING
465  if (this->m_LogText_OutputPort[0].isConnected()) {
466 #if FW_OBJECT_NAMES == 1
467  const char* _formatString =
468  "(%s) %s: Error opening SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
469 #else
470  const char* _formatString =
471  "%s: Error opening SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
472 #endif
473 
474  Fw::TextLogString _logString;
475  _logString.format(
476  _formatString,
477 #if FW_OBJECT_NAMES == 1
478  this->m_objName.toChar(),
479 #endif
480  "SPI_OpenError ",
481  device,
482  select,
483  error
484  );
485 
486  this->m_LogText_OutputPort[0].invoke(
487  _id,
488  _logTime,
490  _logString
491  );
492  }
493 #endif
494  }
495 
498  I32 device,
499  I32 select,
500  I32 error
501  ) const
502  {
503  // Get the time
504  Fw::Time _logTime;
505  if (this->m_Time_OutputPort[0].isConnected()) {
506  this->m_Time_OutputPort[0].invoke(_logTime);
507  }
508 
509  FwEventIdType _id = static_cast<FwEventIdType>(0);
510 
511  _id = this->getIdBase() + EVENTID_SPI_CONFIGERROR;
512 
513  // Emit the event on the log port
514  if (this->m_Log_OutputPort[0].isConnected()) {
515  Fw::LogBuffer _logBuff;
517 
518 #if FW_AMPCS_COMPATIBLE
519  // Serialize the number of arguments
520  _status = _logBuff.serializeFrom(static_cast<U8>(3));
521  FW_ASSERT(
522  _status == Fw::FW_SERIALIZE_OK,
523  static_cast<FwAssertArgType>(_status)
524  );
525 #endif
526 
527 #if FW_AMPCS_COMPATIBLE
528  // Serialize the argument size
529  _status = _logBuff.serializeFrom(
530  static_cast<U8>(sizeof(I32))
531  );
532  FW_ASSERT(
533  _status == Fw::FW_SERIALIZE_OK,
534  static_cast<FwAssertArgType>(_status)
535  );
536 #endif
537  _status = _logBuff.serializeFrom(device);
538  FW_ASSERT(
539  _status == Fw::FW_SERIALIZE_OK,
540  static_cast<FwAssertArgType>(_status)
541  );
542 
543 #if FW_AMPCS_COMPATIBLE
544  // Serialize the argument size
545  _status = _logBuff.serializeFrom(
546  static_cast<U8>(sizeof(I32))
547  );
548  FW_ASSERT(
549  _status == Fw::FW_SERIALIZE_OK,
550  static_cast<FwAssertArgType>(_status)
551  );
552 #endif
553  _status = _logBuff.serializeFrom(select);
554  FW_ASSERT(
555  _status == Fw::FW_SERIALIZE_OK,
556  static_cast<FwAssertArgType>(_status)
557  );
558 
559 #if FW_AMPCS_COMPATIBLE
560  // Serialize the argument size
561  _status = _logBuff.serializeFrom(
562  static_cast<U8>(sizeof(I32))
563  );
564  FW_ASSERT(
565  _status == Fw::FW_SERIALIZE_OK,
566  static_cast<FwAssertArgType>(_status)
567  );
568 #endif
569  _status = _logBuff.serializeFrom(error);
570  FW_ASSERT(
571  _status == Fw::FW_SERIALIZE_OK,
572  static_cast<FwAssertArgType>(_status)
573  );
574 
575  this->m_Log_OutputPort[0].invoke(
576  _id,
577  _logTime,
579  _logBuff
580  );
581  }
582 
583  // Emit the event on the text log port
584 #if FW_ENABLE_TEXT_LOGGING
585  if (this->m_LogText_OutputPort[0].isConnected()) {
586 #if FW_OBJECT_NAMES == 1
587  const char* _formatString =
588  "(%s) %s: Error configuring SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
589 #else
590  const char* _formatString =
591  "%s: Error configuring SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
592 #endif
593 
594  Fw::TextLogString _logString;
595  _logString.format(
596  _formatString,
597 #if FW_OBJECT_NAMES == 1
598  this->m_objName.toChar(),
599 #endif
600  "SPI_ConfigError ",
601  device,
602  select,
603  error
604  );
605 
606  this->m_LogText_OutputPort[0].invoke(
607  _id,
608  _logTime,
610  _logString
611  );
612  }
613 #endif
614  }
615 
618  I32 device,
619  I32 select,
620  I32 error
621  )
622  {
623  // Check throttle value
624  if (this->m_SPI_WriteErrorThrottle >= EVENTID_SPI_WRITEERROR_THROTTLE) {
625  return;
626  }
627  else {
628  this->m_SPI_WriteErrorThrottle++;
629  }
630 
631  // Get the time
632  Fw::Time _logTime;
633  if (this->m_Time_OutputPort[0].isConnected()) {
634  this->m_Time_OutputPort[0].invoke(_logTime);
635  }
636 
637  FwEventIdType _id = static_cast<FwEventIdType>(0);
638 
639  _id = this->getIdBase() + EVENTID_SPI_WRITEERROR;
640 
641  // Emit the event on the log port
642  if (this->m_Log_OutputPort[0].isConnected()) {
643  Fw::LogBuffer _logBuff;
645 
646 #if FW_AMPCS_COMPATIBLE
647  // Serialize the number of arguments
648  _status = _logBuff.serializeFrom(static_cast<U8>(3));
649  FW_ASSERT(
650  _status == Fw::FW_SERIALIZE_OK,
651  static_cast<FwAssertArgType>(_status)
652  );
653 #endif
654 
655 #if FW_AMPCS_COMPATIBLE
656  // Serialize the argument size
657  _status = _logBuff.serializeFrom(
658  static_cast<U8>(sizeof(I32))
659  );
660  FW_ASSERT(
661  _status == Fw::FW_SERIALIZE_OK,
662  static_cast<FwAssertArgType>(_status)
663  );
664 #endif
665  _status = _logBuff.serializeFrom(device);
666  FW_ASSERT(
667  _status == Fw::FW_SERIALIZE_OK,
668  static_cast<FwAssertArgType>(_status)
669  );
670 
671 #if FW_AMPCS_COMPATIBLE
672  // Serialize the argument size
673  _status = _logBuff.serializeFrom(
674  static_cast<U8>(sizeof(I32))
675  );
676  FW_ASSERT(
677  _status == Fw::FW_SERIALIZE_OK,
678  static_cast<FwAssertArgType>(_status)
679  );
680 #endif
681  _status = _logBuff.serializeFrom(select);
682  FW_ASSERT(
683  _status == Fw::FW_SERIALIZE_OK,
684  static_cast<FwAssertArgType>(_status)
685  );
686 
687 #if FW_AMPCS_COMPATIBLE
688  // Serialize the argument size
689  _status = _logBuff.serializeFrom(
690  static_cast<U8>(sizeof(I32))
691  );
692  FW_ASSERT(
693  _status == Fw::FW_SERIALIZE_OK,
694  static_cast<FwAssertArgType>(_status)
695  );
696 #endif
697  _status = _logBuff.serializeFrom(error);
698  FW_ASSERT(
699  _status == Fw::FW_SERIALIZE_OK,
700  static_cast<FwAssertArgType>(_status)
701  );
702 
703  this->m_Log_OutputPort[0].invoke(
704  _id,
705  _logTime,
707  _logBuff
708  );
709  }
710 
711  // Emit the event on the text log port
712 #if FW_ENABLE_TEXT_LOGGING
713  if (this->m_LogText_OutputPort[0].isConnected()) {
714 #if FW_OBJECT_NAMES == 1
715  const char* _formatString =
716  "(%s) %s: Error writing/reading SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
717 #else
718  const char* _formatString =
719  "%s: Error writing/reading SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
720 #endif
721 
722  Fw::TextLogString _logString;
723  _logString.format(
724  _formatString,
725 #if FW_OBJECT_NAMES == 1
726  this->m_objName.toChar(),
727 #endif
728  "SPI_WriteError ",
729  device,
730  select,
731  error
732  );
733 
734  this->m_LogText_OutputPort[0].invoke(
735  _id,
736  _logTime,
738  _logString
739  );
740  }
741 #endif
742  }
743 
746  I32 device,
747  I32 select,
748  const Fw::StringBase& parameter,
749  U32 write_value,
750  U32 read_value
751  ) const
752  {
753  // Get the time
754  Fw::Time _logTime;
755  if (this->m_Time_OutputPort[0].isConnected()) {
756  this->m_Time_OutputPort[0].invoke(_logTime);
757  }
758 
759  FwEventIdType _id = static_cast<FwEventIdType>(0);
760 
761  _id = this->getIdBase() + EVENTID_SPI_CONFIGMISMATCH;
762 
763  // Emit the event on the log port
764  if (this->m_Log_OutputPort[0].isConnected()) {
765  Fw::LogBuffer _logBuff;
767 
768 #if FW_AMPCS_COMPATIBLE
769  // Serialize the number of arguments
770  _status = _logBuff.serializeFrom(static_cast<U8>(5));
771  FW_ASSERT(
772  _status == Fw::FW_SERIALIZE_OK,
773  static_cast<FwAssertArgType>(_status)
774  );
775 #endif
776 
777 #if FW_AMPCS_COMPATIBLE
778  // Serialize the argument size
779  _status = _logBuff.serializeFrom(
780  static_cast<U8>(sizeof(I32))
781  );
782  FW_ASSERT(
783  _status == Fw::FW_SERIALIZE_OK,
784  static_cast<FwAssertArgType>(_status)
785  );
786 #endif
787  _status = _logBuff.serializeFrom(device);
788  FW_ASSERT(
789  _status == Fw::FW_SERIALIZE_OK,
790  static_cast<FwAssertArgType>(_status)
791  );
792 
793 #if FW_AMPCS_COMPATIBLE
794  // Serialize the argument size
795  _status = _logBuff.serializeFrom(
796  static_cast<U8>(sizeof(I32))
797  );
798  FW_ASSERT(
799  _status == Fw::FW_SERIALIZE_OK,
800  static_cast<FwAssertArgType>(_status)
801  );
802 #endif
803  _status = _logBuff.serializeFrom(select);
804  FW_ASSERT(
805  _status == Fw::FW_SERIALIZE_OK,
806  static_cast<FwAssertArgType>(_status)
807  );
808 
809  _status = parameter.serializeTo(_logBuff, FW_MIN(FW_LOG_STRING_MAX_SIZE, 80));
810  FW_ASSERT(
811  _status == Fw::FW_SERIALIZE_OK,
812  static_cast<FwAssertArgType>(_status)
813  );
814 
815 #if FW_AMPCS_COMPATIBLE
816  // Serialize the argument size
817  _status = _logBuff.serializeFrom(
818  static_cast<U8>(sizeof(U32))
819  );
820  FW_ASSERT(
821  _status == Fw::FW_SERIALIZE_OK,
822  static_cast<FwAssertArgType>(_status)
823  );
824 #endif
825  _status = _logBuff.serializeFrom(write_value);
826  FW_ASSERT(
827  _status == Fw::FW_SERIALIZE_OK,
828  static_cast<FwAssertArgType>(_status)
829  );
830 
831 #if FW_AMPCS_COMPATIBLE
832  // Serialize the argument size
833  _status = _logBuff.serializeFrom(
834  static_cast<U8>(sizeof(U32))
835  );
836  FW_ASSERT(
837  _status == Fw::FW_SERIALIZE_OK,
838  static_cast<FwAssertArgType>(_status)
839  );
840 #endif
841  _status = _logBuff.serializeFrom(read_value);
842  FW_ASSERT(
843  _status == Fw::FW_SERIALIZE_OK,
844  static_cast<FwAssertArgType>(_status)
845  );
846 
847  this->m_Log_OutputPort[0].invoke(
848  _id,
849  _logTime,
851  _logBuff
852  );
853  }
854 
855  // Emit the event on the text log port
856 #if FW_ENABLE_TEXT_LOGGING
857  if (this->m_LogText_OutputPort[0].isConnected()) {
858 #if FW_OBJECT_NAMES == 1
859  const char* _formatString =
860  "(%s) %s: SPI device %" PRIi32 ".%" PRIi32 " configuration mismatch for %s: wrote %" PRIu32 ", read %" PRIu32 "";
861 #else
862  const char* _formatString =
863  "%s: SPI device %" PRIi32 ".%" PRIi32 " configuration mismatch for %s: wrote %" PRIu32 ", read %" PRIu32 "";
864 #endif
865 
866  Fw::TextLogString _logString;
867  _logString.format(
868  _formatString,
869 #if FW_OBJECT_NAMES == 1
870  this->m_objName.toChar(),
871 #endif
872  "SPI_ConfigMismatch ",
873  device,
874  select,
875  parameter.toChar(),
876  write_value,
877  read_value
878  );
879 
880  this->m_LogText_OutputPort[0].invoke(
881  _id,
882  _logTime,
884  _logString
885  );
886  }
887 #endif
888  }
889 
892  I32 device,
893  I32 select
894  ) const
895  {
896  // Get the time
897  Fw::Time _logTime;
898  if (this->m_Time_OutputPort[0].isConnected()) {
899  this->m_Time_OutputPort[0].invoke(_logTime);
900  }
901 
902  FwEventIdType _id = static_cast<FwEventIdType>(0);
903 
904  _id = this->getIdBase() + EVENTID_SPI_PORTOPENED;
905 
906  // Emit the event on the log port
907  if (this->m_Log_OutputPort[0].isConnected()) {
908  Fw::LogBuffer _logBuff;
910 
911 #if FW_AMPCS_COMPATIBLE
912  // Serialize the number of arguments
913  _status = _logBuff.serializeFrom(static_cast<U8>(2));
914  FW_ASSERT(
915  _status == Fw::FW_SERIALIZE_OK,
916  static_cast<FwAssertArgType>(_status)
917  );
918 #endif
919 
920 #if FW_AMPCS_COMPATIBLE
921  // Serialize the argument size
922  _status = _logBuff.serializeFrom(
923  static_cast<U8>(sizeof(I32))
924  );
925  FW_ASSERT(
926  _status == Fw::FW_SERIALIZE_OK,
927  static_cast<FwAssertArgType>(_status)
928  );
929 #endif
930  _status = _logBuff.serializeFrom(device);
931  FW_ASSERT(
932  _status == Fw::FW_SERIALIZE_OK,
933  static_cast<FwAssertArgType>(_status)
934  );
935 
936 #if FW_AMPCS_COMPATIBLE
937  // Serialize the argument size
938  _status = _logBuff.serializeFrom(
939  static_cast<U8>(sizeof(I32))
940  );
941  FW_ASSERT(
942  _status == Fw::FW_SERIALIZE_OK,
943  static_cast<FwAssertArgType>(_status)
944  );
945 #endif
946  _status = _logBuff.serializeFrom(select);
947  FW_ASSERT(
948  _status == Fw::FW_SERIALIZE_OK,
949  static_cast<FwAssertArgType>(_status)
950  );
951 
952  this->m_Log_OutputPort[0].invoke(
953  _id,
954  _logTime,
956  _logBuff
957  );
958  }
959 
960  // Emit the event on the text log port
961 #if FW_ENABLE_TEXT_LOGGING
962  if (this->m_LogText_OutputPort[0].isConnected()) {
963 #if FW_OBJECT_NAMES == 1
964  const char* _formatString =
965  "(%s) %s: SPI Device %" PRIi32 ".%" PRIi32 " configured";
966 #else
967  const char* _formatString =
968  "%s: SPI Device %" PRIi32 ".%" PRIi32 " configured";
969 #endif
970 
971  Fw::TextLogString _logString;
972  _logString.format(
973  _formatString,
974 #if FW_OBJECT_NAMES == 1
975  this->m_objName.toChar(),
976 #endif
977  "SPI_PortOpened ",
978  device,
979  select
980  );
981 
982  this->m_LogText_OutputPort[0].invoke(
983  _id,
984  _logTime,
986  _logString
987  );
988  }
989 #endif
990  }
991 
992  // ----------------------------------------------------------------------
993  // Event throttle reset functions
994  // ----------------------------------------------------------------------
995 
998  {
999  // Reset throttle counter
1000  this->m_SPI_WriteErrorThrottle = 0;
1001  }
1002 
1003  // ----------------------------------------------------------------------
1004  // Telemetry write functions
1005  // ----------------------------------------------------------------------
1006 
1009  FwSizeType arg,
1010  Fw::Time _tlmTime
1011  ) const
1012  {
1013  if (this->m_Tlm_OutputPort[0].isConnected()) {
1014  if (
1015  this->m_Time_OutputPort[0].isConnected() &&
1016  (_tlmTime == Fw::ZERO_TIME)
1017  ) {
1018  this->m_Time_OutputPort[0].invoke(_tlmTime);
1019  }
1020 
1021  Fw::TlmBuffer _tlmBuff;
1022  Fw::SerializeStatus _stat = _tlmBuff.serializeFrom(arg);
1023  FW_ASSERT(
1024  _stat == Fw::FW_SERIALIZE_OK,
1025  static_cast<FwAssertArgType>(_stat)
1026  );
1027 
1028  FwChanIdType _id;
1029 
1030  _id = this->getIdBase() + CHANNELID_SPI_BYTES;
1031 
1032  this->m_Tlm_OutputPort[0].invoke(
1033  _id,
1034  _tlmTime,
1035  _tlmBuff
1036  );
1037  }
1038  }
1039 
1040  // ----------------------------------------------------------------------
1041  // Time
1042  // ----------------------------------------------------------------------
1043 
1045  getTime() const
1046  {
1047  if (this->m_Time_OutputPort[0].isConnected()) {
1048  Fw::Time _time;
1049  this->m_Time_OutputPort[0].invoke(_time);
1050  return _time;
1051  }
1052  else {
1053  return Fw::Time(TimeBase::TB_NONE, 0, 0);
1054  }
1055  }
1056 
1057  // ----------------------------------------------------------------------
1058  // Calls for messages received on typed input ports
1059  // ----------------------------------------------------------------------
1060 
1061  void LinuxSpiDriverComponentBase ::
1062  m_p_SpiReadWrite_in(
1063  Fw::PassiveComponentBase* callComp,
1064  FwIndexType portNum,
1065  Fw::Buffer& writeBuffer,
1066  Fw::Buffer& readBuffer
1067  )
1068  {
1069  FW_ASSERT(callComp);
1070  LinuxSpiDriverComponentBase* compPtr = static_cast<LinuxSpiDriverComponentBase*>(callComp);
1071  compPtr->SpiReadWrite_handlerBase(
1072  portNum,
1073  writeBuffer,
1074  readBuffer
1075  );
1076  }
1077 
1078 }
void SpiReadWrite_handlerBase(FwIndexType portNum, Fw::Buffer &writeBuffer, Fw::Buffer &readBuffer)
Handler base-class function for input port SpiReadWrite.
Serialization/Deserialization operation was successful.
void addCallPort(InputTimePort *callPort)
Register an input port.
Definition: TimePortAc.cpp:134
SerializeStatus serializeFrom(U8 val, Endianness mode=Endianness::BIG) override
Serialize an 8-bit unsigned integer value.
void log_WARNING_HI_SPI_ConfigError(I32 device, I32 select, I32 error) const
PlatformSizeType FwSizeType
I32 FwEnumStoreType
virtual void SpiReadWrite_handler(FwIndexType portNum, Fw::Buffer &writeBuffer, Fw::Buffer &readBuffer)=0
Handler for input port SpiReadWrite.
static constexpr FwIndexType getNum_Time_OutputPorts()
void log_WARNING_HI_SPI_WriteError(I32 device, I32 select, I32 error)
virtual const CHAR * toChar() const =0
Convert to a C-style char*.
const Time ZERO_TIME
Definition: Time.cpp:5
void log_WARNING_LO_SPI_ConfigMismatch(I32 device, I32 select, const Fw::StringBase &parameter, U32 write_value, U32 read_value) const
void init()
Initialization function.
Definition: TlmPortAc.cpp:144
No time base has been established (Required)
virtual ~LinuxSpiDriverComponentBase()
Destroy LinuxSpiDriverComponentBase object.
void set_Time_OutputPort(FwIndexType portNum, Fw::InputTimePort *port)
Connect port to Time[portNum].
void addCallPort(InputTlmPort *callPort)
Register an input port.
Definition: TlmPortAc.cpp:150
void init()
Object initializer.
Definition: ObjBase.cpp:24
static constexpr FwIndexType getNum_Tlm_OutputPorts()
SerializeStatus
forward declaration for string
bool isConnected_Tlm_OutputPort(FwIndexType portNum)
void log_WARNING_HI_SPI_WriteError_ThrottleClear()
Reset throttle value for SPI_WriteError.
FwIdType FwEventIdType
The type of an event identifier.
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
void tlmWrite_SPI_Bytes(FwSizeType arg, Fw::Time _tlmTime=Fw::Time()) const
Drv::InputSpiReadWritePort * get_SpiReadWrite_InputPort(FwIndexType portNum)
Auto-generated base for LinuxSpiDriver component.
#define FW_OBJECT_NAMES
Indicates whether or not object names are stored (more memory, can be used for tracking objects) ...
Definition: FpConfig.h:26
void init()
Initialization function.
Definition: TimePortAc.cpp:128
bool isConnected_Time_OutputPort(FwIndexType portNum)
#define FW_MIN(a, b)
MIN macro.
Definition: BasicTypes.h:92
A less serious but recoverable event.
LinuxSpiDriverComponentBase(const char *compName="")
Construct LinuxSpiDriverComponentBase object.
void invoke(Fw::Time &time) const
Invoke a port interface.
Definition: TimePortAc.cpp:147
const char * toChar() const
Convert to a C-style char*.
Definition: ObjectName.hpp:50
FwIdType FwChanIdType
The type of a telemetry channel identifier.
void log_ACTIVITY_HI_SPI_PortOpened(I32 device, I32 select) const
A serious but recoverable event.
void invoke(FwChanIdType id, Fw::Time &timeTag, Fw::TlmBuffer &val) const
Invoke a port interface.
Definition: TlmPortAc.cpp:163
bool isConnected() const
Definition: PortBase.cpp:38
static constexpr FwIndexType getNum_SpiReadWrite_InputPorts()
void set_Log_OutputPort(FwIndexType portNum, Fw::InputLogPort *port)
Connect port to Log[portNum].
#define PRI_FwIndexType
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:39
void init()
Initialization function.
Definition: LogPortAc.cpp:151
void log_WARNING_HI_SPI_OpenError(I32 device, I32 select, I32 error) const
void setPortNum(FwIndexType portNum)
static constexpr FwIndexType getNum_Log_OutputPorts()
void set_Tlm_OutputPort(FwIndexType portNum, Fw::InputTlmPort *port)
Connect port to Tlm[portNum].
Important informational events.
void invoke(FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity &severity, Fw::LogBuffer &args) const
Invoke a port interface.
Definition: LogPortAc.cpp:170
void init()
Initialization function.
bool isConnected_Log_OutputPort(FwIndexType portNum)
PlatformIndexType FwIndexType
Input SpiReadWrite port.
void addCallPort(InputLogPort *callPort)
Register an input port.
Definition: LogPortAc.cpp:157
Implementation of malloc based allocator.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
SerializeStatus serializeTo(SerialBufferBase &buffer, Endianness mode=Endianness::BIG) const override
Serialize the contents of this object to a buffer.