#==================================================================
# Record example for an IntField, RO, 1 element, no encoding register.
# It is a longin record with type asynInt32.
# The INP field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RO, without encoding is 0.
#==================================================================

record(longin,  "$(P):ClkFreq") {
    field(DTYP, "asynInt32")
    field(DESC, "AMC Clock frequency")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(INP,  "@asyn($(PORT),0)AMC$(AMC):AmcClkFreq")
}
#==================================================================
# Record example for an IntField, RO, 1 element, no encoding register.
# It is a longin record with type asynInt32.
# The INP field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RO, without encoding is 0.
#==================================================================

record(longin,  "$(P):DSPVers") {
    field(DTYP, "asynInt32")
    field(DESC, "System generator core vers")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(INP,  "@asyn($(PORT),0)AMC$(AMC):Version")
}
#==================================================================
# Record example for an IntField, RW, 1 element, no encoding register.
# It is a longout record with type asynInt32.
# The OUT field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, without encoding is 1.
#==================================================================

record(longout, "$(P):NumSamp0") {
    field(DTYP, "asynInt32")
    field(DESC, "Number of samples 0")
    field(PINI, "NO")
    field(SCAN, "Passive")
    field(OUT,  "@asyn($(PORT),1)AMC$(AMC):NumSamp0")
    info(autosaveFields, "VAL")
}
#==================================================================
# Record example for an IntField, RW, 1 element, no encoding register.
# It is a longout record with type asynInt32.
# The OUT field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, without encoding is 1.
#==================================================================

record(longout, "$(P):NumSamp1") {
    field(DTYP, "asynInt32")
    field(DESC, "Number of samples 1")
    field(PINI, "NO")
    field(SCAN, "Passive")
    field(OUT,  "@asyn($(PORT),1)AMC$(AMC):NumSamp1")
    info(autosaveFields, "VAL")
}
#==================================================================
# Record example for an IntField, RW, 1 element, no encoding register.
# It is a longout record with type asynInt32.
# The OUT field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, without encoding is 1.
#==================================================================

record(longout, "$(P):NumSamp2") {
    field(DTYP, "asynInt32")
    field(DESC, "Number of samples 2")
    field(PINI, "NO")
    field(SCAN, "Passive")
    field(OUT,  "@asyn($(PORT),1)AMC$(AMC):NumSamp2")
    info(autosaveFields, "VAL")
}
#==================================================================
# Record example for an IntField, RW, 1 element, no encoding register.
# It is a longout record with type asynInt32.
# The OUT field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, without encoding is 1.
#==================================================================

record(longout, "$(P):TrigDelay1") {
    field(DTYP, "asynInt32")
    field(DESC, "Trigger delay 1")
    field(PINI, "NO")
    field(SCAN, "Passive")
    field(OUT,  "@asyn($(PORT),1)AMC$(AMC):TrigDelay1")
    info(autosaveFields, "VAL")
}
#==================================================================
# Record example for an IntField, RW, 1 element, no encoding register.
# It is a longout record with type asynInt32.
# The OUT field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, without encoding is 1.
#==================================================================

record(longout, "$(P):TrigDelay2") {
    field(DTYP, "asynInt32")
    field(DESC, "Trigger delay 2")
    field(PINI, "NO")
    field(SCAN, "Passive")
    field(OUT,  "@asyn($(PORT),1)AMC$(AMC):TrigDelay2")
    info(autosaveFields, "VAL")
}
#==================================================================
# Record example for reading back from an IntField, RW, 1 element,
# no encoding register.
# It is a longin record with type asynInt32.
# The INP field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, without encoding is 1.
#==================================================================

record(longin,  "$(P):NumSamp0RBV") {
    field(DTYP, "asynInt32")
    field(DESC, "Number of samples 0")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(INP,  "@asyn($(PORT),1)AMC$(AMC):NumSamp0")
}
#==================================================================
# Record example for reading back from an IntField, RW, 1 element,
# no encoding register.
# It is a longin record with type asynInt32.
# The INP field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, without encoding is 1.
#==================================================================

record(longin,  "$(P):NumSamp1RBV") {
    field(DTYP, "asynInt32")
    field(DESC, "Number of samples 1")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(INP,  "@asyn($(PORT),1)AMC$(AMC):NumSamp1")
}
#==================================================================
# Record example for reading back from an IntField, RW, 1 element,
# no encoding register.
# It is a longin record with type asynInt32.
# The INP field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, without encoding is 1.
#==================================================================

record(longin,  "$(P):NumSamp2RBV") {
    field(DTYP, "asynInt32")
    field(DESC, "Number of samples 2")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(INP,  "@asyn($(PORT),1)AMC$(AMC):NumSamp2")
}
#==================================================================
# Record example for reading back from an IntField, RW, 1 element,
# no encoding register.
# It is a longin record with type asynInt32.
# The INP field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, without encoding is 1.
#==================================================================

record(longin,  "$(P):TrigDelay1RBV") {
    field(DTYP, "asynInt32")
    field(DESC, "Trigger delay 1")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(INP,  "@asyn($(PORT),1)AMC$(AMC):TrigDelay1")
}
#==================================================================
# Record example for reading back from an IntField, RW, 1 element,
# no encoding register.
# It is a longin record with type asynInt32.
# The INP field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, without encoding is 1.
#==================================================================

record(longin,  "$(P):TrigDelay2RBV") {
    field(DTYP, "asynInt32")
    field(DESC, "Trigger delay 2")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(INP,  "@asyn($(PORT),1)AMC$(AMC):TrigDelay2")
}
#==================================================================
# Record example for an IntField, RW, 1 element, no encoding,
# enum (1-bit) register.
# It is a bo record with type asynUInt32Digital.
# The OUT field has the form @asynMask(PORT,ADDR,MASK)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - MASK  : It is 1 for 1-bit register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, without encoding is 1.
#==================================================================

record(bo,      "$(P):AutoRearm") {
    field(DTYP, "asynUInt32Digital")
    field(DESC, "Auto rearm")
    field(PINI, "NO")
    field(SCAN, "Passive")
    field(OUT,  "@asynMask($(PORT),1,1)AMC$(AMC):AutoRearm")
    field(ZNAM, "Disabled")
    field(ONAM, "Enabled")
}
#==================================================================
# Record example for reading back an IntField, RW, 1 element, no encoding,
# enum (1-bit) register.
# It is a bi record with type asynUInt32Digital.
# The INP field has the form @asynMask(PORT,ADDR,MASK)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - MASK  : It is 1 for 1-bit register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, without encoding is 1.
#==================================================================

record(bi,      "$(P):AutoRearmRBV") {
    field(DTYP, "asynUInt32Digital")
    field(DESC, "Auto rearm")
    field(PINI, "YES")
    field(SCAN, ".5 second")
    field(INP,  "@asynMask($(PORT),1,1)AMC$(AMC):AutoRearm")
    field(ZNAM, "Disabled")
    field(ONAM, "Enabled")
}
#==================================================================
# Record example for an IntField, RO, 1 element, IEEE_754 encoding 
# register.
# It is a ai record with type asynFloat64.
# The INP field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given 
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn paramter name. It must be defined in the 
#            dictionary file and assigned to a register.
#  - ADDR  : Addrres based on the type of register. 
#            For IntField, RO, with IEEE_754 encoding is 2.
#==================================================================

record(ai,      "$(P):GATED_INTEGRAL") {
    field(DTYP, "asynFloat64")
    field(DESC, "PMT Charge")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(EGU,  "")
    field(HIGH, "131071")
    field(HSV, "MAJOR")
    field(LOW, "-1")
    field(LSV, "MAJOR")
    field(EGU,  "")
    field(INP,  "@asyn($(PORT),2)AMC$(AMC):PMTCharge")
}
#==================================================================
# Record example for an IntField, RO, 1 element, IEEE_754 encoding 
# register.
# It is a ai record with type asynFloat64.
# The INP field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given 
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn paramter name. It must be defined in the 
#            dictionary file and assigned to a register.
#  - ADDR  : Addrres based on the type of register. 
#            For IntField, RO, with IEEE_754 encoding is 2.
#==================================================================

record(ai,      "$(P):ResultA0") {
    field(DTYP, "asynFloat64")
    field(DESC, "CeofA0*SumS0")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(EGU,  "")
    field(HIGH, "")
    field(HSV, "")
    field(LOW, "")
    field(LSV, "")
    field(EGU,  "")
    field(INP,  "@asyn($(PORT),2)AMC$(AMC):ResultA0")
}
#==================================================================
# Record example for an IntField, RO, 1 element, IEEE_754 encoding 
# register.
# It is a ai record with type asynFloat64.
# The INP field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given 
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn paramter name. It must be defined in the 
#            dictionary file and assigned to a register.
#  - ADDR  : Addrres based on the type of register. 
#            For IntField, RO, with IEEE_754 encoding is 2.
#==================================================================

record(ai,      "$(P):ResultA1") {
    field(DTYP, "asynFloat64")
    field(DESC, "CeofA1*SumS1")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(EGU,  "")
    field(HIGH, "")
    field(HSV, "")
    field(LOW, "")
    field(LSV, "")
    field(EGU,  "")
    field(INP,  "@asyn($(PORT),2)AMC$(AMC):ResultA1")
}
#==================================================================
# Record example for an IntField, RO, 1 element, IEEE_754 encoding 
# register.
# It is a ai record with type asynFloat64.
# The INP field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given 
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn paramter name. It must be defined in the 
#            dictionary file and assigned to a register.
#  - ADDR  : Addrres based on the type of register. 
#            For IntField, RO, with IEEE_754 encoding is 2.
#==================================================================

record(ai,      "$(P):ResultA2") {
    field(DTYP, "asynFloat64")
    field(DESC, "CeofA2*SumS2")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(EGU,  "")
    field(HIGH, "")
    field(HSV, "")
    field(LOW, "")
    field(LSV, "")
    field(EGU,  "")
    field(INP,  "@asyn($(PORT),2)AMC$(AMC):ResultA2")
}
#==================================================================
# Record example for an IntField, RO, 1 element, IEEE_754 encoding 
# register.
# It is a ai record with type asynFloat64.
# The INP field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given 
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn paramter name. It must be defined in the 
#            dictionary file and assigned to a register.
#  - ADDR  : Addrres based on the type of register. 
#            For IntField, RO, with IEEE_754 encoding is 2.
#==================================================================

record(ai,      "$(P):AddSumS0") {
    field(DTYP, "asynFloat64")
    field(DESC, "ResultA0+ResultA1")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(EGU,  "")
    field(HIGH, "")
    field(HSV, "")
    field(LOW, "")
    field(LSV, "")
    field(EGU,  "")
    field(INP,  "@asyn($(PORT),2)AMC$(AMC):AddS0")
}
#==================================================================
# Record example for an IntField, RO, 1 element, IEEE_754 encoding 
# register.
# It is a ai record with type asynFloat64.
# The INP field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given 
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn paramter name. It must be defined in the 
#            dictionary file and assigned to a register.
#  - ADDR  : Addrres based on the type of register. 
#            For IntField, RO, with IEEE_754 encoding is 2.
#==================================================================

record(ai,      "$(P):AddSumS1") {
    field(DTYP, "asynFloat64")
    field(DESC, "ResultA2+CoeffOff")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(EGU,  "")
    field(HIGH, "")
    field(HSV, "")
    field(LOW, "")
    field(LSV, "")
    field(EGU,  "")
    field(INP,  "@asyn($(PORT),2)AMC$(AMC):AddS1")
}
#==================================================================
# Record example for an IntField, RW, 1 element, IEEE_754 encoding
# register.
# It is an ao record with type asynFloat64.
# The OUT field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, with IEEE_754 encoding is 3.
#==================================================================

record(ao,      "$(P):CoefA0") {
    field(DTYP, "asynFloat64")
    field(DESC, "Coef A0 for PMT")
    field(PINI, "YES")
    field(SCAN, "Passive")
    field(OUT,  "@asyn($(PORT),3)AMC$(AMC):CoefA0")
    info(autosaveFields, "VAL")
}
#==================================================================
# Record example for an IntField, RW, 1 element, IEEE_754 encoding
# register.
# It is an ao record with type asynFloat64.
# The OUT field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, with IEEE_754 encoding is 3.
#==================================================================

record(ao,      "$(P):CoefA1") {
    field(DTYP, "asynFloat64")
    field(DESC, "Coef A1 for PMT")
    field(PINI, "YES")
    field(SCAN, "Passive")
    field(OUT,  "@asyn($(PORT),3)AMC$(AMC):CoefA1")
    info(autosaveFields, "VAL")
}
#==================================================================
# Record example for an IntField, RW, 1 element, IEEE_754 encoding
# register.
# It is an ao record with type asynFloat64.
# The OUT field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, with IEEE_754 encoding is 3.
#==================================================================

record(ao,      "$(P):CoefA2") {
    field(DTYP, "asynFloat64")
    field(DESC, "Coef A2 for PMT")
    field(PINI, "YES")
    field(SCAN, "Passive")
    field(OUT,  "@asyn($(PORT),3)AMC$(AMC):CoefA2")
    info(autosaveFields, "VAL")
}
#==================================================================
# Record example for an IntField, RW, 1 element, IEEE_754 encoding
# register.
# It is an ao record with type asynFloat64.
# The OUT field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, with IEEE_754 encoding is 3.
#==================================================================

record(ao,      "$(P):CoefOff") {
    field(DTYP, "asynFloat64")
    field(DESC, "Coef Offset for PMT")
    field(PINI, "YES")
    field(SCAN, "Passive")
    field(OUT,  "@asyn($(PORT),3)AMC$(AMC):Offset")
    info(autosaveFields, "VAL")
}
#==================================================================
# Record example for reading back an IntField, RW, 1 element,
# IEEE_754 encoding register.
# It is an ai record with type asynFloat64.
# The INP field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, with IEEE_754 encoding is 3.
#==================================================================

record(ai,      "$(P):CoefA0RBV") {
    field(DTYP, "asynFloat64")
    field(DESC, "Coef A0 for PMT")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(INP,  "@asyn($(PORT),3)AMC$(AMC):CoefA0")
}
#==================================================================
# Record example for reading back an IntField, RW, 1 element,
# IEEE_754 encoding register.
# It is an ai record with type asynFloat64.
# The INP field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, with IEEE_754 encoding is 3.
#==================================================================

record(ai,      "$(P):CoefA1RBV") {
    field(DTYP, "asynFloat64")
    field(DESC, "Coef A1 for PMT")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(INP,  "@asyn($(PORT),3)AMC$(AMC):CoefA1")
}
#==================================================================
# Record example for reading back an IntField, RW, 1 element,
# IEEE_754 encoding register.
# It is an ai record with type asynFloat64.
# The INP field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, with IEEE_754 encoding is 3.
#==================================================================

record(ai,      "$(P):CoefA2RBV") {
    field(DTYP, "asynFloat64")
    field(DESC, "Coef A2 for PMT")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(INP,  "@asyn($(PORT),3)AMC$(AMC):CoefA2")
}
#==================================================================
# Record example for reading back an IntField, RW, 1 element,
# IEEE_754 encoding register.
# It is an ai record with type asynFloat64.
# The INP field has the form @asyn(PORT,ADDR)PARAM where:
#  - PORT  : The asyn port name. It must match the port name given
#            when calling "YCPSWASYNConfig" on st.cmd
#  - PARAM : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register.
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, with IEEE_754 encoding is 3.
#==================================================================

record(ai,      "$(P):CoefOffRBV") {
    field(DTYP, "asynFloat64")
    field(DESC, "Coef Offset for PMT")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(INP,  "@asyn($(PORT),3)AMC$(AMC):Offset")
}

# These are the records that transform tick counts to time in nanoseconds,
# by using the sampling frequency of the ADCs.

# Giving the frequency in Hz, calculate the time in ns between each sample
record (calc, "$(P):SAMP_TIME") {
  field(DESC, "Time between samples in ns")
  field(INPA, "$(P):ClkFreq CP")
  field(CALC, "1000000000/(2 * A)")
}

# Calculate the time correspondent to the number of samples of the pre-edge
#m of the weight function
record (calc, "$(P):PED_WIDTH_RBV") {
  field(DESC, "Duration of pre-edge in ns")
  field(INPA, "$(P):SAMP_TIME CP")
  field(INPB, "$(P):NumSamp0RBV")
  field(CALC, "A * B")
}

# Calculate the time correspondent to the number of samples of between edges
# of the weight function. It must be at least the same size of the
# pre-edge time because the time counts from the beginning of the pre-edge.
record (calc, "$(P):GATE_START_RBV") {
  field(DESC, "Duration between edges in ns")
  field(INPA, "$(P):SAMP_TIME CP")
  field(INPB, "$(P):TrigDelay1RBV")
  field(CALC, "B*2 * A")
}

# Calculate the time correspondent to the number of samples of the pos-edge
# of the weight function
record (calc, "$(P):GATE_WIDTH_RBV") {
  field(DESC, "Duration of pos-edge in ns")
  field(INPA, "$(P):SAMP_TIME CP")
  field(INPB, "$(P):NumSamp1RBV")
  field(CALC, "A * B")
}

# Desired time of the weight function pre-edge
record (ao, "$(P):PED_WIDTH") {
  field(DESC, "Duration of pre-edge in ns")
  field(DRVH, "724")
  field(HOPR, "724")
  info(autosaveFields, "VAL")
}

# Calculate the number of samples of the pre-edge of the weight function 
# giving the correspondent time and writes it to the firmware. Only even
# numbers are allowed in the FPGA register (that is why we use ((~0)-1)&
record (calcout, "$(P):NumSamp0_CLC") {
  field(DESC, "Number samples of pre-edge")
  field(INPA, "$(P):PED_WIDTH CP")
  field(INPB, "$(P):ClkFreq CP")
  field(CALC, "((~0)-1)&FLOOR((2*A*B)/1000000000)")
  field(OUT, "$(P):NumSamp0 PP")
  field(DOPT, "Use CALC")
}

# Desired time of the weight function between edges
record (ao, "$(P):GATE_START") {
  field(DESC, "Duration of between edge in ns")
  field(DRVH, "1448")
  field(HOPR, "1448")
  info(autosaveFields, "VAL")
}

# Time between edges is doubled related to the edges. Also, timing zero for
# this time is exactly timing zero for the pre-edge. So, we must not allow
# that the between edges time keeps greater than the pre-edge.
record (calc, "$(P):TIME_MIDC") {
  field(DESC, "Duration of between edge in ns")
  field(INPA, "$(P):PED_WIDTH CP")
  field(INPB, "$(P):GATE_START CP")
  field(CALC, "A<B? B/2 : A/2")
}

# Calculate the number of samples of between edges of the weight function 
# giving the correspondent time and writes it to the firmware. The time
# here is twice the time in pre and post edges. Only even numbers are allowed
# in the FPGA register (that is why we use ((~0)-1)&).
record (calcout, "$(P):TrigDelay1_CLC") {
  field(DESC, "Number samples of between edges")
  field(INPA, "$(P):TIME_MIDC CP")
  field(INPB, "$(P):ClkFreq CP")
  field(CALC, "((~0)-1)&FLOOR((2*A*B)/1000000000)")
  field(OUT, "$(P):TrigDelay1 PP")
  field(DOPT, "Use CALC")
}

#Desired time of the weight function pos-edge
record (ao, "$(P):GATE_WIDTH") {
  field(DESC, "Duration of pos-edge in ns")
  field(DRVH, "724")
  field(HOPR, "724")
  info(autosaveFields, "VAL")
}

# Calculate the number of samples of the pos-edge of the weight function 
# giving the correspondent time and writes it to the firmware. Only even
# numbers are allowed in the FPGA register (that is why we use ((~0)-1)&).
record (calcout, "$(P):NumSamp1_CLC") {
  field(DESC, "Number samples of pos-edge")
  field(INPA, "$(P):GATE_WIDTH CP")
  field(INPB, "$(P):ClkFreq CP")
  field(CALC, "((~0)-1)&FLOOR((2*A*B)/1000000000)")
  field(OUT, "$(P):NumSamp1 PP")
  field(DOPT, "Use CALC")
}

# Weight function calculated from pre edge, edge, and pos edge sample amounts.
record (acalcout, "$(P):SCL_WF_CLC") {
  field(DESC, "Weight function")
  field(CALC, "ARR(1){0,A-1} + ARR(-1){B*2,B*2+C-1}")
  field(NELM, "1024")
  field(INPA, "$(P):NumSamp0 CP")
  field(INPB, "$(P):TrigDelay1 CP")
  field(INPC, "$(P):NumSamp1 CP")
}

# Transform an acalcout AVAL info into an waveform VAL, just to maintain
# compatibility with previous systems.
record (waveform, "$(P):SCL_WF") {
  field(DESC, "Weight function")
  field(INP, "$(P):SCL_WF_CLC.AVAL CP")
  field(NELM, "1024")
  field(FTVL, "SHORT")
}

# The records below scales the +1 | 0 | -1 from the Weight Function to
# max(Raw Waveform) | (max(Raw Waveform) + min(Raw Waveform) / 2) | min(Raw Waveform)
# in order to plot raw + weight on the same chart using the same scale.

# Need to use 2 acalcouts to get MAX and MIN from the waveform because the CALC
# field is too small (36 characters)
record (acalcout, "$(P):FAST_RAW_WF_MAX") {
  field(DESC, "Max value of the raw waveform")
  field(CALC, "AMAX(AA)")
  field(INAA, "$(P):FAST_WF_RAW_U16.VALA CP")
  field(DOPT, "Use CALC")
  field(NELM, "1024")
}

record (acalcout, "$(P):FAST_RAW_WF_MIN") {
  field(DESC, "Min value of the raw waveform")
  field(CALC, "AMIN(AA)")
  field(INAA, "$(P):FAST_WF_RAW_U16.VALA CP")
  field(DOPT, "Use CALC")
  field(NELM, "1024")
}

# Change the top of the visual weight function only if it is greater than 35%
# of the last calculated top value.
record (acalcout, "$(P):WF_MAX") {
  field(DESC, "Smooth function for the top")
  field(CALC, "ABS(A-C)>ABS(A-B)*0.35?A:C")
  field(INPA, "$(P):FAST_RAW_WF_MAX CP")
  field(INPB, "$(P):FAST_RAW_WF_MIN CP")
  field(OUT, "$(P):WF_MAX.C")
  field(DOPT, "Use CALC")
  field(NELM, "1024")
}

# Change the bottom of the visual weight function only if it is greater than 35%
# of the last calculated bottom value.
record (acalcout, "$(P):WF_MIN") {
  field(DESC, "Smooth function for the bottom")
  field(CALC, "ABS(B-C)>ABS(A-B)*0.35?B:C")
  field(INPA, "$(P):FAST_RAW_WF_MAX CP")
  field(INPB, "$(P):FAST_RAW_WF_MIN CP")
  field(OUT, "$(P):WF_MIN.C")
  field(DOPT, "Use CALC")
  field(NELM, "1024")
}

# Line before the edge (corresponding to +1 of the Weight Function)
record (acalcout, "$(P):SCL_VWF_PRE") {
  field(DESC, "Equivalent to +1 in Weight")
  # Fills the array with the maximum of the raw waveform until the edge.
  # All other elements remain zero.
  field(CALC, "ARR(E){0,A-1}")
  field(NELM, "1024")
  # Number of samples pre-edge
  field(INPA, "$(P):NumSamp0 CP")
  field(INPE, "$(P):WF_MAX CP")
  # Raw waveform 16 bits.
  field(INAA, "$(P):FAST_WF_RAW_U16.VALA CP")
}

# Line after the edge (corresponding to -1 of the Weight Function)
record (acalcout, "$(P):SCL_VWF_POS") {
  field(DESC, "Equivalent to -1 in Weight")
  # Fills the array with the minimum of the raw waveform after the edge.
  # All other elements remain zero.
  field(CALC, "ARR(D){B*2,B*2+C-1}")
  field(NELM, "1024")
  # Number of samples pre-edge
  field(INPA, "$(P):NumSamp0 CP")
  # Number of samples of the edge
  field(INPB, "$(P):TrigDelay1 CP")
  # Number of samples pos-edge
  field(INPC, "$(P):NumSamp1 CP")
  field(INPD, "$(P):WF_MIN CP")
  # Raw waveform 16 bits.
  field(INAA, "$(P):FAST_WF_RAW_U16.VALA CP")
}

# Line of the edge (corresponding to 0 of the Weight Function)
record (acalcout, "$(P):SCL_VWF_MID") {
  field(DESC, "Equivalent to 0 in Weight")
  # Fills the array with the average of the maximum and minimum raw waveform
  # and places it between the pre and the pos-edge curves.
  # All other elements remain zero.
  field(CALC, "ARR((D+E)/2){A,B*2-1}")
  field(NELM, "1024")
  # Number of samples pre-edge
  field(INPA, "$(P):NumSamp0 CP")
  # Number of samples of the edge
  field(INPB, "$(P):TrigDelay1 CP")
  field(INPD, "$(P):WF_MAX CP")
  field(INPE, "$(P):WF_MIN CP")
  # Raw waveform 16 bits.
  field(INAA, "$(P):FAST_WF_RAW_U16.VALA CP")
}

# Last part of the weight function, after the pos-edge.
record (acalcout, "$(P):SCL_VWF_FINAL") {
  field(DESC, "Final portion, after pos-edge")
  # Obtain the same value as used for the edge, placing it at the end of the
  # curve.
  field(CALC, "ARR((D+E)/2){B*2+C,-1}")
  field(NELM, "1024")
  # Number of samples pre-edge
  field(INPA, "$(P):NumSamp0 CP")
  # Number of samples of the edge
  field(INPB, "$(P):TrigDelay1 CP")
  # Number of samples pos-edge
  field(INPC, "$(P):NumSamp1 CP")
  field(INPD, "$(P):WF_MAX CP")
  field(INPE, "$(P):WF_MIN CP")
  # Raw waveform 16 bits.
  field(INAA, "$(P):FAST_WF_RAW_U16.VALA CP")
}

# This is the weight function multiplied by the raw min and max. The only
# purpose is to fit the curve on the same chart as the raw data using the
# same scale in the y-axis.
record (acalcout, "$(P):SCL_VWF") {
  field(DESC, "Weight scaled for best plot")
  field(CALC, "AA+BB+CC+DD")
  field(NELM, "1024")
  field(INAA, "$(P):SCL_VWF_PRE.AVAL CP")
  field(INBB, "$(P):SCL_VWF_POS.AVAL CP")
  field(INCC, "$(P):SCL_VWF_MID.AVAL CP")
  field(INDD, "$(P):SCL_VWF_FINAL.AVAL CP")
}

# Calculated waveforms when multiplying raw for weight
record (acalcout, "$(P):S_P_WF_CLC") {
  field(DESC, "Raw times weight")
  field(INAA, "$(P):FAST_WF_RAW_U16.VALA CP")
  field(INBB, "$(P):SCL_WF_CLC.AVAL CP")
  field(NELM, "1024")
  field(CALC, "AA * BB")
}

# Transform an acalcout AVAL info into an waveform VAL, just to maintain
# compatibility with previous systems.
record (waveform, "$(P):S_P_WF") {
  field(DESC, "Raw times weight")
  field(INP, "$(P):S_P_WF_CLC.AVAL CP")
  field(NELM, "1024")
  field(FTVL, "SHORT")
}

##########################################################################
# Description:
# This database reads the stream from firmware 
# It converts raw data to user units
# It reads a portion of the waveform into a record as per user request
#
# Macros:
# DEVICE: Device prefix
# ATTR  : Device attribute  
# DESC  : Device description
# PORT  : The asyn port name. It must match the port name given
#         when calling "YCPSWASYNConfig" on st.cmd
# PARAM : The asyn parameter name. It must be defined in the
#         dictionary file and assigned to a register.
##########################################################################
# Buffer PV, to hold all the stream data
# up to 10e6 points
record(waveform, "$(P):FAST_WF_RAW-BUF")
{
  field(DESC,    "waveform Buffer Data")
  field(DTYP,    "asynInt16ArrayIn")
  field(NELM,    "1000000")
  field(FTVL,    "SHORT")
  field(SCAN,    "I/O Intr")
  field(INP,     "@asyn($(PORT),5)AMC$(AMC):StreamRaw:16")
  field(FLNK,    "$(P):FAST_WF_RAW PP")
  field(ASG,     "Internal")
}

# Interface PV, to display only the necessary data
# range from the data received in the buffer
record(subArray, "$(P):FAST_WF_RAW") 
{
  field(DESC,    "waveform Raw Subarray")
  field(INP,     "$(P):FAST_WF_RAW-BUF")
  field(FTVL,    "SHORT")
  field(MALM,    "1000000")
  field(NELM,    "1024")
  field(INDX,    "0")
  field(FLNK,    "$(P):FAST_WF_R2E PP")
}

# Interface PV, to display only the necessary data
# range from the data received in the buffer in user units
record(subArray, "$(P):FAST_WF") 
{
  field(DESC,    "waveform Subarray")
  field(INP,     "$(P):FAST_WF_R2E.VALA")
  field(FTVL,    "DOUBLE")
  field(MALM,    "1000000")
  field(NELM,    "1024")
  field(INDX,    "0")
  field(EGU,    "mV")
  field(FLNK,    "$(P):FAST_WF_RAW_U16 PP")
}

# Interface PV, to display only the necessary data
# range from the data received in unsigned array
record(subArray, "$(P):FAST_SIG")
{
  field(DESC,    "Subarray")
  field(INP,     "$(P):FAST_WF_RAW_U16.VALA")
  field(FTVL,    "SHORT")
  field(MALM,    "1000000")
  field(NELM,    "1024")
  field(INDX,    "0")
  field(FLNK,    "$(P):FAST_SIG_MULT PP")
}

# PV to hold the start for the display array
record(ao, "$(P):FAST_WF_START") 
{
  field(DESC,    "waveform Subarray start")
  field(DRVH,    "1000000")
  field(HOPR,    "1000000")
  field(PINI,    "YES")
  field(FLNK,    "$(P):FAST_WF_SEQ")
  info(autosaveFields, "VAL")
}

# PV to hold the length for the display array
record(ao, "$(P):FAST_WF_NELM") 
{
  field(DESC,    "waveform Subarray length")
  field(DRVH,    "1000000")
  field(HOPR,    "1000000")
  field(PINI,    "YES")
  field(FLNK,    "$(P):FAST_WF_SEQ")
  info(autosaveFields, "VAL")
}

# PV to send data start and nelm to raw and wf PVs
record(seq, "$(P):FAST_WF_SEQ") 
{
  field(DESC, "Update NELM and INDX value")
  field(DOL1, "$(P):FAST_WF_START")
  field(LNK1, "$(P):FAST_WF_RAW.INDX PP")

  field(DOL2, "$(P):FAST_WF_START")
  field(LNK2, "$(P):FAST_WF.INDX PP")
  
  field(DOL3, "$(P):FAST_WF_START")
  field(LNK3, "$(P):FAST_SIG.INDX PP")

  field(DOL4, "$(P):FAST_WF_START")
  field(LNK4, "$(P):FAST_SIG_DECONVOLVED.INDX PP")

  field(DOL5, "$(P):FAST_WF_NELM")
  field(LNK5, "$(P):FAST_WF_RAW.NELM PP")

  field(DOL6, "$(P):FAST_WF_NELM")
  field(LNK6, "$(P):FAST_WF.NELM PP")

  field(DOL7, "$(P):FAST_WF_NELM")
  field(LNK7, "$(P):FAST_SIG_MULT.NELM PP")

  field(DOL8, "$(P):FAST_WF_NELM")
  field(LNK8, "$(P):FAST_SIG_DECONVOLVED.NELM PP")

  field(DOL8, "$(P):FAST_WF_NELM")
  field(LNK8, "$(P):FAST_WF_TIME.NELM PP")

  field(DOL9, "$(P):FAST_WF_NELM")
  field(LNK9, "$(P):FAST_SIG.NELM PP")

  field(DOLA, "$(P):FAST_WF_NELM")
  field(LNKA, "$(P):FAST_WF_Z.NELM PP")

  field(ASG,  "Internal")
}


# PV to hold the slope for the display array (raw to egu conversion)
record(ao, "$(P):FAST_SLOPE_WF") 
{
  field(DESC,    "waveform WF slope")
  field(PREC,    "2")
  field(EGU,    "mV/raw")
  field(PINI,    "YES")
  field(FLNK,    "$(P):FAST_WF_R2E")
  info(autosaveFields, "VAL")
}


# PV to hold the offset for the display array (raw to egu conversion)
record(ao, "$(P):FAST_OFFSET_WF") 
{
  field(DESC,    "waveform WF offset in raw")
  field(PINI,    "YES")
  field(FLNK,    "$(P):FAST_WF_R2E")
  field(EGU,    "raw")
  info(autosaveFields, "VAL")
}

# PV to enable debug mode for gain to voltage subroutine 
record(bo, "$(P):FAST_WF_DEBUG") {
  field(DESC, "Subroutine Debug")
  field(ONAM, "DEBUG ON")
  field(ZNAM, "DEBUG OFF")
}

# PV to calculate the interface pv in user units
record (aSub, "$(P):FAST_WF_R2E") 
{
  field(DESC, "waveform subarray raw to egu")
  field(SNAM, "calcWFinEGU")
  field(INPA, "$(P):FAST_WF_RAW PP")
  field(NOA, "1000000")
  field(FTA, "SHORT")
  field(INPB, "$(P):FAST_SLOPE_WF PP")
  field(FTB, "DOUBLE")
  field(INPC, "$(P):FAST_OFFSET_WF PP")
  field(FTC, "SHORT")
  field(INPD, "$(P):FAST_WF_DEBUG PP")
  field(OUTA, "$(P):FAST_WF")
  field(FLNK, "$(P):FAST_WF")
  field(NOVA, "1000000")
  field(FTVA, "DOUBLE")
  field(FLNK, "$(P):FAST_WF_RAW_U16 PP")
}

# Pv to calculate an unsiged 16 bit array from a signed array
record (aSub, "$(P):FAST_WF_RAW_U16") {
  field(DESC, "Slow raw waveform")
  field(SNAM, "calcRWF16")
  field(INPA, "$(P):FAST_WF_RAW PP")
  field(NOA, "1000000")
  field(FTA, "SHORT")
  field(NOVA,"1000000")
  field(FTVA, "SHORT")
  field(OUTA, "$(P):FAST_SIG")
  field(FLNK, "$(P):FAST_SIG")
}

# Waveform for matrix multiplication
record(waveform, "$(P):FAST_SIG_MULT_WF") {
    field(DESC,  "Multiplier to loss WF")
    field(NELM,  "1024")
    field(FTVL,  "SHORT")
    field(FLNK, "$(P):FAST_SIG_MULT")
}

# Interface PV, to display only the necessary data
# range from mult
record(subArray, "$(P):FAST_SIG_MULT") 
{
  field(DESC,    "waveform Subarray")
  field(INP,     "$(P):FAST_SIG_MULT_WF")
  field(FTVL,    "SHORT")
  field(MALM,    "1024")
  field(NELM,    "1024")
  field(INDX,    "0")
  field(FLNK,    "$(P):FAST_SIG_DECONVOLVED PP")
}

# Calculated waveform when multiplying with deconvolution matrix
record (acalcout, "$(P):FAST_SIG_DECONVOLVED") {
  field(DESC, "Raw times deconvolution matrix")
  field(INAA, "$(P):FAST_SIG PP")
  field(INBB, "$(P):FAST_SIG_MULT PP")
  field(NELM, "1024")
  field(CALC, "AA * BB")
  field(FLNK, "$(P):FAST_WF_TIME_CLC PP")
}

# Create a waveform with the sampling time. This will be the X axis of the
# waveform.
record (aSub, "$(P):FAST_WF_TIME_CLC") {
  field(SNAM, "calcTimeArray")
  field(FTA, "LONG")
  field(FTVA, "DOUBLE")
  field(NOVA, "1000000")
  field(INPA, "$(P):ClkFreq PP")
  field(OUTA, "$(P):FAST_WF_TIME")
  field(FLNK, "$(P):FAST_WF_TIME")
}

# Interface PV, to display X axis of waveform
record(subArray, "$(P):FAST_WF_TIME")
{
  field(DESC,    "Subarray")
  field(INP,     "$(P):FAST_WF_TIME_CLC.VALA")
  field(FTVL,    "DOUBLE")
  field(MALM,    "1000000")
  field(NELM,    "1024")
  field(INDX,    "0")
  field(FLNK, "$(P):FAST_WF_Z_CLC")
}

#Desired scaling for time to Z
record (ao, "$(P):FAST_WF_SLOPE_Z") {
  field(DESC, "scaling factor for time to Z")
  field(PREC, "4")
  field(EGU, "m/ns")
  field(VAL, "0.166")
  info(autosaveFields, "VAL")
}

#Desired start of Z
record (ao, "$(P):FAST_WF_OFFSET_Z") {
  field(DESC, "start Z for LBLM")
  field(PREC, "4")
  field(EGU, "m")
  field(VAL, "9.9")
  info(autosaveFields, "VAL")
}

#Desired reference for T
record (ao, "$(P):FAST_WF_TIME_REF") {
  field(DESC, "Tref for LBLM")
  field(PREC, "4")
  field(EGU, "ns")
  field(VAL, "185")
  info(autosaveFields, "VAL")
}

# waveform of Z start.
record (acalcout, "$(P):FAST_WF_Z_CLC") {
  field(DESC, "WF Z calc")
  field(CALC, "(AA * ARR(A)) + ARR (B) -ARR(C*A)")
  field(NELM, "1024")
  field(INPA, "$(P):FAST_WF_SLOPE_Z CP NMS")
  field(INPB, "$(P):FAST_WF_OFFSET_Z CP NMS")
  field(INPC, "$(P):FAST_WF_TIME_REF CP NMS")
  field(INAA, "$(P):FAST_WF_TIME CP NMS")
  field(FLNK, "$(P):FAST_WF_Z")
}

# Interface PV, to display X axis of waveform in Z locations
record(subArray, "$(P):FAST_WF_Z")
{
  field(DESC,    "Subarray")
  field(INP,     "$(P):FAST_WF_Z_CLC.AVAL")
  field(FTVL,    "DOUBLE")
  field(MALM,    "1000000")
  field(NELM,    "1024")
  field(INDX,    "0")
}

##########################################################################
# Description:
# This database works with LBLM Gain Control Chassis. 
# It adjusts the gain on the analog input through ATCA AMD DAQ channel
#
# Macros:
# DEVICE: Device prefix
# ATTR  : Device attribute  
# PORT  : The asyn port name. It must match the port name given
#         when calling "YCPSWASYNConfig" on st.cmd
# PARAM : The asyn parameter name. It must be defined in the
#         dictionary file and assigned to a register.
##########################################################################
# PV to set amplifier bypass
record(bo, "$(P):FAST_AMP_BYP") {
  field(DESC, "Bypass amplifier")
  field(ONAM, "BYPASS")
  field(ZNAM, "NO BYPASS")
  field(FLNK, "$(P):FAST_AMP_BYP_SEQ")
  info(autosaveFields, "VAL")
}

# PV to set voltage and gain approritately when amplifier is  bypassed.
# Set Gain to -5.6dB and Voltage to -1.2V
# Notes from Alan Fisher:
# The chassis bypasses the amplifier if the DAC voltage is less than -1 V. There should be a bypass on/off switch that sets the DAC to something about -1.2 V (to be far from the transition). When bypassed, the path attenuates by -5.6 dB
record(seq, "$(P):FAST_AMP_BYP_SEQ") {
  field(DESC, "Amplifier Bypass")
  field(DO1, "-5.6")
  field(LNK1, "$(P):FAST_AMP_GAIN PP")
  field(DO2, "-1.2")
  field(LNK2, "$(P):FAST_AMP_V PP")
  field(ASG,  "Internal")
}

# PV that holds amplifier voltage 
record(ao, "$(P):FAST_AMP_V") {
  field(DESC, "Amplifier Voltage")
  field(PINI, "NO")
  field(EGU, "V")
  field(DRVH, "1.59")
  field(DRVL,"-1.66")
  field(PREC, "2")
  field(FLNK, "$(P):FAST_AMP_V2R_SUB")
}

# PV that sets amplifier voltage in register units 
record(longout, "$(P):FAST_AMP_RAW"){
  field(DTYP, "asynInt32")
  field(DESC, "Amplifier Voltage Raw")
  field(OUT,  "@asyn($(PORT),1)AMC$(AMC):VoltOut$(DOut)")
  field(SCAN, "Passive")
}

# Readback PV for amplifier voltage in register units 
record(longin, "$(P):FAST_AMP_RAW_RBV"){
  field(DTYP, "asynInt32")
  field(DESC, "Amplifier Voltage RBV in Raw Counts")
  field(INP,  "@asyn($(PORT),1)AMC$(AMC):VoltOut$(DOut)")
  field(SCAN, "1 second")
  field(PINI, "YES")
}

# PV that holds amplifier voltage 
record(ai, "$(P):FAST_AMP_V_RBV"){
  field(DESC, "Amplifier Voltage RBV")
  field(EGU, "V")
  field(HOPR, "1.59")
  field(LOPR,"-1.66")
  field(PREC, "2")
}

# PV that holds amplifier gain in dB
# When amplifier is bypasses, disable use of this PV.
record(ao, "$(P):FAST_AMP_GAIN") {
  field(DESC, "Amplifier Gain Requested")
  field(PINI, "NO")
  field(EGU, "dB")
  field(HOPR, "56.70")
  field(LOPR,"-27.05")
  field(DRVH, "56.70")
  field(DRVL,"-27.05")
  field(SCAN, "Passive")
  field(PREC, "2")
  field(DISV, "1")
  field(SDIS, "$(P):FAST_AMP_BYP")
  info(autosaveFields, "VAL")
  field(FLNK, "$(P):FAST_AMP_G2V")
}

# PV to enable debug mode for gain to voltage subroutine 
record(bo, "$(P):FAST_AMP_DEBUG") {
  field(DESC, "Subroutine Debug")
  field(ONAM, "DEBUG ON")
  field(ZNAM, "DEBUG OFF")
}

# PV to calculate gain to voltage  
record(aSub, "$(P):FAST_AMP_G2V") {
  field(DESC, " V calc Subroutine")
  field(INAM, "aInit")
  field(SNAM, "calcG2V")
  field(INPA, "$(P):FAST_AMP_GAIN PP")
  field(INPB, "$(P):FAST_AMP_DEBUG")
  field(OUTA, "$(P):FAST_AMP_V")
  field(FLNK, "$(P):FAST_AMP_V")
  field(PREC, "2")
  info(autosaveFields, "INPA")
}

# PV to calculate voltage to Raw 
record(sub, "$(P):FAST_AMP_V2R_SUB") {
  field(SCAN, "Passive")
  field(INPA, "32740")
  field(INPB, "18471")
  field(INPC, "-26.89")
  field(INPD, "488.8")
  field(INPE, "31.39")
  field(INPF, "0")
  field(INPG, "0")
  field(INPH, "0")
  field(INPL, "$(P):FAST_AMP_V")
  field(PREC, "4")
  field(PINI, "YES")
  field(INAM, "initPolynomial")
  field(SNAM, "calcPolynomial")
  field(FLNK, "$(P):FAST_AMP_V2R_CALC")
}

# PV to save ,voltage to register, output to PV that writes to the register
record(calcout, "$(P):FAST_AMP_V2R_CALC") {
  field(CALC, "A")
  field(INPA, "$(P):FAST_AMP_V2R_SUB.VAL")
  field(OUT,  "$(P):FAST_AMP_RAW")
  field(FLNK, "$(P):FAST_AMP_RAW")
}
 
# PV to calculate register readback to voltage readback
record(sub, "$(P):FAST_AMP_R2V_SUB") {
  field(SCAN, "Passive")
  field(INPA, "1.687")
  field(INPB, "-5.587e-05")
  field(INPC, "1.638e-09")
  field(INPD, "-1.506e-13")
  field(INPE, "6.275e-18")
  field(INPF, "-1.337e-22")
  field(INPG, "1.414e-27")
  field(INPH, "-5.862e-33")
  field(INPL, "$(P):FAST_AMP_RAW_RBV")
  field(PREC, "4")
  field(PINI, "YES")
  field(INAM, "initPolynomial")
  field(SNAM, "calcPolynomial")
  field(FLNK, "$(P):FAST_AMP_R2V_CALC")
}

# PV to save ,voltage to register, output to PV that writes to the register
record(calcout, "$(P):FAST_AMP_R2V_CALC") {
  field(CALC, "A")
  field(INPA, "$(P):FAST_AMP_R2V_SUB.VAL")
  field(OUT,  "$(P):FAST_AMP_V_RBV")
  field(FLNK, "$(P):FAST_AMP_V_RBV")
}

# This database is used to set all the necessary FW registers
# depending on the requested number of 16-bit words to be
# acquired with the DaqMux device.
#
# From the number of requested point, N, we must:
# - Set the DaqMuxV2/DataBufferSize to N/2 (as this
#   is expressed in 32-bit words,
# - Set the WaveformEngineBuffer to N*2 (as this is
#   expressed in bytes
#
# Macros:
# - P,R       : Register name as $(P):DM0_BUFFER_SIZE
# - BAY       : Bay number (0 or 1)
# - INIT_SIZE : Initial buffer size
# The macro BAY is used to specify the bay number (0 or 1)

## This in the number of words from the user (N) ##
record(ao, "$(P):DM0_BUFFER_SIZE") {
  field(SCAN, "Passive")
  field(DESC, "Bay $(AMC) buffer size (16-bit words)")
  field(EGU,  "words")
  field(PINI, "NO")
  field(OUT,  "$(P):DM0_BUFFER_SIZE-S1 PP")
  info(autosaveFields, "VAL")
}

# Sequence: set the buffer size first, and then initialize them
record(seq,   "$(P):DM0_BUFFER_SIZE-S1") {
  field(SCAN, "Passive")
  field(DOL1, "$(P):DM0_BUFFER_SIZE")         # First, set the buffer sizes
  field(LNK1, "$(P):DM0_BUFFER_SIZE-DFO1 PP")
  field(DO2,  "1")                 # Then, call the Initialize command
  field(LNK2, "$(P):DM0_BUFFER_SIZE-BO6 PP")
  field(DLY2, "0.1")
  field(SELM, "All")
  field(ASG,  "Internal")
}

# Propagate the data buffer size value
record(dfanout, "$(P):DM0_BUFFER_SIZE-DFO1") {
  field(SCAN, "Passive")
  field(OUTA, "$(P):DM0_BUFFER_SIZE_RBV PP")    # Readback value
  field(OUTB, "$(P):DM0_BUFFER_SIZE-CO2.A PP")  # DaqMux data size
  field(OUTC, "$(P):DM0_BUFFER_SIZE-CO3.A PP")  # WaveformEngineBuffer 0
  field(OUTD, "$(P):DM0_BUFFER_SIZE-CO4.A PP")  # WaveformEngineBuffer 1
  field(OUTE, "$(P):DM0_BUFFER_SIZE-CO5.A PP")  # WaveformEngineBuffer 2
  field(ASG,  "Internal")
}

## Readback value ##

record(ai, "$(P):DM0_BUFFER_SIZE_RBV") {
  field(SCAN, "Passive")
  field(DESC, "Bay $(AMC) buffer size (16-bit words)")
  field(EGU,  "words")
}

## DaqMux Data buffer size ##

# Calculate the DaqMux Data Buffer Size (N/2)
record(calcout, "$(P):DM0_BUFFER_SIZE-CO2") {
  field(SCAN, "Passive")
  field(CALC, "A/2")
  field(OUT, "$(P):DM0_BUFFER_SIZE-DO1 PP")
  field(ASG,  "Internal")
}

# This writes to the DaqMuxV2/DataBufferSize register
record(longout, "$(P):DM0_BUFFER_SIZE-DO1") {
  field(DTYP, "asynInt32")
  field(SCAN, "Passive")
  field(OUT,  "@asyn($(PORT),1)DM$(AMC)_DataBufferSize")
  field(ASG,  "Internal")
}

## WaveformEngineBuffer 0 size ##

# Calculate the buffer end address, which is
# the buffer begin address + 2*N
record(calcout, "$(P):DM0_BUFFER_SIZE-CO3") {
  field(SCAN, "Passive")
  field(INPB, "$(P):DM0_BUFFER_SIZE-DI3.VAL")
  field(CALC, "B + 2*A")
  field(OUT, "$(P):DM0_BUFFER_SIZE-DO3 PP")
  field(ASG,  "Internal")
}

# Read the buffer begin address
record(longin, "$(P):DM0_BUFFER_SIZE-DI3") {
  field(DTYP, "asynInt32")
  field(SCAN, "1 second")
  field(PINI, "YES")
  field(INP,  "@asyn($(PORT),1)WEB$(AMC)_StartAddr_0")
  field(ASG,  "Internal")
}

# This writes to the WaveformEngineBuffers/EndAddr register
record(longout, "$(P):DM0_BUFFER_SIZE-DO3") {
  field(DTYP, "asynInt32")
  field(SCAN, "Passive")
  field(OUT,  "@asyn($(PORT),1)WEB$(AMC)_EndAddr_0")
  field(ASG,  "Internal")
}

## WaveformEngineBuffer 1 size ##

# Calculate the buffer end address, which is
# the buffer begin address + 2*N
record(calcout, "$(P):DM0_BUFFER_SIZE-CO4") {
  field(SCAN, "Passive")
  field(INPB, "$(P):DM0_BUFFER_SIZE-DI4.VAL")
  field(CALC, "B + 2*A")
  field(OUT, "$(P):DM0_BUFFER_SIZE-DO4 PP")
  field(ASG,  "Internal")
}

# Read the buffer begin address
record(longin, "$(P):DM0_BUFFER_SIZE-DI4") {
  field(DTYP, "asynInt32")
  field(SCAN, "1 second")
  field(PINI, "YES")
  field(INP,  "@asyn($(PORT),1)WEB$(AMC)_StartAddr_1")
  field(ASG,  "Internal")
}

# This writes to the WaveformEngineBuffers/EndAddr register
record(longout, "$(P):DM0_BUFFER_SIZE-DO4") {
  field(DTYP, "asynInt32")
  field(SCAN, "Passive")
  field(OUT,  "@asyn($(PORT),1)WEB$(AMC)_EndAddr_1")
  field(ASG,  "Internal")
}

## WaveformEngineBuffer 2 size ##

# Calculate the buffer end address, which is
# the buffer begin address + 2*N
record(calcout, "$(P):DM0_BUFFER_SIZE-CO5") {
  field(SCAN, "Passive")
  field(INPB, "$(P):DM0_BUFFER_SIZE-DI5.VAL")
  field(CALC, "B + 2*A")
  field(OUT, "$(P):DM0_BUFFER_SIZE-DO5 PP")
  field(ASG,  "Internal")
}

# Read the buffer begin address
record(longin, "$(P):DM0_BUFFER_SIZE-DI5") {
  field(DTYP, "asynInt32")
  field(SCAN, "1 second")
  field(PINI, "YES")
  field(INP,  "@asyn($(PORT),1)WEB$(AMC)_StartAddr_2")
  field(ASG,  "Internal")
}

# This writes to the WaveformEngineBuffers/EndAddr register
record(longout, "$(P):DM0_BUFFER_SIZE-DO5") {
  field(DTYP, "asynInt32")
  field(SCAN, "Passive")
  field(OUT,  "@asyn($(PORT),1)WEB$(AMC)_EndAddr_2")
  field(ASG,  "Internal")
}

## WaveformEngineBuffer Initialize command ##

# This write to the WaveformEngineBuffers/Initialize register
record(bo,    "$(P):DM0_BUFFER_SIZE-BO6") {
  field(DTYP, "asynUInt32Digital")
  field(DESC, "Bay $(AMC) buffer initialize")
  field(SCAN, "Passive")
  field(OUT,  "@asynMask($(PORT),4,1)WEB$(AMC)_Initialize")
  field(ASG,  "Internal")
}
