// Copyright (2019-2023) Paul Scherrer Institute #include "hls_jfjoch.h" void eiger_reorder(STREAM_512 &data_in, STREAM_512 &data_out, hls::stream &s_axis_completion, hls::stream &m_axis_completion) { #pragma HLS INTERFACE ap_ctrl_none port=return #pragma HLS INTERFACE register both axis port=data_in #pragma HLS INTERFACE register both axis port=data_out #pragma HLS INTERFACE register both axis port=m_axis_completion #pragma HLS INTERFACE register both axis port=s_axis_completion packet_512_t packet; { #pragma HLS PROTOCOL fixed data_in >> packet; ap_wait(); data_out << packet; ap_wait(); } ap_uint<512> memory_0[128]; #pragma HLS BIND_STORAGE variable=memory_0 type=ram_t2p impl=bram latency=3 ap_uint<512> memory_1[128]; #pragma HLS BIND_STORAGE variable=memory_1 type=ram_t2p impl=bram latency=3 packet_512_t packet_out; packet_out.user = 0; packet_out.last = 0; packet_out.id = 0; axis_completion cmpl; s_axis_completion >> cmpl; while (!cmpl.last) { m_axis_completion << cmpl; if (cmpl.detector_type == SLS_DETECTOR_TYPE_EIGER) { for (int i = 0; i < 16384; i++) { #pragma HLS PIPELINE II=1 data_in >> packet; size_t counter = i % 128; size_t col0 = (counter >= 64) ? 16 : 0; size_t line0 = (counter / 16) % 4; if (i < 8192) line0 = 3 - line0; // second half is reversed size_t pos = line0 * 32 + col0 + counter % 16; if ((i / 128) % 2 == 0) { memory_0[pos] = packet.data; packet_out.data = memory_1[counter]; } else { memory_1[pos] = packet.data; packet_out.data = memory_0[counter]; } if (i >= 128) data_out << packet_out; } for (int i = 0; i < 128; i++) { #pragma HLS PIPELINE II=1 packet_out.data = memory_1[i]; if (i == 127) packet_out.last = 1; data_out << packet_out; } } else { for (int i = 0; i < 16384; i++) { #pragma HLS PIPELINE II=1 data_in >> packet; data_out << packet; } } s_axis_completion >> cmpl; } m_axis_completion << cmpl; data_in >> packet; data_out << packet; }