Skip to content

Commit

Permalink
Update IO devices upon processor reset #269
Browse files Browse the repository at this point in the history
  • Loading branch information
mortbopet committed Mar 25, 2023
1 parent 2a03b38 commit b67d690
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/io/iobase.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ class IOBase : public QWidget {
*/
virtual unsigned byteSize() const = 0;

/**
* @brief reset
* Hook for an IO device to run a reset procedure upon processor reset.
*/
virtual void reset() {}

/**
* Read/write functions from processor
*/
Expand Down
4 changes: 4 additions & 0 deletions src/io/ioledmatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class IOLedMatrix : public IOBase {
virtual VInt ioRead(AInt offset, unsigned size) override;
virtual void ioWrite(AInt offset, VInt value, unsigned size) override;

virtual void reset() override {
std::fill(m_ledRegs.begin(), m_ledRegs.end(), 0);
}

protected:
virtual void parameterChanged(unsigned) override { updateLEDRegs(); };

Expand Down
7 changes: 7 additions & 0 deletions src/io/iomanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ QString IOManager::cSymbolsHeaderpath() const {
}
}

void IOManager::reset() {
for (auto &device : m_peripherals) {
device->reset();
device->update();
}
}

AInt IOManager::nextPeripheralAddress() const {
AInt base = 0;
if (m_periphMMappings.empty()) {
Expand Down
6 changes: 6 additions & 0 deletions src/io/iomanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ class IOManager : public QObject {
std::vector<std::pair<Symbol, AInt>>
assemblerSymbolsForPeriph(IOBase *peripheral) const;

/**
* @brief reset
* Call to reset all IO devices.
*/
void reset();

signals:
void memoryMapChanged();
void peripheralRemoved(QObject *peripheral);
Expand Down
5 changes: 5 additions & 0 deletions src/processorhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "assembler/program.h"
#include "assembler/rv32i_assembler.h"
#include "assembler/rv64i_assembler.h"
#include "io/iomanager.h"

#include "syscall/riscv_syscall.h"

Expand Down Expand Up @@ -272,6 +273,10 @@ void ProcessorHandler::_reset() {
for (const auto &kv : m_currentRegInits) {
_setRegisterValue(RegisterFileType::GPR, kv.first, kv.second);
}

// Reset IO devices.
IOManager::get().reset();

// Forcing memory values doesn't necessarily mean that the processor will
// notify that its state changed. Manually trigger a state change signal, to
// ensure this.
Expand Down

0 comments on commit b67d690

Please sign in to comment.