| Line | Branch | Exec | Source |
|---|---|---|---|
| 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> | ||
| 18 | #include <Svc/ActiveRateGroup/ActiveRateGroup.hpp> | ||
| 19 | #include <config/ActiveRateGroupCfg.hpp> | ||
| 20 | |||
| 21 | namespace Svc { | ||
| 22 | |||
| 23 | 7 | ActiveRateGroup::ActiveRateGroup(const char* compName) | |
| 24 | : ActiveRateGroupComponentBase(compName), | ||
| 25 | 7 | m_cycles(0), | |
| 26 | 7 | m_maxTime(0), | |
| 27 | 7 | m_cycleStarted(false), | |
| 28 | 7 | m_numContexts(0), | |
| 29 | 7 | m_overrunThrottle(0), | |
| 30 | 14 | m_cycleSlips(0) {} | |
| 31 | |||
| 32 | 7 | void ActiveRateGroup::configure(const ContextArray& contexts) { | |
| 33 | static_assert(FW_NUM_ARRAY_ELEMENTS(m_contexts) == NUM_RATEGROUPMEMBEROUT_OUTPUT_PORTS, | ||
| 34 | "Context table size must match the number of rate group member output ports"); | ||
| 35 | |||
| 36 | 7 | this->m_numContexts = CONNECTION_COUNT_MAX; | |
| 37 | // copy context values | ||
| 38 |
2/2✓ Branch 4 taken 70 times.
✓ Branch 5 taken 7 times.
|
77 | for (FwIndexType entry = 0; entry < this->m_numContexts; entry++) { |
| 39 | 70 | this->m_contexts[entry] = contexts[static_cast<FwSizeType>(entry)]; | |
| 40 | } | ||
| 41 | 7 | } | |
| 42 | |||
| 43 | ✗ | void ActiveRateGroup::configure(const U32 contexts[], const FwIndexType numContexts) { | |
| 44 | ✗ | FW_ASSERT(contexts != nullptr); | |
| 45 | ✗ | FW_ASSERT(numContexts == this->getNum_RateGroupMemberOut_OutputPorts(), static_cast<FwAssertArgType>(numContexts), | |
| 46 | static_cast<FwAssertArgType>(this->getNum_RateGroupMemberOut_OutputPorts())); | ||
| 47 | |||
| 48 | ✗ | ContextArray contextArray; | |
| 49 | ✗ | for (FwIndexType entry = 0; entry < numContexts; entry++) { | |
| 50 | ✗ | contextArray[static_cast<FwSizeType>(entry)] = contexts[entry]; | |
| 51 | } | ||
| 52 | ✗ | this->configure(contextArray); | |
| 53 | ✗ | } | |
| 54 | |||
| 55 | 14 | ActiveRateGroup::~ActiveRateGroup() {} | |
| 56 | |||
| 57 | 6 | void ActiveRateGroup::preamble() { | |
| 58 | 6 | this->log_DIAGNOSTIC_RateGroupStarted(); | |
| 59 | 6 | } | |
| 60 | |||
| 61 | 27 | void ActiveRateGroup::CycleIn_handler(FwIndexType portNum, Os::RawTime& cycleStart) { | |
| 62 | // Make sure it's been configured | ||
| 63 | 27 | FW_ASSERT(this->m_numContexts != 0); | |
| 64 | |||
| 65 |
1/1✓ Branch 2 taken 27 times.
|
27 | Os::RawTime endTime; |
| 66 | |||
| 67 | 27 | this->m_cycleStarted = false; | |
| 68 | |||
| 69 | // invoke any members of the rate group | ||
| 70 |
2/2✓ Branch 4 taken 270 times.
✓ Branch 5 taken 27 times.
|
297 | for (FwIndexType port = 0; port < this->m_numContexts; port++) { |
| 71 |
2/3✓ Branch 5 taken 270 times.
✓ Branch 7 taken 270 times.
✗ Branch 8 not taken.
|
270 | if (this->isConnected_RateGroupMemberOut_OutputPort(port)) { |
| 72 |
1/1✓ Branch 10 taken 270 times.
|
270 | this->RateGroupMemberOut_out(port, static_cast<U32>(this->m_contexts[port])); |
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | // grab timer for endTime of cycle | ||
| 77 |
1/1✓ Branch 2 taken 27 times.
|
27 | Os::RawTime::Status timeStatus = endTime.now(); |
| 78 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
|
27 | if (timeStatus != Os::RawTime::Status::OP_OK) { |
| 79 | ✗ | this->log_WARNING_HI_RateGroupTimeGetError(Os::RawTimeStatus(static_cast<Os::RawTimeStatus::T>(timeStatus))); | |
| 80 | } | ||
| 81 | |||
| 82 | // get rate group execution time | ||
| 83 | 27 | U32 cycleTime; | |
| 84 | // Cast to void as the only possible error is overflow, which we can't handle other | ||
| 85 | // than capping cycleTime to max value of U32 (which is done in getDiffUsec anyways) | ||
| 86 |
1/1✓ Branch 3 taken 27 times.
|
27 | (void)endTime.getDiffUsec(cycleStart, cycleTime); |
| 87 | |||
| 88 | // check to see if the time has exceeded the previous maximum | ||
| 89 |
2/2✓ Branch 4 taken 6 times.
✓ Branch 5 taken 21 times.
|
27 | if (cycleTime > this->m_maxTime) { |
| 90 | 6 | this->m_maxTime = cycleTime; | |
| 91 | } | ||
| 92 | |||
| 93 | // update cycle telemetry | ||
| 94 |
2/2✓ Branch 6 taken 27 times.
✓ Branch 13 taken 27 times.
|
27 | this->tlmWrite_RgMaxTime(this->m_maxTime); |
| 95 | |||
| 96 | // check for cycle slip. That will happen if new cycle message has been received | ||
| 97 | // which will cause flag will be set again. | ||
| 98 |
3/4✗ Branch 3 not taken.
✓ Branch 4 taken 27 times.
✓ Branch 5 taken 21 times.
✓ Branch 6 taken 6 times.
|
27 | if (this->m_cycleStarted) { |
| 99 | 21 | this->m_cycleSlips++; | |
| 100 |
2/2✓ Branch 4 taken 18 times.
✓ Branch 5 taken 3 times.
|
21 | if (this->m_overrunThrottle < ACTIVE_RATE_GROUP_OVERRUN_THROTTLE) { |
| 101 |
1/1✓ Branch 9 taken 18 times.
|
18 | this->log_WARNING_HI_RateGroupCycleSlip(this->m_cycles); |
| 102 | 18 | this->m_overrunThrottle++; | |
| 103 | } | ||
| 104 | // update cycle slips | ||
| 105 |
2/2✓ Branch 6 taken 21 times.
✓ Branch 13 taken 21 times.
|
21 | this->tlmWrite_RgCycleSlips(this->m_cycleSlips); |
| 106 | } else { // if cycle is okay start decrementing throttle value | ||
| 107 |
2/2✓ Branch 4 taken 3 times.
✓ Branch 5 taken 3 times.
|
6 | if (this->m_overrunThrottle > 0) { |
| 108 | 3 | this->m_overrunThrottle--; | |
| 109 | } | ||
| 110 | } | ||
| 111 | |||
| 112 | // increment cycle | ||
| 113 | 27 | this->m_cycles++; | |
| 114 | 54 | } | |
| 115 | |||
| 116 | 48 | void ActiveRateGroup::CycleIn_preMsgHook(FwIndexType portNum, Os::RawTime& cycleStart) { | |
| 117 | // set flag to indicate cycle has started. Check in thread for overflow. | ||
| 118 | 48 | this->m_cycleStarted = true; | |
| 119 | 48 | } | |
| 120 | |||
| 121 | 1 | void ActiveRateGroup::PingIn_handler(FwIndexType portNum, U32 key) { | |
| 122 | // return the key to health | ||
| 123 | 1 | this->PingOut_out(0, key); | |
| 124 | 1 | } | |
| 125 | |||
| 126 | } // namespace Svc | ||
| 127 |