Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

cinterface/accarraygen example (Bounded by Generic Package - VHDL 2008) #5

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move to accarrayint
RocketRoss committed Apr 13, 2020
commit ec5affbcdc0e6187e4742c5c1515a113c8317e5b
88 changes: 44 additions & 44 deletions ...direct/cinterface/accarrayvar/cAccess.vhd → ...direct/cinterface/accarrayint/cAccess.vhd
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
library ieee;
use ieee.std_logic_1164.all;

package cAccess is

type int_ptr is access integer; -- represented C-side with int
function c_intArrSize return integer; -- represented C-side with int*
attribute foreign of c_intArrSize :
function is "VHPIDIRECT getIntArrSize"; -- getIntArrSize is the C-side function name

shared variable c_sizeInt : integer := c_intArrSize;

type int_arr is array(0 to c_sizeInt-1) of integer;
type int_arr_ptr is access int_arr; -- represented C-side with int*


function c_intArr_ptr return int_arr_ptr;
attribute foreign of c_intArr_ptr :
function is "VHPIDIRECT getIntArr_ptr";

procedure c_freeIntArray;
attribute foreign of c_freeIntArray :
procedure is "VHPIDIRECT freeIntArray";

shared variable c_intArr : int_arr_ptr := c_intArr_ptr;
end package cAccess;

package body cAccess is

function c_intArrSize return integer is
begin
assert false report "c_intArrSize VHPI" severity failure;
end c_intArrSize;

function c_intArr_ptr return int_arr_ptr is
begin
assert false report "c_intArr_ptr VHPI" severity failure;
end c_intArr_ptr;

procedure c_freeIntArray is
begin
assert false report "c_freeIntArray VHPI" severity failure;
end c_freeIntArray;
end package body cAccess;
library ieee;
use ieee.std_logic_1164.all;

package cAccess is

type int_ptr is access integer; -- represented C-side with int
function c_intArrSize return integer; -- represented C-side with int*
attribute foreign of c_intArrSize :
function is "VHPIDIRECT getIntArrSize"; -- getIntArrSize is the C-side function name

shared variable c_sizeInt : integer := c_intArrSize;

type int_arr is array(0 to c_sizeInt-1) of integer;
type int_arr_ptr is access int_arr; -- represented C-side with int*


function c_intArr_ptr return int_arr_ptr;
attribute foreign of c_intArr_ptr :
function is "VHPIDIRECT getIntArr_ptr";

procedure c_freeIntArray;
attribute foreign of c_freeIntArray :
procedure is "VHPIDIRECT freeIntArray";

shared variable c_intArr : int_arr_ptr := c_intArr_ptr;
end package cAccess;

package body cAccess is

function c_intArrSize return integer is
begin
assert false report "c_intArrSize VHPI" severity failure;
end c_intArrSize;

function c_intArr_ptr return int_arr_ptr is
begin
assert false report "c_intArr_ptr VHPI" severity failure;
end c_intArr_ptr;

procedure c_freeIntArray is
begin
assert false report "c_freeIntArray VHPI" severity failure;
end c_freeIntArray;
end package body cAccess;
44 changes: 22 additions & 22 deletions ...irect/cinterface/accarrayvar/cSharedVar.c → ...irect/cinterface/accarrayint/cSharedVar.c
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#include "cSharedVar.h"

int getIntArrSize(){//function acts like a constructor so initialise the variable
sizeInt = 5;
return sizeInt;
}

int* getIntArr_ptr(){//function acts like a constructor so initialise the variable
intArray = malloc(sizeInt*sizeof(int));
for (int i = 0; i < sizeInt; i++)
{
intArray[i] = 11*(i+1);
}
return intArray;
}

void freeIntArray(){
for (int i = 0; i < sizeInt; i++)
{
printf("intArray[%d] = %d\n", i, intArray[i]);
}
free(intArray);
#include "cSharedVar.h"

int getIntArrSize(){//function acts like a constructor so initialise the variable
sizeInt = 5;
return sizeInt;
}

int* getIntArr_ptr(){//function acts like a constructor so initialise the variable
intArray = malloc(sizeInt*sizeof(int));
for (int i = 0; i < sizeInt; i++)
{
intArray[i] = 11*(i+1);
}
return intArray;
}

void freeIntArray(){
for (int i = 0; i < sizeInt; i++)
{
printf("intArray[%d] = %d\n", i, intArray[i]);
}
free(intArray);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <stdio.h>
#include <malloc.h>

int sizeInt;
int getIntArrSize();

int* intArray;
int* getIntArray_ptr();
#include <stdio.h>
#include <malloc.h>

int sizeInt;
int getIntArrSize();

int* intArray;
int* getIntArray_ptr();
void freeIntArray();
File renamed without changes.
54 changes: 27 additions & 27 deletions vhpidirect/cinterface/accarrayvar/tb.vhd → vhpidirect/cinterface/accarrayint/tb.vhd
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

use work.cAccess.all;

entity tb is
end entity tb;

architecture RTL of tb is

begin

process
begin
report "Array length: " & integer'image(c_intArr.all'length);

for i in 0 to c_intArr.all'right loop
report "c_intArr[" & integer'image(i) &"] = " & integer'image(c_intArr.all(i)) & ". Set to: " & integer'image(-2*c_intArr.all(i));
c_intArr.all(i) := -2*c_intArr.all(i);
end loop;

c_freeIntArray;
wait;
end process;

end architecture RTL;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

use work.cAccess.all;

entity tb is
end entity tb;

architecture RTL of tb is

begin

process
begin
report "Array length: " & integer'image(c_intArr.all'length);

for i in 0 to c_intArr.all'right loop
report "c_intArr[" & integer'image(i) &"] = " & integer'image(c_intArr.all(i)) & ". Set to: " & integer'image(-2*c_intArr.all(i));
c_intArr.all(i) := -2*c_intArr.all(i);
end loop;

c_freeIntArray;
wait;
end process;

end architecture RTL;