15 #include "nlohmann/json.hpp"
27 memset(
this, 0,
sizeof(
VI));
54 memset(
this, 0,
sizeof(
VO));
85 IO::IO(
string _name,
VI _vi,
VO _vo): name(_name), vi(_vi), vo(_vo), _string(0)
92 if (_string)
delete _string;
97 return name +
" VI:" + to_string(
vi.
len()) +
" VO:" + to_string(
vo.
len());
104 for (
auto uut:
uuts){
105 cerr <<
"\t" <<
"[" << port <<
"] " << uut->toString() <<endl;
112 cerr <<
"dump_data" <<endl;
116 ACQ::ACQ(
int _devnum,
string _name,
VI _vi,
VO _vo,
VI _vi_offsets,
VO _vo_offsets,
VI& sys_vi_cursor,
VO& sys_vo_cursor) :
119 vi_offsets(_vi_offsets), vo_offsets(_vo_offsets),
120 vi_cursor(sys_vi_cursor), vo_cursor(sys_vo_cursor),
121 nowait(false), wd_mask(0), pollcount(0)
134 sprintf(wd,
" WD mask: 0x%08x",
wd_mask);
141 cerr <<
" new sample: " << sample <<
" " <<
getName() << endl;
152 cerr <<
"placeholder: ARM unit " <<
getName() <<
" now" <<endl;
159 }
catch (std::exception& e){
160 return default_value;
164 HBA::HBA(vector <ACQ*> _uuts,
VI _vi,
VO _vo):
165 devnum(_uuts[0]->devnum&~0x3),
166 IO(
"HBA"+to_string(devnum), _vi, _vo),
167 uuts(_uuts), vi(_vi), vo(_vo)
169 for (
auto uut: uuts){
170 devs.push_back(uut->devnum);
175 for (
auto uut :
uuts){
186 for (
auto uut :
uuts){
187 while(!uut->newSample(sample)){
191 fprintf(stderr,
"ERROR: poll timeout on uut %s at sample %d\n", uut->getName().c_str(), sample);
196 for (
auto uut :
uuts){
197 uut->action(systemInterface);
200 for (
auto uut :
uuts){
201 uut->action2(systemInterface);
207 string dev_str =
"devs=";
209 for (
auto dev:
devs){
213 dev_str += to_string(dev);
218 typedef pair<std::string, int>
KVP;
219 typedef std::map <std::string, int>
KVM;
221 typedef pair<std::string, string>
KVPS;
222 typedef std::map <std::string, string>
KVMS;
226 #define COM(i) "__comment" #i "__"
228 #define INSERT_IF(map, vx, vxo, field) \
229 if (uut->vx.field){ \
230 map.insert(KVP(#field, uut->vxo.field)); \
235 jsys[
COM(1)] =
"created from " + fname;
236 jsys[
COM(2)] =
"LOCAL VI_OFFSETS: field offset VI in bytes";
237 jsys[
COM(3)] =
"LOCAL VO_OFFSETS: field offset VO in bytes";
238 jsys[
COM(4)] =
"LOCAL VX_LEN: length of VI|VO in bytes";
239 jsys[
COM(5)] =
"GLOBAL_LEN: total length of each type in SystemInterface";
240 jsys[
COM(6)] =
"GLOBAL_INDICES: index of field in type-specific array in SI";
241 jsys[
COM(7)] =
"SPIX: Scratch Pad Index, index of field in SP32";
248 jsys[
"SPIX"] = spix_map;
253 json &jgl = jsys[
"GLOBAL_LEN"];
254 json &jlen_vi = jgl[
"VI"];
261 json &jlen_vo = jgl[
"VO"];
272 json &jsys = j[
"SYS"];
277 for (
auto uut : hba.
uuts){
278 json &jlo = jsys[
"UUT"][
"LOCAL"][ii];
280 jlo[
"VX_LEN"] = { {
"VI", uut->vi.len() }, {
"VO", uut->vo.len() } };
283 INSERT_IF(vi_offsets_map, vi, vi_offsets, AI16);
284 INSERT_IF(vi_offsets_map, vi, vi_offsets, AI32);
285 INSERT_IF(vi_offsets_map, vi, vi_offsets, DI32);
286 INSERT_IF(vi_offsets_map, vi, vi_offsets, SP32);
287 jlo[
"VI_OFFSETS"] = vi_offsets_map;
290 INSERT_IF(vo_offsets_map, vo, vo_offsets, AO16);
291 INSERT_IF(vo_offsets_map, vo, vo_offsets, DO32);
292 INSERT_IF(vo_offsets_map, vo, vo_offsets, PW32);
293 INSERT_IF(vo_offsets_map, vo, vo_offsets, CC32);
294 jlo[
"VO_OFFSETS"] = vo_offsets_map;
296 json &jix = jsys[
"UUT"][
"GLOBAL_INDICES"][ii++];
313 std::ofstream o(
"runtime.json");
314 o << std::setw(4) << j << std::endl;
322 bool strstr(
string haystack,
string needle)
324 return haystack.find(needle) != string::npos;
332 std::ifstream i(json_def);
343 int hba_devnum =
get_int(j[
"AFHBA"][
"DEVNUM"]);
345 for (
auto uut : j[
"AFHBA"][
"UUT"]) {
347 if (
get_int(uut[
"DEVNUM"], -1) != -1){
348 hba_devnum =
get_int(uut[
"DEVNUM"]);
368 int wd_bit = uut[
"WD_BIT"].get<
int>();
372 cerr <<
"WARNING: " << uut[
"name"] <<
" attempted to set WD_BIT when PORT (" << port <<
") != 0" <<endl;
374 }
catch (exception& e) {
377 string uut_type = uut[
"type"];
380 first_type = uut_type;
383 cerr <<
"NOTICE: port " << port <<
" is bolo in non-bolo set, set nowait" << endl;
385 }
else if (::
strstr(first_type,
"pcs") &&
::strstr(uut_type,
"nowait")){
386 cerr <<
"NOTICE: port " << port <<
" set nowait" << endl;
388 }
else if (::
strstr(first_type,
"bolo") && !
::strstr(uut_type,
"bolo")){
389 cerr <<
"WARNING: port " << port <<
" is NOT bolo when port0 IS bolo" << endl;
396 the_hba =
new HBA(
uuts, VI_sys, VO_sys);