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 
32 void ActiveRateGroup::configure(U32 contexts[], FwIndexType numContexts) {
33  FW_ASSERT(contexts);
34  FW_ASSERT(numContexts == this->getNum_RateGroupMemberOut_OutputPorts(), static_cast<FwAssertArgType>(numContexts),
35  static_cast<FwAssertArgType>(this->getNum_RateGroupMemberOut_OutputPorts()));
37  static_cast<FwAssertArgType>(FW_NUM_ARRAY_ELEMENTS(this->m_contexts)),
38  static_cast<FwAssertArgType>(this->getNum_RateGroupMemberOut_OutputPorts()));
39 
40  this->m_numContexts = numContexts;
41  // copy context values
42  for (FwIndexType entry = 0; entry < this->m_numContexts; entry++) {
43  this->m_contexts[entry] = contexts[entry];
44  }
45 }
46 
48 
49 void ActiveRateGroup::preamble() {
51 }
52 
53 void ActiveRateGroup::CycleIn_handler(FwIndexType portNum, Os::RawTime& cycleStart) {
54  // Make sure it's been configured
55  FW_ASSERT(this->m_numContexts);
56 
57  Os::RawTime endTime;
58 
59  this->m_cycleStarted = false;
60 
61  // invoke any members of the rate group
62  for (FwIndexType port = 0; port < this->m_numContexts; port++) {
64  this->RateGroupMemberOut_out(port, static_cast<U32>(this->m_contexts[port]));
65  }
66  }
67 
68  // grab timer for endTime of cycle
69  endTime.now();
70 
71  // get rate group execution time
72  U32 cycleTime;
73  // Cast to void as the only possible error is overflow, which we can't handle other
74  // than capping cycleTime to max value of U32 (which is done in getDiffUsec anyways)
75  (void)endTime.getDiffUsec(cycleStart, cycleTime);
76 
77  // check to see if the time has exceeded the previous maximum
78  if (cycleTime > this->m_maxTime) {
79  this->m_maxTime = cycleTime;
80  }
81 
82  // update cycle telemetry
83  this->tlmWrite_RgMaxTime(this->m_maxTime);
84 
85  // check for cycle slip. That will happen if new cycle message has been received
86  // which will cause flag will be set again.
87  if (this->m_cycleStarted) {
88  this->m_cycleSlips++;
89  if (this->m_overrunThrottle < ACTIVE_RATE_GROUP_OVERRUN_THROTTLE) {
90  this->log_WARNING_HI_RateGroupCycleSlip(this->m_cycles);
91  this->m_overrunThrottle++;
92  }
93  // update cycle slips
94  this->tlmWrite_RgCycleSlips(this->m_cycleSlips);
95  } else { // if cycle is okay start decrementing throttle value
96  if (this->m_overrunThrottle > 0) {
97  this->m_overrunThrottle--;
98  }
99  }
100 
101  // increment cycle
102  this->m_cycles++;
103 }
104 
105 void ActiveRateGroup::CycleIn_preMsgHook(FwIndexType portNum, Os::RawTime& cycleStart) {
106  // set flag to indicate cycle has started. Check in thread for overflow.
107  this->m_cycleStarted = true;
108 }
109 
110 void ActiveRateGroup::PingIn_handler(FwIndexType portNum, U32 key) {
111  // return the key to health
112  this->PingOut_out(0, key);
113 }
114 
115 } // namespace Svc
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.
Number of overruns allowed before overrun event is throttled.
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:90
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