From 821898e4fce66f646cb8c3007f05ea4ded08bbd3 Mon Sep 17 00:00:00 2001 From: Jin Huang Date: Tue, 16 May 2023 16:44:36 -0400 Subject: [PATCH 1/3] add support of multiple FELIX devices --- dam_plugin.cc | 15 +++++++++++++++ daq_device_dam.cc | 8 +++++--- daq_device_dam.h | 8 +++++--- pl_lib.c | 4 ++-- pl_lib.h | 3 +-- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/dam_plugin.cc b/dam_plugin.cc index 5658341..c0c4a3c 100644 --- a/dam_plugin.cc +++ b/dam_plugin.cc @@ -65,6 +65,21 @@ int dam_plugin::create_device(deviceblock *db) npackets)); return 0; // say "we handled this request" } + else if ( db->npar == 7) + { + int trigger = get_value ( db->argv3); + int nunits = get_value ( db->argv4); + int npackets = get_value ( db->argv5); + std::string devName = ( db->argv6); + + add_readoutdevice ( new daq_device_dam( eventtype, + subid, + trigger, + nunits, + npackets, + devName)); + return 0; // say "we handled this request" + } else { diff --git a/daq_device_dam.cc b/daq_device_dam.cc index 5ce6029..cc27a5b 100644 --- a/daq_device_dam.cc +++ b/daq_device_dam.cc @@ -29,6 +29,7 @@ daq_device_dam::daq_device_dam(const int eventtype , const int trigger , const int nunits , const int npackets + , const std::string & damDevName ) { @@ -39,6 +40,7 @@ daq_device_dam::daq_device_dam(const int eventtype _nunits = nunits; // how much we cram into one packet _npackets = npackets; // how many packet we make _broken = 0; + m_deviceName = damDevName; if ( _nunits <= 0) _nunits = 1; if ( _npackets <= 0) _npackets = 1; @@ -89,7 +91,7 @@ int daq_device_dam::init() } _broken = 0; - pl_open(&_dam_fd); + pl_open(&_dam_fd, m_deviceName.c_str()); if ( _dam_fd < 0) { @@ -199,7 +201,7 @@ void daq_device_dam::identify(std::ostream& os) const { if ( _broken) { - os << "FELIX DAM Card Event Type: " << m_eventType + os << "FELIX DAM Card "< #include #include +#include class Fee; @@ -17,7 +18,9 @@ class daq_device_dam: public daq_device { , const int subeventid , const int trigger = 1 , const int nunits=1 - , const int npackets=1); + , const int npackets=1 + , const std::string & damDevName = "/dev/dam0" + ); ~daq_device_dam(); @@ -35,7 +38,6 @@ class daq_device_dam: public daq_device { int rearm( const int etype); int endrun(); - protected: @@ -51,7 +53,7 @@ class daq_device_dam: public daq_device { damTriggerHandler *_th; - + std::string m_deviceName; }; diff --git a/pl_lib.c b/pl_lib.c index 0c1d191..6f2cc68 100755 --- a/pl_lib.c +++ b/pl_lib.c @@ -44,8 +44,8 @@ int dam_wait_for_dma(int fd, int *data) return 0; } -int pl_open(int *fd) { - if ( (*fd = open(DEVNAME, O_RDWR)) <= 0 ) { +int pl_open(int *fd, const char * dev_name) { + if ( (*fd = open(dev_name, O_RDWR)) <= 0 ) { perror(__func__); return -1; } diff --git a/pl_lib.h b/pl_lib.h index 0496c21..923a258 100755 --- a/pl_lib.h +++ b/pl_lib.h @@ -7,10 +7,9 @@ extern "C" { #include "dam_ioctl.h" -#define DEVNAME "/dev/dam0" #define PAGE_SIZE 4096 -int pl_open(int *fd); +int pl_open(int *fd, const char * dev_name); int pl_close(int fd); uint32_t pl_register_read(int fd, uint32_t addr); int pl_register_write(int fd, uint32_t addr, uint32_t data); From 80b39a6dfc082660475d34dfea20f91cf737fb63 Mon Sep 17 00:00:00 2001 From: Jin Huang Date: Tue, 16 May 2023 16:45:25 -0400 Subject: [PATCH 2/3] git ignore for autotool --- .gitignore | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ef9f2bb --- /dev/null +++ b/.gitignore @@ -0,0 +1,91 @@ +# http://www.gnu.org/software/automake + +Makefile.in + +# http://www.gnu.org/software/autoconf + +autom4te.cache +aclocal.m4 +compile +configure +depcomp +install-sh +missing +stamp-h1 + +config.guess +config.sub +ltmain.sh + +build +*.json + +# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore: +# +# * Create a file at ~/.gitignore +# * Include files you want ignored +# * Run: git config --global core.excludesfile ~/.gitignore +# +# After doing this, these files will be ignored in all your git projects, +# saving you from having to 'pollute' every project you touch with them +# +# For MacOS: +# +.DS_Store + +# ignore RVM configuration +.rvmrc + +# For TextMate +*.tmproj +tmtags + +# For emacs: +*~ +\#* +.\#* + +# For vim: +*.swp + +# For redcar: +.redcar + +# For rubinius: +*.rbc + +# standard C++ Git igore + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib +*.pcm +*_Dict.cc +*.status + +# Executables +*.exe +*.out +*.app +/.cproject +/.project \ No newline at end of file From 1cd81851f1533d1ab748724ea187729371770dfd Mon Sep 17 00:00:00 2001 From: Jin Huang Date: Mon, 22 May 2023 23:56:59 -0400 Subject: [PATCH 3/3] Fixing mismatched data length --- daq_device_dam.cc | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/daq_device_dam.cc b/daq_device_dam.cc index cc27a5b..1eeaacc 100644 --- a/daq_device_dam.cc +++ b/daq_device_dam.cc @@ -11,7 +11,9 @@ #include "pl_lib.h" //#include "fee_reg.h" -#define DATA_LENGTH 137*256 // 137 words * 256 channels +// DAM transmit 256 bit word. +// This byte-unit length is just and large chunk of multiple of 256 bits +#define DATA_LENGTH 256*256 #define FEE_SAMPA_CTRL 0x5 #define DAM_DMA_FIFO 0x5 #define DAM_DMA_CTRL 0x4004 @@ -177,20 +179,19 @@ int daq_device_dam::put_data(const int etype, int * adr, const int length ) sevt->reserved[0] = 0; sevt->reserved[1] = 0; + // DAM IO uses unistd read(), which operates on the byte length units + uint8_t *dest = (uint8_t *) &sevt->data; - uint16_t *dest = (uint16_t *) &sevt->data; + ssize_t c = read(_dam_fd, dest, _length); + // cout << __LINE__ << " " << __FILE__ << " read " << c << " bytes " << endl; - int ret; - - ret = read(_dam_fd, dest, _length); + // padding to 8 bytes + sevt->sub_padding = c%8; + if ( sevt->sub_padding) sevt->sub_padding = 8 - sevt->sub_padding; + + sevt->sub_length += (c + sevt->sub_padding) /4; + // cout << __LINE__ << " " << __FILE__ << " sevt->sub_padding = " << sevt->sub_padding << " return add " << (c + sevt->sub_padding) /4 << endl; - //cout << __LINE__ << " " << __FILE__ << " read " << ret << " words " << endl; - - // sevt->sub_padding = ret%2 ; - sevt->sub_padding = 0; // we can never have an odd number of uint16s - - sevt->sub_length += (ret + sevt->sub_padding); - // cout << __LINE__ << " " << __FILE__ << " returning " << sevt->sub_length << endl; overall_length += sevt->sub_length; } return overall_length;