F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
ActiveRateGroupImpl.cpp
Go to the documentation of this file.
1/*
2* \author: Tim Canham
3* \file:
4* \brief
5*
6* This file implements the ActiveRateGroup component,
7* which invokes a set of components the comprise the rate group.
8*
9* Copyright 2014-2015, by the California Institute of Technology.
10* ALL RIGHTS RESERVED. United States Government Sponsorship
11* acknowledged.
12*
13*/
14
15#include <Svc/ActiveRateGroup/ActiveRateGroupImpl.hpp>
16#include <ActiveRateGroupImplCfg.hpp>
17#include <FpConfig.hpp>
18#include <Fw/Types/Assert.hpp>
19#include <Os/Log.hpp>
20
21namespace Svc {
22
23 ActiveRateGroupImpl::ActiveRateGroupImpl(const char* compName, NATIVE_UINT_TYPE contexts[], NATIVE_UINT_TYPE numContexts) :
24 ActiveRateGroupComponentBase(compName),
25 m_cycles(0),
26 m_maxTime(0),
27 m_cycleStarted(false),
28 m_overrunThrottle(0),
29 m_cycleSlips(0) {
30 FW_ASSERT(contexts);
31 FW_ASSERT(numContexts == static_cast<NATIVE_UINT_TYPE>(this->getNum_RateGroupMemberOut_OutputPorts()),numContexts,this->getNum_RateGroupMemberOut_OutputPorts());
32 FW_ASSERT(FW_NUM_ARRAY_ELEMENTS(this->m_contexts) == this->getNum_RateGroupMemberOut_OutputPorts(),
33 static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_contexts)),
34 this->getNum_RateGroupMemberOut_OutputPorts());
35
36 // copy context values
37 for (NATIVE_INT_TYPE entry = 0; entry < this->getNum_RateGroupMemberOut_OutputPorts(); entry++) {
38 this->m_contexts[entry] = contexts[entry];
39 }
40 }
41
42 void ActiveRateGroupImpl::init(NATIVE_INT_TYPE queueDepth, NATIVE_INT_TYPE instance) {
43 ActiveRateGroupComponentBase::init(queueDepth,instance);
44 }
45
46 ActiveRateGroupImpl::~ActiveRateGroupImpl() {
47
48 }
49
50 void ActiveRateGroupImpl::preamble() {
51 this->log_DIAGNOSTIC_RateGroupStarted();
52 }
53
54 void ActiveRateGroupImpl::CycleIn_handler(NATIVE_INT_TYPE portNum, Svc::TimerVal& cycleStart) {
55
56 TimerVal end;
57
58 this->m_cycleStarted = false;
59
60 // invoke any members of the rate group
61 for (NATIVE_INT_TYPE port = 0; port < this->getNum_RateGroupMemberOut_OutputPorts(); port++) {
62 if (this->isConnected_RateGroupMemberOut_OutputPort(port)) {
63 this->RateGroupMemberOut_out(port,this->m_contexts[port]);
64 }
65 }
66
67 // grab timer for end of cycle
68 end.take();
69
70 // get rate group execution time
71 U32 cycle_time = end.diffUSec(cycleStart);
72
73 // check to see if the time has exceeded the previous maximum
74 if (cycle_time > this->m_maxTime) {
75 this->m_maxTime = cycle_time;
76 }
77
78 // update cycle telemetry
79 this->tlmWrite_RgMaxTime(this->m_maxTime);
80
81 // check for cycle slip. That will happen if new cycle message has been received
82 // which will cause flag will be set again.
83 if (this->m_cycleStarted) {
84 this->m_cycleSlips++;
85 if (this->m_overrunThrottle < ACTIVE_RATE_GROUP_OVERRUN_THROTTLE) {
86 this->log_WARNING_HI_RateGroupCycleSlip(this->m_cycles);
87 this->m_overrunThrottle++;
88 }
89 // update cycle slips
90 this->tlmWrite_RgCycleSlips(this->m_cycleSlips);
91 } else { // if cycle is okay start decrementing throttle value
92 if (this->m_overrunThrottle > 0) {
93 this->m_overrunThrottle--;
94 }
95 }
96
97 // increment cycle
98 this->m_cycles++;
99
100 }
101
102 void ActiveRateGroupImpl::CycleIn_preMsgHook(NATIVE_INT_TYPE portNum, Svc::TimerVal& cycleStart) {
103 // set flag to indicate cycle has started. Check in thread for overflow.
104 this->m_cycleStarted = true;
105 }
106
107 void ActiveRateGroupImpl::PingIn_handler(NATIVE_INT_TYPE portNum, U32 key) {
108 // return the key to health
109 this->PingOut_out(0,key);
110 }
111
112
113}
#define FW_ASSERT(...)
Definition Assert.hpp:7
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition BasicTypes.h:66
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:52
C++-compatible configuration header for fprime configuration.
Serializable class for carrying timer values.
Definition TimerVal.hpp:22