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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [BFM/] [sim/] [tests/] [tb_video_frame_dpi/] [py_dpi.c] - Blame information for rev 43

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 43 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2018 Authors and OPENCORES.ORG                 ////
4
////                                                              ////
5
//// This source file may be used and distributed without         ////
6
//// restriction provided that this copyright statement is not    ////
7
//// removed from the file and that any derivative work contains  ////
8
//// the original copyright notice and the associated disclaimer. ////
9
////                                                              ////
10
//// This source file is free software; you can redistribute it   ////
11
//// and/or modify it under the terms of the GNU Lesser General   ////
12
//// Public License as published by the Free Software Foundation; ////
13
//// either version 2.1 of the License, or (at your option) any   ////
14
//// later version.                                               ////
15
////                                                              ////
16
//// This source is distributed in the hope that it will be       ////
17
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
18
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
19
//// PURPOSE.  See the GNU Lesser General Public License for more ////
20
//// details.                                                     ////
21
////                                                              ////
22
//// You should have received a copy of the GNU Lesser General    ////
23
//// Public License along with this source; if not, download it   ////
24
//// from http://www.opencores.org/lgpl.shtml                     ////
25
////                                                              ////
26
//////////////////////////////////////////////////////////////////////
27
#include <stdio.h>
28
#include <conio.h>
29
#include <Python.h>
30
#include "vpi_user.h"
31
#include "py_dpi.h"
32
 
33
// --------------------------------------------------------------------
34
PyObject *g_dva_i;
35
 
36
// --------------------------------------------------------------------
37
void c_do_it()
38
{
39
  printf("^^^ | c_do_it()\n");
40
 
41
  /* result = instance.method(x,y) */
42
  PyObject *pmeth  = PyObject_GetAttrString(g_dva_i, "do_it");
43
  // Py_DECREF(pinst);
44
  // pargs  = Py_BuildValue("(ss)", arg1, arg2); /* convert to Python */
45
  // PyObject *pres = PyEval_CallObject(pmeth, pargs); /* call method(x,y) */
46
  PyObject *pres = PyEval_CallObject(pmeth, NULL);
47
  Py_DECREF(pmeth);
48
  // Py_DECREF(pargs);
49
  Py_DECREF(pres);
50
}
51
 
52
// --------------------------------------------------------------------
53
unsigned int *g_va = NULL;
54
 
55
void c_get_array(const svOpenArrayHandle va)
56
{
57
  int va_y = svSize(va, 1);
58
  int va_x = svSize(va, 2);
59
 
60
  printf("^^^ | c_get_array() | %dx%d\n", va_x, va_y);
61
 
62
  g_va = (unsigned int *)svGetArrElemPtr2(va, 0, 0);
63
 
64
  PyObject *pmeth = PyObject_GetAttrString(g_dva_i, "py_get_array");
65
  // pargs  = Py_BuildValue("(ss)", arg1, arg2); /* convert to Python */
66
  // PyObject *pres = PyEval_CallObject(pmeth, pargs); /* call method(x,y) */
67
  PyObject *pres = PyEval_CallObject(pmeth, NULL);
68
  Py_DECREF(pmeth);
69
  // Py_DECREF(pargs);
70
  Py_DECREF(pres);
71
}
72
 
73
// --------------------------------------------------------------------
74
int py_run_file
75
( const char *filename
76
, int argc
77
, const svOpenArrayHandle args
78
)
79
{
80
  printf("^^^ | py_run_file | %s |\n", filename);
81
 
82
  char *argv[4];  // limit of 4 args
83
  int i;
84
  for(i = 0; i < argc && i < 4; i++)
85
  {
86
    argv[i] = *(char **)svGetArrElemPtr1(args, i);
87
    printf( "^^^ | py_run_file | args[%d] = %s\n"
88
          , i
89
          , argv[i]
90
          );
91
  }
92
 
93
  PySys_SetArgv(argc, argv);
94
  PyObject *PyFileObject = PyFile_FromString((char *)filename, "r");
95
  return PyRun_SimpleFileEx(PyFile_AsFile(PyFileObject), filename, 1);
96
}
97
 
98
// --------------------------------------------------------------------
99
void init_py_dpi(int width, int height)
100
{
101
  printf("^^^ | init_py_dpi() | %dx%d\n", width, height);
102
  Py_Initialize();
103
  init_py_to_video_frame();
104
 
105
  PyObject *dva_m = PyImport_ImportModule("dpi_video_array");
106
  if(!dva_m)
107
  {
108
      PyErr_Print();
109
      printf("^^^ | init_py_dpi() | dva_m Error\n");
110
  }
111
 
112
  PyObject *dva_c = PyObject_GetAttrString(dva_m, "dpi_video_array");
113
  Py_DECREF(dva_m);
114
  if(!dva_c)
115
  {
116
      PyErr_Print();
117
      printf("^^^ | init_py_dpi() | dva_c Error\n");
118
  }
119
 
120
  PyObject *args = Py_BuildValue("(ii)", width, height);
121
  g_dva_i = PyObject_CallObject(dva_c, args);
122
  Py_DECREF(args);
123
  Py_DECREF(dva_c);
124
  if(!g_dva_i)
125
  {
126
      PyErr_Print();
127
      printf("^^^ | init_py_dpi() | g_dva_i Error\n");
128
      Py_DECREF(g_dva_i);
129
      g_dva_i = NULL;
130
  }
131
}
132
 
133
// --------------------------------------------------------------------
134
void exit_py_dpi()
135
{
136
  printf("^^^ | exit_py_dpi()\n");
137
 
138
  if(g_dva_i)
139
    Py_DECREF(g_dva_i);
140
 
141
  Py_Finalize();
142
}

powered by: WebSVN 2.1.0

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