Skip to content

Commit

Permalink
Fixing ASSERT and removing m_numDivisors
Browse files Browse the repository at this point in the history
  • Loading branch information
LeStarch committed Oct 26, 2023
1 parent c262890 commit 2766808
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
20 changes: 8 additions & 12 deletions Svc/RateGroupDriver/RateGroupDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,33 @@ namespace Svc {

RateGroupDriver::RateGroupDriver(const char* compName) :
RateGroupDriverComponentBase(compName),
m_numDividers(0),m_ticks(0),m_rollover(1) {
m_ticks(0),m_rollover(1),m_configured(false) {

}

void RateGroupDriver::configure(DividerSet dividersSet)
void RateGroupDriver::configure(const DividerSet& dividersSet)
{

// check arguments
FW_ASSERT(dividersSet.dividers);
this->m_numDividers = RateGroupDriver::DIVIDER_SIZE;
FW_ASSERT(this->m_numDividers <= static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_dividers)),
this->m_numDividers,
static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_dividers)));
// verify port/table size matches
FW_ASSERT(FW_NUM_ARRAY_ELEMENTS(this->m_dividers) == this->getNum_CycleOut_OutputPorts(),
static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_dividers)),
this->getNum_CycleOut_OutputPorts());
// copy provided array of dividers
for (NATIVE_UINT_TYPE entry = 0; entry < RateGroupDriver::DIVIDER_SIZE; entry++) {
// A port with an offset equal or bigger than the divisor is not accepted because it would never be called
FW_ASSERT((this->m_dividers[entry].offset==0)||(this->m_dividers[entry].offset < this->m_dividers[entry].divisor),
this->m_dividers[entry].offset,
this->m_dividers[entry].divisor);
FW_ASSERT((dividersSet.dividers[entry].offset==0)||(dividersSet.dividers[entry].offset < dividersSet.dividers[entry].divisor),
dividersSet.dividers[entry].offset,
dividersSet.dividers[entry].divisor);
this->m_dividers[entry] = dividersSet.dividers[entry];
// rollover value should be product of all dividers to make sure integer rollover doesn't jump cycles
// only use non-zero dividers
if (dividersSet.dividers[entry].divisor != 0) {
this->m_rollover *= dividersSet.dividers[entry].divisor;
}
}

this->m_configured = true;
}

RateGroupDriver::~RateGroupDriver() {
Expand All @@ -49,12 +45,12 @@ namespace Svc {

// Make sure that the dividers have been configured:
// If this asserts, add the configure() call to initialization.
FW_ASSERT(this->m_numDividers);
FW_ASSERT(this->m_configured);

// Loop through each divider. For a given port, the port will be called when the divider value
// divides evenly into the number of ticks. For example, if the divider value for a port is 4,
// it would be called every fourth invocation of the CycleIn port.
for (NATIVE_INT_TYPE entry = 0; entry < this->m_numDividers; entry++) {
for (NATIVE_UINT_TYPE entry = 0; entry < RateGroupDriver::DIVIDER_SIZE; entry++) {
if (this->m_dividers[entry].divisor != 0) {
if (this->isConnected_CycleOut_OutputPort(entry)) {
if ((this->m_ticks % this->m_dividers[entry].divisor) == this->m_dividers[entry].offset) {
Expand Down
8 changes: 4 additions & 4 deletions Svc/RateGroupDriver/RateGroupDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace Svc {
//! \brief RateGroupDriver configuration function
//! \param dividersSet set of dividers used to divide down input tick

void configure(DividerSet dividersSet);
void configure(const DividerSet& dividersSet);

//! \brief RateGroupDriverImpl destructor

Expand All @@ -86,14 +86,14 @@ namespace Svc {
//! divider array
Divider m_dividers[NUM_CYCLEOUT_OUTPUT_PORTS];

//! size of divider array
NATIVE_INT_TYPE m_numDividers;

//! tick counter
NATIVE_INT_TYPE m_ticks;

//! rollover counter
NATIVE_INT_TYPE m_rollover;

//! has the configure method been called
bool m_configured;
};

}
Expand Down

0 comments on commit 2766808

Please sign in to comment.