Skip to content

Commit

Permalink
Add support for RTM delay modules
Browse files Browse the repository at this point in the history
  • Loading branch information
exzombie authored and zioven committed Mar 7, 2024
1 parent 963db85 commit 1b576c2
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 18 deletions.
1 change: 1 addition & 0 deletions evrMrmApp/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ evrMrm_SRCS += drvemPulser.cpp
evrMrm_SRCS += drvemCML.cpp
evrMrm_SRCS += drvemTSBuffer.cpp
evrMrm_SRCS += delayModule.cpp
evrMrm_SRCS += delayModuleRP.cpp
evrMrm_SRCS += drvemRxBuf.cpp
evrMrm_SRCS += devMrmBuf.cpp

Expand Down
61 changes: 61 additions & 0 deletions evrMrmApp/src/delayModuleRP.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*************************************************************************\
* Copyright (c) 2022 Cosylab d.d., Ljubljana, Slovenia
* mrfioc2 is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/

#include "delayModuleRP.h"

#include <drvem.h>
#include <evrRegMap.h>

#define MAX_DELAY (8.686)

static inline epicsUInt32 delay2Int(double val) {
if(val < 0) val = 0;
if(val > MAX_DELAY) val = MAX_DELAY;
return val / MAX_DELAY * 1023.0;
}

static inline double int2Delay(epicsUInt32 val) {
return val * MAX_DELAY / 1023.0;
}

DelayModuleRP::DelayModuleRP(const std::string& n, EVRMRM* o, unsigned int idx)
: DelayModuleEvr(n)
,evr_(o)
,N_(idx)
{
}

DelayModuleRP::~DelayModuleRP()
{
}

void DelayModuleRP::setDelay0(double val)
{
WRITE32(evr_->base, RTMDLY(2 * N_), delay2Int(val));
}

double DelayModuleRP::getDelay0() const
{
return int2Delay(READ32(evr_->base, RTMDLY(2 * N_)));
}

void DelayModuleRP::setDelay1(double val)
{
WRITE32(evr_->base, RTMDLY(2 * N_ + 1), delay2Int(val));
}

double DelayModuleRP::getDelay1() const
{
return int2Delay(READ32(evr_->base, RTMDLY(2 * N_ + 1)));
}

void DelayModuleRP::setState(bool) {

}

bool DelayModuleRP::enabled() const {
return true;
}
68 changes: 68 additions & 0 deletions evrMrmApp/src/delayModuleRP.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*************************************************************************\
* Copyright (c) 2015 Paul Scherrer Institute (PSI), Villigen, Switzerland
* Copyright (c) 2022 Cosylab d.d., Ljubljana, Slovenia
* mrfioc2 is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
#ifndef DELAYMODULERP_H
#define DELAYMODULERP_H

#include "evr/delay.h"

#include "mrmGpio.h"


class EVRMRM;

class DelayModuleRP : public DelayModuleEvr
{
public:
DelayModuleRP(const std::string&, EVRMRM*, unsigned int);
virtual ~DelayModuleRP();

/**
* @brief setDelay0 Sets the delay of the output 0 in the module
* @param val Delay in range of 0ns - 8.686ns. If the value is greater it will be set to maximum range value, if it is smaller it will be set to minimum range value.
*/
virtual void setDelay0(double val) OVERRIDE FINAL;
/**
* @brief getDelay0 Returns the last set delay for the output 0 in the module
* @return The delay in [ns]
*/
virtual double getDelay0() const OVERRIDE FINAL;

/**
* @brief setDelay1 Sets the delay of the output 1 in the module
* @param val Delay in range of 0ns - 8.686ns. If the value is greater it will be set to maximum range value, if it is smaller it will be set to minimum range value.
*/
virtual void setDelay1(double val) OVERRIDE FINAL;
/**
* @brief getDelay1R eturns the last set delay for the output 1 in the module
* @return The delay in [ns]
*/
virtual double getDelay1() const OVERRIDE FINAL;

/**
* @brief setState Sets the enabled state of the delay module. If disabled, the module will output logic low on both ouputs.
* @param enabled True for enabled and false for disabled
*/
virtual void setState(bool enabled) OVERRIDE FINAL;
/**
* @brief enabled Checks if the module is enabled or not.
* @return True if the module is enabled, false othwerwise.
*/
virtual bool enabled() const OVERRIDE FINAL;

//void set(bool a, bool b, epicsUInt16 c, epicsUInt16 d){setDelay(a,b,c,d);}

private:
EVRMRM* evr_;
const unsigned int N_;
epicsUInt16 dly0_, dly1_;

// There is no locking needed, but methods must be present since there are virtual in mrf::Object class
virtual void lock() const OVERRIDE FINAL {}
virtual void unlock() const OVERRIDE FINAL {}
};

#endif // DELAYMODULERP_H
18 changes: 14 additions & 4 deletions evrMrmApp/src/drvem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ try{
<< " OFPUNIV " << conf->nOFPUV
<< " ORB " << conf->nORB
<< " OBack " << conf->nOBack
<< " OFPDly " << conf->nOFPDly
<< " UnivDly " << conf->nOUnivDly
<< " CML " << conf->nCML
<< " Kind " << static_cast<int>(conf->kind)
<< " IFP " << conf->nIFP
Expand All @@ -236,9 +236,19 @@ try{
outputs[std::make_pair(OutputFPUniv, i)] = new MRMOutput(SB() << n << ":FrontUnivOut" << i, this, OutputFPUniv, i);
}

delays.resize(conf->nOFPDly);
for(unsigned int i=0; i<conf->nOFPDly; i++){
delays[i] = new DelayModule(SB() << n << ":UnivDlyModule" << i, this, i);
delays.resize(conf->nOUnivDly);
for(unsigned int i=0; i<conf->nOUnivDly; i++){
if(formfactor==formFactor_PCIe) {
delays[i] = new DelayModuleRP(SB() << n << ":UnivDlyModule" << i, this, i);
} else if(formfactor==formFactor_mTCA) {
if(i<2){
delays[i] = new DelayModule(SB() << n << ":UnivDlyModule" << i, this, i);
} else {
delays[i] = new DelayModuleRP(SB() << n << ":UnivDlyModule" << i, this, i-2);
}
} else {
delays[i] = new DelayModule(SB() << n << ":UnivDlyModule" << i, this, i);
}
}

for(unsigned int i=0; i<conf->nORB; i++){
Expand Down
6 changes: 4 additions & 2 deletions evrMrmApp/src/drvem.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "drvemCML.h"
#include "drvemTSBuffer.h"
#include "delayModule.h"
#include "delayModuleRP.h"
#include "drvemRxBuf.h"
#include "mrmevrseq.h"
#include "mrmspi.h"
Expand Down Expand Up @@ -109,7 +110,8 @@ class epicsShareClass EVRMRM : public mrf::ObjectInst<EVRMRM, EVR>,
size_t nPS; // number of prescalers
// # of outputs (Front panel, FP Universal, Rear transition module, Backplane)
size_t nOFP, nOFPUV, nORB, nOBack;
size_t nOFPDly; // # of slots== # of delay modules. Some of the FP Universals have GPIOs. Each FPUV==2 GPIO pins, 2 FPUVs in one slot = 4 GPIO pins. One dly module uses 4 GPIO pins.
// Number of fine delay modules.
size_t nOUnivDly;
// # of CML outputs
size_t nCML;
MRMCML::outkind kind;
Expand Down Expand Up @@ -270,7 +272,7 @@ class epicsShareClass EVRMRM : public mrf::ObjectInst<EVRMRM, EVR>,
typedef std::map<std::pair<OutputType,epicsUInt32>,MRMOutput*> outputs_t;
outputs_t outputs;

std::vector<DelayModule*> delays;
std::vector<DelayModuleEvr*> delays;

typedef std::vector<MRMPreScaler*> prescalers_t;
prescalers_t prescalers;
Expand Down
24 changes: 12 additions & 12 deletions evrMrmApp/src/drvemSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static const EVRMRM::Config cpci_evr_230 = {
4, // FPUV outputs
0, // RB outputs
0, // Backplane outputs
2, // FP Delay outputs
2, // Univ. IO Delay outputs
0, // CML/GTX outputs
MRMCML::typeCML,
2, // FP inputs
Expand All @@ -112,7 +112,7 @@ static const EVRMRM::Config pmc_evr_230 = {
0, // FPUV outputs
10, // RB outputs
0, // Backplane outputs
0, // FP Delay outputs
0, // Univ. IO Delay outputs
0, // CML/GTX outputs
MRMCML::typeCML,
1, // FP inputs
Expand All @@ -126,7 +126,7 @@ static const EVRMRM::Config pcie_evr_230 = {
16, // FPUV outputs
0, // RB outputs
0, // Backplane outputs
0, // FP Delay outputs
0, // Univ. IO Delay outputs
0, // CML/GTX outputs
MRMCML::typeCML,
0, // FP inputs
Expand All @@ -140,7 +140,7 @@ static const EVRMRM::Config vme_evrrf_230 = { // no way to distinguish RF and no
4, // FPUV outputs
16, // RB outputs
0, // Backplane outputs
2, // FP Delay outputs
2, // Univ. IO Delay outputs
3, // CML/GTX outputs
MRMCML::typeCML,
2, // FP inputs
Expand All @@ -154,7 +154,7 @@ static const EVRMRM::Config cpci_evrtg_300 = {
4, // FPUV outputs
0, // RB outputs
0, // Backplane outputs
0, // FP Delay outputs
0, // Univ. IO Delay outputs
4, // CML/GTX outputs
MRMCML::typeTG300,
0, // FP inputs
Expand All @@ -168,7 +168,7 @@ static const EVRMRM::Config cpci_evr_300 = {
12, // FPUV outputs
0, // RB outputs
0, // Backplane outputs
0, // FP Delay outputs
0, // Univ. IO Delay outputs
4, // CML/GTX outputs
MRMCML::typeTG300,
2, // FP inputs
Expand All @@ -182,7 +182,7 @@ static const EVRMRM::Config mtca_evr_300rf = {
2, // FPUV outputs (only FPUV0/1, mapped to FrontUnivOut0/1, FPUV2/3 mapped in the code to FrontUnivOut18/19)
10, // RB outputs (RTM)
8, // Backplane outputs
2, // FP Delay outputs
7, // Univ. IO Delay outputs
6, // CML/GTX outputs - CLKA/B, 1x UNIV I/O slot (2 outputs), 1x SFP, 1x CML
MRMCML::typeCML,
/**
Expand All @@ -201,7 +201,7 @@ static const EVRMRM::Config mtca_evr_300u = { // with UNIV slots on FP
4, // FPUV outputs
10, // RB outputs (RTM)
8, // Backplane outputs
2, // FP Delay outputs
7, // Univ. IO Delay outputs
2, // CML/GTX outputs - CLKA/B
MRMCML::typeCML,
/**
Expand All @@ -220,7 +220,7 @@ static const EVRMRM::Config mtca_evr_300 = {
4, // Univ outputs
10, // RB outputs (10 EVRTM)
8, // Backplane outputs
2, // FP Delay outputs
5, // Univ. IO Delay outputs
2, // CML/GTX outputs - CLKA/B
MRMCML::typeCML,
/**
Expand All @@ -240,7 +240,7 @@ static const EVRMRM::Config mtca_evr_300ifb = {
0, // FPUV outputs
10, // RB outputs (via external IFB)
8, // Backplane outputs
0, // FP Delay outputs
0, // Univ. IO Delay outputs
2, // CML/GTX outputs
MRMCML::typeCML,
/**
Expand All @@ -259,7 +259,7 @@ static const EVRMRM::Config pcie_evr_300 = {
16, // FPUV outputs (via external IFB)
0, // RB outputs
0, // Backplane outputs
0, // FP Delay outputs
4, // Univ. IO Delay outputs
0, // CML/GTX outputs
MRMCML::typeCML,
/**
Expand All @@ -277,7 +277,7 @@ static const EVRMRM::Config cpci_evr_unknown = {
2, // FPUV outputs
1, // RB outputs
1, // Backplane outputs
1, // FP Delay outputs
1, // Univ. IO Delay outputs
1, // CML/GTX outputs
MRMCML::typeCML,
1, // FP inputs
Expand Down
5 changes: 5 additions & 0 deletions evrMrmApp/src/evrRegMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,14 @@

#define U32_SFPEEPROM_base 0x8200
#define U32_SFPEEPROM(N) (U32_SFPEEPROM_base + (N))

#define U32_SFPDIAG_base 0x8300
#define U32_SFPDIAG(N) (U32_SFPDIAG_base + (N))

// Rear Transition Module Delay
#define U32_RTMDLY_base 0x8400
#define U32_RTMDLY(N) (U32_RTMDLY_base + 4*(N))

#define EVR_REGMAP_SIZE 0x40000 // Total register map size = 256K

#endif /* EVRREGMAP_H */

0 comments on commit 1b576c2

Please sign in to comment.