From 54bbcebba8f534a7caa77cb94a1a117914a551e7 Mon Sep 17 00:00:00 2001
From: Rolf Bork <rolf.bork@ligo.org>
Date: Fri, 12 Jan 2018 18:43:28 +0000
Subject: [PATCH] Added ability to compile FE code to produce DAQ buffers used
 by mx_stream or by zmq.

git-svn-id: https://redoubt.ligo-wa.caltech.edu/svn/advLigoRTS/trunk@4633 6dcd42c9-f523-4c6d-aada-af552506706e
---
 NEWS                        |  6 ++++--
 src/epics/util/feCodeGen.pl |  9 +++++++++
 src/fe/controllerApp.c      |  6 +++++-
 src/fe/controllerIop.c      | 10 +++++++---
 4 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/NEWS b/NEWS
index 5abd6d91e..43e8a4009 100644
--- a/NEWS
+++ b/NEWS
@@ -1,8 +1,10 @@
 ==================================================================================================
 Changes for 3.5  (NOT YET RELEASED)
 ==================================================================================================
-- daqLib.c and supporting components modified to send out GDS TP data via separate shared memory
-  area for use with new ZMQ DAQ transmission software.
+- daqLibZmq.c developed to send out GDS TP data via separate shared memory area for use with 
+  new ZMQ DAQ transmission software.
+  - This code is inserted if USE_ZMQ file exists in release/src/include directory. If not, then
+    build will default to using mx_stream version (daqLib.c).
 - RCG now builds user space code as well as kernel objects.
 - controller.c and moduleLoad.c now split into new files to clean out #defs:
 	- controllerIop.c and moduleLoadIop.c for IOP model builds.
diff --git a/src/epics/util/feCodeGen.pl b/src/epics/util/feCodeGen.pl
index ce1836156..bd97b8026 100755
--- a/src/epics/util/feCodeGen.pl
+++ b/src/epics/util/feCodeGen.pl
@@ -70,7 +70,13 @@ $currWorkDir = &Cwd::cwd();
 $rcg_src_dir = $ENV{"RCG_SRC_DIR"};
 $lrpciefile = $rcg_src_dir . "/src/include/USE_LR_PCIE";
 $pciegenfile = $rcg_src_dir . "/src/include/USE_DOLPHIN_GEN2";
+$zmqfile = $rcg_src_dir . "/src/include/USE_ZMQ";
+$usezmq = 0;
 
+if (-e "$zmqfile") {
+        print "Using ZMQ for DAQ\n";
+        $usezmq = 1;
+}
 if (-e "$lrpciefile") {
         print "PCIE LR exists\n";
         $rfm_via_pcie = 1;
@@ -2584,6 +2590,9 @@ if ($iopTimeSlave > -1) {
 if($rfm_via_pcie == 1) {
   print OUTM "EXTRA_CFLAGS += -DRFM_VIA_PCIE=1\n";
 }
+if($usezmq == 1) {
+  print OUTM "EXTRA_CFLAGS += -DUSE_ZMQ=1\n";
+}
 if ($rfmTimeSlave > -1) {
   print OUTM "EXTRA_CFLAGS += -DRFM_TIME_SLAVE=1\n";
 } else {
diff --git a/src/fe/controllerApp.c b/src/fe/controllerApp.c
index f1abc19ad..226f24c23 100644
--- a/src/fe/controllerApp.c
+++ b/src/fe/controllerApp.c
@@ -73,7 +73,11 @@ int printk(const char *fmt, ...) {
 
 #ifndef NO_DAQ
 #include "drv/fb.h"
-#include "drv/daqLib.c"		// DAQ/GDS connection software
+#ifdef USE_ZMQ
+	#include "drv/daqLibZmq.c"		// DAQ/GDS connection software
+#else
+	#include "drv/daqLib.c"		// DAQ/GDS connection software
+#endif
 #endif
 
 #include "drv/map.h"		// PCI hardware defs
diff --git a/src/fe/controllerIop.c b/src/fe/controllerIop.c
index b1073d464..b61f21292 100644
--- a/src/fe/controllerIop.c
+++ b/src/fe/controllerIop.c
@@ -74,7 +74,11 @@ int printk(const char *fmt, ...) {
 
 #ifndef NO_DAQ
 #include "drv/fb.h"
-#include "drv/daqLib.c"		// DAQ/GDS connection software
+#ifdef USE_ZMQ
+        #include "drv/daqLibZmq.c"              // DAQ/GDS connection software
+#else
+        #include "drv/daqLib.c"         // DAQ/GDS connection software
+#endif
 #endif
 
 #include "drv/map.h"		// PCI hardware defs
@@ -1127,7 +1131,7 @@ udelay(1000);
                                 if(cycleNum < 100) dac_out = limit / 20;
                                 else dac_out = 0;
                         }
-                        if((ii==0) && (jj == 6))
+                        if((ii==0) && (jj == 2))
                         {
                                 if(cycleNum < 100) dac_out = limit / 20;
                                 else dac_out = 0;
@@ -1647,7 +1651,7 @@ udelay(1000);
 	/// \> Compute code cycle time diag information.
 	cycleTime = (cpuClock[CPU_TIME_CYCLE_END] - cpuClock[CPU_TIME_CYCLE_START])/CPURATE;
 	if (longestWrite2 < ((tempClock[3]-tempClock[2])/CPURATE)) longestWrite2 = (tempClock[3]-tempClock[2])/CPURATE;
-	if(cycleTime > 20) printf("Long Cycle = at cycle %d\n",cycleTime,cycleNum); 
+	if(cycleTime > 20) printf("Long Cycle = %d at cycle %d\n",cycleTime,cycleNum); 
 	// Hold the max cycle time over the last 1 second
 	if(cycleTime > timeHold) { 
 		timeHold = cycleTime;
-- 
GitLab