2

I'm thinking about writing a C function which basically passes an array/vector of real numbers to a VHDL implementation as an argument and the VHDL code does some computation using the array in a FPGA and returns the result back to the C function. So, my question - How do I go about writing a C function to call the VHDL implementation? Can anyone guide me in the right direction like a tutorial,API or anything?

Any help will be appreciated. Thanks! :)

Josh
  • 363
  • 3
  • 16
  • Probably not without a TON of work. There's nothing that can be done in software that can't be done in hardware, since eventually everything happens in the hardware anyway, but working with floating point numbers in any HDL is a huge pain. See if your FPGA vendor has some IP or libraries that can help - they may have a floating-point coprocessor that you can use. – skrrgwasme Jun 18 '15 at 22:10
  • 1
    Where is the C code running? How is that processor connected to the FPGA? – Ben Voigt Jun 18 '15 at 22:22
  • Do you mean a passing data to an actual FPGA running synthsized VHDL code or just some simulation that's running VHDL? – rost0031 Jun 18 '15 at 22:39
  • Yes, I mean passing data to an actual FPGA running synthsized VHDL code. Sry, I'm just getting started with FPGAs. Want to try something interesting. – Josh Jun 18 '15 at 23:17
  • 3
    You would need the FPGA to provide a register interface and use a driver to transfer the data to the FPGA. Or use DMA. That is definitively not a beginner's job, much less with PCIe. You seem to have a completely wrong idea how FGPA-design actually works. Note that VHDL is _not_ a programming language, but a hardware description language. Try to do some blinking LED wiith an FPGA in VHDL first. The you might get an idea. Much later, you might think about synthesizing VHDL code from a program (I would not use C for that, however - think of e.g. Python, Ruby, etc.). – too honest for this site Jun 18 '15 at 23:21
  • @Josh you could probably just clock the data in via something like SPI. You could get away without having a register interface by having two pins, a busy pin (so the computer knows when the computation has finished) and a start pin (that the computer can use to tell the FPGA to begin processing). Some beginner FPGA dev boards also have a USB to serial converter built in that you could also use to transfer data across with no extra hardware required. On the whole though, I agree with Olaf. Try something a bit simpler before you dive in to interfacing with a computer. – tangrs Jun 19 '15 at 05:59

1 Answers1

4

VHDL does not result in a run time routine, it turns into an actual implementation in HW. To be able to communicate with a VHDL routine to/from a high level lalnguage in a CPU, the CPU and the VHDL module must be connected and the VHDL code must have proper mean to provide data from the CPU.

In your case, there are 2 ways, one is that the VHDL is implemented in a way that the shared data can be accessed by both the CPU and the FPGA logic, in that case, you need to know what that address is. The other way is if the VHDL is providing data via serial port, or USB or ethernet to the CPU, but in both cases, this must be supported by the VHDL routine.

In any case, you need to know a lot more about the FPGA than just making a procedure call.

This article might help you a bit to understand who things works (might not be the right FPGA either, but probably helps anyway).

How to interface FPGAs to microcontrollers

FarhadA
  • 853
  • 2
  • 8
  • 19