diff --git a/Sim/RomCode/RomCode.cpp b/Sim/RomCode/RomCode.cpp index f840ff8..08b731c 100644 --- a/Sim/RomCode/RomCode.cpp +++ b/Sim/RomCode/RomCode.cpp @@ -8,10 +8,15 @@ #include "Nand/Hal/NandHal.h" std::function _SetExecuteFunc; -std::unique_ptr _CustomProtocolInterface = nullptr; +CustomProtocolInterface* _CustomProtocolInterface = nullptr; extern "C" { + void __declspec(dllexport) __stdcall Initialize(NandHal* nandHal, BufferHal* bufferHal, CustomProtocolInterface* customProtocolInterface) + { + _CustomProtocolInterface = customProtocolInterface; + } + void __declspec(dllexport) __stdcall Execute() { if (_CustomProtocolInterface == nullptr) @@ -44,12 +49,6 @@ extern "C" } } - void __declspec(dllexport) __stdcall SetCustomProtocolIpcName(const std::string& protocolIpcName) - { - _CustomProtocolInterface = std::make_unique(); - _CustomProtocolInterface->Init(protocolIpcName.c_str()); - } - void __declspec(dllexport) __stdcall SetExecuteCallback(std::function setExecuteFunc) { _SetExecuteFunc = setExecuteFunc; diff --git a/Sim/SimFramework/FirmwareCore.cpp b/Sim/SimFramework/FirmwareCore.cpp index 74b3c47..df10e0d 100644 --- a/Sim/SimFramework/FirmwareCore.cpp +++ b/Sim/SimFramework/FirmwareCore.cpp @@ -6,13 +6,13 @@ HMODULE _DllInstance; HMODULE _NewDllInstance; -typedef void(__stdcall *fInitialize)(std::shared_ptr nandHal, std::shared_ptr bufferHal); +typedef void(__stdcall *fInitialize)(NandHal* nandHal, BufferHal* bufferHal, CustomProtocolInterface* customProtocolInterface); typedef void(__stdcall *fSetIpcName)(const std::string& ipcName); typedef void(__stdcall *fExecute)(); typedef void(__stdcall *fExecuteCallback)(std::function callback); typedef void(__stdcall *fShutdown)(); -FirmwareCore::FirmwareCore() : _Execute(nullptr), _NewExecute(nullptr), _NandHal(nullptr), _BufferHal(nullptr) +FirmwareCore::FirmwareCore() : _Execute(nullptr), _NewExecute(nullptr), _NandHal(nullptr), _BufferHal(nullptr), _CustomProtocolInterface(nullptr) { _DllInstance = NULL; _NewDllInstance = NULL; @@ -27,21 +27,12 @@ bool FirmwareCore::SetExecute(std::string Filename) return false; } - // search the Initialize and execute auto initialize = (fInitialize)GetProcAddress(_NewDllInstance, "Initialize"); if (initialize) { - initialize(_NandHal, _BufferHal); + initialize(_NandHal, _BufferHal, _CustomProtocolInterface); } - // search the SetIpcName functions and execute - auto setIpcName = (fSetIpcName)GetProcAddress(_NewDllInstance, "SetCustomProtocolIpcName"); - if (setIpcName) - { - setIpcName(_CustomProtocolIpcName); - } - - // resolve function address here auto execute = (fExecute)GetProcAddress(_NewDllInstance, "Execute"); if (!execute) { @@ -49,7 +40,6 @@ bool FirmwareCore::SetExecute(std::string Filename) return false; } - // search the SetExecuteCall and set auto setExecuteCallback = (fExecuteCallback)GetProcAddress(_NewDllInstance, "SetExecuteCallback"); if (setExecuteCallback) { @@ -114,13 +104,9 @@ void FirmwareCore::SwapExecute() _NewDllInstance = NULL; } -void FirmwareCore::SetHalComponents(std::shared_ptr nandHal, std::shared_ptr bufferHal) +void FirmwareCore::SetHalComponents(NandHal* nandHal, BufferHal* bufferHal, CustomProtocolInterface* customProtocolInterface) { _NandHal = nandHal; _BufferHal = bufferHal; -} - -void FirmwareCore::SetIpcNames(const std::string& customProtocolIpcName) -{ - _CustomProtocolIpcName = customProtocolIpcName; + _CustomProtocolInterface = customProtocolInterface; } diff --git a/Sim/SimFramework/FirmwareCore.h b/Sim/SimFramework/FirmwareCore.h index e9dd6ec..1f2edde 100644 --- a/Sim/SimFramework/FirmwareCore.h +++ b/Sim/SimFramework/FirmwareCore.h @@ -6,6 +6,7 @@ #include "SimFrameworkBase/FrameworkThread.h" #include "Nand/Hal/NandHal.h" #include "Buffer/Hal/BufferHal.h" +#include "HostComm/CustomProtocol/CustomProtocolInterface.h" class FirmwareCore : public FrameworkThread { @@ -16,8 +17,7 @@ class FirmwareCore : public FrameworkThread FirmwareCore(); bool SetExecute(std::string Filename); void Unload(); - void SetHalComponents(std::shared_ptr nandHal, std::shared_ptr bufferHal); - void SetIpcNames(const std::string& customProtocolIpcName); + void SetHalComponents(NandHal* nandHal, BufferHal* bufferHal, CustomProtocolInterface* customProtocolInterface); private: void SwapExecute(); @@ -25,9 +25,9 @@ class FirmwareCore : public FrameworkThread private: std::function _Execute; std::function _NewExecute; - std::shared_ptr _NandHal; - std::shared_ptr _BufferHal; - std::string _CustomProtocolIpcName; + NandHal* _NandHal; + BufferHal* _BufferHal; + CustomProtocolInterface* _CustomProtocolInterface; }; #endif \ No newline at end of file diff --git a/Sim/SimFramework/Framework.cpp b/Sim/SimFramework/Framework.cpp index 5b5313e..34551c7 100644 --- a/Sim/SimFramework/Framework.cpp +++ b/Sim/SimFramework/Framework.cpp @@ -70,7 +70,8 @@ void Framework::Init(const std::string& configFileName, std::string ipcNamesPref } } - _FirmwareCore->SetIpcNames(customProtocolIpcName); + _CustomProtocolInterface = std::make_shared(); + _CustomProtocolInterface->Init(customProtocolIpcName.c_str(), _BufferHal.get()); } void Framework::SetupNandHal(JSONParser& parser) @@ -184,10 +185,11 @@ void Framework::GetFirmwareCoreInfo(JSONParser& parser) void Framework::operator()() { std::future nandHal; + std::future customProtocolInterface; std::future firmwareMain; // Load ROM - _FirmwareCore->SetHalComponents(_NandHal, _BufferHal); + _FirmwareCore->SetHalComponents(_NandHal.get(), _BufferHal.get(), _CustomProtocolInterface.get()); _FirmwareCore->SetExecute(this->_RomCodePath); while (State::Exit != _State) @@ -197,6 +199,7 @@ void Framework::operator()() case State::Start: { nandHal = std::async(std::launch::async, &NandHal::operator(), _NandHal); + customProtocolInterface = std::async(std::launch::async, &CustomProtocolInterface::operator(), _CustomProtocolInterface); firmwareMain = std::async(std::launch::async, &FirmwareCore::operator(), _FirmwareCore); _State = State::Run; @@ -237,9 +240,11 @@ void Framework::operator()() _FirmwareCore->Stop(); _NandHal->Stop(); + _CustomProtocolInterface->Stop(); firmwareMain.wait(); nandHal.wait(); + customProtocolInterface.wait(); _FirmwareCore->Unload(); } diff --git a/Sim/SimFramework/Framework.h b/Sim/SimFramework/Framework.h index 247cabf..dc5c97d 100644 --- a/Sim/SimFramework/Framework.h +++ b/Sim/SimFramework/Framework.h @@ -10,6 +10,7 @@ #include "FirmwareCore.h" #include "HostComm/Ipc/MessageServer.hpp" #include "HostComm/CustomProtocol/CustomProtocolCommand.h" +#include "HostComm/CustomProtocol/CustomProtocolInterface.h" class JSONParser; @@ -66,6 +67,7 @@ class Framework std::shared_ptr> _ProtocolServer; std::shared_ptr _BufferHal; std::shared_ptr _NandHal; + std::shared_ptr _CustomProtocolInterface; std::shared_ptr _FirmwareCore; std::string _RomCodePath; }; diff --git a/Sim/SimFramework/SimFramework.vcxproj b/Sim/SimFramework/SimFramework.vcxproj index 1e639f2..33e20a8 100644 --- a/Sim/SimFramework/SimFramework.vcxproj +++ b/Sim/SimFramework/SimFramework.vcxproj @@ -144,6 +144,11 @@ + + + {fdf75646-6e43-4a8a-bc13-d597b68754c2} + + diff --git a/Sim/SimpleFtl/SimpleFtlCode.cpp b/Sim/SimpleFtl/SimpleFtlCode.cpp index af46445..96a45bc 100644 --- a/Sim/SimpleFtl/SimpleFtlCode.cpp +++ b/Sim/SimpleFtl/SimpleFtlCode.cpp @@ -5,18 +5,17 @@ #include "Nand/Hal/NandHal.h" #include "SimpleFtl.h" -std::shared_ptr _CustomProtocolInterface = nullptr; -std::shared_ptr _BufferHal = nullptr; +CustomProtocolInterface* _CustomProtocolInterface = nullptr; SimpleFtl _SimpleFtl; -std::future _CustomProtocolInterfaceFuture; extern "C" { - void __declspec(dllexport) __stdcall Initialize(std::shared_ptr nandHal, std::shared_ptr bufferHal) + void __declspec(dllexport) __stdcall Initialize(NandHal* nandHal, BufferHal* bufferHal, CustomProtocolInterface* customProtocolInterface) { - _SimpleFtl.SetNandHal(nandHal.get()); - _SimpleFtl.SetBufferHal(bufferHal.get()); - _BufferHal = bufferHal; + _SimpleFtl.SetNandHal(nandHal); + _SimpleFtl.SetBufferHal(bufferHal); + _SimpleFtl.SetProtocol(customProtocolInterface); + _CustomProtocolInterface = customProtocolInterface; } void __declspec(dllexport) __stdcall Execute() @@ -34,23 +33,8 @@ extern "C" _SimpleFtl(); } - void __declspec(dllexport) __stdcall SetCustomProtocolIpcName(const std::string& protocolIpcName) - { - _CustomProtocolInterface = std::make_shared(); - _CustomProtocolInterface->Init(protocolIpcName.c_str(), _BufferHal.get()); - _SimpleFtl.SetProtocol(_CustomProtocolInterface.get()); - - _CustomProtocolInterfaceFuture = std::async(std::launch::async, &CustomProtocolInterface::operator(), _CustomProtocolInterface); - } - void __declspec(dllexport) __stdcall Shutdown() { - if (_CustomProtocolInterface == nullptr) - { - return; - } - - _CustomProtocolInterface->Stop(); - _CustomProtocolInterfaceFuture.wait(); + } }; diff --git a/SsdSim.sln b/SsdSim.sln index bceeb2b..98d4e84 100644 --- a/SsdSim.sln +++ b/SsdSim.sln @@ -20,6 +20,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Nand", "Sim\Nand\Nand.vcxpr EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SimFramework", "Sim\SimFramework\SimFramework.vcxproj", "{89F1CB64-54C0-4448-8D36-7BFC3D7A8CC4}" ProjectSection(ProjectDependencies) = postProject + {FDF75646-6E43-4A8A-BC13-D597B68754C2} = {FDF75646-6E43-4A8A-BC13-D597B68754C2} {E2C37474-B57F-49F8-B5BB-EB427C95A2E1} = {E2C37474-B57F-49F8-B5BB-EB427C95A2E1} EndProjectSection EndProject