F´ Flight Software - C/C++ Documentation devel
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
15namespace 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
77 void BlockDriverComponentBase ::
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 char portName[120];
101 (void) snprintf(
102 portName,
103 sizeof(portName),
104 "%s_BufferIn_InputPort[%" PRI_PlatformIntType "]",
105 this->m_objName,
106 port
107 );
108 this->m_BufferIn_InputPort[port].setObjName(portName);
109#endif
110 }
111
112 // Connect input port PingIn
113 for (
114 PlatformIntType port = 0;
115 port < static_cast<PlatformIntType>(this->getNum_PingIn_InputPorts());
116 port++
117 ) {
118 this->m_PingIn_InputPort[port].init();
119 this->m_PingIn_InputPort[port].addCallComp(
120 this,
121 m_p_PingIn_in
122 );
123 this->m_PingIn_InputPort[port].setPortNum(port);
124
125#if FW_OBJECT_NAMES == 1
126 char portName[120];
127 (void) snprintf(
128 portName,
129 sizeof(portName),
130 "%s_PingIn_InputPort[%" PRI_PlatformIntType "]",
131 this->m_objName,
132 port
133 );
134 this->m_PingIn_InputPort[port].setObjName(portName);
135#endif
136 }
137
138 // Connect input port Sched
139 for (
140 PlatformIntType port = 0;
141 port < static_cast<PlatformIntType>(this->getNum_Sched_InputPorts());
142 port++
143 ) {
144 this->m_Sched_InputPort[port].init();
145 this->m_Sched_InputPort[port].addCallComp(
146 this,
147 m_p_Sched_in
148 );
149 this->m_Sched_InputPort[port].setPortNum(port);
150
151#if FW_OBJECT_NAMES == 1
152 char portName[120];
153 (void) snprintf(
154 portName,
155 sizeof(portName),
156 "%s_Sched_InputPort[%" PRI_PlatformIntType "]",
157 this->m_objName,
158 port
159 );
160 this->m_Sched_InputPort[port].setObjName(portName);
161#endif
162 }
163
164 // Connect output port Time
165 for (
166 PlatformIntType port = 0;
167 port < static_cast<PlatformIntType>(this->getNum_Time_OutputPorts());
168 port++
169 ) {
170 this->m_Time_OutputPort[port].init();
171
172#if FW_OBJECT_NAMES == 1
173 char portName[120];
174 (void) snprintf(
175 portName,
176 sizeof(portName),
177 "%s_Time_OutputPort[%" PRI_PlatformIntType "]",
178 this->m_objName,
179 port
180 );
181 this->m_Time_OutputPort[port].setObjName(portName);
182#endif
183 }
184
185 // Connect output port Tlm
186 for (
187 PlatformIntType port = 0;
188 port < static_cast<PlatformIntType>(this->getNum_Tlm_OutputPorts());
189 port++
190 ) {
191 this->m_Tlm_OutputPort[port].init();
192
193#if FW_OBJECT_NAMES == 1
194 char portName[120];
195 (void) snprintf(
196 portName,
197 sizeof(portName),
198 "%s_Tlm_OutputPort[%" PRI_PlatformIntType "]",
199 this->m_objName,
200 port
201 );
202 this->m_Tlm_OutputPort[port].setObjName(portName);
203#endif
204 }
205
206 // Connect output port BufferOut
207 for (
208 PlatformIntType port = 0;
209 port < static_cast<PlatformIntType>(this->getNum_BufferOut_OutputPorts());
210 port++
211 ) {
212 this->m_BufferOut_OutputPort[port].init();
213
214#if FW_OBJECT_NAMES == 1
215 char portName[120];
216 (void) snprintf(
217 portName,
218 sizeof(portName),
219 "%s_BufferOut_OutputPort[%" PRI_PlatformIntType "]",
220 this->m_objName,
221 port
222 );
223 this->m_BufferOut_OutputPort[port].setObjName(portName);
224#endif
225 }
226
227 // Connect output port CycleOut
228 for (
229 PlatformIntType port = 0;
230 port < static_cast<PlatformIntType>(this->getNum_CycleOut_OutputPorts());
231 port++
232 ) {
233 this->m_CycleOut_OutputPort[port].init();
234
235#if FW_OBJECT_NAMES == 1
236 char portName[120];
237 (void) snprintf(
238 portName,
239 sizeof(portName),
240 "%s_CycleOut_OutputPort[%" PRI_PlatformIntType "]",
241 this->m_objName,
242 port
243 );
244 this->m_CycleOut_OutputPort[port].setObjName(portName);
245#endif
246 }
247
248 // Connect output port PingOut
249 for (
250 PlatformIntType port = 0;
251 port < static_cast<PlatformIntType>(this->getNum_PingOut_OutputPorts());
252 port++
253 ) {
254 this->m_PingOut_OutputPort[port].init();
255
256#if FW_OBJECT_NAMES == 1
257 char portName[120];
258 (void) snprintf(
259 portName,
260 sizeof(portName),
261 "%s_PingOut_OutputPort[%" PRI_PlatformIntType "]",
262 this->m_objName,
263 port
264 );
265 this->m_PingOut_OutputPort[port].setObjName(portName);
266#endif
267 }
268
269 Os::Queue::QueueStatus qStat = this->createQueue(
270 queueDepth,
271 ComponentIpcSerializableBuffer::SERIALIZATION_SIZE
272 );
273 FW_ASSERT(
274 Os::Queue::QUEUE_OK == qStat,
275 static_cast<FwAssertArgType>(qStat)
276 );
277 }
278
279 // ----------------------------------------------------------------------
280 // Getters for typed input ports
281 // ----------------------------------------------------------------------
282
283 Drv::InputDataBufferPort* BlockDriverComponentBase ::
284 get_BufferIn_InputPort(NATIVE_INT_TYPE portNum)
285 {
286 FW_ASSERT(
287 portNum < this->getNum_BufferIn_InputPorts(),
288 static_cast<FwAssertArgType>(portNum)
289 );
290
291 return &this->m_BufferIn_InputPort[portNum];
292 }
293
294 Svc::InputPingPort* BlockDriverComponentBase ::
295 get_PingIn_InputPort(NATIVE_INT_TYPE portNum)
296 {
297 FW_ASSERT(
298 portNum < this->getNum_PingIn_InputPorts(),
299 static_cast<FwAssertArgType>(portNum)
300 );
301
302 return &this->m_PingIn_InputPort[portNum];
303 }
304
305 Svc::InputSchedPort* BlockDriverComponentBase ::
306 get_Sched_InputPort(NATIVE_INT_TYPE portNum)
307 {
308 FW_ASSERT(
309 portNum < this->getNum_Sched_InputPorts(),
310 static_cast<FwAssertArgType>(portNum)
311 );
312
313 return &this->m_Sched_InputPort[portNum];
314 }
315
316 // ----------------------------------------------------------------------
317 // Connect input ports to special output ports
318 // ----------------------------------------------------------------------
319
320 void BlockDriverComponentBase ::
321 set_Time_OutputPort(
322 NATIVE_INT_TYPE portNum,
324 )
325 {
326 FW_ASSERT(
327 portNum < this->getNum_Time_OutputPorts(),
328 static_cast<FwAssertArgType>(portNum)
329 );
330
331 this->m_Time_OutputPort[portNum].addCallPort(port);
332 }
333
334 void BlockDriverComponentBase ::
335 set_Tlm_OutputPort(
336 NATIVE_INT_TYPE portNum,
337 Fw::InputTlmPort* port
338 )
339 {
340 FW_ASSERT(
341 portNum < this->getNum_Tlm_OutputPorts(),
342 static_cast<FwAssertArgType>(portNum)
343 );
344
345 this->m_Tlm_OutputPort[portNum].addCallPort(port);
346 }
347
348 // ----------------------------------------------------------------------
349 // Connect typed input ports to typed output ports
350 // ----------------------------------------------------------------------
351
352 void BlockDriverComponentBase ::
353 set_BufferOut_OutputPort(
354 NATIVE_INT_TYPE portNum,
356 )
357 {
358 FW_ASSERT(
359 portNum < this->getNum_BufferOut_OutputPorts(),
360 static_cast<FwAssertArgType>(portNum)
361 );
362
363 this->m_BufferOut_OutputPort[portNum].addCallPort(port);
364 }
365
366 void BlockDriverComponentBase ::
367 set_CycleOut_OutputPort(
368 NATIVE_INT_TYPE portNum,
370 )
371 {
372 FW_ASSERT(
373 portNum < this->getNum_CycleOut_OutputPorts(),
374 static_cast<FwAssertArgType>(portNum)
375 );
376
377 this->m_CycleOut_OutputPort[portNum].addCallPort(port);
378 }
379
380 void BlockDriverComponentBase ::
381 set_PingOut_OutputPort(
382 NATIVE_INT_TYPE portNum,
384 )
385 {
386 FW_ASSERT(
387 portNum < this->getNum_PingOut_OutputPorts(),
388 static_cast<FwAssertArgType>(portNum)
389 );
390
391 this->m_PingOut_OutputPort[portNum].addCallPort(port);
392 }
393
394#if FW_PORT_SERIALIZATION
395
396 // ----------------------------------------------------------------------
397 // Connect serial input ports to special output ports
398 // ----------------------------------------------------------------------
399
400 void BlockDriverComponentBase ::
401 set_Time_OutputPort(
402 NATIVE_INT_TYPE portNum,
403 Fw::InputSerializePort* port
404 )
405 {
406 FW_ASSERT(
407 portNum < this->getNum_Time_OutputPorts(),
408 static_cast<FwAssertArgType>(portNum)
409 );
410
411 this->m_Time_OutputPort[portNum].registerSerialPort(port);
412 }
413
414 void BlockDriverComponentBase ::
415 set_Tlm_OutputPort(
416 NATIVE_INT_TYPE portNum,
417 Fw::InputSerializePort* port
418 )
419 {
420 FW_ASSERT(
421 portNum < this->getNum_Tlm_OutputPorts(),
422 static_cast<FwAssertArgType>(portNum)
423 );
424
425 this->m_Tlm_OutputPort[portNum].registerSerialPort(port);
426 }
427
428#endif
429
430#if FW_PORT_SERIALIZATION
431
432 // ----------------------------------------------------------------------
433 // Connect serial input ports to typed output ports
434 // ----------------------------------------------------------------------
435
436 void BlockDriverComponentBase ::
437 set_BufferOut_OutputPort(
438 NATIVE_INT_TYPE portNum,
439 Fw::InputSerializePort* port
440 )
441 {
442 FW_ASSERT(
443 portNum < this->getNum_BufferOut_OutputPorts(),
444 static_cast<FwAssertArgType>(portNum)
445 );
446
447 this->m_BufferOut_OutputPort[portNum].registerSerialPort(port);
448 }
449
450 void BlockDriverComponentBase ::
451 set_CycleOut_OutputPort(
452 NATIVE_INT_TYPE portNum,
453 Fw::InputSerializePort* port
454 )
455 {
456 FW_ASSERT(
457 portNum < this->getNum_CycleOut_OutputPorts(),
458 static_cast<FwAssertArgType>(portNum)
459 );
460
461 this->m_CycleOut_OutputPort[portNum].registerSerialPort(port);
462 }
463
464 void BlockDriverComponentBase ::
465 set_PingOut_OutputPort(
466 NATIVE_INT_TYPE portNum,
467 Fw::InputSerializePort* port
468 )
469 {
470 FW_ASSERT(
471 portNum < this->getNum_PingOut_OutputPorts(),
472 static_cast<FwAssertArgType>(portNum)
473 );
474
475 this->m_PingOut_OutputPort[portNum].registerSerialPort(port);
476 }
477
478#endif
479
480 // ----------------------------------------------------------------------
481 // Component construction and destruction
482 // ----------------------------------------------------------------------
483
484 BlockDriverComponentBase ::
485 BlockDriverComponentBase(const char* compName) :
486 Fw::ActiveComponentBase(compName)
487 {
488
489 }
490
491 BlockDriverComponentBase ::
492 ~BlockDriverComponentBase()
493 {
494
495 }
496
497 // ----------------------------------------------------------------------
498 // Getters for numbers of typed input ports
499 // ----------------------------------------------------------------------
500
501 NATIVE_INT_TYPE BlockDriverComponentBase ::
502 getNum_BufferIn_InputPorts() const
503 {
504 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_BufferIn_InputPort));
505 }
506
507 NATIVE_INT_TYPE BlockDriverComponentBase ::
508 getNum_PingIn_InputPorts() const
509 {
510 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_PingIn_InputPort));
511 }
512
513 NATIVE_INT_TYPE BlockDriverComponentBase ::
514 getNum_Sched_InputPorts() const
515 {
516 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_Sched_InputPort));
517 }
518
519 // ----------------------------------------------------------------------
520 // Getters for numbers of special output ports
521 // ----------------------------------------------------------------------
522
523 NATIVE_INT_TYPE BlockDriverComponentBase ::
524 getNum_Time_OutputPorts() const
525 {
526 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_Time_OutputPort));
527 }
528
529 NATIVE_INT_TYPE BlockDriverComponentBase ::
530 getNum_Tlm_OutputPorts() const
531 {
532 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_Tlm_OutputPort));
533 }
534
535 // ----------------------------------------------------------------------
536 // Getters for numbers of typed output ports
537 // ----------------------------------------------------------------------
538
539 NATIVE_INT_TYPE BlockDriverComponentBase ::
540 getNum_BufferOut_OutputPorts() const
541 {
542 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_BufferOut_OutputPort));
543 }
544
545 NATIVE_INT_TYPE BlockDriverComponentBase ::
546 getNum_CycleOut_OutputPorts() const
547 {
548 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_CycleOut_OutputPort));
549 }
550
551 NATIVE_INT_TYPE BlockDriverComponentBase ::
552 getNum_PingOut_OutputPorts() const
553 {
554 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_PingOut_OutputPort));
555 }
556
557 // ----------------------------------------------------------------------
558 // Connection status queries for special output ports
559 // ----------------------------------------------------------------------
560
561 bool BlockDriverComponentBase ::
562 isConnected_Time_OutputPort(NATIVE_INT_TYPE portNum)
563 {
564 FW_ASSERT(
565 portNum < this->getNum_Time_OutputPorts(),
566 static_cast<FwAssertArgType>(portNum)
567 );
568
569 return this->m_Time_OutputPort[portNum].isConnected();
570 }
571
572 bool BlockDriverComponentBase ::
573 isConnected_Tlm_OutputPort(NATIVE_INT_TYPE portNum)
574 {
575 FW_ASSERT(
576 portNum < this->getNum_Tlm_OutputPorts(),
577 static_cast<FwAssertArgType>(portNum)
578 );
579
580 return this->m_Tlm_OutputPort[portNum].isConnected();
581 }
582
583 // ----------------------------------------------------------------------
584 // Connection status queries for typed output ports
585 // ----------------------------------------------------------------------
586
587 bool BlockDriverComponentBase ::
588 isConnected_BufferOut_OutputPort(NATIVE_INT_TYPE portNum)
589 {
590 FW_ASSERT(
591 portNum < this->getNum_BufferOut_OutputPorts(),
592 static_cast<FwAssertArgType>(portNum)
593 );
594
595 return this->m_BufferOut_OutputPort[portNum].isConnected();
596 }
597
598 bool BlockDriverComponentBase ::
599 isConnected_CycleOut_OutputPort(NATIVE_INT_TYPE portNum)
600 {
601 FW_ASSERT(
602 portNum < this->getNum_CycleOut_OutputPorts(),
603 static_cast<FwAssertArgType>(portNum)
604 );
605
606 return this->m_CycleOut_OutputPort[portNum].isConnected();
607 }
608
609 bool BlockDriverComponentBase ::
610 isConnected_PingOut_OutputPort(NATIVE_INT_TYPE portNum)
611 {
612 FW_ASSERT(
613 portNum < this->getNum_PingOut_OutputPorts(),
614 static_cast<FwAssertArgType>(portNum)
615 );
616
617 return this->m_PingOut_OutputPort[portNum].isConnected();
618 }
619
620 // ----------------------------------------------------------------------
621 // Port handler base-class functions for typed input ports
622 //
623 // Call these functions directly to bypass the corresponding ports
624 // ----------------------------------------------------------------------
625
626 void BlockDriverComponentBase ::
627 BufferIn_handlerBase(
628 NATIVE_INT_TYPE portNum,
629 Drv::DataBuffer& buff
630 )
631 {
632 // Make sure port number is valid
633 FW_ASSERT(
634 portNum < this->getNum_BufferIn_InputPorts(),
635 static_cast<FwAssertArgType>(portNum)
636 );
637
638 // Call pre-message hook
639 BufferIn_preMsgHook(
640 portNum,
641 buff
642 );
643 ComponentIpcSerializableBuffer msg;
645
646 // Serialize message ID
647 _status = msg.serialize(
648 static_cast<NATIVE_INT_TYPE>(BUFFERIN_DATABUFFER)
649 );
650 FW_ASSERT(
651 _status == Fw::FW_SERIALIZE_OK,
652 static_cast<FwAssertArgType>(_status)
653 );
654
655 // Serialize port number
656 _status = msg.serialize(portNum);
657 FW_ASSERT(
658 _status == Fw::FW_SERIALIZE_OK,
659 static_cast<FwAssertArgType>(_status)
660 );
661
662 // Serialize argument buff
663 _status = msg.serialize(buff);
664 FW_ASSERT(
665 _status == Fw::FW_SERIALIZE_OK,
666 static_cast<FwAssertArgType>(_status)
667 );
668
669 // Send message
671 Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 0, _block);
672
673 FW_ASSERT(
674 qStatus == Os::Queue::QUEUE_OK,
675 static_cast<FwAssertArgType>(qStatus)
676 );
677 }
678
679 void BlockDriverComponentBase ::
680 PingIn_handlerBase(
681 NATIVE_INT_TYPE portNum,
682 U32 key
683 )
684 {
685 // Make sure port number is valid
686 FW_ASSERT(
687 portNum < this->getNum_PingIn_InputPorts(),
688 static_cast<FwAssertArgType>(portNum)
689 );
690
691 // Call pre-message hook
692 PingIn_preMsgHook(
693 portNum,
694 key
695 );
696 ComponentIpcSerializableBuffer msg;
698
699 // Serialize message ID
700 _status = msg.serialize(
701 static_cast<NATIVE_INT_TYPE>(PINGIN_PING)
702 );
703 FW_ASSERT(
704 _status == Fw::FW_SERIALIZE_OK,
705 static_cast<FwAssertArgType>(_status)
706 );
707
708 // Serialize port number
709 _status = msg.serialize(portNum);
710 FW_ASSERT(
711 _status == Fw::FW_SERIALIZE_OK,
712 static_cast<FwAssertArgType>(_status)
713 );
714
715 // Serialize argument key
716 _status = msg.serialize(key);
717 FW_ASSERT(
718 _status == Fw::FW_SERIALIZE_OK,
719 static_cast<FwAssertArgType>(_status)
720 );
721
722 // Send message
724 Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 0, _block);
725
726 FW_ASSERT(
727 qStatus == Os::Queue::QUEUE_OK,
728 static_cast<FwAssertArgType>(qStatus)
729 );
730 }
731
732 void BlockDriverComponentBase ::
733 Sched_handlerBase(
734 NATIVE_INT_TYPE portNum,
735 NATIVE_UINT_TYPE context
736 )
737 {
738 // Make sure port number is valid
739 FW_ASSERT(
740 portNum < this->getNum_Sched_InputPorts(),
741 static_cast<FwAssertArgType>(portNum)
742 );
743
744 // Call pre-message hook
745 Sched_preMsgHook(
746 portNum,
747 context
748 );
749 ComponentIpcSerializableBuffer msg;
751
752 // Serialize message ID
753 _status = msg.serialize(
754 static_cast<NATIVE_INT_TYPE>(SCHED_SCHED)
755 );
756 FW_ASSERT(
757 _status == Fw::FW_SERIALIZE_OK,
758 static_cast<FwAssertArgType>(_status)
759 );
760
761 // Serialize port number
762 _status = msg.serialize(portNum);
763 FW_ASSERT(
764 _status == Fw::FW_SERIALIZE_OK,
765 static_cast<FwAssertArgType>(_status)
766 );
767
768 // Serialize argument context
769 _status = msg.serialize(context);
770 FW_ASSERT(
771 _status == Fw::FW_SERIALIZE_OK,
772 static_cast<FwAssertArgType>(_status)
773 );
774
775 // Send message
777 Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 0, _block);
778
779 FW_ASSERT(
780 qStatus == Os::Queue::QUEUE_OK,
781 static_cast<FwAssertArgType>(qStatus)
782 );
783 }
784
785 // ----------------------------------------------------------------------
786 // Pre-message hooks for typed async input ports
787 //
788 // Each of these functions is invoked just before processing a message
789 // on the corresponding port. By default, they do nothing. You can
790 // override them to provide specific pre-message behavior.
791 // ----------------------------------------------------------------------
792
793 void BlockDriverComponentBase ::
794 BufferIn_preMsgHook(
795 NATIVE_INT_TYPE portNum,
796 Drv::DataBuffer& buff
797 )
798 {
799 // Default: no-op
800 }
801
802 void BlockDriverComponentBase ::
803 PingIn_preMsgHook(
804 NATIVE_INT_TYPE portNum,
805 U32 key
806 )
807 {
808 // Default: no-op
809 }
810
811 void BlockDriverComponentBase ::
812 Sched_preMsgHook(
813 NATIVE_INT_TYPE portNum,
814 NATIVE_UINT_TYPE context
815 )
816 {
817 // Default: no-op
818 }
819
820 // ----------------------------------------------------------------------
821 // Invocation functions for typed output ports
822 // ----------------------------------------------------------------------
823
824 void BlockDriverComponentBase ::
825 BufferOut_out(
826 NATIVE_INT_TYPE portNum,
827 Drv::DataBuffer& buff
828 )
829 {
830 FW_ASSERT(
831 portNum < this->getNum_BufferOut_OutputPorts(),
832 static_cast<FwAssertArgType>(portNum)
833 );
834 this->m_BufferOut_OutputPort[portNum].invoke(
835 buff
836 );
837 }
838
839 void BlockDriverComponentBase ::
840 CycleOut_out(
841 NATIVE_INT_TYPE portNum,
842 Svc::TimerVal& cycleStart
843 )
844 {
845 FW_ASSERT(
846 portNum < this->getNum_CycleOut_OutputPorts(),
847 static_cast<FwAssertArgType>(portNum)
848 );
849 this->m_CycleOut_OutputPort[portNum].invoke(
850 cycleStart
851 );
852 }
853
854 void BlockDriverComponentBase ::
855 PingOut_out(
856 NATIVE_INT_TYPE portNum,
857 U32 key
858 )
859 {
860 FW_ASSERT(
861 portNum < this->getNum_PingOut_OutputPorts(),
862 static_cast<FwAssertArgType>(portNum)
863 );
864 this->m_PingOut_OutputPort[portNum].invoke(
865 key
866 );
867 }
868
869 // ----------------------------------------------------------------------
870 // Internal interface base-class functions
871 // ----------------------------------------------------------------------
872
873 void BlockDriverComponentBase ::
874 InterruptReport_internalInterfaceInvoke(U32 interrupt)
875 {
876 ComponentIpcSerializableBuffer msg;
878
879 // Serialize the message ID
880 _status = msg.serialize(static_cast<NATIVE_INT_TYPE>(INT_IF_INTERRUPTREPORT));
881 FW_ASSERT (
882 _status == Fw::FW_SERIALIZE_OK,
883 static_cast<FwAssertArgType>(_status)
884 );
885
886 // Fake port number to make message dequeue work
887 _status = msg.serialize(static_cast<NATIVE_INT_TYPE>(0));
888 FW_ASSERT (
889 _status == Fw::FW_SERIALIZE_OK,
890 static_cast<FwAssertArgType>(_status)
891 );
892
893 _status = msg.serialize(interrupt);
894 FW_ASSERT(
895 _status == Fw::FW_SERIALIZE_OK,
896 static_cast<FwAssertArgType>(_status)
897 );
898
899 // Send message
901 Os::Queue::QueueStatus qStatus = this->m_queue.send(msg, 1, _block);
902
903 FW_ASSERT(
904 qStatus == Os::Queue::QUEUE_OK,
905 static_cast<FwAssertArgType>(qStatus)
906 );
907 }
908
909 // ----------------------------------------------------------------------
910 // Telemetry write functions
911 // ----------------------------------------------------------------------
912
913 void BlockDriverComponentBase ::
914 tlmWrite_BD_Cycles(
915 U32 arg,
916 Fw::Time _tlmTime
917 )
918 {
919 if (this->m_Tlm_OutputPort[0].isConnected()) {
920 if (
921 this->m_Time_OutputPort[0].isConnected() &&
922 (_tlmTime == Fw::ZERO_TIME)
923 ) {
924 this->m_Time_OutputPort[0].invoke(_tlmTime);
925 }
926
927 Fw::TlmBuffer _tlmBuff;
928 Fw::SerializeStatus _stat = _tlmBuff.serialize(arg);
929 FW_ASSERT(
930 _stat == Fw::FW_SERIALIZE_OK,
931 static_cast<FwAssertArgType>(_stat)
932 );
933
934 FwChanIdType _id;
935
936 _id = this->getIdBase() + CHANNELID_BD_CYCLES;
937
938 this->m_Tlm_OutputPort[0].invoke(
939 _id,
940 _tlmTime,
941 _tlmBuff
942 );
943 }
944 }
945
946 // ----------------------------------------------------------------------
947 // Time
948 // ----------------------------------------------------------------------
949
950 Fw::Time BlockDriverComponentBase ::
951 getTime()
952 {
953 if (this->m_Time_OutputPort[0].isConnected()) {
954 Fw::Time _time;
955 this->m_Time_OutputPort[0].invoke(_time);
956 return _time;
957 }
958 else {
959 return Fw::Time(TB_NONE, 0, 0);
960 }
961 }
962
963 // ----------------------------------------------------------------------
964 // Message dispatch functions
965 // ----------------------------------------------------------------------
966
967 Fw::QueuedComponentBase::MsgDispatchStatus BlockDriverComponentBase ::
968 doDispatch()
969 {
970 ComponentIpcSerializableBuffer msg;
971 NATIVE_INT_TYPE priority = 0;
972
973 Os::Queue::QueueStatus msgStatus = this->m_queue.receive(
974 msg,
975 priority,
977 );
978 FW_ASSERT(
979 msgStatus == Os::Queue::QUEUE_OK,
980 static_cast<FwAssertArgType>(msgStatus)
981 );
982
983 // Reset to beginning of buffer
984 msg.resetDeser();
985
986 NATIVE_INT_TYPE desMsg = 0;
987 Fw::SerializeStatus deserStatus = msg.deserialize(desMsg);
988 FW_ASSERT(
989 deserStatus == Fw::FW_SERIALIZE_OK,
990 static_cast<FwAssertArgType>(deserStatus)
991 );
992
993 MsgTypeEnum msgType = static_cast<MsgTypeEnum>(desMsg);
994
995 if (msgType == BLOCKDRIVER_COMPONENT_EXIT) {
996 return MSG_DISPATCH_EXIT;
997 }
998
999 NATIVE_INT_TYPE portNum = 0;
1000 deserStatus = msg.deserialize(portNum);
1001 FW_ASSERT(
1002 deserStatus == Fw::FW_SERIALIZE_OK,
1003 static_cast<FwAssertArgType>(deserStatus)
1004 );
1005
1006 switch (msgType) {
1007 // Handle async input port BufferIn
1008 case BUFFERIN_DATABUFFER: {
1009 // Deserialize argument buff
1010 Drv::DataBuffer buff;
1011 deserStatus = msg.deserialize(buff);
1012 FW_ASSERT(
1013 deserStatus == Fw::FW_SERIALIZE_OK,
1014 static_cast<FwAssertArgType>(deserStatus)
1015 );
1016 // Call handler function
1017 this->BufferIn_handler(
1018 portNum,
1019 buff
1020 );
1021
1022 break;
1023 }
1024
1025 // Handle async input port PingIn
1026 case PINGIN_PING: {
1027 // Deserialize argument key
1028 U32 key;
1029 deserStatus = msg.deserialize(key);
1030 FW_ASSERT(
1031 deserStatus == Fw::FW_SERIALIZE_OK,
1032 static_cast<FwAssertArgType>(deserStatus)
1033 );
1034 // Call handler function
1035 this->PingIn_handler(
1036 portNum,
1037 key
1038 );
1039
1040 break;
1041 }
1042
1043 // Handle async input port Sched
1044 case SCHED_SCHED: {
1045 // Deserialize argument context
1046 NATIVE_UINT_TYPE context;
1047 deserStatus = msg.deserialize(context);
1048 FW_ASSERT(
1049 deserStatus == Fw::FW_SERIALIZE_OK,
1050 static_cast<FwAssertArgType>(deserStatus)
1051 );
1052 // Call handler function
1053 this->Sched_handler(
1054 portNum,
1055 context
1056 );
1057
1058 break;
1059 }
1060
1061 // Handle internal interface InterruptReport
1062 case INT_IF_INTERRUPTREPORT: {
1063 U32 interrupt;
1064 deserStatus = msg.deserialize(interrupt);
1065
1066 // Internal interface should always deserialize
1067 FW_ASSERT(
1068 Fw::FW_SERIALIZE_OK == deserStatus,
1069 static_cast<FwAssertArgType>(deserStatus)
1070 );
1071
1072 // Make sure there was no data left over.
1073 // That means the buffer size was incorrect.
1074 FW_ASSERT(
1075 msg.getBuffLeft() == 0,
1076 static_cast<FwAssertArgType>(msg.getBuffLeft())
1077 );
1078
1079 // Call handler function
1080 this->InterruptReport_internalInterfaceHandler(
1081 interrupt
1082 );
1083
1084 break;
1085 }
1086
1087 default:
1088 return MSG_DISPATCH_ERROR;
1089 }
1090
1091 return MSG_DISPATCH_OK;
1092 }
1093
1094 // ----------------------------------------------------------------------
1095 // Calls for messages received on typed input ports
1096 // ----------------------------------------------------------------------
1097
1098 void BlockDriverComponentBase ::
1099 m_p_BufferIn_in(
1100 Fw::PassiveComponentBase* callComp,
1101 NATIVE_INT_TYPE portNum,
1102 Drv::DataBuffer& buff
1103 )
1104 {
1105 FW_ASSERT(callComp);
1106 BlockDriverComponentBase* compPtr = static_cast<BlockDriverComponentBase*>(callComp);
1107 compPtr->BufferIn_handlerBase(
1108 portNum,
1109 buff
1110 );
1111 }
1112
1113 void BlockDriverComponentBase ::
1114 m_p_PingIn_in(
1115 Fw::PassiveComponentBase* callComp,
1116 NATIVE_INT_TYPE portNum,
1117 U32 key
1118 )
1119 {
1120 FW_ASSERT(callComp);
1121 BlockDriverComponentBase* compPtr = static_cast<BlockDriverComponentBase*>(callComp);
1122 compPtr->PingIn_handlerBase(
1123 portNum,
1124 key
1125 );
1126 }
1127
1128 void BlockDriverComponentBase ::
1129 m_p_Sched_in(
1130 Fw::PassiveComponentBase* callComp,
1131 NATIVE_INT_TYPE portNum,
1132 NATIVE_UINT_TYPE context
1133 )
1134 {
1135 FW_ASSERT(callComp);
1136 BlockDriverComponentBase* compPtr = static_cast<BlockDriverComponentBase*>(callComp);
1137 compPtr->Sched_handlerBase(
1138 portNum,
1139 context
1140 );
1141 }
1142
1143}
#define FW_ASSERT(...)
Definition Assert.hpp:7
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
@ SERIALIZED_SIZE
The size of the serial representations of the port arguments.
@ ACTIVE_COMPONENT_EXIT
message to exit active component task
void init()
Object initializer.
Definition ObjBase.cpp:27
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
@ QUEUE_OK
message sent/received okay
Definition Queue.hpp:28
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.
@ SERIALIZED_SIZE
The size of the serial representations of the port arguments.
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