From 06ea4a844e893d9125ef8aabb04cdf68c2938b56 Mon Sep 17 00:00:00 2001 From: joevt Date: Sat, 27 Jun 2026 04:39:56 -0700 Subject: [PATCH] dbdma: Add is_active. --- devices/common/dbdma.cpp | 33 +++++++++++++++------------------ devices/common/dbdma.h | 2 ++ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/devices/common/dbdma.cpp b/devices/common/dbdma.cpp index 4ccf4e1d..e7c0d750 100644 --- a/devices/common/dbdma.cpp +++ b/devices/common/dbdma.cpp @@ -358,8 +358,7 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) { if (data & CH_STAT_FLUSH) { if ( this->cur_cmd <= DBDMA_Cmd::INPUT_LAST && - (this->ch_stat & CH_STAT_ACTIVE) && - !(this->ch_stat & CH_STAT_DEAD) + this->is_active() ) { this->ch_stat |= CH_STAT_FLUSH; if (this->dev_obj != nullptr) @@ -495,8 +494,9 @@ void DMAChannel::xfer_retry() { } bool DMAChannel::dma_is_ready() { - if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE) || - this->xfer_dir == DMA_DIR_UNDEF || this->cur_cmd >= DBDMA_Cmd::NOP) + if (!this->is_active() || + this->xfer_dir == DMA_DIR_UNDEF || this->cur_cmd >= DBDMA_Cmd::NOP + ) return false; return true; @@ -506,7 +506,7 @@ DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8 { *avail_len = 0; - if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) { + if (!this->is_active()) { // dead or idle channel? -> no more data LOG_F(WARNING, "%s: Dead/idle channel -> no more data", this->get_name().c_str()); return DmaPullResult::NoMoreData; @@ -604,16 +604,15 @@ void DMAChannel::end_push_data() { } bool DMAChannel::is_out_active() { - if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) { - return false; - } - else { - return true; - } + return this->is_active(); } bool DMAChannel::is_in_active() { - if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) { + return this->is_active(); +} + +bool DMAChannel::is_active() { + if ((this->ch_stat & CH_STAT_DEAD) || !(this->ch_stat & CH_STAT_ACTIVE)) { return false; } else { @@ -643,9 +642,8 @@ void DMAChannel::start() { // between a device and memory (LOAD_QUAD, STORE_QUAD, NOP and STOP). // We thus interprete the DBDMA program until a data transfer between // a device and memory is queued or the channel becomes idle/dead. - while (!this->cmd_in_progress && !(this->ch_stat & CH_STAT_DEAD) && - (this->ch_stat & CH_STAT_ACTIVE)) { - this->interpret_cmd(); + while (!this->cmd_in_progress && this->is_active()) { + this->interpret_cmd(); } } @@ -662,9 +660,8 @@ void DMAChannel::resume() { // between a device and memory (LOAD_QUAD, STORE_QUAD, NOP and STOP). // We thus interprete the DBDMA program until a data transfer between // a device and memory is queued or the channel becomes idle/dead. - while (!this->cmd_in_progress && !(this->ch_stat & CH_STAT_DEAD) && - (this->ch_stat & CH_STAT_ACTIVE)) { - this->interpret_cmd(); + while (!this->cmd_in_progress && this->is_active()) { + this->interpret_cmd(); } } diff --git a/devices/common/dbdma.h b/devices/common/dbdma.h index a2adabb9..ad7cbd3b 100644 --- a/devices/common/dbdma.h +++ b/devices/common/dbdma.h @@ -152,6 +152,8 @@ protected: void abort(void); void pause(void); + bool is_active(); + private: std::function start_cb = nullptr; // DMA channel start callback std::function stop_cb = nullptr; // DMA channel stop callback