From 3aad040f289f402417e931c0b1f26c69fe9fd04a Mon Sep 17 00:00:00 2001 From: Maxim Poliakovski Date: Sun, 21 Apr 2024 22:56:08 +0200 Subject: [PATCH] mesh: improve exception register emulation. --- devices/common/scsi/mesh.cpp | 28 ++++++++++++---------------- devices/common/scsi/mesh.h | 4 ++-- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/devices/common/scsi/mesh.cpp b/devices/common/scsi/mesh.cpp index 37e4106..c279058 100644 --- a/devices/common/scsi/mesh.cpp +++ b/devices/common/scsi/mesh.cpp @@ -33,8 +33,7 @@ along with this program. If not, see . using namespace MeshScsi; -int MeshController::device_postinit() -{ +int MeshController::device_postinit() { this->bus_obj = dynamic_cast(gMachineObj->get_comp_by_name("ScsiMesh")); this->int_ctrl = dynamic_cast( @@ -44,11 +43,11 @@ int MeshController::device_postinit() return 0; } -void MeshController::reset(bool is_hard_reset) -{ +void MeshController::reset(bool is_hard_reset) { this->cur_cmd = SeqCmd::NoOperation; this->fifo_cnt = 0; this->int_mask = 0; + this->exception = 0; this->xfer_count = 0; this->src_id = 7; @@ -58,8 +57,7 @@ void MeshController::reset(bool is_hard_reset) } } -uint8_t MeshController::read(uint8_t reg_offset) -{ +uint8_t MeshController::read(uint8_t reg_offset) { switch(reg_offset) { case MeshReg::XferCount0: return this->xfer_count & 0xFFU; @@ -74,7 +72,7 @@ uint8_t MeshController::read(uint8_t reg_offset) case MeshReg::FIFOCount: return this->fifo_cnt; case MeshReg::Exception: - return 0; + return this->exception; case MeshReg::Error: return 0; case MeshReg::IntMask: @@ -94,8 +92,7 @@ uint8_t MeshController::read(uint8_t reg_offset) return 0; } -void MeshController::write(uint8_t reg_offset, uint8_t value) -{ +void MeshController::write(uint8_t reg_offset, uint8_t value) { uint16_t new_stat; switch(reg_offset) { @@ -141,19 +138,20 @@ void MeshController::write(uint8_t reg_offset, uint8_t value) } } -void MeshController::perform_command(const uint8_t cmd) -{ +void MeshController::perform_command(const uint8_t cmd) { this->cur_cmd = cmd; this->int_stat &= ~INT_CMD_DONE; switch (this->cur_cmd & 0xF) { case SeqCmd::Arbitrate: + this->exception &= EXC_ARB_LOST; this->bus_obj->release_ctrl_lines(this->src_id); this->cur_state = SeqState::BUS_FREE; this->sequencer(); break; case SeqCmd::Select: + this->exception &= EXC_SEL_TIMEOUT; this->cur_state = SeqState::SEL_BEGIN; this->sequencer(); break; @@ -162,7 +160,7 @@ void MeshController::perform_command(const uint8_t cmd) this->int_stat |= INT_CMD_DONE; break; case SeqCmd::EnaReselect: - LOG_F(INFO, "MESH: EnaReselect stub invoked"); + LOG_F(9, "MESH: EnaReselect stub invoked"); this->int_stat |= INT_CMD_DONE; break; case SeqCmd::DisReselect: @@ -182,8 +180,7 @@ void MeshController::perform_command(const uint8_t cmd) } } -void MeshController::seq_defer_state(uint64_t delay_ns) -{ +void MeshController::seq_defer_state(uint64_t delay_ns) { seq_timer_id = TimerManager::get_instance()->add_oneshot_timer( delay_ns, [this]() { @@ -254,8 +251,7 @@ void MeshController::sequencer() } } -void MeshController::update_irq() -{ +void MeshController::update_irq() { uint8_t new_irq = !!(this->int_stat & this->int_mask); if (new_irq != this->irq) { this->irq = new_irq; diff --git a/devices/common/scsi/mesh.h b/devices/common/scsi/mesh.h index 2a5a20b..31c7c72 100644 --- a/devices/common/scsi/mesh.h +++ b/devices/common/scsi/mesh.h @@ -157,7 +157,7 @@ protected: private: uint8_t chip_id; - uint8_t int_mask; + uint8_t int_mask = 0; uint8_t int_stat = 0; uint8_t sync_params; uint8_t src_id; @@ -165,7 +165,7 @@ private: uint8_t cur_cmd; uint8_t error; uint8_t fifo_cnt; - uint8_t exception; + uint8_t exception = 0; uint32_t xfer_count; ScsiBus* bus_obj;