diff --git a/fpga/hdl/action_config.v b/fpga/hdl/action_config.v index 64d0848d..589401de 100644 --- a/fpga/hdl/action_config.v +++ b/fpga/hdl/action_config.v @@ -48,8 +48,8 @@ `define ADDR_NFRAMES 16'h0098 `define ADDR_NSTORAGE_CELLS 16'h009C -`define ADDR_SPOT_FINDER_THRESHOLD 16'h0100 -`define ADDR_SPOT_FINDER_SNR 16'h0104 +`define ADDR_SPOT_FINDER_CNT_THR 16'h0100 +`define ADDR_SPOT_FINDER_SNR_THR 16'h0104 module action_config @@ -91,8 +91,8 @@ module action_config output reg [7:0] nmodules , output reg [3:0] nstorage_cells , output wire [31:0] hbm_size_bytes , - output reg[15:0] spot_finder_threshold , - output reg[15:0] spot_finder_snr , + output reg[15:0] spot_finder_count_threshold , + output reg[15:0] spot_finder_snr_threshold , output reg data_collection_start , output reg data_collection_cancel , @@ -378,11 +378,11 @@ always @(posedge clk) begin `ADDR_FIFO_STATUS: begin rdata <= reg_fifo_status; end - `ADDR_SPOT_FINDER_THRESHOLD: begin - rdata <= spot_finder_threshold; + `ADDR_SPOT_FINDER_CNT_THR: begin + rdata <= spot_finder_count_threshold; end - `ADDR_SPOT_FINDER_SNR: begin - rdata <= spot_finder_snr; + `ADDR_SPOT_FINDER_SNR_THR: begin + rdata <= spot_finder_snr_threshold; end default: rdata <= 32'hffffffff; @@ -521,16 +521,16 @@ end always @(posedge clk) begin if (!resetn) - spot_finder_snr <= 0; - else if (w_hs && waddr == `ADDR_SPOT_FINDER_SNR) - spot_finder_snr <= (s_axi_WDATA[15:0] & wmask[15:0]) | (spot_finder_snr & !wmask[3:0]); + spot_finder_snr_threshold <= 0; + else if (w_hs && waddr == `ADDR_SPOT_FINDER_SNR_THR) + spot_finder_snr_threshold <= (s_axi_WDATA[15:0] & wmask[15:0]) | (spot_finder_snr_threshold & !wmask[3:0]); end always @(posedge clk) begin if (!resetn) - spot_finder_threshold <= 0; - else if (w_hs && waddr == `ADDR_SPOT_FINDER_THRESHOLD) - spot_finder_threshold <= (s_axi_WDATA[15:0] & wmask[15:0]) | (spot_finder_threshold & !wmask[3:0]); + spot_finder_count_threshold <= 0; + else if (w_hs && waddr == `ADDR_SPOT_FINDER_CNT_THR) + spot_finder_count_threshold <= (s_axi_WDATA[15:0] & wmask[15:0]) | (spot_finder_count_threshold & !wmask[3:0]); end always @ (posedge clk) begin diff --git a/fpga/hls/hls_jfjoch.h b/fpga/hls/hls_jfjoch.h index b9f73659..69914f6c 100644 --- a/fpga/hls/hls_jfjoch.h +++ b/fpga/hls/hls_jfjoch.h @@ -83,132 +83,16 @@ struct axis_completion { void setup_datamover (hls::stream &datamover_cmd_stream, uint64_t address, size_t bytes_to_write); -void data_collection_fsm(AXI_STREAM ð_in, - STREAM_512 &data_out, - hls::stream &addr_in, - hls::stream &addr_out, - volatile ap_uint<1> &in_run, - volatile ap_uint<1> &in_cancel, - volatile ap_uint<1> &out_idle, - ap_uint<32> mode, - ap_uint<32> one_over_energy, - ap_uint<32> nframes, - ap_uint<8> nmodules, - ap_uint<4> nstorage_cells); - -void load_calibration(ap_uint<256> *d_hbm_p0, - ap_uint<256> *d_hbm_p1, - ap_uint<8> modules, - ap_uint<5> storage_cells, - ap_uint<32> hbm_size_bytes, - ap_uint<8> destination, - hls::stream &datamover_in_cmd, - hls::stream > &host_memory_in, - uint64_t in_mem_location[(3 * 16 + 3) * MAX_MODULES_FPGA]) ; - -void frame_generator(STREAM_512 &data_out, - ap_uint<256> *d_hbm_p0, - ap_uint<256> *d_hbm_p1, - ap_uint<32> hbm_size_bytes, - ap_uint<32> frames, - ap_uint<5> modules, - ap_uint<48> src_mac_addr, - ap_uint<48> dest_mac_addr, - ap_uint<32> src_ipv4_addr, - ap_uint<32> dest_ipv4_addr, - ap_uint<64> bunchid, - ap_uint<32> exptime, - ap_uint<32> debug); - -void jf_conversion(STREAM_512 &data_in, STREAM_512 &data_out, - hls::stream &s_axis_completion, - hls::stream &m_axis_completion, - hls::burst_maxi d_hbm_p0, hls::burst_maxi d_hbm_p1, - hls::burst_maxi d_hbm_p2, hls::burst_maxi d_hbm_p3, - hls::burst_maxi d_hbm_p4, hls::burst_maxi d_hbm_p5, - hls::burst_maxi d_hbm_p6, hls::burst_maxi d_hbm_p7, - hls::burst_maxi d_hbm_p8, hls::burst_maxi d_hbm_p9, - hls::burst_maxi d_hbm_p10, hls::burst_maxi d_hbm_p11, - ap_uint<32> hbm_size_bytes) ; - -void host_writer(STREAM_512 &data_in, - hls::stream> &adu_histo_in, - hls::stream> &integration_in, - hls::stream> &spot_finder_in, - hls::stream &s_axis_completion, - hls::stream > &host_memory_out, - hls::stream &datamover_out_cmd, - hls::stream > &s_axis_work_request, - hls::stream > &m_axis_completion, - volatile uint64_t &packets_processed, - volatile ap_uint<1> &idle, - volatile ap_uint<8> &err_reg); - -void load_from_hbm(STREAM_512 &data_in, - STREAM_512 &data_out, - hls::stream &s_axis_completion, - hls::stream &m_axis_completion, - hls::stream > &m_axis_free_handles, - hls::stream > &hbm_in_0, - hls::stream > &hbm_in_1, - hls::stream &datamover_0_cmd, - hls::stream &datamover_1_cmd, - ap_uint<32> hbm_size_bytes); - -void save_to_hbm(STREAM_512 &data_in, - STREAM_512 &data_out, - hls::stream &addr_in, - hls::stream &m_axis_completion, - hls::stream> &s_axis_free_handles, - hls::stream > &hbm_out_0, - hls::stream > &hbm_out_1, - hls::stream &datamover_0_cmd, - hls::stream &datamover_1_cmd, - ap_uint<32> hbm_size_bytes); - -void mask_missing(STREAM_512 &data_in, - STREAM_512 &data_out, - hls::stream &s_axis_completion, - hls::stream &m_axis_completion); - -void timer_host(STREAM_512 &data_in, - STREAM_512 &data_out, - volatile uint64_t &counter); - void stream_merge(AXI_STREAM &input_0, AXI_STREAM &input_1, AXI_STREAM &output); -void integration(STREAM_512 &data_in, - STREAM_512 &data_out, - hls::stream> &result_out, - hls::stream &s_axis_completion, - hls::stream &m_axis_completion, - ap_uint<256> *d_hbm_p0, - ap_uint<256> *d_hbm_p1, - ap_uint<32> hbm_size_bytes); - void axis_256_to_512(hls::stream> &data_in, hls::stream> &data_out); void axis_32_to_512(hls::stream> &data_in, hls::stream> &data_out); -void spot_finder(STREAM_512 &data_in, - STREAM_512 &data_out, - hls::stream> &strong_pixel_out, - volatile ap_int<16> &in_photon_count_threshold, - volatile ap_uint<16> &in_strong_pixel_threshold); - -void adu_histo(STREAM_512 &data_in, - STREAM_512 &data_out, - hls::stream> &result_out, - hls::stream &s_axis_completion, - hls::stream &m_axis_completion); - -void bitshuffle(STREAM_512 &data_in, - STREAM_512 &data_out); - template ap_uint pack32(ap_int in[32]) { #pragma HLS INLINE ap_uint out; @@ -318,4 +202,128 @@ void sls_detector(AXI_STREAM &udp_payload_in, uint32_t& counter_eth_error, uint32_t& counter_len_error, volatile ap_uint<1> &in_clear_counters); + +// Image modification and analysis cores + +void mask_missing(STREAM_512 &data_in, + STREAM_512 &data_out, + hls::stream &s_axis_completion, + hls::stream &m_axis_completion); + +void adu_histo(STREAM_512 &data_in, + STREAM_512 &data_out, + hls::stream> &result_out, + hls::stream &s_axis_completion, + hls::stream &m_axis_completion); + +void jf_conversion(STREAM_512 &data_in, STREAM_512 &data_out, + hls::stream &s_axis_completion, + hls::stream &m_axis_completion, + hls::burst_maxi d_hbm_p0, hls::burst_maxi d_hbm_p1, + hls::burst_maxi d_hbm_p2, hls::burst_maxi d_hbm_p3, + hls::burst_maxi d_hbm_p4, hls::burst_maxi d_hbm_p5, + hls::burst_maxi d_hbm_p6, hls::burst_maxi d_hbm_p7, + hls::burst_maxi d_hbm_p8, hls::burst_maxi d_hbm_p9, + hls::burst_maxi d_hbm_p10, hls::burst_maxi d_hbm_p11, + ap_uint<32> hbm_size_bytes); + +void spot_finder(STREAM_512 &data_in, + STREAM_512 &data_out, + hls::stream> &strong_pixel_out, + volatile ap_int<16> &in_count_threshold, + volatile ap_uint<16> &in_snr_threshold); + +void bitshuffle(STREAM_512 &data_in, + STREAM_512 &data_out); + +void integration(STREAM_512 &data_in, + STREAM_512 &data_out, + hls::stream> &result_out, + hls::stream &s_axis_completion, + hls::stream &m_axis_completion, + ap_uint<256> *d_hbm_p0, + ap_uint<256> *d_hbm_p1, + ap_uint<32> hbm_size_bytes); + +// Packet stream handling + +void data_collection_fsm(AXI_STREAM ð_in, + STREAM_512 &data_out, + hls::stream &addr_in, + hls::stream &addr_out, + volatile ap_uint<1> &in_run, + volatile ap_uint<1> &in_cancel, + volatile ap_uint<1> &out_idle, + ap_uint<32> mode, + ap_uint<32> one_over_energy, + ap_uint<32> nframes, + ap_uint<8> nmodules, + ap_uint<4> nstorage_cells); + +void host_writer(STREAM_512 &data_in, + hls::stream> &adu_histo_in, + hls::stream> &integration_in, + hls::stream> &spot_finder_in, + hls::stream &s_axis_completion, + hls::stream > &host_memory_out, + hls::stream &datamover_out_cmd, + hls::stream > &s_axis_work_request, + hls::stream > &m_axis_completion, + volatile uint64_t &packets_processed, + volatile ap_uint<1> &idle, + volatile ap_uint<8> &err_reg); + +void load_from_hbm(STREAM_512 &data_in, + STREAM_512 &data_out, + hls::stream &s_axis_completion, + hls::stream &m_axis_completion, + hls::stream > &m_axis_free_handles, + hls::stream > &hbm_in_0, + hls::stream > &hbm_in_1, + hls::stream &datamover_0_cmd, + hls::stream &datamover_1_cmd, + ap_uint<32> hbm_size_bytes); + +void save_to_hbm(STREAM_512 &data_in, + STREAM_512 &data_out, + hls::stream &addr_in, + hls::stream &m_axis_completion, + hls::stream> &s_axis_free_handles, + hls::stream > &hbm_out_0, + hls::stream > &hbm_out_1, + hls::stream &datamover_0_cmd, + hls::stream &datamover_1_cmd, + ap_uint<32> hbm_size_bytes); + +void timer_host(STREAM_512 &data_in, + STREAM_512 &data_out, + volatile uint64_t &counter); + +// Helper cores - not part of main "data" path + +void frame_generator(STREAM_512 &data_out, + ap_uint<256> *d_hbm_p0, + ap_uint<256> *d_hbm_p1, + ap_uint<32> hbm_size_bytes, + ap_uint<32> frames, + ap_uint<5> modules, + ap_uint<48> src_mac_addr, + ap_uint<48> dest_mac_addr, + ap_uint<32> src_ipv4_addr, + ap_uint<32> dest_ipv4_addr, + ap_uint<64> bunchid, + ap_uint<32> exptime, + ap_uint<32> debug); + + +void load_calibration(ap_uint<256> *d_hbm_p0, + ap_uint<256> *d_hbm_p1, + ap_uint<8> modules, + ap_uint<5> storage_cells, + ap_uint<32> hbm_size_bytes, + ap_uint<8> destination, + hls::stream &datamover_in_cmd, + hls::stream > &host_memory_in, + uint64_t in_mem_location[(3 * 16 + 3) * MAX_MODULES_FPGA]) ; + #endif diff --git a/fpga/hls/spot_finder.cpp b/fpga/hls/spot_finder.cpp index 82f7b69a..d0e6a03a 100644 --- a/fpga/hls/spot_finder.cpp +++ b/fpga/hls/spot_finder.cpp @@ -13,21 +13,21 @@ ap_uint<32> count_pixels(ap_uint<32> &in) { void spot_finder(STREAM_512 &data_in, STREAM_512 &data_out, hls::stream> &strong_pixel_out, - volatile ap_int<16> &in_photon_count_threshold, - volatile ap_uint<16> &in_strong_pixel_threshold) { + volatile ap_int<16> &in_count_threshold, + volatile ap_uint<16> &in_snr_threshold) { #pragma HLS INTERFACE axis port=data_in #pragma HLS INTERFACE axis port=data_out #pragma HLS INTERFACE axis port=strong_pixel_out -#pragma HLS INTERFACE ap_none register port=in_photon_count_threshold -#pragma HLS INTERFACE ap_none register port=in_strong_pixel_threshold +#pragma HLS INTERFACE ap_none register port=in_count_threshold +#pragma HLS INTERFACE ap_none register port=in_snr_threshold packet_512_t packet; data_in >> packet; data_out << packet; data_in >> packet; while (!packet.user) { - ap_int<16> count_threshold = in_photon_count_threshold; - ap_uint<16> snr_threshold = in_strong_pixel_threshold; + ap_int<16> count_threshold = in_count_threshold; + ap_uint<16> snr_threshold = in_snr_threshold; ap_uint<32> strong_pixel_count = 0; for (int i = 0; i < RAW_MODULE_SIZE * sizeof(uint16_t) / 64; i++) { #pragma HLS PIPELINE II=1 @@ -36,7 +36,7 @@ void spot_finder(STREAM_512 &data_in, ap_int<16> data_unpacked[32]; unpack32(packet.data, data_unpacked); for (int j = 0; j < 32; j++) { - if (data_unpacked[j] > count_threshold) + if (data_unpacked[j] >= count_threshold) strong_pixel[j] = 1; else strong_pixel[j] = 0; diff --git a/fpga/scripts/jfjoch.tcl b/fpga/scripts/jfjoch.tcl index f61de861..92fb7814 100644 --- a/fpga/scripts/jfjoch.tcl +++ b/fpga/scripts/jfjoch.tcl @@ -687,8 +687,8 @@ proc create_hier_cell_jungfraujoch { parentCell nameHier } { connect_bd_net -net action_config_0_nmodules [get_bd_pins action_config_0/nmodules] [get_bd_pins data_collection_fsm_0/nmodules] connect_bd_net -net action_config_0_nstorage_cells [get_bd_pins action_config_0/nstorage_cells] [get_bd_pins data_collection_fsm_0/nstorage_cells] connect_bd_net -net action_config_0_one_over_energy [get_bd_pins action_config_0/one_over_energy] [get_bd_pins data_collection_fsm_0/one_over_energy] - connect_bd_net -net action_config_0_spot_finder_snr [get_bd_pins action_config_0/spot_finder_snr] [get_bd_pins spot_finder_0/in_strong_pixel_threshold] - connect_bd_net -net action_config_0_spot_finder_threshold [get_bd_pins action_config_0/spot_finder_threshold] [get_bd_pins spot_finder_0/in_photon_count_threshold] + connect_bd_net -net action_config_0_spot_finder_snr [get_bd_pins action_config_0/spot_finder_snr_threshold] [get_bd_pins spot_finder_0/in_snr_threshold] + connect_bd_net -net action_config_0_spot_finder_threshold [get_bd_pins action_config_0/spot_finder_count_threshold] [get_bd_pins spot_finder_0/in_count_threshold] connect_bd_net -net ap_clk_1 [get_bd_pins axi_clk] [get_bd_pins action_config_0/clk] [get_bd_pins adu_histo_0/ap_clk] [get_bd_pins axi_datamover_0/m_axi_mm2s_aclk] [get_bd_pins axi_datamover_0/m_axi_s2mm_aclk] [get_bd_pins axi_datamover_0/m_axis_mm2s_cmdsts_aclk] [get_bd_pins axi_datamover_0/m_axis_s2mm_cmdsts_awclk] [get_bd_pins axi_datamover_1/m_axi_mm2s_aclk] [get_bd_pins axi_datamover_1/m_axi_s2mm_aclk] [get_bd_pins axi_datamover_1/m_axis_mm2s_cmdsts_aclk] [get_bd_pins axi_datamover_1/m_axis_s2mm_cmdsts_awclk] [get_bd_pins axis_256_to_512_0/ap_clk] [get_bd_pins axis_32_to_512_0/ap_clk] [get_bd_pins axis_addr_fifo_0/s_axis_aclk] [get_bd_pins axis_adu_histo_result_fifo/s_axis_aclk] [get_bd_pins axis_compl_fifo_0/s_axis_aclk] [get_bd_pins axis_compl_fifo_1/s_axis_aclk] [get_bd_pins axis_compl_fifo_2/s_axis_aclk] [get_bd_pins axis_compl_fifo_3/s_axis_aclk] [get_bd_pins axis_compl_fifo_4/s_axis_aclk] [get_bd_pins axis_compl_fifo_5/s_axis_aclk] [get_bd_pins axis_data_fifo_0/s_axis_aclk] [get_bd_pins axis_data_fifo_1/s_axis_aclk] [get_bd_pins axis_data_fifo_2/s_axis_aclk] [get_bd_pins axis_data_fifo_3/s_axis_aclk] [get_bd_pins axis_data_fifo_4/s_axis_aclk] [get_bd_pins axis_data_fifo_5/s_axis_aclk] [get_bd_pins axis_data_fifo_6/s_axis_aclk] [get_bd_pins axis_data_fifo_7/s_axis_aclk] [get_bd_pins axis_data_fifo_8/s_axis_aclk] [get_bd_pins axis_data_fifo_9/s_axis_aclk] [get_bd_pins axis_data_fifo_c2h_cmd/s_axis_aclk] [get_bd_pins axis_data_fifo_c2h_data/s_axis_aclk] [get_bd_pins axis_data_fifo_h2c_cmd/s_axis_aclk] [get_bd_pins axis_data_fifo_h2c_data/s_axis_aclk] [get_bd_pins axis_datamover_cmd_fifo_0/s_axis_aclk] [get_bd_pins axis_datamover_cmd_fifo_1/s_axis_aclk] [get_bd_pins axis_datamover_cmd_fifo_2/s_axis_aclk] [get_bd_pins axis_datamover_cmd_fifo_3/s_axis_aclk] [get_bd_pins axis_datamover_fifo_0/s_axis_aclk] [get_bd_pins axis_datamover_fifo_1/s_axis_aclk] [get_bd_pins axis_datamover_fifo_2/s_axis_aclk] [get_bd_pins axis_datamover_fifo_3/s_axis_aclk] [get_bd_pins axis_eth_in_fifo/s_axis_aclk] [get_bd_pins axis_frame_generator_fifo_0/s_axis_aclk] [get_bd_pins axis_hbm_handles_fifo/s_axis_aclk] [get_bd_pins axis_integration_result_fifo_0/s_axis_aclk] [get_bd_pins axis_integration_result_fifo_1/s_axis_aclk] [get_bd_pins axis_register_slice_addr_0/aclk] [get_bd_pins axis_register_slice_data_0/aclk] [get_bd_pins axis_register_slice_data_1/aclk] [get_bd_pins axis_register_slice_data_2/aclk] [get_bd_pins axis_register_slice_data_in_0/aclk] [get_bd_pins axis_register_slice_host_mem/aclk] [get_bd_pins axis_register_slice_udp/aclk] [get_bd_pins axis_spot_finder_fifo_0/s_axis_aclk] [get_bd_pins axis_spot_finder_fifo_1/s_axis_aclk] [get_bd_pins axis_udp_addr_fifo_0/s_axis_aclk] [get_bd_pins axis_udp_fifo_0/s_axis_aclk] [get_bd_pins axis_work_completion_fifo_0/s_axis_aclk] [get_bd_pins axis_work_request_fifo_0/s_axis_aclk] [get_bd_pins data_collection_fsm_0/ap_clk] [get_bd_pins frame_generator_0/ap_clk] [get_bd_pins host_writer_0/ap_clk] [get_bd_pins integration_0/ap_clk] [get_bd_pins jf_conversion_0/ap_clk] [get_bd_pins load_calibration_0/ap_clk] [get_bd_pins load_from_hbm_0/ap_clk] [get_bd_pins mailbox_0/M1_AXIS_ACLK] [get_bd_pins mailbox_0/S0_AXI_ACLK] [get_bd_pins mailbox_0/S1_AXIS_ACLK] [get_bd_pins mask_missing_0/ap_clk] [get_bd_pins network_stack/axiclk] [get_bd_pins save_to_hbm_0/ap_clk] [get_bd_pins smartconnect_0/aclk] [get_bd_pins smartconnect_1/aclk] [get_bd_pins smartconnect_2/aclk] [get_bd_pins spot_finder_0/ap_clk] [get_bd_pins stream_merge_0/ap_clk] [get_bd_pins timer_hbm/ap_clk] [get_bd_pins timer_host/ap_clk] connect_bd_net -net axis_addr_fifo_0_almost_empty [get_bd_pins action_config_0/calib_addr_fifo_empty] [get_bd_pins axis_addr_fifo_0/almost_empty] connect_bd_net -net axis_addr_fifo_0_almost_full [get_bd_pins action_config_0/calib_addr_fifo_full] [get_bd_pins axis_addr_fifo_0/almost_full] diff --git a/tests/FPGAIntegrationTest.cpp b/tests/FPGAIntegrationTest.cpp index 1b1a16d5..3f30dd96 100644 --- a/tests/FPGAIntegrationTest.cpp +++ b/tests/FPGAIntegrationTest.cpp @@ -1160,7 +1160,7 @@ TEST_CASE("HLS_C_Simulation_internal_packet_generator_spot_finder_count_threshol test.SetInternalGeneratorFrame(frame); - test.SetSpotFinderParameters(9, 0.0); + test.SetSpotFinderParameters(10, 0.0); REQUIRE_NOTHROW(test.StartAction(x)); REQUIRE_NOTHROW(test.WaitForActionComplete()); @@ -1177,7 +1177,7 @@ TEST_CASE("HLS_C_Simulation_internal_packet_generator_spot_finder_count_threshol auto spot_finder_result = test.GetDeviceOutput(0, 0)->spot_finding_result; REQUIRE (spot_finder_result.strong_pixel_count == 3); REQUIRE (spot_finder_result.snr_threshold == 0); - REQUIRE (spot_finder_result.count_threshold == 9); + REQUIRE (spot_finder_result.count_threshold == 10); REQUIRE (spot_finder_result.strong_pixel[0] == (1<<0)); REQUIRE (spot_finder_result.strong_pixel[(123*1024 + 578) / 8] == (1<<2)); // 578 % 8 == 2 REQUIRE (spot_finder_result.strong_pixel[(121*1024 + 800) / 8] == (1<<0)); // 800 % 8 == 0