Belle II Software  release-05-01-25
xsi_loader.cc
1 #include <iostream>
2 #include "trg/cdc/xsi_loader.h"
3 
4 using namespace Xsi;
5 
6 Loader::Loader(const std::string& design_libname, const std::string& simkernel_libname) :
7  _design_libname(design_libname),
8  _simkernel_libname(simkernel_libname),
9  _design_handle(NULL),
10  _xsi_open(NULL),
11  _xsi_close(NULL),
12  _xsi_run(NULL),
13  _xsi_get_value(NULL),
14  _xsi_put_value(NULL),
15  _xsi_get_status(NULL),
16  _xsi_get_error_info(NULL),
17  _xsi_restart(NULL),
18  _xsi_get_port_number(NULL),
19  _xsi_trace_all(NULL)
20 {
21 
22  if (!initialize()) {
23  throw LoaderException("Failed to Load up XSI.");
24  }
25 
26 }
27 
28 Loader::~Loader()
29 {
30  close();
31 }
32 
33 bool
34 Loader::isopen() const
35 {
36  return (_design_handle != NULL);
37 }
38 
39 void
40 Loader::open(p_xsi_setup_info setup_info)
41 {
42  _design_handle = _xsi_open(setup_info);
43 }
44 
45 void
46 Loader::close()
47 {
48  if (_design_handle) {
49  _xsi_close(_design_handle);
50  _design_handle = NULL;
51  }
52 }
53 
54 void
55 Loader::run(XSI_INT64 step)
56 {
57  _xsi_run(_design_handle, step);
58 }
59 
60 void
61 Loader::restart()
62 {
63  _xsi_restart(_design_handle);
64 }
65 
66 int
67 Loader::get_value(int port_number, void* value)
68 {
69  return _xsi_get_value(_design_handle, port_number, value);
70 }
71 
72 int
73 Loader::get_port_number(const char* port_name)
74 {
75  return _xsi_get_port_number(_design_handle, port_name);
76 }
77 
78 void
79 Loader::put_value(int port_number, const void* value)
80 {
81  _xsi_put_value(_design_handle, port_number, const_cast<void*>(value));
82 }
83 
84 int
85 Loader::get_status()
86 {
87  return _xsi_get_status(_design_handle);
88 }
89 
90 const char*
91 Loader::get_error_info()
92 {
93  return _xsi_get_error_info(_design_handle);
94 }
95 
96 void
97 Loader::trace_all()
98 {
99  _xsi_trace_all(_design_handle);
100 }
101 
102 bool
103 Loader::initialize()
104 {
105 
106  // Load ISIM design shared library
107  if (!_design_lib.load(_design_libname)) {
108  std::cerr << "Could not load XSI simulation shared library (" << _design_libname << "): " << _design_lib.error() << std::endl;
109  return false;
110  }
111 
112 
113  if (!_simkernel_lib.load(_simkernel_libname)) {
114  std::cerr << "Could not load simulaiton kernel library (" << _simkernel_libname << ") :" << _simkernel_lib.error() << "\n";
115  return false;
116  }
117 
118  // Get function pointer for getting an ISIM design handle
119  _xsi_open = (t_fp_xsi_open) _design_lib.getfunction("xsi_open");
120  if (!_xsi_open) {
121  return false;
122  }
123 
124 
125  // Get function pointer for running ISIM simulation
126  _xsi_run = (t_fp_xsi_run) _simkernel_lib.getfunction("xsi_run");
127  if (!_xsi_run) {
128  return false;
129  }
130 
131  // Get function pointer for terminating ISIM simulation
132  _xsi_close = (t_fp_xsi_close) _simkernel_lib.getfunction("xsi_close");
133  if (!_xsi_close) {
134  return false;
135  }
136 
137  // Get function pointer for running ISIM simulation
138  _xsi_restart = (t_fp_xsi_restart) _simkernel_lib.getfunction("xsi_restart");
139  if (!_xsi_restart) {
140  return false;
141  }
142 
143  // Get function pointer for reading data from ISIM
144  _xsi_get_value = (t_fp_xsi_get_value) _simkernel_lib.getfunction("xsi_get_value");
145  if (!_xsi_get_value) {
146  return false;
147  }
148 
149  // Get function pointer for reading data from ISIM
150  _xsi_get_port_number = (t_fp_xsi_get_port_number) _simkernel_lib.getfunction("xsi_get_port_number");
151  if (!_xsi_get_port_number) {
152  return false;
153  }
154  // Get function pointer for passing data to ISIM
155  _xsi_put_value = (t_fp_xsi_put_value) _simkernel_lib.getfunction("xsi_put_value");
156  if (!_xsi_put_value) {
157  return false;
158  }
159 
160  // Get function pointer for checking error status
161  _xsi_get_status = (t_fp_xsi_get_status) _simkernel_lib.getfunction("xsi_get_status");
162  if (!_xsi_get_status) {
163  return false;
164  }
165 
166  // Get function pointer for getting error message
167  _xsi_get_error_info = (t_fp_xsi_get_error_info) _simkernel_lib.getfunction("xsi_get_error_info");
168  if (!_xsi_get_error_info) {
169  return false;
170  }
171 
172  // Get function pointer for tracing all signals to WDB
173  _xsi_trace_all = (t_fp_xsi_trace_all) _simkernel_lib.getfunction("xsi_trace_all");
174  if (!_xsi_trace_all) {
175  return false;
176  }
177 
178  return true;
179 }
180 
181 // 67d7842dbbe25473c3c32b93c0da8047785f30d78e8a024de1b57352245f9689
Xsi::LoaderException
Definition: xsi_loader.h:12
t_xsi_setup_info
Note: VHDL std_logic value is stored in a byte (char).
Definition: xsi.h:137