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 #if !FW_DIRECT_PORT_CALLS
27  // Connect input port SpiReadWrite
28  for (
29  FwIndexType port = 0;
30  port < static_cast<FwIndexType>(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  Fw::ObjectName portName;
42  portName.format(
43  "%s_SpiReadWrite_InputPort[%" PRI_FwIndexType "]",
44  this->m_objName.toChar(),
45  port
46  );
47  this->m_SpiReadWrite_InputPort[port].setObjName(portName.toChar());
48 #endif
49  }
50 #endif
51 
52 #if !FW_DIRECT_PORT_CALLS
53  // Connect input port SpiWriteRead
54  for (
55  FwIndexType port = 0;
56  port < static_cast<FwIndexType>(this->getNum_SpiWriteRead_InputPorts());
57  port++
58  ) {
59  this->m_SpiWriteRead_InputPort[port].init();
60  this->m_SpiWriteRead_InputPort[port].addCallComp(
61  this,
62  m_p_SpiWriteRead_in
63  );
64  this->m_SpiWriteRead_InputPort[port].setPortNum(port);
65 
66 #if FW_OBJECT_NAMES == 1
67  Fw::ObjectName portName;
68  portName.format(
69  "%s_SpiWriteRead_InputPort[%" PRI_FwIndexType "]",
70  this->m_objName.toChar(),
71  port
72  );
73  this->m_SpiWriteRead_InputPort[port].setObjName(portName.toChar());
74 #endif
75  }
76 #endif
77 
78 #if !FW_DIRECT_PORT_CALLS
79  // Connect output port Log
80  for (
81  FwIndexType port = 0;
82  port < static_cast<FwIndexType>(this->getNum_Log_OutputPorts());
83  port++
84  ) {
85  this->m_Log_OutputPort[port].init();
86 
87 #if FW_OBJECT_NAMES == 1
88  Fw::ObjectName portName;
89  portName.format(
90  "%s_Log_OutputPort[%" PRI_FwIndexType "]",
91  this->m_objName.toChar(),
92  port
93  );
94  this->m_Log_OutputPort[port].setObjName(portName.toChar());
95 #endif
96  }
97 #endif
98 
99 #if !FW_DIRECT_PORT_CALLS && FW_ENABLE_TEXT_LOGGING
100  // Connect output port LogText
101  for (
102  FwIndexType port = 0;
103  port < static_cast<FwIndexType>(this->getNum_LogText_OutputPorts());
104  port++
105  ) {
106  this->m_LogText_OutputPort[port].init();
107 
108 #if FW_OBJECT_NAMES == 1
109  Fw::ObjectName portName;
110  portName.format(
111  "%s_LogText_OutputPort[%" PRI_FwIndexType "]",
112  this->m_objName.toChar(),
113  port
114  );
115  this->m_LogText_OutputPort[port].setObjName(portName.toChar());
116 #endif
117  }
118 #endif
119 
120 #if !FW_DIRECT_PORT_CALLS
121  // Connect output port Time
122  for (
123  FwIndexType port = 0;
124  port < static_cast<FwIndexType>(this->getNum_Time_OutputPorts());
125  port++
126  ) {
127  this->m_Time_OutputPort[port].init();
128 
129 #if FW_OBJECT_NAMES == 1
130  Fw::ObjectName portName;
131  portName.format(
132  "%s_Time_OutputPort[%" PRI_FwIndexType "]",
133  this->m_objName.toChar(),
134  port
135  );
136  this->m_Time_OutputPort[port].setObjName(portName.toChar());
137 #endif
138  }
139 #endif
140 
141 #if !FW_DIRECT_PORT_CALLS
142  // Connect output port Tlm
143  for (
144  FwIndexType port = 0;
145  port < static_cast<FwIndexType>(this->getNum_Tlm_OutputPorts());
146  port++
147  ) {
148  this->m_Tlm_OutputPort[port].init();
149 
150 #if FW_OBJECT_NAMES == 1
151  Fw::ObjectName portName;
152  portName.format(
153  "%s_Tlm_OutputPort[%" PRI_FwIndexType "]",
154  this->m_objName.toChar(),
155  port
156  );
157  this->m_Tlm_OutputPort[port].setObjName(portName.toChar());
158 #endif
159  }
160 #endif
161  }
162 
163 #if !FW_DIRECT_PORT_CALLS
164 
165  // ----------------------------------------------------------------------
166  // Getters for typed input ports
167  // ----------------------------------------------------------------------
168 
171  {
172  FW_ASSERT(
173  (0 <= portNum) && (portNum < this->getNum_SpiReadWrite_InputPorts()),
174  static_cast<FwAssertArgType>(portNum)
175  );
176 
177  return &this->m_SpiReadWrite_InputPort[portNum];
178  }
179 
182  {
183  FW_ASSERT(
184  (0 <= portNum) && (portNum < this->getNum_SpiWriteRead_InputPorts()),
185  static_cast<FwAssertArgType>(portNum)
186  );
187 
188  return &this->m_SpiWriteRead_InputPort[portNum];
189  }
190 
191 #endif
192 
193 #if !FW_DIRECT_PORT_CALLS
194 
195  // ----------------------------------------------------------------------
196  // Connect input ports to special output ports
197  // ----------------------------------------------------------------------
198 
201  FwIndexType portNum,
202  Fw::InputLogPort* port
203  )
204  {
205  FW_ASSERT(
206  (0 <= portNum) && (portNum < this->getNum_Log_OutputPorts()),
207  static_cast<FwAssertArgType>(portNum)
208  );
209 
210  this->m_Log_OutputPort[portNum].addCallPort(port);
211  }
212 
213 #if FW_ENABLE_TEXT_LOGGING == 1
214 
215  void LinuxSpiDriverComponentBase ::
216  set_LogText_OutputPort(
217  FwIndexType portNum,
219  )
220  {
221  FW_ASSERT(
222  (0 <= portNum) && (portNum < this->getNum_LogText_OutputPorts()),
223  static_cast<FwAssertArgType>(portNum)
224  );
225 
226  this->m_LogText_OutputPort[portNum].addCallPort(port);
227  }
228 
229 #endif
230 
233  FwIndexType portNum,
234  Fw::InputTimePort* port
235  )
236  {
237  FW_ASSERT(
238  (0 <= portNum) && (portNum < this->getNum_Time_OutputPorts()),
239  static_cast<FwAssertArgType>(portNum)
240  );
241 
242  this->m_Time_OutputPort[portNum].addCallPort(port);
243  }
244 
247  FwIndexType portNum,
248  Fw::InputTlmPort* port
249  )
250  {
251  FW_ASSERT(
252  (0 <= portNum) && (portNum < this->getNum_Tlm_OutputPorts()),
253  static_cast<FwAssertArgType>(portNum)
254  );
255 
256  this->m_Tlm_OutputPort[portNum].addCallPort(port);
257  }
258 
259 #endif
260 
261 #if !FW_DIRECT_PORT_CALLS && FW_PORT_SERIALIZATION
262 
263  // ----------------------------------------------------------------------
264  // Connect serial input ports to special output ports
265  // ----------------------------------------------------------------------
266 
269  FwIndexType portNum,
270  Fw::InputSerializePort* port
271  )
272  {
273  FW_ASSERT(
274  (0 <= portNum) && (portNum < this->getNum_Log_OutputPorts()),
275  static_cast<FwAssertArgType>(portNum)
276  );
277 
278  this->m_Log_OutputPort[portNum].registerSerialPort(port);
279  }
280 
281 #if FW_ENABLE_TEXT_LOGGING == 1
282 
283  void LinuxSpiDriverComponentBase ::
284  set_LogText_OutputPort(
285  FwIndexType portNum,
286  Fw::InputSerializePort* port
287  )
288  {
289  FW_ASSERT(
290  (0 <= portNum) && (portNum < this->getNum_LogText_OutputPorts()),
291  static_cast<FwAssertArgType>(portNum)
292  );
293 
294  this->m_LogText_OutputPort[portNum].registerSerialPort(port);
295  }
296 
297 #endif
298 
301  FwIndexType portNum,
302  Fw::InputSerializePort* port
303  )
304  {
305  FW_ASSERT(
306  (0 <= portNum) && (portNum < this->getNum_Time_OutputPorts()),
307  static_cast<FwAssertArgType>(portNum)
308  );
309 
310  this->m_Time_OutputPort[portNum].registerSerialPort(port);
311  }
312 
315  FwIndexType portNum,
316  Fw::InputSerializePort* port
317  )
318  {
319  FW_ASSERT(
320  (0 <= portNum) && (portNum < this->getNum_Tlm_OutputPorts()),
321  static_cast<FwAssertArgType>(portNum)
322  );
323 
324  this->m_Tlm_OutputPort[portNum].registerSerialPort(port);
325  }
326 
327 #endif
328 
329  // ----------------------------------------------------------------------
330  // Component construction and destruction
331  // ----------------------------------------------------------------------
332 
334  LinuxSpiDriverComponentBase(const char* compName) :
335  Fw::PassiveComponentBase(compName)
336  {
337  this->m_SPI_WriteErrorThrottle = 0;
338  }
339 
342  {
343 
344  }
345 
346 #if !FW_DIRECT_PORT_CALLS
347 
348  // ----------------------------------------------------------------------
349  // Connection status queries for special output ports
350  // ----------------------------------------------------------------------
351 
354  {
355  FW_ASSERT(
356  (0 <= portNum) && (portNum < this->getNum_Log_OutputPorts()),
357  static_cast<FwAssertArgType>(portNum)
358  );
359 
360  return this->m_Log_OutputPort[portNum].isConnected();
361  }
362 
363 #if FW_ENABLE_TEXT_LOGGING == 1
364 
365  bool LinuxSpiDriverComponentBase ::
366  isConnected_LogText_OutputPort(FwIndexType portNum) const
367  {
368  FW_ASSERT(
369  (0 <= portNum) && (portNum < this->getNum_LogText_OutputPorts()),
370  static_cast<FwAssertArgType>(portNum)
371  );
372 
373  return this->m_LogText_OutputPort[portNum].isConnected();
374  }
375 
376 #endif
377 
380  {
381  FW_ASSERT(
382  (0 <= portNum) && (portNum < this->getNum_Time_OutputPorts()),
383  static_cast<FwAssertArgType>(portNum)
384  );
385 
386  return this->m_Time_OutputPort[portNum].isConnected();
387  }
388 
391  {
392  FW_ASSERT(
393  (0 <= portNum) && (portNum < this->getNum_Tlm_OutputPorts()),
394  static_cast<FwAssertArgType>(portNum)
395  );
396 
397  return this->m_Tlm_OutputPort[portNum].isConnected();
398  }
399 
400 #endif
401 
402  // ----------------------------------------------------------------------
403  // Port handler base-class functions for typed input ports
404  //
405  // Call these functions directly to bypass the corresponding ports
406  // ----------------------------------------------------------------------
407 
410  FwIndexType portNum,
411  Fw::Buffer& writeBuffer,
412  Fw::Buffer& readBuffer
413  )
414  {
415  // Make sure port number is valid
416  FW_ASSERT(
417  (0 <= portNum) && (portNum < this->getNum_SpiReadWrite_InputPorts()),
418  static_cast<FwAssertArgType>(portNum)
419  );
420 
421  // Call handler function
422  this->SpiReadWrite_handler(
423  portNum,
424  writeBuffer,
425  readBuffer
426  );
427  }
428 
431  FwIndexType portNum,
432  Fw::Buffer& writeBuffer,
433  Fw::Buffer& readBuffer
434  )
435  {
436  // Make sure port number is valid
437  FW_ASSERT(
438  (0 <= portNum) && (portNum < this->getNum_SpiWriteRead_InputPorts()),
439  static_cast<FwAssertArgType>(portNum)
440  );
441 
442  Drv::SpiStatus retVal;
443 
444  // Lock guard mutex before calling
445  this->lock();
446 
447  // Call handler function
448  retVal = this->SpiWriteRead_handler(
449  portNum,
450  writeBuffer,
451  readBuffer
452  );
453 
454  // Unlock guard mutex
455  this->unLock();
456 
457  return retVal;
458  }
459 
460  // ----------------------------------------------------------------------
461  // Event logging functions
462  // ----------------------------------------------------------------------
463 
466  I32 device,
467  I32 select,
468  I32 error
469  ) const
470  {
471  // Get the time
472  Fw::Time _logTime;
473  if (this->isConnected_Time_OutputPort(0)) {
474  this->Time_out(0, _logTime);
475  }
476 
477  const FwEventIdType _id = this->getIdBase() + EVENTID_SPI_OPENERROR;
478 
479  // Emit the event on the log port
480  if (this->isConnected_Log_OutputPort(0)) {
481  Fw::LogBuffer _logBuff;
483 
484 #if FW_AMPCS_COMPATIBLE
485  // Serialize the number of arguments
486  _status = _logBuff.serializeFrom(static_cast<U8>(3));
487  FW_ASSERT(
488  _status == Fw::FW_SERIALIZE_OK,
489  static_cast<FwAssertArgType>(_status)
490  );
491 #endif
492 
493 #if FW_AMPCS_COMPATIBLE
494  // Serialize the argument size
495  _status = _logBuff.serializeFrom(
496  static_cast<U8>(sizeof(I32))
497  );
498  FW_ASSERT(
499  _status == Fw::FW_SERIALIZE_OK,
500  static_cast<FwAssertArgType>(_status)
501  );
502 #endif
503  _status = _logBuff.serializeFrom(device);
504  FW_ASSERT(
505  _status == Fw::FW_SERIALIZE_OK,
506  static_cast<FwAssertArgType>(_status)
507  );
508 
509 #if FW_AMPCS_COMPATIBLE
510  // Serialize the argument size
511  _status = _logBuff.serializeFrom(
512  static_cast<U8>(sizeof(I32))
513  );
514  FW_ASSERT(
515  _status == Fw::FW_SERIALIZE_OK,
516  static_cast<FwAssertArgType>(_status)
517  );
518 #endif
519  _status = _logBuff.serializeFrom(select);
520  FW_ASSERT(
521  _status == Fw::FW_SERIALIZE_OK,
522  static_cast<FwAssertArgType>(_status)
523  );
524 
525 #if FW_AMPCS_COMPATIBLE
526  // Serialize the argument size
527  _status = _logBuff.serializeFrom(
528  static_cast<U8>(sizeof(I32))
529  );
530  FW_ASSERT(
531  _status == Fw::FW_SERIALIZE_OK,
532  static_cast<FwAssertArgType>(_status)
533  );
534 #endif
535  _status = _logBuff.serializeFrom(error);
536  FW_ASSERT(
537  _status == Fw::FW_SERIALIZE_OK,
538  static_cast<FwAssertArgType>(_status)
539  );
540 
541  this->Log_out(
542  0,
543  _id,
544  _logTime,
546  _logBuff
547  );
548  }
549 
550  // Emit the event on the text log port
551 #if FW_ENABLE_TEXT_LOGGING
552  if (this->isConnected_LogText_OutputPort(0)) {
553 #if FW_OBJECT_NAMES == 1
554  const char* _formatString =
555  "(%s) %s: Error opening SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
556 #else
557  const char* _formatString =
558  "%s: Error opening SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
559 #endif
560 
561  Fw::TextLogString _logString;
562  _logString.format(
563  _formatString,
564 #if FW_OBJECT_NAMES == 1
565  this->m_objName.toChar(),
566 #endif
567  "SPI_OpenError ",
568  device,
569  select,
570  error
571  );
572 
573  this->LogText_out(
574  0,
575  _id,
576  _logTime,
578  _logString
579  );
580  }
581 #endif
582  }
583 
586  I32 device,
587  I32 select,
588  I32 error
589  ) const
590  {
591  // Get the time
592  Fw::Time _logTime;
593  if (this->isConnected_Time_OutputPort(0)) {
594  this->Time_out(0, _logTime);
595  }
596 
597  const FwEventIdType _id = this->getIdBase() + EVENTID_SPI_CONFIGERROR;
598 
599  // Emit the event on the log port
600  if (this->isConnected_Log_OutputPort(0)) {
601  Fw::LogBuffer _logBuff;
603 
604 #if FW_AMPCS_COMPATIBLE
605  // Serialize the number of arguments
606  _status = _logBuff.serializeFrom(static_cast<U8>(3));
607  FW_ASSERT(
608  _status == Fw::FW_SERIALIZE_OK,
609  static_cast<FwAssertArgType>(_status)
610  );
611 #endif
612 
613 #if FW_AMPCS_COMPATIBLE
614  // Serialize the argument size
615  _status = _logBuff.serializeFrom(
616  static_cast<U8>(sizeof(I32))
617  );
618  FW_ASSERT(
619  _status == Fw::FW_SERIALIZE_OK,
620  static_cast<FwAssertArgType>(_status)
621  );
622 #endif
623  _status = _logBuff.serializeFrom(device);
624  FW_ASSERT(
625  _status == Fw::FW_SERIALIZE_OK,
626  static_cast<FwAssertArgType>(_status)
627  );
628 
629 #if FW_AMPCS_COMPATIBLE
630  // Serialize the argument size
631  _status = _logBuff.serializeFrom(
632  static_cast<U8>(sizeof(I32))
633  );
634  FW_ASSERT(
635  _status == Fw::FW_SERIALIZE_OK,
636  static_cast<FwAssertArgType>(_status)
637  );
638 #endif
639  _status = _logBuff.serializeFrom(select);
640  FW_ASSERT(
641  _status == Fw::FW_SERIALIZE_OK,
642  static_cast<FwAssertArgType>(_status)
643  );
644 
645 #if FW_AMPCS_COMPATIBLE
646  // Serialize the argument size
647  _status = _logBuff.serializeFrom(
648  static_cast<U8>(sizeof(I32))
649  );
650  FW_ASSERT(
651  _status == Fw::FW_SERIALIZE_OK,
652  static_cast<FwAssertArgType>(_status)
653  );
654 #endif
655  _status = _logBuff.serializeFrom(error);
656  FW_ASSERT(
657  _status == Fw::FW_SERIALIZE_OK,
658  static_cast<FwAssertArgType>(_status)
659  );
660 
661  this->Log_out(
662  0,
663  _id,
664  _logTime,
666  _logBuff
667  );
668  }
669 
670  // Emit the event on the text log port
671 #if FW_ENABLE_TEXT_LOGGING
672  if (this->isConnected_LogText_OutputPort(0)) {
673 #if FW_OBJECT_NAMES == 1
674  const char* _formatString =
675  "(%s) %s: Error configuring SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
676 #else
677  const char* _formatString =
678  "%s: Error configuring SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
679 #endif
680 
681  Fw::TextLogString _logString;
682  _logString.format(
683  _formatString,
684 #if FW_OBJECT_NAMES == 1
685  this->m_objName.toChar(),
686 #endif
687  "SPI_ConfigError ",
688  device,
689  select,
690  error
691  );
692 
693  this->LogText_out(
694  0,
695  _id,
696  _logTime,
698  _logString
699  );
700  }
701 #endif
702  }
703 
706  I32 device,
707  I32 select,
708  I32 error
709  )
710  {
711  // Check throttle value
712  if (this->m_SPI_WriteErrorThrottle >= EVENTID_SPI_WRITEERROR_THROTTLE) {
713  return;
714  }
715  else {
716  this->m_SPI_WriteErrorThrottle++;
717  }
718 
719  // Get the time
720  Fw::Time _logTime;
721  if (this->isConnected_Time_OutputPort(0)) {
722  this->Time_out(0, _logTime);
723  }
724 
725  const FwEventIdType _id = this->getIdBase() + EVENTID_SPI_WRITEERROR;
726 
727  // Emit the event on the log port
728  if (this->isConnected_Log_OutputPort(0)) {
729  Fw::LogBuffer _logBuff;
731 
732 #if FW_AMPCS_COMPATIBLE
733  // Serialize the number of arguments
734  _status = _logBuff.serializeFrom(static_cast<U8>(3));
735  FW_ASSERT(
736  _status == Fw::FW_SERIALIZE_OK,
737  static_cast<FwAssertArgType>(_status)
738  );
739 #endif
740 
741 #if FW_AMPCS_COMPATIBLE
742  // Serialize the argument size
743  _status = _logBuff.serializeFrom(
744  static_cast<U8>(sizeof(I32))
745  );
746  FW_ASSERT(
747  _status == Fw::FW_SERIALIZE_OK,
748  static_cast<FwAssertArgType>(_status)
749  );
750 #endif
751  _status = _logBuff.serializeFrom(device);
752  FW_ASSERT(
753  _status == Fw::FW_SERIALIZE_OK,
754  static_cast<FwAssertArgType>(_status)
755  );
756 
757 #if FW_AMPCS_COMPATIBLE
758  // Serialize the argument size
759  _status = _logBuff.serializeFrom(
760  static_cast<U8>(sizeof(I32))
761  );
762  FW_ASSERT(
763  _status == Fw::FW_SERIALIZE_OK,
764  static_cast<FwAssertArgType>(_status)
765  );
766 #endif
767  _status = _logBuff.serializeFrom(select);
768  FW_ASSERT(
769  _status == Fw::FW_SERIALIZE_OK,
770  static_cast<FwAssertArgType>(_status)
771  );
772 
773 #if FW_AMPCS_COMPATIBLE
774  // Serialize the argument size
775  _status = _logBuff.serializeFrom(
776  static_cast<U8>(sizeof(I32))
777  );
778  FW_ASSERT(
779  _status == Fw::FW_SERIALIZE_OK,
780  static_cast<FwAssertArgType>(_status)
781  );
782 #endif
783  _status = _logBuff.serializeFrom(error);
784  FW_ASSERT(
785  _status == Fw::FW_SERIALIZE_OK,
786  static_cast<FwAssertArgType>(_status)
787  );
788 
789  this->Log_out(
790  0,
791  _id,
792  _logTime,
794  _logBuff
795  );
796  }
797 
798  // Emit the event on the text log port
799 #if FW_ENABLE_TEXT_LOGGING
800  if (this->isConnected_LogText_OutputPort(0)) {
801 #if FW_OBJECT_NAMES == 1
802  const char* _formatString =
803  "(%s) %s: Error writing/reading SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
804 #else
805  const char* _formatString =
806  "%s: Error writing/reading SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
807 #endif
808 
809  Fw::TextLogString _logString;
810  _logString.format(
811  _formatString,
812 #if FW_OBJECT_NAMES == 1
813  this->m_objName.toChar(),
814 #endif
815  "SPI_WriteError ",
816  device,
817  select,
818  error
819  );
820 
821  this->LogText_out(
822  0,
823  _id,
824  _logTime,
826  _logString
827  );
828  }
829 #endif
830  }
831 
834  I32 device,
835  I32 select,
836  const Fw::StringBase& parameter,
837  U32 write_value,
838  U32 read_value
839  ) const
840  {
841  // Get the time
842  Fw::Time _logTime;
843  if (this->isConnected_Time_OutputPort(0)) {
844  this->Time_out(0, _logTime);
845  }
846 
847  const FwEventIdType _id = this->getIdBase() + EVENTID_SPI_CONFIGMISMATCH;
848 
849  // Emit the event on the log port
850  if (this->isConnected_Log_OutputPort(0)) {
851  Fw::LogBuffer _logBuff;
853 
854 #if FW_AMPCS_COMPATIBLE
855  // Serialize the number of arguments
856  _status = _logBuff.serializeFrom(static_cast<U8>(5));
857  FW_ASSERT(
858  _status == Fw::FW_SERIALIZE_OK,
859  static_cast<FwAssertArgType>(_status)
860  );
861 #endif
862 
863 #if FW_AMPCS_COMPATIBLE
864  // Serialize the argument size
865  _status = _logBuff.serializeFrom(
866  static_cast<U8>(sizeof(I32))
867  );
868  FW_ASSERT(
869  _status == Fw::FW_SERIALIZE_OK,
870  static_cast<FwAssertArgType>(_status)
871  );
872 #endif
873  _status = _logBuff.serializeFrom(device);
874  FW_ASSERT(
875  _status == Fw::FW_SERIALIZE_OK,
876  static_cast<FwAssertArgType>(_status)
877  );
878 
879 #if FW_AMPCS_COMPATIBLE
880  // Serialize the argument size
881  _status = _logBuff.serializeFrom(
882  static_cast<U8>(sizeof(I32))
883  );
884  FW_ASSERT(
885  _status == Fw::FW_SERIALIZE_OK,
886  static_cast<FwAssertArgType>(_status)
887  );
888 #endif
889  _status = _logBuff.serializeFrom(select);
890  FW_ASSERT(
891  _status == Fw::FW_SERIALIZE_OK,
892  static_cast<FwAssertArgType>(_status)
893  );
894 
895  _status = parameter.serializeTo(
896  _logBuff,
897  FW_MIN(static_cast<FwSizeType>(FW_LOG_STRING_MAX_SIZE), static_cast<FwSizeType>(FW_FIXED_LENGTH_STRING_SIZE))
898  );
899  FW_ASSERT(
900  _status == Fw::FW_SERIALIZE_OK,
901  static_cast<FwAssertArgType>(_status)
902  );
903 
904 #if FW_AMPCS_COMPATIBLE
905  // Serialize the argument size
906  _status = _logBuff.serializeFrom(
907  static_cast<U8>(sizeof(U32))
908  );
909  FW_ASSERT(
910  _status == Fw::FW_SERIALIZE_OK,
911  static_cast<FwAssertArgType>(_status)
912  );
913 #endif
914  _status = _logBuff.serializeFrom(write_value);
915  FW_ASSERT(
916  _status == Fw::FW_SERIALIZE_OK,
917  static_cast<FwAssertArgType>(_status)
918  );
919 
920 #if FW_AMPCS_COMPATIBLE
921  // Serialize the argument size
922  _status = _logBuff.serializeFrom(
923  static_cast<U8>(sizeof(U32))
924  );
925  FW_ASSERT(
926  _status == Fw::FW_SERIALIZE_OK,
927  static_cast<FwAssertArgType>(_status)
928  );
929 #endif
930  _status = _logBuff.serializeFrom(read_value);
931  FW_ASSERT(
932  _status == Fw::FW_SERIALIZE_OK,
933  static_cast<FwAssertArgType>(_status)
934  );
935 
936  this->Log_out(
937  0,
938  _id,
939  _logTime,
941  _logBuff
942  );
943  }
944 
945  // Emit the event on the text log port
946 #if FW_ENABLE_TEXT_LOGGING
947  if (this->isConnected_LogText_OutputPort(0)) {
948 #if FW_OBJECT_NAMES == 1
949  const char* _formatString =
950  "(%s) %s: SPI device %" PRIi32 ".%" PRIi32 " configuration mismatch for %s: wrote %" PRIu32 ", read %" PRIu32 "";
951 #else
952  const char* _formatString =
953  "%s: SPI device %" PRIi32 ".%" PRIi32 " configuration mismatch for %s: wrote %" PRIu32 ", read %" PRIu32 "";
954 #endif
955 
956  Fw::TextLogString _logString;
957  _logString.format(
958  _formatString,
959 #if FW_OBJECT_NAMES == 1
960  this->m_objName.toChar(),
961 #endif
962  "SPI_ConfigMismatch ",
963  device,
964  select,
965  parameter.toChar(),
966  write_value,
967  read_value
968  );
969 
970  this->LogText_out(
971  0,
972  _id,
973  _logTime,
975  _logString
976  );
977  }
978 #endif
979  }
980 
983  I32 device,
984  I32 select
985  ) const
986  {
987  // Get the time
988  Fw::Time _logTime;
989  if (this->isConnected_Time_OutputPort(0)) {
990  this->Time_out(0, _logTime);
991  }
992 
993  const FwEventIdType _id = this->getIdBase() + EVENTID_SPI_PORTOPENED;
994 
995  // Emit the event on the log port
996  if (this->isConnected_Log_OutputPort(0)) {
997  Fw::LogBuffer _logBuff;
999 
1000 #if FW_AMPCS_COMPATIBLE
1001  // Serialize the number of arguments
1002  _status = _logBuff.serializeFrom(static_cast<U8>(2));
1003  FW_ASSERT(
1004  _status == Fw::FW_SERIALIZE_OK,
1005  static_cast<FwAssertArgType>(_status)
1006  );
1007 #endif
1008 
1009 #if FW_AMPCS_COMPATIBLE
1010  // Serialize the argument size
1011  _status = _logBuff.serializeFrom(
1012  static_cast<U8>(sizeof(I32))
1013  );
1014  FW_ASSERT(
1015  _status == Fw::FW_SERIALIZE_OK,
1016  static_cast<FwAssertArgType>(_status)
1017  );
1018 #endif
1019  _status = _logBuff.serializeFrom(device);
1020  FW_ASSERT(
1021  _status == Fw::FW_SERIALIZE_OK,
1022  static_cast<FwAssertArgType>(_status)
1023  );
1024 
1025 #if FW_AMPCS_COMPATIBLE
1026  // Serialize the argument size
1027  _status = _logBuff.serializeFrom(
1028  static_cast<U8>(sizeof(I32))
1029  );
1030  FW_ASSERT(
1031  _status == Fw::FW_SERIALIZE_OK,
1032  static_cast<FwAssertArgType>(_status)
1033  );
1034 #endif
1035  _status = _logBuff.serializeFrom(select);
1036  FW_ASSERT(
1037  _status == Fw::FW_SERIALIZE_OK,
1038  static_cast<FwAssertArgType>(_status)
1039  );
1040 
1041  this->Log_out(
1042  0,
1043  _id,
1044  _logTime,
1046  _logBuff
1047  );
1048  }
1049 
1050  // Emit the event on the text log port
1051 #if FW_ENABLE_TEXT_LOGGING
1052  if (this->isConnected_LogText_OutputPort(0)) {
1053 #if FW_OBJECT_NAMES == 1
1054  const char* _formatString =
1055  "(%s) %s: SPI Device %" PRIi32 ".%" PRIi32 " configured";
1056 #else
1057  const char* _formatString =
1058  "%s: SPI Device %" PRIi32 ".%" PRIi32 " configured";
1059 #endif
1060 
1061  Fw::TextLogString _logString;
1062  _logString.format(
1063  _formatString,
1064 #if FW_OBJECT_NAMES == 1
1065  this->m_objName.toChar(),
1066 #endif
1067  "SPI_PortOpened ",
1068  device,
1069  select
1070  );
1071 
1072  this->LogText_out(
1073  0,
1074  _id,
1075  _logTime,
1077  _logString
1078  );
1079  }
1080 #endif
1081  }
1082 
1083  // ----------------------------------------------------------------------
1084  // Event throttle reset functions
1085  // ----------------------------------------------------------------------
1086 
1089  {
1090  // Reset throttle counter
1091  this->m_SPI_WriteErrorThrottle = 0;
1092  }
1093 
1094  // ----------------------------------------------------------------------
1095  // Telemetry serialized write
1096  // ----------------------------------------------------------------------
1097 
1100  FwChanIdType id,
1101  Fw::TlmBuffer& _tlmBuff,
1102  Fw::Time _tlmTime
1103  ) const
1104  {
1105  if (this->isConnected_Tlm_OutputPort(0)) {
1106  if (
1107  this->isConnected_Time_OutputPort(0) &&
1108  (_tlmTime == Fw::ZERO_TIME)
1109  ) {
1110  this->Time_out(0, _tlmTime);
1111  }
1112 
1113  FwChanIdType _id;
1114  _id = this->getIdBase() + id;
1115 
1116  this->Tlm_out(
1117  0,
1118  _id,
1119  _tlmTime,
1120  _tlmBuff
1121  );
1122  }
1123  }
1124 
1125  // ----------------------------------------------------------------------
1126  // Telemetry write functions
1127  // ----------------------------------------------------------------------
1128 
1131  FwSizeType arg,
1132  Fw::Time _tlmTime
1133  ) const
1134  {
1135  if (this->isConnected_Tlm_OutputPort(0)) {
1136  Fw::TlmBuffer _tlmBuff;
1137  Fw::SerializeStatus _stat = _tlmBuff.serializeFrom(arg);
1138  FW_ASSERT(
1139  _stat == Fw::FW_SERIALIZE_OK,
1140  static_cast<FwAssertArgType>(_stat)
1141  );
1142 
1143  this->tlmWrite(
1145  _tlmBuff,
1146  _tlmTime
1147  );
1148  }
1149  }
1150 
1151  // ----------------------------------------------------------------------
1152  // Time
1153  // ----------------------------------------------------------------------
1154 
1156  getTime() const
1157  {
1158  if (this->isConnected_Time_OutputPort(0)) {
1159  Fw::Time _time;
1160  this->Time_out(0, _time);
1161  return _time;
1162  }
1163  else {
1164  return Fw::Time(TimeBase::TB_NONE, 0, 0);
1165  }
1166  }
1167 
1168  // ----------------------------------------------------------------------
1169  // Mutex operations for guarded ports
1170  //
1171  // You can override these operations to provide more sophisticated
1172  // synchronization
1173  // ----------------------------------------------------------------------
1174 
1177  {
1178  this->m_guardedPortMutex.lock();
1179  }
1180 
1183  {
1184  this->m_guardedPortMutex.unLock();
1185  }
1186 
1187  // ----------------------------------------------------------------------
1188  // Calls for messages received on typed input ports
1189  // ----------------------------------------------------------------------
1190 
1191  void LinuxSpiDriverComponentBase ::
1192  m_p_SpiReadWrite_in(
1193  Fw::PassiveComponentBase* callComp,
1194  FwIndexType portNum,
1195  Fw::Buffer& writeBuffer,
1196  Fw::Buffer& readBuffer
1197  )
1198  {
1199  FW_ASSERT(callComp);
1200  LinuxSpiDriverComponentBase* compPtr = static_cast<LinuxSpiDriverComponentBase*>(callComp);
1201  compPtr->SpiReadWrite_handlerBase(
1202  portNum,
1203  writeBuffer,
1204  readBuffer
1205  );
1206  }
1207 
1208  Drv::SpiStatus LinuxSpiDriverComponentBase ::
1209  m_p_SpiWriteRead_in(
1210  Fw::PassiveComponentBase* callComp,
1211  FwIndexType portNum,
1212  Fw::Buffer& writeBuffer,
1213  Fw::Buffer& readBuffer
1214  )
1215  {
1216  FW_ASSERT(callComp);
1217  LinuxSpiDriverComponentBase* compPtr = static_cast<LinuxSpiDriverComponentBase*>(callComp);
1218  return compPtr->SpiWriteRead_handlerBase(
1219  portNum,
1220  writeBuffer,
1221  readBuffer
1222  );
1223  }
1224 
1225 #if !FW_DIRECT_PORT_CALLS
1226 
1227  // ----------------------------------------------------------------------
1228  // Invocation functions for special output ports
1229  // ----------------------------------------------------------------------
1230 
1231  void LinuxSpiDriverComponentBase ::
1232  Log_out(
1233  FwIndexType portNum,
1234  FwEventIdType id,
1235  Fw::Time& timeTag,
1236  const Fw::LogSeverity& severity,
1237  Fw::LogBuffer& args
1238  ) const
1239  {
1240  FW_ASSERT(
1241  (0 <= portNum) && (portNum < this->getNum_Log_OutputPorts()),
1242  static_cast<FwAssertArgType>(portNum)
1243  );
1244 
1245  FW_ASSERT(
1246  this->m_Log_OutputPort[portNum].isConnected(),
1247  static_cast<FwAssertArgType>(portNum)
1248  );
1249  this->m_Log_OutputPort[portNum].invoke(
1250  id,
1251  timeTag,
1252  severity,
1253  args
1254  );
1255  }
1256 
1257 #if FW_ENABLE_TEXT_LOGGING
1258 
1259  void LinuxSpiDriverComponentBase ::
1260  LogText_out(
1261  FwIndexType portNum,
1262  FwEventIdType id,
1263  Fw::Time& timeTag,
1264  const Fw::LogSeverity& severity,
1265  Fw::TextLogString& text
1266  ) const
1267  {
1268  FW_ASSERT(
1269  (0 <= portNum) && (portNum < this->getNum_LogText_OutputPorts()),
1270  static_cast<FwAssertArgType>(portNum)
1271  );
1272 
1273  FW_ASSERT(
1274  this->m_LogText_OutputPort[portNum].isConnected(),
1275  static_cast<FwAssertArgType>(portNum)
1276  );
1277  this->m_LogText_OutputPort[portNum].invoke(
1278  id,
1279  timeTag,
1280  severity,
1281  text
1282  );
1283  }
1284 
1285 #endif
1286 
1287  void LinuxSpiDriverComponentBase ::
1288  Time_out(
1289  FwIndexType portNum,
1290  Fw::Time& time
1291  ) const
1292  {
1293  FW_ASSERT(
1294  (0 <= portNum) && (portNum < this->getNum_Time_OutputPorts()),
1295  static_cast<FwAssertArgType>(portNum)
1296  );
1297 
1298  FW_ASSERT(
1299  this->m_Time_OutputPort[portNum].isConnected(),
1300  static_cast<FwAssertArgType>(portNum)
1301  );
1302  this->m_Time_OutputPort[portNum].invoke(
1303  time
1304  );
1305  }
1306 
1307  void LinuxSpiDriverComponentBase ::
1308  Tlm_out(
1309  FwIndexType portNum,
1310  FwChanIdType id,
1311  Fw::Time& timeTag,
1312  Fw::TlmBuffer& val
1313  ) const
1314  {
1315  FW_ASSERT(
1316  (0 <= portNum) && (portNum < this->getNum_Tlm_OutputPorts()),
1317  static_cast<FwAssertArgType>(portNum)
1318  );
1319 
1320  FW_ASSERT(
1321  this->m_Tlm_OutputPort[portNum].isConnected(),
1322  static_cast<FwAssertArgType>(portNum)
1323  );
1324  this->m_Tlm_OutputPort[portNum].invoke(
1325  id,
1326  timeTag,
1327  val
1328  );
1329  }
1330 
1331 #endif
1332 
1333 }
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:157
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
static constexpr FwIndexType getNum_SpiWriteRead_InputPorts()
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()
bool isConnected_Time_OutputPort(FwIndexType portNum) const
void unLock()
unlock the mutex and assert success
Definition: Mutex.cpp:41
virtual void lock()
Lock the guarded mutex.
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:171
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
No time base has been established (Required)
virtual ~LinuxSpiDriverComponentBase()
Destroy LinuxSpiDriverComponentBase object.
virtual Drv::SpiStatus SpiWriteRead_handler(FwIndexType portNum, Fw::Buffer &writeBuffer, Fw::Buffer &readBuffer)=0
Handler for input port SpiWriteRead.
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:177
void init()
Object initializer.
Definition: ObjBase.cpp:24
static constexpr FwIndexType getNum_Tlm_OutputPorts()
SerializeStatus
forward declaration for string
void log_WARNING_HI_SPI_WriteError_ThrottleClear()
Reset throttle value for SPI_WriteError.
bool isConnected_Tlm_OutputPort(FwIndexType portNum) const
FwIdType FwEventIdType
The type of an event identifier.
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
Input SpiWriteRead port.
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:40
void init()
Initialization function.
Definition: TimePortAc.cpp:151
#define FW_MIN(a, b)
MIN macro (deprecated in C++, use std::min)
Definition: BasicTypes.h:94
A less serious but recoverable event.
LinuxSpiDriverComponentBase(const char *compName="")
Construct LinuxSpiDriverComponentBase object.
void invoke(Fw::Time &time) const
Invoke a port connection.
Definition: TimePortAc.cpp:170
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.
bool isConnected_Log_OutputPort(FwIndexType portNum) const
void invoke(FwChanIdType id, Fw::Time &timeTag, Fw::TlmBuffer &val) const
Invoke a port connection.
Definition: TlmPortAc.cpp:190
bool isConnected() const
Definition: PortBase.cpp:38
static constexpr FwIndexType getNum_SpiReadWrite_InputPorts()
Enum representing event severity.
void tlmWrite(FwChanIdType id, Fw::TlmBuffer &_tlmBuff, Fw::Time _tlmTime=Fw::Time()) const
virtual void unLock()
Unlock the guarded mutex.
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:180
void log_WARNING_HI_SPI_OpenError(I32 device, I32 select, I32 error) const
void setPortNum(FwIndexType portNum)
static constexpr FwIndexType getNum_Log_OutputPorts()
Drv::SpiStatus SpiWriteRead_handlerBase(FwIndexType portNum, Fw::Buffer &writeBuffer, Fw::Buffer &readBuffer)
Handler base-class function for input port SpiWriteRead.
Drv::InputSpiWriteReadPort * get_SpiWriteRead_InputPort(FwIndexType portNum)
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 connection.
Definition: LogPortAc.cpp:199
void init()
Initialization function.
PlatformIndexType FwIndexType
void addCallPort(InputLogPort *callPort)
Register an input port.
Definition: LogPortAc.cpp:186
Implementation of malloc based allocator.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
void init()
Initialization function.
void lock()
lock the mutex and assert success
Definition: Mutex.cpp:34
SerializeStatus serializeTo(SerialBufferBase &buffer, Endianness mode=Endianness::BIG) const override
Serialize the contents of this object to a buffer.