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 3, 2019
1 parent 48d1d96 commit de9113e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 46 deletions.
8 changes: 6 additions & 2 deletions examples/vhdl/external_buffer/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
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 @@ -38,13 +40,15 @@
print(popen(' '.join([
'gcc', '-fPIC',
'-DTYPE=int32_t',
'-I', ext_srcs,
'-c', join(src_path, 'main.c'),
'-o', c_iobj
])).read())

print(popen(' '.join([
'gcc', '-fPIC',
'-DTYPE=uint8_t',
'-I', ext_srcs,
'-c', join(src_path, 'main.c'),
'-o', c_bobj
])).read())
Expand All @@ -58,8 +62,8 @@

# 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()
26 changes: 26 additions & 0 deletions examples/vhdl/external_buffer/sigabrt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
When VHDL 1993 is used, the simulation is terminated with an `abort`, which prevents the user from running post-checks.
These are some snippets to test it. See https://github.com/VUnit/vunit/pull/469#issuecomment-485723516.

``` python
https://bugs.python.org/issue12423
def handler(signum, frame):
print('Signal handler called with signal', signum)
import signal
signal.signal(signal.SIGABRT, handler)
import os
os.abort()
```

``` c
#include <signal.h>

void sigabrtHandler(int sig_num)
{
// Reset handler to catch SIGINT next time. Refer http://en.cppreference.com/w/c/program/signal
signal(SIGABRT, sigabrtHandler);
printf("\nSIGABRT caught!\n");
fflush(stdout);
}

signal(SIGABRT, sigabrtHandler);
```
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;