Re: [vhdl-200x] DPI example

From: <hans@ht-lab>
Date: Fri Feb 18 2011 - 07:35:31 PST

Hi Chris,

Thanks for the VHPI example, very interesting.

Looking at your C-code, it does look overly complex, are you sure you need
all these calls and custom types?

It looks like you are doing more of foreign architecture creation rather
than a simple function/sub program call. If this is indeed the required VHPI
code then I am all for a new VHDL DPI interface :-)

Just for completeness, here is the same example in FLI:

-- Demonstration of a simple call into C using FLI
package pkg is
    procedure randint(n:out integer);
    attribute FOREIGN of randint : procedure is "randint ./my_func.so";
end;
package body pkg is
  procedure randint(n:out integer) is begin end;
end;

entity tb is
end tb;

use work.pkg.all;

architecture example of tb is
begin
  mytest : process
     variable myint : integer;
   begin
      wait for 100 ns;
      randint(myint);
      report "Got random value " & integer'image(myint) severity note;
   end process;
end;

and the C-code is very simple and requires no custom types (at least not for
ints):

/* Simple C example of a VHDL -> C function call */
#include <stdio.h>
#include <stdlib.h>
#include "mti.h"

void randint(int *m)
{
    *m=rand();
    printf("\nReturning random value %d\n",*m);
}

I don't believe you can call a VHDL procedure from C but I will investigate
this,

Regards,
Hans.
www.ht-lab.com

-----Original Message-----
From: Chris Higgs
Sent: Friday, February 18, 2011 11:38 AM
To: vhdl-200x@eda.org
Subject: [POSSIBLE VIRUS:###] Re: [vhdl-200x] DPI example

All,

I have attached a simple VHPI example demonstrating a call out from VHDL
to a C function, which returns a random integer. There is more
boilerplate code required to register the foreign function when compared
to Hans' DPI example but I don't believe it's too onerous.

I'm not sure whether it's possible to call a VHDL function from C. If it
isn't, perhaps we should look to extend VHPI to include this capability.

Thanks,

Chris

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Fri Feb 18 07:37:23 2011

This archive was generated by hypermail 2.1.8 : Fri Feb 18 2011 - 07:37:41 PST