Skip to content

Commit

Permalink
fix(examples/vhdl/external_buffer): use the reference C sources
Browse files Browse the repository at this point in the history
* add sigabrt.md
  • Loading branch information
umarcor committed Oct 13, 2019
1 parent f23b2ae commit bec5fe9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 46 deletions.
20 changes: 18 additions & 2 deletions examples/vhdl/external_buffer/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@
from vunit import VUnit
from os import popen
from os.path import join, dirname
import inspect

src_path = join(dirname(__file__), "src")
ext_srcs = join(
dirname(inspect.getfile(VUnit)), "vhdl", "data_types", "src", "external"
)

# Compile C applications to an objects
c_iobj = join(src_path, "imain.o")
Expand All @@ -42,6 +46,8 @@
"gcc",
"-fPIC",
"-DTYPE=int32_t",
"-I",
ext_srcs,
"-c",
join(src_path, "main.c"),
"-o",
Expand All @@ -58,6 +64,8 @@
"gcc",
"-fPIC",
"-DTYPE=uint8_t",
"-I",
ext_srcs,
"-c",
join(src_path, "main.c"),
"-o",
Expand All @@ -76,8 +84,16 @@

# Add the C object to the elaboration of GHDL
for tb in lib.get_test_benches(pattern="*tb_ext*", allow_empty=False):
tb.set_sim_option("ghdl.elab_flags", ["-Wl," + c_bobj], overwrite=True)
tb.set_sim_option(
"ghdl.elab_flags",
["-Wl," + c_bobj, "-Wl,-Wl,--version-script=" + join(ext_srcs, "grt.ver")],
overwrite=True,
)
for tb in lib.get_test_benches(pattern="*tb_ext*_integer*", allow_empty=False):
tb.set_sim_option("ghdl.elab_flags", ["-Wl," + c_iobj], overwrite=True)
tb.set_sim_option(
"ghdl.elab_flags",
["-Wl," + c_iobj, "-Wl,-Wl,--version-script=" + join(ext_srcs, "grt.ver")],
overwrite=True,
)

vu.main()
46 changes: 2 additions & 44 deletions examples/vhdl/external_buffer/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ or tb_ext_integer_vector.vhd
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "vhpidirect_user.h"

extern int ghdl_main (int argc, char **argv);

uint8_t *D[1];
const uint32_t length = 5;

/*
Expand All @@ -34,7 +32,7 @@ const uint32_t length = 5;
[2/3, 3/3), while incrementing each value by two.
*/
static void exit_handler(void) {
uint i, j, z, k;
unsigned i, j, z, k;
TYPE expected, got;
k = 0;
for (j=0; j<3; j++) {
Expand Down Expand Up @@ -80,43 +78,3 @@ int main(int argc, char **argv) {
// Start the simulation
return ghdl_main(argc, argv);
}

// External string/byte_vector through access (mode = extacc)

void set_string_ptr(uint8_t id, uint8_t *p) {
D[id] = p;
}

uintptr_t get_string_ptr(uint8_t id) {
return (uintptr_t)D[id];
}

// External string/byte_vector through functions (mode = extfnc)

void write_char(uint8_t id, uint32_t i, uint8_t v ) {
D[id][i] = v;
}

uint8_t read_char(uint8_t id, uint32_t i) {
return D[id][i];
}

// External integer_vector through access (mode = extacc)

void set_intvec_ptr(uint8_t id, uintptr_t *p) {
D[id] = (uint8_t*)p;
}

uintptr_t get_intvec_ptr(uint8_t id) {
return (uintptr_t)D[id];
}

// External integer_vector through functions (mode = extfnc)

void write_integer(uint8_t id, uint32_t i, int32_t v) {
((int32_t*)D[id])[i] = v;
}

int32_t read_integer(uint8_t id, uint32_t i) {
return ((int32_t*)D[id])[i];
}

0 comments on commit bec5fe9

Please sign in to comment.