Adnan Khalid
Adnan Khalid

Reputation: 19

how to convert c function to verilog module?

below is the code in C that is used to fuzzify an input. I have been trying to convert it to verilog syntax but i am having a lot of problem regarding the data types and such. The errors keep on piling.

float fuzzify_MF(float x,a,b,c,d) //x=crisp input 
{ 
float dom; 
if ( x >a && x <b) 
{ dom=(x-a)/(b – a); } 
else if (x>c && x<d) 
{ dom=(d-x)/(d-c); } 
else if (x>=b && x<=c) 
{dom=1.0; } 
else 
{ dom=0; } 
return dom; 
} 

Upvotes: 1

Views: 6517

Answers (3)

Karan Shah
Karan Shah

Reputation: 1992

You can import a "C" function in the Verilog, by using PLIs.

Include following header file with the C function:

#include <svdip.h>

Now in the Verilog module:

module top;
  import "DPI-C" context function shortreal fuzzify_MF(shortreal x, shortreal a, shortreal b, shortreal c, shortreal d);
  shortreal t;

  initial
  begin
    t = fuzzify_MF(<Arguments>);
  end    
endmodule

You can read more on this topic in the link : DPI Tutorial

Upvotes: 0

sm535
sm535

Reputation: 587

You can use PLI to solve this, but if you want to look cool and still solve it, use DPI of SystemVerilog.

http://www.project-veripage.com/dpi_tutorial_1.php

Upvotes: 0

nav_jan
nav_jan

Reputation: 2553

why dont you try using PLI. Try this link : PLI tutorial

Upvotes: 1

Related Questions