F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
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
7namespace Svc {
8
9 RateGroupDriver::RateGroupDriver(const char* compName) :
10 RateGroupDriverComponentBase(compName),
11 m_numDividers(0),m_ticks(0),m_rollover(1) {
12
13 }
14
16 {
17
18 // check arguments
19 FW_ASSERT(dividers);
20 FW_ASSERT(numDividers);
21 this->m_numDividers = numDividers;
22 FW_ASSERT(numDividers <= static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_dividers)),
23 numDividers,
24 static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_dividers)));
25 // verify port/table size matches
26 FW_ASSERT(FW_NUM_ARRAY_ELEMENTS(this->m_dividers) == this->getNum_CycleOut_OutputPorts(),
27 static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_dividers)),
28 this->getNum_CycleOut_OutputPorts());
29 // clear table
30 ::memset(this->m_dividers,0,sizeof(this->m_dividers));
31 // copy provided array of dividers
32 for (NATIVE_INT_TYPE entry = 0; entry < numDividers; entry++) {
33 this->m_dividers[entry] = dividers[entry];
34 // rollover value should be product of all dividers to make sure integer rollover doesn't jump cycles
35 // only use non-zero dividers
36 if (dividers[entry] != 0) {
37 this->m_rollover *= dividers[entry];
38 }
39 }
40
41 }
42
44
45 }
46
48 RateGroupDriverComponentBase::init(instanceId);
49 }
50
51 void RateGroupDriver::CycleIn_handler(NATIVE_INT_TYPE portNum, Svc::TimerVal& cycleStart) {
52
53 // Make sure that the dividers have been configured:
54 // If this asserts, add the configure() call to initialization.
55 FW_ASSERT(this->m_numDividers);
56
57 // Loop through each divider. For a given port, the port will be called when the divider value
58 // divides evenly into the number of ticks. For example, if the divider value for a port is 4,
59 // it would be called every fourth invocation of the CycleIn port.
60 for (NATIVE_INT_TYPE entry = 0; entry < this->m_numDividers; entry++) {
61 if (this->m_dividers[entry] != 0) {
62 if (this->isConnected_CycleOut_OutputPort(entry)) {
63 if ((this->m_ticks % this->m_dividers[entry]) == 0) {
64 this->CycleOut_out(entry,cycleStart);
65 }
66 }
67 }
68 }
69
70 // rollover the tick value when the tick count reaches the rollover value
71 // the rollover value is the product of all the dividers. See comment in constructor.
72 this->m_ticks = (this->m_ticks + 1) % this->m_rollover;
73
74 }
75
76}
#define FW_ASSERT(...)
Definition Assert.hpp:7
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition BasicTypes.h:66
C++-compatible configuration header for fprime configuration.
RateGroupDivider component implementation.
void configure(NATIVE_INT_TYPE dividers[], NATIVE_INT_TYPE numDividers)
RateGroupDriver configuration function.
~RateGroupDriver()
RateGroupDriverImpl destructor.
void init(NATIVE_INT_TYPE instanceId=0)
RateGroupDriver initialization function.
RateGroupDriver(const char *compName)
RateGroupDriver constructor.
Serializable class for carrying timer values.
Definition TimerVal.hpp:22