Skip to content

Commit

Permalink
FPGA primitive APIs. (#1076)
Browse files Browse the repository at this point in the history
* struct params + few primitive

* remove struct APIs
  • Loading branch information
amehra-ni authored Aug 7, 2024
1 parent 9f32d64 commit c58c89d
Show file tree
Hide file tree
Showing 11 changed files with 382 additions and 7 deletions.
56 changes: 56 additions & 0 deletions generated/nifpga/nifpga.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ service NiFpga {
rpc Abort(AbortRequest) returns (AbortResponse);
rpc Close(CloseRequest) returns (CloseResponse);
rpc CommitFifoConfiguration(CommitFifoConfigurationRequest) returns (CommitFifoConfigurationResponse);
rpc ConfigureFifo(ConfigureFifoRequest) returns (ConfigureFifoResponse);
rpc ConfigureFifo2(ConfigureFifo2Request) returns (ConfigureFifo2Response);
rpc Download(DownloadRequest) returns (DownloadResponse);
rpc FindFifo(FindFifoRequest) returns (FindFifoResponse);
rpc FindRegister(FindRegisterRequest) returns (FindRegisterResponse);
rpc Open(OpenRequest) returns (OpenResponse);
rpc ReadArrayBool(ReadArrayBoolRequest) returns (ReadArrayBoolResponse);
rpc ReadArrayDbl(ReadArrayDblRequest) returns (ReadArrayDblResponse);
Expand Down Expand Up @@ -86,6 +90,7 @@ service NiFpga {
rpc WriteFifoU8(WriteFifoU8Request) returns (WriteFifoU8Response);
rpc WriteI16(WriteI16Request) returns (WriteI16Response);
rpc WriteI32(WriteI32Request) returns (WriteI32Response);
rpc WriteI64(WriteI64Request) returns (WriteI64Response);
rpc WriteI8(WriteI8Request) returns (WriteI8Response);
rpc WriteSgl(WriteSglRequest) returns (WriteSglResponse);
rpc WriteU16(WriteU16Request) returns (WriteU16Response);
Expand Down Expand Up @@ -120,6 +125,27 @@ message CommitFifoConfigurationResponse {
int32 status = 1;
}

message ConfigureFifoRequest {
nidevice_grpc.Session session = 1;
uint32 fifo = 2;
uint32 depth = 3;
}

message ConfigureFifoResponse {
int32 status = 1;
}

message ConfigureFifo2Request {
nidevice_grpc.Session session = 1;
uint32 fifo = 2;
uint32 requested_depth = 3;
}

message ConfigureFifo2Response {
int32 status = 1;
uint32 actual_depth = 2;
}

message DownloadRequest {
nidevice_grpc.Session session = 1;
}
Expand All @@ -128,6 +154,26 @@ message DownloadResponse {
int32 status = 1;
}

message FindFifoRequest {
nidevice_grpc.Session session = 1;
string fifo_name = 2;
}

message FindFifoResponse {
int32 status = 1;
uint32 fifo_number = 2;
}

message FindRegisterRequest {
nidevice_grpc.Session session = 1;
string register_name = 2;
}

message FindRegisterResponse {
int32 status = 1;
uint32 register_offset = 2;
}

message OpenRequest {
string session_name = 1;
string bitfile = 2;
Expand Down Expand Up @@ -853,6 +899,16 @@ message WriteI32Response {
int32 status = 1;
}

message WriteI64Request {
nidevice_grpc.Session session = 1;
uint32 control = 2;
int64 value = 3;
}

message WriteI64Response {
int32 status = 1;
}

message WriteI8Request {
nidevice_grpc.Session session = 1;
uint32 control = 2;
Expand Down
93 changes: 93 additions & 0 deletions generated/nifpga/nifpga_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,44 @@ commit_fifo_configuration(const StubPtr& stub, const nidevice_grpc::Session& ses
return response;
}

ConfigureFifoResponse
configure_fifo(const StubPtr& stub, const nidevice_grpc::Session& session, const pb::uint32& fifo, const pb::uint32& depth)
{
::grpc::ClientContext context;

auto request = ConfigureFifoRequest{};
request.mutable_session()->CopyFrom(session);
request.set_fifo(fifo);
request.set_depth(depth);

auto response = ConfigureFifoResponse{};

raise_if_error(
stub->ConfigureFifo(&context, request, &response),
context);

return response;
}

ConfigureFifo2Response
configure_fifo2(const StubPtr& stub, const nidevice_grpc::Session& session, const pb::uint32& fifo, const pb::uint32& requested_depth)
{
::grpc::ClientContext context;

auto request = ConfigureFifo2Request{};
request.mutable_session()->CopyFrom(session);
request.set_fifo(fifo);
request.set_requested_depth(requested_depth);

auto response = ConfigureFifo2Response{};

raise_if_error(
stub->ConfigureFifo2(&context, request, &response),
context);

return response;
}

DownloadResponse
download(const StubPtr& stub, const nidevice_grpc::Session& session)
{
Expand All @@ -87,6 +125,42 @@ download(const StubPtr& stub, const nidevice_grpc::Session& session)
return response;
}

FindFifoResponse
find_fifo(const StubPtr& stub, const nidevice_grpc::Session& session, const std::string& fifo_name)
{
::grpc::ClientContext context;

auto request = FindFifoRequest{};
request.mutable_session()->CopyFrom(session);
request.set_fifo_name(fifo_name);

auto response = FindFifoResponse{};

raise_if_error(
stub->FindFifo(&context, request, &response),
context);

return response;
}

FindRegisterResponse
find_register(const StubPtr& stub, const nidevice_grpc::Session& session, const std::string& register_name)
{
::grpc::ClientContext context;

auto request = FindRegisterRequest{};
request.mutable_session()->CopyFrom(session);
request.set_register_name(register_name);

auto response = FindRegisterResponse{};

raise_if_error(
stub->FindRegister(&context, request, &response),
context);

return response;
}

OpenResponse
open(const StubPtr& stub, const std::string& bitfile, const std::string& signature, const std::string& resource, const pb::uint32& attribute, const nidevice_grpc::SessionInitializationBehavior& initialization_behavior)
{
Expand Down Expand Up @@ -1348,6 +1422,25 @@ write_i32(const StubPtr& stub, const nidevice_grpc::Session& session, const pb::
return response;
}

WriteI64Response
write_i64(const StubPtr& stub, const nidevice_grpc::Session& session, const pb::uint32& control, const pb::int64& value)
{
::grpc::ClientContext context;

auto request = WriteI64Request{};
request.mutable_session()->CopyFrom(session);
request.set_control(control);
request.set_value(value);

auto response = WriteI64Response{};

raise_if_error(
stub->WriteI64(&context, request, &response),
context);

return response;
}

WriteI8Response
write_i8(const StubPtr& stub, const nidevice_grpc::Session& session, const pb::uint32& control, const pb::int32& value)
{
Expand Down
5 changes: 5 additions & 0 deletions generated/nifpga/nifpga_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ using namespace nidevice_grpc::experimental::client;
AbortResponse abort(const StubPtr& stub, const nidevice_grpc::Session& session);
CloseResponse close(const StubPtr& stub, const nidevice_grpc::Session& session, const pb::uint32& attribute);
CommitFifoConfigurationResponse commit_fifo_configuration(const StubPtr& stub, const nidevice_grpc::Session& session, const pb::uint32& fifo);
ConfigureFifoResponse configure_fifo(const StubPtr& stub, const nidevice_grpc::Session& session, const pb::uint32& fifo, const pb::uint32& depth);
ConfigureFifo2Response configure_fifo2(const StubPtr& stub, const nidevice_grpc::Session& session, const pb::uint32& fifo, const pb::uint32& requested_depth);
DownloadResponse download(const StubPtr& stub, const nidevice_grpc::Session& session);
FindFifoResponse find_fifo(const StubPtr& stub, const nidevice_grpc::Session& session, const std::string& fifo_name);
FindRegisterResponse find_register(const StubPtr& stub, const nidevice_grpc::Session& session, const std::string& register_name);
OpenResponse open(const StubPtr& stub, const std::string& bitfile, const std::string& signature, const std::string& resource, const pb::uint32& attribute, const nidevice_grpc::SessionInitializationBehavior& initialization_behavior = nidevice_grpc::SESSION_INITIALIZATION_BEHAVIOR_UNSPECIFIED);
ReadArrayBoolResponse read_array_bool(const StubPtr& stub, const nidevice_grpc::Session& session, const pb::uint32& indicator, const pb::uint32& size);
ReadArrayDblResponse read_array_dbl(const StubPtr& stub, const nidevice_grpc::Session& session, const pb::uint32& indicator, const pb::uint32& size);
Expand Down Expand Up @@ -92,6 +96,7 @@ WriteFifoU64Response write_fifo_u64(const StubPtr& stub, const nidevice_grpc::Se
WriteFifoU8Response write_fifo_u8(const StubPtr& stub, const nidevice_grpc::Session& session, const pb::uint32& fifo, const std::vector<pb::uint32>& data, const pb::uint32& timeout);
WriteI16Response write_i16(const StubPtr& stub, const nidevice_grpc::Session& session, const pb::uint32& control, const pb::int32& value);
WriteI32Response write_i32(const StubPtr& stub, const nidevice_grpc::Session& session, const pb::uint32& control, const pb::int32& value);
WriteI64Response write_i64(const StubPtr& stub, const nidevice_grpc::Session& session, const pb::uint32& control, const pb::int64& value);
WriteI8Response write_i8(const StubPtr& stub, const nidevice_grpc::Session& session, const pb::uint32& control, const pb::int32& value);
WriteSglResponse write_sgl(const StubPtr& stub, const nidevice_grpc::Session& session, const pb::uint32& control, const float& value);
WriteU16Response write_u16(const StubPtr& stub, const nidevice_grpc::Session& session, const pb::uint32& control, const pb::uint32& value);
Expand Down
25 changes: 25 additions & 0 deletions generated/nifpga/nifpga_compilation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,31 @@ NiFpga_Status CommitFifoConfiguration(NiFpga_Session session, uint32_t fifo)
return NiFpga_CommitFifoConfiguration(session, fifo);
}

NiFpga_Status ConfigureFifo(NiFpga_Session session, uint32_t fifo, size_t depth)
{
return NiFpga_ConfigureFifo(session, fifo, depth);
}

NiFpga_Status ConfigureFifo2(NiFpga_Session session, uint32_t fifo, size_t requestedDepth, size_t* actualDepth)
{
return NiFpga_ConfigureFifo2(session, fifo, requestedDepth, actualDepth);
}

NiFpga_Status Download(NiFpga_Session session)
{
return NiFpga_Download(session);
}

NiFpga_Status FindFifo(NiFpga_Session session, char fifoName[], uint32_t* fifoNumber)
{
return NiFpga_FindFifo(session, fifoName, fifoNumber);
}

NiFpga_Status FindRegister(NiFpga_Session session, char registerName[], uint32_t* registerOffset)
{
return NiFpga_FindRegister(session, registerName, registerOffset);
}

NiFpga_Status Open(char bitfile[], char signature[], char resource[], uint32_t attribute, NiFpga_Session* session)
{
return NiFpga_Open(bitfile, signature, resource, attribute, session);
Expand Down Expand Up @@ -357,6 +377,11 @@ NiFpga_Status WriteI32(NiFpga_Session session, uint32_t control, int32_t value)
return NiFpga_WriteI32(session, control, value);
}

NiFpga_Status WriteI64(NiFpga_Session session, uint32_t control, int64_t value)
{
return NiFpga_WriteI64(session, control, value);
}

NiFpga_Status WriteI8(NiFpga_Session session, uint32_t control, int8_t value)
{
return NiFpga_WriteI8(session, control, value);
Expand Down
45 changes: 45 additions & 0 deletions generated/nifpga/nifpga_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ NiFpgaLibrary::NiFpgaLibrary(std::shared_ptr<nidevice_grpc::SharedLibraryInterfa
function_pointers_.Abort = reinterpret_cast<AbortPtr>(shared_library_->get_function_pointer("NiFpgaDll_Abort"));
function_pointers_.Close = reinterpret_cast<ClosePtr>(shared_library_->get_function_pointer("NiFpgaDll_Close"));
function_pointers_.CommitFifoConfiguration = reinterpret_cast<CommitFifoConfigurationPtr>(shared_library_->get_function_pointer("NiFpgaDll_CommitFifoConfiguration"));
function_pointers_.ConfigureFifo = reinterpret_cast<ConfigureFifoPtr>(shared_library_->get_function_pointer("NiFpgaDll_ConfigureFifo"));
function_pointers_.ConfigureFifo2 = reinterpret_cast<ConfigureFifo2Ptr>(shared_library_->get_function_pointer("NiFpgaDll_ConfigureFifo2"));
function_pointers_.Download = reinterpret_cast<DownloadPtr>(shared_library_->get_function_pointer("NiFpgaDll_Download"));
function_pointers_.FindFifo = reinterpret_cast<FindFifoPtr>(shared_library_->get_function_pointer("NiFpgaDll_FindFifo"));
function_pointers_.FindRegister = reinterpret_cast<FindRegisterPtr>(shared_library_->get_function_pointer("NiFpgaDll_FindRegister"));
function_pointers_.Open = reinterpret_cast<OpenPtr>(shared_library_->get_function_pointer("NiFpgaDll_Open"));
function_pointers_.ReadArrayBool = reinterpret_cast<ReadArrayBoolPtr>(shared_library_->get_function_pointer("NiFpgaDll_ReadArrayBool"));
function_pointers_.ReadArrayDbl = reinterpret_cast<ReadArrayDblPtr>(shared_library_->get_function_pointer("NiFpgaDll_ReadArrayDbl"));
Expand Down Expand Up @@ -97,6 +101,7 @@ NiFpgaLibrary::NiFpgaLibrary(std::shared_ptr<nidevice_grpc::SharedLibraryInterfa
function_pointers_.WriteFifoU8 = reinterpret_cast<WriteFifoU8Ptr>(shared_library_->get_function_pointer("NiFpgaDll_WriteFifoU8"));
function_pointers_.WriteI16 = reinterpret_cast<WriteI16Ptr>(shared_library_->get_function_pointer("NiFpgaDll_WriteI16"));
function_pointers_.WriteI32 = reinterpret_cast<WriteI32Ptr>(shared_library_->get_function_pointer("NiFpgaDll_WriteI32"));
function_pointers_.WriteI64 = reinterpret_cast<WriteI64Ptr>(shared_library_->get_function_pointer("NiFpgaDll_WriteI64"));
function_pointers_.WriteI8 = reinterpret_cast<WriteI8Ptr>(shared_library_->get_function_pointer("NiFpgaDll_WriteI8"));
function_pointers_.WriteSgl = reinterpret_cast<WriteSglPtr>(shared_library_->get_function_pointer("NiFpgaDll_WriteSgl"));
function_pointers_.WriteU16 = reinterpret_cast<WriteU16Ptr>(shared_library_->get_function_pointer("NiFpgaDll_WriteU16"));
Expand Down Expand Up @@ -140,6 +145,22 @@ NiFpga_Status NiFpgaLibrary::CommitFifoConfiguration(NiFpga_Session session, uin
return function_pointers_.CommitFifoConfiguration(session, fifo);
}

NiFpga_Status NiFpgaLibrary::ConfigureFifo(NiFpga_Session session, uint32_t fifo, size_t depth)
{
if (!function_pointers_.ConfigureFifo) {
throw nidevice_grpc::LibraryLoadException("Could not find NiFpga_ConfigureFifo.");
}
return function_pointers_.ConfigureFifo(session, fifo, depth);
}

NiFpga_Status NiFpgaLibrary::ConfigureFifo2(NiFpga_Session session, uint32_t fifo, size_t requestedDepth, size_t* actualDepth)
{
if (!function_pointers_.ConfigureFifo2) {
throw nidevice_grpc::LibraryLoadException("Could not find NiFpga_ConfigureFifo2.");
}
return function_pointers_.ConfigureFifo2(session, fifo, requestedDepth, actualDepth);
}

NiFpga_Status NiFpgaLibrary::Download(NiFpga_Session session)
{
if (!function_pointers_.Download) {
Expand All @@ -148,6 +169,22 @@ NiFpga_Status NiFpgaLibrary::Download(NiFpga_Session session)
return function_pointers_.Download(session);
}

NiFpga_Status NiFpgaLibrary::FindFifo(NiFpga_Session session, char fifoName[], uint32_t* fifoNumber)
{
if (!function_pointers_.FindFifo) {
throw nidevice_grpc::LibraryLoadException("Could not find NiFpga_FindFifo.");
}
return function_pointers_.FindFifo(session, fifoName, fifoNumber);
}

NiFpga_Status NiFpgaLibrary::FindRegister(NiFpga_Session session, char registerName[], uint32_t* registerOffset)
{
if (!function_pointers_.FindRegister) {
throw nidevice_grpc::LibraryLoadException("Could not find NiFpga_FindRegister.");
}
return function_pointers_.FindRegister(session, registerName, registerOffset);
}

NiFpga_Status NiFpgaLibrary::Open(char bitfile[], char signature[], char resource[], uint32_t attribute, NiFpga_Session* session)
{
if (!function_pointers_.Open) {
Expand Down Expand Up @@ -676,6 +713,14 @@ NiFpga_Status NiFpgaLibrary::WriteI32(NiFpga_Session session, uint32_t control,
return function_pointers_.WriteI32(session, control, value);
}

NiFpga_Status NiFpgaLibrary::WriteI64(NiFpga_Session session, uint32_t control, int64_t value)
{
if (!function_pointers_.WriteI64) {
throw nidevice_grpc::LibraryLoadException("Could not find NiFpga_WriteI64.");
}
return function_pointers_.WriteI64(session, control, value);
}

NiFpga_Status NiFpgaLibrary::WriteI8(NiFpga_Session session, uint32_t control, int8_t value)
{
if (!function_pointers_.WriteI8) {
Expand Down
Loading

0 comments on commit c58c89d

Please sign in to comment.