F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
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
17#include <FpConfig.hpp>
18#include <Fw/Types/Assert.hpp>
19#include <Os/Console.hpp>
20
21namespace 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
50
51 void ActiveRateGroup::preamble() {
53 }
54
55 void ActiveRateGroup::CycleIn_handler(NATIVE_INT_TYPE portNum, Os::RawTime& cycleStart) {
56
57 // Make sure it's been configured
58 FW_ASSERT(this->m_numContexts);
59
60 Os::RawTime endTime;
61
62 this->m_cycleStarted = false;
63
64 // invoke any members of the rate group
65 for (NATIVE_INT_TYPE port = 0; port < this->m_numContexts; port++) {
67 this->RateGroupMemberOut_out(port, static_cast<U32>(this->m_contexts[port]));
68 }
69 }
70
71 // grab timer for endTime of cycle
72 endTime.now();
73
74 // get rate group execution time
75 U32 cycleTime;
76 // Cast to void as the only possible error is overflow, which we can't handle other
77 // than capping cycleTime to max value of U32 (which is done in getDiffUsec anyways)
78 (void) endTime.getDiffUsec(cycleStart, cycleTime);
79
80 // check to see if the time has exceeded the previous maximum
81 if (cycleTime > this->m_maxTime) {
82 this->m_maxTime = cycleTime;
83 }
84
85 // update cycle telemetry
86 this->tlmWrite_RgMaxTime(this->m_maxTime);
87
88 // check for cycle slip. That will happen if new cycle message has been received
89 // which will cause flag will be set again.
90 if (this->m_cycleStarted) {
91 this->m_cycleSlips++;
92 if (this->m_overrunThrottle < ACTIVE_RATE_GROUP_OVERRUN_THROTTLE) {
93 this->log_WARNING_HI_RateGroupCycleSlip(this->m_cycles);
94 this->m_overrunThrottle++;
95 }
96 // update cycle slips
97 this->tlmWrite_RgCycleSlips(this->m_cycleSlips);
98 } else { // if cycle is okay start decrementing throttle value
99 if (this->m_overrunThrottle > 0) {
100 this->m_overrunThrottle--;
101 }
102 }
103
104 // increment cycle
105 this->m_cycles++;
106
107 }
108
109 void ActiveRateGroup::CycleIn_preMsgHook(NATIVE_INT_TYPE portNum, Os::RawTime& cycleStart) {
110 // set flag to indicate cycle has started. Check in thread for overflow.
111 this->m_cycleStarted = true;
112 }
113
114 void ActiveRateGroup::PingIn_handler(NATIVE_INT_TYPE portNum, U32 key) {
115 // return the key to health
116 this->PingOut_out(0,key);
117 }
118
119
120}
#define FW_ASSERT(...)
Definition Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:55
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition BasicTypes.h:70
C++-compatible configuration header for fprime configuration.
Status getDiffUsec(const RawTime &other, U32 &result) const
Calculate the difference in microseconds between two RawTime objects.
Definition RawTime.cpp:56
Status now() override
Get the current time.
Definition RawTime.cpp:36
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.
@ ACTIVE_RATE_GROUP_OVERRUN_THROTTLE
Number of overruns allowed before overrun event is throttled.