# run 'ipython --pylab -i' # and then in ipython run: # '%run -i /home/rwilson/adc_tests/rww_tools.py setup roach2-01' # the -i there causes rww_tools.py to be run in the interactive name space import sys import os import time from corr import katcp_wrapper from corr.snap import snapshots_get from struct import pack, unpack from scipy.signal import correlate from scipy.fftpack import fft, rfft #import katcp_wrapper roach2 = katcp_wrapper.FpgaClient('roach2-00.cfa.harvard.edu') zdok = 0 import adc5g import matplotlib.pyplot as plt from matplotlib import mlab import numpy as np from numpy import math import fit_cores lanio = "lanio 131.142.9.146 " # DEFAULT_BITCODE = 'sma_corr_2014_Apr_21_1603.bof.gz' # DEFAULT_BITCODE = 'sma_corr_2014_Oct_22_1745.bof.gz' #DEFAULT_BITCODE = 'sma_corr_2014_Nov_03_1817.bof.gz' DEFAULT_BITCODE = 'sma_corr_2015_Jan_22_0908.bof.gz' freq = 10.070801 pwr = 1.0 numpoints = 16384 #samp_freq = 5000.0
'--skip', action='store_true', default=False, help='Skip programming FPGA') args = parser.parse_args() #print(roach2, katcp_port, bitstream) #print(opts.nbins, opts.fftshift, opts.gain, opts.acclen, opts.bitsel) #for i in xgbe_devices: #print(fabric_ip_string[i], fabric_ip[i], fabric_port[i], mac_base + fabric_ip[i]) #print(dest_ip_string[i], dest_ip[i], dest_port[i]) #print print('Connecting to server %s on port %i... ' % (roach2, katcp_port)), fpga = katcp_wrapper.FpgaClient(roach2, katcp_port, timeout=10, logger=logger) time.sleep(0.1) if fpga.is_connected(): print('ok') else: print('ERROR connecting to server %s on port %i.\n' % (roach2, katcp_port)) exit_fail() print('-' * 20) if not args.skip: print('Programming FPGA with %s ... ' % bitstream), fpga.progdev(bitstream)
vs._setTimeout(2) globals()[rv] = vs vsd[rn] = vs except Exception, e: print "could not connect to VegasServer", rn print e vses = vsd.values() if 'roachd' not in globals(): roachd = {} for rn in range(1, 9): rv = 'r%d' % rn #each roach will be accessed by r1, r2, etc if rv not in globals(): try: print "connecting to roach", rn roach = katcp_wrapper.FpgaClient('vegas-r%d' % rn) tic = time.time() while time.time() - tic < 2: if roach.is_connected(): break time.sleep(0.1) else: raise Exception("timeout waiting for roach") globals()[rv] = roach roachd[rn] = roach except Exception, e: print "could not connect to roach", rn print e roaches = roachd.values() ################### End setting up global namespace
def read_config_file(self, filename): """ read_config_file(filename) Reads the config file 'filename' and loads the values into data structures in memory. 'filename' should be a fully qualified filename. The config file contains a 'bank' section of interest to this bank; in addition, it contains any number of 'MODEX' sections, where 'X' is a mode name/number. """ try: config = ConfigParser.ConfigParser() config.readfp(open(filename)) if not self.bank_name: self.bank_name = self.get_bank_name(config) if not self.bank_name: sys.exit(0) bank = self.bank_name print "bank =", bank, "filename =", filename # Read general stuff: telescope = config.get( 'DEFAULTS', 'telescope').lstrip().rstrip().lstrip('"').rstrip('"') self.set_status(TELESCOP=telescope) # Read the HPC MAC addresses macs = config.items('HPCMACS') self.hpc_macs = {} for i in macs: key = _ip_string_to_int(_hostname_to_ip(i[0])) & 0xFF self.hpc_macs[key] = int(i[1], 16) # Get all bank data and store it. This is needed by any mode # where there is 1 ROACH and N Players & HPC programs banks = [s for s in config.sections() if 'BANK' in s] for bank in banks: b = BankData() b.load_config(config, bank) self.banks[bank] = b # Get config info on this bank's ROACH2. Normally there is 1 # ROACH per Player/HPC node, so this is it. self.bank_data = self.banks[self.bank_name] self.instance_id = self.bank2inst( self.bank_name) #self.bank_data.instance_id # Get config info on all modes modes = [s for s in config.sections() if 'MODE' in s] for mode in modes: m = ModeData() try: m.load_config(config, mode) except Exception, e: if self.simulate: pass else: raise e self.mode_data[mode] = m except ConfigParser.NoSectionError as e: print str(e) return str(e) # Now that all the configuration data is loaded, set up some # basic things: KATCP, Valon, etc. Not all backends will # have/need katcp & valon, so it config data says no roach & # valon, these steps will not happen. self.valon = None self.roach = None if not self.simulate and self.bank_data.has_roach: self.roach = katcp_wrapper.FpgaClient(self.bank_data.katcp_ip, self.bank_data.katcp_port, timeout=30.0) time.sleep( 1 ) # It takes the KATCP interface a little while to get ready. It's used below # by the Valon interface, so we must wait a little. # The Valon can be on this host ('local') or on the ROACH # ('katcp'), or None. Create accordingly. if self.bank_data.synth == 'local': import valon_synth self.valon = valon_synth.Synthesizer(self.bank_data.synth_port) elif self.bank_data.synth == 'katcp': from valon_katcp import ValonKATCP self.valon = ValonKATCP(self.roach, self.bank_data.synth_port) # Valon is now assumed to be working if self.valon: self.valon.set_ref_select(self.bank_data.synth_ref) self.valon.set_reference(self.bank_data.synth_ref_freq) self.valon.set_vco_range(0, *self.bank_data.synth_vco_range) self.valon.set_rf_level(0, self.bank_data.synth_rf_level) self.valon.set_options(0, *self.bank_data.synth_options) print "connecting to %s, port %i" % (self.bank_data.katcp_ip, self.bank_data.katcp_port) print self.bank_data return "config file loaded."
def main(): global roach, boffile, zdok_n, clk_rate, tone_freq, tone_amp parser = OptionParser() parser.add_option("-v", action="store_true", dest="verbose", help="use verbose output while testing") parser.add_option("-r", "--remote", dest="remote", metavar="HOST:PORT", help="run tests remotely over katcp using HOST and PORT") parser.add_option( "-b", "--boffile", dest="boffile", metavar="BOFFILE", default= "adcethvfullv64_2015_Dec_01_0023.bof", #adcethvfullv2_2014_Dec_11_1649.bof", #adcethvfullv1_2014_Dec_04_1703.bof", #"adcethvfullv1_2014_Oct_09_1231.bof", help="test using the BOFFILE bitcode") parser.add_option("-z", "--zdok", dest="zdok_n", metavar="ZDOK", type='int', default=0, help="test the ADC in the ZDOK port") parser.add_option("-c", "--clk-rate", dest="clk_rate", metavar="CLK_MHZ", type='float', default=2500.0, help="specify the input clock frequency in MHz") parser.add_option("-f", "--tone-freq", dest="tone_freq", metavar="TONE_FREQ_MHZ", type='float', default=10.0, help="specify the input tone frequency in MHz") parser.add_option( "-a", "--tone-amp", dest="tone_amp", metavar="TONE_AMP_FS", type='float', default=0.64, help="specify the input tone amplitude in units of full-scale") parser.add_option("-l", "--list", action="callback", callback=print_tests, help="list info on the tests that will be run") (options, args) = parser.parse_args() if options.verbose: verbosity = 2 else: verbosity = 1 if options.remote: if REMOTE_POSSIBLE: roach = katcp_wrapper.FpgaClient(*options.remote.split(':')) roach.wait_connected(1) else: raise ImportError("corr package was not found, " "remote operation not possible!") else: roach = adc5g.LocalRoachClient() boffile = options.boffile zdok_n = options.zdok_n clk_rate = options.clk_rate tone_freq = options.tone_freq tone_amp = options.tone_amp * 128. run_tests(verbosity)
''' Example script on how to use the dram class ''' cd ~/Documents/uWaveMux-software-devel/examples/dram/ import time from corr import katcp_wrapper import tenGbEthernet import dram roach2 = katcp_wrapper.FpgaClient('192.168.0.136', 7147) Dram = dram.DRAM(roach2) while (not roach2.is_connected()): time.sleep(1) roach2.progdev('wip_dram.bof') #initial simple write with readback Dram.dac_I = range(2**8) Dram.dac_Q = range(2**8) lut_bin = [] lut_bin = Dram.createLUTs() Dram.writeLUTs(lut_bin) addr, reg8, reg7, reg6, reg5, reg4, reg3, reg2, reg1, reg0 = dram.regReadLUT(512) for x in range(len(reg7)): print addr[x], ' ', print (reg8[x] & 0xFFFF0000) >> 16, (reg8[x] & 0x000FFFF) >> 00,' ', print (reg7[x] & 0xFFFF0000) >> 16, (reg7[x] & 0x000FFFF) >> 00,' ',
type='string', default='spead_tx_test.bof', help='Boffile to load. Default is spead_tx_test.bof') p.add_option('-v', '--verbose', dest='verbose', action='store_true', default=False, help='Be verbose about errors.') opts, args = p.parse_args(sys.argv[1:]) lh = log_handlers.DebugLogHandler() try: seng = katcp_wrapper.FpgaClient(opts.roach_ip, 7147) time.sleep(0.2) if opts.prog_fpga: print 'programming roach %s with boffile %s' % (opts.roach_ip, opts.boffile) seng.progdev(opts.boffile) else: print 'skipping programming' print 'Estimating board clock:' brd_clk = seng.est_brd_clk() print brd_clk print '\n======================' print 'Initial configuration:'
def write_ramp(bram): """Writes a frequency ramp to the test pfb Input: bram: The bram to write the test vector to """ snap.write_int('test', 1) ramp = np.arange(2**9, dtype='uint64') snap.write(bram, struct.pack('>512L', *ramp)) print('Connecting to SNAP and programming..') print( 'Make sure the ADC is calibrated in DEMUX 1 MODE, with a CLOCK FREQUENCY of 200MHz' ) snap = k.FpgaClient('10.10.0.233') time.sleep(0.1) print( 'Connected!\n\nSetting registers..\nACC_LEN:\t%d\nSHIFT:\t2047\nDEST_IP:\t10.0.10.10\nDEST_PORT:\t10000\nSYNC PERIOD: %d' % (ACC_LEN, SYNC)) snap.write_int('acc_len', ACC_LEN) snap.write_int('shift', 2047) snap.write_int('rst_of', 1) time.sleep(0.01) snap.write_int('rst_of', 0) snap.write_int('dest_ip', ((10 << 24) + (0 << 16) + (10 << 8) + (10)))