#==================================================================
# 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, 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):FWSEncStat") {
    field(DTYP, "asynInt32")
    field(DESC, "Encoder Status")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(INP,  "@asyn($(PORT),0)Conf:EncStat")
}
#==================================================================
# 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):FWSLLimStat") {
    field(DTYP, "asynInt32")
    field(DESC, "LLim Status")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(INP,  "@asyn($(PORT),0)Conf:LLimStat")
}
#==================================================================
# 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):ADCStat") {
    field(DTYP, "asynInt32")
    field(DESC, "ADC Status")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(INP,  "@asyn($(PORT),0)Conf:Adc0Stat")
}
#==================================================================
# 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):EthStat") {
    field(DTYP, "asynInt32")
    field(DESC, "Eth Status")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(INP,  "@asyn($(PORT),0)Conf:EthStat")
}
#==================================================================
# 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):TimingStat") {
    field(DTYP, "asynInt32")
    field(DESC, "Timing Status")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(INP,  "@asyn($(PORT),0)Conf:TimingStat")
}
#==================================================================
# 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):ADCConfigStat") {
    field(DTYP, "asynInt32")
    field(DESC, "ADCdata config Sts")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(INP,  "@asyn($(PORT),0)Conf:ADCConfigStat")
}
#==================================================================
# Record example for an IntField, RW, 1 element, no encoding,
# enum (n-bits) register.
# It is a mbbo record with type asynUInt32Digital.
# NOTE: This example uses just 2-bits, but you can extended to
# use more bits, just add more xxVL and xxST filed accordingly.
# You must set a correct number of bits on the field NOBT
# 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<<NOBT)
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, without encoding is 1.
#==================================================================

record(mbbo,    "$(P):ADCSelect") {
    field(DTYP, "asynUInt32Digital")
    field(DESC, "ADC Installed")
    field(PINI, "NO")
    field(SCAN, "Passive")
    field(OUT,  "@asynMask($(PORT),1,3)Conf:AdcSelect")
    field(NOBT, "2")
    field(ZRVL, "0")
    field(ONVL, "1")
    field(TWVL, "2")
    field(THVL, "3")
    field(ZRST, "YES")
    field(ONST, "NA")
    field(TWST, "NA")
    field(THST, "No ADC")
}
#==================================================================
# Record example for reading back an IntField, RW, 1 element, no encoding,
# enum (n-bits) register.
# It is a mbbi record with type asynUInt32Digital.
# NOTE: This example uses just 2-bits, but you can extended to
# use more bits, just add more xxVL and xxST filed accordingly.
# You must set a correct number of bits on the field NOBT
# 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<<NOBT)
#  - ADDR  : Address based on the type of register.
#            For IntField, RW, without encoding is 1.
#==================================================================

record(mbbi,    "$(P):ADCSelectRBV") {
    field(DTYP, "asynUInt32Digital")
    field(DESC, "ADC Inserted")
    field(PINI, "YES")
    field(SCAN, "1 second")
    field(INP,  "@asynMask($(PORT),1,3)Conf:AdcSelect")
    field(NOBT, "2")
    field(ZRVL, "0")
    field(ONVL, "1")
    field(TWVL, "2")
    field(THVL, "3")
    field(ZRST, "YES")
    field(ONST, "NA")
    field(TWST, "NA")
    field(THST, "No ADC")
}
#==================================================================
# 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,      "$(PMT):PMTCHARGE") {
    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,      "$(PMT):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,      "$(PMT):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,      "$(PMT):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,      "$(PMT):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,      "$(PMT):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,      "$(PMT):CoefA0") {
    field(DTYP, "asynFloat64")
    field(DESC, "Coef A0 for PMT")
    field(PINI, "NO")
    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,      "$(PMT):CoefA1") {
    field(DTYP, "asynFloat64")
    field(DESC, "Coef A1 for PMT")
    field(PINI, "NO")
    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,      "$(PMT):CoefA2") {
    field(DTYP, "asynFloat64")
    field(DESC, "Coef A2 for PMT")
    field(PINI, "NO")
    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,      "$(PMT):CoefOff") {
    field(DTYP, "asynFloat64")
    field(DESC, "Coef Offset for PMT")
    field(PINI, "NO")
    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,      "$(PMT):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,      "$(PMT):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,      "$(PMT):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,      "$(PMT):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")
}
#==================================================================
# Record example for an IntField Stream port.
# It is a waveform record with type asynInt32ArrayIn.
# SCAN must be "I/O Intr" for streaming interfaces.
# 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 an stream it is 5.
#==================================================================

record(waveform,    "$(PMT):FAST_RAW_WF") {
    field(DTYP,     "asynInt32ArrayIn")
    field(DESC,     "PMT waveform (32-bit)")
    field(PINI,     "NO")
    field(SCAN,     "I/O Intr")
    field(NELM,     "1000")
    field(FTVL,     "LONG")
    field(INP,      "@asyn($(PORT),5)AMC$(AMC):StreamRaw")
}
#============================================================================
# Record example for an IntField Stream port.
# For Stream ports, an additional parameter is automatically created
# and the name is generated adding ":16" to the original parameter name
# This gives access to the same stream data, but as 16-bit words which
# is the case for ADC samples for example.
# For this case it is a waveform record with type asynInt16ArrayIn
# 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
#  - PARM  : The asyn parameter name. It must be defined in the
#            dictionary file and assigned to a register. In this case it is
#            the original parameter name with a suffix ":16".
#  - ADDR  : Address based on the type of register.
#            For an stream it is 5.
#============================================================================

record(waveform,    "$(PMT):FAST_RAW_WF_S16") {
    field(DTYP,     "asynInt16ArrayIn")
    field(DESC,     "PMT waveform (s16-bit)")
    field(PINI,     "NO")
    field(SCAN,     "I/O Intr")
    field(NELM,     "2000")
    field(FTVL,     "SHORT")
    field(INP,      "@asyn($(PORT),5)AMC$(AMC):StreamRaw:16")
}
# Create a waveform with the sampling time. This will be the X axis of the
# waveform.
record (aSub, "$(P):FAST_WF_TIME") {
  field(SNAM, "calcTimeArray")
  field(FTA, "LONG")
  field(FTVA, "DOUBLE")
  field(NOA, "2020")
  field(NOVA, "2020")
  field(INPA, "$(P):ClkFreq CP")
}

# 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 an unsiged 16 bit array from a signed array
record (aSub, "$(P):FAST_RAW_WF_U16") {
  field(DESC, "Slow raw waveform")
  field(SNAM, "calcRWF16")
  field(INPA, "$(P):FAST_RAW_WF_S16")
  field(NOA, "1024")
  field(NOVA, "1024")
  field(FTA, "SHORT")
  field(FTVA, "SHORT")
  field(SCAN, "1 second") 
}

# Calculate the time correspondent to the number of samples of the pre-edge
# of the weight function
record (calc, "$(P):TIME_PRE_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):TIME_MID_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):TIME_POS_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):TIME_PRE") {
  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):TIME_PRE 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):TIME_MID") {
  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):TIME_PRE CP")
  field(INPB, "$(P):TIME_MID 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):TIME_POS") {
  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):TIME_POS CP")
  field(INPB, "$(P):ClkFreq CP")
  field(CALC, "((~0)-1)&FLOOR((2*A*B)/1000000000)")
  field(OUT, "$(P):NumSamp1 PP")
  field(DOPT, "Use CALC")
}

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

# 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_RAW_WF_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_RAW_WF_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_RAW_WF_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_RAW_WF_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_RAW_WF_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_RAW_WF_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_RAW_WF_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")
}
