コード例 #1
0
    def run(board,
            node,
            bynode=False,
            chan=None,
            buffer=None,
            romode=None,
            rocapture=None):
        if chan is not None:
            if buffer is not None:
                b = {'rx': mp7.kRx, 'tx': mp7.kTx}[buffer]
                board.getDatapath().selectLinkBuffer(chan, b)
                logging.notice('Channel %d, buffer %s selected', chan, b)
            else:
                board.getDatapath().selectLink(chan)
                logging.notice('Channel %d selected', chan)

        if romode is not None:
            board.getReadout().getNode('readout_control').selectMode(romode)
            logging.notice('Readout mode %d selected', romode)

        if romode is not None:
            board.getReadout().getNode('readout_control').selectCapture(
                rocapture)
            logging.notice('Readout capture %d selected', rocapture)

        nodes = board.hw().getNodes(node)
        for subnode in nodes:
            n = board.hw().getNode(subnode)
            cl = n.getClient()

            if not bynode:
                v = n.read()
                snap = mp7.snapshot(n)

                print node, '=', hex(v)
                for k in sorted(snap):
                    print node + '.' + k, '=', hex(snap[k])
            else:
                print node, '=',
                sys.stdout.flush()
                v = n.read()
                cl.dispatch()
                print hex(v)

                for sn in sorted(n.getNodes()):
                    print node + '.' + sn, '=',
                    sys.stdout.flush()
                    v = n.getNode(sn).read()
                    cl.dispatch()
                    print hex(v)
コード例 #2
0
ファイル: testzs.py プロジェクト: herbberg/mp7fw_v2_4_1
# import sys
# sys.exit(0)

board = mp7.MP7Controller(dev)

config = getSettings()

# Reset board
infra.Reset.run(board, **config['reset'])

zs = board.hw().getNode('readout.readout_zs')

zs_csr = board.hw().getNode('readout.readout_zs.csr')
# zs_ram = board.hw().getNode('readout.readout_zs.ram')

info = mp7.snapshot(zs_csr.getNode('info'))

print 'ZS block detected: ', 'Yes' if info['zs_enabled'] else 'No'
print info
ncap = info['mask_ram_depth'] / 6

print 'Supported capture modes: 0', ncap - 1

zs.enable()

menuFile = "${MP7_TESTS}/python/daq/simple.py"
menuName = "menuA"
zsMenuName = "zsMenuA"

# print 'Resetting board'
# infra.Reset.run(board, **config['reset'])
コード例 #3
0
    def run(board, histlen, capall):

        ctrl = board.getCtrl()
        ttc = board.getTTC()
        ro = board.getReadout()
        rc = ro.getControl()

        logging.notice('Firmware information')
        # logging.info('Revision')
        # logging.info('   Infra 0x%06x', ctrl.readFwRevision())
        # logging.info('   Algo  0x%08x', ctrl.readAlgoRevision())

        gens = mp7.snapshot(ctrl.getNode('id'))
        for r in sorted(gens):
            logging.info('   %s : 0x%x', r, gens[r])

        logging.notice('TTC status')
        ttcstat = mp7.snapshot(ttc.getNode('csr'))

        logging.info('Event counter : %d', ttcstat['stat1.evt_ctr'])
        logging.info('BC0 Lock      : %d', ttcstat['stat0.bc0_lock'])
        logging.info('TTC phase     : %d', ttcstat['stat0.ttc_phase_ok'])
        logging.info('TTC SBE       : %d', ttcstat['stat3.double_biterr_ctr'])
        logging.info('TTC DBE       : %d', ttcstat['stat3.single_biterr_ctr'])

        evt_chk = ro.getNode('evt_check.evt_err').read()
        ro.getClient().dispatch()

        logging.info('Event order errors: %d', evt_chk)
        if evt_chk != 0:
            logging.error('Event order looks to be wrong')

        logging.info('TTC counters')
        ttcctrs = mp7.snapshot(ttc.getNode('cmd_ctrs'))
        for k in sorted(ttcctrs):
            logging.info('   %s : %d', k, ttcctrs[k])

        # Print the TTC history
        # Useless until Maxime masks BC0s in configurations

        logging.info('TTC History')
        history = ttc.captureHistory()

        for i, e in enumerate(history):
            logging.info(
                '%4d | orb:0x%06x bx:0x%03x ev:0x%06x l1a:%1d cmd:%02x', i,
                e.orbit, e.bx, e.event, e.l1a, e.cmd)

        logging.notice('Readout status')
        rostat = mp7.snapshot(ro.getNode('csr'))

        dynLog(rostat['stat.src_err'] == 0, 'Event source error : %d',
               rostat['stat.src_err'])
        dynLog(rostat['stat.rob_err'] == 0, 'Readout error      : %d',
               rostat['stat.rob_err'])
        logging.info('Debug              : 0x%06x', rostat['stat.debug'])
        logging.info('Event counter      : %d', rostat['evt_count'])

        #
        # TTS State section
        #
        logging.notice('TTS status')
        ttsstat = mp7.snapshot(ro.getNode('tts_csr.stat'))

        # log = logging.info if ttsstat['tts_stat'] == 0x8 else logging.warn
        dynLog(ttsstat['tts_stat'] == 0x8, 'Status        : %d',
               ttsstat['tts_stat'])

        logging.notice('TTS history')

        TTSCapture.run(board, False)

        logging.notice('RO history')

        HistoryCapture.run(board, False, histlen)

        logging.notice('Fifo status')
        robstat = mp7.snapshot(ro.getNode('buffer.fifo_flags'))

        for f in sorted(robstat):
            logging.info('%s : %d', f, robstat[f])

        #
        # Readout Control section
        #
        logging.notice('Readout Control & ZS')
        rcstat = mp7.snapshot(rc.getNode('csr.stat'))

        nBanks = rcstat['n_banks']
        nModes = rcstat['n_modes']
        nCaps = rcstat['n_caps']

        logging.info('Banks %d, Modes %d, Captures %d', nBanks, nModes, nCaps)

        # A. Print existing menu
        menu = rc.readMenu()

        logging.debug('Readout menu (on-board)')
        for l in str(menu).split('\n'):
            logging.debug('%s', l)

        try:
            if len(ro.getNodes('readout_zs')) == 0:
                raise RuntimeError('ZS node not found')

            zs = ro.getNode('readout_zs')
            logging.info('Zero Suppression is %s',
                         'ON' if zs.isEnabled() else 'OFF')
            logging.info('ZS FSMs')
            logging.info(' - Main          : %s', zs.readMainState())
            logging.info(' - Fifo Transfer : %s', zs.readFifoTransferState())
            logging.info(' - Output        : %s', zs.readOutputState())

            menu = zs.readMenu()
            logging.debug('ZS menu (on-board)')
            for l in str(menu).split('\n'):
                logging.debug('%s', l)
        except (mp7.ZeroSuppressionNotAvailable, RuntimeError):
            logging.info('ZeroSuppression block not instantiated')

        logging.notice('Bank occupancy')

        for iB in xrange(nBanks):
            rc.selectBank(iB)
            dr_occ = rc.getNode('bank_csr.stat.dr_occupancy').read()
            rc.getClient().dispatch()

            logging.info('%d : %d', iB, dr_occ)

        logging.notice('Readout Modes and Captures')

        for iM in xrange(nModes):
            logging.info('Mode %d', iM)

            rc.selectMode(iM)
            mctrl = mp7.snapshot(rc.getNode('mode_csr.ctrl'))
            mstat = mp7.snapshot(rc.getNode('mode_csr.stat'))
            for r in sorted(mstat):
                logging.info('- %s : %d', r, mstat[r])

            nCapEn = 0
            for iC in xrange(nCaps):
                rc.selectCapture(iC)
                cctrl = mp7.snapshot(rc.getNode('cap_csr.ctrl'))
                if not (cctrl['cap_en'] or capall): continue
                nCapEn += 1
                logging.info('   Capture %d', iC)
                cstat = mp7.snapshot(rc.getNode('cap_csr.stat'))
                for r in sorted(cstat):
                    logging.info('   - %s : %d', r, cstat[r])
            if not nCapEn:
                logging.info('No captures enabled for mode %d', iM)

        #
        # Trigger anf Capture mode section
        #
        # trigger_mode_hist(0) <= '1' WHEN ro_state = ST_IDLE ELSE '0';
        # trigger_mode_hist(1) <= '1' WHEN ro_state = ST_READ ELSE '0';
        # trigger_mode_hist(2) <= '1' WHEN state = ST_IDLE ELSE '0';
        # trigger_mode_hist(3) <= '1' WHEN state = ST_TOK_DEL ELSE '0';
        # trigger_mode_hist(4) <= '1' WHEN state = ST_HDR ELSE '0';
        # trigger_mode_hist(5) <= '1' WHEN state = ST_DATA ELSE '0';
        # trigger_mode_hist(6) <= ctrs_fifo_full;
        #
        # cap_mode_hist(0) <= '1' WHEN ro_state = ST_IDLE ELSE '0';
        # cap_mode_hist(1) <= '1' WHEN ro_state = ST_INIT ELSE '0';
        # cap_mode_hist(2) <= '1' WHEN ro_state = ST_READ ELSE '0';
        # cap_mode_hist(3) <= '1' WHEN ro_state = ST_PREP ELSE '0';
        # cap_mode_hist(4) <= '1' WHEN cap_state = ST_CAP ELSE '0';
        #
        # hist_state <= trigger_mode_hist & cap_mode_hist

        rchist = rc.getNode('hist')

        def getBit(w, i):
            return (w >> i) & 1

        def printBit(on, off, w, i):
            return on if getBit(w, i) else off

        def printMod(w):
            return (printBit('I', '_', w, 0) + printBit('R', '_', w, 1) +
                    printBit('I', '_', w, 2) + printBit('T', '_', w, 3) +
                    printBit('H', '_', w, 4) + printBit('D', '_', w, 5) +
                    printBit('F', '_', w, 6))

        def printCap(w):
            return (printBit('I', '_', w, 0) + printBit('S', '_', w, 1) +
                    printBit('R', '_', w, 2) + printBit('P', '_', w, 3) +
                    printBit('C', '_', w, 4))

        logging.notice('Readout Modes and Captures history')
        for iM in xrange(nModes):
            logging.info('Mode %d', iM)

            rc.selectMode(iM)

            for iC in xrange(nCaps):
                rc.selectCapture(iC)
                cctrl = mp7.snapshot(rc.getNode('cap_csr.ctrl'))
                if not (cctrl['cap_en'] or capall): continue
                logging.info('   Capture %d', iC)

                history = rchist.capture()

                h = history[-histlen:] if histlen else history
                if histlen:
                    logging.info('Printing last %d entries', histlen)

                for i in xrange(len(h)):
                    e = h[i]
                    if i:
                        em1 = h[i - 1]
                        gap = '%4d' % (e.bx - em1.bx)
                    else:
                        gap = ' NA '
                    # Capture state, lower 5bits
                    capstate = (e.data & 0x1f)
                    # Trigger Mode state, following 7 bits
                    modstate = ((e.data >> 5) & 0x7f)

                    # print printMod(modstate), printCap(capstate)
                    # logging.debug('%4d | orb:0x%06x bx:0x%03x ev:0x%06x gap: %s, mod: %s cap: %s', i, e.orbit, e.bx, e.event, gap, '{0:07b}'.format(modstate), '{0:05b}'.format(capstate))
                    logging.info(
                        '%4d | orb:0x%06x bx:0x%03x cyc:0x%03x ev:0x%06x gap: %s, mod: %s cap: %s',
                        i, e.orbit, e.bx, e.cyc, e.event, gap,
                        printMod(modstate), printCap(capstate))
コード例 #4
0
    def run(board, nevents, outputpath, bxs):

        r = CaptureResult()

        ttc = board.getTTC()
        ro = board.getReadout()

        # print ro.readFifoOccupancy()
        logging.info('TTS: 0x%x', ro.readTTSState())

        ttc.maskHistoryBC0L1a(True)

        # Reset the orbit counter
        ttc.forceBCmd(mp7.TTCBCommand.kOC0)
        # Reset the event counter
        ttc.forceBCmd(mp7.TTCBCommand.kEC0)
        # Reset the readout block counter
        ttc.forceBCmd(mp7.TTCBCommand.kResync)

        # Don't drain!
        ro.enableAutoDrain(False)

        logging.info('TTS: 0x%x', ro.readTTSState())

        # ro.enableAutoDrain(True)
        ro.enableAutoDrain(False)

        logging.info('TTS: 0x%x', ro.readTTSState())

        logging.notice('Injecting L1As')

        from itertools import cycle

        bxPool = cycle(bxs) if bxs is not None else None

        # Inject L1As
        for i in xrange(nevents):
            if bxPool is None:
                ttc.forceL1A()
            else:
                bx = next(bxPool)
                logging.info('Firing l1A on bx %d', bx)

                ttc.forceL1AOnBx(bx)

            if board.kind() == mp7.kMP7Sim:
                logging.debug('Sleep 10 secs because simulation is slow')
                time.sleep(10)

            # Check fifo level
            # fifo_cnt = ro.getNode('buffer.fifo_flags.fifo_cnt').read()
            tts = ro.readTTSState()

            flags = mp7.snapshot(ro.getNode('buffer.fifo_flags'))

            # print(i,flags)
            logging.info(
                '%02d - TTS: 0x%x | Fifo valid: %d, warn: %d, full: %d, empty %d: cnt: %d',
                i, tts, flags['fifo_valid'], flags['fifo_warn'],
                flags['fifo_full'], flags['fifo_empty'], flags['fifo_cnt'])

        logging.debug('Now there should be an event')
        empty = ro.isFifoEmpty()
        logging.debug('Is fifo empty? %s', empty)

        # Print the TTC history
        logging.info('TTC History')
        history = ttc.captureHistory()
        # Save it in the result
        r.history = history

        for i, e in enumerate(history):
            logging.info(
                '%4d | orb:0x%06x bx:0x%03x ev:0x%06x l1a:%1d cmd:%02x', i,
                e.orbit, e.bx, e.event, e.l1a, e.cmd)

        if (empty):
            # Throw an exception here
            logging.warn('The fifo is empty, something is not quite right')
            r.status = -1
            r.msg = "The fifo is empty, something is not quite right. No event was captured"
            return

        logging.notice('Reading events back')

        # Read events back
        events = []
        for i in xrange(nevents):
            tts = ro.getNode('tts_csr.stat').read()
            flags = mp7.snapshot(ro.getNode('buffer.fifo_flags'))

            logging.info(
                '%02d - TTS: 0x%x | Fifo valid: %d, warn: %d, full: %d, empty %d: cnt: %d',
                i, tts, flags['fifo_valid'], flags['fifo_warn'],
                flags['fifo_full'], flags['fifo_empty'], flags['fifo_cnt'])

            e = ro.readEvent()
            events.append(e)

        logging.info('%d events read', len(events))

        # Copy events into result object
        r.events.extend(events)

        src = ro.getNode('csr.ctrl.src_sel').read()
        ro.getClient().dispatch()
        fake = (src == ro.kFakeEventSource)
        logging.info('Fake? %s', fake)

        upEv = []
        # Unpack events
        for i, ev in enumerate(events):
            logging.info('## Decoding event %d ##', i + 1)
            # Create an unpacker result
            upEv.append(unpacker.unpackROBEvent(ev, unpacker.AMCEvent(i),
                                                fake))

        # returnEvent['Event'] = upEv
        r.unpacked.extend(upEv)

        if outputpath:
            dn = os.path.dirname(outputpath)
            if dn:
                os.system('mkdir -p ' + dn)

            with open(outputpath, 'w') as f:
                for i, ev in enumerate(events):

                    ttcentry = filter(
                        lambda x: x.l1a == True and x.event == (i + 1),
                        history)[0]
                    # print ttcentry, ttcentry.bx

                    hdr = 'Event %d' % (i + 1)
                    f.write(hdr + '\n')
                    f.write('-' * len(hdr) + '\n')
                    f.write('ttc | orb: 0x%06x bx: 0x%03x\n' %
                            (ttcentry.orbit, ttcentry.bx))
                    f.write('-' * 20 + '\n')
                    for j, w in enumerate(ev):
                        f.write('%04d : 0x%08x\n' % (2 * j, (w & 0xffffffff)))
                        f.write('%04d : 0x%08x\n' % (2 * j + 1,
                                                     ((w >> 32) & 0xffffffff)))
                    f.write('-' * 20 + '\n\n')

            logging.info('Events saved to %s', dn)

        # return returnEvent
        return r
コード例 #5
0
    def run(board, rate, secs):

        logging.notice('Input rate %f Hz', rate)
        ttc = board.getTTC()
        ro = board.getReadout()

        # Reset the orbit counter
        ttc.forceBCmd(mp7.TTCBCommand.kResync)
        # Reset the readout block counter
        ttc.forceBCmd(mp7.TTCBCommand.kOC0)
        # Reset the event counter
        ttc.forceBCmd(mp7.TTCBCommand.kEC0)

        # Print the status before starting
        logging.info('Before enabling triggers')

        ttcev = ttc.readEventCounter()
        roev = ro.readEventCounter()
        logging.info('ttc l1As    : %d', ttcev)
        logging.info('ro events  : %d', roev)

        src_err = ro.getNode('csr.stat.src_err').read()
        rob_err = ro.getNode('csr.stat.rob_err').read()
        ro.getClient().dispatch()

        logging.info('Source error : %d', src_err)
        logging.info('ROB error : %d', rob_err)

        ttc.generateRandomL1As(rate)

        logging.info('Take a nap for %d secs', secs)

        for i in xrange(secs / 10):
            time.sleep(10)
            logging.info('%ds...', (i + 1) * 10)

        time.sleep(secs % 10)
        logging.info('Wake up!')

        # Disable triggers
        ttc.generateRandomL1As(0)

        ttcev = ttc.readEventCounter()
        roev = ro.readEventCounter()
        # Print the status before starting
        logging.info('ttc l1As    : %d', ttcev)
        logging.info('ro events  : %d', roev)

        src_err = ro.getNode('csr.stat.src_err').read()
        rob_err = ro.getNode('csr.stat.rob_err').read()
        ro.getClient().dispatch()

        logging.info('Source error : %d', src_err)
        logging.info('ROB error : %d', rob_err)

        tts = ro.readTTSState()

        flags = mp7.snapshot(ro.getNode('buffer.fifo_flags'))

        # print(i,flags)
        logging.info(
            'TTS: 0x%x | Fifo valid: %d, warn: %d, full: %d, empty %d: cnt: %d',
            tts, flags['fifo_valid'], flags['fifo_warn'], flags['fifo_full'],
            flags['fifo_empty'], flags['fifo_cnt'])

        # Return ttc events, ro events, time
        return (ttcev, roev, tts)
コード例 #6
0
ファイル: testDAQP5.py プロジェクト: herbberg/mp7fw_v2_4_1
    def linkStatus(self, msg=None):

        mp7daq = self._mp7
        a13 = self._amc13

        if msg:
            logging.info('- %s ---' % msg)

        ro_stat = mp7.snapshot(mp7daq.getReadout().getNode('csr.stat'))
        tts_stat = mp7.snapshot(mp7daq.getReadout().getNode('tts_csr.stat'))

        # Final Summary
        # log = logging.notice if ro_stat['amc13_rdy'] else logging.warning
        # for k in ['amc13_rdy']:
        #     log('   %s = %s', k, ro_stat[k])

        logging.debug(' MP7 Side')
        for k in sorted(ro_stat):
            logging.debug('   readout.csr.stat.%s = %s', k, ro_stat[k])

        for k in sorted(tts_stat):
            logging.debug('   readout.tts_csr.stat.%s = %s', k, tts_stat[k])

        logging.debug('-' * 80)

        slot = mp7daq.slot

        logging.debug(' AMC13 Side')
        amc13ttsenc = {
            0: 'RDY',
            1: 'OFW',
            2: 'BSY',
            4: 'SYN',
            8: 'ERR',
            16: 'DIS',
        }

        amc13ttsraw = {
            0: 'DIS',
            1: 'OFW',
            2: 'SYN',
            4: 'BSY',
            8: 'RDY',
            16: 'DIS',
        }

        # AMC13 global variables
        regs = [
            'CONF.RUN',
            'STATUS.AMC_TTS_STATE',
            'STATUS.T1_TTS_STATE',
            # 'STATUS.SFP.TTS_SFP_ABSENT',
            # 'STATUS.SFP.TTS_LOS_LOL',
            # 'STATUS.SFP.TTS_TX_FAULT',
        ]
        #        for r in regs:
        #            logging.info('   %s : %d', r,a13.read(a13.Board.T1, r))
        #
        #
        #        for s in [slot]:
        #            rdy = a13.read(a13.Board.T1,'STATUS.AMC%02d.AMC_LINK_READY_MASK' % s)
        #            enc = a13.read(a13.Board.T1,'STATUS.AMC%02d.TTS_ENCODED' % s)
        #            raw = a13.read(a13.Board.T1,'STATUS.AMC%02d.TTS_RAW' % s)
        #
        #            logging.debug('   AMC%02d.AMC_LINK_READY_MASK : %d', s, rdy )
        #            logging.debug('   AMC%02d.TTS_ENCODED : %d (%s)', s, enc, amc13ttsenc[enc] )
        #            logging.debug('   AMC%02d.TTS_RAW : %d (%s)', s, raw, amc13ttsraw[raw] )
        #            logging.debug('-'*80)

        return ro_stat['amc13_rdy']