LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I access FPGA register addresses from C#

Solved!
Go to solution

When creating a FPGA bit file, LabView also creates a .h file that contains information for communicating to the FPGA application (such as the signature, and the register addresses).

The challenge is that my application is written in C# and I need access to those register addresses.

 

The only options I can think of are:
1) Cut-and-paste the contents of the .h file into a .cs file ~~~~ ... gives me the shivers,  C# is one developer and FPGA is another.

2) Parse the .h file  ~~~~ ... gives me the shivers too - writing my own language parser 😞

 

There has got to be a better way

0 Kudos
Message 1 of 6
(4,460 Views)

Well, I'm not sure that the NI forums are going to be much help here... the process that you're going to need to follow (in C#) is called marshaling. Looking through what google results I could find quickly, this seems to be the best description of what it is, and why it's needed:

http://www.codeproject.com/Articles/66245/Marshaling-with-C-Chapter-1-Introducing-Marshaling

 

and here's an example to get you started:

http://msdn.microsoft.com/en-us/library/aa288468(v=vs.71).aspx

 

I'm not sure I know of anyone who's done this before with the LabVIEW C API, but it should be possible using the above "call c from c#" methods.

Cheers!

TJ G
0 Kudos
Message 2 of 6
(4,453 Views)

We have actually already done the marshalling part (actually I think it was our brother group in Germany that did it for this part).

Our test applications are 100% C# and access all the instruments (NI and other) through .NET classes.

We just use LabView for creating the FPGA bit files.

 

The challenge for me was getting the values from the .h file that was auto-generated.

0 Kudos
Message 3 of 6
(4,407 Views)
Solution
Accepted by topic author markshancock

I solved the problem by creating a C++/CLI project that includes the .h file and creates a .NET class that exposes the information in the .h via static methods.

Message 4 of 6
(4,405 Views)

Could you please share your solution files?

0 Kudos
Message 5 of 6
(3,798 Views)

Unfortunately our application is proprietary and so I cannot share the solution files and the FPGA portion is too embedded into some of the proprietary portions that it is not easily extracted.

 

The basics of what we do is to create an Abstract class 'AFpga' written in C#.  It has access to the driver that talks to the FPGA.  This contains several abstract methods that provide access to:

  • The filename of the bitfile
  • The signature of the bitfile
  • An address lookup method 'int Address(string regName)'
  • A 'Register<T>' class that can be used to hold all the register information
  • We also have some support functions for voltage conversion and FIFO access

Then for every FPGA application (bitfile) we create a derived class in CPP/CLI that implements  'AFpga', provides the register maps, and references the application's .h file to get the information it needs.  On extra challenge we had is that CPP/CLI can't do AnyCPU so we had to provide 64-bit and 32-bit classes that can be chosen at runtime.

 

Hope this helps

0 Kudos
Message 6 of 6
(3,787 Views)