F´ Flight Software - C/C++ Documentation  NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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/Types/BasicTypes.hpp>
18 #include <Fw/Types/Assert.hpp>
19 #include <Os/Log.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 
34  FW_ASSERT(contexts);
35  FW_ASSERT(numContexts == this->getNum_RateGroupMemberOut_OutputPorts(),numContexts,this->getNum_RateGroupMemberOut_OutputPorts());
36  FW_ASSERT(FW_NUM_ARRAY_ELEMENTS(this->m_contexts) == this->getNum_RateGroupMemberOut_OutputPorts(),
37  FW_NUM_ARRAY_ELEMENTS(this->m_contexts),
38  this->getNum_RateGroupMemberOut_OutputPorts());
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() {
56  this->log_DIAGNOSTIC_RateGroupStarted();
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++) {
70  if (this->isConnected_RateGroupMemberOut_OutputPort(port)) {
71  this->RateGroupMemberOut_out(port,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 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 }
FW_NUM_ARRAY_ELEMENTS
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.hpp:100
Svc::TimerVal
Serializable class for carrying timer values.
Definition: TimerVal.hpp:22
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:27
Svc::ActiveRateGroup::ActiveRateGroup
ActiveRateGroup(const char *compName)
ActiveRateGroup constructor.
Definition: ActiveRateGroup.cpp:23
ActiveRateGroupCfg.hpp
ActiveRateGroup.hpp
FW_ASSERT
#define FW_ASSERT(...)
Definition: Assert.hpp:9
Svc
Definition: ActiveRateGroupCfg.hpp:18
Svc::ActiveRateGroup::~ActiveRateGroup
~ActiveRateGroup()
ActiveRateGroup destructor.
Definition: ActiveRateGroup.cpp:51
Svc::ACTIVE_RATE_GROUP_OVERRUN_THROTTLE
@ ACTIVE_RATE_GROUP_OVERRUN_THROTTLE
Number of overruns allowed before overrun event is throttled.
Definition: ActiveRateGroupCfg.hpp:22
Svc::ActiveRateGroup::configure
void configure(NATIVE_INT_TYPE contexts[], NATIVE_INT_TYPE numContexts)
ActiveRateGroup configuration function.
Definition: ActiveRateGroup.cpp:33
Svc::ActiveRateGroup::init
void init(NATIVE_INT_TYPE queueDepth, NATIVE_INT_TYPE instance)
ActiveRateGroup initialization function.
Definition: ActiveRateGroup.cpp:47
Log.hpp