def __init__(
            self,
            dataDebug=False,
            dev='/dev/datadev_0',  # path to PCIe device
            enLclsI=True,
            enLclsII=False,
            startupMode=False,  # False = LCLS-I timing mode, True = LCLS-II timing mode
            standAloneMode=False,  # False = using fiber timing, True = locally generated timing
            pgp3=False,  # true = PGPv3, false = PGP2b
            pollEn=True,  # Enable automatic polling registers
            initRead=True,  # Read all registers at start of the system
            numLanes=4,  # Number of PGP lanes
            camType=None,
            defaultFile=None,
            enableDump=False,
            clDevTarget=clDev.ClinkDevKcu1500,
            **kwargs):

        # Set the firmware Version lock = firmware/targets/shared_version.mk
        self.FwVersionLock = 0x04090000

        # Set number of lanes to min. requirement
        if numLanes > len(camType):
            laneSize = len(camType)
        else:
            laneSize = numLanes

        # Set local variables
        self.camType = [camType[i] for i in range(laneSize)]
        self.defaultFile = defaultFile
        self.dev = dev
        self.startupMode = startupMode
        self.standAloneMode = standAloneMode
        self.enableDump = enableDump

        # Check for simulation
        if dev == 'sim':
            kwargs['timeout'] = 100000000  # 100 s
        else:
            kwargs['timeout'] = 5000000  # 5 s

        # Pass custom value to parent via super function
        super().__init__(dev=dev,
                         pgp3=pgp3,
                         pollEn=pollEn,
                         initRead=initRead,
                         numLanes=laneSize,
                         **kwargs)

        # Unhide the RemoteVariableDump command
        self.RemoteVariableDump.hidden = False

        # Create memory interface
        self.memMap = axipcie.createAxiPcieMemMap(dev, 'localhost', 8000)
        self.memMap.setName('PCIe_Bar0')

        # Instantiate the top level Device and pass it the memory map
        self.add(
            clDevTarget(
                name='ClinkPcie',
                memBase=self.memMap,
                numLanes=laneSize,
                pgp3=pgp3,
                enLclsI=enLclsI,
                enLclsII=enLclsII,
                expand=True,
            ))

        # CLink SRP, CLink serial
        destList = [0, 2]

        # Create DMA streams
        self.dmaStreams = axipcie.createAxiPcieDmaStreams(
            dev,
            {lane: {dest
                    for dest in destList}
             for lane in range(laneSize)}, 'localhost', 8000)

        # Check if not doing simulation
        if (dev != 'sim'):

            # Create arrays to be filled
            self._srp = [None for lane in range(laneSize)]

            # Create the stream interface
            for lane in range(laneSize):

                # SRP
                self._srp[lane] = rogue.protocols.srp.SrpV3()
                self._srp[lane].setName(f'SRPv3[{lane}]')
                pr.streamConnectBiDir(self.dmaStreams[lane][0],
                                      self._srp[lane])

                # CameraLink Feb Board
                self.add(
                    feb.ClinkFeb(
                        name=(f'ClinkFeb[{lane}]'),
                        memBase=self._srp[lane],
                        serial=self.dmaStreams[lane][2],
                        camType=self.camType[lane],
                        version3=pgp3,
                        enableDeps=[
                            self.ClinkPcie.Hsio.PgpMon[lane].RxRemLinkReady
                        ],  # Only allow access if the PGP link is established
                        expand=True,
                    ))

        # Else doing Rogue VCS simulation
        else:
            self.roguePgp = shared.RogueStreams(numLanes=laneSize, pgp3=pgp3)

            # Create arrays to be filled
            self._frameGen = [None for lane in range(laneSize)]

            # Create the stream interface
            for lane in range(laneSize):

                # Create the frame generator
                self._frameGen[lane] = MyCustomMaster()

                # Connect the frame generator
                print(self.roguePgp.pgpStreams)
                self._frameGen[lane] >> self.roguePgp.pgpStreams[lane][1]

                # Create a command to execute the frame generator
                self.add(
                    pr.BaseCommand(
                        name=f'GenFrame[{lane}]',
                        function=lambda cmd, lane=lane: self._frameGen[lane].
                        myFrameGen(),
                    ))

                # Create a command to execute the frame generator. Accepts user data argument
                self.add(
                    pr.BaseCommand(
                        name=f'GenUserFrame[{lane}]',
                        function=lambda cmd, lane=lane: self._frameGen[lane].
                        myFrameGen,
                    ))

        # Create arrays to be filled
        self._dbg = [None for lane in range(laneSize)]
        self.unbatchers = [
            rogue.protocols.batcher.SplitterV1() for lane in range(laneSize)
        ]

        # Create the stream interface
        for lane in range(laneSize):
            # Debug slave
            if dataDebug:
                # Connect the streams
                self.dmaStreams[lane][1] >> self.unbatchers[lane] >> self._dbg[
                    lane]

        self.add(
            pr.LocalVariable(
                name='RunState',
                description=
                'Run state status, which is controlled by the StopRun() and StartRun() commands',
                mode='RO',
                value=False,
            ))

        @self.command(
            description='Stops the triggers and blows off data in the pipeline'
        )
        def StopRun():
            print('ClinkDev.StopRun() executed')

            # Get devices
            eventBuilder = self.find(typ=batcher.AxiStreamBatcherEventBuilder)
            trigger = self.find(typ=l2si.TriggerEventBuffer)

            # Turn off the triggering
            for devPtr in trigger:
                devPtr.MasterEnable.set(False)

            # Flush the downstream data/trigger pipelines
            for devPtr in eventBuilder:
                devPtr.Blowoff.set(True)

            # Update the run state status variable
            self.RunState.set(False)

        @self.command(
            description=
            'starts the triggers and allow steams to flow to DMA engine')
        def StartRun():
            print('ClinkDev.StartRun() executed')

            # Get devices
            eventBuilder = self.find(typ=batcher.AxiStreamBatcherEventBuilder)
            trigger = self.find(typ=l2si.TriggerEventBuffer)

            # Reset all counters
            self.CountReset()

            # Arm for data/trigger stream
            for devPtr in eventBuilder:
                devPtr.Blowoff.set(False)
                devPtr.SoftRst()

            # Turn on the triggering
            for devPtr in trigger:
                devPtr.MasterEnable.set(True)

            # Update the run state status variable
            self.RunState.set(True)
Esempio n. 2
0
    def __init__(self, serial=None, **kwargs):
        super().__init__(**kwargs)

        # Attach the serial devices
        self._rx = clink.UartUp900cl12bRx(self.path)
        pr.streamConnect(serial,self._rx)

        self._tx = clink.ClinkSerialTx(self.path)
        pr.streamConnect(self._tx,serial)

        @self.command(value='', name='SendString', description='Send a command string')
        def sendString(arg):
            if self._tx is not None:
                self._tx.sendString(arg)

        ##############################
        # Variables
        ##############################

        self.add(pr.LocalVariable(
            name         = 'RU',
            description  = 'Recall user page: Must have a number after “ru” such as 1, 2, 3 or 4',
            mode         = 'RW',
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'ru{value}') if value!='' else ''
        ))

        self.add(pr.BaseCommand(
            name         = 'RP',
            description  = 'Report current camera setting',
            function     = lambda cmd: self._tx.sendString('rp')
        ))

        self.add(pr.BaseCommand(
            name         = 'RF',
            description  = 'Recall factory setting page',
            function     = lambda cmd: self._tx.sendString('rf')
        ))

        self.add(pr.LocalVariable(
            name         = 'SM',
            description  = 'Shutter mode: Must have a number after sm (1 ~ f), refer to section 3.3 for details.',
            mode         = 'RW',
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'sm{value}') if value!='' else ''
        ))

        self.add(pr.LocalVariable(
            name         = 'SP',
            description  = 'Save user page: There are 4 user page available',
            mode         = 'RW',
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'sp{value}') if value!='' else ''
        ))

        self.add(pr.BaseCommand(
            name         = 'NS',
            description  = 'Normal speed: Refer to camera specifications',
            function     = lambda cmd: self._tx.sendString('ns')
        ))

        self.add(pr.BaseCommand(
            name         = 'DS',
            description  = 'Double speed: Refer to camera specifications',
            function     = lambda cmd: self._tx.sendString('ds')
        ))

        self.add(pr.BaseCommand(
            name         = 'NM',
            description  = 'Normal mode: Normal free running',
            function     = lambda cmd: self._tx.sendString('nm')
        ))

        self.add(pr.BaseCommand(
            name         = 'AM',
            description  = 'Asynchronous mode: Asynchronous reset',
            function     = lambda cmd: self._tx.sendString('am')
        ))

        self.add(pr.LocalVariable(
            name         = 'GI',
            description  = 'Gain increase: ### = Hexadecimals (000 ~ 3ff). If no number entered, gain will be increased by factor of 1. If a number is entered, then number will be added to stored gain.',
            mode         = 'RW',
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'gi{value}') if value!='' else ''
        ))

        self.add(pr.LocalVariable(
            name         = 'GD',
            description  = 'Gain decrease: ### = Hexadecimals (000 ~ 3ff). Same as gi, except it will be decreased.',
            mode         = 'RW',
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'gd{value}') if value!='' else ''
        ))

        self.add(pr.LocalVariable(
            name         = 'GN',
            description  = 'Gain number: ### = Hexadecimals (000 ~ 3ff). Refer to the gain curves below for details',
            mode         = 'RW',
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'gn{value}') if value!='' else ''
        ))

        self.add(pr.LocalVariable(
            name         = 'BI',
            description  = 'Reference increase: ### = Hexadecimals (000 ~ 3ff). If no number entered, reference will be increased by factor of 1. If a number is entered, then number will be added to stored reference. Note: It’s very uncommon to change reference level, contact UNIQ for further details.',
            mode         = 'RW',
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'bi{value}') if value!='' else ''
        ))

        self.add(pr.LocalVariable(
            name         = 'BD',
            description  = 'Reference decrease: ### = Hexadecimals (000 ~ 3ff). If no number entered, reference will be increased by factor of 1. If a number is entered, then number will be added to stored reference. Note: It’s very uncommon to change reference level, contact UNIQ for further details.',
            mode         = 'RW',
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'bd{value}') if value!='' else ''
        ))

        self.add(pr.LocalVariable(
            name         = 'BN',
            description  = 'Reference number: ### = Hexadecimals (000 ~ 3ff). If no number entered, reference will be increased by factor of 1. If a number is entered, then number will be added to stored reference. Note: It’s very uncommon to change reference level, contact UNIQ for further details.',
            mode         = 'RW',
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'bn{value}') if value!='' else ''
        ))
Esempio n. 3
0
    def __init__(
            self,
            name='TimeToolDev',
            description='Container for TimeTool Dev',
            dataDebug=False,
            dev='/dev/datadev_0',  # path to PCIe device
            version3=False,  # true = PGPv3, false = PGP2b
            pollEn=True,  # Enable automatic polling registers
            initRead=True,  # Read all registers at start of the system
            numLane=1,  # Number of PGP lanes
            **kwargs):
        super().__init__(name=name,
                         description=description,
                         dev=dev,
                         version3=version3,
                         pollEn=pollEn,
                         initRead=initRead,
                         numLane=numLane,
                         **kwargs)

        # Check if not doing simulation
        if (dev != 'sim'):

            # Create arrays to be filled
            self._srp = [None for lane in range(numLane)]

            # Create the stream interface
            for lane in range(numLane):

                # SRP
                self._srp[lane] = rogue.protocols.srp.SrpV3()
                pr.streamConnectBiDir(self._dma[lane][0], self._srp[lane])

                # CameraLink Feb Board
                self.add(
                    feb.ClinkFeb(
                        name=(f'ClinkFeb[{lane}]'),
                        memBase=self._srp[lane],
                        serial=[self._dma[lane][2], None],
                        camType=['Piranha4', None],
                        version3=version3,
                        enableDeps=[
                            self.Hardware.PgpMon[lane].RxRemLinkReady
                        ],  # Only allow access if the PGP link is established
                        # expand      = False,
                    ))

        # Else doing Rogue VCS simulation
        else:

            # Create arrays to be filled
            self._frameGen = [None for lane in range(numLane)]

            # Create the stream interface
            for lane in range(numLane):

                # Create the frame generator
                self._frameGen[lane] = MyCustomMaster()

                # Connect the frame generator
                pr.streamConnect(self._frameGen[lane], self._pgp[lane][1])

                # Create a command to execute the frame generator
                self.add(
                    pr.BaseCommand(
                        name=f'GenFrame[{lane}]',
                        function=lambda cmd: self._frameGen[lane].myFrameGen(),
                    ))

        # Create arrays to be filled
        self._dbg = [None for lane in range(numLane)]

        # Create the stream interface
        for lane in range(numLane):
            # Debug slave
            if dataDebug:
                self._dbg[lane] = TimeToolRx(expand=False)
                pr.streamTap(self._dma[lane][1], self._dbg[lane])
                self.add(self._dbg)

        # Time tool application
        self.add(
            timeTool.Application(
                memBase=self._memMap,
                offset=0x00C00000,
                numLane=numLane,
            ))

        # Start the system
        self.start(
            pollEn=self._pollEn,
            initRead=self._initRead,
            timeout=self._timeout,
        )

        # Check if not simulation
        if (dev != 'sim'):
            # Read all the variables
            self.ReadAll()
            # Some initialization after starting root
            for lane in range(numLane):
                self.ClinkFeb[lane].ClinkTop.Ch[0].BaudRate.set(9600)
                self.ClinkFeb[lane].ClinkTop.Ch[0].SerThrottle.set(10000)
                self.ClinkFeb[lane].ClinkTop.Ch[0].LinkMode.setDisp('Full')
                self.ClinkFeb[lane].ClinkTop.Ch[0].DataMode.setDisp('8Bit')
                self.ClinkFeb[lane].ClinkTop.Ch[0].FrameMode.setDisp('Line')
                self.ClinkFeb[lane].ClinkTop.Ch[0].TapCount.set(8)
                self.ClinkFeb[lane].ClinkTop.Ch[0].UartPiranha4.SendEscape()
                self.ClinkFeb[lane].ClinkTop.Ch[0].UartPiranha4.SPF.setDisp(
                    '0')
                self.ClinkFeb[lane].ClinkTop.Ch[0].UartPiranha4.GCP()
        else:
            # Disable the PGP PHY device (speed up the simulation)
            self.Hardware.enable.set(False)
            self.Hardware.hidden = True
            # Bypass the time AXIS channel
            eventDev = self.find(typ=batcher.AxiStreamBatcherEventBuilder)
            for dev in eventDev:
                dev.Bypass.set(0x1)
Esempio n. 4
0
    def __init__(   self,       
            name        = 'UartPiranha4',
            description = 'Uart Piranha4 channel access',
            serial      = None,
            **kwargs):
        super().__init__(name=name, description=description, **kwargs) 

        # Attach the serial devices
        self._rx = clink.ClinkSerialRx()
        pr.streamConnect(serial,self._rx)

        self._tx = clink.ClinkSerialTx()
        pr.streamConnect(self._tx,serial)
        
        @self.command(value='', name='SendString', description='Send a command string')
        def sendString(arg):
            if self._tx is not None:
                self._tx.sendString(arg)

        ##############################
        # Variables
        ##############################        
        
        self.add(pr.LocalVariable(    
            name         = 'CCF',
            description  = 'Calibrate user FPN dark flat field coefficients',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'ccf {value}') if value!='' else ''
        ))
        
        self.add(pr.LocalVariable(    
            name         = 'CLS',
            description  = 'Camera Link clock frequency',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'cls {value}') if value!='' else ''
        )) 

        self.add(pr.LocalVariable(    
            name         = 'CLM',
            description  = 'Camera Link Mode',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'clm {value}') if value!='' else ''
        )) 

        self.add(pr.LocalVariable(    
            name         = 'CPA[0]',
            description  = 'Calibrate user PRNU flat field coefficients: Algorithm Argument',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'cpa {self.CPA[0].get()} {self.CPA[1].get()} {self.CPA[2].get()}') if (self.CPA[0].get()!='' and self.CPA[1].get()!='' and self.CPA[2].get()!='') else ''
        ))          
        
        self.add(pr.LocalVariable(    
            name         = 'CPA[1]',
            description  = 'Calibrate user PRNU flat field coefficients: \# of lines to average Argument',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'cpa {self.CPA[0].get()} {self.CPA[1].get()} {self.CPA[2].get()}') if (self.CPA[0].get()!='' and self.CPA[1].get()!='' and self.CPA[2].get()!='') else ''
        )) 

        self.add(pr.LocalVariable(    
            name         = 'CPA[2]',
            description  = 'Calibrate user PRNU flat field coefficients: Target Argument',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'cpa {self.CPA[0].get()} {self.CPA[1].get()} {self.CPA[2].get()}') if (self.CPA[0].get()!='' and self.CPA[1].get()!='' and self.CPA[2].get()!='') else ''
        ))             

        self.add(pr.LocalVariable(    
            name         = 'DST',
            description  = 'Use this command to switch between Area and Single Line modes.',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'dst {value}') if value!='' else ''
        ))

        self.add(pr.LocalVariable(    
            name         = 'FFM',
            description  = 'Set flat field mode',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'ffm {value}') if value!='' else ''
        )) 

        self.add(pr.LocalVariable(    
            name         = 'FRS',
            description  = 'Set scan direction controlled reverse set',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'frs {value}') if value!='' else ''
        ))

        self.add(pr.BaseCommand(    
            name         = 'GCP',
            description  = 'Display current value of camera configuration parameters',
            function     = lambda cmd: self._tx.sendString('gcp')
        ))            

        self.add(pr.LocalVariable(    
            name         = 'GET',
            description  = 'The /"get/" command displays the current value(s) of the feature specified in the string parameter. Note that the parameter is preceded by a single quote \"\". Using this command will be easier for control software than parsing the output from the \"gcp\" command.',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'get {value}') if value!='' else ''
        ))            
        
        self.add(pr.BaseCommand(    
            name         = 'H',
            description  = 'Display list of three letter commands',
            function     = lambda cmd: self._tx.sendString('h')
        ))             
        
        self.add(pr.LocalVariable(    
            name         = 'LPC',
            description  = 'Load user set',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'lpc {value}') if value!='' else ''
        ))            
        
        self.add(pr.BaseCommand(    
            name         = 'RC',
            description  = 'Resets the camera to the saved user default settings. These settings are saved using the usd command.',
            function     = lambda cmd: self._tx.sendString('rc')
        ))            
        
        self.add(pr.LocalVariable(    
            name         = 'ROI[0]',
            description  = 'Flat field region of interest: First pixel Argument',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'roi {self.ROI[0].get()} {self.ROI[1].get()}') if (self.ROI[0].get()!='' and self.ROI[1].get()!='') else ''
        ))          
        
        self.add(pr.LocalVariable(    
            name         = 'ROI[1]',
            description  = 'Flat field region of interest: Last pixel Argument',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'roi {self.ROI[0].get()} {self.ROI[1].get()}') if (self.ROI[0].get()!='' and self.ROI[1].get()!='') else ''
        )) 
        
        self.add(pr.BaseCommand(    
            name         = 'RPC',
            description  = 'Reset all user FPN values to zero and all user PRNU coefficients to one',
            function     = lambda cmd: self._tx.sendString('rpc')
        ))               
        
        self.add(pr.LocalVariable(    
            name         = 'SAC',
            description  = 'Set AOI Counter',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'sac {value}') if value!='' else ''
        ))             
        
        self.add(pr.LocalVariable(    
            name         = 'SAD[0]',
            description  = 'Define an AOI: Selector Argument',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'sad {self.SAD[0].get()} {self.SAD[1].get()} {self.SAD[2].get()}') if (self.SAD[0].get()!='' and self.SAD[1].get()!='' and self.SAD[2].get()!='') else ''
        ))          
        
        self.add(pr.LocalVariable(    
            name         = 'SAD[1]',
            description  = 'Define an AOI: Offset Argument',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'sad {self.SAD[0].get()} {self.SAD[1].get()} {self.SAD[2].get()}') if (self.SAD[0].get()!='' and self.SAD[1].get()!='' and self.SAD[2].get()!='') else ''
        )) 

        self.add(pr.LocalVariable(    
            name         = 'SAD[2]',
            description  = 'Define an AOI: Width Argument',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'sad {self.SAD[0].get()} {self.SAD[1].get()} {self.SAD[2].get()}') if (self.SAD[0].get()!='' and self.SAD[1].get()!='' and self.SAD[2].get()!='') else ''
        ))              
        
        self.add(pr.LocalVariable(    
            name         = 'SAM',
            description  = 'Set AOI mode',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'sam {value}') if value!='' else ''
        )) 

        self.add(pr.LocalVariable(    
            name         = 'SBH',
            description  = 'Set horizontal binning',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'sbh {value}') if value!='' else ''
        ))  

        self.add(pr.LocalVariable(    
            name         = 'SBR',
            description  = 'Set baud rate',
            mode         = 'RW', 
            value        = '',
            units        = 'bps',
            localSet     = lambda value: self._tx.sendString(f'sbr {value}') if value!='' else ''
        ))

        self.add(pr.LocalVariable(    
            name         = 'SBV',
            description  = 'Set vertical binning',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'sbv {value}') if value!='' else ''
        )) 

        self.add(pr.LocalVariable(    
            name         = 'SCD',
            description  = 'Set sensor scan direction',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'scd {value}') if value!='' else ''
        ))  

        self.add(pr.LocalVariable(    
            name         = 'SEM',
            description  = 'Set exposure time mode',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'sem {value}') if value!='' else ''
        ))

        self.add(pr.LocalVariable(    
            name         = 'SET',
            description  = 'Set internal exposure time in nanoseconds (25 ns resolution)',
            mode         = 'RW', 
            value        = '',
            units        = '25ns',
            localSet     = lambda value: self._tx.sendString(f'set {value}') if value!='' else ''
        ))            

        self.add(pr.LocalVariable(    
            name         = 'SMM',
            description  = 'Set mirroring mode',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'smm {value}') if value!='' else ''
        ))

        self.add(pr.LocalVariable(    
            name         = 'SPF',
            description  = 'Set pixel format',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'spf {value}') if value!='' else ''
        ))

        self.add(pr.LocalVariable(    
            name         = 'SSB',
            description  = 'Set contrast offset - single value added to all pixels after PRNU/flat field coefficients (before gain).',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'ssb {value}') if value!='' else ''
        ))

        self.add(pr.LocalVariable(    
            name         = 'SSF',
            description  = 'Set internal line rate in Hz',
            mode         = 'RW', 
            value        = '',
            units        = 'Hz',
            localSet     = lambda value: self._tx.sendString(f'ssf {value}') if value!='' else ''
        ))            
        
        self.add(pr.LocalVariable(    
            name         = 'SSG',
            description  = 'Set gain as a single value multiplied by all pixels.',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'ssg {value}') if value!='' else ''
        ))   

        self.add(pr.LocalVariable(    
            name         = 'STG',
            description  = 'Set TDI Stages',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'stg {value}') if value!='' else ''
        ))  

        self.add(pr.LocalVariable(    
            name         = 'STM',
            description  = 'Set trigger mode',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'stm {value}') if value!='' else ''
        )) 

        self.add(pr.LocalVariable(    
            name         = 'SVM',
            description  = 'Select test pattern',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'svm {value}') if value!='' else ''
        ))  

        self.add(pr.LocalVariable(    
            name         = 'USD',
            description  = 'Select user set to load when camera is reset',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'usd {value}') if value!='' else ''
        )) 

        self.add(pr.LocalVariable(    
            name         = 'USL',
            description  = 'Load user set',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'usl {value}') if value!='' else ''
        )) 

        self.add(pr.LocalVariable(    
            name         = 'USS',
            description  = 'Save user set',
            mode         = 'RW', 
            value        = '',
            localSet     = lambda value: self._tx.sendString(f'uss {value}') if value!='' else ''
        ))  

        self.add(pr.BaseCommand(    
            name         = 'VT',
            description  = 'Display internal temperature in degrees Celsius',
            function     = lambda cmd: self._tx.sendString('vt'),
        ))

        self.add(pr.BaseCommand(    
            name         = 'VV',
            description  = 'Display supply voltage',
            function     = lambda cmd: self._tx.sendString('vv'),
        ))  

        self.add(pr.BaseCommand(    
            name         = 'SendEscape',
            description  = 'Send the Escape Char',
            function     = lambda cmd: self._tx.sendEscape()
        ))              
Esempio n. 5
0
    def __init__(
            self,
            name='ClinkDev',
            description='Container for CameraLink Dev',
            dev='/dev/datadev_0',  # path to PCIe device
            version3=False,  # true = PGPv3, false = PGP2b
            pollEn=True,  # Enable automatic polling registers
            initRead=True,  # Read all registers at start of the system
            numLane=4,  # Number of PGP lanes
            camType=['Opal000', None],
            defaultFile=None,
            **kwargs):
        super().__init__(name=name,
                         description=description,
                         dev=dev,
                         version3=version3,
                         numLane=numLane,
                         **kwargs)

        self.defaultFile = defaultFile

        # Set the min. firmware Versions
        self.minPcieVersion = 0x01000200
        self.minFebVersion = 0x01000200

        # PGP Application on PCIe
        self.add(
            app.Application(
                memBase=self._memMap,
                numLane=numLane,
                expand=True,
            ))

        # Check if not doing simulation
        if (dev != 'sim'):

            # Create arrays to be filled
            self._srp = [None for lane in range(numLane)]

            # Create the stream interface
            for lane in range(numLane):

                # SRP
                self._srp[lane] = rogue.protocols.srp.SrpV3()
                pr.streamConnectBiDir(self._dma[lane][0], self._srp[lane])

                # CameraLink Feb Board
                self.add(
                    feb.ClinkFeb(
                        name=(f'ClinkFeb[{lane}]'),
                        memBase=self._srp[lane],
                        serial=[self._dma[lane][2], self._dma[lane][3]],
                        camType=camType,
                        version3=version3,
                        enableDeps=[
                            self.Hardware.PgpMon[lane].RxRemLinkReady
                        ],  # Only allow access if the PGP link is established
                        expand=False,
                    ))

        # Else doing Rogue VCS simulation
        else:

            # Create arrays to be filled
            self._frameGen = [None for lane in range(numLane)]

            # Create the stream interface
            for lane in range(numLane):

                # Create the frame generator
                self._frameGen[lane] = MyCustomMaster()

                # Connect the frame generator
                pr.streamConnect(self._frameGen[lane], self._pgp[lane][1])

                # Create a command to execute the frame generator
                self.add(
                    pr.BaseCommand(
                        name=f'GenFrame[{lane}]',
                        function=lambda cmd, lane=lane: self._frameGen[lane].
                        myFrameGen(),
                    ))

        self.add(
            pr.LocalVariable(
                name='RunState',
                description=
                'Run state status, which is controlled by the StopRun() and StartRun() commands',
                mode='RO',
                value=False,
            ))

        @self.command(
            description='Stops the triggers and blows off data in the pipeline'
        )
        def StopRun():
            print('ClinkDev.StopRun() executed')

            # Get devices
            trigChDev = self.find(typ=timingCore.EvrV2ChannelReg)

            # Turn off the triggering
            for devPtr in trigChDev:
                devPtr.EnableReg.set(False)

            # Update the run state status variable
            self.RunState.set(False)

        @self.command(
            description=
            'starts the triggers and allow steams to flow to DMA engine')
        def StartRun():
            print('ClinkDev.StartRun() executed')

            # Get devices
            trigChDev = self.find(typ=timingCore.EvrV2ChannelReg)

            # Reset all counters
            self.CountReset()

            # Turn on the triggering
            for devPtr in trigChDev:
                devPtr.EnableReg.set(True)

            # Update the run state status variable
            self.RunState.set(True)

        # Start the system
        self.start(
            pollEn=self._pollEn,
            initRead=self._initRead,
            timeout=self._timeout,
        )

        # Hide all the "enable" variables
        for enableList in self.find(typ=pr.EnableVariable):
            # Hide by default
            enableList.hidden = True

        # Check if simulation
        if (dev == 'sim'):
            # Disable the PGP PHY device (speed up the simulation)
            self.Hardware.enable.set(False)
            self.Hardware.hidden = True
            # Bypass the time AXIS channel
            eventDev = self.find(typ=batcher.AxiStreamBatcherEventBuilder)
            for dev in eventDev:
                dev.Bypass.set(0x1)
        else:
            # Read all the variables
            self.ReadAll()

            # Check for min. PCIe FW version
            fwVersion = self.Hardware.AxiPcieCore.AxiVersion.FpgaVersion.get()
            if (fwVersion < self.minPcieVersion):
                errMsg = f"""
                    PCIe.AxiVersion.FpgaVersion = {fwVersion:#04x} < {self.minPcieVersion:#04x}
                    Please update PCIe firmware using software/scripts/updatePcieFpga.py
                    """
                click.secho(errMsg, bg='red')
                raise ValueError(errMsg)

            # Check for min. FEB FW version
            for lane in range(numLane):
                # Unhide the because dependent on PGP link status
                self.ClinkFeb[lane].enable.hidden = False
                # Check for PGP link up
                if (self.Hardware.PgpMon[lane].RxRemLinkReady.get() != 0):

                    # Expand for the GUI
                    self.ClinkFeb[lane]._expand = True
                    self.ClinkFeb[lane].ClinkTop._expand = True
                    self.ClinkFeb[lane].TrigCtrl[0]._expand = True
                    self.ClinkFeb[lane].TrigCtrl[1]._expand = True
                    if camType[1] is None:
                        self.ClinkFeb[lane].ClinkTop.Ch[1]._expand = False
                        self.ClinkFeb[lane].TrigCtrl[1]._expand = False

                    # Check for min. FW version
                    fwVersion = self.ClinkFeb[lane].AxiVersion.FpgaVersion.get(
                    )
                    if (fwVersion < self.minFebVersion):
                        errMsg = f"""
                            Fpga[lane={lane}].AxiVersion.FpgaVersion = {fwVersion:#04x} < {self.minFebVersion:#04x}
                            Please update Fpga[{lane}] at Lane={lane} firmware using software/scripts/updateFeb.py
                            """
                        click.secho(errMsg, bg='red')
                        raise ValueError(errMsg)
                else:
                    self.Application.AppLane[lane]._expand = False

            # Startup procedures for OPA1000
            uartDev = self.find(typ=cl.UartOpal1000)
            for dev in uartDev:
                pass

            # Startup procedures for Piranha4
            uartDev = self.find(typ=cl.UartPiranha4)
            for dev in uartDev:
                dev.SendEscape()
                dev.SPF.setDisp('0')
                dev.GCP()

            # Startup procedures for Up900cl12b
            uartDev = self.find(typ=cl.UartUp900cl12b)
            for dev in uartDev:
                clCh = self.find(typ=cl.ClinkChannel)
                for clChDev in clCh:
                    clChDev.SerThrottle.set(30000)
                dev.AM()
                dev.SM.set('f')
                dev.RP()

        # Load the configurations
        if self.defaultFile is not None:
            print(f'Loading {self.defaultFile} Configuration File...')
            self.LoadConfig(self.defaultFile)
Esempio n. 6
0
    def __init__(
            self,
            dataDebug=False,
            dev='/dev/datadev_0',  # path to PCIe device
            pgp3=True,  # true = PGPv3, false = PGP2b
            pollEn=True,  # Enable automatic polling registers
            initRead=True,  # Read all registers at start of the system
            numLanes=1,  # Number of PGP lanes
            defaultFile=None,
            devTarget=None,
            **kwargs):

        # Set the min. firmware Versions
        self.PcieVersion = 0x04000000
        self.FebVersion = 0x04000000

        # Set local variables
        self.defaultFile = defaultFile
        self.dev = dev

        kwargs['timeout'] = 5000000  # 5 s

        # Pass custom value to parent via super function
        super().__init__(dev=dev,
                         pgp3=pgp3,
                         pollEn=pollEn,
                         initRead=initRead,
                         numLanes=numLanes,
                         **kwargs)

        # Create memory interface
        self.memMap = axipcie.createAxiPcieMemMap(dev, 'localhost', 8000)

        # Instantiate the top level Device and pass it the memory map
        self.add(
            devTarget(
                name='PgpPcie',
                memBase=self.memMap,
                numLanes=numLanes,
                pgp3=pgp3,
                expand=True,
            ))

        # Create DMA streams
        vcs = [0, 1, 2] if dataDebug else [0, 2]
        self.dmaStreams = axipcie.createAxiPcieDmaStreams(
            dev, {lane: {dest
                         for dest in vcs}
                  for lane in range(numLanes)}, 'localhost', 8000)

        # Check if not doing simulation
        if (dev != 'sim'):

            # Create arrays to be filled
            self._srp = [None for lane in range(numLanes)]

            # Create the stream interface
            for lane in range(numLanes):

                # SRP
                self._srp[lane] = rogue.protocols.srp.SrpV3()
                pr.streamConnectBiDir(self.dmaStreams[lane][0],
                                      self._srp[lane])

                # CameraLink Feb Board
                self.add(
                    feb.ClinkFeb(
                        name=(f'ClinkFeb[{lane}]'),
                        memBase=self._srp[lane],
                        serial=self.dmaStreams[lane][2],
                        camType=self.camType[lane],
                        version3=pgp3,
                        enableDeps=[
                            self.ClinkPcie.Hsio.PgpMon[lane].RxRemLinkReady
                        ],  # Only allow access if the PGP link is established
                        expand=True,
                    ))

        # Else doing Rogue VCS simulation
        else:
            self.roguePgp = shared.RogueStreams(numLanes=numLanes, pgp3=pgp3)

            # Create arrays to be filled
            self._frameGen = [None for lane in range(numLanes)]

            # Create the stream interface
            for lane in range(numLanes):

                # Create the frame generator
                self._frameGen[lane] = MyCustomMaster()

                # Connect the frame generator
                print(self.roguePgp.pgpStreams)
                self._frameGen[lane] >> self.roguePgp.pgpStreams[lane][1]

                # Create a command to execute the frame generator
                self.add(
                    pr.BaseCommand(
                        name=f'GenFrame[{lane}]',
                        function=lambda cmd, lane=lane: self._frameGen[lane].
                        myFrameGen(),
                    ))

                # Create a command to execute the frame generator. Accepts user data argument
                self.add(
                    pr.BaseCommand(
                        name=f'GenUserFrame[{lane}]',
                        function=lambda cmd, lane=lane: self._frameGen[lane].
                        myFrameGen,
                    ))

        # Create arrays to be filled
        self._dbg = [None for lane in range(numLanes)]
        self.unbatchers = [
            rogue.protocols.batcher.SplitterV1() for lane in range(numLanes)
        ]

        # Create the stream interface
        for lane in range(numLanes):
            # Debug slave
            if dataDebug:
                # Connect the streams
                #self.dmaStreams[lane][1] >> self.unbatchers[lane] >> self._dbg[lane]
                self.dmaStreams[lane][1] >> self.unbatchers[lane]

        self.add(
            pr.LocalVariable(
                name='RunState',
                description=
                'Run state status, which is controlled by the StopRun() and StartRun() commands',
                mode='RO',
                value=False,
            ))
Esempio n. 7
0
    def __init__(
            self,
            name='FmcDev',
            description='Container for Fmc Dev',
            hwType='eth',  # Define whether sim/rce/pcie/eth HW config
            ip='192.168.2.10',
            dev='/dev/datadev_0',  # path to device
            pllConfig='config/pll-config/Si5345-RevD-Registers-160MHz.csv',
            fullRate=True,  # For simulation: True=1.28Gb/s, False=160Mb/s
            pollEn=True,  # Enable automatic polling registers
            initRead=True,  # Read all registers at start of the system
            fmcFru=False,  # True if configuring the FMC's FRU
            testPattern=False,
            **kwargs):
        super().__init__(name=name, description=description, **kwargs)

        self._dmaSrp = None
        self._dmaCmd = [None for i in range(4)]
        self._dmaData = [None for i in range(4)]
        self._frameGen = [None for lane in range(5)]
        self._printFrame = [None for lane in range(4)]

        self.fmcFru = fmcFru
        self.pllConfig = pllConfig
        self.hwType = hwType
        self.testPattern = True if hwType == 'sim' else testPattern

        # Set the timeout
        self._timeout = 1.0  # 1.0 default

        # Start up flags
        self._pollEn = pollEn
        self._initRead = initRead

        # Check for HW type
        if (hwType == 'eth'):

            # Connected to FW DMA.Lane[0]
            self.rudpData = pr.protocols.UdpRssiPack(
                host=ip,
                port=8192,
                packVer=2,
            )
            self.rudpData.locMaxBuffers(
                64
            )  # Set the SW RSSI buffer to 64 buffers (instead of default=32)
            self.add(self.rudpData
                     )  # Add the RSSI protocol to the GUI's device tree

            # Connected to FW DMA.Lane[1]
            self.rudpSrp = pr.protocols.UdpRssiPack(
                host=ip,
                port=8193,
                packVer=2,
            )
            self.rudpSrp.locMaxBuffers(
                64
            )  # Set the SW RSSI buffer to 64 buffers (instead of default=32)
            self.add(
                self.rudpSrp)  # Add the RSSI protocol to the GUI's device tree

            # SRPv3 on DMA.Lane[1]
            self._dmaSrp = self.rudpSrp.application(0)

            for i in range(4):
                # CMD on DMA.Lane[0].VC[3:0]
                self._dmaCmd[i] = self.rudpData.application(i + 0)

                # DATA on DMA.Lane[0].VC[7:4]
                self._dmaData[i] = self.rudpData.application(i + 4)

        elif (hwType == 'sim'):
            # FW/SW co-simulation
            self.memMap = rogue.interfaces.memory.TcpClient('localhost', 8000)

            # Set the timeout
            self._timeout = 100.0  # firmware simulation slow and timeout base on real time (not simulation time)

            # Start up flags
            self._pollEn = False
            self._initRead = False

            # SRPv3 on DMA.Lane[1]
            self._dmaSrp = rogue.interfaces.stream.TcpClient(
                'localhost', 8002 + (512 * 1) + 2 * 0)

            for i in range(4):
                # CMD on DMA.Lane[0].VC[3:0]
                self._dmaCmd[i] = rogue.interfaces.stream.TcpClient(
                    'localhost', 8002 + (512 * 0) + 2 * (i + 0))

                # DATA on DMA.Lane[0].VC[7:4]
                self._dmaData[i] = rogue.interfaces.stream.TcpClient(
                    'localhost', 8002 + (512 * 0) + 2 * (i + 4))

        elif (hwType == 'pcie'):
            # BAR0 access
            self.memMap = rogue.hardware.axi.AxiMemMap(dev)

            # Add the PCIe core device to base
            self.add(
                pcie.AxiPcieCore(
                    memBase=self.memMap,
                    offset=0x00000000,
                    numDmaLanes=2,
                    expand=False,
                ))

            # SRPv3 on DMA.Lane[1]
            self._dmaSrp = rogue.hardware.axi.AxiStreamDma(
                dev, (0x100 * 1) + 0, True)

            for i in range(4):
                # CMD on DMA.Lane[0].VC[3:0]
                self._dmaCmd[i] = rogue.hardware.axi.AxiStreamDma(
                    dev, (0x100 * 0) + i + 0, True)

                # DATA on DMA.Lane[0].VC[7:4]
                self._dmaData[i] = rogue.hardware.axi.AxiStreamDma(
                    dev, (0x100 * 0) + i + 4, True)

        elif (hwType == 'rce'):
            # Create the mmap interface
            memMap = rogue.hardware.axi.AxiMemMap('/dev/rce_memmap')

            # Add RCE version device
            self.add(rce.RceVersion(
                memBase=memMap,
                expand=False,
            ))

            # SRPv3 on DMA.Lane[1]
            self._dmaSrp = rogue.hardware.axi.AxiStreamDma(
                '/dev/axi_stream_dma_1', 0, True)

            for i in range(4):
                # CMD on DMA.Lane[0].VC[3:0]
                self._dmaCmd[i] = rogue.hardware.axi.AxiStreamDma(
                    '/dev/axi_stream_dma_0', i + 0, True)

                # DATA on DMA.Lane[0].VC[7:4]
                self._dmaData[i] = rogue.hardware.axi.AxiStreamDma(
                    '/dev/axi_stream_dma_0', i + 4, True)

        else:
            raise ValueError(
                f'Invalid hwType. Must be either [sim,rce,pcie,eth]')

        # Connect the DMA SRPv3 stream
        self._srp = rogue.protocols.srp.SrpV3()
        pr.streamConnectBiDir(self._dmaSrp, self._srp)

        # Check if doing test patterns
        if self.testPattern:

            # Create the frame generator
            self._frameGen[4] = LoadSimConfig(fullRate)

            # Connect the frame generator to "broadcast the Cmd from SW to all the MiniDP ports"
            pr.streamConnect(self._frameGen[4],
                             self._dmaData[0])  # DMA.Lane[0].VC[4].TX

            for i in range(4):

                # Create the frame generator
                self._frameGen[i] = LoadSimConfig(fullRate)
                self._printFrame[i] = PrintSlaveStream()

                # Connect the frame generator
                pr.streamConnect(self._frameGen[i],
                                 self._dmaCmd[i])  # DMA.Lane[0].VC[3:0].TX
                pr.streamConnect(self._dmaData[i],
                                 self._printFrame[i])  # DMA.Lane[0].VC[7:4].RX

                # Create a command to execute the frame generator
                self.add(
                    pr.BaseCommand(
                        name=f'SimConfig[{i}]',
                        function=lambda cmd, i=i: self._frameGen[i].config(),
                    ))
                self.add(
                    pr.BaseCommand(
                        name=f'SimScan[{i}]',
                        function=lambda cmd, i=i: [
                            self.CountReset(), self._printFrame[i].cntRst(),
                            self._frameGen[i].scan()
                        ],
                    ))
                # self.add(pr.BaseCommand(
                # name         = f'SimCntRst[{i}]',
                # function     = lambda cmd, i=i: self._printFrame[i].cntRst(),
                # ))

        # FMC Board
        self.add(
            hw.Fmc(
                memBase=self._srp,
                simulation=(hwType == 'sim'),
                fmcFru=fmcFru,
                expand=True,
            ))

        # Start the system
        self.start(
            pollEn=self._pollEn,
            initRead=self._initRead,
            timeout=self._timeout,
        )