F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
RateGroupDriver.cpp
Go to the documentation of this file.
2 #include <FpConfig.hpp>
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<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_dividers)),
24  // copy provided array of dividers
25  for (NATIVE_UINT_TYPE 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  dividerSet.dividers[entry].offset,
29  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  this->m_rollover *= dividerSet.dividers[entry].divisor;
35  }
36  }
37  this->m_configured = true;
38  }
39 
41 
42  }
43 
44  void RateGroupDriver::CycleIn_handler(NATIVE_INT_TYPE portNum, Svc::TimerVal& cycleStart) {
45 
46  // Make sure that the dividers have been configured:
47  // If this asserts, add the configure() call to initialization.
48  FW_ASSERT(this->m_configured);
49 
50  // Loop through each divider. For a given port, the port will be called when the divider value
51  // divides evenly into the number of ticks. For example, if the divider value for a port is 4,
52  // it would be called every fourth invocation of the CycleIn port.
53  for (NATIVE_UINT_TYPE entry = 0; entry < RateGroupDriver::DIVIDER_SIZE; entry++) {
54  if (this->m_dividers[entry].divisor != 0) {
55  if (this->isConnected_CycleOut_OutputPort(static_cast<FwIndexType>(entry))) {
56  if ((this->m_ticks % this->m_dividers[entry].divisor) == this->m_dividers[entry].offset) {
57  this->CycleOut_out(static_cast<FwIndexType>(entry),cycleStart);
58  }
59  }
60  }
61  }
62 
63  // rollover the tick value when the tick count reaches the rollover value
64  // the rollover value is the product of all the dividers. See comment in constructor.
65  this->m_ticks = (this->m_ticks + 1) % this->m_rollover;
66 
67  }
68 
69 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:51
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:66
PlatformUIntType NATIVE_UINT_TYPE
Definition: BasicTypes.h:52
PlatformIndexType FwIndexType
Definition: FpConfig.h:20
C++-compatible configuration header for fprime configuration.
RateGroupDivider component implementation.
Auto-generated base for RateGroupDriver component.
void CycleOut_out(FwIndexType portNum, Svc::TimerVal &cycleStart)
Invoke output port CycleOut.
bool isConnected_CycleOut_OutputPort(FwIndexType portNum)
~RateGroupDriver()
RateGroupDriverImpl destructor.
RateGroupDriver(const char *compName)
RateGroupDriver constructor.
void configure(const DividerSet &dividersSet)
RateGroupDriver configuration function.
static const NATIVE_UINT_TYPE DIVIDER_SIZE
Size of the divider table, provided as a constants to users passing the table in.
Serializable class for carrying timer values.
Definition: TimerVal.hpp:22
NATIVE_INT_TYPE divisor
Divisor.
NATIVE_INT_TYPE offset
Offset.
Struct containing an array of dividers.
Divider dividers[Svc::RateGroupDriver::DIVIDER_SIZE]
Dividers.