F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
BlockDriverComponentAc.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title BlockDriverComponentAc.cpp
3 // \author Generated by fpp-to-cpp
4 // \brief cpp file for BlockDriver component base class
5 // ======================================================================
6 
7 #include <cstdio>
8 
10 #include "Fw/Types/Assert.hpp"
11 #if FW_ENABLE_TEXT_LOGGING
12 #include "Fw/Types/String.hpp"
13 #endif
14 
15 namespace Drv {
16 
17  namespace {
18  enum MsgTypeEnum {
19  BLOCKDRIVER_COMPONENT_EXIT = Fw::ActiveComponentBase::ACTIVE_COMPONENT_EXIT,
20  BUFFERIN_DATABUFFER,
21  PINGIN_PING,
22  SCHED_SCHED,
23  INT_IF_INTERRUPTREPORT,
24  };
25 
26  // Get the max size by constructing a union of the async input, command, and
27  // internal port serialization sizes
28  union BuffUnion {
32  // Size of InterruptReport argument list
34  sizeof(U32)
35  ];
36  };
37 
38  // Define a message buffer class large enough to handle all the
39  // asynchronous inputs to the component
40  class ComponentIpcSerializableBuffer :
42  {
43 
44  public:
45 
46  enum {
47  // Max. message size = size of data + message id + port
48  SERIALIZATION_SIZE =
49  sizeof(BuffUnion) +
50  sizeof(NATIVE_INT_TYPE) +
51  sizeof(NATIVE_INT_TYPE)
52  };
53 
54  NATIVE_UINT_TYPE getBuffCapacity() const {
55  return sizeof(m_buff);
56  }
57 
58  U8* getBuffAddr() {
59  return m_buff;
60  }
61 
62  const U8* getBuffAddr() const {
63  return m_buff;
64  }
65 
66  private:
67  // Should be the max of all the input ports serialized sizes...
68  U8 m_buff[SERIALIZATION_SIZE];
69 
70  };
71  }
72 
73  // ----------------------------------------------------------------------
74  // Component initialization
75  // ----------------------------------------------------------------------
76 
78  init(
79  NATIVE_INT_TYPE queueDepth,
80  NATIVE_INT_TYPE instance
81  )
82  {
83  // Initialize base class
85 
86  // Connect input port BufferIn
87  for (
88  PlatformIntType port = 0;
89  port < static_cast<PlatformIntType>(this->getNum_BufferIn_InputPorts());
90  port++
91  ) {
92  this->m_BufferIn_InputPort[port].init();
93  this->m_BufferIn_InputPort[port].addCallComp(
94  this,
95  m_p_BufferIn_in
96  );
97  this->m_BufferIn_InputPort[port].setPortNum(port);
98 
99 #if FW_OBJECT_NAMES == 1
100  // The port name consists of this->m_objName and some extra info.
101  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
102  // However, the compiler may assume that this->m_objName fills
103  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
104  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
105  // bytes to cover the extra info.
106  char portName[2*FW_OBJ_NAME_MAX_SIZE];
107  (void) snprintf(
108  portName,
109  sizeof(portName),
110  "%s_BufferIn_InputPort[%" PRI_PlatformIntType "]",
111  this->m_objName,
112  port
113  );
114  this->m_BufferIn_InputPort[port].setObjName(portName);
115 #endif
116  }
117 
118  // Connect input port PingIn
119  for (
120  PlatformIntType port = 0;
121  port < static_cast<PlatformIntType>(this->getNum_PingIn_InputPorts());
122  port++
123  ) {
124  this->m_PingIn_InputPort[port].init();
125  this->m_PingIn_InputPort[port].addCallComp(
126  this,
127  m_p_PingIn_in
128  );
129  this->m_PingIn_InputPort[port].setPortNum(port);
130 
131 #if FW_OBJECT_NAMES == 1
132  // The port name consists of this->m_objName and some extra info.
133  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
134  // However, the compiler may assume that this->m_objName fills
135  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
136  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
137  // bytes to cover the extra info.
138  char portName[2*FW_OBJ_NAME_MAX_SIZE];
139  (void) snprintf(
140  portName,
141  sizeof(portName),
142  "%s_PingIn_InputPort[%" PRI_PlatformIntType "]",
143  this->m_objName,
144  port
145  );
146  this->m_PingIn_InputPort[port].setObjName(portName);
147 #endif
148  }
149 
150  // Connect input port Sched
151  for (
152  PlatformIntType port = 0;
153  port < static_cast<PlatformIntType>(this->getNum_Sched_InputPorts());
154  port++
155  ) {
156  this->m_Sched_InputPort[port].init();
157  this->m_Sched_InputPort[port].addCallComp(
158  this,
159  m_p_Sched_in
160  );
161  this->m_Sched_InputPort[port].setPortNum(port);
162 
163 #if FW_OBJECT_NAMES == 1
164  // The port name consists of this->m_objName and some extra info.
165  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
166  // However, the compiler may assume that this->m_objName fills
167  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
168  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
169  // bytes to cover the extra info.
170  char portName[2*FW_OBJ_NAME_MAX_SIZE];
171  (void) snprintf(
172  portName,
173  sizeof(portName),
174  "%s_Sched_InputPort[%" PRI_PlatformIntType "]",
175  this->m_objName,
176  port
177  );
178  this->m_Sched_InputPort[port].setObjName(portName);
179 #endif
180  }
181 
182  // Connect output port Time
183  for (
184  PlatformIntType port = 0;
185  port < static_cast<PlatformIntType>(this->getNum_Time_OutputPorts());
186  port++
187  ) {
188  this->m_Time_OutputPort[port].init();
189 
190 #if FW_OBJECT_NAMES == 1
191  // The port name consists of this->m_objName and some extra info.
192  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
193  // However, the compiler may assume that this->m_objName fills
194  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
195  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
196  // bytes to cover the extra info.
197  char portName[2*FW_OBJ_NAME_MAX_SIZE];
198  (void) snprintf(
199  portName,
200  sizeof(portName),
201  "%s_Time_OutputPort[%" PRI_PlatformIntType "]",
202  this->m_objName,
203  port
204  );
205  this->m_Time_OutputPort[port].setObjName(portName);
206 #endif
207  }
208 
209  // Connect output port Tlm
210  for (
211  PlatformIntType port = 0;
212  port < static_cast<PlatformIntType>(this->getNum_Tlm_OutputPorts());
213  port++
214  ) {
215  this->m_Tlm_OutputPort[port].init();
216 
217 #if FW_OBJECT_NAMES == 1
218  // The port name consists of this->m_objName and some extra info.
219  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
220  // However, the compiler may assume that this->m_objName fills
221  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
222  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
223  // bytes to cover the extra info.
224  char portName[2*FW_OBJ_NAME_MAX_SIZE];
225  (void) snprintf(
226  portName,
227  sizeof(portName),
228  "%s_Tlm_OutputPort[%" PRI_PlatformIntType "]",
229  this->m_objName,
230  port
231  );
232  this->m_Tlm_OutputPort[port].setObjName(portName);
233 #endif
234  }
235 
236  // Connect output port BufferOut
237  for (
238  PlatformIntType port = 0;
239  port < static_cast<PlatformIntType>(this->getNum_BufferOut_OutputPorts());
240  port++
241  ) {
242  this->m_BufferOut_OutputPort[port].init();
243 
244 #if FW_OBJECT_NAMES == 1
245  // The port name consists of this->m_objName and some extra info.
246  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
247  // However, the compiler may assume that this->m_objName fills
248  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
249  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
250  // bytes to cover the extra info.
251  char portName[2*FW_OBJ_NAME_MAX_SIZE];
252  (void) snprintf(
253  portName,
254  sizeof(portName),
255  "%s_BufferOut_OutputPort[%" PRI_PlatformIntType "]",
256  this->m_objName,
257  port
258  );
259  this->m_BufferOut_OutputPort[port].setObjName(portName);
260 #endif
261  }
262 
263  // Connect output port CycleOut
264  for (
265  PlatformIntType port = 0;
266  port < static_cast<PlatformIntType>(this->getNum_CycleOut_OutputPorts());
267  port++
268  ) {
269  this->m_CycleOut_OutputPort[port].init();
270 
271 #if FW_OBJECT_NAMES == 1
272  // The port name consists of this->m_objName and some extra info.
273  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
274  // However, the compiler may assume that this->m_objName fills
275  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
276  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
277  // bytes to cover the extra info.
278  char portName[2*FW_OBJ_NAME_MAX_SIZE];
279  (void) snprintf(
280  portName,
281  sizeof(portName),
282  "%s_CycleOut_OutputPort[%" PRI_PlatformIntType "]",
283  this->m_objName,
284  port
285  );
286  this->m_CycleOut_OutputPort[port].setObjName(portName);
287 #endif
288  }
289 
290  // Connect output port PingOut
291  for (
292  PlatformIntType port = 0;
293  port < static_cast<PlatformIntType>(this->getNum_PingOut_OutputPorts());
294  port++
295  ) {
296  this->m_PingOut_OutputPort[port].init();
297 
298 #if FW_OBJECT_NAMES == 1
299  // The port name consists of this->m_objName and some extra info.
300  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
301  // However, the compiler may assume that this->m_objName fills
302  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
303  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
304  // bytes to cover the extra info.
305  char portName[2*FW_OBJ_NAME_MAX_SIZE];
306  (void) snprintf(
307  portName,
308  sizeof(portName),
309  "%s_PingOut_OutputPort[%" PRI_PlatformIntType "]",
310  this->m_objName,
311  port
312  );
313  this->m_PingOut_OutputPort[port].setObjName(portName);
314 #endif
315  }
316 
317  Os::Queue::QueueStatus qStat = this->createQueue(
318  queueDepth,
319  ComponentIpcSerializableBuffer::SERIALIZATION_SIZE
320  );
321  FW_ASSERT(
322  Os::Queue::QUEUE_OK == qStat,
323  static_cast<FwAssertArgType>(qStat)
324  );
325  }
326 
327  // ----------------------------------------------------------------------
328  // Getters for typed input ports
329  // ----------------------------------------------------------------------
330 
333  {
334  FW_ASSERT(
335  portNum < this->getNum_BufferIn_InputPorts(),
336  static_cast<FwAssertArgType>(portNum)
337  );
338 
339  return &this->m_BufferIn_InputPort[portNum];
340  }
341 
344  {
345  FW_ASSERT(
346  portNum < this->getNum_PingIn_InputPorts(),
347  static_cast<FwAssertArgType>(portNum)
348  );
349 
350  return &this->m_PingIn_InputPort[portNum];
351  }
352 
355  {
356  FW_ASSERT(
357  portNum < this->getNum_Sched_InputPorts(),
358  static_cast<FwAssertArgType>(portNum)
359  );
360 
361  return &this->m_Sched_InputPort[portNum];
362  }
363 
364  // ----------------------------------------------------------------------
365  // Connect input ports to special output ports
366  // ----------------------------------------------------------------------
367 
370  NATIVE_INT_TYPE portNum,
371  Fw::InputTimePort* port
372  )
373  {
374  FW_ASSERT(
375  portNum < this->getNum_Time_OutputPorts(),
376  static_cast<FwAssertArgType>(portNum)
377  );
378 
379  this->m_Time_OutputPort[portNum].addCallPort(port);
380  }
381 
384  NATIVE_INT_TYPE portNum,
385  Fw::InputTlmPort* port
386  )
387  {
388  FW_ASSERT(
389  portNum < this->getNum_Tlm_OutputPorts(),
390  static_cast<FwAssertArgType>(portNum)
391  );
392 
393  this->m_Tlm_OutputPort[portNum].addCallPort(port);
394  }
395 
396  // ----------------------------------------------------------------------
397  // Connect typed input ports to typed output ports
398  // ----------------------------------------------------------------------
399 
402  NATIVE_INT_TYPE portNum,
404  )
405  {
406  FW_ASSERT(
407  portNum < this->getNum_BufferOut_OutputPorts(),
408  static_cast<FwAssertArgType>(portNum)
409  );
410 
411  this->m_BufferOut_OutputPort[portNum].addCallPort(port);
412  }
413 
416  NATIVE_INT_TYPE portNum,
417  Svc::InputCyclePort* port
418  )
419  {
420  FW_ASSERT(
421  portNum < this->getNum_CycleOut_OutputPorts(),
422  static_cast<FwAssertArgType>(portNum)
423  );
424 
425  this->m_CycleOut_OutputPort[portNum].addCallPort(port);
426  }
427 
430  NATIVE_INT_TYPE portNum,
431  Svc::InputPingPort* port
432  )
433  {
434  FW_ASSERT(
435  portNum < this->getNum_PingOut_OutputPorts(),
436  static_cast<FwAssertArgType>(portNum)
437  );
438 
439  this->m_PingOut_OutputPort[portNum].addCallPort(port);
440  }
441 
442 #if FW_PORT_SERIALIZATION
443 
444  // ----------------------------------------------------------------------
445  // Connect serial input ports to special output ports
446  // ----------------------------------------------------------------------
447 
450  NATIVE_INT_TYPE portNum,
451  Fw::InputSerializePort* port
452  )
453  {
454  FW_ASSERT(
455  portNum < this->getNum_Time_OutputPorts(),
456  static_cast<FwAssertArgType>(portNum)
457  );
458 
459  this->m_Time_OutputPort[portNum].registerSerialPort(port);
460  }
461 
464  NATIVE_INT_TYPE portNum,
465  Fw::InputSerializePort* port
466  )
467  {
468  FW_ASSERT(
469  portNum < this->getNum_Tlm_OutputPorts(),
470  static_cast<FwAssertArgType>(portNum)
471  );
472 
473  this->m_Tlm_OutputPort[portNum].registerSerialPort(port);
474  }
475 
476 #endif
477 
478 #if FW_PORT_SERIALIZATION
479 
480  // ----------------------------------------------------------------------
481  // Connect serial input ports to typed output ports
482  // ----------------------------------------------------------------------
483 
486  NATIVE_INT_TYPE portNum,
487  Fw::InputSerializePort* port
488  )
489  {
490  FW_ASSERT(
491  portNum < this->getNum_BufferOut_OutputPorts(),
492  static_cast<FwAssertArgType>(portNum)
493  );
494 
495  this->m_BufferOut_OutputPort[portNum].registerSerialPort(port);
496  }
497 
500  NATIVE_INT_TYPE portNum,
501  Fw::InputSerializePort* port
502  )
503  {
504  FW_ASSERT(
505  portNum < this->getNum_CycleOut_OutputPorts(),
506  static_cast<FwAssertArgType>(portNum)
507  );
508 
509  this->m_CycleOut_OutputPort[portNum].registerSerialPort(port);
510  }
511 
514  NATIVE_INT_TYPE portNum,
515  Fw::InputSerializePort* port
516  )
517  {
518  FW_ASSERT(
519  portNum < this->getNum_PingOut_OutputPorts(),
520  static_cast<FwAssertArgType>(portNum)
521  );
522 
523  this->m_PingOut_OutputPort[portNum].registerSerialPort(port);
524  }
525 
526 #endif
527 
528  // ----------------------------------------------------------------------
529  // Component construction and destruction
530  // ----------------------------------------------------------------------
531 
533  BlockDriverComponentBase(const char* compName) :
534  Fw::ActiveComponentBase(compName)
535  {
536 
537  }
538 
541  {
542 
543  }
544 
545  // ----------------------------------------------------------------------
546  // Getters for numbers of typed input ports
547  // ----------------------------------------------------------------------
548 
551  {
552  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_BufferIn_InputPort));
553  }
554 
557  {
558  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_PingIn_InputPort));
559  }
560 
563  {
564  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_Sched_InputPort));
565  }
566 
567  // ----------------------------------------------------------------------
568  // Getters for numbers of special output ports
569  // ----------------------------------------------------------------------
570 
573  {
574  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_Time_OutputPort));
575  }
576 
579  {
580  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_Tlm_OutputPort));
581  }
582 
583  // ----------------------------------------------------------------------
584  // Getters for numbers of typed output ports
585  // ----------------------------------------------------------------------
586 
589  {
590  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_BufferOut_OutputPort));
591  }
592 
595  {
596  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_CycleOut_OutputPort));
597  }
598 
601  {
602  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_PingOut_OutputPort));
603  }
604 
605  // ----------------------------------------------------------------------
606  // Connection status queries for special output ports
607  // ----------------------------------------------------------------------
608 
611  {
612  FW_ASSERT(
613  portNum < this->getNum_Time_OutputPorts(),
614  static_cast<FwAssertArgType>(portNum)
615  );
616 
617  return this->m_Time_OutputPort[portNum].isConnected();
618  }
619 
622  {
623  FW_ASSERT(
624  portNum < this->getNum_Tlm_OutputPorts(),
625  static_cast<FwAssertArgType>(portNum)
626  );
627 
628  return this->m_Tlm_OutputPort[portNum].isConnected();
629  }
630 
631  // ----------------------------------------------------------------------
632  // Connection status queries for typed output ports
633  // ----------------------------------------------------------------------
634 
637  {
638  FW_ASSERT(
639  portNum < this->getNum_BufferOut_OutputPorts(),
640  static_cast<FwAssertArgType>(portNum)
641  );
642 
643  return this->m_BufferOut_OutputPort[portNum].isConnected();
644  }
645 
648  {
649  FW_ASSERT(
650  portNum < this->getNum_CycleOut_OutputPorts(),
651  static_cast<FwAssertArgType>(portNum)
652  );
653 
654  return this->m_CycleOut_OutputPort[portNum].isConnected();
655  }
656 
659  {
660  FW_ASSERT(
661  portNum < this->getNum_PingOut_OutputPorts(),
662  static_cast<FwAssertArgType>(portNum)
663  );
664 
665  return this->m_PingOut_OutputPort[portNum].isConnected();
666  }
667 
668  // ----------------------------------------------------------------------
669  // Port handler base-class functions for typed input ports
670  //
671  // Call these functions directly to bypass the corresponding ports
672  // ----------------------------------------------------------------------
673 
676  NATIVE_INT_TYPE portNum,
677  Drv::DataBuffer& buff
678  )
679  {
680  // Make sure port number is valid
681  FW_ASSERT(
682  portNum < this->getNum_BufferIn_InputPorts(),
683  static_cast<FwAssertArgType>(portNum)
684  );
685 
686  // Call pre-message hook
688  portNum,
689  buff
690  );
691  ComponentIpcSerializableBuffer msg;
693 
694  // Serialize message ID
695  _status = msg.serialize(
696  static_cast<NATIVE_INT_TYPE>(BUFFERIN_DATABUFFER)
697  );
698  FW_ASSERT(
699  _status == Fw::FW_SERIALIZE_OK,
700  static_cast<FwAssertArgType>(_status)
701  );
702 
703  // Serialize port number
704  _status = msg.serialize(portNum);
705  FW_ASSERT(
706  _status == Fw::FW_SERIALIZE_OK,
707  static_cast<FwAssertArgType>(_status)
708  );
709 
710  // Serialize argument buff
711  _status = msg.serialize(buff);
712  FW_ASSERT(
713  _status == Fw::FW_SERIALIZE_OK,
714  static_cast<FwAssertArgType>(_status)
715  );
716 
717  // Send message
719  Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 0, _block);
720 
721  FW_ASSERT(
722  qStatus == Os::Queue::QUEUE_OK,
723  static_cast<FwAssertArgType>(qStatus)
724  );
725  }
726 
729  NATIVE_INT_TYPE portNum,
730  U32 key
731  )
732  {
733  // Make sure port number is valid
734  FW_ASSERT(
735  portNum < this->getNum_PingIn_InputPorts(),
736  static_cast<FwAssertArgType>(portNum)
737  );
738 
739  // Call pre-message hook
741  portNum,
742  key
743  );
744  ComponentIpcSerializableBuffer msg;
746 
747  // Serialize message ID
748  _status = msg.serialize(
749  static_cast<NATIVE_INT_TYPE>(PINGIN_PING)
750  );
751  FW_ASSERT(
752  _status == Fw::FW_SERIALIZE_OK,
753  static_cast<FwAssertArgType>(_status)
754  );
755 
756  // Serialize port number
757  _status = msg.serialize(portNum);
758  FW_ASSERT(
759  _status == Fw::FW_SERIALIZE_OK,
760  static_cast<FwAssertArgType>(_status)
761  );
762 
763  // Serialize argument key
764  _status = msg.serialize(key);
765  FW_ASSERT(
766  _status == Fw::FW_SERIALIZE_OK,
767  static_cast<FwAssertArgType>(_status)
768  );
769 
770  // Send message
772  Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 0, _block);
773 
774  FW_ASSERT(
775  qStatus == Os::Queue::QUEUE_OK,
776  static_cast<FwAssertArgType>(qStatus)
777  );
778  }
779 
782  NATIVE_INT_TYPE portNum,
783  NATIVE_UINT_TYPE context
784  )
785  {
786  // Make sure port number is valid
787  FW_ASSERT(
788  portNum < this->getNum_Sched_InputPorts(),
789  static_cast<FwAssertArgType>(portNum)
790  );
791 
792  // Call pre-message hook
794  portNum,
795  context
796  );
797  ComponentIpcSerializableBuffer msg;
799 
800  // Serialize message ID
801  _status = msg.serialize(
802  static_cast<NATIVE_INT_TYPE>(SCHED_SCHED)
803  );
804  FW_ASSERT(
805  _status == Fw::FW_SERIALIZE_OK,
806  static_cast<FwAssertArgType>(_status)
807  );
808 
809  // Serialize port number
810  _status = msg.serialize(portNum);
811  FW_ASSERT(
812  _status == Fw::FW_SERIALIZE_OK,
813  static_cast<FwAssertArgType>(_status)
814  );
815 
816  // Serialize argument context
817  _status = msg.serialize(context);
818  FW_ASSERT(
819  _status == Fw::FW_SERIALIZE_OK,
820  static_cast<FwAssertArgType>(_status)
821  );
822 
823  // Send message
825  Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 0, _block);
826 
827  FW_ASSERT(
828  qStatus == Os::Queue::QUEUE_OK,
829  static_cast<FwAssertArgType>(qStatus)
830  );
831  }
832 
833  // ----------------------------------------------------------------------
834  // Pre-message hooks for typed async input ports
835  //
836  // Each of these functions is invoked just before processing a message
837  // on the corresponding port. By default, they do nothing. You can
838  // override them to provide specific pre-message behavior.
839  // ----------------------------------------------------------------------
840 
843  NATIVE_INT_TYPE portNum,
844  Drv::DataBuffer& buff
845  )
846  {
847  // Default: no-op
848  }
849 
852  NATIVE_INT_TYPE portNum,
853  U32 key
854  )
855  {
856  // Default: no-op
857  }
858 
861  NATIVE_INT_TYPE portNum,
862  NATIVE_UINT_TYPE context
863  )
864  {
865  // Default: no-op
866  }
867 
868  // ----------------------------------------------------------------------
869  // Invocation functions for typed output ports
870  // ----------------------------------------------------------------------
871 
874  NATIVE_INT_TYPE portNum,
875  Drv::DataBuffer& buff
876  )
877  {
878  FW_ASSERT(
879  portNum < this->getNum_BufferOut_OutputPorts(),
880  static_cast<FwAssertArgType>(portNum)
881  );
882  this->m_BufferOut_OutputPort[portNum].invoke(
883  buff
884  );
885  }
886 
889  NATIVE_INT_TYPE portNum,
890  Svc::TimerVal& cycleStart
891  )
892  {
893  FW_ASSERT(
894  portNum < this->getNum_CycleOut_OutputPorts(),
895  static_cast<FwAssertArgType>(portNum)
896  );
897  this->m_CycleOut_OutputPort[portNum].invoke(
898  cycleStart
899  );
900  }
901 
904  NATIVE_INT_TYPE portNum,
905  U32 key
906  )
907  {
908  FW_ASSERT(
909  portNum < this->getNum_PingOut_OutputPorts(),
910  static_cast<FwAssertArgType>(portNum)
911  );
912  this->m_PingOut_OutputPort[portNum].invoke(
913  key
914  );
915  }
916 
917  // ----------------------------------------------------------------------
918  // Internal interface base-class functions
919  // ----------------------------------------------------------------------
920 
923  {
924  ComponentIpcSerializableBuffer msg;
926 
927  // Serialize the message ID
928  _status = msg.serialize(static_cast<NATIVE_INT_TYPE>(INT_IF_INTERRUPTREPORT));
929  FW_ASSERT (
930  _status == Fw::FW_SERIALIZE_OK,
931  static_cast<FwAssertArgType>(_status)
932  );
933 
934  // Fake port number to make message dequeue work
935  _status = msg.serialize(static_cast<NATIVE_INT_TYPE>(0));
936  FW_ASSERT (
937  _status == Fw::FW_SERIALIZE_OK,
938  static_cast<FwAssertArgType>(_status)
939  );
940 
941  _status = msg.serialize(interrupt);
942  FW_ASSERT(
943  _status == Fw::FW_SERIALIZE_OK,
944  static_cast<FwAssertArgType>(_status)
945  );
946 
947  // Send message
949  Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 1, _block);
950 
951  FW_ASSERT(
952  qStatus == Os::Queue::QUEUE_OK,
953  static_cast<FwAssertArgType>(qStatus)
954  );
955  }
956 
957  // ----------------------------------------------------------------------
958  // Telemetry write functions
959  // ----------------------------------------------------------------------
960 
963  U32 arg,
964  Fw::Time _tlmTime
965  )
966  {
967  if (this->m_Tlm_OutputPort[0].isConnected()) {
968  if (
969  this->m_Time_OutputPort[0].isConnected() &&
970  (_tlmTime == Fw::ZERO_TIME)
971  ) {
972  this->m_Time_OutputPort[0].invoke(_tlmTime);
973  }
974 
975  Fw::TlmBuffer _tlmBuff;
976  Fw::SerializeStatus _stat = _tlmBuff.serialize(arg);
977  FW_ASSERT(
978  _stat == Fw::FW_SERIALIZE_OK,
979  static_cast<FwAssertArgType>(_stat)
980  );
981 
982  FwChanIdType _id;
983 
984  _id = this->getIdBase() + CHANNELID_BD_CYCLES;
985 
986  this->m_Tlm_OutputPort[0].invoke(
987  _id,
988  _tlmTime,
989  _tlmBuff
990  );
991  }
992  }
993 
994  // ----------------------------------------------------------------------
995  // Time
996  // ----------------------------------------------------------------------
997 
999  getTime()
1000  {
1001  if (this->m_Time_OutputPort[0].isConnected()) {
1002  Fw::Time _time;
1003  this->m_Time_OutputPort[0].invoke(_time);
1004  return _time;
1005  }
1006  else {
1007  return Fw::Time(TB_NONE, 0, 0);
1008  }
1009  }
1010 
1011  // ----------------------------------------------------------------------
1012  // Message dispatch functions
1013  // ----------------------------------------------------------------------
1014 
1015  Fw::QueuedComponentBase::MsgDispatchStatus BlockDriverComponentBase ::
1016  doDispatch()
1017  {
1018  ComponentIpcSerializableBuffer msg;
1019  NATIVE_INT_TYPE priority = 0;
1020 
1021  Os::Queue::QueueStatus msgStatus = this->m_queue.receive(
1022  msg,
1023  priority,
1025  );
1026  FW_ASSERT(
1027  msgStatus == Os::Queue::QUEUE_OK,
1028  static_cast<FwAssertArgType>(msgStatus)
1029  );
1030 
1031  // Reset to beginning of buffer
1032  msg.resetDeser();
1033 
1034  NATIVE_INT_TYPE desMsg = 0;
1035  Fw::SerializeStatus deserStatus = msg.deserialize(desMsg);
1036  FW_ASSERT(
1037  deserStatus == Fw::FW_SERIALIZE_OK,
1038  static_cast<FwAssertArgType>(deserStatus)
1039  );
1040 
1041  MsgTypeEnum msgType = static_cast<MsgTypeEnum>(desMsg);
1042 
1043  if (msgType == BLOCKDRIVER_COMPONENT_EXIT) {
1044  return MSG_DISPATCH_EXIT;
1045  }
1046 
1047  NATIVE_INT_TYPE portNum = 0;
1048  deserStatus = msg.deserialize(portNum);
1049  FW_ASSERT(
1050  deserStatus == Fw::FW_SERIALIZE_OK,
1051  static_cast<FwAssertArgType>(deserStatus)
1052  );
1053 
1054  switch (msgType) {
1055  // Handle async input port BufferIn
1056  case BUFFERIN_DATABUFFER: {
1057  // Deserialize argument buff
1058  Drv::DataBuffer buff;
1059  deserStatus = msg.deserialize(buff);
1060  FW_ASSERT(
1061  deserStatus == Fw::FW_SERIALIZE_OK,
1062  static_cast<FwAssertArgType>(deserStatus)
1063  );
1064  // Call handler function
1065  this->BufferIn_handler(
1066  portNum,
1067  buff
1068  );
1069 
1070  break;
1071  }
1072 
1073  // Handle async input port PingIn
1074  case PINGIN_PING: {
1075  // Deserialize argument key
1076  U32 key;
1077  deserStatus = msg.deserialize(key);
1078  FW_ASSERT(
1079  deserStatus == Fw::FW_SERIALIZE_OK,
1080  static_cast<FwAssertArgType>(deserStatus)
1081  );
1082  // Call handler function
1083  this->PingIn_handler(
1084  portNum,
1085  key
1086  );
1087 
1088  break;
1089  }
1090 
1091  // Handle async input port Sched
1092  case SCHED_SCHED: {
1093  // Deserialize argument context
1094  NATIVE_UINT_TYPE context;
1095  deserStatus = msg.deserialize(context);
1096  FW_ASSERT(
1097  deserStatus == Fw::FW_SERIALIZE_OK,
1098  static_cast<FwAssertArgType>(deserStatus)
1099  );
1100  // Call handler function
1101  this->Sched_handler(
1102  portNum,
1103  context
1104  );
1105 
1106  break;
1107  }
1108 
1109  // Handle internal interface InterruptReport
1110  case INT_IF_INTERRUPTREPORT: {
1111  U32 interrupt;
1112  deserStatus = msg.deserialize(interrupt);
1113 
1114  // Internal interface should always deserialize
1115  FW_ASSERT(
1116  Fw::FW_SERIALIZE_OK == deserStatus,
1117  static_cast<FwAssertArgType>(deserStatus)
1118  );
1119 
1120  // Make sure there was no data left over.
1121  // That means the buffer size was incorrect.
1122  FW_ASSERT(
1123  msg.getBuffLeft() == 0,
1124  static_cast<FwAssertArgType>(msg.getBuffLeft())
1125  );
1126 
1127  // Call handler function
1129  interrupt
1130  );
1131 
1132  break;
1133  }
1134 
1135  default:
1136  return MSG_DISPATCH_ERROR;
1137  }
1138 
1139  return MSG_DISPATCH_OK;
1140  }
1141 
1142  // ----------------------------------------------------------------------
1143  // Calls for messages received on typed input ports
1144  // ----------------------------------------------------------------------
1145 
1146  void BlockDriverComponentBase ::
1147  m_p_BufferIn_in(
1148  Fw::PassiveComponentBase* callComp,
1149  NATIVE_INT_TYPE portNum,
1150  Drv::DataBuffer& buff
1151  )
1152  {
1153  FW_ASSERT(callComp);
1154  BlockDriverComponentBase* compPtr = static_cast<BlockDriverComponentBase*>(callComp);
1155  compPtr->BufferIn_handlerBase(
1156  portNum,
1157  buff
1158  );
1159  }
1160 
1161  void BlockDriverComponentBase ::
1162  m_p_PingIn_in(
1163  Fw::PassiveComponentBase* callComp,
1164  NATIVE_INT_TYPE portNum,
1165  U32 key
1166  )
1167  {
1168  FW_ASSERT(callComp);
1169  BlockDriverComponentBase* compPtr = static_cast<BlockDriverComponentBase*>(callComp);
1170  compPtr->PingIn_handlerBase(
1171  portNum,
1172  key
1173  );
1174  }
1175 
1176  void BlockDriverComponentBase ::
1177  m_p_Sched_in(
1178  Fw::PassiveComponentBase* callComp,
1179  NATIVE_INT_TYPE portNum,
1180  NATIVE_UINT_TYPE context
1181  )
1182  {
1183  FW_ASSERT(callComp);
1184  BlockDriverComponentBase* compPtr = static_cast<BlockDriverComponentBase*>(callComp);
1185  compPtr->Sched_handlerBase(
1186  portNum,
1187  context
1188  );
1189  }
1190 
1191 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:51
U8 BYTE
byte type
Definition: BasicTypes.h:27
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:26
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:66
PlatformUIntType NATIVE_UINT_TYPE
Definition: BasicTypes.h:52
BYTE PingInPortSize[Svc::InputPingPort::SERIALIZED_SIZE]
BYTE InterruptReportIntIfSize[sizeof(U32)]
BYTE BufferInPortSize[Drv::InputDataBufferPort::SERIALIZED_SIZE]
BYTE SchedPortSize[Svc::InputSchedPort::SERIALIZED_SIZE]
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
#define PRI_PlatformIntType
@ TB_NONE
No time base has been established.
Definition: FpConfig.h:39
PlatformAssertArgType FwAssertArgType
Definition: FpConfig.h:21
U32 FwChanIdType
Definition: FpConfig.h:59
#define FW_OBJ_NAME_MAX_SIZE
Size of object name (if object names enabled). AC Limits to 80, truncation occurs above 80.
Definition: FpConfig.h:184
void set_PingOut_OutputPort(NATIVE_INT_TYPE portNum, Svc::InputPingPort *port)
Connect port to PingOut[portNum].
void CycleOut_out(NATIVE_INT_TYPE portNum, Svc::TimerVal &cycleStart)
Invoke output port CycleOut.
bool isConnected_CycleOut_OutputPort(NATIVE_INT_TYPE portNum)
NATIVE_INT_TYPE getNum_BufferOut_OutputPorts() const
void set_CycleOut_OutputPort(NATIVE_INT_TYPE portNum, Svc::InputCyclePort *port)
Connect port to CycleOut[portNum].
virtual void PingIn_preMsgHook(NATIVE_INT_TYPE portNum, U32 key)
Pre-message hook for async input port PingIn.
bool isConnected_Tlm_OutputPort(NATIVE_INT_TYPE portNum)
bool isConnected_Time_OutputPort(NATIVE_INT_TYPE portNum)
NATIVE_INT_TYPE getNum_Tlm_OutputPorts() const
void tlmWrite_BD_Cycles(U32 arg, Fw::Time _tlmTime=Fw::Time())
bool isConnected_BufferOut_OutputPort(NATIVE_INT_TYPE portNum)
NATIVE_INT_TYPE getNum_CycleOut_OutputPorts() const
void InterruptReport_internalInterfaceInvoke(U32 interrupt)
Internal interface base-class function for InterruptReport.
@ CHANNELID_BD_CYCLES
Channel ID for BD_Cycles.
virtual void PingIn_handler(NATIVE_INT_TYPE portNum, U32 key)=0
Handler for input port PingIn.
virtual void Sched_handler(NATIVE_INT_TYPE portNum, NATIVE_UINT_TYPE context)=0
Handler for input port Sched.
void BufferOut_out(NATIVE_INT_TYPE portNum, Drv::DataBuffer &buff)
Invoke output port BufferOut.
BlockDriverComponentBase(const char *compName="")
Construct BlockDriverComponentBase object.
NATIVE_INT_TYPE getNum_PingIn_InputPorts() const
NATIVE_INT_TYPE getNum_PingOut_OutputPorts() const
void set_Tlm_OutputPort(NATIVE_INT_TYPE portNum, Fw::InputTlmPort *port)
Connect port to Tlm[portNum].
NATIVE_INT_TYPE getNum_Time_OutputPorts() const
void set_BufferOut_OutputPort(NATIVE_INT_TYPE portNum, Drv::InputDataBufferPort *port)
Connect port to BufferOut[portNum].
NATIVE_INT_TYPE getNum_Sched_InputPorts() const
virtual void InterruptReport_internalInterfaceHandler(U32 interrupt)=0
Internal interface handler for InterruptReport.
void Sched_handlerBase(NATIVE_INT_TYPE portNum, NATIVE_UINT_TYPE context)
Handler base-class function for input port Sched.
void BufferIn_handlerBase(NATIVE_INT_TYPE portNum, Drv::DataBuffer &buff)
Handler base-class function for input port BufferIn.
virtual void BufferIn_preMsgHook(NATIVE_INT_TYPE portNum, Drv::DataBuffer &buff)
Pre-message hook for async input port BufferIn.
NATIVE_INT_TYPE getNum_BufferIn_InputPorts() const
virtual ~BlockDriverComponentBase()
Destroy BlockDriverComponentBase object.
bool isConnected_PingOut_OutputPort(NATIVE_INT_TYPE portNum)
Svc::InputSchedPort * get_Sched_InputPort(NATIVE_INT_TYPE portNum)
Svc::InputPingPort * get_PingIn_InputPort(NATIVE_INT_TYPE portNum)
void PingOut_out(NATIVE_INT_TYPE portNum, U32 key)
Invoke output port PingOut.
void PingIn_handlerBase(NATIVE_INT_TYPE portNum, U32 key)
Handler base-class function for input port PingIn.
virtual void Sched_preMsgHook(NATIVE_INT_TYPE portNum, NATIVE_UINT_TYPE context)
Pre-message hook for async input port Sched.
virtual void BufferIn_handler(NATIVE_INT_TYPE portNum, Drv::DataBuffer &buff)=0
Handler for input port BufferIn.
Drv::InputDataBufferPort * get_BufferIn_InputPort(NATIVE_INT_TYPE portNum)
void set_Time_OutputPort(NATIVE_INT_TYPE portNum, Fw::InputTimePort *port)
Connect port to Time[portNum].
@ SERIALIZED_SIZE
The size of the serial representations of the port arguments.
void init()
Initialization function.
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
void addCallPort(InputDataBufferPort *callPort)
Register an input port.
void invoke(Drv::DataBuffer &buff)
Invoke a port interface.
void init()
Initialization function.
@ ACTIVE_COMPONENT_EXIT
message to exit active component task
void setPortNum(NATIVE_INT_TYPE portNum)
void init()
Object initializer.
Definition: ObjBase.cpp:27
void addCallPort(InputTimePort *callPort)
Register an input port.
Definition: TimePortAc.cpp:134
void invoke(Fw::Time &time)
Invoke a port interface.
Definition: TimePortAc.cpp:147
void init()
Initialization function.
Definition: TimePortAc.cpp:128
void addCallPort(InputTlmPort *callPort)
Register an input port.
Definition: TlmPortAc.cpp:150
void init()
Initialization function.
Definition: TlmPortAc.cpp:144
void invoke(FwChanIdType id, Fw::Time &timeTag, Fw::TlmBuffer &val)
Invoke a port interface.
Definition: TlmPortAc.cpp:163
bool isConnected()
Definition: PortBase.cpp:41
Os::Queue::QueueStatus createQueue(NATIVE_INT_TYPE depth, NATIVE_INT_TYPE msgSize)
Os::Queue m_queue
queue object for active component
@ MSG_DISPATCH_OK
Dispatch was normal.
@ MSG_DISPATCH_EXIT
A message was sent requesting an exit of the loop.
@ MSG_DISPATCH_ERROR
Errors dispatching messages.
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
Definition: Time.hpp:9
QueueStatus
Definition: Queue.hpp:27
@ QUEUE_OK
message sent/received okay
Definition: Queue.hpp:28
QueueStatus send(const Fw::SerializeBufferBase &buffer, NATIVE_INT_TYPE priority, QueueBlocking block)
send a message
Definition: QueueCommon.cpp:13
QueueStatus receive(Fw::SerializeBufferBase &buffer, NATIVE_INT_TYPE &priority, QueueBlocking block)
receive a message
Definition: QueueCommon.cpp:22
QueueBlocking
Definition: Queue.hpp:40
@ QUEUE_BLOCKING
Queue receive blocks until a message arrives.
Definition: Queue.hpp:41
@ QUEUE_NONBLOCKING
Queue receive always returns even if there is no message.
Definition: Queue.hpp:42
@ SERIALIZED_SIZE
The size of the serial representations of the port arguments.
Definition: PingPortAc.hpp:36
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
Definition: PingPortAc.cpp:62
void init()
Initialization function.
Definition: PingPortAc.cpp:56
@ SERIALIZED_SIZE
The size of the serial representations of the port arguments.
Definition: SchedPortAc.hpp:36
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
Definition: SchedPortAc.cpp:62
void init()
Initialization function.
Definition: SchedPortAc.cpp:56
void init()
Initialization function.
void addCallPort(InputCyclePort *callPort)
Register an input port.
void invoke(Svc::TimerVal &cycleStart)
Invoke a port interface.
void invoke(U32 key)
Invoke a port interface.
Definition: PingPortAc.cpp:147
void init()
Initialization function.
Definition: PingPortAc.cpp:128
void addCallPort(InputPingPort *callPort)
Register an input port.
Definition: PingPortAc.cpp:134
Serializable class for carrying timer values.
Definition: TimerVal.hpp:22
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
const Time ZERO_TIME
Definition: Time.cpp:5