15 namespace itk::itkpix::cmd {
19 const uint16_t
SYNC = 0x817E;
20 const uint16_t
IDLE = 0xAAAA;
39 return enc_symb[data5];
45 assert(trig != 0 && trig < 16);
66 static_assert(PLLLOCK == 0xAA);
67 static_assert(TRIGRD == 0x69);
68 static_assert(CLEAR == 0x5A);
69 static_assert(GLOBAL == 0x5C);
70 static_assert(CALIB == 0x63);
71 static_assert(REGWR == 0x66);
72 static_assert(REGRD == 0x65);
114 trunc_bits<5>(data5);
122 inline uint16_t
encode10b(uint8_t data5a, uint8_t data5b) {
123 trunc_bits<5>(data5a);
124 trunc_bits<5>(data5b);
132 return encode10b(0x1F & (data >> 5), 0x1F & data);
149 inline uint32_t decode_data(uint16_t frame) {
150 auto [data0, data1] = decode16b(frame);
151 assert(data0 < 32 && data1 < 32);
152 return data0 << 5 | data1;
155 inline uint16_t make_head(uint8_t cmd, uint8_t chip_id) {
156 return cmd << 8 | encode5b(chip_id);
159 inline auto parse_head(uint16_t frame) {
160 uint8_t cmd = decode8b(frame >> 8);
161 uint8_t chip_id = decode8b(frame & 0xFF);
163 struct res { uint8_t cmd; uint8_t chip_id; };
164 return res { cmd, chip_id };
169 inline std::array<uint16_t, 1>
174 inline std::array<uint16_t, 1>
182 inline std::array<uint16_t, 1>
186 if (bc == 0 || tag >= 54)
return { cmd::IDLE };
187 uint16_t trig =
enc_trig(bc) << 8 | enc_symb[tag];
196 auto [bc_tag, tag] =
decode16b(frames[0]);
200 struct res { uint8_t
status; uint8_t bc; uint8_t tag; };
201 return res {
status, bc, tag };
208 inline std::array<uint16_t, 1>
210 trunc_bits<5>(chip_id);
211 return { make_head(
CLEAR, chip_id) };
219 auto [cmd, chip_id] =
decode16b(frames[0]);
221 struct res { uint8_t
status; uint8_t cmd; uint8_t chip_id; };
222 return res {
status, cmd, chip_id };
230 inline std::array<uint16_t, 2>
232 trunc_bits<5>(chip_id);
233 return { make_head(cmd::TRIGRD, chip_id),
encode10b(ext_tag) };
241 auto [cmd, chip_id] =
decode16b(frames[0]);
242 auto data = decode_data(frames[1]);
243 uint8_t ext_tag = data & 0xFF;
246 status |= (data & 0x300 ? 0x0 : 0x2);
247 struct res { uint8_t
status; uint8_t cmd; uint8_t chip_id; uint8_t ext_tag; };
248 return res {
status, cmd, chip_id, ext_tag };
252 inline std::array<uint16_t, 1>
253 make_global(uint8_t chip_id) {
254 trunc_bits<5>(chip_id);
255 return { make_head(cmd::GLOBAL, chip_id) };
258 inline auto parse_global(std::array<uint16_t, 1> frames) {
259 auto [cmd, chip_id] = parse_head(frames[0]);
260 uint8_t
status = (cmd == TAG_GLOBAL ? 0x0 : 0x1);
261 struct res { uint8_t
status; uint8_t cmd; uint8_t chip_id; };
262 return res {
status, cmd, chip_id };
283 inline std::array<uint16_t, 3>
284 make_calib(uint8_t chip_id, uint8_t edg_mode, uint8_t edg_delay, uint8_t edg_width,
285 uint8_t aux_mode, uint8_t aux_delay) {
287 trunc_bits<5>(chip_id);
288 trunc_bits<1>(edg_mode);
289 trunc_bits<5>(edg_delay);
290 trunc_bits<8>(edg_width);
291 trunc_bits<1>(aux_mode);
292 trunc_bits<5>(aux_delay);
298 uint32_t buff = edg_mode << 19 | edg_delay << 14 | edg_width << 6 | aux_mode << 5 | aux_delay;
306 auto [cmd, chip_id] = parse_head(frames[0]);
307 auto buff = decode_data(frames[1]) << 10 | decode_data(frames[2]);
308 uint8_t aux_delay = buff & 0x1F; buff = buff >> 5;
309 uint8_t aux_mode = buff & 0x1; buff = buff >> 1;
310 uint8_t edge_width = buff & 0xFF; buff = buff >> 8;
311 uint8_t edge_delay = buff & 0x1F; buff = buff >> 5;
312 uint8_t edge_mode = buff & 0x1; buff = buff >> 1;
316 uint8_t
status; uint8_t cmd; uint8_t chip_id;
317 uint8_t edge_mode; uint8_t edge_delay; uint8_t edge_width;
318 uint8_t aux_mode; uint8_t aux_delay;
320 return res {
status, cmd, chip_id, edge_mode, edge_delay, edge_width, aux_mode, aux_delay };
332 inline std::array<uint16_t, 2>
334 trunc_bits<5>(chip_id);
339 return { make_head(cmd::REGRD, chip_id),
encode10b(addr) };
347 auto [cmd, chip_id] = parse_head(frames[0]);
348 uint16_t addr = decode_data(frames[1]);
351 status |= (addr < 0x200 ? 0x0 : 0x2);
352 struct res { uint8_t
status; uint8_t cmd; uint8_t chip_id; uint16_t addr; };
353 return res {
status, cmd, chip_id, addr };
360 inline std::array<uint16_t, 4>
362 trunc_bits<5>(chip_id);
366 uint32_t buff = addr << 20 | data << 4;
368 return { make_head(cmd::REGWR, chip_id),
380 auto [cmd, chip_id] = parse_head(frames[0]);
381 auto buff = decode_data(frames[1]) << 20 | decode_data(frames[2]) << 10 | decode_data(frames[3]);
382 uint16_t addr = (buff >> 20) & 0x1FF;
383 uint16_t data = (buff >> 4) & 0xFFFF;
386 status |= (buff >> 29 ? 0x0 : 0x2);
387 status |= (buff & 0xF ? 0x0 : 0x4);
388 struct res { uint8_t
status; uint8_t cmd; uint8_t chip_id; uint16_t addr; uint16_t data; };
389 return res {
status, cmd, chip_id, addr, data };
400 inline std::array<uint16_t, 2>
402 trunc_bits<5>(chip_id);
412 auto [cmd, chip_id] = parse_head(frames[0]);
413 uint16_t data = decode_data(frames[1]);
416 status |= (cmd == cmd::REGWR ? 0x0 : 0x1);
417 status |= (data == 0x200 ? 0x0 : 0x2);
418 struct res { uint8_t
status; uint8_t cmd; };
419 return res {
status, cmd };
423 inline uint16_t make_write_pix_next(uint16_t data) {
424 return encode10b(data);
Logger class definition, wrapper around CoreLogger, adds templated methods for different logging leve...
Definition: logger.hpp:108
std::array< uint16_t, 3 > make_calib(uint8_t chip_id, uint8_t edg_mode, uint8_t edg_delay, uint8_t edg_width, uint8_t aux_mode, uint8_t aux_delay)
'Cal' command format:
Definition: cmdfuncs.hpp:284
constexpr uint8_t TAG_CALIB
Symbols.
Definition: cmdfuncs.hpp:23
auto parse_calib(std::array< uint16_t, 3 > frames)
Parse 'Cal' command.
Definition: cmdfuncs.hpp:305
auto parse_clear(std::array< uint16_t, 1 > frames)
Parse 'clear' command.
Definition: cmdfuncs.hpp:218
uint8_t enc_tag(uint8_t tag)
Encode trigger tag.
Definition: cmdfuncs.hpp:51
std::array< uint16_t, 2 > make_read_trig(uint8_t chip_id, uint8_t ext_tag)
Make 'ReadTrigger' command.
Definition: cmdfuncs.hpp:231
uint8_t decode8b(uint8_t code)
Decoding encoded symbol.
Definition: cmdfuncs.hpp:138
constexpr uint8_t TAG_TRIG0
pseudo-tag for bc = '0000'
Definition: cmdfuncs.hpp:31
constexpr uint8_t CALIB
0x63
Definition: cmdfuncs.hpp:61
constexpr uint8_t REGWR
0x66
Definition: cmdfuncs.hpp:62
constexpr uint8_t TRIGRD
0x69
Definition: cmdfuncs.hpp:58
std::array< uint16_t, 1 > make_trig(uint8_t bc, uint8_t tag)
Make trigger command, if bc = 0 returns IDLE frame.
Definition: cmdfuncs.hpp:183
constexpr uint8_t TAG_PLLLOCK
'Pll Lock' tag
Definition: cmdfuncs.hpp:26
std::array< uint16_t, 1 > make_clear(uint8_t chip_id)
Make 'clear' command.
Definition: cmdfuncs.hpp:209
auto parse_trig(std::array< uint16_t, 1 > frames)
Parse trigger command.
Definition: cmdfuncs.hpp:195
bool is_trig_tag(uint8_t tag)
Check if trigger tag.
Definition: cmdfuncs.hpp:84
uint16_t encode10b(uint8_t data5a, uint8_t data5b)
Encode two 5-bit data to 16-bit command frame.
Definition: cmdfuncs.hpp:122
const uint16_t IDLE
idle command
Definition: cmdfuncs.hpp:20
std::array< uint16_t, 1 > make_sync()
Make sync frame.
Definition: cmdfuncs.hpp:175
constexpr uint8_t TAG_TRIG1
Trigger tag for bc ='000T'.
Definition: cmdfuncs.hpp:32
std::array< uint16_t, 4 > make_write_reg(uint8_t chip_id, uint16_t addr, uint16_t data)
Write register command.
Definition: cmdfuncs.hpp:361
constexpr uint8_t TAG_REGWR
'Write Register' command tag
Definition: cmdfuncs.hpp:29
constexpr uint8_t TAG_GLOBAL
'GlobalPulse' command tag
Definition: cmdfuncs.hpp:25
bool is_data_tag(uint8_t tag)
Check if data tag.
Definition: cmdfuncs.hpp:77
std::array< uint16_t, 1 > make_idle()
Make idle frame.
Definition: cmdfuncs.hpp:170
const uint16_t SYNC
sync and idle (pll_lock) words
Definition: cmdfuncs.hpp:19
uint8_t enc_data(uint8_t data5)
Encode data.
Definition: cmdfuncs.hpp:37
bool is_data(uint8_t code)
Check if encoded symbol is data.
Definition: cmdfuncs.hpp:98
uint8_t enc_trig(uint8_t trig)
Encode 4 BC trigger pattern.
Definition: cmdfuncs.hpp:44
constexpr uint8_t TAG_TRIGRD
'Read Trigger' command tag
Definition: cmdfuncs.hpp:28
bool is_cmd(uint8_t code)
Check if encoded symbol is command.
Definition: cmdfuncs.hpp:108
bool is_cmd_tag(uint8_t tag)
Check if command tag.
Definition: cmdfuncs.hpp:91
constexpr uint8_t TAG_REGRD
'Read Register' command tag
Definition: cmdfuncs.hpp:27
constexpr uint8_t CLEAR
0x5A
Definition: cmdfuncs.hpp:59
uint8_t encode5b(uint8_t data5)
Encode 5-bit data to 8-bit.
Definition: cmdfuncs.hpp:113
auto parse_write_pix_start(std::array< uint16_t, 2 > frames)
Parse multi-write start command.
Definition: cmdfuncs.hpp:411
auto parse_read_trig(std::array< uint16_t, 2 > frames)
Parse 'ReadTrigger' command.
Definition: cmdfuncs.hpp:240
constexpr uint8_t TAG_CLEAR
'Clear' command tag
Definition: cmdfuncs.hpp:24
std::array< uint16_t, 2 > make_write_pix_start(uint8_t chip_id)
Start of multi-write to pixel portal 'PIX_PORTAL'.
Definition: cmdfuncs.hpp:401
bool is_trig(uint8_t code)
Check if encoded symbol is trigger.
Definition: cmdfuncs.hpp:103
constexpr uint8_t GLOBAL
0x5C
Definition: cmdfuncs.hpp:60
constexpr uint8_t TAG_TRIGF
Trigger tag for bc = 'TTTT'.
Definition: cmdfuncs.hpp:33
constexpr uint8_t PLLLOCK
Commands.
Definition: cmdfuncs.hpp:57
auto parse_write_reg(std::array< uint16_t, 4 > frames)
Parse 'WriteReg' command.
Definition: cmdfuncs.hpp:379
constexpr uint8_t REGRD
0x65
Definition: cmdfuncs.hpp:63
auto decode16b(uint16_t frame)
Decode command frame.
Definition: cmdfuncs.hpp:145
std::array< uint16_t, 2 > make_read_reg(uint8_t chip_id, uint16_t addr)
'ReadReg' command format
Definition: cmdfuncs.hpp:333
auto parse_read_reg(std::array< uint16_t, 2 > frames)
Parse 'ReadReg' command.
Definition: cmdfuncs.hpp:346
ITkPix Commander look up tables.
constexpr uint16_t dec_symb[256]
Decode encoded symbol.
Definition: cmdluts.hpp:29