diff --git a/common/Definitions.h b/common/Definitions.h index 84ac7877..31af5c02 100644 --- a/common/Definitions.h +++ b/common/Definitions.h @@ -103,6 +103,9 @@ #define ADDR_NFRAMES 0x0098 #define ADDR_NSTORAGE_CELLS 0x009C +#define ADDR_SPOT_FINDER_THRESHOLD 0x0100 +#define ADDR_SPOT_FINDER_SNR 0x0104 + #define ADDR_MAILBOX_WRDATA 0x00 #define ADDR_MAILBOX_RDDATA 0x08 #define ADDR_MAILBOX_STATUS 0x10 diff --git a/fpga/host_library/JungfraujochDevice.cpp b/fpga/host_library/JungfraujochDevice.cpp index 919e7bdb..483e6b18 100644 --- a/fpga/host_library/JungfraujochDevice.cpp +++ b/fpga/host_library/JungfraujochDevice.cpp @@ -204,3 +204,8 @@ uint16_t *JungfraujochDevice::MapKernelBuffer(uint32_t id) { return tmp; } + +void JungfraujochDevice::SetSpotFinderParameters(const SpotFinderParameters& params) { + if (ioctl(fd, IOCTL_JFJOCH_SPOT_FINDER_PAR, ¶ms) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed settings spot finder parameters", errno); +} diff --git a/fpga/host_library/JungfraujochDevice.h b/fpga/host_library/JungfraujochDevice.h index 5c7cf149..bd9b38bb 100644 --- a/fpga/host_library/JungfraujochDevice.h +++ b/fpga/host_library/JungfraujochDevice.h @@ -87,6 +87,8 @@ public: // Must be placed in first kernel buffer locations void LoadIntegrationMap(uint32_t modules); + void SetSpotFinderParameters(const SpotFinderParameters ¶ms); + // Get number of kernel buffers uint32_t GetBufferCount() const; // Allocate id kernel buffer ( id must be less than GetBufferCount() ) diff --git a/fpga/pcie_driver/ActionConfig.h b/fpga/pcie_driver/ActionConfig.h index ccc1f4c6..c676d4eb 100644 --- a/fpga/pcie_driver/ActionConfig.h +++ b/fpga/pcie_driver/ActionConfig.h @@ -84,6 +84,10 @@ struct RegisterConfig { uint32_t val; }; +struct SpotFinderParameters { + int16_t count_threshold; + uint16_t snr_threshold; +}; #pragma pack(pop) #endif //JUNGFRAUJOCH_ACTIONCONFIG_H diff --git a/fpga/pcie_driver/jfjoch_drv.h b/fpga/pcie_driver/jfjoch_drv.h index 78e79fcf..5582089c 100644 --- a/fpga/pcie_driver/jfjoch_drv.h +++ b/fpga/pcie_driver/jfjoch_drv.h @@ -127,6 +127,7 @@ int jfjoch_load_calibration(struct jfjoch_drvdata *drvdata, struct DataCollectio int jfjoch_load_integration_map(struct jfjoch_drvdata *drvdata, struct DataCollectionConfig *config); int jfjoch_run_frame_gen(struct jfjoch_drvdata *drvdata, struct FrameGeneratorConfig *config); u32 jfjoch_get_c2h_descriptors(struct jfjoch_drvdata *drvdata); +void jfjoch_set_spot_finder_parameters(struct jfjoch_drvdata *drvdata, struct SpotFinderParameters *params); u64 jfjoch_read_mac_addr(struct jfjoch_drvdata *drvdata); diff --git a/fpga/pcie_driver/jfjoch_function.c b/fpga/pcie_driver/jfjoch_function.c index cc62a56c..5da4b956 100644 --- a/fpga/pcie_driver/jfjoch_function.c +++ b/fpga/pcie_driver/jfjoch_function.c @@ -446,3 +446,8 @@ int jfjoch_run_frame_gen(struct jfjoch_drvdata *drvdata, struct FrameGeneratorCo u32 jfjoch_get_c2h_descriptors(struct jfjoch_drvdata *drvdata) { return ioread32(drvdata->bar0 + PCIE_OFFSET + (1<<12) + 0x48); } + +void jfjoch_set_spot_finder_parameters(struct jfjoch_drvdata *drvdata, struct SpotFinderParameters *params) { + iowrite32(params->count_threshold, drvdata->bar0 + ADDR_SPOT_FINDER_THRESHOLD); + iowrite32(params->snr_threshold, drvdata->bar0 + ADDR_SPOT_FINDER_SNR); +} \ No newline at end of file diff --git a/fpga/pcie_driver/jfjoch_ioctl.c b/fpga/pcie_driver/jfjoch_ioctl.c index 4b1d5e99..02a92076 100644 --- a/fpga/pcie_driver/jfjoch_ioctl.c +++ b/fpga/pcie_driver/jfjoch_ioctl.c @@ -10,6 +10,7 @@ long jfjoch_cdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct DeviceStatus env_params; struct FrameGeneratorConfig frame_generator_config; struct RegisterConfig reg_config; + struct SpotFinderParameters spot_finder_parameters; u32 exchange[16]; int err; @@ -107,6 +108,13 @@ long jfjoch_cdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { if (copy_to_user((char *) arg, exchange, sizeof(u32)) != 0) return -EFAULT; return 0; + case IOCTL_JFJOCH_SPOT_FINDER_PAR: + if (!(file->f_mode & FMODE_WRITE)) + return -EACCES; + if (copy_from_user(&spot_finder_parameters, (char *) arg, sizeof(struct SpotFinderParameters)) != 0) + return -EFAULT; + jfjoch_set_spot_finder_parameters(drvdata, &spot_finder_parameters); + return 0; case IOCTL_JFJOCH_ISIDLE: jfjoch_is_idle(drvdata, exchange); if (copy_to_user((char *) arg, exchange, sizeof(int32_t)) != 0) diff --git a/fpga/pcie_driver/jfjoch_ioctl.h b/fpga/pcie_driver/jfjoch_ioctl.h index 33595be1..f86bb2d4 100644 --- a/fpga/pcie_driver/jfjoch_ioctl.h +++ b/fpga/pcie_driver/jfjoch_ioctl.h @@ -39,5 +39,6 @@ #define IOCTL_JFJOCH_C2H_DMA_DESC _IOR(IOCTL_JFJOCH_MAGIC, 24, uint32_t) #define IOCTL_JFJOCH_WRITE_REGISTER _IOW(IOCTL_JFJOCH_MAGIC, 25, struct RegisterConfig ) #define IOCTL_JFJOCH_READ_REGISTER _IOWR(IOCTL_JFJOCH_MAGIC, 26, struct RegisterConfig ) +#define IOCTL_JFJOCH_SPOT_FINDER_PAR _IOW(IOCTL_JFJOCH_MAGIC, 27, struct SpotFinderParameters) #endif //JUNGFRAUJOCH_JFJOCH_IOCTL_H diff --git a/receiver/AcquisitionDevice.h b/receiver/AcquisitionDevice.h index 6ef62f0d..12cf9e86 100644 --- a/receiver/AcquisitionDevice.h +++ b/receiver/AcquisitionDevice.h @@ -110,6 +110,7 @@ public: virtual void InitializeIntegrationMap(const DiffractionExperiment &experiment, const std::vector &v); const AcquisitionCounters& Counters() const; + virtual void SetSpotFinderParameters(int16_t count_threshold, double snr_threshold) {}; virtual std::string GetIPv4Address() const; virtual std::string GetMACAddress() const; virtual uint16_t GetUDPPort() const; diff --git a/receiver/FPGAAcquisitionDevice.cpp b/receiver/FPGAAcquisitionDevice.cpp index c6ea267a..dbe7be2d 100644 --- a/receiver/FPGAAcquisitionDevice.cpp +++ b/receiver/FPGAAcquisitionDevice.cpp @@ -3,6 +3,7 @@ #include "FPGAAcquisitionDevice.h" #include #include +#include "../common/to_fixed.h" void FPGAAcquisitionDevice::StartSendingWorkRequests() { stop_work_requests = false; @@ -317,3 +318,16 @@ FPGAAcquisitionDevice::FPGAAcquisitionDevice(uint16_t data_stream) internal_pkt_gen_frame(RAW_MODULE_SIZE * FRAME_GENERATOR_MODULES) { } +void FPGAAcquisitionDevice::SetSpotFinderParameters(int16_t count_threshold, double snr_threshold) { + if (snr_threshold < 0) { + if (logger) + logger->Warning("Trying to set SNR threshold below zero: {}", snr_threshold ); + snr_threshold = 0; + } else if (snr_threshold > 64) { + if (logger) + logger->Warning("Trying to set SNR threshold too high: {}", snr_threshold ); + snr_threshold = 64; + } + SpotFinderParameters params{.count_threshold = count_threshold, .snr_threshold = to_fixed(snr_threshold, 4)}; + HW_SetSpotFinderParameters(params); +} diff --git a/receiver/FPGAAcquisitionDevice.h b/receiver/FPGAAcquisitionDevice.h index f37ffcb9..08434168 100644 --- a/receiver/FPGAAcquisitionDevice.h +++ b/receiver/FPGAAcquisitionDevice.h @@ -31,6 +31,7 @@ class FPGAAcquisitionDevice : public AcquisitionDevice { virtual void HW_LoadInternalGeneratorFrame(uint32_t modules) = 0; virtual bool HW_ReadMailbox(uint32_t values[16]) = 0; virtual bool HW_SendWorkRequest(uint32_t handle) = 0; + virtual void HW_SetSpotFinderParameters(const SpotFinderParameters ¶ms) = 0; void StartSendingWorkRequests() override; void Start(const DiffractionExperiment &experiment) override; protected: @@ -48,6 +49,7 @@ public: void SetInternalGeneratorFrame(const std::vector &v); void SetInternalGeneratorFrame(); std::vector GetInternalGeneratorFrame() const override; + void SetSpotFinderParameters(int16_t count_threshold, double snr_threshold) override; }; #endif //JUNGFRAUJOCH_FPGAACQUISITIONDEVICE_H diff --git a/receiver/HLSSimulatedDevice.cpp b/receiver/HLSSimulatedDevice.cpp index f9b4159a..4a775254 100644 --- a/receiver/HLSSimulatedDevice.cpp +++ b/receiver/HLSSimulatedDevice.cpp @@ -348,14 +348,10 @@ void HLSSimulatedDevice::HLSMainThread() { hbm_if_size); }); - ap_int<16> photon_count_threshold = 5; - ap_uint<16> strong_pixel_threshold = 7; + // 6. Spot finding - hls_cores.emplace_back([&] { spot_finder(converted_5, converted_6, - spot_finder_result_0, - photon_count_threshold, - strong_pixel_threshold);}); + hls_cores.emplace_back([&] { spot_finder(converted_5, converted_6, spot_finder_result_0, count_threshold, snr_threshold);}); hls_cores.emplace_back([&] { axis_32_to_512(spot_finder_result_0, spot_finder_result_1);}); @@ -553,4 +549,9 @@ void HLSSimulatedDevice::HW_LoadInternalGeneratorFrame(uint32_t modules) { uint32_t HLSSimulatedDevice::GetCompletedDescriptors() const { return datamover_out.GetCompletedDescriptors(); -} \ No newline at end of file +} + +void HLSSimulatedDevice::HW_SetSpotFinderParameters(const SpotFinderParameters ¶ms) { + count_threshold = params.count_threshold; + snr_threshold = params.snr_threshold; +} diff --git a/receiver/HLSSimulatedDevice.h b/receiver/HLSSimulatedDevice.h index 031af184..355e34c9 100644 --- a/receiver/HLSSimulatedDevice.h +++ b/receiver/HLSSimulatedDevice.h @@ -18,6 +18,9 @@ class HLSSimulatedDevice : public FPGAAcquisitionDevice { AXI_STREAM din_frame_generator; AXI_STREAM dout_eth; + ap_int<16> count_threshold = INT16_MAX; + ap_uint<16> snr_threshold = 0; + DataCollectionConfig cfg; volatile bool idle; @@ -55,8 +58,8 @@ class HLSSimulatedDevice : public FPGAAcquisitionDevice { void HW_LoadIntegrationMap(uint32_t modules) override; void HW_LoadInternalGeneratorFrame(uint32_t modules) override; void HW_GetStatus(DataCollectionStatus *status) const override; + void HW_SetSpotFinderParameters(const SpotFinderParameters ¶ms) override; void HLSMainThread() ; - void RunFrameGenerator(const FrameGeneratorConfig& config); public: HLSSimulatedDevice(uint16_t data_stream, size_t in_frame_buffer_size_modules, int16_t numa_node = -1); ~HLSSimulatedDevice(); diff --git a/receiver/PCIExpressDevice.cpp b/receiver/PCIExpressDevice.cpp index fe5672b0..f604b29a 100644 --- a/receiver/PCIExpressDevice.cpp +++ b/receiver/PCIExpressDevice.cpp @@ -127,3 +127,6 @@ void PCIExpressDevice::HW_LoadInternalGeneratorFrame(uint32_t in_modules) { dev.LoadInternalGeneratorFrame(in_modules); } +void PCIExpressDevice::HW_SetSpotFinderParameters(const SpotFinderParameters ¶ms) { + dev.SetSpotFinderParameters(params); +} diff --git a/receiver/PCIExpressDevice.h b/receiver/PCIExpressDevice.h index 8545e722..b0ae6a01 100644 --- a/receiver/PCIExpressDevice.h +++ b/receiver/PCIExpressDevice.h @@ -18,6 +18,7 @@ class PCIExpressDevice : public FPGAAcquisitionDevice { void HW_LoadCalibration(uint32_t modules, uint32_t storage_cells) override; void HW_LoadIntegrationMap(uint32_t modules) override; void HW_LoadInternalGeneratorFrame(uint32_t modules) override; + void HW_SetSpotFinderParameters(const SpotFinderParameters ¶ms) override; void FPGA_EndAction() override; public: explicit PCIExpressDevice(uint16_t data_stream);