OpenCores
URL https://opencores.org/ocsvn/qaz_libs/qaz_libs/trunk

Subversion Repositories qaz_libs

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /qaz_libs/trunk/BFM/sim
    from Rev 43 to Rev 44
    Reverse comparison

Rev 43 → Rev 44

/tests/tb_video_frame_dpi/count.raw Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream
tests/tb_video_frame_dpi/count.raw Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: tests/tb_video_frame_dpi/init_test.do =================================================================== --- tests/tb_video_frame_dpi/init_test.do (revision 43) +++ tests/tb_video_frame_dpi/init_test.do (revision 44) @@ -9,7 +9,8 @@ set env(SIM_TARGET) fpga radix -hexadecimal -quietly set env(PATH) "D:/Anaconda2;$::env(PATH)" +# quietly set env(PATH) "D:/Anaconda2;$::env(PATH)" +quietly set env(PATH) "D:/anaconda3;$::env(PATH)" make_lib work 1
/tests/tb_video_frame_dpi/py_dpi.c
37,7 → 37,7
void c_do_it()
{
printf("^^^ | c_do_it()\n");
 
/* result = instance.method(x,y) */
PyObject *pmeth = PyObject_GetAttrString(g_dva_i, "do_it");
// Py_DECREF(pinst);
56,15 → 56,15
{
int va_y = svSize(va, 1);
int va_x = svSize(va, 2);
 
printf("^^^ | c_get_array() | %dx%d\n", va_x, va_y);
g_va = (unsigned int *)svGetArrElemPtr2(va, 0, 0);
 
PyObject *pmeth = PyObject_GetAttrString(g_dva_i, "py_get_array");
// pargs = Py_BuildValue("(ss)", arg1, arg2); /* convert to Python */
// PyObject *pres = PyEval_CallObject(pmeth, pargs); /* call method(x,y) */
PyObject *pres = PyEval_CallObject(pmeth, NULL);
 
Py_DECREF(pmeth);
// Py_DECREF(pargs);
Py_DECREF(pres);
71,6 → 71,8
}
 
// --------------------------------------------------------------------
#define MAX_ARGV 4
 
int py_run_file
( const char *filename
, int argc
79,29 → 81,40
{
printf("^^^ | py_run_file | %s |\n", filename);
 
char *argv[4]; // limit of 4 args
wchar_t *w_argv[MAX_ARGV]; // limit of MAX_ARGV args
int i;
for(i = 0; i < argc && i < 4; i++)
{
argv[i] = *(char **)svGetArrElemPtr1(args, i);
printf( "^^^ | py_run_file | args[%d] = %s\n"
, i
, argv[i]
);
}
for(i = 0; i < argc && i < MAX_ARGV; i++)
w_argv[i] = Py_DecodeLocale(*((char **)svGetArrElemPtr1(args, i)), NULL);
 
PySys_SetArgv(argc, argv);
PyObject *PyFileObject = PyFile_FromString((char *)filename, "r");
return PyRun_SimpleFileEx(PyFile_AsFile(PyFileObject), filename, 1);
PySys_SetArgv(argc, w_argv);
 
char pre_string[] = "exec(open('./";
char post_string[] = "').read())";
char v_filename[] = "try_it.py";
unsigned int size = (sizeof(pre_string) + sizeof(post_string)) * sizeof(char);
size += strlen(filename);
char *run_string = (char *)malloc(size);
sprintf(run_string, "%s%s%s", pre_string, filename, post_string);
 
PyRun_SimpleString(run_string);
free(run_string);
return 0;
}
 
// --------------------------------------------------------------------
extern PyMODINIT_FUNC PyInit_py_to_video_frame(void);
 
void init_py_dpi(int width, int height)
{
printf("^^^ | init_py_dpi() | %dx%d\n", width, height);
 
PyImport_AppendInittab("py_to_video_frame", PyInit_py_to_video_frame);
Py_Initialize();
init_py_to_video_frame();
 
PyObject *sys = PyImport_ImportModule("sys");
PyObject *path = PyObject_GetAttrString(sys, "path");
PyList_Append(path, PyUnicode_FromString("."));
 
PyObject *dva_m = PyImport_ImportModule("dpi_video_array");
if(!dva_m)
{
108,7 → 121,7
PyErr_Print();
printf("^^^ | init_py_dpi() | dva_m Error\n");
}
 
PyObject *dva_c = PyObject_GetAttrString(dva_m, "dpi_video_array");
Py_DECREF(dva_m);
if(!dva_c)
116,7 → 129,7
PyErr_Print();
printf("^^^ | init_py_dpi() | dva_c Error\n");
}
 
PyObject *args = Py_BuildValue("(ii)", width, height);
g_dva_i = PyObject_CallObject(dva_c, args);
Py_DECREF(args);
134,9 → 147,9
void exit_py_dpi()
{
printf("^^^ | exit_py_dpi()\n");
 
if(g_dva_i)
Py_DECREF(g_dva_i);
 
Py_Finalize();
}
/tests/tb_video_frame_dpi/py_dpi.h
53,10 → 53,6
int height);
 
DPI_LINK_DECL DPI_DLLESPEC
void
init_py_to_video_frame();
 
DPI_LINK_DECL DPI_DLLESPEC
int
py_run_file(
const char* filename,
/tests/tb_video_frame_dpi/py_raw_to_frame.py
0,0 → 1,92
#
# ////////////////////////////////////////////////////////////////////
# // ////
# // Copyright (C) 2018 Authors and OPENCORES.ORG ////
# // ////
# // This source file may be used and distributed without ////
# // restriction provided that this copyright statement is not ////
# // removed from the file and that any derivative work contains ////
# // the original copyright notice and the associated disclaimer. ////
# // ////
# // This source file is free software; you can redistribute it ////
# // and/or modify it under the terms of the GNU Lesser General ////
# // Public License as published by the Free Software Foundation; ////
# // either version 2.1 of the License, or (at your option) any ////
# // later version. ////
# // ////
# // This source is distributed in the hope that it will be ////
# // useful, but WITHOUT ANY WARRANTY; without even the implied ////
# // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
# // PURPOSE. See the GNU Lesser General Public License for more ////
# // details. ////
# // ////
# // You should have received a copy of the GNU Lesser General ////
# // Public License along with this source; if not, download it ////
# // from http://www.opencores.org/lgpl.shtml ////
# // ////
# ////////////////////////////////////////////////////////////////////
import sys
# import sv_video
import numpy as np
# import matplotlib.pyplot as plt
 
print("^^^ | py_raw_to_frame |")
print('Number of arguments:', len(sys.argv), 'arguments.')
print('Argument List:', str(sys.argv))
 
# dataSend = np.arange(1, 9 + 1, dtype=np.uint32)
 
# tiny_frame = np.arange(32, 32 + 32, dtype=np.uint32)
# data_list = tiny_frame.flatten()
# data_list = tiny_frame.tolist()
 
# sv_video.py_list_to_c_array(data_list)
 
# ---------------------------------------------------------
v_frames = 1
v_width = 8
v_height = 16
 
# # fname = sys.argv[0]
# fname = 'count.raw'
# print("file name: ", fname)
 
# with open(fname, 'r') as infile:
# data = np.fromfile(infile, dtype='uint16').reshape(v_frames, v_height, v_width)
 
# np.set_printoptions(formatter={'int':hex})
 
# for i in range(v_frames):
# print(data[i])
# fig, ax = plt.subplots()
# im = ax.imshow(data[i], cmap='gray')
# ax.set(xticks=[], yticks=[])
# fig.colorbar(im)
# plt.show()
 
# from __future__ import print_function
# with open('out.txt', 'w') as f:
# print('qqq\n', file=f)
# print(data[0], file=f)
# f = open('out.txt','w')
# print >>f,'some Text'
# print >>f, data[0].flatten()
# for i in range(v_frames*v_height*v_width):
# print >>f, data[0].flatten()[i]
 
# data = np.arange(v_frames*v_width*v_height, dtype='uint16')
# data = data.reshape(v_frames, v_height, v_width)
 
# f = open('count.raw','r')
data = np.fromfile('count.raw', dtype='uint16')
 
print(data)
print(data.shape)
# with open('init_test.do') as fp:
# for line in fp:
# print line
/tests/tb_video_frame_dpi/py_video.py
1,5 → 1,30
#
 
# ////////////////////////////////////////////////////////////////////
# // ////
# // Copyright (C) 2018 Authors and OPENCORES.ORG ////
# // ////
# // This source file may be used and distributed without ////
# // restriction provided that this copyright statement is not ////
# // removed from the file and that any derivative work contains ////
# // the original copyright notice and the associated disclaimer. ////
# // ////
# // This source file is free software; you can redistribute it ////
# // and/or modify it under the terms of the GNU Lesser General ////
# // Public License as published by the Free Software Foundation; ////
# // either version 2.1 of the License, or (at your option) any ////
# // later version. ////
# // ////
# // This source is distributed in the hope that it will be ////
# // useful, but WITHOUT ANY WARRANTY; without even the implied ////
# // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
# // PURPOSE. See the GNU Lesser General Public License for more ////
# // details. ////
# // ////
# // You should have received a copy of the GNU Lesser General ////
# // Public License along with this source; if not, download it ////
# // from http://www.opencores.org/lgpl.shtml ////
# // ////
# ////////////////////////////////////////////////////////////////////
import numpy as np
import matplotlib.pyplot as plt
 
/tests/tb_video_frame_dpi/sim.f
1,11 → 1,5
#
#
 
# -voptargs="-f ./acc_file.f"
 
# -suppress 12110
# -novopt
 
-ldflags "D:/Anaconda2/python27.dll"
# -ldflags "D:/Anaconda2/Lib/site-packages/numpy/core/lib/npymath.lib"
 
# -ldflags "D:/Anaconda2/python27.dll"
-ldflags "D:/anaconda3/python36.dll"
/tests/tb_video_frame_dpi/sv_video_frame_dpi.svh
35,7 → 35,7
int return_status;
return_status = py_run_file(filename, py_args.size(), py_args);
endfunction : py_file
 
// --------------------------------------------------------------------
task do_it();
$display("^^^ %16.t | %m |", $time);
51,11 → 51,6
endtask
 
// --------------------------------------------------------------------
function new;
$display("^^^ | video_frame_dpi | new");
endfunction
 
// --------------------------------------------------------------------
function void init(int width, int height, buffer_in_size=2, buffer_out_size=2);
video_array_t a_h;
$display("^^^ | video_frame_dpi | init");
62,14 → 57,14
this.array_buffer = new(buffer_in_size);
this.buffer_in = new(buffer_in_size);
this.buffer_out = new(buffer_out_size);
 
for(int i = 0; i < buffer_in_size; i++)
begin
a_h = new[height];
 
foreach(a_h[y])
a_h[y] = new[width];
 
if(array_buffer.try_put(a_h) == 0)
begin
$display("^^^ | video_frame_dpi | init ERROR!");
76,7 → 71,7
$stop;
end
end
 
init_py_dpi(width, height);
endfunction
 
86,6 → 81,11
exit_py_dpi();
endfunction
 
// --------------------------------------------------------------------
function new;
$display("^^^ | video_frame_dpi | new");
endfunction
 
// --------------------------------------------------------------------
endclass : video_frame_dpi
 
/tests/tb_video_frame_dpi/tb_files.f
1,10 → 1,10
#
 
# ${PROJECT_DIR}/sim/src//.sv
# -ccflags "-Bsymbolic -ID:/Anaconda2/include -D MS_WIN64"
# -ccflags "-ID:/Anaconda2/Lib/site-packages/numpy/core/include"
-ccflags "-Bsymbolic -ID:/anaconda3/include -D MS_WIN64"
-ccflags "-ID:/anaconda3/Lib/site-packages/numpy/core/include"
 
-ccflags "-Bsymbolic -ID:/Anaconda2/include -D MS_WIN64"
-ccflags "-ID:/Anaconda2/Lib/site-packages/numpy/core/include"
 
-ccflags "-std=c99"
-dpiheader py_dpi.h
 
/tests/tb_video_frame_dpi/try_it.py
24,10 → 24,10
# // from http://www.opencores.org/lgpl.shtml ////
# ////////////////////////////////////////////////////////////////////
import sys
# import py_to_video_frame as vf
import py_to_video_frame as vf
import numpy as np
 
print("^^^ | running python!")
print("~~~ | running python!")
print('Number of arguments:', len(sys.argv), 'arguments.')
print('Argument List:', str(sys.argv))
 
/tests/tb_video_frame_dpi/video_frame_dpi.sv
40,7 → 40,6
import "DPI-C" context function void c_do_it();
import "DPI-C" context function void c_get_array(inout video_array_t va);
import "DPI-C" context function int py_run_file(string filename, int argc, string args[]);
import "DPI-C" context function void init_py_to_video_frame();
export "DPI-C" task sv_write;
 
// --------------------------------------------------------------------
62,7 → 61,8
vf_h.init(WIDTH, HEIGHT);
 
vf_h.get_frame(va);
// vf_h.do_it();
vf_h.do_it();
vf_h.py_file("try_it.py", '{"Larry", "Curly", "Moe"});
 
vf_h.exit();
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.