def set_roach_attn(): '''Auto-set the ROACH attenuations, plus set fftshift to 31''' import roach as r r1 = r.Roach('roach1') r1.set_attn(update=True) pktfft = r1.fpga.read_int('swreg_pkt_fft') r1.fpga.write_int('swreg_pkt_fft', (pktfft & 0xff0000) + 31) r2 = r.Roach('roach2') r2.set_attn(update=True) pktfft = r2.fpga.read_int('swreg_pkt_fft') r2.fpga.write_int('swreg_pkt_fft', (pktfft & 0xff0000) + 31) r1.fpga.stop() r2.fpga.stop()
def __init__(self, roachhost, port=7147, boffile=None, ctrl_reg='ctrl', reg_suffix='', reg_prefix='', connect_passively=True, num=0, logger=logger): """ Instantiate an engine which lives on ROACH 'roachhost' who listens on port 'port'. All shared memory belonging to this engine has a name beginning with 'reg_prefix' and ending in 'reg_suffix'. At least one control register named 'ctrl_reg' (plus pre/suffixes) should exist. After configuring these you can write to registers without these additions to the register names, allowing multiple engines to live on the same ROACH boards transparently. If 'connect_passively' is True, the Engine instance will be created and its current control software status read, but no changes to the running firmware will be made. """ self._logger = logger.getChild('(%s:%d)' % (roachhost.host, num)) #self._logger.handlers = logger.handlers self.hostname = roachhost.host self.roachhost = roach.Roach(self.hostname, port) time.sleep(0.02) self.ctrl_reg = ctrl_reg self.reg_suffix = reg_suffix self.reg_prefix = reg_prefix self.num = num if connect_passively: self.get_ctrl_sw() else: self.initialise_ctrl_sw()
def connect_to_roaches(self): """ Set up katcp connections to all ROACHes in the correlator config file. Add the FpgaClient instances to the self.fpgas list. Returns a list of boolean values, corresponding to the connection state of each ROACH in the system. """ self.fpgas = {} connected = {} for rn,roachhost in enumerate(self.roaches): self._logger.info("Connecting to ROACH %d, %s"%(rn,roachhost)) self.fpgas[roachhost] = roach.Roach(roachhost,boffile=self.c_global['boffile']) time.sleep(0.01) connected[roachhost] = self.fpgas[roachhost].is_connected() if not connected[roachhost]: self._logger.error('Could not connect to roachhost: %s'%roachhost) return connected
def grab_all(self): roachname = self.name buf = [] #adc buffer for single slot an channel self.iter_n += 1 fh = open(roachname + '-' + str(self.iter_n) + '.dat', 'wb') udata = np.zeros( (4, 50, 8192), float) #numpy array of data to return in form of [chan,slot,data] done = np.zeros( (4, 50), bool ) #values in done array are true if a given slot and channel have been processed lasttm = time( ) #last time is needed to ensure processing does not hang (gets stuck on slot 29 for some reason) rn = r.Roach(roachname) #set up the roach #loop until all slots and channels processed or stop signal sent while not np.all(done) and not self.stop: f, s = np.modf( time()) #get fractional and integer part of the time tfrac = ( np.floor(f * 50) + 1.0 ) / 50.0 #compute the fractional part of the time for the next adc read slot = int(tfrac * 50) % 50 #get the slot number for the next read sleep(tfrac - f) #wait till next read chan, = np.where( done[:, slot] == False) # get list of unprocessed channels if (chan.size > 0): #if still channels to process #print "Processing Slot "+str(slot)+" Chan "+str(chan[0]) #display slot and channel (used for error checking) #read in the adc values rn.fpga.write_int('swreg_snap_select', chan[0]) rn.fpga.write_int('adc_data_adc_ctrl', 0) # Calculate slot to be read, from time at instant before trigger is written t1 = time() rn.fpga.write_int('adc_data_adc_ctrl', 7) t2 = time() f, s = np.modf(t1) slot_read = int(f * 50) buf = rn.fpga.read('adc_data_adc_bram', 2048 * 4, 0) udata[chan[0], slot_read] = np.array(struct.unpack('>8192b', buf)) done[ chan[0], slot] = True #set value of done for current slot and channel to true lasttm = time() #update lasttm x = np.array([slot_read, t1, t2]) fh.write(x) if time( ) - lasttm > 4.0: #if more than 4 seconds since last read, the exit the loop break #go through each slot to see if any left to process if not self.stop: for slot in range(50): chan, = np.where( done[:, slot] == False) #get channels to process for current slot if chan.size > 0: #if channels left to be processed for c in chan: #go through each channel and get get adc values f, s = np.modf(time( )) #get fractional and integer part of the time dt = slot * 0.02 #get fractional part of time for current slot #wait for time to read slot if f < dt: sleep(dt - f) else: sleep(dt + 1.0 - f) #process the slot as above #print "Processing Slot "+str(slot)+" Chan "+str(c) rn.fpga.write_int('swreg_snap_select', c) rn.fpga.write_int('adc_data_adc_ctrl', 0) t1 = time() rn.fpga.write_int('adc_data_adc_ctrl', 7) t2 = time() f, s = np.modf(t1) slot_read = int(f * 50) buf = rn.fpga.read('adc_data_adc_bram', 2048 * 4, 0) udata[c, slot_read] = np.array( struct.unpack('>8192b', buf)) done[c, slot] = True x = np.array([slot_read, t1, t2]) fh.write(x) rn.fpga.stop() fh.close() return udata