-
Notifications
You must be signed in to change notification settings - Fork 5
/
krunxx.cpp
149 lines (121 loc) · 4.81 KB
/
krunxx.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
//
// Created by Petr Mánek on 13.07.18.
//
#include <chrono>
#include <iostream>
#include <katherinexx/katherinexx.hpp>
static const std::string remote_addr{"192.168.1.145"};
using mode = katherine::acq::f_toa_tot;
void
configure(katherine::config& config)
{
using namespace std::literals::chrono_literals;
// For now, these constants are hard-coded.
// This configuration will produce meaningful results only for: M7-W0005
config.set_bias_id(0);
config.set_acq_time(10s);
config.set_no_frames(1);
config.set_bias(230); // V
config.set_delayed_start(false);
config.set_start_trigger(katherine::no_trigger);
config.set_stop_trigger(katherine::no_trigger);
config.set_gray_disable(false);
config.set_polarity_holes(false);
config.set_phase(katherine::phase::p1);
config.set_freq(katherine::freq::f40);
katherine::dacs dacs{};
dacs.named.Ibias_Preamp_ON = 128;
dacs.named.Ibias_Preamp_OFF = 8;
dacs.named.VPReamp_NCAS = 128;
dacs.named.Ibias_Ikrum = 15;
dacs.named.Vfbk = 164;
dacs.named.Vthreshold_fine = 476;
dacs.named.Vthreshold_coarse = 8;
dacs.named.Ibias_DiscS1_ON = 100;
dacs.named.Ibias_DiscS1_OFF = 8;
dacs.named.Ibias_DiscS2_ON = 128;
dacs.named.Ibias_DiscS2_OFF = 8;
dacs.named.Ibias_PixelDAC = 128;
dacs.named.Ibias_TPbufferIn = 128;
dacs.named.Ibias_TPbufferOut = 128;
dacs.named.VTP_coarse = 128;
dacs.named.VTP_fine = 256;
dacs.named.Ibias_CP_PLL = 128;
dacs.named.PLL_Vcntrl = 128;
config.set_dacs(std::move(dacs));
katherine::px_config px_config = katherine::load_bmc_file("chipconfig.bmc");
config.set_pixel_config(std::move(px_config));
}
static uint64_t n_hits;
void
frame_started(int frame_idx)
{
n_hits = 0;
std::cerr << "Started frame " << frame_idx << "." << std::endl;
std::cerr << "X\tY\tToA\tfToA\tToT" << std::endl;
}
void
frame_ended(int frame_idx, bool completed, const katherine_frame_info_t& info)
{
const double recv_perc = 100. * info.received_pixels / info.sent_pixels;
std::cerr << std::endl << std::endl;
std::cerr << "Ended frame " << frame_idx << "." << std::endl;
std::cerr << " - tpx3->katherine lost " << info.lost_pixels << " pixels" << std::endl
<< " - katherine->pc sent " << info.sent_pixels << " pixels" << std::endl
<< " - katherine->pc received " << info.received_pixels << " pixels (" << recv_perc << " %)" << std::endl
<< " - state: " << (completed ? "completed" : "not completed") << std::endl
<< " - start time: " << info.start_time.d << std::endl
<< " - end time: " << info.end_time.d << std::endl;
}
void
pixels_received(const mode::pixel_type *px, size_t count)
{
n_hits += count;
for (size_t i = 0; i < count; ++i) {
std::cerr << (unsigned) px[i].coord.x << '\t'
<< (unsigned) px[i].coord.y << '\t'
<< (unsigned) px[i].toa << '\t'
<< (unsigned) px[i].ftoa << '\t'
<< (unsigned) px[i].tot << std::endl;
}
}
void
print_chip_id(katherine::device& device)
{
std::string chip_id = device.chip_id();
std::cerr << "Chip ID: " << chip_id << std::endl;
}
void
run_acquisition(katherine::device& dev, const katherine::config& c)
{
using namespace std::chrono;
using namespace std::literals::chrono_literals;
katherine::acquisition<mode> acq{dev, katherine::md_size * 34952533, sizeof(mode::pixel_type) * 65536, 500ms, 10s, true};
acq.set_frame_started_handler(frame_started);
acq.set_frame_ended_handler(frame_ended);
acq.set_pixels_received_handler(pixels_received);
acq.begin(c, katherine::readout_type::data_driven);
std::cerr << "Acquisition started." << std::endl;
auto tic = steady_clock::now();
acq.read();
auto toc = steady_clock::now();
double duration = duration_cast<milliseconds>(toc - tic).count() / 1000.;
std::cerr << std::endl;
std::cerr << "Acquisition completed:" << std::endl
<< " - state: " << katherine::str_acq_state(acq.state()) << std::endl
<< " - received " << acq.completed_frames() << " complete frames" << std::endl
<< " - dropped " << acq.dropped_measurement_data() << " measurement data items" << std::endl
<< " - total hits: " << n_hits << std::endl
<< " - total duration: " << duration << " s" << std::endl
<< " - throughput: " << (n_hits / duration) << " hits/s" << std::endl;
}
int
main(int argc, char *argv[])
{
katherine::config c{};
configure(c);
katherine::device device{remote_addr};
print_chip_id(device);
run_acquisition(device, c);
return 0;
}