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  // check arguments
14  FW_ASSERT(dividerSet.dividers);
15  // verify port/table size matches
16  FW_ASSERT(FW_NUM_ARRAY_ELEMENTS(this->m_dividers) == this->getNum_CycleOut_OutputPorts(),
17  static_cast<FwAssertArgType>(FW_NUM_ARRAY_ELEMENTS(this->m_dividers)),
18  static_cast<FwAssertArgType>(this->getNum_CycleOut_OutputPorts()));
19  // copy provided array of dividers
20  for (FwIndexType entry = 0; entry < RateGroupDriver::DIVIDER_SIZE; entry++) {
21  // A port with an offset equal or bigger than the divisor is not accepted because it would never be called
22  FW_ASSERT((dividerSet.dividers[entry].offset == 0) ||
23  (dividerSet.dividers[entry].offset < dividerSet.dividers[entry].divisor),
24  static_cast<FwAssertArgType>(dividerSet.dividers[entry].offset),
25  static_cast<FwAssertArgType>(dividerSet.dividers[entry].divisor));
26  this->m_dividers[entry] = dividerSet.dividers[entry];
27  // rollover value should be product of all dividers to make sure integer rollover doesn't jump cycles
28  // only use non-zero dividers
29  if (dividerSet.dividers[entry].divisor != 0) {
30  // Ensure that rollover will not overflow
31  FW_ASSERT((std::numeric_limits<FwSizeType>::max() / dividerSet.dividers[entry].divisor) >= this->m_rollover,
32  static_cast<FwAssertArgType>(this->m_rollover),
33  static_cast<FwAssertArgType>(dividerSet.dividers[entry].divisor));
34  this->m_rollover *= dividerSet.dividers[entry].divisor;
35  }
36  }
37  this->m_configured = true;
38 }
39 
41 
42 void RateGroupDriver::CycleIn_handler(FwIndexType portNum, Os::RawTime& cycleStart) {
43  // Make sure that the dividers have been configured:
44  // If this asserts, add the configure() call to initialization.
45  FW_ASSERT(this->m_configured);
46 
47  // Loop through each divider. For a given port, the port will be called when the divider value
48  // divides evenly into the number of ticks. For example, if the divider value for a port is 4,
49  // it would be called every fourth invocation of the CycleIn port.
50  for (FwIndexType entry = 0; entry < RateGroupDriver::DIVIDER_SIZE; entry++) {
51  if (this->m_dividers[entry].divisor != 0) {
52  if (this->isConnected_CycleOut_OutputPort(static_cast<FwIndexType>(entry))) {
53  if ((this->m_ticks % this->m_dividers[entry].divisor) == this->m_dividers[entry].offset) {
54  this->CycleOut_out(static_cast<FwIndexType>(entry), cycleStart);
55  }
56  }
57  }
58  }
59 
60  // rollover the tick value when the tick count reaches the rollover value
61  // the rollover value is the product of all the dividers. See comment in constructor.
62  this->m_ticks = (this->m_ticks + 1) % this->m_rollover;
63 }
64 
65 } // namespace Svc
Auto-generated base for RateGroupDriver component.
void CycleOut_out(FwIndexType portNum, Os::RawTime &cycleStart)
Invoke output port CycleOut.
void configure(const DividerSet &dividersSet)
RateGroupDriver configuration function.
bool isConnected_CycleOut_OutputPort(FwIndexType portNum)
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:90
RateGroupDivider component implementation.
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