Skip to content

Commit

Permalink
Rename CustomProtocolInterface to CustomProtocolHal
Browse files Browse the repository at this point in the history
  • Loading branch information
phandinhlan committed Jan 12, 2020
1 parent 9920a37 commit 80399be
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 93 deletions.
4 changes: 2 additions & 2 deletions Sim/HostComm/CustomProtocol/CustomProtocolCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "HostComm/BasicTypes.h"
#include "Buffer/Types.h"

class CustomProtocolInterface;
class CustomProtocolHal;

struct DownloadAndExecutePayload
{
Expand Down Expand Up @@ -80,7 +80,7 @@ struct CustomProtocolCommand

private:
CommandId CommandId;
friend class CustomProtocolInterface;
friend class CustomProtocolHal;
};

#endif
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#include "CustomProtocolInterface.h"
#include "CustomProtocolHal.h"

CustomProtocolInterface::CustomProtocolInterface()
CustomProtocolHal::CustomProtocolHal()
{
_TransferCommandQueue = std::unique_ptr<boost::lockfree::spsc_queue<TransferCommandDesc>>(new boost::lockfree::spsc_queue<TransferCommandDesc>{ 1024 });
}

void CustomProtocolInterface::Init(const char *protocolIpcName, BufferHal *bufferHal)
void CustomProtocolHal::Init(const char *protocolIpcName, BufferHal *bufferHal)
{
_MessageServer = std::make_unique<MessageServer<CustomProtocolCommand>>(protocolIpcName);
_BufferHal = bufferHal;
}

bool CustomProtocolInterface::HasCommand()
bool CustomProtocolHal::HasCommand()
{
return _MessageServer->HasMessage();
}

CustomProtocolCommand* CustomProtocolInterface::GetCommand()
CustomProtocolCommand* CustomProtocolHal::GetCommand()
{
Message<CustomProtocolCommand>* msg = _MessageServer->Pop();
if (msg)
Expand All @@ -28,7 +28,7 @@ CustomProtocolCommand* CustomProtocolInterface::GetCommand()
return nullptr;
}

void CustomProtocolInterface::SubmitResponse(CustomProtocolCommand *command)
void CustomProtocolHal::SubmitResponse(CustomProtocolCommand *command)
{
Message<CustomProtocolCommand> *message = _MessageServer->GetMessage(command->CommandId);
if (message->ExpectsResponse())
Expand All @@ -41,12 +41,12 @@ void CustomProtocolInterface::SubmitResponse(CustomProtocolCommand *command)
}
}

void CustomProtocolInterface::QueueCommand(const TransferCommandDesc& command)
void CustomProtocolHal::QueueCommand(const TransferCommandDesc& command)
{
_TransferCommandQueue->push(command);
}

U8* CustomProtocolInterface::GetBuffer(CustomProtocolCommand *command, const U32 &sectorIndex)
U8* CustomProtocolHal::GetBuffer(CustomProtocolCommand *command, const U32 &sectorIndex)
{
Message<CustomProtocolCommand>* msg = _MessageServer->GetMessage(command->CommandId);
if (msg)
Expand All @@ -59,7 +59,7 @@ U8* CustomProtocolInterface::GetBuffer(CustomProtocolCommand *command, const U32
return nullptr;
}

void CustomProtocolInterface::Run()
void CustomProtocolHal::Run()
{
while (_TransferCommandQueue->empty() == false)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __CustomProtocolInterface_h__
#define __CustomProtocolInterface_h__
#ifndef __CustomProtocolHal_h__
#define __CustomProtocolHal_h__

#include "boost/lockfree/spsc_queue.hpp"

Expand All @@ -11,10 +11,10 @@
#include "Buffer/Hal/BufferHal.h"
#include "Nand/Hal/NandHal.h"

class CustomProtocolInterface : public FrameworkThread
class CustomProtocolHal : public FrameworkThread
{
public:
CustomProtocolInterface();
CustomProtocolHal();

void Init(const char *protocolIpcName = nullptr, BufferHal *bufferHal = nullptr);

Expand Down
4 changes: 2 additions & 2 deletions Sim/HostComm/HostComm.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
<ItemGroup>
<ClInclude Include="BasicTypes.h" />
<ClInclude Include="CustomProtocol\CustomProtocolCommand.h" />
<ClInclude Include="CustomProtocol\CustomProtocolInterface.h" />
<ClInclude Include="CustomProtocol\CustomProtocolHal.h" />
<ClInclude Include="Ipc\Constant.h" />
<ClInclude Include="Ipc\Message.hpp" />
<ClInclude Include="Ipc\MessageBaseService.hpp" />
Expand All @@ -146,7 +146,7 @@
<ClInclude Include="Ipc\SynchronizedQueue.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="CustomProtocol\CustomProtocolInterface.cpp" />
<ClCompile Include="CustomProtocol\CustomProtocolHal.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
14 changes: 7 additions & 7 deletions Sim/HostComm/HostComm.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@
<ClInclude Include="CustomProtocol\CustomProtocolCommand.h">
<Filter>Header Files\CustomProtocol</Filter>
</ClInclude>
<ClInclude Include="CustomProtocol\CustomProtocolInterface.h">
<Filter>Header Files\CustomProtocol</Filter>
</ClInclude>
<ClInclude Include="Ipc\SynchronizedQueue.hpp">
<Filter>Header Files\Ipc</Filter>
</ClInclude>
<ClInclude Include="CustomProtocol\CustomProtocolHal.h">
<Filter>Header Files\CustomProtocol</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="CustomProtocol\CustomProtocolInterface.cpp">
<Filter>Source Files\CustomProtocol</Filter>
</ClCompile>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<ClCompile Include="CustomProtocol\CustomProtocolHal.cpp">
<Filter>Source Files\CustomProtocol</Filter>
</ClCompile>
</ItemGroup>
</Project>
16 changes: 8 additions & 8 deletions Sim/RomCode/RomCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
#include <memory>
#include <functional>

#include "HostComm/CustomProtocol/CustomProtocolInterface.h"
#include "HostComm/CustomProtocol/CustomProtocolHal.h"
#include "Nand/Hal/NandHal.h"

std::function<bool(std::string)> _SetExecuteFunc;
CustomProtocolInterface* _CustomProtocolInterface = nullptr;
CustomProtocolHal* _CustomProtocolHal = nullptr;

extern "C"
{
void __declspec(dllexport) __stdcall Initialize(NandHal* nandHal, BufferHal* bufferHal, CustomProtocolInterface* customProtocolInterface)
void __declspec(dllexport) __stdcall Initialize(NandHal* nandHal, BufferHal* bufferHal, CustomProtocolHal* CustomProtocolHal)
{
_CustomProtocolInterface = customProtocolInterface;
_CustomProtocolHal = CustomProtocolHal;
}

void __declspec(dllexport) __stdcall Execute()
{
if (_CustomProtocolInterface == nullptr)
if (_CustomProtocolHal == nullptr)
{
throw "CustomProtocol is null";
}

if (_CustomProtocolInterface->HasCommand())
if (_CustomProtocolHal->HasCommand())
{
CustomProtocolCommand *command = _CustomProtocolInterface->GetCommand();
CustomProtocolCommand *command = _CustomProtocolHal->GetCommand();

switch (command->Command)
{
Expand All @@ -43,7 +43,7 @@ extern "C"
delete[] temp;

_SetExecuteFunc(filename);
_CustomProtocolInterface->SubmitResponse(command);
_CustomProtocolHal->SubmitResponse(command);
} break;
}
}
Expand Down
10 changes: 5 additions & 5 deletions Sim/SimFramework/FirmwareCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
HMODULE _DllInstance;
HMODULE _NewDllInstance;

typedef void(__stdcall *fInitialize)(NandHal* nandHal, BufferHal* bufferHal, CustomProtocolInterface* customProtocolInterface);
typedef void(__stdcall *fInitialize)(NandHal* nandHal, BufferHal* bufferHal, CustomProtocolHal* CustomProtocolHal);
typedef void(__stdcall *fSetIpcName)(const std::string& ipcName);
typedef void(__stdcall *fExecute)();
typedef void(__stdcall *fExecuteCallback)(std::function<bool(std::string)> callback);
typedef void(__stdcall *fShutdown)();

FirmwareCore::FirmwareCore() : _Execute(nullptr), _NewExecute(nullptr), _NandHal(nullptr), _BufferHal(nullptr), _CustomProtocolInterface(nullptr)
FirmwareCore::FirmwareCore() : _Execute(nullptr), _NewExecute(nullptr), _NandHal(nullptr), _BufferHal(nullptr), _CustomProtocolHal(nullptr)
{
_DllInstance = NULL;
_NewDllInstance = NULL;
Expand All @@ -30,7 +30,7 @@ bool FirmwareCore::SetExecute(std::string Filename)
auto initialize = (fInitialize)GetProcAddress(_NewDllInstance, "Initialize");
if (initialize)
{
initialize(_NandHal, _BufferHal, _CustomProtocolInterface);
initialize(_NandHal, _BufferHal, _CustomProtocolHal);
}

auto execute = (fExecute)GetProcAddress(_NewDllInstance, "Execute");
Expand Down Expand Up @@ -104,9 +104,9 @@ void FirmwareCore::SwapExecute()
_NewDllInstance = NULL;
}

void FirmwareCore::SetHalComponents(NandHal* nandHal, BufferHal* bufferHal, CustomProtocolInterface* customProtocolInterface)
void FirmwareCore::SetHalComponents(NandHal* nandHal, BufferHal* bufferHal, CustomProtocolHal* CustomProtocolHal)
{
_NandHal = nandHal;
_BufferHal = bufferHal;
_CustomProtocolInterface = customProtocolInterface;
_CustomProtocolHal = CustomProtocolHal;
}
6 changes: 3 additions & 3 deletions Sim/SimFramework/FirmwareCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "SimFrameworkBase/FrameworkThread.h"
#include "Nand/Hal/NandHal.h"
#include "Buffer/Hal/BufferHal.h"
#include "HostComm/CustomProtocol/CustomProtocolInterface.h"
#include "HostComm/CustomProtocol/CustomProtocolHal.h"

class FirmwareCore : public FrameworkThread
{
Expand All @@ -17,7 +17,7 @@ class FirmwareCore : public FrameworkThread
FirmwareCore();
bool SetExecute(std::string Filename);
void Unload();
void SetHalComponents(NandHal* nandHal, BufferHal* bufferHal, CustomProtocolInterface* customProtocolInterface);
void SetHalComponents(NandHal* nandHal, BufferHal* bufferHal, CustomProtocolHal* CustomProtocolHal);

private:
void SwapExecute();
Expand All @@ -27,7 +27,7 @@ class FirmwareCore : public FrameworkThread
std::function<void()> _NewExecute;
NandHal* _NandHal;
BufferHal* _BufferHal;
CustomProtocolInterface* _CustomProtocolInterface;
CustomProtocolHal* _CustomProtocolHal;
};

#endif
14 changes: 7 additions & 7 deletions Sim/SimFramework/Framework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ void Framework::Init(const std::string& configFileName, std::string ipcNamesPref
}
}

_CustomProtocolInterface = std::make_shared<CustomProtocolInterface>();
_CustomProtocolInterface->Init(customProtocolIpcName.c_str(), _BufferHal.get());
_CustomProtocolHal = std::make_shared<CustomProtocolHal>();
_CustomProtocolHal->Init(customProtocolIpcName.c_str(), _BufferHal.get());
}

void Framework::SetupNandHal(JSONParser& parser)
Expand Down Expand Up @@ -185,11 +185,11 @@ void Framework::GetFirmwareCoreInfo(JSONParser& parser)
void Framework::operator()()
{
std::future<void> nandHal;
std::future<void> customProtocolInterface;
std::future<void> CustomProtocolHal;
std::future<void> firmwareMain;

// Load ROM
_FirmwareCore->SetHalComponents(_NandHal.get(), _BufferHal.get(), _CustomProtocolInterface.get());
_FirmwareCore->SetHalComponents(_NandHal.get(), _BufferHal.get(), _CustomProtocolHal.get());
_FirmwareCore->SetExecute(this->_RomCodePath);

while (State::Exit != _State)
Expand All @@ -199,7 +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);
CustomProtocolHal = std::async(std::launch::async, &CustomProtocolHal::operator(), _CustomProtocolHal);
firmwareMain = std::async(std::launch::async, &FirmwareCore::operator(), _FirmwareCore);

_State = State::Run;
Expand Down Expand Up @@ -240,11 +240,11 @@ void Framework::operator()()

_FirmwareCore->Stop();
_NandHal->Stop();
_CustomProtocolInterface->Stop();
_CustomProtocolHal->Stop();

firmwareMain.wait();
nandHal.wait();
customProtocolInterface.wait();
CustomProtocolHal.wait();

_FirmwareCore->Unload();
}
4 changes: 2 additions & 2 deletions Sim/SimFramework/Framework.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "FirmwareCore.h"
#include "HostComm/Ipc/MessageServer.hpp"
#include "HostComm/CustomProtocol/CustomProtocolCommand.h"
#include "HostComm/CustomProtocol/CustomProtocolInterface.h"
#include "HostComm/CustomProtocol/CustomProtocolHal.h"

class JSONParser;

Expand Down Expand Up @@ -67,7 +67,7 @@ class Framework
std::shared_ptr<MessageServer<CustomProtocolCommand>> _ProtocolServer;
std::shared_ptr<BufferHal> _BufferHal;
std::shared_ptr<NandHal> _NandHal;
std::shared_ptr<CustomProtocolInterface> _CustomProtocolInterface;
std::shared_ptr<CustomProtocolHal> _CustomProtocolHal;
std::shared_ptr<FirmwareCore> _FirmwareCore;
std::string _RomCodePath;
};
Expand Down
22 changes: 11 additions & 11 deletions Sim/SimpleFtl/SimpleFtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ SimpleFtl::SimpleFtl() : _ProcessingCommand(nullptr)
_EventQueue = std::unique_ptr<boost::lockfree::queue<Event>>(new boost::lockfree::queue<Event>{ 1024 });
}

void SimpleFtl::SetProtocol(CustomProtocolInterface *interface)
void SimpleFtl::SetProtocol(CustomProtocolHal *customProtocolHal)
{
SimpleFtl::_CustomProtocolInterface = interface;
SimpleFtl::_CustomProtocolHal = customProtocolHal;
}

void SimpleFtl::SetNandHal(NandHal *nandHal)
Expand Down Expand Up @@ -166,14 +166,14 @@ void SimpleFtl::ReadNextLbas()

void SimpleFtl::TransferOut(const Buffer &buffer, const NandHal::NandAddress &nandAddress, const U32 &sectorIndex)
{
CustomProtocolInterface::TransferCommandDesc transferCommand;
CustomProtocolHal::TransferCommandDesc transferCommand;
transferCommand.Buffer = buffer;
transferCommand.Command = _ProcessingCommand;
transferCommand.Direction = CustomProtocolInterface::TransferCommandDesc::Direction::Out;
transferCommand.Direction = CustomProtocolHal::TransferCommandDesc::Direction::Out;
transferCommand.SectorIndex = sectorIndex;
transferCommand.NandAddress = nandAddress;
transferCommand.Listener = this;
_CustomProtocolInterface->QueueCommand(transferCommand);
_CustomProtocolHal->QueueCommand(transferCommand);
}

void SimpleFtl::ReadPage(const NandHal::NandAddress &nandAddress, const Buffer &outBuffer, const U32 &descSectorIndex)
Expand Down Expand Up @@ -217,14 +217,14 @@ void SimpleFtl::WriteNextLbas()

void SimpleFtl::TransferIn(const Buffer &buffer, const NandHal::NandAddress &nandAddress, const U32 &sectorIndex)
{
CustomProtocolInterface::TransferCommandDesc transferCommand;
CustomProtocolHal::TransferCommandDesc transferCommand;
transferCommand.Buffer = buffer;
transferCommand.Command = _ProcessingCommand;
transferCommand.Direction = CustomProtocolInterface::TransferCommandDesc::Direction::In;
transferCommand.Direction = CustomProtocolHal::TransferCommandDesc::Direction::In;
transferCommand.SectorIndex = sectorIndex;
transferCommand.NandAddress = nandAddress;
transferCommand.Listener = this;
_CustomProtocolInterface->QueueCommand(transferCommand);
_CustomProtocolHal->QueueCommand(transferCommand);
}

void SimpleFtl::WritePage(const NandHal::NandAddress &nandAddress, const Buffer &inBuffer)
Expand All @@ -241,7 +241,7 @@ void SimpleFtl::WritePage(const NandHal::NandAddress &nandAddress, const Buffer
_NandHal->QueueCommand(commandDesc);
}

void SimpleFtl::OnTransferCommandCompleted(const CustomProtocolInterface::TransferCommandDesc &command)
void SimpleFtl::OnTransferCommandCompleted(const CustomProtocolHal::TransferCommandDesc &command)
{
if (CustomProtocolCommand::Code::Read == _ProcessingCommand->Command)
{
Expand Down Expand Up @@ -302,7 +302,7 @@ void SimpleFtl::SubmitCustomProtocolCommand(CustomProtocolCommand *command)
_EventQueue->push(event);
}

void SimpleFtl::HandleCommandCompleted(const CustomProtocolInterface::TransferCommandDesc &command)
void SimpleFtl::HandleCommandCompleted(const CustomProtocolHal::TransferCommandDesc &command)
{
Event event;
event.EventType = Event::Type::TransferCompleted;
Expand All @@ -326,6 +326,6 @@ bool SimpleFtl::IsProcessingCommand()
void SimpleFtl::SubmitResponse()
{
assert(_ProcessingCommand != nullptr);
_CustomProtocolInterface->SubmitResponse(_ProcessingCommand);
_CustomProtocolHal->SubmitResponse(_ProcessingCommand);
_ProcessingCommand = nullptr;
}
Loading

0 comments on commit 80399be

Please sign in to comment.