From 39cf7170aaf766dc6866442d14cfab8e3d785b61 Mon Sep 17 00:00:00 2001 From: Zan Pratnemer Date: Thu, 6 Oct 2022 13:56:48 +0200 Subject: [PATCH 1/2] Add prescaler trigger for pulsers --- evrApp/Db/evrpulser.db | 21 +++++++++++++++++++++ evrApp/src/evr.cpp | 2 ++ evrApp/src/evr/pulser.h | 7 +++++++ evrFRIBApp/src/evr_frib.h | 3 +++ evrMrmApp/src/drvemPulser.cpp | 27 +++++++++++++++++++++++++++ evrMrmApp/src/drvemPulser.h | 3 +++ evrMrmApp/src/evrRegMap.h | 5 +++-- 7 files changed, 66 insertions(+), 2 deletions(-) diff --git a/evrApp/Db/evrpulser.db b/evrApp/Db/evrpulser.db index 1c806638..e078af63 100644 --- a/evrApp/Db/evrpulser.db +++ b/evrApp/Db/evrpulser.db @@ -178,3 +178,24 @@ record(waveform, "$(PN)Label-I") { field(NELM, "128") info(autosaveFields_pass1, "VAL") } + +# Triger pulser generator by one or more prescalers +record(mbboDirect, "$(PN)PSTrig-Sel") +{ + field(DTYP, "Obj Prop uint32") + field(OUT , "@OBJ=$(OBJ), PROP=PSTrig") + field(PINI, "YES") + field(NOBT, "8") + field(VAL , "0") + field(FLNK, "$(PN)PSTrig-RB") + info(autosaveFields_pass0, "RVAL") +} + +record(mbbiDirect, "$(PN)PSTrig-RB") +{ + field(DTYP, "Obj Prop uint32") + field(INP , "@OBJ=$(OBJ), PROP=PSTrig") + field(PINI, "YES") + field(NOBT, "8") + info(autosaveFields_pass0, "RVAL") +} diff --git a/evrApp/src/evr.cpp b/evrApp/src/evr.cpp index 006b1489..22e6c121 100644 --- a/evrApp/src/evr.cpp +++ b/evrApp/src/evr.cpp @@ -201,6 +201,8 @@ OBJECT_BEGIN(Pulser) { OBJECT_PROP2("Prescaler", &Pulser::prescaler, &Pulser::setPrescaler); + OBJECT_PROP2("PSTrig", &Pulser::psTrig, &Pulser::setPSTrig); + } OBJECT_END(Pulser) diff --git a/evrApp/src/evr/pulser.h b/evrApp/src/evr/pulser.h index 1486b442..998ea60f 100644 --- a/evrApp/src/evr/pulser.h +++ b/evrApp/src/evr/pulser.h @@ -85,6 +85,13 @@ class epicsShareClass Pulser : public mrf::ObjectInst virtual void setPrescaler(epicsUInt32)=0; /*@}*/ + /**\defgroup scaler Set prescaler triggering + */ + /*@{*/ + virtual epicsUInt32 psTrig() const=0; + virtual void setPSTrig(epicsUInt32)=0; + /*@}*/ + /**\defgroup pol Set output polarity * * Selects normal or inverted. diff --git a/evrFRIBApp/src/evr_frib.h b/evrFRIBApp/src/evr_frib.h index cc34c36d..15b8e733 100644 --- a/evrFRIBApp/src/evr_frib.h +++ b/evrFRIBApp/src/evr_frib.h @@ -78,6 +78,9 @@ struct PulserFRIB : public Pulser virtual epicsUInt32 prescaler() const { return 1u; } virtual void setPrescaler(epicsUInt32) {} + virtual epicsUInt32 psTrig() const { return 0u; } + virtual void setPSTrig(epicsUInt32) {} + virtual bool polarityInvert() const { return false; } virtual void setPolarityInvert(bool) {} diff --git a/evrMrmApp/src/drvemPulser.cpp b/evrMrmApp/src/drvemPulser.cpp index 056a2f6c..25ec33eb 100644 --- a/evrMrmApp/src/drvemPulser.cpp +++ b/evrMrmApp/src/drvemPulser.cpp @@ -151,6 +151,33 @@ MRMPulser::setPrescaler(epicsUInt32 v) WRITE32(owner.base, PulserScal(id), v); } +epicsUInt32 +MRMPulser::psTrig() const +{ + epicsUInt32 r = 0; + for (int i = 0; i < ScalerMax; i++) { + if (READ32(owner.base, ScalerPulsTrig(i)) & (1 << id)) { + r |= 1 << i; + } + } + + return r; +} + +void +MRMPulser::setPSTrig(epicsUInt32 v) +{ + for (int i = 0; i < ScalerMax; i++) { + epicsUInt32 t = READ32(owner.base, ScalerPulsTrig(i)); + if (v & (1 << i)) { + t |= 1 << id; + } else { + t &= ~(1 << id); + } + WRITE32(owner.base, ScalerPulsTrig(i), t); + } +} + bool MRMPulser::polarityInvert() const { diff --git a/evrMrmApp/src/drvemPulser.h b/evrMrmApp/src/drvemPulser.h index adf09ece..0e15a3a8 100644 --- a/evrMrmApp/src/drvemPulser.h +++ b/evrMrmApp/src/drvemPulser.h @@ -50,6 +50,9 @@ class MRMPulser : public mrf::ObjectInst virtual epicsUInt32 prescaler() const OVERRIDE FINAL; virtual void setPrescaler(epicsUInt32) OVERRIDE FINAL; + virtual epicsUInt32 psTrig() const OVERRIDE FINAL; + virtual void setPSTrig(epicsUInt32) OVERRIDE FINAL; + virtual bool polarityInvert() const OVERRIDE FINAL; virtual void setPolarityInvert(bool) OVERRIDE FINAL; diff --git a/evrMrmApp/src/evrRegMap.h b/evrMrmApp/src/evrRegMap.h index c67d44ec..b69bfe37 100755 --- a/evrMrmApp/src/evrRegMap.h +++ b/evrMrmApp/src/evrRegMap.h @@ -190,10 +190,11 @@ #define U32_ScalerN 0x100 -# define ScalerMax 3 -/* 0 <= N <= 2 */ +# define ScalerMax 8 +/* 0 <= N <= 7 */ #define U32_Scaler(N) (U32_ScalerN + (4*(N))) # define ScalerPhasOffs_offset 0x20 +#define U32_ScalerPulsTrig(N) (U32_ScalerN + 0x40 + (4*(N))) #define U32_PulserNCtrl 0x200 #define U32_PulserNScal 0x204 From fd0855e101223a20e5cda14a06978f5bd22ecce6 Mon Sep 17 00:00:00 2001 From: Zan Pratnemer Date: Fri, 7 Oct 2022 13:15:30 +0200 Subject: [PATCH 2/2] Add DBus bit trig for pulsers --- evrApp/Db/evrpulser.db | 21 +++++++++++++++++++++ evrApp/src/evr.cpp | 2 ++ evrApp/src/evr/pulser.h | 7 +++++++ evrFRIBApp/src/evr_frib.h | 3 +++ evrMrmApp/src/drvemPulser.cpp | 27 +++++++++++++++++++++++++++ evrMrmApp/src/drvemPulser.h | 3 +++ evrMrmApp/src/evrRegMap.h | 5 +++++ 7 files changed, 68 insertions(+) diff --git a/evrApp/Db/evrpulser.db b/evrApp/Db/evrpulser.db index e078af63..e40a1b9f 100644 --- a/evrApp/Db/evrpulser.db +++ b/evrApp/Db/evrpulser.db @@ -199,3 +199,24 @@ record(mbbiDirect, "$(PN)PSTrig-RB") field(NOBT, "8") info(autosaveFields_pass0, "RVAL") } + +# Trigger pulser generator by one or more DBus bits +record(mbboDirect, "$(PN)DBusTrig-Sel") +{ + field(DTYP, "Obj Prop uint32") + field(OUT , "@OBJ=$(OBJ), PROP=DBusTrig") + field(PINI, "YES") + field(NOBT, "8") + field(VAL , "0") + field(FLNK, "$(PN)DBusTrig-RB") + info(autosaveFields_pass0, "RVAL") +} + +record(mbbiDirect, "$(PN)DBusTrig-RB") +{ + field(DTYP, "Obj Prop uint32") + field(INP , "@OBJ=$(OBJ), PROP=DBusTrig") + field(PINI, "YES") + field(NOBT, "8") + info(autosaveFields_pass0, "RVAL") +} diff --git a/evrApp/src/evr.cpp b/evrApp/src/evr.cpp index 22e6c121..fb92600a 100644 --- a/evrApp/src/evr.cpp +++ b/evrApp/src/evr.cpp @@ -203,6 +203,8 @@ OBJECT_BEGIN(Pulser) { OBJECT_PROP2("PSTrig", &Pulser::psTrig, &Pulser::setPSTrig); + OBJECT_PROP2("DBusTrig", &Pulser::dbusTrig, &Pulser::setDBusTrig); + } OBJECT_END(Pulser) diff --git a/evrApp/src/evr/pulser.h b/evrApp/src/evr/pulser.h index 998ea60f..9cec80e7 100644 --- a/evrApp/src/evr/pulser.h +++ b/evrApp/src/evr/pulser.h @@ -92,6 +92,13 @@ class epicsShareClass Pulser : public mrf::ObjectInst virtual void setPSTrig(epicsUInt32)=0; /*@}*/ + /**\defgroup DBus Set DBus triggering + */ + /*@{*/ + virtual epicsUInt32 dbusTrig() const=0; + virtual void setDBusTrig(epicsUInt32)=0; + /*@}*/ + /**\defgroup pol Set output polarity * * Selects normal or inverted. diff --git a/evrFRIBApp/src/evr_frib.h b/evrFRIBApp/src/evr_frib.h index 15b8e733..88d759ad 100644 --- a/evrFRIBApp/src/evr_frib.h +++ b/evrFRIBApp/src/evr_frib.h @@ -81,6 +81,9 @@ struct PulserFRIB : public Pulser virtual epicsUInt32 psTrig() const { return 0u; } virtual void setPSTrig(epicsUInt32) {} + virtual epicsUInt32 dbusTrig() const { return 0u; } + virtual void setDBusTrig(epicsUInt32) {} + virtual bool polarityInvert() const { return false; } virtual void setPolarityInvert(bool) {} diff --git a/evrMrmApp/src/drvemPulser.cpp b/evrMrmApp/src/drvemPulser.cpp index 25ec33eb..ef72c408 100644 --- a/evrMrmApp/src/drvemPulser.cpp +++ b/evrMrmApp/src/drvemPulser.cpp @@ -178,6 +178,33 @@ MRMPulser::setPSTrig(epicsUInt32 v) } } +epicsUInt32 +MRMPulser::dbusTrig() const +{ + epicsUInt32 r = 0; + for (int i = 0; i < evrNumDbusBit; i++) { + if (READ32(owner.base, DBusPulsTrig(i)) & (1 << id)) { + r |= 1 << i; + } + } + + return r; +} + +void +MRMPulser::setDBusTrig(epicsUInt32 v) +{ + for (int i = 0; i < evrNumDbusBit; i++) { + epicsUInt32 t = READ32(owner.base, DBusPulsTrig(i)); + if (v & (1 << i)) { + t |= 1 << id; + } else { + t &= ~(1 << id); + } + WRITE32(owner.base, DBusPulsTrig(i), t); + } +} + bool MRMPulser::polarityInvert() const { diff --git a/evrMrmApp/src/drvemPulser.h b/evrMrmApp/src/drvemPulser.h index 0e15a3a8..1dd7ab01 100644 --- a/evrMrmApp/src/drvemPulser.h +++ b/evrMrmApp/src/drvemPulser.h @@ -53,6 +53,9 @@ class MRMPulser : public mrf::ObjectInst virtual epicsUInt32 psTrig() const OVERRIDE FINAL; virtual void setPSTrig(epicsUInt32) OVERRIDE FINAL; + virtual epicsUInt32 dbusTrig() const OVERRIDE FINAL; + virtual void setDBusTrig(epicsUInt32) OVERRIDE FINAL; + virtual bool polarityInvert() const OVERRIDE FINAL; virtual void setPolarityInvert(bool) OVERRIDE FINAL; diff --git a/evrMrmApp/src/evrRegMap.h b/evrMrmApp/src/evrRegMap.h index b69bfe37..c8ab70ad 100755 --- a/evrMrmApp/src/evrRegMap.h +++ b/evrMrmApp/src/evrRegMap.h @@ -42,6 +42,8 @@ * do this assuming 32-bit data width. */ +#define evrNumDbusBit 8 + #define U32_Status 0x000 # define Status_dbus_mask 0xff000000 # define Status_dbus_shift 24 @@ -196,6 +198,9 @@ # define ScalerPhasOffs_offset 0x20 #define U32_ScalerPulsTrig(N) (U32_ScalerN + 0x40 + (4*(N))) +#define U32_DBusTrigN 0x180 +#define U32_DBusPulsTrig(N) (U32_DBusTrigN + (4*(N))) + #define U32_PulserNCtrl 0x200 #define U32_PulserNScal 0x204 #define U32_PulserNDely 0x208