F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
ActiveRateGroup.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 <Fw/FPrimeBasicTypes.hpp>
16 #include <Fw/Types/Assert.hpp>
17 #include <Os/Console.hpp>
19 #include <config/ActiveRateGroupCfg.hpp>
20 
21 namespace Svc {
22 
23 ActiveRateGroup::ActiveRateGroup(const char* compName)
24  : ActiveRateGroupComponentBase(compName),
25  m_cycles(0),
26  m_maxTime(0),
27  m_cycleStarted(false),
28  m_numContexts(0),
29  m_overrunThrottle(0),
30  m_cycleSlips(0) {}
31 
34  "Context table size must match the number of rate group member output ports");
35 
36  this->m_numContexts = CONNECTION_COUNT_MAX;
37  // copy context values
38  for (FwIndexType entry = 0; entry < this->m_numContexts; entry++) {
39  this->m_contexts[entry] = contexts[static_cast<FwSizeType>(entry)];
40  }
41 }
42 
43 void ActiveRateGroup::configure(const U32 contexts[], const FwIndexType numContexts) {
44  FW_ASSERT(contexts != nullptr);
45  FW_ASSERT(numContexts == this->getNum_RateGroupMemberOut_OutputPorts(), static_cast<FwAssertArgType>(numContexts),
46  static_cast<FwAssertArgType>(this->getNum_RateGroupMemberOut_OutputPorts()));
47 
48  ContextArray contextArray;
49  for (FwIndexType entry = 0; entry < numContexts; entry++) {
50  contextArray[static_cast<FwSizeType>(entry)] = contexts[entry];
51  }
52  this->configure(contextArray);
53 }
54 
56 
57 void ActiveRateGroup::preamble() {
59 }
60 
61 void ActiveRateGroup::CycleIn_handler(FwIndexType portNum, Os::RawTime& cycleStart) {
62  // Make sure it's been configured
63  FW_ASSERT(this->m_numContexts != 0);
64 
65  Os::RawTime endTime;
66 
67  this->m_cycleStarted = false;
68 
69  // invoke any members of the rate group
70  for (FwIndexType port = 0; port < this->m_numContexts; port++) {
72  this->RateGroupMemberOut_out(port, static_cast<U32>(this->m_contexts[port]));
73  }
74  }
75 
76  // grab timer for endTime of cycle
77  Os::RawTime::Status timeStatus = endTime.now();
78  if (timeStatus != Os::RawTime::Status::OP_OK) {
79  this->log_WARNING_HI_RateGroupTimeGetError(Os::RawTimeStatus(static_cast<Os::RawTimeStatus::T>(timeStatus)));
80  }
81 
82  // get rate group execution time
83  U32 cycleTime;
84  // Cast to void as the only possible error is overflow, which we can't handle other
85  // than capping cycleTime to max value of U32 (which is done in getDiffUsec anyways)
86  (void)endTime.getDiffUsec(cycleStart, cycleTime);
87 
88  // check to see if the time has exceeded the previous maximum
89  if (cycleTime > this->m_maxTime) {
90  this->m_maxTime = cycleTime;
91  }
92 
93  // update cycle telemetry
94  this->tlmWrite_RgMaxTime(this->m_maxTime);
95 
96  // check for cycle slip. That will happen if new cycle message has been received
97  // which will cause flag will be set again.
98  if (this->m_cycleStarted) {
99  this->m_cycleSlips++;
100  if (this->m_overrunThrottle < ACTIVE_RATE_GROUP_OVERRUN_THROTTLE) {
101  this->log_WARNING_HI_RateGroupCycleSlip(this->m_cycles);
102  this->m_overrunThrottle++;
103  }
104  // update cycle slips
105  this->tlmWrite_RgCycleSlips(this->m_cycleSlips);
106  } else { // if cycle is okay start decrementing throttle value
107  if (this->m_overrunThrottle > 0) {
108  this->m_overrunThrottle--;
109  }
110  }
111 
112  // increment cycle
113  this->m_cycles++;
114 }
115 
116 void ActiveRateGroup::CycleIn_preMsgHook(FwIndexType portNum, Os::RawTime& cycleStart) {
117  // set flag to indicate cycle has started. Check in thread for overflow.
118  this->m_cycleStarted = true;
119 }
120 
121 void ActiveRateGroup::PingIn_handler(FwIndexType portNum, U32 key) {
122  // return the key to health
123  this->PingOut_out(0, key);
124 }
125 
126 } // namespace Svc
void configure(const ContextArray &contexts)
ActiveRateGroup configuration function.
void tlmWrite_RgCycleSlips(U32 arg, Fw::Time _tlmTime=Fw::Time())
Operation succeeded.
Definition: Os.hpp:27
ActiveRateGroup(const char *compName)
ActiveRateGroup constructor.
FPP shadow-enum representing Os::RawTime::Status.
PlatformSizeType FwSizeType
static constexpr FwIndexType getNum_RateGroupMemberOut_OutputPorts()
void log_WARNING_HI_RateGroupTimeGetError(const Os::RawTimeStatus &status)
Status now() override
Get the current time.
void PingOut_out(FwIndexType portNum, U32 key) const
Invoke output port PingOut.
~ActiveRateGroup()
ActiveRateGroup destructor.
void tlmWrite_RgMaxTime(U32 arg, Fw::Time _tlmTime=Fw::Time())
void RateGroupMemberOut_out(FwIndexType portNum, U32 context) const
Invoke output port RateGroupMemberOut.
static constexpr FwIndexType CONNECTION_COUNT_MAX
Auto-generated base for ActiveRateGroup component.
PlatformIndexType FwIndexType
Status getDiffUsec(const RawTime &other, U32 &result) const override
Calculate the difference in microseconds between two RawTime objects.
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:94
RateGroupDivider component implementation.
Fw::Array< U32, CONNECTION_COUNT_MAX > ContextArray
Array of context values for rate group members, indexed by output port number.
bool isConnected_RateGroupMemberOut_OutputPort(FwIndexType portNum) const
#define FW_ASSERT(...)
Definition: Assert.hpp:14
Number of overruns allowed before overrun event is throttled.