From dd5304c68edc6c6a2c3b6b70ade2a91a35655dc2 Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Sat, 16 Apr 2022 20:16:17 +0200 Subject: [PATCH] Adds debug log to the common DccDecoder class. (#619) * 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. --- src/freertos_drivers/common/DccDecoder.hxx | 12 ++++++++++++ src/freertos_drivers/common/SimpleLog.hxx | 22 ++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/freertos_drivers/common/DccDecoder.hxx b/src/freertos_drivers/common/DccDecoder.hxx index f66bc266b..45a9cdf3a 100644 --- a/src/freertos_drivers/common/DccDecoder.hxx +++ b/src/freertos_drivers/common/DccDecoder.hxx @@ -198,6 +198,10 @@ private: inputData_->flush(); }; +#ifdef DCC_DECODER_DEBUG + LogRing debugLog_; +#endif + typedef DCCPacket input_data_type; DeviceBuffer *inputData_ { DeviceBuffer::create(Module::Q_SIZE)}; @@ -291,6 +295,11 @@ __attribute__((optimize("-O3"))) void DccDecoder::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) { @@ -311,6 +320,9 @@ __attribute__((optimize("-O3"))) void DccDecoder::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()) diff --git a/src/freertos_drivers/common/SimpleLog.hxx b/src/freertos_drivers/common/SimpleLog.hxx index 79cf4e081..75e8e8d5d 100644 --- a/src/freertos_drivers/common/SimpleLog.hxx +++ b/src/freertos_drivers/common/SimpleLog.hxx @@ -64,24 +64,22 @@ private: /// Actual class that keeps 8 log entries of one byte each. typedef SimpleLog LogBuffer; - /// Alternative for hundreds of entries. -template class LogRing { +template 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_