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 input port SpiWriteRead
51  for (
52  FwIndexType port = 0;
53  port < static_cast<FwIndexType>(this->getNum_SpiWriteRead_InputPorts());
54  port++
55  ) {
56  this->m_SpiWriteRead_InputPort[port].init();
57  this->m_SpiWriteRead_InputPort[port].addCallComp(
58  this,
59  m_p_SpiWriteRead_in
60  );
61  this->m_SpiWriteRead_InputPort[port].setPortNum(port);
62 
63 #if FW_OBJECT_NAMES == 1
64  Fw::ObjectName portName;
65  portName.format(
66  "%s_SpiWriteRead_InputPort[%" PRI_FwIndexType "]",
67  this->m_objName.toChar(),
68  port
69  );
70  this->m_SpiWriteRead_InputPort[port].setObjName(portName.toChar());
71 #endif
72  }
73 
74  // Connect output port Log
75  for (
76  FwIndexType port = 0;
77  port < static_cast<FwIndexType>(this->getNum_Log_OutputPorts());
78  port++
79  ) {
80  this->m_Log_OutputPort[port].init();
81 
82 #if FW_OBJECT_NAMES == 1
83  Fw::ObjectName portName;
84  portName.format(
85  "%s_Log_OutputPort[%" PRI_FwIndexType "]",
86  this->m_objName.toChar(),
87  port
88  );
89  this->m_Log_OutputPort[port].setObjName(portName.toChar());
90 #endif
91  }
92 
93 #if FW_ENABLE_TEXT_LOGGING == 1
94  // Connect output port LogText
95  for (
96  FwIndexType port = 0;
97  port < static_cast<FwIndexType>(this->getNum_LogText_OutputPorts());
98  port++
99  ) {
100  this->m_LogText_OutputPort[port].init();
101 
102 #if FW_OBJECT_NAMES == 1
103  Fw::ObjectName portName;
104  portName.format(
105  "%s_LogText_OutputPort[%" PRI_FwIndexType "]",
106  this->m_objName.toChar(),
107  port
108  );
109  this->m_LogText_OutputPort[port].setObjName(portName.toChar());
110 #endif
111  }
112 #endif
113 
114  // Connect output port Time
115  for (
116  FwIndexType port = 0;
117  port < static_cast<FwIndexType>(this->getNum_Time_OutputPorts());
118  port++
119  ) {
120  this->m_Time_OutputPort[port].init();
121 
122 #if FW_OBJECT_NAMES == 1
123  Fw::ObjectName portName;
124  portName.format(
125  "%s_Time_OutputPort[%" PRI_FwIndexType "]",
126  this->m_objName.toChar(),
127  port
128  );
129  this->m_Time_OutputPort[port].setObjName(portName.toChar());
130 #endif
131  }
132 
133  // Connect output port Tlm
134  for (
135  FwIndexType port = 0;
136  port < static_cast<FwIndexType>(this->getNum_Tlm_OutputPorts());
137  port++
138  ) {
139  this->m_Tlm_OutputPort[port].init();
140 
141 #if FW_OBJECT_NAMES == 1
142  Fw::ObjectName portName;
143  portName.format(
144  "%s_Tlm_OutputPort[%" PRI_FwIndexType "]",
145  this->m_objName.toChar(),
146  port
147  );
148  this->m_Tlm_OutputPort[port].setObjName(portName.toChar());
149 #endif
150  }
151  }
152 
153  // ----------------------------------------------------------------------
154  // Getters for typed input ports
155  // ----------------------------------------------------------------------
156 
159  {
160  FW_ASSERT(
161  (0 <= portNum) && (portNum < this->getNum_SpiReadWrite_InputPorts()),
162  static_cast<FwAssertArgType>(portNum)
163  );
164 
165  return &this->m_SpiReadWrite_InputPort[portNum];
166  }
167 
170  {
171  FW_ASSERT(
172  (0 <= portNum) && (portNum < this->getNum_SpiWriteRead_InputPorts()),
173  static_cast<FwAssertArgType>(portNum)
174  );
175 
176  return &this->m_SpiWriteRead_InputPort[portNum];
177  }
178 
179  // ----------------------------------------------------------------------
180  // Connect input ports to special output ports
181  // ----------------------------------------------------------------------
182 
185  FwIndexType portNum,
186  Fw::InputLogPort* port
187  )
188  {
189  FW_ASSERT(
190  (0 <= portNum) && (portNum < this->getNum_Log_OutputPorts()),
191  static_cast<FwAssertArgType>(portNum)
192  );
193 
194  this->m_Log_OutputPort[portNum].addCallPort(port);
195  }
196 
197 #if FW_ENABLE_TEXT_LOGGING == 1
198 
199  void LinuxSpiDriverComponentBase ::
200  set_LogText_OutputPort(
201  FwIndexType portNum,
203  )
204  {
205  FW_ASSERT(
206  (0 <= portNum) && (portNum < this->getNum_LogText_OutputPorts()),
207  static_cast<FwAssertArgType>(portNum)
208  );
209 
210  this->m_LogText_OutputPort[portNum].addCallPort(port);
211  }
212 
213 #endif
214 
217  FwIndexType portNum,
218  Fw::InputTimePort* port
219  )
220  {
221  FW_ASSERT(
222  (0 <= portNum) && (portNum < this->getNum_Time_OutputPorts()),
223  static_cast<FwAssertArgType>(portNum)
224  );
225 
226  this->m_Time_OutputPort[portNum].addCallPort(port);
227  }
228 
231  FwIndexType portNum,
232  Fw::InputTlmPort* port
233  )
234  {
235  FW_ASSERT(
236  (0 <= portNum) && (portNum < this->getNum_Tlm_OutputPorts()),
237  static_cast<FwAssertArgType>(portNum)
238  );
239 
240  this->m_Tlm_OutputPort[portNum].addCallPort(port);
241  }
242 
243 #if FW_PORT_SERIALIZATION
244 
245  // ----------------------------------------------------------------------
246  // Connect serial input ports to special output ports
247  // ----------------------------------------------------------------------
248 
251  FwIndexType portNum,
252  Fw::InputSerializePort* port
253  )
254  {
255  FW_ASSERT(
256  (0 <= portNum) && (portNum < this->getNum_Log_OutputPorts()),
257  static_cast<FwAssertArgType>(portNum)
258  );
259 
260  this->m_Log_OutputPort[portNum].registerSerialPort(port);
261  }
262 
263 #if FW_ENABLE_TEXT_LOGGING == 1
264 
265  void LinuxSpiDriverComponentBase ::
266  set_LogText_OutputPort(
267  FwIndexType portNum,
268  Fw::InputSerializePort* port
269  )
270  {
271  FW_ASSERT(
272  (0 <= portNum) && (portNum < this->getNum_LogText_OutputPorts()),
273  static_cast<FwAssertArgType>(portNum)
274  );
275 
276  this->m_LogText_OutputPort[portNum].registerSerialPort(port);
277  }
278 
279 #endif
280 
283  FwIndexType portNum,
284  Fw::InputSerializePort* port
285  )
286  {
287  FW_ASSERT(
288  (0 <= portNum) && (portNum < this->getNum_Time_OutputPorts()),
289  static_cast<FwAssertArgType>(portNum)
290  );
291 
292  this->m_Time_OutputPort[portNum].registerSerialPort(port);
293  }
294 
297  FwIndexType portNum,
298  Fw::InputSerializePort* port
299  )
300  {
301  FW_ASSERT(
302  (0 <= portNum) && (portNum < this->getNum_Tlm_OutputPorts()),
303  static_cast<FwAssertArgType>(portNum)
304  );
305 
306  this->m_Tlm_OutputPort[portNum].registerSerialPort(port);
307  }
308 
309 #endif
310 
311  // ----------------------------------------------------------------------
312  // Component construction and destruction
313  // ----------------------------------------------------------------------
314 
316  LinuxSpiDriverComponentBase(const char* compName) :
317  Fw::PassiveComponentBase(compName)
318  {
319  this->m_SPI_WriteErrorThrottle = 0;
320  }
321 
324  {
325 
326  }
327 
328  // ----------------------------------------------------------------------
329  // Connection status queries for special output ports
330  // ----------------------------------------------------------------------
331 
334  {
335  FW_ASSERT(
336  (0 <= portNum) && (portNum < this->getNum_Log_OutputPorts()),
337  static_cast<FwAssertArgType>(portNum)
338  );
339 
340  return this->m_Log_OutputPort[portNum].isConnected();
341  }
342 
343 #if FW_ENABLE_TEXT_LOGGING == 1
344 
345  bool LinuxSpiDriverComponentBase ::
346  isConnected_LogText_OutputPort(FwIndexType portNum)
347  {
348  FW_ASSERT(
349  (0 <= portNum) && (portNum < this->getNum_LogText_OutputPorts()),
350  static_cast<FwAssertArgType>(portNum)
351  );
352 
353  return this->m_LogText_OutputPort[portNum].isConnected();
354  }
355 
356 #endif
357 
360  {
361  FW_ASSERT(
362  (0 <= portNum) && (portNum < this->getNum_Time_OutputPorts()),
363  static_cast<FwAssertArgType>(portNum)
364  );
365 
366  return this->m_Time_OutputPort[portNum].isConnected();
367  }
368 
371  {
372  FW_ASSERT(
373  (0 <= portNum) && (portNum < this->getNum_Tlm_OutputPorts()),
374  static_cast<FwAssertArgType>(portNum)
375  );
376 
377  return this->m_Tlm_OutputPort[portNum].isConnected();
378  }
379 
380  // ----------------------------------------------------------------------
381  // Port handler base-class functions for typed input ports
382  //
383  // Call these functions directly to bypass the corresponding ports
384  // ----------------------------------------------------------------------
385 
388  FwIndexType portNum,
389  Fw::Buffer& writeBuffer,
390  Fw::Buffer& readBuffer
391  )
392  {
393  // Make sure port number is valid
394  FW_ASSERT(
395  (0 <= portNum) && (portNum < this->getNum_SpiReadWrite_InputPorts()),
396  static_cast<FwAssertArgType>(portNum)
397  );
398 
399  // Call handler function
400  this->SpiReadWrite_handler(
401  portNum,
402  writeBuffer,
403  readBuffer
404  );
405  }
406 
409  FwIndexType portNum,
410  Fw::Buffer& writeBuffer,
411  Fw::Buffer& readBuffer
412  )
413  {
414  // Make sure port number is valid
415  FW_ASSERT(
416  (0 <= portNum) && (portNum < this->getNum_SpiWriteRead_InputPorts()),
417  static_cast<FwAssertArgType>(portNum)
418  );
419 
420  Drv::SpiStatus retVal;
421 
422  // Lock guard mutex before calling
423  this->lock();
424 
425  // Call handler function
426  retVal = this->SpiWriteRead_handler(
427  portNum,
428  writeBuffer,
429  readBuffer
430  );
431 
432  // Unlock guard mutex
433  this->unLock();
434 
435  return retVal;
436  }
437 
438  // ----------------------------------------------------------------------
439  // Event logging functions
440  // ----------------------------------------------------------------------
441 
444  I32 device,
445  I32 select,
446  I32 error
447  ) const
448  {
449  // Get the time
450  Fw::Time _logTime;
451  if (this->m_Time_OutputPort[0].isConnected()) {
452  this->m_Time_OutputPort[0].invoke(_logTime);
453  }
454 
455  FwEventIdType _id = static_cast<FwEventIdType>(0);
456 
457  _id = this->getIdBase() + EVENTID_SPI_OPENERROR;
458 
459  // Emit the event on the log port
460  if (this->m_Log_OutputPort[0].isConnected()) {
461  Fw::LogBuffer _logBuff;
463 
464 #if FW_AMPCS_COMPATIBLE
465  // Serialize the number of arguments
466  _status = _logBuff.serializeFrom(static_cast<U8>(3));
467  FW_ASSERT(
468  _status == Fw::FW_SERIALIZE_OK,
469  static_cast<FwAssertArgType>(_status)
470  );
471 #endif
472 
473 #if FW_AMPCS_COMPATIBLE
474  // Serialize the argument size
475  _status = _logBuff.serializeFrom(
476  static_cast<U8>(sizeof(I32))
477  );
478  FW_ASSERT(
479  _status == Fw::FW_SERIALIZE_OK,
480  static_cast<FwAssertArgType>(_status)
481  );
482 #endif
483  _status = _logBuff.serializeFrom(device);
484  FW_ASSERT(
485  _status == Fw::FW_SERIALIZE_OK,
486  static_cast<FwAssertArgType>(_status)
487  );
488 
489 #if FW_AMPCS_COMPATIBLE
490  // Serialize the argument size
491  _status = _logBuff.serializeFrom(
492  static_cast<U8>(sizeof(I32))
493  );
494  FW_ASSERT(
495  _status == Fw::FW_SERIALIZE_OK,
496  static_cast<FwAssertArgType>(_status)
497  );
498 #endif
499  _status = _logBuff.serializeFrom(select);
500  FW_ASSERT(
501  _status == Fw::FW_SERIALIZE_OK,
502  static_cast<FwAssertArgType>(_status)
503  );
504 
505 #if FW_AMPCS_COMPATIBLE
506  // Serialize the argument size
507  _status = _logBuff.serializeFrom(
508  static_cast<U8>(sizeof(I32))
509  );
510  FW_ASSERT(
511  _status == Fw::FW_SERIALIZE_OK,
512  static_cast<FwAssertArgType>(_status)
513  );
514 #endif
515  _status = _logBuff.serializeFrom(error);
516  FW_ASSERT(
517  _status == Fw::FW_SERIALIZE_OK,
518  static_cast<FwAssertArgType>(_status)
519  );
520 
521  this->m_Log_OutputPort[0].invoke(
522  _id,
523  _logTime,
525  _logBuff
526  );
527  }
528 
529  // Emit the event on the text log port
530 #if FW_ENABLE_TEXT_LOGGING
531  if (this->m_LogText_OutputPort[0].isConnected()) {
532 #if FW_OBJECT_NAMES == 1
533  const char* _formatString =
534  "(%s) %s: Error opening SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
535 #else
536  const char* _formatString =
537  "%s: Error opening SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
538 #endif
539 
540  Fw::TextLogString _logString;
541  _logString.format(
542  _formatString,
543 #if FW_OBJECT_NAMES == 1
544  this->m_objName.toChar(),
545 #endif
546  "SPI_OpenError ",
547  device,
548  select,
549  error
550  );
551 
552  this->m_LogText_OutputPort[0].invoke(
553  _id,
554  _logTime,
556  _logString
557  );
558  }
559 #endif
560  }
561 
564  I32 device,
565  I32 select,
566  I32 error
567  ) const
568  {
569  // Get the time
570  Fw::Time _logTime;
571  if (this->m_Time_OutputPort[0].isConnected()) {
572  this->m_Time_OutputPort[0].invoke(_logTime);
573  }
574 
575  FwEventIdType _id = static_cast<FwEventIdType>(0);
576 
577  _id = this->getIdBase() + EVENTID_SPI_CONFIGERROR;
578 
579  // Emit the event on the log port
580  if (this->m_Log_OutputPort[0].isConnected()) {
581  Fw::LogBuffer _logBuff;
583 
584 #if FW_AMPCS_COMPATIBLE
585  // Serialize the number of arguments
586  _status = _logBuff.serializeFrom(static_cast<U8>(3));
587  FW_ASSERT(
588  _status == Fw::FW_SERIALIZE_OK,
589  static_cast<FwAssertArgType>(_status)
590  );
591 #endif
592 
593 #if FW_AMPCS_COMPATIBLE
594  // Serialize the argument size
595  _status = _logBuff.serializeFrom(
596  static_cast<U8>(sizeof(I32))
597  );
598  FW_ASSERT(
599  _status == Fw::FW_SERIALIZE_OK,
600  static_cast<FwAssertArgType>(_status)
601  );
602 #endif
603  _status = _logBuff.serializeFrom(device);
604  FW_ASSERT(
605  _status == Fw::FW_SERIALIZE_OK,
606  static_cast<FwAssertArgType>(_status)
607  );
608 
609 #if FW_AMPCS_COMPATIBLE
610  // Serialize the argument size
611  _status = _logBuff.serializeFrom(
612  static_cast<U8>(sizeof(I32))
613  );
614  FW_ASSERT(
615  _status == Fw::FW_SERIALIZE_OK,
616  static_cast<FwAssertArgType>(_status)
617  );
618 #endif
619  _status = _logBuff.serializeFrom(select);
620  FW_ASSERT(
621  _status == Fw::FW_SERIALIZE_OK,
622  static_cast<FwAssertArgType>(_status)
623  );
624 
625 #if FW_AMPCS_COMPATIBLE
626  // Serialize the argument size
627  _status = _logBuff.serializeFrom(
628  static_cast<U8>(sizeof(I32))
629  );
630  FW_ASSERT(
631  _status == Fw::FW_SERIALIZE_OK,
632  static_cast<FwAssertArgType>(_status)
633  );
634 #endif
635  _status = _logBuff.serializeFrom(error);
636  FW_ASSERT(
637  _status == Fw::FW_SERIALIZE_OK,
638  static_cast<FwAssertArgType>(_status)
639  );
640 
641  this->m_Log_OutputPort[0].invoke(
642  _id,
643  _logTime,
645  _logBuff
646  );
647  }
648 
649  // Emit the event on the text log port
650 #if FW_ENABLE_TEXT_LOGGING
651  if (this->m_LogText_OutputPort[0].isConnected()) {
652 #if FW_OBJECT_NAMES == 1
653  const char* _formatString =
654  "(%s) %s: Error configuring SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
655 #else
656  const char* _formatString =
657  "%s: Error configuring SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
658 #endif
659 
660  Fw::TextLogString _logString;
661  _logString.format(
662  _formatString,
663 #if FW_OBJECT_NAMES == 1
664  this->m_objName.toChar(),
665 #endif
666  "SPI_ConfigError ",
667  device,
668  select,
669  error
670  );
671 
672  this->m_LogText_OutputPort[0].invoke(
673  _id,
674  _logTime,
676  _logString
677  );
678  }
679 #endif
680  }
681 
684  I32 device,
685  I32 select,
686  I32 error
687  )
688  {
689  // Check throttle value
690  if (this->m_SPI_WriteErrorThrottle >= EVENTID_SPI_WRITEERROR_THROTTLE) {
691  return;
692  }
693  else {
694  this->m_SPI_WriteErrorThrottle++;
695  }
696 
697  // Get the time
698  Fw::Time _logTime;
699  if (this->m_Time_OutputPort[0].isConnected()) {
700  this->m_Time_OutputPort[0].invoke(_logTime);
701  }
702 
703  FwEventIdType _id = static_cast<FwEventIdType>(0);
704 
705  _id = this->getIdBase() + EVENTID_SPI_WRITEERROR;
706 
707  // Emit the event on the log port
708  if (this->m_Log_OutputPort[0].isConnected()) {
709  Fw::LogBuffer _logBuff;
711 
712 #if FW_AMPCS_COMPATIBLE
713  // Serialize the number of arguments
714  _status = _logBuff.serializeFrom(static_cast<U8>(3));
715  FW_ASSERT(
716  _status == Fw::FW_SERIALIZE_OK,
717  static_cast<FwAssertArgType>(_status)
718  );
719 #endif
720 
721 #if FW_AMPCS_COMPATIBLE
722  // Serialize the argument size
723  _status = _logBuff.serializeFrom(
724  static_cast<U8>(sizeof(I32))
725  );
726  FW_ASSERT(
727  _status == Fw::FW_SERIALIZE_OK,
728  static_cast<FwAssertArgType>(_status)
729  );
730 #endif
731  _status = _logBuff.serializeFrom(device);
732  FW_ASSERT(
733  _status == Fw::FW_SERIALIZE_OK,
734  static_cast<FwAssertArgType>(_status)
735  );
736 
737 #if FW_AMPCS_COMPATIBLE
738  // Serialize the argument size
739  _status = _logBuff.serializeFrom(
740  static_cast<U8>(sizeof(I32))
741  );
742  FW_ASSERT(
743  _status == Fw::FW_SERIALIZE_OK,
744  static_cast<FwAssertArgType>(_status)
745  );
746 #endif
747  _status = _logBuff.serializeFrom(select);
748  FW_ASSERT(
749  _status == Fw::FW_SERIALIZE_OK,
750  static_cast<FwAssertArgType>(_status)
751  );
752 
753 #if FW_AMPCS_COMPATIBLE
754  // Serialize the argument size
755  _status = _logBuff.serializeFrom(
756  static_cast<U8>(sizeof(I32))
757  );
758  FW_ASSERT(
759  _status == Fw::FW_SERIALIZE_OK,
760  static_cast<FwAssertArgType>(_status)
761  );
762 #endif
763  _status = _logBuff.serializeFrom(error);
764  FW_ASSERT(
765  _status == Fw::FW_SERIALIZE_OK,
766  static_cast<FwAssertArgType>(_status)
767  );
768 
769  this->m_Log_OutputPort[0].invoke(
770  _id,
771  _logTime,
773  _logBuff
774  );
775  }
776 
777  // Emit the event on the text log port
778 #if FW_ENABLE_TEXT_LOGGING
779  if (this->m_LogText_OutputPort[0].isConnected()) {
780 #if FW_OBJECT_NAMES == 1
781  const char* _formatString =
782  "(%s) %s: Error writing/reading SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
783 #else
784  const char* _formatString =
785  "%s: Error writing/reading SPI device %" PRIi32 ".%" PRIi32 ": %" PRIi32 "";
786 #endif
787 
788  Fw::TextLogString _logString;
789  _logString.format(
790  _formatString,
791 #if FW_OBJECT_NAMES == 1
792  this->m_objName.toChar(),
793 #endif
794  "SPI_WriteError ",
795  device,
796  select,
797  error
798  );
799 
800  this->m_LogText_OutputPort[0].invoke(
801  _id,
802  _logTime,
804  _logString
805  );
806  }
807 #endif
808  }
809 
812  I32 device,
813  I32 select,
814  const Fw::StringBase& parameter,
815  U32 write_value,
816  U32 read_value
817  ) const
818  {
819  // Get the time
820  Fw::Time _logTime;
821  if (this->m_Time_OutputPort[0].isConnected()) {
822  this->m_Time_OutputPort[0].invoke(_logTime);
823  }
824 
825  FwEventIdType _id = static_cast<FwEventIdType>(0);
826 
827  _id = this->getIdBase() + EVENTID_SPI_CONFIGMISMATCH;
828 
829  // Emit the event on the log port
830  if (this->m_Log_OutputPort[0].isConnected()) {
831  Fw::LogBuffer _logBuff;
833 
834 #if FW_AMPCS_COMPATIBLE
835  // Serialize the number of arguments
836  _status = _logBuff.serializeFrom(static_cast<U8>(5));
837  FW_ASSERT(
838  _status == Fw::FW_SERIALIZE_OK,
839  static_cast<FwAssertArgType>(_status)
840  );
841 #endif
842 
843 #if FW_AMPCS_COMPATIBLE
844  // Serialize the argument size
845  _status = _logBuff.serializeFrom(
846  static_cast<U8>(sizeof(I32))
847  );
848  FW_ASSERT(
849  _status == Fw::FW_SERIALIZE_OK,
850  static_cast<FwAssertArgType>(_status)
851  );
852 #endif
853  _status = _logBuff.serializeFrom(device);
854  FW_ASSERT(
855  _status == Fw::FW_SERIALIZE_OK,
856  static_cast<FwAssertArgType>(_status)
857  );
858 
859 #if FW_AMPCS_COMPATIBLE
860  // Serialize the argument size
861  _status = _logBuff.serializeFrom(
862  static_cast<U8>(sizeof(I32))
863  );
864  FW_ASSERT(
865  _status == Fw::FW_SERIALIZE_OK,
866  static_cast<FwAssertArgType>(_status)
867  );
868 #endif
869  _status = _logBuff.serializeFrom(select);
870  FW_ASSERT(
871  _status == Fw::FW_SERIALIZE_OK,
872  static_cast<FwAssertArgType>(_status)
873  );
874 
875  _status = parameter.serializeTo(_logBuff, FW_MIN(FW_LOG_STRING_MAX_SIZE, 80));
876  FW_ASSERT(
877  _status == Fw::FW_SERIALIZE_OK,
878  static_cast<FwAssertArgType>(_status)
879  );
880 
881 #if FW_AMPCS_COMPATIBLE
882  // Serialize the argument size
883  _status = _logBuff.serializeFrom(
884  static_cast<U8>(sizeof(U32))
885  );
886  FW_ASSERT(
887  _status == Fw::FW_SERIALIZE_OK,
888  static_cast<FwAssertArgType>(_status)
889  );
890 #endif
891  _status = _logBuff.serializeFrom(write_value);
892  FW_ASSERT(
893  _status == Fw::FW_SERIALIZE_OK,
894  static_cast<FwAssertArgType>(_status)
895  );
896 
897 #if FW_AMPCS_COMPATIBLE
898  // Serialize the argument size
899  _status = _logBuff.serializeFrom(
900  static_cast<U8>(sizeof(U32))
901  );
902  FW_ASSERT(
903  _status == Fw::FW_SERIALIZE_OK,
904  static_cast<FwAssertArgType>(_status)
905  );
906 #endif
907  _status = _logBuff.serializeFrom(read_value);
908  FW_ASSERT(
909  _status == Fw::FW_SERIALIZE_OK,
910  static_cast<FwAssertArgType>(_status)
911  );
912 
913  this->m_Log_OutputPort[0].invoke(
914  _id,
915  _logTime,
917  _logBuff
918  );
919  }
920 
921  // Emit the event on the text log port
922 #if FW_ENABLE_TEXT_LOGGING
923  if (this->m_LogText_OutputPort[0].isConnected()) {
924 #if FW_OBJECT_NAMES == 1
925  const char* _formatString =
926  "(%s) %s: SPI device %" PRIi32 ".%" PRIi32 " configuration mismatch for %s: wrote %" PRIu32 ", read %" PRIu32 "";
927 #else
928  const char* _formatString =
929  "%s: SPI device %" PRIi32 ".%" PRIi32 " configuration mismatch for %s: wrote %" PRIu32 ", read %" PRIu32 "";
930 #endif
931 
932  Fw::TextLogString _logString;
933  _logString.format(
934  _formatString,
935 #if FW_OBJECT_NAMES == 1
936  this->m_objName.toChar(),
937 #endif
938  "SPI_ConfigMismatch ",
939  device,
940  select,
941  parameter.toChar(),
942  write_value,
943  read_value
944  );
945 
946  this->m_LogText_OutputPort[0].invoke(
947  _id,
948  _logTime,
950  _logString
951  );
952  }
953 #endif
954  }
955 
958  I32 device,
959  I32 select
960  ) const
961  {
962  // Get the time
963  Fw::Time _logTime;
964  if (this->m_Time_OutputPort[0].isConnected()) {
965  this->m_Time_OutputPort[0].invoke(_logTime);
966  }
967 
968  FwEventIdType _id = static_cast<FwEventIdType>(0);
969 
970  _id = this->getIdBase() + EVENTID_SPI_PORTOPENED;
971 
972  // Emit the event on the log port
973  if (this->m_Log_OutputPort[0].isConnected()) {
974  Fw::LogBuffer _logBuff;
976 
977 #if FW_AMPCS_COMPATIBLE
978  // Serialize the number of arguments
979  _status = _logBuff.serializeFrom(static_cast<U8>(2));
980  FW_ASSERT(
981  _status == Fw::FW_SERIALIZE_OK,
982  static_cast<FwAssertArgType>(_status)
983  );
984 #endif
985 
986 #if FW_AMPCS_COMPATIBLE
987  // Serialize the argument size
988  _status = _logBuff.serializeFrom(
989  static_cast<U8>(sizeof(I32))
990  );
991  FW_ASSERT(
992  _status == Fw::FW_SERIALIZE_OK,
993  static_cast<FwAssertArgType>(_status)
994  );
995 #endif
996  _status = _logBuff.serializeFrom(device);
997  FW_ASSERT(
998  _status == Fw::FW_SERIALIZE_OK,
999  static_cast<FwAssertArgType>(_status)
1000  );
1001 
1002 #if FW_AMPCS_COMPATIBLE
1003  // Serialize the argument size
1004  _status = _logBuff.serializeFrom(
1005  static_cast<U8>(sizeof(I32))
1006  );
1007  FW_ASSERT(
1008  _status == Fw::FW_SERIALIZE_OK,
1009  static_cast<FwAssertArgType>(_status)
1010  );
1011 #endif
1012  _status = _logBuff.serializeFrom(select);
1013  FW_ASSERT(
1014  _status == Fw::FW_SERIALIZE_OK,
1015  static_cast<FwAssertArgType>(_status)
1016  );
1017 
1018  this->m_Log_OutputPort[0].invoke(
1019  _id,
1020  _logTime,
1022  _logBuff
1023  );
1024  }
1025 
1026  // Emit the event on the text log port
1027 #if FW_ENABLE_TEXT_LOGGING
1028  if (this->m_LogText_OutputPort[0].isConnected()) {
1029 #if FW_OBJECT_NAMES == 1
1030  const char* _formatString =
1031  "(%s) %s: SPI Device %" PRIi32 ".%" PRIi32 " configured";
1032 #else
1033  const char* _formatString =
1034  "%s: SPI Device %" PRIi32 ".%" PRIi32 " configured";
1035 #endif
1036 
1037  Fw::TextLogString _logString;
1038  _logString.format(
1039  _formatString,
1040 #if FW_OBJECT_NAMES == 1
1041  this->m_objName.toChar(),
1042 #endif
1043  "SPI_PortOpened ",
1044  device,
1045  select
1046  );
1047 
1048  this->m_LogText_OutputPort[0].invoke(
1049  _id,
1050  _logTime,
1052  _logString
1053  );
1054  }
1055 #endif
1056  }
1057 
1058  // ----------------------------------------------------------------------
1059  // Event throttle reset functions
1060  // ----------------------------------------------------------------------
1061 
1064  {
1065  // Reset throttle counter
1066  this->m_SPI_WriteErrorThrottle = 0;
1067  }
1068 
1069  // ----------------------------------------------------------------------
1070  // Telemetry write functions
1071  // ----------------------------------------------------------------------
1072 
1075  FwSizeType arg,
1076  Fw::Time _tlmTime
1077  ) const
1078  {
1079  if (this->m_Tlm_OutputPort[0].isConnected()) {
1080  if (
1081  this->m_Time_OutputPort[0].isConnected() &&
1082  (_tlmTime == Fw::ZERO_TIME)
1083  ) {
1084  this->m_Time_OutputPort[0].invoke(_tlmTime);
1085  }
1086 
1087  Fw::TlmBuffer _tlmBuff;
1088  Fw::SerializeStatus _stat = _tlmBuff.serializeFrom(arg);
1089  FW_ASSERT(
1090  _stat == Fw::FW_SERIALIZE_OK,
1091  static_cast<FwAssertArgType>(_stat)
1092  );
1093 
1094  FwChanIdType _id;
1095 
1096  _id = this->getIdBase() + CHANNELID_SPI_BYTES;
1097 
1098  this->m_Tlm_OutputPort[0].invoke(
1099  _id,
1100  _tlmTime,
1101  _tlmBuff
1102  );
1103  }
1104  }
1105 
1106  // ----------------------------------------------------------------------
1107  // Time
1108  // ----------------------------------------------------------------------
1109 
1111  getTime() const
1112  {
1113  if (this->m_Time_OutputPort[0].isConnected()) {
1114  Fw::Time _time;
1115  this->m_Time_OutputPort[0].invoke(_time);
1116  return _time;
1117  }
1118  else {
1119  return Fw::Time(TimeBase::TB_NONE, 0, 0);
1120  }
1121  }
1122 
1123  // ----------------------------------------------------------------------
1124  // Mutex operations for guarded ports
1125  //
1126  // You can override these operations to provide more sophisticated
1127  // synchronization
1128  // ----------------------------------------------------------------------
1129 
1132  {
1133  this->m_guardedPortMutex.lock();
1134  }
1135 
1138  {
1139  this->m_guardedPortMutex.unLock();
1140  }
1141 
1142  // ----------------------------------------------------------------------
1143  // Calls for messages received on typed input ports
1144  // ----------------------------------------------------------------------
1145 
1146  void LinuxSpiDriverComponentBase ::
1147  m_p_SpiReadWrite_in(
1148  Fw::PassiveComponentBase* callComp,
1149  FwIndexType portNum,
1150  Fw::Buffer& writeBuffer,
1151  Fw::Buffer& readBuffer
1152  )
1153  {
1154  FW_ASSERT(callComp);
1155  LinuxSpiDriverComponentBase* compPtr = static_cast<LinuxSpiDriverComponentBase*>(callComp);
1156  compPtr->SpiReadWrite_handlerBase(
1157  portNum,
1158  writeBuffer,
1159  readBuffer
1160  );
1161  }
1162 
1163  Drv::SpiStatus LinuxSpiDriverComponentBase ::
1164  m_p_SpiWriteRead_in(
1165  Fw::PassiveComponentBase* callComp,
1166  FwIndexType portNum,
1167  Fw::Buffer& writeBuffer,
1168  Fw::Buffer& readBuffer
1169  )
1170  {
1171  FW_ASSERT(callComp);
1172  LinuxSpiDriverComponentBase* compPtr = static_cast<LinuxSpiDriverComponentBase*>(callComp);
1173  return compPtr->SpiWriteRead_handlerBase(
1174  portNum,
1175  writeBuffer,
1176  readBuffer
1177  );
1178  }
1179 
1180 }
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
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()
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:144
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: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.
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: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()
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:151
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 interface.
Definition: LogPortAc.cpp:170
void init()
Initialization function.
bool isConnected_Log_OutputPort(FwIndexType portNum)
PlatformIndexType FwIndexType
void addCallPort(InputLogPort *callPort)
Register an input port.
Definition: LogPortAc.cpp:157
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.