F´ Flight Software - C/C++ Documentation  NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
RateGroupDriverImpl.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  RateGroupDriverImpl::RateGroupDriverImpl(const char* compName, I32 dividers[], I32 numDividers) :
10  RateGroupDriverComponentBase(compName),
11  m_ticks(0),m_rollover(1)
12  {
13 
14  // double check arguments
15  FW_ASSERT(dividers);
16  FW_ASSERT(numDividers <= static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_dividers)),
17  numDividers,
18  static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_dividers)));
19  // verify port/table size matches
20  FW_ASSERT(FW_NUM_ARRAY_ELEMENTS(this->m_dividers) == this->getNum_CycleOut_OutputPorts(),
21  static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_dividers)),
22  this->getNum_CycleOut_OutputPorts());
23  // clear table
24  ::memset(this->m_dividers,0,sizeof(this->m_dividers));
25  for (NATIVE_INT_TYPE entry = 0; entry < numDividers; entry++) {
26  this->m_dividers[entry] = 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 (dividers[entry] != 0) {
30  this->m_rollover *= dividers[entry];
31  }
32  }
33 
34  }
35 
37 
38  }
39 
41  RateGroupDriverComponentBase::init(instanceId);
42  }
43 
44  void RateGroupDriverImpl::CycleIn_handler(NATIVE_INT_TYPE portNum, Svc::TimerVal& cycleStart) {
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 (NATIVE_INT_TYPE entry = 0; entry < static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_dividers)); entry++) {
50  if (this->m_dividers[entry] != 0) {
51  if (this->isConnected_CycleOut_OutputPort(entry)) {
52  if ((this->m_ticks % this->m_dividers[entry]) == 0) {
53  this->CycleOut_out(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  this->m_ticks = (this->m_ticks + 1) % this->m_rollover;
62 
63  }
64 
65 }
Svc::RateGroupDriverImpl::init
void init(NATIVE_INT_TYPE instanceId=0)
RateGroupDriverImpl initialization function.
Definition: RateGroupDriverImpl.cpp:40
Svc::RateGroupDriverImpl::~RateGroupDriverImpl
~RateGroupDriverImpl()
RateGroupDriverImpl destructor.
Definition: RateGroupDriverImpl.cpp:36
RateGroupDriverImpl.hpp
RateGroupDivider component implementation.
FW_NUM_ARRAY_ELEMENTS
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.hpp:101
Assert.hpp
Svc::TimerVal
Serializable class for carrying timer values.
Definition: TimerVal.hpp:22
FW_ASSERT
#define FW_ASSERT(...)
Definition: Assert.hpp:8
Svc
Definition: ActiveRateGroupImplCfg.hpp:18
Svc::RateGroupDriverImpl::RateGroupDriverImpl
RateGroupDriverImpl(const char *compName, NATIVE_INT_TYPE dividers[], NATIVE_INT_TYPE numDividers)
RateGroupDriverImpl constructor.
Definition: RateGroupDriverImpl.cpp:9
BasicTypes.hpp
Declares ISF basic types.
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29