Skip to content

Commit edc7609

Browse files
umarcor1138-4EB
authored andcommitted
fix(examples/vhdl/external_buffer): use the reference C sources
* add sigabrt.md
1 parent 9c2563d commit edc7609

2 files changed

Lines changed: 32 additions & 78 deletions

File tree

examples/vhdl/external_buffer/run.py

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,47 +25,35 @@
2525
simulation.
2626
"""
2727

28-
from vunit import VUnit
28+
from vunit import VUnit, ROOT
2929
from os import popen
3030
from os.path import join, dirname
3131

3232
src_path = join(dirname(__file__), "src")
33+
ext_srcs = join(ROOT, "vunit", "vhdl", "data_types", "src", "external", "ghdl")
3334

3435
# Compile C applications to an objects
3536
c_iobj = join(src_path, "imain.o")
3637
c_bobj = join(src_path, "bmain.o")
3738

38-
print(
39-
popen(
40-
" ".join(
41-
[
42-
"gcc",
43-
"-fPIC",
44-
"-DTYPE=int32_t",
45-
"-c",
46-
join(src_path, "main.c"),
47-
"-o",
48-
c_iobj,
49-
]
50-
)
51-
).read()
52-
)
53-
54-
print(
55-
popen(
56-
" ".join(
57-
[
58-
"gcc",
59-
"-fPIC",
60-
"-DTYPE=uint8_t",
61-
"-c",
62-
join(src_path, "main.c"),
63-
"-o",
64-
c_bobj,
65-
]
66-
)
67-
).read()
68-
)
39+
for val in [["int32_t", c_iobj], ["uint8_t", c_bobj]]:
40+
print(
41+
popen(
42+
" ".join(
43+
[
44+
"gcc",
45+
"-fPIC",
46+
"-DTYPE=" + val[0],
47+
"-I",
48+
ext_srcs,
49+
"-c",
50+
join(src_path, "main.c"),
51+
"-o",
52+
val[1],
53+
]
54+
)
55+
).read()
56+
)
6957

7058
# Enable the external feature for strings/byte_vectors and integer_vectors
7159
vu = VUnit.from_argv(vhdl_standard="2008", compile_builtins=False)
@@ -76,8 +64,16 @@
7664

7765
# Add the C object to the elaboration of GHDL
7866
for tb in lib.get_test_benches(pattern="*tb_ext*", allow_empty=False):
79-
tb.set_sim_option("ghdl.elab_flags", ["-Wl," + c_bobj], overwrite=True)
67+
tb.set_sim_option(
68+
"ghdl.elab_flags",
69+
["-Wl," + c_bobj, "-Wl,-Wl,--version-script=" + join(ext_srcs, "grt.ver")],
70+
overwrite=True,
71+
)
8072
for tb in lib.get_test_benches(pattern="*tb_ext*_integer*", allow_empty=False):
81-
tb.set_sim_option("ghdl.elab_flags", ["-Wl," + c_iobj], overwrite=True)
73+
tb.set_sim_option(
74+
"ghdl.elab_flags",
75+
["-Wl," + c_iobj, "-Wl,-Wl,--version-script=" + join(ext_srcs, "grt.ver")],
76+
overwrite=True,
77+
)
8278

8379
vu.main()

examples/vhdl/external_buffer/src/main.c

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ or tb_ext_integer_vector.vhd
2121
#include <stdio.h>
2222
#include <stdlib.h>
2323
#include <stdint.h>
24+
#include "vhpidirect_user.h"
2425

25-
extern int ghdl_main (int argc, char **argv);
26-
27-
uint8_t *D[1];
2826
const uint32_t length = 5;
2927

3028
/*
@@ -34,7 +32,7 @@ const uint32_t length = 5;
3432
[2/3, 3/3), while incrementing each value by two.
3533
*/
3634
static void exit_handler(void) {
37-
uint i, j, z, k;
35+
unsigned i, j, z, k;
3836
TYPE expected, got;
3937
k = 0;
4038
for (j=0; j<3; j++) {
@@ -80,43 +78,3 @@ int main(int argc, char **argv) {
8078
// Start the simulation
8179
return ghdl_main(argc, argv);
8280
}
83-
84-
// External string/byte_vector through access (mode = extacc)
85-
86-
void set_string_ptr(uint8_t id, uint8_t *p) {
87-
D[id] = p;
88-
}
89-
90-
uintptr_t get_string_ptr(uint8_t id) {
91-
return (uintptr_t)D[id];
92-
}
93-
94-
// External string/byte_vector through functions (mode = extfnc)
95-
96-
void write_char(uint8_t id, uint32_t i, uint8_t v ) {
97-
D[id][i] = v;
98-
}
99-
100-
uint8_t read_char(uint8_t id, uint32_t i) {
101-
return D[id][i];
102-
}
103-
104-
// External integer_vector through access (mode = extacc)
105-
106-
void set_intvec_ptr(uint8_t id, uintptr_t *p) {
107-
D[id] = (uint8_t*)p;
108-
}
109-
110-
uintptr_t get_intvec_ptr(uint8_t id) {
111-
return (uintptr_t)D[id];
112-
}
113-
114-
// External integer_vector through functions (mode = extfnc)
115-
116-
void write_integer(uint8_t id, uint32_t i, int32_t v) {
117-
((int32_t*)D[id])[i] = v;
118-
}
119-
120-
int32_t read_integer(uint8_t id, uint32_t i) {
121-
return ((int32_t*)D[id])[i];
122-
}

0 commit comments

Comments
 (0)