##############################################################################
## This file is part of 'SLAC Firmware Standard Library'.
## It is subject to the license terms in the LICENSE.txt file found in the 
## top-level directory of this distribution and at: 
##    https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. 
## No part of 'SLAC Firmware Standard Library', including this file, 
## may be copied, modified, propagated, or distributed except according to 
## the terms contained in the LICENSE.txt file.
##############################################################################
#schemaversion 3.0.0
#once AmcBay1Core.yaml
#include JesdRx.yaml
#include Lmk04828.yaml
#include Adc16Dx370.yaml
#include AttHMC624.yaml
#include DacLtc2000.yaml
#include LvdsSigGen.yaml
#include SigGenRam.yaml

AmcBay1Core: &AmcBay1Core 
  description: "AMC1 LLRF Module (SD-376-396-17)"
  size: 0x00800000
  class: MMIODev
  configPrio: 1
  ########
  children:
  ########
    JesdRx:
      <<: *JesdRx
      at:
        offset: 0x00000000  
    ##################################################     
    Adc16Dx370:
      <<: *Adc16Dx370
      name: "Adc16Dx370"
      at:
        offset: 0x00100000 
        nelms:  3
        stride: 0x00100000 
    ##################################################     
    Lmk04828:
      <<: *Lmk04828
      at:
        offset: 0x00400000     
    ##################################################     
    DacLtc200:
      <<: *DacLtc2000
      at:
        offset: 0x00500000     
    ##################################################
    AttHMC624:
      <<: *AttHMC624
      at:
        offset: 0x00600000 
        nelms: 4
        stride: 0x10
    ##################################################
    LvdsSigGen:
      <<: *LvdsSigGen
      at:
        offset: 0x00700000 
    ################################################## 
    SigGenRam:
      <<: *SigGenRam
      at:
        offset: 0x00710000
    ##################################################
    InitAmcBay1:
      description: "Initialization for AMC card's JESD modules"
      class: SequenceCommand
      at:
        offset: 0x0
      sequence:
        # Put the RX's GTs into RESET
        - entry: JesdRx/ResetGTs
          value: 0x1       
        # Calibrate the JESD ADCs
        - entry: Adc16Dx370/CalibrateAdc
          value: 0x1       
        # 1000 ms sleep
        # - entry: usleep
          # value: 1000000       

        # Power up the LMK's SYSREF
        # - entry: Lmk04828/PwrUpSysRef
          # value: 0x1       
        # 1000 ms sleep
        # - entry: usleep
          # value: 1000000    

        # Clear the Alarms
        # - entry: Lmk04828/InitLmk          
          # value: 0x1
          
        # 1000 ms sleep
        - entry: usleep
          value: 1000000  

        # Release the RX's GTs RESET
        - entry: JesdRx/ResetGTs
          value: 0x0
        # Clear errors to have a fresh start
        - entry: JesdRx/ClearRxErrors
          value: 0x1           
    ##################################################
