-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2014-2019, Lars Asplund [email protected] | ||
|
||
from os import popen | ||
from os.path import join, dirname | ||
from vunit import VUnit | ||
|
||
std = "2008" | ||
#std = "93" | ||
|
||
ui = VUnit.from_argv(vhdl_standard=std) | ||
|
||
src_path = join(dirname(__file__), "src") | ||
|
||
lib = ui.add_library("lib") | ||
lib.add_source_files(join(src_path, "test", "*.vhd")) | ||
|
||
c_obj = join(src_path, '..', 'vunit_out', 'main.o') | ||
print(popen('gcc -fPIC -rdynamic -c '+join(src_path, '**', 'main.c')+' -o '+c_obj).read()) | ||
|
||
ui.set_objects([c_obj]) | ||
|
||
ui.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
|
||
extern int ghdl_main (int argc, char **argv); | ||
|
||
uint8_t *D[1]; | ||
|
||
uintptr_t get_addr(uint8_t id) { | ||
//printf("C get_addr(%d): %p\n", id, D[id]); | ||
return (uintptr_t)D[id]; | ||
} | ||
|
||
void write_byte(uint8_t id, uint32_t i, uint8_t v ) { | ||
//printf("C write_byte(%d, %d): %d\n", id, i, v); | ||
D[id][i] = v; | ||
} | ||
|
||
uint8_t read_byte(uint8_t id, uint32_t i) { | ||
//printf("C read_byte(%d, %d): %d\n", id, i, D[id][i]); | ||
return D[id][i]; | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
|
||
const uint32_t length = 5; | ||
|
||
D[0] = (uint8_t *) malloc(3*length*sizeof(uint8_t)); | ||
if ( D[0] == NULL ) { | ||
perror("execution of malloc() failed!\n"); | ||
return -1; | ||
} | ||
|
||
int i; | ||
for(i=0; i<length; i++) { | ||
D[0][i] = (i+1)*11; | ||
} | ||
|
||
for(i=0; i<3*length; i++) { | ||
printf("%d: %d\n", i, D[0][i]); | ||
} | ||
|
||
ghdl_main(argc, argv); | ||
|
||
for(i=0; i<3*length; i++) { | ||
printf("%d: %d\n", i, D[0][i]); | ||
} | ||
|
||
free(D[0]); | ||
|
||
return 0; | ||
} |
52 changes: 52 additions & 0 deletions
52
examples/vhdl/external_buffer/src/test/tb_external_buffer.vhd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
-- This Source Code Form is subject to the terms of the Mozilla Public | ||
-- License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
-- You can obtain one at http://mozilla.org/MPL/2.0/. | ||
-- | ||
-- Copyright (c) 2014-2019, Lars Asplund [email protected] | ||
|
||
--library vunit_lib; | ||
--context vunit_lib.vunit_context; | ||
|
||
library vunit_lib; | ||
use vunit_lib.run_pkg.all; | ||
use vunit_lib.logger_pkg.all; | ||
use vunit_lib.byte_vector_ptr_pkg.all; | ||
|
||
entity tb_external_buffer is | ||
generic ( | ||
runner_cfg : string | ||
); | ||
end entity; | ||
|
||
architecture tb of tb_external_buffer is | ||
|
||
constant block_len : natural := 5; | ||
|
||
constant ebuf: byte_vector_ptr_t:= new_byte_vector_ptr( 1024, 0, -1); -- external through VHPIDIRECT functions 'read_byte' and 'write_byte' | ||
constant abuf: byte_vector_ptr_t:= new_byte_vector_ptr( 1024, 0, 1); -- external through access (required VHPIDIRECT function 'get_addr') | ||
|
||
begin | ||
|
||
main: process | ||
variable val: integer; | ||
begin | ||
test_runner_setup(runner, runner_cfg); | ||
while test_suite loop | ||
if run("test") then | ||
info("Init test"); | ||
for x in 0 to block_len-1 loop | ||
val := get(ebuf, x); --report "E get(" & to_string(x) & "): " & to_string(val) severity note; | ||
set(ebuf, block_len+x, val); --report "E set(" & to_string(5+x) & "): " & to_string(val) severity note; | ||
end loop; | ||
for x in block_len to 2*block_len-1 loop | ||
val := get(abuf, x); --report "A get(" & to_string(x) & "): " & to_string(val) severity note; | ||
set(abuf, block_len+x, val); --report "A set(" & to_string(5+x) & "): " & to_string(val) severity note; | ||
end loop; | ||
info("End test"); | ||
end if; | ||
end loop; | ||
test_runner_cleanup(runner); | ||
wait; | ||
end process; | ||
|
||
end architecture; |