F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
RateGroupDriver.cpp
Go to the documentation of this file.
2 #include <Fw/Types/Assert.hpp>
4 #include <cstdio>
5 #include <cstring>
6 
7 namespace Svc {
8 
9 RateGroupDriver::RateGroupDriver(const char* compName)
10  : RateGroupDriverComponentBase(compName), m_ticks(0), m_rollover(1), m_configured(false) {}
11 
12 void RateGroupDriver::configure(const DividerSet& dividerSet) {
13  // verify port/table size matches
14  static_assert(FW_NUM_ARRAY_ELEMENTS(m_dividers) == NUM_CYCLEOUT_OUTPUT_PORTS,
15  "Divider table size must match the number of cycle output ports");
16  // reset rollover so a reconfigure does not multiply onto the prior product
17  this->m_rollover = 1;
18  // copy provided array of dividers
19  for (FwIndexType entry = 0; entry < RateGroupDriver::DIVIDER_SIZE; entry++) {
20  // A port with an offset equal or bigger than the divisor is not accepted because it would never be called
21  FW_ASSERT((dividerSet.dividers[entry].offset == 0) ||
22  (dividerSet.dividers[entry].offset < dividerSet.dividers[entry].divisor),
23  static_cast<FwAssertArgType>(dividerSet.dividers[entry].offset),
24  static_cast<FwAssertArgType>(dividerSet.dividers[entry].divisor));
25  this->m_dividers[entry] = dividerSet.dividers[entry];
26  // rollover value should be product of all dividers to make sure integer rollover doesn't jump cycles
27  // only use non-zero dividers
28  if (dividerSet.dividers[entry].divisor != 0) {
29  // Ensure that rollover will not overflow
30  FW_ASSERT((std::numeric_limits<FwSizeType>::max() / dividerSet.dividers[entry].divisor) >= this->m_rollover,
31  static_cast<FwAssertArgType>(this->m_rollover),
32  static_cast<FwAssertArgType>(dividerSet.dividers[entry].divisor));
33  this->m_rollover *= dividerSet.dividers[entry].divisor;
34  }
35  }
36  this->m_configured = true;
37 }
38 
40 
41 void RateGroupDriver::CycleIn_handler(FwIndexType portNum, Os::RawTime& cycleStart) {
42  // Make sure that the dividers have been configured:
43  // If this asserts, add the configure() call to initialization.
44  FW_ASSERT(this->m_configured);
45 
46  // Loop through each divider. For a given port, the port will be called when the divider value
47  // divides evenly into the number of ticks. For example, if the divider value for a port is 4,
48  // it would be called every fourth invocation of the CycleIn port.
49  for (FwIndexType entry = 0; entry < RateGroupDriver::DIVIDER_SIZE; entry++) {
50  if (this->m_dividers[entry].divisor != 0) {
51  if (this->isConnected_CycleOut_OutputPort(static_cast<FwIndexType>(entry))) {
52  if ((this->m_ticks % this->m_dividers[entry].divisor) == this->m_dividers[entry].offset) {
53  this->CycleOut_out(static_cast<FwIndexType>(entry), cycleStart);
54  }
55  }
56  }
57  }
58 
59  // rollover the tick value when the tick count reaches the rollover value
60  // the rollover value is the product of all the dividers. See comment in constructor.
61  FW_ASSERT(this->m_rollover > 0);
62  this->m_ticks = (this->m_ticks + 1) % this->m_rollover;
63 }
64 
65 } // namespace Svc
bool isConnected_CycleOut_OutputPort(FwIndexType portNum) const
Auto-generated base for RateGroupDriver component.
void configure(const DividerSet &dividersSet)
RateGroupDriver configuration function.
RateGroupDriver(const char *compName)
RateGroupDriver constructor.
PlatformIndexType FwIndexType
Divider dividers[Svc::RateGroupDriver::DIVIDER_SIZE]
Dividers.
~RateGroupDriver()
RateGroupDriverImpl destructor.
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:94
RateGroupDivider component implementation.
void CycleOut_out(FwIndexType portNum, Os::RawTime &cycleStart) const
Invoke output port CycleOut.
static const FwIndexType DIVIDER_SIZE
Size of the divider table, provided as a constants to users passing the table in. ...
Struct containing an array of dividers.
#define FW_ASSERT(...)
Definition: Assert.hpp:14