From 388842e57864626a976b10ae300aa4437294e904 Mon Sep 17 00:00:00 2001 From: pbrazzle Date: Tue, 6 Feb 2024 12:17:50 -0500 Subject: [PATCH] Setting up Component Connections --- src/MemoryTypes/Component/Bank.cpp | 12 +++++++++ src/MemoryTypes/Component/Bank.h | 6 +++++ src/MemoryTypes/Component/Bus.cpp | 12 +++++++++ src/MemoryTypes/Component/Bus.h | 5 ++++ src/MemoryTypes/Component/ComponentSystem.cpp | 26 ++++++++++++++++--- src/MemoryTypes/Component/ComponentSystem.h | 12 ++++++++- .../Component/MemoryController.cpp | 7 +++++ src/MemoryTypes/Component/MemoryController.h | 4 +++ 8 files changed, 79 insertions(+), 5 deletions(-) diff --git a/src/MemoryTypes/Component/Bank.cpp b/src/MemoryTypes/Component/Bank.cpp index 6846bb3..f9bdaa3 100644 --- a/src/MemoryTypes/Component/Bank.cpp +++ b/src/MemoryTypes/Component/Bank.cpp @@ -13,3 +13,15 @@ void NVM::ComponentType::Bank::cycle() {} NVM::Stats::StatBlock NVM::ComponentType::Bank::getStats() { return Stats::StatBlock(); } + +void NVM::ComponentType::Bank::setResponseConnection( + Connection* connection) { + responseConnection = connection; +} + +void NVM::ComponentType::Bank::setCommandConnection( + Connection* connection) { + commandConnection = connection; +} + +bool NVM::ComponentType::Bank::busy() const { return false; } diff --git a/src/MemoryTypes/Component/Bank.h b/src/MemoryTypes/Component/Bank.h index e857749..511ef52 100644 --- a/src/MemoryTypes/Component/Bank.h +++ b/src/MemoryTypes/Component/Bank.h @@ -26,6 +26,12 @@ class Bank : public Component { */ Stats::StatBlock getStats(); + void setResponseConnection(Connection* connection); + + void setCommandConnection(Connection* connection); + + bool busy() const; + private: Connection* responseConnection; Connection* commandConnection; diff --git a/src/MemoryTypes/Component/Bus.cpp b/src/MemoryTypes/Component/Bus.cpp index 90b3a0a..c5669b4 100644 --- a/src/MemoryTypes/Component/Bus.cpp +++ b/src/MemoryTypes/Component/Bus.cpp @@ -2,6 +2,8 @@ #include "Stats/StatBlock.h" +using namespace NVM::ComponentType; + NVM::ComponentType::Bus::Bus() {} void NVM::ComponentType::Bus::process() {} @@ -11,3 +13,13 @@ void NVM::ComponentType::Bus::cycle() {} NVM::Stats::StatBlock NVM::ComponentType::Bus::getStats() { return Stats::StatBlock(); } + +bool NVM::ComponentType::Bus::busy() const { return false; } + +Connection* NVM::ComponentType::Bus::getResponseConnection() { + return &bankConnection; +} + +Connection* NVM::ComponentType::Bus::getCommandConnection() { + return &commandConnection; +} diff --git a/src/MemoryTypes/Component/Bus.h b/src/MemoryTypes/Component/Bus.h index d65be22..bc8e968 100644 --- a/src/MemoryTypes/Component/Bus.h +++ b/src/MemoryTypes/Component/Bus.h @@ -26,6 +26,11 @@ class Bus : public Component { */ Stats::StatBlock getStats(); + bool busy() const; + + Connection* getResponseConnection(); + Connection* getCommandConnection(); + private: Connection bankConnection; Connection commandConnection; diff --git a/src/MemoryTypes/Component/ComponentSystem.cpp b/src/MemoryTypes/Component/ComponentSystem.cpp index 5ab0186..00a3737 100644 --- a/src/MemoryTypes/Component/ComponentSystem.cpp +++ b/src/MemoryTypes/Component/ComponentSystem.cpp @@ -2,9 +2,23 @@ #include "Stats/StatBlock.h" -void NVM::ComponentType::ComponentSystem::process() {} +NVM::ComponentType::ComponentSystem::ComponentSystem() { + bank.setCommandConnection(bus.getCommandConnection()); + bank.setResponseConnection(bus.getResponseConnection()); + controller.setCommandConnection(bus.getCommandConnection()); +} + +void NVM::ComponentType::ComponentSystem::process() { + bank.process(); + bus.process(); + controller.process(); +} -void NVM::ComponentType::ComponentSystem::cycle() {} +void NVM::ComponentType::ComponentSystem::cycle() { + bank.cycle(); + bus.cycle(); + controller.cycle(); +} NVM::Stats::StatBlock NVM::ComponentType::ComponentSystem::getStats() { return Stats::StatBlock(); @@ -32,9 +46,13 @@ bool NVM::ComponentType::ComponentSystem::pim(std::vector
operands, return true; } -bool NVM::ComponentType::ComponentSystem::isEmpty() const { return true; } +bool NVM::ComponentType::ComponentSystem::isEmpty() const { + return !(bank.busy() || bus.busy() || controller.busy()); +} -void NVM::ComponentType::ComponentSystem::cycle(unsigned int cycles) {} +void NVM::ComponentType::ComponentSystem::cycle(unsigned int cycles) { + for (int i = 0; i < cycles; i++) cycle(); +} void NVM::ComponentType::ComponentSystem::printStats(std::ostream& statStream) { diff --git a/src/MemoryTypes/Component/ComponentSystem.h b/src/MemoryTypes/Component/ComponentSystem.h index 231c329..ca6d679 100644 --- a/src/MemoryTypes/Component/ComponentSystem.h +++ b/src/MemoryTypes/Component/ComponentSystem.h @@ -1,12 +1,17 @@ #pragma once #include "Memory/MemorySystem.h" +#include "MemoryTypes/Component/Bank.h" +#include "MemoryTypes/Component/Bus.h" #include "MemoryTypes/Component/Component.h" +#include "MemoryTypes/Component/MemoryController.h" namespace NVM::ComponentType { class ComponentSystem : public NVM::Memory::MemorySystem, Component { public: + ComponentSystem(); + /* * Processes incoming commands from upstream Components */ @@ -34,9 +39,14 @@ class ComponentSystem : public NVM::Memory::MemorySystem, Component { bool isEmpty() const; - void cycle(unsigned int cycles = 1); + void cycle(unsigned int cycles); void printStats(std::ostream& statStream); + + private: + Bank bank; + MemoryController controller; + Bus bus; }; } // namespace NVM::ComponentType \ No newline at end of file diff --git a/src/MemoryTypes/Component/MemoryController.cpp b/src/MemoryTypes/Component/MemoryController.cpp index 3757709..076eef4 100644 --- a/src/MemoryTypes/Component/MemoryController.cpp +++ b/src/MemoryTypes/Component/MemoryController.cpp @@ -12,3 +12,10 @@ void NVM::ComponentType::MemoryController::cycle() {} NVM::Stats::StatBlock NVM::ComponentType::MemoryController::getStats() { return Stats::StatBlock(); } + +void NVM::ComponentType::MemoryController::setCommandConnection( + Connection* connection) { + commandConnection = connection; +} + +bool NVM::ComponentType::MemoryController::busy() const { return false; } diff --git a/src/MemoryTypes/Component/MemoryController.h b/src/MemoryTypes/Component/MemoryController.h index cc3d54d..471baf4 100644 --- a/src/MemoryTypes/Component/MemoryController.h +++ b/src/MemoryTypes/Component/MemoryController.h @@ -25,6 +25,10 @@ class MemoryController : public Component { */ Stats::StatBlock getStats(); + void setCommandConnection(Connection* connection); + + bool busy() const; + private: Connection* commandConnection; };