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