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