forked from psi46/psi46test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixel_dtb.cpp
157 lines (130 loc) · 2.95 KB
/
pixel_dtb.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// psi46_tb.cpp
#include "pixel_dtb.h"
#include <stdio.h>
#ifndef _WIN32
#include <unistd.h>
#include <iostream>
#endif
bool CTestboard::EnumNext(string &name)
{
char s[64];
if (!usb.EnumNext(s)) return false;
name = s;
return true;
}
bool CTestboard::Enum(unsigned int pos, string &name)
{
char s[64];
if (!usb.Enum(s, pos)) return false;
name = s;
return true;
}
bool CTestboard::FindDTB(string &usbId)
{
string name;
vector<string> devList;
unsigned int nDev;
unsigned int nr;
try
{
if (!EnumFirst(nDev)) throw int(1);
for (nr=0; nr<nDev; nr++)
{
if (!EnumNext(name)) continue;
if (name.size() < 4) continue;
if (name.compare(0, 4, "DTB_") == 0) devList.push_back(name);
}
}
catch (int e)
{
switch (e)
{
case 1: printf("Cannot access the USB driver\n"); return false;
default: return false;
}
}
if (devList.size() == 0)
{
printf("No DTB connected.\n");
return false;
}
if (devList.size() == 1)
{
usbId = devList[0];
return true;
}
// If more than 1 connected device list them
printf("\nConnected DTBs:\n");
for (nr=0; nr<devList.size(); nr++)
{
printf("%2u: %s", nr, devList[nr].c_str());
if (Open(devList[nr], false))
{
try
{
unsigned int bid = GetBoardId();
printf(" BID=%2u\n", bid);
}
catch (...)
{
printf(" Not identifiable\n");
}
Close();
}
else printf(" - in use\n");
}
printf("Please choose DTB (0-%u): ", (nDev-1));
char choice[8];
fgets(choice, 8, stdin);
sscanf (choice, "%d", &nr);
if (nr >= devList.size())
{
nr = 0;
printf("No DTB opened\n");
return false;
}
usbId = devList[nr];
return true;
}
bool CTestboard::Open(string &usbId, bool init)
{
rpc_Clear();
if (!usb.Open(&(usbId[0]))) return false;
if (init) Init();
return true;
}
void CTestboard::Close()
{
// if (usb.Connected()) Daq_Close();
usb.Close();
rpc_Clear();
}
int32_t CTestboard::ChipThreshold(int32_t start, int32_t step, int32_t thrLevel, int32_t nTrig, int32_t dacReg, int32_t xtalk, int32_t cals, int32_t trim[], int32_t res[])
{
vectorR<int32_t> trim_v, res_v;
for(int i = 0; i < ROC_NUMROWS * ROC_NUMCOLS; i++)
{
trim_v.push_back(trim[i]);
}
for(int i = 0; i < ROC_NUMROWS * ROC_NUMCOLS; i++)
{
printf("%d\n",i);
res_v.push_back(res[i]);
}
int32_t val = ChipThresholdConvert(start, step, thrLevel, nTrig, dacReg, xtalk, cals, trim_v, res_v);
//int32_t val = ChipThresholdConvert(start, step, thrLevel, nTrig, dacReg, xtalk, cals, trim, res);
res[0] = res_v.at(0);
printf("res = %d \n",res[0]);
// for (int i = 0; i < ROC_NUMROWS * ROC_NUMCOLS; i++) trim[i] = trim_v.at(i);
// for (int i = 0; i < ROC_NUMROWS * ROC_NUMCOLS; i++) res[i] = res_v.at(i);
return val;
}
void CTestboard::mDelay(uint16_t ms)
{
Flush();
#ifdef _WIN32
Sleep(ms); // Windows
#else
usleep(ms*1000); // Linux
#endif
}