forked from tud-ccc/RTSim
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
145 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "MemoryTypes/State/Bus.h" | ||
|
||
#include <iostream> | ||
|
||
NVM::State::Bus::Bus() : bank(nullptr), currentState(BUS_STATE::NO_OP) {} | ||
|
||
void NVM::State::Bus::setBank(StateBank* b) { bank = b; } | ||
|
||
bool NVM::State::Bus::read(const Address& address, const RowData& data) { | ||
if (currentState != BUS_STATE::NO_OP) return except(); | ||
currentState = BUS_STATE::READ; | ||
if (bank) return bank->read(address, data); | ||
return false; | ||
} | ||
|
||
bool NVM::State::Bus::write(const Address& address, const RowData& data) { | ||
if (currentState != BUS_STATE::NO_OP) return except(); | ||
currentState = BUS_STATE::WRITE; | ||
if (bank) return bank->write(address, data); | ||
return false; | ||
} | ||
|
||
bool NVM::State::Bus::activate(const Address& address) { | ||
if (currentState != BUS_STATE::NO_OP) return except(); | ||
if (bank) return bank->activate(address); | ||
return false; | ||
} | ||
|
||
bool NVM::State::Bus::precharge(const Address& address) { | ||
if (currentState != BUS_STATE::NO_OP) return except(); | ||
if (bank) return bank->precharge(address); | ||
return false; | ||
} | ||
|
||
bool NVM::State::Bus::refresh() { | ||
if (currentState != BUS_STATE::NO_OP) return except(); | ||
if (bank) return bank->refresh(); | ||
return false; | ||
} | ||
|
||
bool NVM::State::Bus::sendData() { | ||
if (currentState != BUS_STATE::NO_OP) return except(); | ||
return true; | ||
} | ||
|
||
void NVM::State::Bus::cycle() { | ||
commandHistory.push_back(currentState); | ||
currentState = BUS_STATE::NO_OP; | ||
if (bank) bank->cycle(); | ||
} | ||
|
||
void NVM::State::Bus::printCycles() const { | ||
for (const auto state : commandHistory) std::cout << state << '\n'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#pragma once | ||
|
||
#include "MemoryTypes/State/Commandable.h" | ||
#include "MemoryTypes/State/StateBank.h" | ||
|
||
namespace NVM::State { | ||
|
||
class Bus : public Commandable { | ||
public: | ||
Bus(); | ||
|
||
void setBank(StateBank* b); | ||
|
||
/* | ||
* Performs a READ command. | ||
*/ | ||
bool read(const Address& address, const RowData& data); | ||
|
||
/* | ||
* Performs a WRITE command. | ||
*/ | ||
bool write(const Address& address, const RowData& data); | ||
|
||
/* | ||
* Performs an ACTIVATE command. | ||
*/ | ||
bool activate(const Address& address); | ||
|
||
/* | ||
* Performs a PRECHARGE command. | ||
*/ | ||
bool precharge(const Address& address); | ||
|
||
/* | ||
* Performs a REFRESH command. | ||
*/ | ||
bool refresh(); | ||
|
||
bool sendData(); | ||
|
||
void cycle(); | ||
|
||
void printCycles() const; | ||
|
||
private: | ||
StateBank* bank; | ||
|
||
enum class BUS_STATE { READ, WRITE, NO_OP }; | ||
|
||
BUS_STATE currentState; | ||
std::vector<BUS_STATE> commandHistory; | ||
|
||
friend std::ostream& operator<<(std::ostream& out, const BUS_STATE state) { | ||
switch (state) { | ||
case BUS_STATE::NO_OP: | ||
out << "no_op"; | ||
break; | ||
case BUS_STATE::READ: | ||
out << "read"; | ||
break; | ||
case BUS_STATE::WRITE: | ||
out << "write"; | ||
break; | ||
} | ||
return out; | ||
} | ||
}; | ||
|
||
} // namespace NVM::State |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters