#-----------------------------------------------------------------------------
# This file is part of the '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 the '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.
#-----------------------------------------------------------------------------

import surf.xilinx

class ClockManager(surf.xilinx.ClockManager):
    def __init__(self,**kwargs):
        super().__init__(**kwargs)

        @self.command(description="Sets the 85 MHz configuration",)
        def Config85MHz():
            self.POWER.set(0xffff)
            self.PHASE_MUX[0].set(0x0)
            self.HIGH_TIME[0].set(0x7)
            self.LOW_TIME[0].set(0x7)
            self.PHASE_MUX[1].set(0x0)
            self.HIGH_TIME[1].set(0x1)
            self.LOW_TIME[1].set(0x1)
            self.PHASE_MUX[2].set(0x0)
            self.HIGH_TIME[2].set(0x1)
            self.LOW_TIME[2].set(0x1)
            self.PHASE_MUX[3].set(0x0)
            self.HIGH_TIME[3].set(0x1)
            self.LOW_TIME[3].set(0x1)
            self.PHASE_MUX[4].set(0x0)
            self.HIGH_TIME[4].set(0x1)
            self.LOW_TIME[4].set(0x1)
            self.PHASE_MUX[5].set(0x0)
            self.HIGH_TIME[5].set(0x1)
            self.LOW_TIME[5].set(0x1)
            self.PHASE_MUX[6].set(0x0)
            self.HIGH_TIME[6].set(0x1)
            self.LOW_TIME[6].set(0x1)
            self.PHASE_MUX_FB.set(0x0)
            self.HIGH_TIME_FB.set(0x7)
            self.LOW_TIME_FB.set(0x7)
            self.FRAC[0].set(0x0)
            self.FRAC_EN[0].set(0x0)
            self.FRAC_WF_R[0].set(0x0)
            self.MX[0].set(0x0)
            self.EDGE[0].set(0x0)
            self.NO_COUNT[0].set(0x0)
            self.DELAY_TIME[0].set(0x0)
            self.MX[1].set(0x0)
            self.EDGE[1].set(0x0)
            self.NO_COUNT[1].set(0x0)
            self.DELAY_TIME[1].set(0x0)
            self.MX[2].set(0x0)
            self.EDGE[2].set(0x0)
            self.NO_COUNT[2].set(0x1)
            self.DELAY_TIME[2].set(0x0)
            self.MX[3].set(0x0)
            self.EDGE[3].set(0x0)
            self.NO_COUNT[3].set(0x1)
            self.DELAY_TIME[3].set(0x0)
            self.MX[4].set(0x0)
            self.EDGE[4].set(0x0)
            self.NO_COUNT[4].set(0x1)
            self.DELAY_TIME[4].set(0x0)
            self.PHASE_MUX_F_CLKOUT[0].set(0x0)
            self.FRAC_WF_F_CLKOUT[0].set(0x0)
            self.MX[5].set(0x0)
            self.EDGE[5].set(0x0)
            self.NO_COUNT[5].set(0x1)
            self.DELAY_TIME[5].set(0x0)
            self.PHASE_MUX_F_CLKOUT_FB.set(0x0)
            self.FRAC_WF_F_CLKOUT_FB.set(0x0)
            self.MX[6].set(0x0)
            self.EDGE[6].set(0x0)
            self.NO_COUNT[6].set(0x1)
            self.DELAY_TIME[6].set(0x0)
            self.FRAC_FB.set(0x0)
            self.FRAC_EN_FB.set(0x0)
            self.FRAC_WF_R_FB.set(0x0)
            self.MX_FB.set(0x0)
            self.EDGE_FB.set(0x0)
            self.NO_COUNT_FB.set(0x0)
            self.DELAY_TIME_FB.set(0x0)
            self.EDGE_DIV.set(0x0)
            self.NO_COUNT_DIV.set(0x1)
            self.HIGH_TIME_DIV.set(0x1)
            self.LOW_TIME_DIV.set(0x1)
            self.LockReg[0].set(0x2bc)
            self.LockReg[1].set(0x7c01)
            self.LockReg[2].set(0xffe9)
            self.FiltReg[0].set(0x9908)
            self.FiltReg[1].set(0x8100)

        @self.command(description="Sets the 50 MHz configuration",)
        def Config50MHz():
            self.POWER.set(0xffff)
            self.PHASE_MUX[0].set(0x0)
            self.HIGH_TIME[0].set(0x7)
            self.LOW_TIME[0].set(0x7)
            self.PHASE_MUX[1].set(0x0)
            self.HIGH_TIME[1].set(0x1)
            self.LOW_TIME[1].set(0x1)
            self.PHASE_MUX[2].set(0x0)
            self.HIGH_TIME[2].set(0x1)
            self.LOW_TIME[2].set(0x1)
            self.PHASE_MUX[3].set(0x0)
            self.HIGH_TIME[3].set(0x1)
            self.LOW_TIME[3].set(0x1)
            self.PHASE_MUX[4].set(0x0)
            self.HIGH_TIME[4].set(0x1)
            self.LOW_TIME[4].set(0x1)
            self.PHASE_MUX[5].set(0x0)
            self.HIGH_TIME[5].set(0x1)
            self.LOW_TIME[5].set(0x1)
            self.PHASE_MUX[6].set(0x0)
            self.HIGH_TIME[6].set(0x1)
            self.LOW_TIME[6].set(0x1)
            self.PHASE_MUX_FB.set(0x0)
            self.HIGH_TIME_FB.set(0x7)
            self.LOW_TIME_FB.set(0x7)
            self.FRAC[0].set(0x0)
            self.FRAC_EN[0].set(0x0)
            self.FRAC_WF_R[0].set(0x0)
            self.MX[0].set(0x0)
            self.EDGE[0].set(0x0)
            self.NO_COUNT[0].set(0x0)
            self.DELAY_TIME[0].set(0x0)
            self.MX[1].set(0x0)
            self.EDGE[1].set(0x0)
            self.NO_COUNT[1].set(0x0)
            self.DELAY_TIME[1].set(0x0)
            self.MX[2].set(0x0)
            self.EDGE[2].set(0x0)
            self.NO_COUNT[2].set(0x1)
            self.DELAY_TIME[2].set(0x0)
            self.MX[3].set(0x0)
            self.EDGE[3].set(0x0)
            self.NO_COUNT[3].set(0x1)
            self.DELAY_TIME[3].set(0x0)
            self.MX[4].set(0x0)
            self.EDGE[4].set(0x0)
            self.NO_COUNT[4].set(0x1)
            self.DELAY_TIME[4].set(0x0)
            self.PHASE_MUX_F_CLKOUT[0].set(0x0)
            self.FRAC_WF_F_CLKOUT[0].set(0x0)
            self.MX[5].set(0x0)
            self.EDGE[5].set(0x0)
            self.NO_COUNT[5].set(0x1)
            self.DELAY_TIME[5].set(0x0)
            self.PHASE_MUX_F_CLKOUT_FB.set(0x0)
            self.FRAC_WF_F_CLKOUT_FB.set(0x0)
            self.MX[6].set(0x0)
            self.EDGE[6].set(0x0)
            self.NO_COUNT[6].set(0x1)
            self.DELAY_TIME[6].set(0x0)
            self.FRAC_FB.set(0x0)
            self.FRAC_EN_FB.set(0x0)
            self.FRAC_WF_R_FB.set(0x0)
            self.MX_FB.set(0x0)
            self.EDGE_FB.set(0x0)
            self.NO_COUNT_FB.set(0x0)
            self.DELAY_TIME_FB.set(0x0)
            self.EDGE_DIV.set(0x0)
            self.NO_COUNT_DIV.set(0x1)
            self.HIGH_TIME_DIV.set(0x1)
            self.LOW_TIME_DIV.set(0x1)
            self.LockReg[0].set(0x2bc)
            self.LockReg[1].set(0x7c01)
            self.LockReg[2].set(0xffe9)
            self.FiltReg[0].set(0x9908)
            self.FiltReg[1].set(0x8100)

        @self.command(description="Sets the 40 MHz configuration",)
        def Config40MHz():
            self.POWER.set(0xffff)
            self.PHASE_MUX[0].set(0x0)
            self.HIGH_TIME[0].set(0xe)
            self.LOW_TIME[0].set(0xe)
            self.PHASE_MUX[1].set(0x0)
            self.HIGH_TIME[1].set(0x2)
            self.LOW_TIME[1].set(0x2)
            self.PHASE_MUX[2].set(0x0)
            self.HIGH_TIME[2].set(0x1)
            self.LOW_TIME[2].set(0x1)
            self.PHASE_MUX[3].set(0x0)
            self.HIGH_TIME[3].set(0x1)
            self.LOW_TIME[3].set(0x1)
            self.PHASE_MUX[4].set(0x0)
            self.HIGH_TIME[4].set(0x1)
            self.LOW_TIME[4].set(0x1)
            self.PHASE_MUX[5].set(0x0)
            self.HIGH_TIME[5].set(0x1)
            self.LOW_TIME[5].set(0x1)
            self.PHASE_MUX[6].set(0x0)
            self.HIGH_TIME[6].set(0x1)
            self.LOW_TIME[6].set(0x1)
            self.PHASE_MUX_FB.set(0x0)
            self.HIGH_TIME_FB.set(0xe)
            self.LOW_TIME_FB.set(0xe)
            self.FRAC[0].set(0x0)
            self.FRAC_EN[0].set(0x0)
            self.FRAC_WF_R[0].set(0x0)
            self.MX[0].set(0x0)
            self.EDGE[0].set(0x0)
            self.NO_COUNT[0].set(0x0)
            self.DELAY_TIME[0].set(0x0)
            self.MX[1].set(0x0)
            self.EDGE[1].set(0x0)
            self.NO_COUNT[1].set(0x0)
            self.DELAY_TIME[1].set(0x0)
            self.MX[2].set(0x0)
            self.EDGE[2].set(0x0)
            self.NO_COUNT[2].set(0x1)
            self.DELAY_TIME[2].set(0x0)
            self.MX[3].set(0x0)
            self.EDGE[3].set(0x0)
            self.NO_COUNT[3].set(0x1)
            self.DELAY_TIME[3].set(0x0)
            self.MX[4].set(0x0)
            self.EDGE[4].set(0x0)
            self.NO_COUNT[4].set(0x1)
            self.DELAY_TIME[4].set(0x0)
            self.PHASE_MUX_F_CLKOUT[0].set(0x0)
            self.FRAC_WF_F_CLKOUT[0].set(0x0)
            self.MX[5].set(0x0)
            self.EDGE[5].set(0x0)
            self.NO_COUNT[5].set(0x1)
            self.DELAY_TIME[5].set(0x0)
            self.PHASE_MUX_F_CLKOUT_FB.set(0x0)
            self.FRAC_WF_F_CLKOUT_FB.set(0x0)
            self.MX[6].set(0x0)
            self.EDGE[6].set(0x0)
            self.NO_COUNT[6].set(0x1)
            self.DELAY_TIME[6].set(0x0)
            self.FRAC_FB.set(0x0)
            self.FRAC_EN_FB.set(0x0)
            self.FRAC_WF_R_FB.set(0x0)
            self.MX_FB.set(0x0)
            self.EDGE_FB.set(0x0)
            self.NO_COUNT_FB.set(0x0)
            self.DELAY_TIME_FB.set(0x0)
            self.EDGE_DIV.set(0x0)
            self.NO_COUNT_DIV.set(0x1)
            self.HIGH_TIME_DIV.set(0x1)
            self.LOW_TIME_DIV.set(0x1)
            self.LockReg[0].set(0x15e)
            self.LockReg[1].set(0x7c01)
            self.LockReg[2].set(0xffe9)
            self.FiltReg[0].set(0x908)
            self.FiltReg[1].set(0x1000)

        @self.command(description="Sets the 25 MHz configuration",)
        def Config25MHz():
            self.POWER.set(0xffff)
            self.PHASE_MUX[0].set(0x0)
            self.HIGH_TIME[0].set(0x15)
            self.LOW_TIME[0].set(0x15)
            self.PHASE_MUX[1].set(0x0)
            self.HIGH_TIME[1].set(0x3)
            self.LOW_TIME[1].set(0x3)
            self.PHASE_MUX[2].set(0x0)
            self.HIGH_TIME[2].set(0x1)
            self.LOW_TIME[2].set(0x1)
            self.PHASE_MUX[3].set(0x0)
            self.HIGH_TIME[3].set(0x1)
            self.LOW_TIME[3].set(0x1)
            self.PHASE_MUX[4].set(0x0)
            self.HIGH_TIME[4].set(0x1)
            self.LOW_TIME[4].set(0x1)
            self.PHASE_MUX[5].set(0x0)
            self.HIGH_TIME[5].set(0x1)
            self.LOW_TIME[5].set(0x1)
            self.PHASE_MUX[6].set(0x0)
            self.HIGH_TIME[6].set(0x1)
            self.LOW_TIME[6].set(0x1)
            self.PHASE_MUX_FB.set(0x0)
            self.HIGH_TIME_FB.set(0x15)
            self.LOW_TIME_FB.set(0x15)
            self.FRAC[0].set(0x0)
            self.FRAC_EN[0].set(0x0)
            self.FRAC_WF_R[0].set(0x0)
            self.MX[0].set(0x0)
            self.EDGE[0].set(0x0)
            self.NO_COUNT[0].set(0x0)
            self.DELAY_TIME[0].set(0x0)
            self.MX[1].set(0x0)
            self.EDGE[1].set(0x0)
            self.NO_COUNT[1].set(0x0)
            self.DELAY_TIME[1].set(0x0)
            self.MX[2].set(0x0)
            self.EDGE[2].set(0x0)
            self.NO_COUNT[2].set(0x1)
            self.DELAY_TIME[2].set(0x0)
            self.MX[3].set(0x0)
            self.EDGE[3].set(0x0)
            self.NO_COUNT[3].set(0x1)
            self.DELAY_TIME[3].set(0x0)
            self.MX[4].set(0x0)
            self.EDGE[4].set(0x0)
            self.NO_COUNT[4].set(0x1)
            self.DELAY_TIME[4].set(0x0)
            self.PHASE_MUX_F_CLKOUT[0].set(0x0)
            self.FRAC_WF_F_CLKOUT[0].set(0x0)
            self.MX[5].set(0x0)
            self.EDGE[5].set(0x0)
            self.NO_COUNT[5].set(0x1)
            self.DELAY_TIME[5].set(0x0)
            self.PHASE_MUX_F_CLKOUT_FB.set(0x0)
            self.FRAC_WF_F_CLKOUT_FB.set(0x0)
            self.MX[6].set(0x0)
            self.EDGE[6].set(0x0)
            self.NO_COUNT[6].set(0x1)
            self.DELAY_TIME[6].set(0x0)
            self.FRAC_FB.set(0x0)
            self.FRAC_EN_FB.set(0x0)
            self.FRAC_WF_R_FB.set(0x0)
            self.MX_FB.set(0x0)
            self.EDGE_FB.set(0x0)
            self.NO_COUNT_FB.set(0x0)
            self.DELAY_TIME_FB.set(0x0)
            self.EDGE_DIV.set(0x0)
            self.NO_COUNT_DIV.set(0x1)
            self.HIGH_TIME_DIV.set(0x1)
            self.LOW_TIME_DIV.set(0x1)
            self.LockReg[0].set(0xfa)
            self.LockReg[1].set(0x7c01)
            self.LockReg[2].set(0xffe9)
            self.FiltReg[0].set(0x808)
            self.FiltReg[1].set(0x8000)
