Skip to content

Commit

Permalink
Adds debug log to the common DccDecoder class. (#619)
Browse files Browse the repository at this point in the history
* Adds debug log to the common DccDecoder class.

* Switches LogRing to assign values forward instead of backward.
It is confusing and unexpected to look at an array in gdb and
see the values in the wrong order.
  • Loading branch information
balazsracz authored Apr 16, 2022
1 parent 28df8db commit dd5304c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
12 changes: 12 additions & 0 deletions src/freertos_drivers/common/DccDecoder.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ private:
inputData_->flush();
};

#ifdef DCC_DECODER_DEBUG
LogRing<uint16_t, 256> debugLog_;
#endif

typedef DCCPacket input_data_type;
DeviceBuffer<DCCPacket> *inputData_ {
DeviceBuffer<DCCPacket>::create(Module::Q_SIZE)};
Expand Down Expand Up @@ -291,6 +295,11 @@ __attribute__((optimize("-O3"))) void DccDecoder<Module>::interrupt_handler()
// Debug::DccDecodeInterrupts::toggle();
uint32_t raw_new_value = Module::get_capture_counter();
uint32_t old_value = lastTimerValue_;
#ifdef DCC_DECODER_DEBUG
debugLog_.add(0);
debugLog_.add(old_value);
debugLog_.add(raw_new_value);
#endif
if (raw_new_value > old_value) {
// Timer has overflowed.
if (nextSample_ < old_value) {
Expand All @@ -311,6 +320,9 @@ __attribute__((optimize("-O3"))) void DccDecoder<Module>::interrupt_handler()
nextSample_ -= Module::SAMPLE_PERIOD_CLOCKS;
}
uint32_t new_value = old_value - raw_new_value;
#ifdef DCC_DECODER_DEBUG
debugLog_.add(new_value);
#endif
bool cutout_just_finished = false;
decoder_.process_data(new_value);
if (decoder_.before_dcc_cutout())
Expand Down
22 changes: 10 additions & 12 deletions src/freertos_drivers/common/SimpleLog.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,22 @@ private:
/// Actual class that keeps 8 log entries of one byte each.
typedef SimpleLog<uint64_t> LogBuffer;


/// Alternative for hundreds of entries.
template<class T, int N> class LogRing {
template <class T, int N> class LogRing
{
public:
void add(T data) {
data_[next_] = data;
last_ = data_ + next_;
if (next_) {
--next_;
} else {
next_ = N-1;
void add(T data)
{
data_[next_++] = data;
if (next_ >= N)
{
next_ = 0;
}
}

private:
T data_[N];
unsigned next_{N};
T* last_{data_};
unsigned next_ {0};
};

#endif // _FREERTOS_DRIVERS_COMMON_SIMPLELOG_HXX_

0 comments on commit dd5304c

Please sign in to comment.