From d6618c9429fb31adeb2f97870a0131deface9da3 Mon Sep 17 00:00:00 2001
From: Juliano Murari <juliano.murari@ess.eu>
Date: Thu, 12 May 2022 08:35:37 +0000
Subject: [PATCH] PBIBCM-209 Extend options of Trigger Source PVs

---
 sis8300bcmApp/Db/sis8300bcm-acct.template | 16 ++++++++++++
 sis8300bcmApp/Db/sis8300bcm.template      | 32 +++++++++++++++++++++++
 vendor/ess/lib/sis8300drvbcm.c            | 24 ++++++++---------
 3 files changed, 60 insertions(+), 12 deletions(-)

diff --git a/sis8300bcmApp/Db/sis8300bcm-acct.template b/sis8300bcmApp/Db/sis8300bcm-acct.template
index c93c3c6..9e62cd4 100644
--- a/sis8300bcmApp/Db/sis8300bcm-acct.template
+++ b/sis8300bcmApp/Db/sis8300bcm-acct.template
@@ -28,6 +28,14 @@ record(mbbo, "$(P)$(R)TriggerSource")
     field(FVST, "BackPlane3")
     field(SXVL, "6")
     field(SXST, "BackPlane4")
+    field(SVVL, "7")
+    field(SVST, "BackPlane5")
+    field(EIVL, "8")
+    field(EIST, "BackPlane6")
+    field(NIVL, "9")
+    field(NIST, "BackPlane7")
+    field(TEVL, "10")
+    field(TEST, "BackPlane8")
     field(PINI, "YES")
     field(VAL,  "3")
     field(ASG,  "critical")
@@ -53,6 +61,14 @@ record(mbbi, "$(P)$(R)TriggerSourceR")
     field(FVST, "BackPlane3")
     field(SXVL, "6")
     field(SXST, "BackPlane4")
+    field(SVVL, "7")
+    field(SVST, "BackPlane5")
+    field(EIVL, "8")
+    field(EIST, "BackPlane6")
+    field(NIVL, "9")
+    field(NIST, "BackPlane7")
+    field(TEVL, "10")
+    field(TEST, "BackPlane8")
 }
 
 record(ai, "$(P)$(R)PulseChargeR")
diff --git a/sis8300bcmApp/Db/sis8300bcm.template b/sis8300bcmApp/Db/sis8300bcm.template
index ac75caa..73f502f 100644
--- a/sis8300bcmApp/Db/sis8300bcm.template
+++ b/sis8300bcmApp/Db/sis8300bcm.template
@@ -24,6 +24,14 @@ record(mbbo, "$(P)$(R)AcquisitionTriggerSource")
     field(FVST, "BackPlane3")
     field(SXVL, "6")
     field(SXST, "BackPlane4")
+    field(SVVL, "7")
+    field(SVST, "BackPlane5")
+    field(EIVL, "8")
+    field(EIST, "BackPlane6")
+    field(NIVL, "9")
+    field(NIST, "BackPlane7")
+    field(TEVL, "10")
+    field(TEST, "BackPlane8")
     field(PINI, "YES")
     field(VAL,  "3")
     field(ASG,  "critical")
@@ -49,6 +57,14 @@ record(mbbi, "$(P)$(R)AcquisitionTriggerSourceR")
     field(FVST, "BackPlane3")
     field(SXVL, "6")
     field(SXST, "BackPlane4")
+    field(SVVL, "7")
+    field(SVST, "BackPlane5")
+    field(EIVL, "8")
+    field(EIST, "BackPlane6")
+    field(NIVL, "9")
+    field(NIST, "BackPlane7")
+    field(TEVL, "10")
+    field(TEST, "BackPlane8")
 }
 
 record(mbbo, "$(P)$(R)BeamTriggerSource")
@@ -69,6 +85,14 @@ record(mbbo, "$(P)$(R)BeamTriggerSource")
     field(FVST, "BackPlane3")
     field(SXVL, "6")
     field(SXST, "BackPlane4")
+    field(SVVL, "7")
+    field(SVST, "BackPlane5")
+    field(EIVL, "8")
+    field(EIST, "BackPlane6")
+    field(NIVL, "9")
+    field(NIST, "BackPlane7")
+    field(TEVL, "10")
+    field(TEST, "BackPlane8")
     field(PINI, "YES")
     field(VAL,  "3")
     field(ASG,  "critical")
@@ -94,6 +118,14 @@ record(mbbi, "$(P)$(R)BeamTriggerSourceR")
     field(FVST, "BackPlane3")
     field(SXVL, "6")
     field(SXST, "BackPlane4")
+    field(SVVL, "7")
+    field(SVST, "BackPlane5")
+    field(EIVL, "8")
+    field(EIST, "BackPlane6")
+    field(NIVL, "9")
+    field(NIST, "BackPlane7")
+    field(TEVL, "10")
+    field(TEST, "BackPlane8")
 }
 
 record(mbbo, "$(P)$(R)ClockSource")
diff --git a/vendor/ess/lib/sis8300drvbcm.c b/vendor/ess/lib/sis8300drvbcm.c
index 778c01f..8569b1a 100644
--- a/vendor/ess/lib/sis8300drvbcm.c
+++ b/vendor/ess/lib/sis8300drvbcm.c
@@ -70,40 +70,40 @@ void sis8300drvbcm_get_sampling_frequency(sis8300drv_usr *sisuser, double *frequ
 // used to control trigger selection for beam start
 int sis8300drvbcm_set_beam_trigger_source(sis8300drv_usr *sisuser, unsigned int source)
 {
-    // register takes 3-bit unsigned value
-    unsigned int value = source & 0x7;
+    // register takes 4-bit unsigned value
+    unsigned int value = source & 0xF;
     int ret = sis8300drv_reg_write(sisuser, SIS8300BCM_BEAM_TRIGGER_SOURCE_REG, value);
     return ret;
 }
 
 int sis8300drvbcm_get_beam_trigger_source(sis8300drv_usr *sisuser, unsigned int *source)
 {
-    // register provides 3-bit unsigned value
+    // register provides 4-bit unsigned value
     int ret = sis8300drv_reg_read(sisuser, SIS8300BCM_BEAM_TRIGGER_SOURCE_REG, source);
     if (ret) {
         return ret;
     }
-    *source &= 0x7;
+    *source &= 0xF;
     return ret;
 }
 
 // used to control trigger selection for data acquisition
 int sis8300drvbcm_set_acquisition_trigger_source(sis8300drv_usr *sisuser, unsigned int source)
 {
-    // register takes 3-bit unsigned value
-    unsigned int value = source & 0x7;
+    // register takes 4-bit unsigned value
+    unsigned int value = source & 0xF;
     int ret = sis8300drv_reg_write(sisuser, SIS8300BCM_ACQUITISION_TRIGGER_SOURCE_REG, value);
     return ret;
 }
 
 int sis8300drvbcm_get_acquisition_trigger_source(sis8300drv_usr *sisuser, unsigned int *source)
 {
-    // register provides 3-bit unsigned value
+    // register provides 4-bit unsigned value
     int ret = sis8300drv_reg_read(sisuser, SIS8300BCM_ACQUITISION_TRIGGER_SOURCE_REG, source);
     if (ret) {
         return ret;
     }
-    *source &= 0x7;
+    *source &= 0xF;
     return ret;
 }
 
@@ -148,8 +148,8 @@ int sis8300drvbcm_set_channel_trigger_source(sis8300drv_usr *sisuser, unsigned i
                         (SIS8300BCM_CHANNEL_BLOCK_SIZE * channel) + \
                         SIS8300BCM_ACCT_BANK_OFF + \
                         SIS8300BCM_ACCT_X_TRIGGER_SOURCE_OFF;
-    // register takes 3-bit unsigned value
-    unsigned int value = source & 0x7;
+    // register takes 4-bit unsigned value
+    unsigned int value = source & 0xF;
     int ret = sis8300drv_reg_write(sisuser, reg, value);
     return ret;
 }
@@ -160,12 +160,12 @@ int sis8300drvbcm_get_channel_trigger_source(sis8300drv_usr *sisuser, unsigned i
                         (SIS8300BCM_CHANNEL_BLOCK_SIZE * channel) + \
                         SIS8300BCM_ACCT_BANK_OFF + \
                         SIS8300BCM_ACCT_X_TRIGGER_SOURCE_OFF;
-    // register provides 3-bit unsigned value
+    // register provides 4-bit unsigned value
     int ret = sis8300drv_reg_read(sisuser, reg, source);
     if (ret) {
         return ret;
     }
-    *source &= 0x7;
+    *source &= 0xF;
     return ret;
 }
 
-- 
GitLab