F´ Flight Software - C/C++ Documentation  devel
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 <FpConfig.hpp>
18 #include <Fw/Types/Assert.hpp>
19 #include <Os/Log.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 
34  FW_ASSERT(contexts);
37  FW_NUM_ARRAY_ELEMENTS(this->m_contexts),
39 
40  this->m_numContexts = numContexts;
41  // copy context values
42  for (NATIVE_INT_TYPE entry = 0; entry < this->m_numContexts; entry++) {
43  this->m_contexts[entry] = contexts[entry];
44  }
45  }
46 
48  ActiveRateGroupComponentBase::init(queueDepth,instance);
49  }
50 
52 
53  }
54 
55  void ActiveRateGroup::preamble() {
57  }
58 
59  void ActiveRateGroup::CycleIn_handler(NATIVE_INT_TYPE portNum, Svc::TimerVal& cycleStart) {
60 
61  // Make sure it's been configured
62  FW_ASSERT(this->m_numContexts);
63 
64  TimerVal end;
65 
66  this->m_cycleStarted = false;
67 
68  // invoke any members of the rate group
69  for (NATIVE_INT_TYPE port = 0; port < this->m_numContexts; port++) {
71  this->RateGroupMemberOut_out(port, static_cast<U32>(this->m_contexts[port]));
72  }
73  }
74 
75  // grab timer for end of cycle
76  end.take();
77 
78  // get rate group execution time
79  U32 cycle_time = end.diffUSec(cycleStart);
80 
81  // check to see if the time has exceeded the previous maximum
82  if (cycle_time > this->m_maxTime) {
83  this->m_maxTime = cycle_time;
84  }
85 
86  // update cycle telemetry
87  this->tlmWrite_RgMaxTime(this->m_maxTime);
88 
89  // check for cycle slip. That will happen if new cycle message has been received
90  // which will cause flag will be set again.
91  if (this->m_cycleStarted) {
92  this->m_cycleSlips++;
93  if (this->m_overrunThrottle < ACTIVE_RATE_GROUP_OVERRUN_THROTTLE) {
94  this->log_WARNING_HI_RateGroupCycleSlip(this->m_cycles);
95  this->m_overrunThrottle++;
96  }
97  // update cycle slips
98  this->tlmWrite_RgCycleSlips(this->m_cycleSlips);
99  } else { // if cycle is okay start decrementing throttle value
100  if (this->m_overrunThrottle > 0) {
101  this->m_overrunThrottle--;
102  }
103  }
104 
105  // increment cycle
106  this->m_cycles++;
107 
108  }
109 
110  void ActiveRateGroup::CycleIn_preMsgHook(NATIVE_INT_TYPE portNum, Svc::TimerVal& cycleStart) {
111  // set flag to indicate cycle has started. Check in thread for overflow.
112  this->m_cycleStarted = true;
113  }
114 
115  void ActiveRateGroup::PingIn_handler(NATIVE_INT_TYPE portNum, U32 key) {
116  // return the key to health
117  this->PingOut_out(0,key);
118  }
119 
120 
121 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:51
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:66
C++-compatible configuration header for fprime configuration.
void init()
Object initializer.
Definition: ObjBase.cpp:27
Auto-generated base for ActiveRateGroup component.
void tlmWrite_RgMaxTime(U32 arg, Fw::Time _tlmTime=Fw::Time())
void tlmWrite_RgCycleSlips(U32 arg, Fw::Time _tlmTime=Fw::Time())
void RateGroupMemberOut_out(FwIndexType portNum, U32 context)
Invoke output port RateGroupMemberOut.
bool isConnected_RateGroupMemberOut_OutputPort(FwIndexType portNum)
void PingOut_out(FwIndexType portNum, U32 key)
Invoke output port PingOut.
void configure(NATIVE_INT_TYPE contexts[], NATIVE_INT_TYPE numContexts)
ActiveRateGroup configuration function.
~ActiveRateGroup()
ActiveRateGroup destructor.
ActiveRateGroup(const char *compName)
ActiveRateGroup constructor.
Serializable class for carrying timer values.
Definition: TimerVal.hpp:22
@ ACTIVE_RATE_GROUP_OVERRUN_THROTTLE
Number of overruns allowed before overrun event is throttled.