casperfpga Sourcecode

CasperLogHandlers

class CasperLogHandlers.CasperConsoleHandler(name, *args, **kwargs)[source]

Stream Log Handler for casperfpga records

  • Trying a custom logger before incorporating into corr2
  • This inherits from the logging.Handler - Stream or File
__init__(name, *args, **kwargs)[source]

New method added to test logger functionality across transport layers

  • Need to add handlers for both Stream AND File
Parameters:
  • name (str) – Name of the StreamHandler
  • max_len – How many log records to store in the FIFO
clear_log()[source]

Clear the list of stored log messages

emit(record)[source]

Handle a log record

Parameters:record – Log record as a string
Returns:True/False = Success/Fail
format(record)[source]
Parameters:record – Log record as a string, of type logging.LogRecord
Returns:Formatted record
get_log_strings(num_to_print=1)[source]

Get all log messages in FIFO associated with a logger entity :param num_to_print:

print_messages(num_to_print=1)[source]

Print log messages stored in FIFO :param num_to_print:

set_max_len(max_len)[source]
Parameters:max_len
CasperLogHandlers.configure_console_logging(logger_entity, console_handler_name=None)[source]

Method to configure logging to console using the casperfpga logging entity

(A similar method exists in casperfpga)

Parameters:
  • logger_entity – Logging entity to create and add the ConsoleHandler to
  • console_handler_name (Optional) – will use logger_entity.name by default
CasperLogHandlers.configure_file_logging(logging_entity, filename=None, file_dir=None)[source]

Method to configure logging to file using the casperfpga logging entity

Parameters:
  • logging_entity – Logging entity to create and add the FileHandler to
  • filename (Optional) –
    • must be in the format of filename.log
    • Will default to casperfpga_{hostname}.log
  • file_dir (Optional) – must be a valid path
CasperLogHandlers.getLogger(*args, **kwargs)[source]

Custom method allowing us to add default handlers to a logger

Parameters:
  • logger_name – Mandatory, logger needs to have a name!
  • log_level – All Instrument-level entities log at logging.DEBUG - All Board-level entities log at logging.ERROR
Returns:

Tuple

  • Boolean Success/Fail, True/False
  • Logger entity with ConsoleHandler added as default

CasperLogHandlers.getNewLogger(*args, **kwargs)[source]

Custom method allowing us to add default handlers to a logger

Returns:Tuple
  • Boolean Success/Fail, True/False
  • Logger entity with FileHandler added as default

adc

class adc.HMCAD1511(interface, controller_name, cs=255)[source]
A_WB_W_3WIRE = 0
CGAIN_DICT_0 = {0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 0, 9: 1, 10: 2, 11: 3, 12: 12}
CGAIN_DICT_1 = {1: 0, 1.25: 1, 2: 2, 2.5: 3, 4: 4, 5: 5, 8: 6, 10: 7, 12.5: 8, 16: 9, 20: 10, 25: 11, 32: 12, 50: 13}
CGAIN_ORDER = {1: [[0, 1, 2, 3, 4, 5, 6, 7]], 2: [[0, 1, 2, 3], [4, 5, 6, 7]], 4: [[0, 1], [2, 3], [4, 5], [6, 7]]}
DICT = [{'rst': 1}, None, None, None, None, None, None, None, None, None, None, None, None, None, None, {'pd_pin_cfg': 3072, 'sleep2_ch': 48, 'sleep4_ch': 15, 'sleep1_ch1': 64, 'sleep': 256, 'pd': 512}, None, {'ilvds_lclk': 7, 'ilvds_frame': 112, 'ilvds_dat': 1792}, {'term_dat': 1792, 'term_lclk': 7, 'term_frame': 112, 'en_lvds_term': 16384}, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, {'invert4_ch': 15, 'invert1_ch1': 64, 'invert2_ch': 48}, {'dual_custom_pat': 112, 'en_ramp': 112, 'single_custom_pat': 112}, {'bits_custom1': 65280}, {'bits_custom2': 65280}, None, None, {'cgain4_ch4': 61440, 'cgain4_ch2': 240, 'cgain4_ch3': 3840, 'cgain4_ch1': 15}, {'cgain1_ch1': 3840, 'cgain2_ch1': 15, 'cgain2_ch2': 240}, None, None, None, None, {'jitter_ctrl': 255}, {'clk_divide': 768, 'channel_num': 7}, None, {'cgain_cfg': 1, 'fine_gain_en': 2}, {'fgain_branch2': 32512, 'fgain_branch1': 127}, {'fgain_branch3': 127, 'fgain_branch4': 32512}, {'fgain_branch6': 32512, 'fgain_branch5': 127}, {'fgain_branch8': 32512, 'fgain_branch7': 127}, None, None, {'inp_sel_adc2': 7936, 'inp_sel_adc1': 31}, {'inp_sel_adc3': 31, 'inp_sel_adc4': 7936}, None, None, None, None, None, None, {'phase_ddr': 96}, None, None, {'pat_deskew': 3, 'pat_sync': 3}, {'msb_first': 8, 'btc_mode': 4}, None, None, None, None, None, None, None, None, None, {'adc_curr': 7, 'ext_vcm_bc': 48}, None, {'lvds_pd_mode': 1}, {'low_clk_freq': 8, 'lvds_advance': 16, 'lvds_delay': 32}, None, {'fs_cntrl': 63}, {'startup_ctrl': 7}]
FGAIN = (0.00390625, 0.001953125, 0.0009765625, 0.00048828125, 0.000244140625, 0.0001220703125)
FGAIN_ORDER = {1: [0, 2, 5, 7, 3, 1, 6, 4], 2: [0, 2, 1, 3, 4, 6, 5, 7], 4: [0, 1, 2, 3, 4, 5, 6, 7]}
M_ADC0_CS1 = 1
M_ADC0_CS2 = 2
M_ADC0_CS3 = 4
M_ADC0_CS4 = 8
M_ADC1_CS1 = 16
M_ADC1_CS2 = 32
M_ADC1_CS3 = 64
M_ADC1_CS4 = 128
M_ADC_SCL = 512
M_ADC_SDA = 256
STATE_3WIRE_START = 1
STATE_3WIRE_STOP = 3
STATE_3WIRE_TRANS = 2
__init__(interface, controller_name, cs=255)[source]

HMCAD1511 High Speed Multi-Mode 8-Bit 1 GSPS A/D Converter

interface: an instance of casperfpga.CasperFpga controller_name: the name of the adc16_interface cs: Set cs to 0xff if you want all ADC chips share the same configuartion. Or if you want to config them separately (e.g. calibrating interleaving adc gain error for each ADC chip), set cs to 0b1, 0b10, 0b100, 0b1000… for different HMCAD1511 python objects

Here is an example of configuring a register. E.g.

# Make an instance of adc adc = HMCAD1511(interface,’adc16_interface’)

# Select the 2nd and 3rd ADCs, but unselect the 1st ADC. # cs stands for chip select. The last bit of cs is for the 1st ADC adc.cs = 0b110

# Target fields you want to configure. They belong to one register # Please refer to HMCAD1511 datasheet for more details # en_lvds_term LVDS buffers # term_lclk<2:0> LCLKN and LCLKP buffers # term_frame<2:0> FCLKN and FCLKP buffers # term_dat<2:0> output data buffers

# Get the register address and masks rid, mask = adc._getMask(‘en_lvds_term’) val = adc._set(0x0, 0b1, mask) rid, mask = adc._getMask(‘term_lclk’) val = adc._set(val, 0b011, mask) # 0b11 corresponds to 94ohm rid, mask = adc._getMask(‘term_frame’) val = adc._set(val, 0b011, mask) rid, mask = adc._getMask(‘term_dat’) val = adc._set(val, 0b011, mask)

# write value into the register adc.write(val, rid)

Please find more examples of of usage in adc.HMCAD1511.init() or snapadc.py

cGain(gains, cgain_cfg=False, fgain_cfg=False)[source]

Set the coarse gain of the ADC channels

Coarse gain control (parameters in dB). Input gain must be a list of integers. Coarse gain range for HMCAD1511: 0dB ~ 12dB E.g.

cGain([1,5,9,12]) # Quad channel mode in dB step cGain([32,50],cgain_cfg=True) # Dual channel mode in x step cGain([10],fgain_cfg=True) # Single channel mode in dB

# step, with fine gain enabled
Coarse gain options when by default cgain_cfg=False:
0 dB, 1 dB, 2 dB, 3 dB, 4 dB, 5 dB, 6 dB, 7 dB, 8 dB, 9 dB, 10 dB, 11 dB and 12 dB
Coarse gain options when cgain_cfg=True:
1x, 1.25x, 2x, 2.5x, 4x, 5x, 8x, 10x, 12.5x, 16x, 20x, 25x, 32x, 50x
fGain(gains, numChannel=1)[source]

Set the fine gain of the 8 ADC cores

Fine gain control (parameters in dB), input gain rounded towards 0 dB Fine gain range for HMCAD1511: -0.0670dB ~ 0.0665dB E.g.

fGain([-0.06, -0.04, -0.02, 0, 0, 0.02, 0.04, 0.06])
init(numChannel=4, clkDivide=1, lowClkFreq=False)[source]

Reset and initialize ADCs

Please see adc.HMCAD1511.setOperatingMode() for more explanations of the parameters

interleave(data, numChannel)[source]

Reshape and return ADC data

powerDown()[source]
powerUp()[source]
reset()[source]
selectInput(inputs)[source]

Input select

E.g.
selectInput([1,2,3,4]) (in four channel mode) selectInput([1,1,1,1]) (in one channel mode)
setOperatingMode(numChannel, clkDivide=1, lowClkFreq=False)[source]

Set interleaving mode and clock divide factor

Available Interleaving mode numChannel=1 – 8 ADC cores per channel numChannel=2 – 4 ADC cores per channel numChannel=4 – 2 ADC cores per channel

Activate lowClkFreq when
Single channel Fs < 240 MHz Dual channel Fs < 120 MHz Quad channel Fs < 60 MHz

Availale clock divide factors: 1, 2, 4, and 8

E.g.
setOperatingMode(1) setOperatingMode(4, 4)
test(mode='off', _bits_custom1=None, _bits_custom2=None)[source]

Test ADC LVDS

Set LVDS test patterns
E.g. test(‘off’)
test(‘en_ramp’) Ramp pattern 0-255 test(‘dual_custom_pat’, 0xabcd, 0xdcba) Alternate between two custom patterns test(‘single_custom_pat’, 0xaaaa) Repeat a custom pattern test(‘pat_deskew’) Deskew pattern (10101010) test(‘pat_sync’) Sync pattern (11110000)
write(data, addr)[source]
class adc.HMCAD1520(interface, controller_name, cs=255)[source]

HMCAD1520 High Speed Multi-Mode 8/12/14-Bit 1000/640/105 MSPS A/D Converter

Please see docstring of HMCAD1511 for brief description

__init__(interface, controller_name, cs=255)[source]

HMCAD1511 High Speed Multi-Mode 8-Bit 1 GSPS A/D Converter

interface: an instance of casperfpga.CasperFpga controller_name: the name of the adc16_interface cs: Set cs to 0xff if you want all ADC chips share the same configuartion. Or if you want to config them separately (e.g. calibrating interleaving adc gain error for each ADC chip), set cs to 0b1, 0b10, 0b100, 0b1000… for different HMCAD1511 python objects

Here is an example of configuring a register. E.g.

# Make an instance of adc adc = HMCAD1511(interface,’adc16_interface’)

# Select the 2nd and 3rd ADCs, but unselect the 1st ADC. # cs stands for chip select. The last bit of cs is for the 1st ADC adc.cs = 0b110

# Target fields you want to configure. They belong to one register # Please refer to HMCAD1511 datasheet for more details # en_lvds_term LVDS buffers # term_lclk<2:0> LCLKN and LCLKP buffers # term_frame<2:0> FCLKN and FCLKP buffers # term_dat<2:0> output data buffers

# Get the register address and masks rid, mask = adc._getMask(‘en_lvds_term’) val = adc._set(0x0, 0b1, mask) rid, mask = adc._getMask(‘term_lclk’) val = adc._set(val, 0b011, mask) # 0b11 corresponds to 94ohm rid, mask = adc._getMask(‘term_frame’) val = adc._set(val, 0b011, mask) rid, mask = adc._getMask(‘term_dat’) val = adc._set(val, 0b011, mask)

# write value into the register adc.write(val, rid)

Please find more examples of of usage in adc.HMCAD1511.init() or snapadc.py

init(numChannel=4, clkDivide=1, lowClkFreq=False, resolution=12)[source]

Reset and initialize ADCs

setOperatingMode(numChannel, clkDivide=1, lowClkFreq=False, resolution=12)[source]

Set operating mode and clock divide factor

Available operating mode numChannel=1 Single channel 12-bit numChannel=2 Dual channel 12-bit numChannel=4 Quad channel 12-bit numChannel=0 Quad channel 14-bit (not supported yet)

Available resolutions: resolution=8 resolution=12 resolution=14 (not supported yet)

Availale clock divide factors: 1, 2, 4, and 8

Activate lowClkFreq when
High speed, single channel Fs < 240 MHz High speed, dual channel Fs < 120 MHz High speed, quad channel Fs < 60 MHz Precision mode Fs < 30 MHz
E.g.
setOperatingMode(1, 4, False, 8) # 1 channel, 8-bit resolution, 8-bit width setOperatingMode(1, 4, False, 12) # 1 channel, 12-bit resolution, 12-bit width setOperatingMode(4, 1, False, 14) # 4 channels, 14-bit resolution, 16-bit width. (Currently not supported)

attribute_container

class attribute_container.AttributeContainer[source]

An iterable class to make registers, snapshots, etc more accessible.

__init__()[source]

x.__init__(…) initializes x; see help(type(x)) for signature

clear()[source]
keys()[source]
names()[source]
remove_attribute(attribute)[source]

Remove an attribute from this container by name.

Parameters:attribute – the name of the attribute to remove

bitfield

class bitfield.Bitfield(name, width_bits, fields=None)[source]

Describes a chunk of memory that consists of a number of Fields.

__init__(name, width_bits, fields=None)[source]
Parameters:
  • name (str) – name of the device
  • width_bits (int) – Bit-width of the Bitfield
  • fields (int) – number of fields - default to None
field_add(newfield, auto_offset=False)[source]

Add a Field to this bitfield.

field_get_by_name(field_name)[source]

Get a field from this bitfield by its name.

Parameters:field_name (str) – name of field to search for
field_names()[source]
fields_add(fields)[source]

Add a dictionary of Fields to this bitfield.

fields_clear()[source]

Reset the fields in this bitstruct.

fields_string_get()[source]

Get a string of all the field names.

class bitfield.Field(name, numtype, width_bits, binary_pt, lsb_offset)[source]

A Field object is a number of bits somewhere in a Bitfield object.

__init__(name, numtype, width_bits, binary_pt, lsb_offset)[source]

Initialise a Field object.

Parameters:
  • name – The name of the field
  • numtype

    A numerical description of the type:

    • 0 is unsigned
    • 1 is signed 2’s comp
    • 2 is boolean
  • width_bits – The width of the field, in bits
  • binary_pt – The binary point position, in bits
  • lsb_offset

    The offset in the memory field, in bits:

    • 1 means it hasn’t been set yet.
bitfield.clean_fields(parent_name, parent_type, field_str)[source]

Take the Simulink string for a field and return a list

Parameters:
  • parent_name – the BitField that will run this
  • parent_type – register, snapshot, etc
  • field_str – the string to be parsed

casperfpga

clockswitch

class clockswitch.HMC922(interface, controller_name)[source]

HMC922 DIFFERENTIAL SPDT SWITCH

__init__(interface, controller_name)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

getSwitch()[source]

getSwitch returns the current signal path being selected

setSwitch(clk)[source]

setSwitch(‘a’) or setSwitch(‘b’)

fortygbe

class fortygbe.FortyGbe(parent, name, address, length_bytes, device_info=None, position=None)[source]
__init__(parent, name, address, length_bytes, device_info=None, position=None)[source]

Implements the Gbe class. This is normally initialised from_device_info.

Parameters:
  • parent – The parent object, normally a CasperFpga instance
  • name – The name of the device
  • position – Optional - defaulted to None
  • address – Integer
  • length_bytes – Integer
  • device_info – Information about the device
static convert_128_to_64(w128)[source]
fabric_disable()[source]

Disables 40G core fabric interface. :return:

fabric_enable()[source]

Enables 40G core fabric interface. :return:

classmethod from_device_info(parent, device_name, device_info, memorymap_dict, **kwargs)[source]

Process device info and the memory map to get all necessary info and return a TenGbe instance.

Parameters:
  • parent – the parent device, normally an FPGA instance
  • device_name – the unique device name
  • device_info – information about this device
  • memorymap_dict – a dictionary containing the device memory map
Returns:

a TenGbe object

get_arp_details(port_dump=None)[source]

Get ARP details from this interface.

Parameters:port_dump (list) – A list of raw bytes from interface memory; if not supplied, fetch from hardware.
get_gbe_core_details(read_arp=False, read_cpu=False)[source]

Get the details of the ethernet core from the device memory map. Updates local variables as well.

get_hw_gbe_stats(rst_counters=False)[source]

Get the traffic statistics of the ethernet core from the device memory map. ::param:: rst_counters: reset the counters after reading them. :return:

get_ip()[source]

Retrieve core’s IP address from HW.

Returns:IpAddress object
get_mac()[source]

Retrieve core’s configured MAC address from HW.

Returns:Mac object
get_port()[source]

Retrieve core’s port from HW.

Returns:int
get_stats()[source]

Retrieves some statistics for this core. Needs to have the debug registers compiled-in to the core at 32b.

ip_address
mac
multicast_receive(ip_str, group_size, port=7148)[source]

Send a request to KATCP to have this tap instance send a multicast group join request.

Parameters:
  • ip_str – A dotted decimal string representation of the base mcast IP address.
  • group_size – An integer for how many additional mcast addresses (from base) to subscribe to. Must be (2^N-1), ie 0, 1, 3, 7, 15 etc.
  • port – The UDP port on which you want to receive. Note that only one port is possible per interface (ie it’s global and will override any other port you may have configured).
port
post_create_update(raw_device_info)[source]

Update the device with information not available at creation.

Parameters:raw_device_info – info about this block that may be useful
print_arp_details(refresh=False, only_hits=False)[source]

Print nicely formatted ARP info. :param refresh: :param only_hits:

print_gbe_core_details(arp=False, cpu=False, refresh=True)[source]

Prints 40GbE core details.

static process_snap_data(d)[source]
read_rxsnap()[source]

Read the RX snapshot embedded in this GbE yellow block

read_txsnap()[source]

Read the TX snapshot embedded in this GbE yellow block

set_port(port)[source]
Parameters:port

gbe

class gbe.Gbe(parent, name, address, length_bytes, device_info=None)[source]

A (multi)gigabit network interface on a device.

__init__(parent, name, address, length_bytes, device_info=None)[source]

Most of initialised from_device_info in child classes

Parameters:
  • parent
  • name
  • device_info
fabric_disable()[source]

Enable the core fabric

fabric_enable()[source]

Enable the core fabric

classmethod from_device_info(parent, device_name, device_info, memorymap_dict, **kwargs)[source]

Process device info and the memory map to get all necessary info and return a Gbe instance.

Parameters:
  • parent – the parent device, normally an FPGA instance
  • device_name – the unique device name
  • device_info – information about this device
  • memorymap_dict – a dictionary containing the device memory map
Returns:

a Gbe object

get_arp_details(port_dump=None)[source]

Get ARP details from this interface.

Parameters:port_dump (list) – A list of raw bytes from interface memory.
get_cpu_details(port_dump=None)[source]

Read details of the CPU buffers.

Parameters:port_dump
get_gbe_core_details(read_arp=False, read_cpu=False)[source]
Parameters:
  • read_arp
  • read_cpu
ip_address
mac
multicast_receive(ip_str, group_size)[source]

Send a multicast group join request.

Parameters:
  • ip_str – A dotted decimal string representation of the base mcast IP address.
  • group_size – An integer for how many mcast addresses from base to respond to.
multicast_remove(ip_str)[source]

Send a request to be removed from a multicast group.

Parameters:ip_str – A dotted decimal string representation of the base mcast IP address.
port
post_create_update(raw_device_info)[source]

Update the device with information not available at creation.

Parameters:raw_device_info – info about this block that may be useful
print_arp_details(refresh=False, only_hits=False)[source]

Print nicely formatted ARP info.

Parameters:
  • refresh
  • only_hits
print_cpu_details(refresh=False)[source]

Print nicely formatted CPU details info.

Parameters:refresh
print_gbe_core_details(arp=False, cpu=False, refresh=True)[source]

Prints 10GbE core details.

Parameters:
  • arp (boolean) – include the ARP table
  • cpu (boolean) – include the CPU packet buffers
  • refresh – read the 10gbe details first
process_device_info(device_info)[source]

Process device info to setup GbE object

Parameters:device_info

Dictionary including:

  • IP Address
  • Mac Address
  • Port number
read_counters()[source]

Read all the counters embedded in this TenGBE yellow block

read_rx_counters()[source]

Read all RX counters embedded in this TenGBE yellow block

read_rxsnap()[source]

Read the RX snapshot embedded in this GbE yellow block

read_tx_counters()[source]

Read all TX counters embedded in this TenGBE yellow block

read_txsnap()[source]

Read the TX snapshot embedded in this GbE yellow block

rx_okay(wait_time=0.2, checks=10)[source]
Is this gbe core receiving okay?
i.e. _rxctr incrementing and _rxerrctr not incrementing
Parameters:
  • wait_time – seconds to wait between checks
  • checks – times to run check
Returns:

True/False

setup(mac, ipaddress, port, gateway=None, subnet_mask=None)[source]

Set up the MAC, IP and port for this interface

Parameters:
  • mac – String or Integer input, MAC address (e.g. ‘02:00:00:00:00:01’)
  • ipaddress – String or Integer input, IP address (eg ‘10.0.0.1’)
  • port – String or Integer input
tx_okay(wait_time=0.2, checks=10)[source]
Is this gbe core transmitting okay?
i.e. _txctr incrementing and _txerrctr not incrementing
Parameters:
  • wait_time – seconds to wait between checks
  • checks – times to run check
Returns:

True/False

i2c

class i2c.I2C(fpga, controller_name, **kwargs)[source]
__init__(fpga, controller_name, **kwargs)[source]

I2C module for I2C yellow block

fpga: casperfpga.CasperFpga instance controller_name: The name of the I2C yellow block retry_wait: Time interval between pulling status of I2C module,

Default value is 0.02. Typical range between [0.1, 0.001].
disable_core()[source]

Disable the wb-i2c core.

  • Set the I2C enable bit to 0,
  • Set the interrupt bit to 0 (disabled).
enable_core()[source]

Enable the wb-i2c core.

  • Set the I2C enable bit to 1,
  • Set the interrupt bit to 0 (disabled).
getClock(reference=None)[source]

Get I2C clock speed

If the reference clock speed is not provided, this method returns the preScale, which equals to:

preScale = int((reference*1e3/(5*target))-1)

where target is the desired I2C clock speed in kHz. Reference clock speed is in MHz.

getClock()          # Returns the value of the divider
getClock(100)       # Returns the I2C clock speed given a reference
                    # clock speed at 100 MHz
getStatus()[source]

Get current status of the I2C module

The status is kept in a dict structure, items of which include:

  • ACK Acknowledge from Slave
  • BUSY Busy i2c bus
  • ARB Lost Arbitration
  • TIP Transfer in Progress
  • INT Interrupt Pending
probe()[source]
read(addr, cmd=None, length=1)[source]

I2C read

Read arbitary number of bytes from an internal address of a slave device. Some I2C datasheets refer to internal address as command (cmd) as well.

Parameters:
  • addr – 7-bit integer, address of the slave device
  • cmd – a byte of a list of bytes, the internal address of the slave device
  • length – non-negative integer, the number of bytes to read

The return is a byte when length==1, or a list of bytes otherwise.

read(0x40)  # Read a byte from the slave device at 0x40, without
            # specifying an internal address
read(0x40,0xe3) # Read a byte from the internal address 0xe3 of the slave
                # at 0x40
read(0x40,length=3) # Read 3 bytes from the slave at 0x40 without specifying
                    # an internal address
read(0x40,[0xfa,0x0f],4)    # Read 4 bytes from the internal address [0xfa,0x0f]
                            # of the slave at 0x40
setClock(target, reference=100)[source]

Set I2C bus clock

The I2C module uses a divider to generate its clock from a reference clock, e.g. a system clock at 100 MHz. The acutally generated I2C clock speed might be slightly different from the target clock speed specified. Reference clock speed in MHz and target clock speed in kHz

setClock(10,100)    # Set I2C bus clock speed to 10 kHz, given a system clock of 100 MHz
write(addr, cmd=None, data=None)[source]

I2C write

Write arbitary number of bytes to an internal address of a slave device. Some I2C datasheets refer to internal address as command (cmd) as well.

Parameters:
  • addr – 7-bit integer, address of the slave device
  • cmd – a byte of a list of bytes, the internal address of the slave device
  • data – a byte of a list of bytes to write
write(0x40,0x1)     # Write 0x1 to slave device at 0x40
write(0x40,0x1,0x2) # Write 0x2 to the internal address 0x1 of the
                    # slave device at address 0x40
write(0x40,data=0x2)    # Write 0x2 to the slave at 0x40, without specifying
                        # an internal address
write(0x40,[0x1,0x2],[0x3,0x4]) # Write [0x3,0x4] to the internal address [0x1,0x2]
                                # of the slave at 0x40
class i2c.I2C_DEVICE(itf, addr)[source]

I2C device base class

DICT = {}
__init__(itf, addr)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

getRegister(rid=None)[source]
getWord(name)[source]
read(reg=None, length=1)[source]
setWord(name, value)[source]
write(reg=None, data=None)[source]
class i2c.I2C_PIGPIO(sda, scl, baud)[source]
__init__(sda, scl, baud)[source]

PIGPIO based I2C

I2C module powered by PIGPIO library.

Parameters:
  • sda – The gpio number of sda pin.
  • scl – The gpio number of scl pin
  • baud – The baud rate of the I2C bus

Be noticed that gpio number is different from pin number!

read(addr, cmd=None, length=1)[source]

I2C read

Read arbitary number of bytes from an internal address of a slave device. Some I2C datasheets refer to internal address as command (cmd) as well.

Parameters:
  • addr – 7-bit integer, address of the slave device
  • cmd – a byte of a list of bytes, the internal address of the slave device
  • length – non-negative integer, the number of bytes to read

The return is a byte when length==1, or a list of bytes otherwise.

read(0x40)  # Read a byte from the slave device at 0x40, without
            # specifying an internal address
read(0x40,0xe3) # Read a byte from the internal address 0xe3 of the slave
                # at 0x40
read(0x40,length=3) # Read 3 bytes from the slave at 0x40 without specifying
                    # an internal address
read(0x40,[0xfa,0x0f],4)    # Read 4 bytes from the internal address [0xfa,0x0f]
                            # of the slave at 0x40
write(addr, cmd=None, data=None)[source]

I2C write

Write arbitary number of bytes to an internal address of a slave device. Some I2C datasheets refer to internal address as command (cmd) as well.

Parameters:
  • addr – 7-bit integer, address of the slave device
  • cmd – a byte of a list of bytes, the internal address of the slave device
  • data – a byte of a list of bytes to write
write(0x40,0x1)     # Write 0x1 to slave device at 0x40
write(0x40,0x1,0x2) # Write 0x2 to the internal address 0x1 of the
                    # slave device at address 0x40
write(0x40,data=0x2)    # Write 0x2 to the slave at 0x40, without specifying
                        # an internal address
write(0x40,[0x1,0x2],[0x3,0x4]) # Write [0x3,0x4] to the internal address [0x1,0x2]
                                # of the slave at 0x40
class i2c.I2C_SMBUS(devid)[source]
__init__(devid)[source]
read(addr, cmd=None, length=1)[source]
write(addr, cmd=None, data=[])[source]

i2c_bar

class i2c_bar.MS5611_01B(itf, addr=119)[source]
OSR_PRESS = {256: 64, 512: 66, 1024: 68, 2048: 70, 4096: 72}
OSR_TEMP = {256: 80, 512: 82, 1024: 84, 2048: 86, 4096: 88}
__init__(itf, addr=119)[source]
crc4(data)[source]

input: 16bit * 8 data list

init()[source]
read(reg=None, length=1)[source]
readCalibration()[source]
readPress(rawtemp=None, dt=None, osr=4096)[source]

Return air pressure

readPress()     # return raw data with osr=4096
readPress(2007,2366)    # return return compensated data with osr=4096

To get rawtemp and dt:

rawtemp, dt = readTemp(raw=True)
readTemp(raw=False, osr=4096)[source]

Return the temperature

readTemp()      # return the temperature
readTemp(raw=True)  # return the raw temperature data together with dt
reset()[source]
toAltitude(bar, temp, P0=1013.25)[source]

Convert air pressure and temperature to altitude

  • bar is air pressure, temp is temperature
  • P0 is air presure at sea level
toAltitude(1000.09,20.07)

To get raw temp:

rawtemp, dt = readTemp(raw=True)

To get bar:

bar = readPress(rawtemp, dt)
write(reg=None, data=None)[source]

i2c_eeprom

class i2c_eeprom.EEP24XX64(itf, addr=81)[source]

64 Kbit Electrically Erasable PROM

__init__(itf, addr=81)[source]
read(reg, length=1)[source]

Read byte(s) out of ROM

read(0)     # read a byte out from address 0 of the ROM
read(0x20,16)   # read 200 bytes from address 0x20 to 0x2f
readString()[source]

Read a string out of the ROM

Read byte(s) and intepret as ASCII character(s). Expect a ‘’ at the end of the string

size = 8192
write(reg, data)[source]

Write byte(s) into ROM

write(0,0xff)       # write 0xff to address 0x00
write(0x10,range(8192)) # write range(8192) to address from 0x10 to 0x1fff
writeString(chars)[source]

Write a string into the ROM

Write the input string into the ROM. Only ASCII characters are allowed A character of ‘’ will be appended to the string to indicate the end of the string.

writeString('Haha')

i2c_gpio

class i2c_gpio.PCF8574(itf, addr=32)[source]

Operate a PCF8574 chip. PCF8574 is a Remote 8-Bit I/O Expander for I2C BUS

__init__(itf, addr=32)[source]
read()[source]
write(data)[source]

i2c_motion

class i2c_motion.AK8963(itf, addr=12)[source]
DICT = {0: {'wia': 255}, 1: {'info': 255}, 2: {'DOR': 2, 'DRDY': 1, 'st1': 255}, 3: {'hxl': 255}, 4: {'hxh': 255}, 5: {'hyl': 255}, 6: {'hyh': 255}, 7: {'hzl': 255}, 8: {'hzh': 255}, 9: {'BITM': 16, 'HOFL': 8, 'st2': 255}, 10: {'BIT': 16, 'MODE': 15, 'cntl1': 255}, 11: {'SRST': 1, 'cntl2': 255}, 12: {'SELF': 64, 'astc': 255}, 13: {'ts1': 255}, 14: {'ts2': 255}, 15: {'i2cdis': 255}, 16: {'asax': 255}, 17: {'asay': 255}, 18: {'asaz': 255}}
WHOAMI = 72
__init__(itf, addr=12)[source]

AK8963 magnetometer

If integrated with mpu9250, make an instance of mpu9250 and enable aux i2c before using AK8963

adj = array([0, 0, 0])
getAdjustment()[source]
getWord(name)[source]
init()[source]

Initialise AKB8963

mag
read(reg, length=1)[source]
reset()[source]
selftest()[source]
setWord(name, value)[source]
whoami()[source]
write(reg, data)[source]
class i2c_motion.IMUSimple(bus, mpuaddr=105, akaddr=None, orient=[[1, 0, 0], [0, 1, 0], [0, 0, 1]])[source]
__init__(bus, mpuaddr=105, akaddr=None, orient=[[1, 0, 0], [0, 1, 0], [0, 0, 1]])[source]

IMUSimple IMU usage demo

bus = i2c.I2C_IPGPIO(2,3,15000)
imu = i2c_motion.IMUSimple(bus,0x69,0x0c)
imu.init()
print(imu.pose)

Default orientation:

  • x+ east
  • y+ north
  • z+ upward
  • IMU chip pin 1 in 4th quadrant
  • IMU chip top side upwards

provide other orientations in the following format:

imu = IMUSimple(bus,0x69, orient =
            [[1,0,0],    # new x+ in old coordinate system
            [0,1,0],    # new y+ in old coordinate system
            [0,0,1]])   # new z+ in old coordinate system
accel
calcRotationMatrix(dst)[source]
gyro
init()[source]
mag
pose
class i2c_motion.MPU9250(itf, addr=104)[source]

9-axis MotionTracking device that combines a 3-axis gyroscope, 3-axis accelerometer, 3-axis magnetometer and a Digital Motion Processor (DMP) all in a small 3x3x1mm package available as a pin-compatible upgrade from the MPU-6515

DICT = {0: {'XG_ST_DATA': 255}, 1: {'YG_ST_DATA': 255}, 2: {'ZG_ST_DATA': 255}, 13: {'XA_ST_DATA': 255}, 14: {'YA_ST_DATA': 255}, 15: {'ZA_ST_DATA': 255}, 19: {'X_OFFS_USR_H': 255}, 20: {'X_OFFS_USR_L': 255}, 21: {'Y_OFFS_USR_H': 255}, 22: {'Y_OFFS_USR_L': 255}, 23: {'Z_OFFS_USR_H': 255}, 24: {'Z_OFFS_USR_L': 255}, 25: {'SMPLRT_DIV': 255}, 26: {'DLPF_CFG': 7, 'EXT_SYNC_SET': 56, 'FIFO_MODE': 64, 'config': 255}, 27: {'FCHOICE_B': 3, 'GYRO_FS_SEL': 24, 'XGYRO_CTEN': 128, 'YGYRO_CTEN': 64, 'ZGYRO_CTEN': 32, 'gyro_config': 255}, 28: {'ACCEL_FS_SEL': 24, 'AX_ST_EN': 128, 'AY_ST_EN': 64, 'AZ_ST_EN': 32, 'accel_config': 255}, 29: {'ACCEL_FCHOICE_B': 12, 'A_DLPF_CFG': 3, 'accel_config2': 255}, 30: {'LPOSC_CLKSEL': 15}, 31: {'WOM_THRESHOLD': 255}, 35: {'ACCEL': 8, 'GYRO_XOUT': 64, 'GYRO_YOUT': 32, 'GYRO_ZOUT': 16, 'SLV0': 1, 'SLV1': 2, 'SLV2': 4, 'TEMP_FIFO_EN': 128, 'fifo_en': 255}, 36: {'I2C_MST_CLK': 15, 'I2C_MST_P_NSR': 16, 'MULT_MST_EN': 128, 'SLV_3_FIFO_EN': 32, 'WAIT_FOR_ES': 64, 'i2c_mst_ctrl': 255}, 37: {'I2C_ID_0': 127, 'I2C_SLV0_RNW': 128}, 38: {'I2C_SLV0_REG': 255}, 39: {'I2C_SLV0_BYTE_SW': 64, 'I2C_SLV0_EN': 128, 'I2C_SLV0_GRP': 16, 'I2C_SLV0_LENG': 15, 'I2C_SLV0_REG_DIS': 32}, 40: {'I2C_ID_1': 127, 'I2C_SLV1_RNW': 128}, 41: {'I2C_SLV1_REG': 255}, 42: {'I2C_SLV1_BYTE_SW': 64, 'I2C_SLV1_EN': 128, 'I2C_SLV1_GRP': 16, 'I2C_SLV1_LENG': 15, 'I2C_SLV1_REG_DIS': 32}, 43: {'I2C_ID_2': 127, 'I2C_SLV2_RNW': 128}, 44: {'I2C_SLV2_REG': 255}, 45: {'I2C_SLV2_BYTE_SW': 64, 'I2C_SLV2_EN': 128, 'I2C_SLV2_GRP': 16, 'I2C_SLV2_LENG': 15, 'I2C_SLV2_REG_DIS': 32}, 46: {'I2C_ID_3': 127, 'I2C_SLV3_RNW': 128}, 47: {'I2C_SLV3_REG': 255}, 48: {'I2C_SLV3_BYTE_SW': 64, 'I2C_SLV3_EN': 128, 'I2C_SLV3_GRP': 16, 'I2C_SLV3_LENG': 15, 'I2C_SLV3_REG_DIS': 32}, 49: {'I2C_ID_4': 127, 'I2C_SLV4_RNW': 128}, 50: {'I2C_SLV3_REG': 255}, 51: {'I2C_SLV4_DO': 255}, 52: {'I2C_MST_DLY': 15, 'I2C_SLV4_EN': 128, 'I2C_SLV4_REG_DIS': 32, 'SLV4_DONE_INT_EN': 64}, 53: {'I2C_SLV4_DI': 255}, 54: {'I2C_LOST_ARB': 32, 'I2C_SLV0_NACK': 1, 'I2C_SLV1_NACK': 2, 'I2C_SLV2_NACK': 4, 'I2C_SLV3_NACK': 8, 'I2C_SLV4_DONE': 64, 'I2C_SLV4_NACK': 16, 'PASS_THROUGH': 128}, 55: {'ACTL': 128, 'ACTL_FSYNC': 8, 'BYPASS_EN': 2, 'FSYNC_INT_MODE_EN': 4, 'INT_ANYRD_2CLEAR': 16, 'LATCH_INT_EN': 32, 'OPEN': 64, 'int_pin_cfg': 255}, 56: {'FIFO_OFLOW_EN': 16, 'FSYNC_INT_EN': 8, 'RAW_RDY_EN': 1, 'WOM_EN': 64, 'int_enable': 255}, 58: {'FIFO_OFLOW_INT': 16, 'FSYNC_INT': 8, 'INT_STATUS': 255, 'RAW_DATA_RDY_INT': 1, 'WOM_INT': 64}, 59: {'ACCEL_XOUT_H': 255}, 60: {'ACCEL_XOUT_L': 255}, 61: {'ACCEL_YOUT_H': 255}, 62: {'ACCEL_YOUT_L': 255}, 63: {'ACCEL_ZOUT_H': 255}, 64: {'ACCEL_ZOUT_L': 255}, 65: {'TEMP_OUT_H': 255}, 66: {'TEMP_OUT_L': 255}, 67: {'GYRO_XOUT_H': 255}, 68: {'GYRO_XOUT_L': 255}, 69: {'GYRO_YOUT_H': 255}, 70: {'GYRO_YOUT_L': 255}, 71: {'GYRO_ZOUT_H': 255}, 72: {'GYRO_ZOUT_L': 255}, 73: {'EXT_SENS_DATA_00': 255}, 74: {'EXT_SENS_DATA_01': 255}, 75: {'EXT_SENS_DATA_02': 255}, 76: {'EXT_SENS_DATA_03': 255}, 77: {'EXT_SENS_DATA_04': 255}, 78: {'EXT_SENS_DATA_05': 255}, 79: {'EXT_SENS_DATA_06': 255}, 80: {'EXT_SENS_DATA_07': 255}, 81: {'EXT_SENS_DATA_08': 255}, 82: {'EXT_SENS_DATA_09': 255}, 83: {'EXT_SENS_DATA_10': 255}, 84: {'EXT_SENS_DATA_11': 255}, 85: {'EXT_SENS_DATA_12': 255}, 86: {'EXT_SENS_DATA_13': 255}, 87: {'EXT_SENS_DATA_14': 255}, 88: {'EXT_SENS_DATA_15': 255}, 89: {'EXT_SENS_DATA_16': 255}, 90: {'EXT_SENS_DATA_17': 255}, 91: {'EXT_SENS_DATA_18': 255}, 92: {'EXT_SENS_DATA_19': 255}, 93: {'EXT_SENS_DATA_20': 255}, 94: {'EXT_SENS_DATA_21': 255}, 95: {'EXT_SENS_DATA_22': 255}, 96: {'EXT_SENS_DATA_23': 255}, 99: {'I2C_SLV0_DO': 255}, 100: {'I2C_SLV1_DO': 255}, 101: {'I2C_SLV2_DO': 255}, 102: {'I2C_SLV3_DO': 255}, 103: {'DELAY_ES_SHADOW': 128, 'I2C_SLV0_DLY_EN': 1, 'I2C_SLV1_DLY_EN': 2, 'I2C_SLV2_DLY_EN': 4, 'I2C_SLV3_DLY_EN': 8, 'I2C_SLV4_DLY_EN': 16}, 104: {'ACCEL_RST': 2, 'GYRO_RST': 4, 'TEMP_RST': 1}, 105: {'ACCEL_INTEL_EN': 128, 'ACCEL_INTEL_MODE': 64}, 106: {'FIFO_EN': 64, 'FIFO_RST': 4, 'I2C_IF_DIS': 16, 'I2C_MST_EN': 32, 'I2C_MST_RST': 2, 'SIG_COND_RST': 1, 'user_ctrl': 255}, 107: {'CLKSEL': 7, 'CYCLE': 32, 'GYRO_STANDBY': 16, 'H_RESET': 128, 'PD_PTAT': 8, 'SLEEP': 64, 'pwr_mgmt_1': 255}, 108: {'DIS_XA': 32, 'DIS_XG': 4, 'DIS_YA': 16, 'DIS_YG': 2, 'DIS_ZA': 8, 'DIS_ZG': 1, 'pwr_mgmt_2': 255}, 114: {'FIFO_CNT_H': 31}, 115: {'FIFO_CNT_L': 255}, 116: {'D': 255, 'fifo_r_w': 255}, 117: {'WHOAMI': 255}, 119: {'XA_OFFS_H': 255}, 120: {'XA_OFFS_L': 254}, 122: {'YA_OFFS_H': 255}, 123: {'YA_OFFS_L': 254}, 125: {'ZA_OFFS_H': 255}, 126: {'ZA_OFFS_L': 254}}
WHOAMI = 113
__init__(itf, addr=104)[source]
accel
accel_offs
accel_scale
calibrate(WRITE_OFFSET_REG=True)[source]

Not working

getRegister(rid=None)[source]
getWord(name)[source]
gyro
gyro_offs
gyro_scale
init(gyro=True, accel=True, lowpower=False)[source]

Initialise MPU9250

interpretAccel(data, scale=None)[source]
interpretGyro(data, scale=None)[source]
powerOff()[source]
read(reg, length=1)[source]
readFIFO(types, length=None, filename=None, raw=False, wait=0.001)[source]

read FIFO and sort data into categories according to given types

readFIFO({'accel':True,'gyro':True})
readFIFO({'accel':True,'gyro':True},length=1200)
readFIFO({'accel':True,'slv0':8},filename='/tmp/data.txt')
readFIFOCount()[source]

Read the number of data available in the FIFO

reset()[source]
setAccelSamplingRate(conf)[source]

Accelerometer sampling rate

parameter conf is in range(9)

num bandwidth (Hz) delay (ms) fs (Hz)
0 1130 0.75 4000
1 460 1.94 1000
2 184 5.8 1000
3 92 7.8 1000
4 41 11.8 1000
5 20 19.8 1000
6 10 35.7 1000
7 5 66.96 1000
8 460 1.94 1000
setFIFO(accel=False, temp=False, gyro=False, slv0=False, slv1=False, slv2=False, slv3=False)[source]
setGyroSamplingRate(conf)[source]

Gyroscope sampling rate

parameter conf is in range(10)

num bandwidth (Hz) delay (ms) fs (Hz)
0 8800 0.064 32000
1 3600 0.11 32000
2 250 0.97 8000
3 184 2.9 1000
4 92 3.9 1000
5 41 5.9 1000
6 20 9.9 1000
7 10 17.85 1000
8 5 33.48 1000
9 3600 0.17 8000
setWord(name, value)[source]
sortFIFOData(types, data=None)[source]

Sort a serial of data into categories according to given types

sortFIFOData({'accel':True,'gyro':True},[0,0,16383,0,0,0])
whoami()[source]
write(reg, data)[source]
i2c_motion.signed(data, bitwidth)[source]

Convert an unsigned data into a 32-bit signed data

signed(0xfff,12) # it's -1
signed(0xff,12) # it's 255

i2c_temp

class i2c_temp.Si7051(itf, addr=64, resolution=14)[source]

Si7051 I2C Temperature Sensors

__init__(itf, addr=64, resolution=14)[source]
cmdFirmRev = [132, 184]

Read Firmware Revision

cmdMeasure = 227

Measure temperature

cmdMeasureN = 243
cmdSNA = [250, 15]

Read Serial Number

cmdSNB = [252, 201]
cmdUserRegR = 231
cmdUserRegW = 230

Write and read user register for resolution config and VDD status checking

crc8(data, poly, initVal=0, bigendian=True)[source]
crcInitVal = 0
crcPoly = 305

CRC generator polynomial and initial value

read(reg=None, length=1)[source]
readTemp()[source]
resBase = 11

Resolution related numbers

resD0Mask = 1
resD1Mask = 128
resList = [0, 1, 128, 129]

11 bit, 12 bit, 13 bit, 14 bit

resTop = 14
sn()[source]

64-bit big-endian serial number with CRC

strFirmRev = {32: 'Firmware version 2.0', 255: 'Firmware version 1.0'}
vddOK = 0
vddStatusMask = 64
write(reg=None, data=None)[source]

i2c_volt

class i2c_volt.INA219(itf, addr=69)[source]

INA219 Zero-Drift, Bidirectional Current/Power Monitor With I2C Interface

ADC = {1: 8, 2: 9, 4: 10, 8: 11, 16: 12, 32: 13, 64: 14, 128: 15, '10b': 1, '11b': 2, '12b': 3, '9b': 0}
BRNG = {16: 0, 32: 1}
DICT = {0: {'BADC': 1920, 'BRNG': 8192, 'MODE': 7, 'PG': 6144, 'RST': 32768, 'SADC': 120, 'configuration': 65535}, 1: {'shuntvoltage': 65535}, 2: {'BD': 65528, 'CNVR': 2, 'OVF': 1, 'busvoltage': 65535}, 3: {'power': 65535}, 4: {'current': 65535}, 5: {'calibration': 65535}}
PG = {40: 0, 80: 1, 160: 2, 320: 3}
__init__(itf, addr=69)[source]
getRegister(rid=None)[source]
getStatus(name='CNVR')[source]
getWord(name)[source]
init(brng=16, pg=320, badc=128, sadc=128, mode=3)[source]

Initialise INA219

Mode, available options:
MODE3 MODE2 MODE1 MODE 0 0 0 Power-down 0 0 1 Shunt voltage, triggered 0 1 0 Bus voltage, triggered 0 1 1 Shunt and bus, triggered 1 0 0 ADC off (disabled) 1 0 1 Shunt voltage, continuous 1 1 0 Bus voltage, continuous 1 1 1 Shunt and bus, continuous
BRNG, Bus voltage range, available options:
16,32
PG, for choosing the full scale range. Available options:
40, 80, 160, 320,
ADC, for bus voltage as well as shunt voltage measurement.
Available options: Do one sample of the following resolution ‘9b’, ‘10b’, ‘11b’, ‘12b’, or do 12bit resolution and average over the following number of samples: 1, 2, 4, 8, 16, 32, 64, 128,
read(reg=None, length=2)[source]
readVolt(name)[source]

Read Voltage

Please switch to corresponding modes using init() before measuring voltage. Possible options are:

‘shunt’ ‘bus’

E.g. readVolt(‘shunt’)

setWord(name, value)[source]
write(reg=None, data=None)[source]
class i2c_volt.LTC2990(itf, addr=79)[source]

Quad I2C Voltage, Current and Temperature Monitor

CDIFFERENTIAL = 1.942e-05
CSINGLEENDED = 0.00030518
DICT = {0: {'BUSY': 1, 'TINTREADY': 2, 'V1READY': 4, 'V2READY': 8, 'V3READY': 16, 'V4READY': 32, 'VCCREADY': 64}, 1: {'MODE0': 7, 'MODE1': 24, 'REPEATSINGLE': 64, 'TEMPERATUREFORMAT': 128}, 2: {'TRIGGER': 255}, 4: {'TINTMSB': 255}, 5: {'TINTLSB': 255}, 6: {'V1MSB': 255}, 7: {'V1LSB': 255}, 8: {'V2MSB': 255}, 9: {'V2LSB': 255}, 10: {'V3MSB': 255}, 11: {'V3LSB': 255}, 12: {'V4MSB': 255}, 13: {'V4LSB': 255}, 14: {'VCCMSB': 255}, 15: {'VCCLSB': 255}}
MODE0 = {0: ['v1', 'v2', 'tr2', 'tr2'], 1: ['v1-v2', 'v1-v2', 'tr2', 'tr2'], 2: ['v1-v2', 'v1-v2', 'v3', 'v4'], 3: ['tr1', 'tr1', 'v3', 'v4'], 4: ['tr1', 'tr1', 'v3-v4', 'v3-v4'], 5: ['tr1', 'tr1', 'tr2', 'tr2'], 6: ['v1-v2', 'v1-v2', 'v3-v4', 'v3-v4'], 7: ['v1', 'v2', 'v3', 'v4']}
MSB = {'TEMP': {'DATA': 63, 'DV': 128, 'SO': 32, 'SS': 64}, 'VOLT': {'DATA': 127, 'DV': 128}}
TEMPFACTOR = 16.0
VCCBIAS = 2.5
__init__(itf, addr=79)[source]
fmt = 0
getRegister(rid=None)[source]
getStatus(name=None)[source]
getWord(name)[source]
init(fmt='celsius', repeat=False, mode1=3, mode0=7)[source]

Initialise LTC2990

mode0 Description
0 V1, V2, TR2(Default)
1 V1-V2, TR2
2 V1-V2, V3, V4
3 TR1, V3, V4
4 TR1, V3-V4
5 TR1, TR2
6 V1-V2, V3-V4
7 V1, V2, V3, V4
mode1 Description
0 Internal Temperature Only (Default)
1 TR1, V1 or V1-V2 Only per Mode[2:0]
2 TR2, V3 or V3-V4 Only per Mode[2:0]
3 All Measurements per Mode[2:0]
mode0 = 0
mode1 = 3
read(reg=None, length=1)[source]
readTemp()[source]
readVolt(name)[source]

Read Voltage

Please switch to corresponding modes using init() before measuring voltage.

Possible options are:

  • vcc
  • v1
  • v2
  • v3
  • v4
  • v1-v2
  • v3-v4
readVolt('v1-v2')
repeat = 1
setWord(name, value)[source]
write(reg=None, data=None)[source]
class i2c_volt.MAX11644(itf, addr=54)[source]
LSB = 0.001
__init__(itf, addr=54)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

init(**kwargs)[source]
readVolt(name=None)[source]

Read voltage Possible options are

AIN0 AIN1
reset()[source]
i2c_volt.str2int(s)[source]

katadc

Created on Feb 28, 2013

@author: paulp

class katadc.KatAdc(parent, name, address, length, device_info)[source]

Information above KatAdc yellow blocks. Seems to be called most often via from_device_info.

__init__(parent, name, address, length, device_info)[source]

Initialise a KatAdc object with the following parameters.

Parameters:
  • parent – The owner of this block.
  • name – The name of this block.
  • address
  • length
  • device_info
classmethod from_device_info(parent, device_name, device_info, memorymap_dict, **kwargs)[source]

Process device info and the memory map to get all necessary info and return a KatAdc instance.

Parameters:
  • device_name – the unique device name
  • device_info – information about this device
  • memorymap_dict – a dictionary containing the device memory map
Returns:

a KatAdc object

memory

The base class for all things memory. More or less everything on the FPGA is accessed by reading and writing memory addresses on the EPB/OPB busses. Normally via KATCP.

class memory.Memory(name, width_bits, address, length_bytes)[source]

Memory on an FPGA.

__init__(name, width_bits, address, length_bytes)[source]

A chunk of memory on a device.

Parameters:
  • name – a name for this memory
  • width_bits – the width, in BITS, PER WORD
  • address – the start address in device memory
  • length_bytes – length, in BYTES

e.g. a Register has width_bits=32, length_bytes=4

e.g.2. a Snapblock could have width_bits=128, length_bytes=32768

length_in_words()[source]
Returns:the memory block’s length, in Words
read(**kwargs)[source]

Read raw binary data and convert it using the bitfield description for this memory.

Returns:(data dictionary, read time)
read_raw(**kwargs)[source]

Placeholder for child classes.

Returns:(rawdata, timestamp)
write(**kwargs)[source]
write_raw(uintvalue)[source]
memory.bin2fp(raw_word, bitwidth, bin_pt, signed)[source]

Convert a raw number based on supplied characteristics.

Parameters:
  • raw_word – the number to convert
  • bitwidth – its width in bits
  • bin_pt – the location of the binary point
  • signed – whether it is signed or not
Returns:

the formatted number, long, float or int

memory.cast_fixed(fpnum, bitwidth, bin_pt)[source]

Represent a fixed point number as an unsigned number, like the Xilinx reinterpret block.

Parameters:
  • fpnum
  • bitwidth
  • bin_pt
memory.fp2fixed(num, bitwidth, bin_pt, signed)[source]

Convert a floating point number to its fixed point equivalent.

Parameters:
  • num
  • bitwidth
  • bin_pt
  • signed
memory.fp2fixed_int(num, bitwidth, bin_pt, signed)[source]

Compatability function, rather use the other functions explicitly.

network

class network.IpAddress(ip)[source]

An IP address.

__init__(ip)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

static ip2str(ip_addr)[source]

Convert an IP in integer form to a human-readable string.

is_multicast()[source]

Does the data source’s IP address begin with 239?

packed()[source]
static str2ip(ip_str)[source]

Convert a human-readable IP string to an integer.

class network.Mac(mac)[source]

A MAC address. Can either be initialised with a IP-string or 32-bit integer.

__init__(mac)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

classmethod from_hostname(hostname, port_num)[source]
classmethod from_roach_hostname(hostname, port_num)[source]

Make a MAC address object from a ROACH hostname

static mac2str(mac)[source]

Convert a MAC in integer form to a human-readable string.

packed()[source]
static str2mac(mac_str)[source]

Convert a human-readable MAC string to an integer.

qdr

Created on Fri Mar 7 07:15:45 2014

@author: paulp

class qdr.Qdr(parent, name, address, length_bytes, device_info, ctrlreg_address)[source]

Qdr memory on an FPGA.

__init__(parent, name, address, length_bytes, device_info, ctrlreg_address)[source]

Make the QDR instance, given a parent, name and info from Simulink.

  • Most often called from_device_info
Parameters:
  • parent – Parent device who owns this Qdr
  • name – A unique device name
  • address – Address of the Qdr in memory
  • length_bytes – Length of the Qdr in memory
  • device_info – Information about this Qdr device
  • ctrlreg_address
classmethod from_device_info(parent, device_name, device_info, memorymap_dict, **kwargs)[source]

Process device info and the memory map to get all necessary info and return a Qdr instance.

Parameters:
  • parent
  • device_name – the unique device name
  • device_info – information about this device
  • memorymap_dict – a dictionary containing the device memory map
Returns:

a Qdr object

qdr_cal(fail_hard=True)[source]
qdr_cal_check(step=-1, quickcheck=True)[source]

Checks calibration on a qdr. Raises an exception if it failed.

Parameters:
  • step – the current step
  • quickcheck – if True, return after the first error, else process all test vectors before returning
qdr_check_cal_any_good(current_step, checkoffset=4194304)[source]

Checks calibration on a qdr.

Parameters:
  • current_step – what is the current output delay step
  • checkoffset – where to write the test data
Returns:

True if any of the bits were good

qdr_reset()[source]

Resets the QDR and the IO delays (sets all taps=0).

reset()[source]

Reset the QDR controller by toggling the lsb of the control register. Sets all taps to zero (all IO delays reset).

qdr.find_cal_area(a)[source]

Given a vector of pass (1) and fail (-1), find contiguous chunks of ‘pass’.

Parameters:a – Vector input (list?)
Returns:Tuple - (max_so_far, begin_index, end_index)
qdr.logl0(msg)[source]
qdr.logl1(msg)[source]
qdr.logl2(msg)[source]
qdr.logl3(msg)[source]

register

class register.Register(parent, name, address, device_info=None, auto_update=False)[source]

A CASPER register on an FPGA.

__init__(parent, name, address, device_info=None, auto_update=False)[source]
Parameters:
  • parent
  • name
  • address
  • device_info
  • auto_update
blindwrite(**kwargs)[source]

As write, but without checking the result

classmethod from_device_info(parent, device_name, device_info, memorymap_dict, **kwargs)[source]

Process device info and the memory map to get all necessary info and return a Register instance.

Parameters:
  • parent – the parent device
  • device_name – the unique device name
  • device_info – information about this device
  • memorymap_dict – a dictionary containing the device memory map
Returns:

a Register object

info()[source]

Return a string with information about this Register instance.

process_info(info)[source]

Set this Register’s extra information.

read(**kwargs)[source]

Memory.read returns a list for all bitfields, so just put those values into single values.

read_raw(**kwargs)[source]

Read a raw 4-byte value from the host device. Size is 4-bytes.

Parameters:kwargs
read_uint(**kwargs)[source]
write(**kwargs)[source]

Write fields in a register, using keyword arguments for fields

Parameters:kwargs
write_int(uintvalue, blindwrite=False, word_offset=0)[source]

Write an unsigned integer to this device using the fpga client.

write_raw(data, blindwrite=False)[source]

Use the katcp_client_fpga write integer function.

write_single(value)[source]

Write single value.

Parameters:value

sbram

class sbram.Sbram(parent, name, address, length_bytes, width_bits, device_info=None)[source]

General SBRAM memory on the FPGA.

__init__(parent, name, address, length_bytes, width_bits, device_info=None)[source]

A chunk of memory on a device.

Parameters:
  • name – a name for this memory
  • width_bits – the width, in BITS, PER WORD
  • address – the start address in device memory
  • length_bytes – length, in BYTES

e.g. a Register has width_bits=32, length_bytes=4

e.g.2. a Snapblock could have width_bits=128, length_bytes=32768

classmethod from_device_info(parent, device_name, device_info, memorymap_dict, **kwargs)[source]

Process device info and the memory map to get all necessary info and return a Sbram instance.

Parameters:
  • parent – the CasperFpga that hosts this SBRAM
  • device_name – the unique device name
  • device_info – information about this device
  • memorymap_dict – a dictionary containing the device memory map
Returns:

a Sbram object

read_raw(**kwargs)[source]

Read raw data from memory.

scroll

Playing with ncurses in Python to scroll up and down, left and right, through a list of data that is periodically refreshed.

Revs:
2010-12-11: JRM Added concat for status line to prevent bailing on small terminals. Code cleanup to prevent modification of external variables. Added left, right page controls
class scroll.Screenline(data, xpos, ypos, cr=True, fixed=False, attributes=0)[source]
__init__(data, xpos, ypos, cr=True, fixed=False, attributes=0)[source]
Parameters:
  • data – A String to be placed on the screen
  • xpos – x position, -1 means at current xpos
  • ypos – y position, -1 means at current ypos
  • ypos – if True, start a new line after this one
  • fixed – if True, always at this pos from top left, scrolling makes no difference
  • attributes – Curses string attributes
class scroll.Scroll(debug=False)[source]

Scrollable ncurses screen.

__init__(debug=False)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

add_line(new_line, attributes=0)[source]

Add a text line to the screen buffer.

Parameters:
  • new_line
  • attributes
add_string(new_str, xpos=-1, ypos=-1, cr=False, fixed=False, attributes=0)[source]

Add a string to a position on the screen.

Parameters:
  • new_str
  • xpos
  • ypos
  • cr
  • fixed
  • attributes
clear_buffer()[source]
clear_screen()[source]

Clear the ncurses screen.

cr()[source]

Carriage return, go to the next line

draw_screen(data=None)[source]

Draw the screen using the provided data TODO: ylimits, xlimits, proper line counts in the status

get_current_line()[source]

Return the current y position of the internal screen buffer.

get_instruction_string()[source]
on_keypress()[source]

Handle key presses.

screen_setup()[source]

Set up a curses screen object and associated options

set_current_line(linenum)[source]

Set the current y position of the internal screen buffer.

Parameters:linenum
set_instruction_string(new_string)[source]
set_xlimits(xmin=-1, xmax=-1)[source]
set_ylimits(ymin=-1, ymax=-1)[source]
scroll.screen_teardown()[source]

Restore sensible options to the terminal upon exit

skarab_definitions

Description: Definitions for the Skarab Motherboard.

  • Includes
  • OPCCODES
  • PORTS
  • Register Masks
  • Data structures
class skarab_definitions.BigReadWishboneReq(start_address_high, start_address_low, number_of_reads)[source]
__init__(start_address_high, start_address_low, number_of_reads)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.BigReadWishboneResp(command_id, seq_num, start_address_high, start_address_low, number_of_reads, read_data)[source]
__init__(command_id, seq_num, start_address_high, start_address_low, number_of_reads, read_data)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
static unpack_process(unpacked_data)[source]
class skarab_definitions.BigWriteWishboneReq(start_address_high, start_address_low, write_data, number_of_writes)[source]
__init__(start_address_high, start_address_low, write_data, number_of_writes)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.BigWriteWishboneResp(command_id, seq_num, start_address_high, start_address_low, number_of_writes_done, error_status, padding)[source]
__init__(command_id, seq_num, start_address_high, start_address_low, number_of_writes_done, error_status, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.ClearFanControllerLogsReq[source]
__init__()[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.ClearFanControllerLogsResp(command_id, seq_num, status, padding)[source]
__init__(command_id, seq_num, status, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.Command(command_id, seq_num=None)[source]

The Command Packet structure for SKARAB communications

__init__(command_id, seq_num=None)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
create_payload(seq_num)[source]

Create payload for sending via UDP Packet to SKARAB

Returns:string representation of data
static pack_two_bytes(data)[source]
static unpack_two_bytes(data)[source]
class skarab_definitions.ConfigureMulticastReq(interface_id, fabric_multicast_ip_address_high, fabric_multicast_ip_address_low, fabric_multicast_ip_address_mask_high, fabric_multicast_ip_address_mask_low)[source]
__init__(interface_id, fabric_multicast_ip_address_high, fabric_multicast_ip_address_low, fabric_multicast_ip_address_mask_high, fabric_multicast_ip_address_mask_low)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.ConfigureMulticastResp(command_id, seq_num, interface_id, fabric_multicast_ip_address_high, fabric_multicast_ip_address_low, fabric_multicast_ip_address_mask_high, fabric_multicast_ip_address_mask_low, status, padding)[source]
__init__(command_id, seq_num, interface_id, fabric_multicast_ip_address_high, fabric_multicast_ip_address_low, fabric_multicast_ip_address_mask_high, fabric_multicast_ip_address_mask_low, status, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.Current[source]
P12V2Current = 0
P12VCurrent = 1
P1V0Current = 7
P1V0MGTAVCCCurrent = 9
P1V2Current = 6
P1V2MGTAVTTCurrent = 10
P1V8Current = 5
P1V8MGTVCCAUXCurrent = 8
P2V5Current = 4
P3V3ConfigCurrent = 11
P3V3Current = 3
P5VCurrent = 2
class skarab_definitions.DebugAddARPCacheEntryReq(interface_id, ip_address_lower_8_bits, mac_high, mac_mid, mac_low)[source]
__init__(interface_id, ip_address_lower_8_bits, mac_high, mac_mid, mac_low)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.DebugAddARPCacheEntryResp(command_id, seq_num, interface_id, ip_address_lower_8_bits, mac_high, mac_mid, mac_low, padding)[source]
__init__(command_id, seq_num, interface_id, ip_address_lower_8_bits, mac_high, mac_mid, mac_low, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.DebugConfigureEthernetReq(interface_id, fabric_mac_high, fabric_mac_mid, fabric_mac_low, fabric_port_address, gateway_arp_cache_address, fabric_ip_address_high, fabric_ip_address_low, fabric_multicast_ip_address_high, fabric_multicast_ip_address_low, fabric_multicast_ip_address_mask_high, fabric_multicast_ip_address_mask_low, enable_fabric_interface)[source]
__init__(interface_id, fabric_mac_high, fabric_mac_mid, fabric_mac_low, fabric_port_address, gateway_arp_cache_address, fabric_ip_address_high, fabric_ip_address_low, fabric_multicast_ip_address_high, fabric_multicast_ip_address_low, fabric_multicast_ip_address_mask_high, fabric_multicast_ip_address_mask_low, enable_fabric_interface)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.DebugConfigureEthernetResp(command_id, seq_num, interface_id, fabric_mac_high, fabric_mac_mid, fabric_mac_low, fabric_port_address, gateway_arp_cache_address, fabric_ip_address_high, fabric_ip_address_low, fabric_multicast_ip_address_high, fabric_multicast_ip_address_low, fabric_multicast_ip_address_mask_high, fabric_multicast_ip_address_mask_low, enable_fabric_interface, padding)[source]
__init__(command_id, seq_num, interface_id, fabric_mac_high, fabric_mac_mid, fabric_mac_low, fabric_port_address, gateway_arp_cache_address, fabric_ip_address_high, fabric_ip_address_low, fabric_multicast_ip_address_high, fabric_multicast_ip_address_low, fabric_multicast_ip_address_mask_high, fabric_multicast_ip_address_mask_low, enable_fabric_interface, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.DebugLoopbackTestReq(interface_id, test_data)[source]
__init__(interface_id, test_data)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.DebugLoopbackTestResp(command_id, seq_num, interface_id, test_data, valid, padding)[source]
__init__(command_id, seq_num, interface_id, test_data, valid, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.EraseFlashBlockReq(block_address_high, block_address_low)[source]
__init__(block_address_high, block_address_low)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.EraseFlashBlockResp(command_id, seq_num, block_address_high, block_address_low, erase_success, padding)[source]
__init__(command_id, seq_num, block_address_high, block_address_low, erase_success, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.EraseSpiSectorReq(sector_address_high, sector_address_low)[source]
__init__(sector_address_high, sector_address_low)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.EraseSpiSectorResp(command_id, seq_num, sector_address_high, sector_address_low, erase_success, padding)[source]
__init__(command_id, seq_num, sector_address_high, sector_address_low, erase_success, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.Fan[source]
FPGAFan = 4
LeftBackFan = 2
LeftFrontFan = 0
LeftMiddleFan = 1
RightBackFan = 3
class skarab_definitions.GetCurrentLogsReq[source]
__init__()[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.GetCurrentLogsResp(command_id, seq_num, current_mon_logs, status)[source]
__init__(command_id, seq_num, current_mon_logs, status)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
static unpack_process(unpacked_data)[source]
class skarab_definitions.GetDHCPMonitorTimeoutReq[source]
__init__()[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.GetDHCPMonitorTimeoutResp(command_id, seq_num, dhcp_monitor_timeout, padding)[source]
__init__(command_id, seq_num, dhcp_monitor_timeout, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.GetEmbeddedSoftwareVersionReq[source]
__init__()[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.GetEmbeddedSoftwareVersionResp(command_id, seq_num, version_major, version_minor, version_patch, qsfp_bootloader_version_major, qsfp_bootloader_version_minor, padding)[source]
__init__(command_id, seq_num, version_major, version_minor, version_patch, qsfp_bootloader_version_major, qsfp_bootloader_version_minor, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.GetFanControllerLogsReq[source]
__init__()[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.GetFanControllerLogsResp(command_id, seq_num, fan_cont_mon_logs, status, padding)[source]
__init__(command_id, seq_num, fan_cont_mon_logs, status, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
static unpack_process(unpacked_data)[source]
class skarab_definitions.GetSensorDataReq[source]
__init__()[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.GetSensorDataResp(command_id, seq_num, sensor_data, status)[source]
__init__(command_id, seq_num, sensor_data, status)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
static unpack_process(unpacked_data)[source]
class skarab_definitions.GetVoltageLogsReq[source]
__init__()[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.GetVoltageLogsResp(command_id, seq_num, voltage_mon_logs, status)[source]
__init__(command_id, seq_num, voltage_mon_logs, status)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
static unpack_process(unpacked_data)[source]
class skarab_definitions.Mezzanine[source]
Mezzanine0 = 0
Mezzanine1 = 1
Mezzanine2 = 2
Mezzanine3 = 3
class skarab_definitions.MulticastLeaveGroupReq(link_id)[source]
__init__(link_id)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.MulticastLeaveGroupResp(command_id, seq_num, link_id, success, padding)[source]
__init__(command_id, seq_num, link_id, success, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.OneWireDS2433ReadMemReq(device_rom, skip_rom_address, num_bytes, target_address_1, target_address_2, one_wire_port)[source]
__init__(device_rom, skip_rom_address, num_bytes, target_address_1, target_address_2, one_wire_port)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.OneWireDS2433ReadMemResp(command_id, seq_num, device_rom, skip_rom_address, read_bytes, num_bytes, target_address_1, target_address_2, one_wire_port, read_success, padding)[source]
__init__(command_id, seq_num, device_rom, skip_rom_address, read_bytes, num_bytes, target_address_1, target_address_2, one_wire_port, read_success, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
static unpack_process(unpacked_data)[source]
class skarab_definitions.OneWireDS2433WriteMemReq(device_rom, skip_rom_address, write_bytes, num_bytes, target_address_1, target_address_2, one_wire_port)[source]
__init__(device_rom, skip_rom_address, write_bytes, num_bytes, target_address_1, target_address_2, one_wire_port)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.OneWireDS2433WriteMemResp(command_id, seq_num, device_rom, skip_rom_address, write_bytes, num_bytes, target_address_1, target_address_2, one_wire_port, write_success, padding)[source]
__init__(command_id, seq_num, device_rom, skip_rom_address, write_bytes, num_bytes, target_address_1, target_address_2, one_wire_port, write_success, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
static unpack_process(unpacked_data)[source]
class skarab_definitions.OneWireReadROMReq(one_wire_port)[source]
__init__(one_wire_port)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.OneWireReadROMResp(command_id, seq_num, one_wire_port, rom, read_success, padding)[source]
__init__(command_id, seq_num, one_wire_port, rom, read_success, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
static unpack_process(unpacked_data)[source]
class skarab_definitions.PMBusReadI2CBytesReq(i2c_interface_id, slave_address, command_code, read_bytes, num_bytes)[source]
__init__(i2c_interface_id, slave_address, command_code, read_bytes, num_bytes)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.PMBusReadI2CBytesResp(command_id, seq_num, i2c_interface_id, slave_address, command_code, read_bytes, num_bytes, read_success)[source]
__init__(command_id, seq_num, i2c_interface_id, slave_address, command_code, read_bytes, num_bytes, read_success)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
static unpack_process(unpacked_data)[source]
class skarab_definitions.ProgramFlashWordsReq(address_high, address_low, total_num_words, packet_num_words, do_buffered_programming, start_program, finish_program, write_words)[source]
__init__(address_high, address_low, total_num_words, packet_num_words, do_buffered_programming, start_program, finish_program, write_words)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.ProgramFlashWordsResp(command_id, seq_num, address_high, address_low, total_num_words, packet_num_words, do_buffered_programming, start_program, finish_program, program_success, padding)[source]
__init__(command_id, seq_num, address_high, address_low, total_num_words, packet_num_words, do_buffered_programming, start_program, finish_program, program_success, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.ProgramSpiPageReq(address_high, address_low, num_bytes, write_bytes)[source]
__init__(address_high, address_low, num_bytes, write_bytes)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.ProgramSpiPageResp(command_id, seq_num, address_high, address_low, num_bytes, verify_bytes, program_spi_page_success, padding)[source]
__init__(command_id, seq_num, address_high, address_low, num_bytes, verify_bytes, program_spi_page_success, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
static unpack_process(unpacked_data)[source]
class skarab_definitions.QSFPResetAndProgramReq(reset, program)[source]
__init__(reset, program)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.QSFPResetAndProgramResp(command_id, seq_num, reset, program, padding)[source]
__init__(command_id, seq_num, reset, program, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.ReadFlashWordsReq(address_high, address_low, num_words)[source]
__init__(address_high, address_low, num_words)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.ReadFlashWordsResp(command_id, seq_num, address_high, address_low, num_words, read_words, padding)[source]
__init__(command_id, seq_num, address_high, address_low, num_words, read_words, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
static unpack_process(unpacked_data)[source]
class skarab_definitions.ReadHMCI2CReq(interface_id, slave_address, read_address)[source]
__init__(interface_id, slave_address, read_address)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.ReadHMCI2CResp(command_id, seq_num, interface_id, slave_address, read_address, read_bytes, read_success, padding)[source]
__init__(command_id, seq_num, interface_id, slave_address, read_address, read_bytes, read_success, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
static unpack_process(unpacked_data)[source]
class skarab_definitions.ReadI2CReq(i2c_interface_id, slave_address, num_bytes)[source]
__init__(i2c_interface_id, slave_address, num_bytes)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.ReadI2CResp(command_id, seq_num, i2c_interface_id, slave_address, num_bytes, read_bytes, read_success, padding)[source]
__init__(command_id, seq_num, i2c_interface_id, slave_address, num_bytes, read_bytes, read_success, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
static unpack_process(unpacked_data)[source]
class skarab_definitions.ReadRegReq(board_reg, reg_addr)[source]
__init__(board_reg, reg_addr)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.ReadRegResp(command_id, seq_num, board_reg, reg_addr, reg_data_high, reg_data_low, padding)[source]
__init__(command_id, seq_num, board_reg, reg_addr, reg_data_high, reg_data_low, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.ReadSpiPageReq(address_high, address_low, num_bytes)[source]
__init__(address_high, address_low, num_bytes)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.ReadSpiPageResp(command_id, seq_num, address_high, address_low, num_bytes, read_bytes, read_spi_page_success, padding)[source]
__init__(command_id, seq_num, address_high, address_low, num_bytes, read_bytes, read_spi_page_success, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
static unpack_process(unpacked_data)[source]
class skarab_definitions.ReadWishboneReq(address_high, address_low)[source]
__init__(address_high, address_low)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.ReadWishboneResp(command_id, seq_num, address_high, address_low, read_data_high, read_data_low, error_status, padding)[source]
__init__(command_id, seq_num, address_high, address_low, read_data_high, read_data_low, error_status, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.ResetDHCPStateMachineReq(link_id)[source]
__init__(link_id)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.ResetDHCPStateMachineResp(command_id, seq_num, link_id, reset_error, padding)[source]
__init__(command_id, seq_num, link_id, reset_error, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.Response(command_id, seq_num=None)[source]
classmethod from_raw_data(rawdata, number_of_words, pad_words)[source]

Unpack the rawdata and return a Response object :param rawdata: :param number_of_words: :param pad_words: :return:

static unpack_preprocess(rawdata, number_of_words, pad_words)[source]
static unpack_process(unpacked_data)[source]
class skarab_definitions.SdramProgramReq(first_packet, last_packet, write_words)[source]
__init__(first_packet, last_packet, write_words)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.SdramProgramWishboneReq(chunk_id, num_total_chunks, image_data)[source]
__init__(chunk_id, num_total_chunks, image_data)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.SdramProgramWishboneResp(command_id, seq_num, chunk_id, ack, padding)[source]
__init__(command_id, seq_num, chunk_id, ack, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.SdramReconfigureReq(output_mode, clear_sdram, finished_writing, about_to_boot, do_reboot, reset_sdram_read_address, clear_ethernet_stats, enable_debug_sdram_read_mode, do_sdram_async_read, do_continuity_test, continuity_test_output_low, continuity_test_output_high)[source]
__init__(output_mode, clear_sdram, finished_writing, about_to_boot, do_reboot, reset_sdram_read_address, clear_ethernet_stats, enable_debug_sdram_read_mode, do_sdram_async_read, do_continuity_test, continuity_test_output_low, continuity_test_output_high)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.SdramReconfigureResp(command_id, seq_num, output_mode, clear_sdram, finished_writing, about_to_boot, do_reboot, reset_sdram_read_address, clear_ethernet_stats, enable_debug_sdram_read_mode, do_sdram_async_read, num_ethernet_frames, num_ethernet_bad_frames, num_ethernet_overload_frames, sdram_async_read_data_high, sdram_async_read_data_low, do_continuity_test, continuity_test_output_low, continuity_test_output_high)[source]
__init__(command_id, seq_num, output_mode, clear_sdram, finished_writing, about_to_boot, do_reboot, reset_sdram_read_address, clear_ethernet_stats, enable_debug_sdram_read_mode, do_sdram_async_read, num_ethernet_frames, num_ethernet_bad_frames, num_ethernet_overload_frames, sdram_async_read_data_high, sdram_async_read_data_low, do_continuity_test, continuity_test_output_low, continuity_test_output_high)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.SetFanSpeedReq(fan_page, pwm_setting)[source]
__init__(fan_page, pwm_setting)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.SetFanSpeedResp(command_id, seq_num, fan_speed_pwm, fan_speed_rpm, padding)[source]
__init__(command_id, seq_num, fan_speed_pwm, fan_speed_rpm, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
exception skarab_definitions.SkarabInvalidBitstream[source]
exception skarab_definitions.SkarabProgrammingError[source]
class skarab_definitions.Tempsensor[source]
FPGATemp = 2
FanContTemp = 7
InletTemp = 0
Mezzanine0Temp = 3
Mezzanine1Temp = 4
Mezzanine2Temp = 5
Mezzanine3Temp = 6
OutletTemp = 1
class skarab_definitions.Voltage[source]
P12V2Voltage = 0
P12VVoltage = 1
P1V0MGTAVCCVoltage = 9
P1V0Voltage = 7
P1V2MGTAVTTVoltage = 10
P1V2Voltage = 6
P1V8MGTVCCAUXVoltage = 8
P1V8Voltage = 5
P2V5Voltage = 4
P3V3ConfigVoltage = 11
P3V3Voltage = 3
P5VVoltage = 2
class skarab_definitions.WriteHMCI2CReq(interface_id, slave_address, write_address, write_data)[source]
__init__(interface_id, slave_address, write_address, write_data)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.WriteHMCI2CResp(command_id, seq_num, interface_id, slave_address, write_address, write_data, write_success, padding)[source]
__init__(command_id, seq_num, interface_id, slave_address, write_address, write_data, write_success, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
static unpack_process(unpacked_data)[source]
class skarab_definitions.WriteI2CReq(i2c_interface_id, slave_address, num_bytes, write_bytes)[source]
__init__(i2c_interface_id, slave_address, num_bytes, write_bytes)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.WriteI2CResp(command_id, seq_num, i2c_interface_id, slave_address, num_bytes, write_bytes, write_success)[source]
__init__(command_id, seq_num, i2c_interface_id, slave_address, num_bytes, write_bytes, write_success)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
static unpack_process(unpacked_data)[source]
class skarab_definitions.WriteRegReq(board_reg, reg_addr, reg_data_high, reg_data_low)[source]
__init__(board_reg, reg_addr, reg_data_high, reg_data_low)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.WriteRegResp(command_id, seq_num, board_reg, reg_addr, reg_data_high, reg_data_low, padding)[source]
__init__(command_id, seq_num, board_reg, reg_addr, reg_data_high, reg_data_low, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.WriteWishboneReq(address_high, address_low, write_data_high, write_data_low)[source]
__init__(address_high, address_low, write_data_high, write_data_low)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value
class skarab_definitions.WriteWishboneResp(command_id, seq_num, address_high, address_low, write_data_high, write_data_low, error_status, padding)[source]
__init__(command_id, seq_num, address_high, address_low, write_data_high, write_data_low, error_status, padding)[source]

A command will always have the following parameters/properties

Parameters:
  • command_id – Integer value
  • seq_num – Integer value

skarab_fileops

snap

class snap.Snap(parent, name, width_bits, address, length_bytes, device_info=None)[source]

Snap blocks are triggered/controlled blocks of RAM on FPGAs.

__init__(parent, name, width_bits, address, length_bytes, device_info=None)[source]

A chunk of memory on a device.

Parameters:
  • name – a name for this memory
  • width_bits – the width, in BITS, PER WORD
  • address – the start address in device memory
  • length_bytes – length, in BYTES

e.g. a Register has width_bits=32, length_bytes=4

e.g.2. a Snapblock could have width_bits=128, length_bytes=32768

arm(man_trig=False, man_valid=False, offset=-1, circular_capture=False)[source]

Arm the snapshot block.

Parameters:
  • man_trig (bool) –
  • man_valid (bool) –
  • offset (int) –
  • circular_capture (bool) –
classmethod from_device_info(parent, device_name, device_info, memorymap_dict, **kwargs)[source]

Process device info and the memory map to get all necessary info and return a Snap instance.

Parameters:
  • parent – the Casperfpga on which this snap is found
  • device_name – the unique device name
  • device_info – information about this device
  • memorymap_dict – a dictionary containing the device memory map
Returns:

a Snap object

static packetise_snapdata(data, eof_key='eof', packet_length=-1, dv_key=None)[source]

Use the given EOF key to packetise a dictionary of snap data

Parameters:
  • data – a dictionary containing snap block data
  • eof_key – the key used to identify the packet boundaries - the eof comes on the LAST VALID word in a packet
  • packet_length – check the length of the packets against this as they are created (in 64-bit words)
  • dv_key – the key used to identify which data samples are valid
Returns:

a list of packets

post_create_update(raw_system_info)[source]

Update the device with information not available at creation.

Parameters:raw_system_info – dictionary of device information
print_snap(limit_lines=-1, **kwargs)[source]

Read and print(a snap block.)

Parameters:
  • limit_lines – limit the number of lines to print
  • offset – trigger offset
  • man_valid – force valid to be true
  • man_trig – force a trigger now
  • circular_capture – enable circular capture
  • timeout – time out after this many seconds
  • read_nowait – do not wait for the snap to finish reading
read(**kwargs)[source]

Override Memory.read to handle the extra value register.

Parameters:
  • offset – trigger offset
  • man_valid – force valid to be true
  • man_trig – force a trigger now
  • circular_capture – enable circular capture
  • timeout – time out after this many seconds
  • read_nowait – do not wait for the snap to finish reading
read_raw(**kwargs)[source]

Read snap data from the memory device.

update_from_bitsnap(info)[source]

Update this device with information from a bitsnap container.

Parameters:info – device information dictionary containing Simulink block information

snapadc

class snapadc.SnapAdc(parent, device_name, device_info, initialise=False)[source]
A_WB_W_3WIRE = 0
A_WB_W_CTRL = 1
A_WB_W_DELAY_STROBE_H = 3
A_WB_W_DELAY_STROBE_L = 2
ERROR_FRAME = 4
ERROR_LINE = 3
ERROR_LMX = 1
ERROR_MMCM = 2
ERROR_RAMP = 5
M_WB_W_DELAY_TAP = 31
M_WB_W_DEMUX_MODE = 50331648
M_WB_W_DEMUX_WRITE = 67108864
M_WB_W_ISERDES_BITSLIP_CHIP_SEL = 65280
M_WB_W_ISERDES_BITSLIP_LANE_SEL = 224
M_WB_W_RESET = 1048576
M_WB_W_SNAP_REQ = 65536
SUCCESS = 0
WB_DICT = [{'ADC16_LOCKED': 50331648, 'ADC16_ADC3WIRE_REG': 65535, 'G_ROACH2_REV': 196608, 'CONTROLLER_REV': 786432, 'G_NUM_UNITS': 15728640, 'G_ZDOK_REV': 805306368}, None, None, None, {'ADC16_CTRL_REG': 4294967295}, None, None, None, {'ADC16_DELAY_STROBE_REG_H': 4294967295}, None, None, None, {'ADC16_DELAY_STROBE_REG_L': 4294967295}]
__init__(parent, device_name, device_info, initialise=False)[source]

Initialise SnapAdc Object :param parent: Parent object creating the SnapAdc Object :type parent: casperfpga.CasperFpga

Parameters:
  • device_name (str) – Name of SnapAdc Object
  • device_info (dict) –
  • intialise – Trigger ADC SerDes calibration.
Returns:

None

example device_info = {‘adc_resolution’: ‘8’,
‘sample_rate’: ‘200’, ‘snap_inputs’: ‘12’, ‘tag’: ‘xps:snap_adc’}
align_frame_clock()[source]

Align the frame clock with data frame

align_line_clock(mode='dual_pat')[source]

Align the rising edge of line clock with data eye

And return the tap settings being using

bitslip(chipSel=None, laneSel=None)[source]

Reorder the parallelize data for word-alignment purpose

Reorder the parallelized data by asserting a itslip command to the bitslip submodule of a ISERDES primitive. Each bitslip command left shift the parallelized data by one bit.

HMCAD1511/HMCAD1520 lane correspondence lane number lane name in ADC datasheet 0 1a 1 1b 2 2a 3 2b 4 3a 5 3b 6 4a 7 4b

E.g. .. code-block:: python

bitslip() # left shift all lanes of all ADCs bitslip(0) # shift all lanes of the 1st ADC bitslip(0,3) # shift the 4th lane of the 1st ADC bitslip([0,1],[3,4]) # shift the 4th and 5th lanes of the 1st

# and the 2nd ADCs
calibrate_adc_offset()[source]
calibration_adc_gain()[source]
clksw = None
controller = None
curDelay = None
decide_delay(data)[source]

Decide and return proper setting for delay tap

Find the tap setting that has the largest margin of error, i.e. the biggest distance to borders (tap=0 and tap=31) and rows with non-zero deviations/mismatches. The parameter data is a 32 by n numpy array, in which the 1st dimension index indicates the delay tap setting

delay(tap, chipSel=None, laneSel=None)[source]

Delay the serial data from ADC LVDS links

Delay the serial data by Xilinx IDELAY primitives E.g.

delay(0) # Set all delay tap of IDELAY to 0 delay(4, 1, 7) # set delay on the 8th lane of the 2nd ADC to 4 delay(31, [0,1,2], [0,1,2,3,4,5,6,7])

# Set all delay taps (in SNAP 1 case) to 31
classmethod from_device_info(parent, device_name, device_info, initialise=False, **kwargs)[source]

Process device info and the memory map to get all the necessary info and return a SNAP ADC instance. :param parent: The parent device, normally a casperfpga instance :param device_name: :param device_info: :param initialise: :param kwargs: :return:

get_reg_id(name)[source]
get_register(rid=None)[source]
get_word(name)[source]
init(sample_rate=None, num_channel=None)[source]

Get SNAP ADCs into working condition

Supported frequency range: 60MHz ~ 1000MHz. Set resolution to None to let init() automatically decide the best resolution.

A run of init() takes approximatly 20 seconds, involving the following actions:

  1. configuring frequency synthesizer LMX2581
  2. configuring clock source switch HMC922
  3. configuring ADCs HMCAD1511 (support HMCAD1520 in future)
  4. configuring IDELAYE2 and ISERDESE2 inside of FPGA
  5. Testing under dual pattern and ramp mode
E.g.
init(1000,1) 1 channel mode, 1Gsps, 8bit, since 1Gsps
is only available in 8bit mode
init(320,2) 2 channel mode, 320Msps, 8bit for HMCAD1511,
or 12bit for HMCAD1520

init(160,4,8) 4 channel mode, 160Msps, 8bit resolution

interleave(data, mode)[source]

Reorder the data according to the interleaving mode

E.g. .. code-block:: python

data = numpy.arange(1024).reshape(-1,8) interleave(data, 1) # return a one-column numpy array interleave(data, 2) # return a two-column numpy array interleave(data, 4) # return a four-column numpy array
ram = None
read_ram(ram=None, signed=True)[source]

Read RAM(s) and return the 1024-sample data

E.g.
readRAM() # read all RAMs, return a list of arrays readRAM(1) # read the 2nd RAMs, return a 128X8 array readRAM([0,1]) # read 2 RAMs, return two arrays readRAM(signed=False) # return a list of arrays in unsiged format
reset()[source]

Reset all adc16_interface logics inside FPGA

resolution = 8
select_adc(chipSel=None)[source]

Select one or multiple ADCs

Select the ADC(s) to be configured. ADCs are numbered by 0, 1, 2… E.g.

selectADC(0) # select the 1st ADC selectADC([0,1]) # select two ADCs selectADC() # select all ADCs
set_demux(numChannel=1)[source]
when mode==0: numChannel=4
data = data[:,[0,4,1,5,2,6,3,7]]
when mode==1: numChannel=2
data = data[:,[0,1,4,5,2,3,6,7]]
when mode==2: numChannel=1
data = data[:,[0,1,2,3,4,5,6,7]]
set_gain(gains, use_linear_step=False, fine_gains=None, fgain_cfg=False)[source]

Set the coarse gain of the ADC channels

Args:
gains (list): List of gains, e.g. [1, 2, 3, 4] use_linear_step (bool): Defaults to use dB steps for values. fine_gains (list): Fine gain values to set fgain_cfg (bool): If fine gains are to be used, set this to True
Notes:
Coarse gain control (parameters in dB). Input gain must be a list of integers. Coarse gain range for HMCAD1511: 0dB ~ 12dB
E.g.

cGain([1,5,9,12]) # Quad channel mode in dB step cGain([32,50],use_linear_step=True) # Dual channel mode in x step cGain([10], fgain_cfg=True) # Single channel mode in dB

# step, with fine gain enabled
Coarse gain options when by default use_linear_step=False:
0 dB, 1 dB, 2 dB, 3 dB, 4 dB, 5 dB, 6 dB, 7 dB, 8 dB, 9 dB, 10 dB, 11 dB and 12 dB
Coarse gain options when use_linear_step=True:
1x, 1.25x, 2x, 2.5x, 4x, 5x, 8x, 10x, 12.5x, 16x, 20x, 25x, 32x, 50x

TODO: Test + improve support for fine gain control

snapshot()[source]

Save 1024 consecutive samples of each ADC into its corresponding bram

synth = None
test_patterns(chipSel=None, taps=None, mode='std', pattern1=None, pattern2=None)[source]

Return a list of std/err for a given tap or a list of taps

Return the lane-wise standard deviation/error of the data under a given tap setting or a list of tap settings. By default, mode=’std’, taps=range(32). ‘err’ mode with single test pattern check data against the given pattern, while ‘err’ mode with dual test patterns guess the counts of the mismatches. ‘guess’ because both patterns could come up at first. This method always returns the smaller counts. ‘ramp’ mode guess the total number of incorrect data. This is implemented based on the assumption that in most cases, $cur = $pre + 1. When using ‘ramp’ mode, taps=None

E.g. .. code-block:: python

testPatterns(taps=True) # Return lane-wise std of all ADCs, taps=range(32) testPatterns(0,taps=range(32))

# Return lane-wise std of the 1st ADC
testPatterns([0,1],2) # Return lane-wise std of the first two ADCs
# with tap = 2
testPatterns(1, taps=[0,2,3], mode=’std’)
# Return lane-wise stds of the 2nd ADC with # three different tap settings
testPatterns(2, mode=’err’, pattern1=0b10101010)
# Check the actual data against the given test # pattern without changing current delay tap # setting and return lane-wise error counts of # the 3rd ADC,
testPatterns(2, mode=’err’, pattern1=0b10101010, pattern2=0b01010101)
# Check the actual data against the given alternate # test pattern without changing current delay tap # setting and return lane-wise error counts of # the 3rd ADC,
testPatterns(mode=’ramp’)
# Check all ADCs under ramp mode

spead

SPEAD operations - unpack and use spead data, usually from Snap blocks.

class spead.SpeadPacket(headers=None, data=None)[source]

A Spead packet. Headers and data.

exception SpeadPacketError[source]
__init__(headers=None, data=None)[source]

Create a new SpeadPacket object

static decode_headers(data, expected_version=None, expected_flavour=None, expected_hdrs=None)[source]

Decode the SPEAD headers given some packet data.

Parameters:
  • data – a list of packet data
  • expected_version – an explicit version, if required
  • expected_flavour – an explicit flavour, if required
  • expected_hdrs – explicit number of hdrs, if required
static decode_item_pointer(header64, id_bits, address_bits)[source]

Decode a 64-bit header word in the id and data/pointer portions

Parameters:
  • header64 – the 64-bit word
  • id_bits – how many bits are used for the ID
  • address_bits – how many bits are used for the data/pointer
Returns:

a tuple of the ID and data/pointer

static decode_spead_magic_word(word64, required_version=None, required_flavour=None, required_numheaders=None)[source]

Decode a 64-bit word as a SPEAD header.

Parameters:
  • word64 – A 64-bit word
  • required_version – the specific SPEAD version required, an integer
  • required_flavour – the specific SPEAD flavour required as a string, e.g. ‘64,48’
  • required_numheaders – the number of headers (NOT incl. the magic number) expected, an integer
static find_spead_header(data64, expected_version=4, expected_flavour='64, 48')[source]

Find a SPEAD header in the given list of 64-bit data

Parameters:
  • data64 – a list of data
  • expected_version – the version wanted
  • expected_flavour – the flavour wanted
Returns:

None if no header is found, else the index and the contents of the header as a tuple

classmethod from_data(data, expected_version=None, expected_flavour=None, expected_hdrs=None, expected_length=None)[source]

Create a SpeadPacket from a list of 64-bit data words Assumes the list of data starts at the SPEAD magic word.

get_strings(headers_only=False, hex_nums=False)[source]

Get a list of the string representation of this packet.

print_packet(headers_only=False, hex_nums=False)[source]

Print a representation of the packet.

class spead.SpeadProcessor(version=4, flavour='64, 48', packet_length=None, num_headers=None)[source]

Set up a SPEAD processor with version, flavour, etc. Then call methods to process data.

__init__(version=4, flavour='64, 48', packet_length=None, num_headers=None)[source]

Create a SpeadProcessor

:param version :param flavour :param packet_length :param num_headers

process_data(data_packets)[source]

Create SpeadPacket objects from a list of data packets.

synth

class synth.LMX2581(interface, controller_name, fosc=10)[source]

LMX2581 Frequency Synthesizer

CMD08 = 545119224
CMD09 = 63422521
CMD10 = 553668810
DICTS = [{'PLL_NUM_L': 65520, 'FRAC_DITHER': 1610612736, 'ID': 2147483648, 'PLL_N': 268369920, 'NO_FCAL': 268435456}, {'VCO_SEL': 100663296, 'FRAC_ORDER': 28672, 'PLL_NUM_H': 33521664, 'PLL_R': 4080, 'CPG': 4160749568}, {'CPP': 134217728, 'PLL_DEN': 67108848, 'OSC_2X': 536870912}, {'OUTA_PD': 16, 'VCO_DIV': 8126464, 'OUTB_PWR': 258048, 'OUTB_PD': 32, 'OUTA_PWR': 4032}, {'PFD_DLY': 3758096384, 'FL_FRCE': 268435456, 'CPG_BLEED': 1008, 'FL_CPG': 63488, 'FL_TOC': 268369920}, {'PWDN_MODE': 224, 'OUTB_MUX': 24576, 'OUT_LDEN': 16777216, 'RESET': 16, 'MODE': 768, 'OUTA_MUX': 6144, '0_DLY': 1024, 'OSC_FREQ': 14680064, 'BUFEN_DIS': 1048576, 'VCO_SEL_MODE': 98304}, {'RDADDR': 480, 'UWIRE_LOCK': 16, 'RD_DIAGNOSATICS': 2147481600}, {'FL_INV': 4194304, 'FL_PINMODE': 58720256, 'LD_INV': 128, 'MUXOUT_SELECT': 4063232, 'MUXOUT_PINMODE': 57344, 'LD_PINMODE': 112, 'FL_SELECT': 2080374784, 'LD_SELECT': 7936, 'MUX_INV': 65536}, None, None, None, None, None, {'DLD_PASS_CNT': 268173312, 'DLD_TOL': 229376, 'DLD_ERR_CNT': 4026531840}, None, {'VCO_CAPCODE': 4080, 'VCO_CAP_MAN': 4096}]
MASK_DIAG = {'BUFEN_PINSTATE': 2048, 'CAL_RUNNING': 2097152, 'CE_PINSTATE': 4096, 'DLD': 16384, 'FIN_DETECT': 268435456, 'FLOUT_ON': 32768, 'LD_PINSTATE': 8192, 'OSCIN_DETECT': 134217728, 'VCO_DETECT': 67108864, 'VCO_RAIL_HIGH': 1048576, 'VCO_RAIL_LOW': 524288, 'VCO_SELECT': 1610612736, 'VCO_TUNE_HIGH': 131072, 'VCO_TUNE_VALID': 65536}
__init__(interface, controller_name, fosc=10)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

getDiagnoses(name=None)[source]
getRegId(name)[source]
getRegister(rid=None)[source]
getWord(name)[source]
get_osc_values(synth_mhz, ref_signal)[source]

This function gets oscillator values

init()[source]
loadCfgFromFile(filename)[source]
outputPower(p=15)[source]
powerOff()[source]
powerOn()[source]
read(addr)[source]
reset()[source]
setFreq(synth_mhz)[source]
setWord(value, name)[source]
write(data, addr=None, mask=None)[source]

tengbe

class tengbe.TenGbe(parent, name, address, length_bytes, device_info=None)[source]

To do with the CASPER ten GBE yellow block implemented on FPGAs, and interfaced-to via KATCP memory reads/writes.

__init__(parent, name, address, length_bytes, device_info=None)[source]
Parameters:
  • parent – Parent object who owns this TenGbe instance
  • name – Unique name of the instance
  • address
  • length_bytes
  • device_info – Information about this device
configure_core()[source]

Setup the interface by writing to the fabric directly, bypassing tap. :param self: :return:

dhcp_start()[source]

Configure this interface, then start a DHCP client on ALL interfaces.

fabric_disable()[source]

Enable the core fabric

fabric_enable()[source]

Enable the core fabric

fabric_soft_reset_toggle()[source]

Toggle the fabric soft reset

get_arp_details(N=256)[source]

Get ARP details from this interface.

get_cpu_details(port_dump=None)[source]

Read details of the CPU buffers.

Parameters:port_dump
get_gbe_core_details(read_arp=False, read_cpu=False, read_multicast=False)[source]

Get 10GbE core details.

Parameters:
  • (bool) (read_multicast) – Get ARP table details (default False)
  • (bool) – Get CPU details (default False)
  • (bool) – Get multicast address table (default False)
Returns:

dictionary of core details (IP address, subnet mask, MAC address, port, etc).

ip_address
mac
multicast_receive(ip_str, group_size)[source]

Send a request to KATCP to have this tap instance send a multicast group join request.

Parameters:
  • ip_str – A dotted decimal string representation of the base mcast IP address.
  • group_size – An integer for how many mcast addresses from base to respond to.
multicast_remove(ip_str)[source]

Send a request to be removed from a multicast group.

Parameters:ip_str – A dotted decimal string representation of the base mcast IP address.
port
post_create_update(raw_device_info)[source]

Update the device with information not available at creation.

Parameters:raw_device_info – info about this block that may be useful
read_rxsnap()[source]

Read the RX snapshot embedded in this TenGBE yellow block

read_txsnap()[source]

Read the TX snapshot embedded in this TenGBE yellow block

set_arp_table(macs)[source]

Set the ARP table with a list of MAC addresses. The list, macs, is passed such that the zeroth element is the MAC address of the device with IP XXX.XXX.XXX.0, and element N is the MAC address of the device with IP XXX.XXX.XXX.N

tap_arp_reload()[source]

Have the tap driver reload its ARP table right now.

tap_info()[source]

Get info on the tap instance running on this interface.

tap_running()[source]

Determine if an instance if tap is already running on for this ten GBE interface.

tap_start(restart=False)[source]

Program a 10GbE device and start the TAP driver.

Parameters:restart – stop before starting
tap_stop()[source]

Stop a TAP driver.

tengbe.read_memory_map_definition(filename)[source]

Read memory map definition from text file.

Returns a python dictionary:
{REGISTER_NAME1: {‘offset’: offset, ‘size’: size, ‘rwflag’: rwflag},
REGISTER_NAME2: {‘offset’: offset, ‘size’: size, ‘rwflag’: rwflag} …}
Notes:
Used by TenGbe.configure_core() to write to mmap.

termcolors

termcolors.py – Taken from corr

termcolors.colorize(text='', opts=(), **kwargs)[source]

Returns your text, enclosed in ANSI graphics codes.

Depends on the keyword arguments ‘fg’ and ‘bg’, and the contents of the opts tuple/list.

Returns the RESET code if no parameters are given.

Valid colors:
‘black’, ‘red’, ‘green’, ‘yellow’, ‘blue’, ‘magenta’, ‘cyan’, ‘white’
Valid options:
‘bold’ ‘underscore’ ‘blink’ ‘reverse’ ‘conceal’ ‘noreset’ - string will not be auto-terminated with the RESET code

Examples:

colorize('hello', fg='red', bg='blue', opts=('blink',))
colorize()
colorize('goodbye', opts=('underscore',))
print colorize('first line', fg='red', opts=('noreset',))
print 'this should be red too'
print colorize('and so should this')
print 'this should not be red'

transport

class transport.Transport(**kwargs)[source]

The actual network transport of data for a CasperFpga object.

__init__(**kwargs)[source]

Initialise the CasperFpga object

Parameters:host
blindwrite(device_name, data, offset=0)[source]

Write binary data to device_name, starting at offset bytes from device_name’s base address..

Parameters:
  • device_name (String) – Name of device to be read
  • data (Big-endian binary string) – Data to write
  • offset (Integer) – Offset from which to begin write, in bytes
Returns:

None

connect(timeout=None)[source]
Parameters:timeout
deprogram()[source]

Deprogram the FPGA connected by this transport

disconnect()[source]
get_system_information_from_transport()[source]
is_connected()[source]

Is the transport layer connected to the platform?

Returns:True or False
is_running()[source]

Is the FPGA programmed and running?

Returns:True or False
listdev()[source]

Get a list of the memory bus items in this design.

Returns:a list of memory devices
ping()[source]

Use the ‘watchdog’ request to ping the FPGA host.

Returns:True or False
post_get_system_information()[source]

Cleanup run after get_system_information

read(device_name, size, offset=0)[source]

Read size bytes from register device_name. Start reading from offset bytes from device_name’s base address. Return the read data as a big-endian binary string.

Parameters:
  • device_name (String) – Name of device to be read
  • size (Integer) – Number of bytes to read
  • offset (Integer) – Offset from which to begin read, in bytes
Returns:

Big-endian binary string

set_igmp_version(version)[source]
Parameters:version
test_connection()[source]

Write to and read from the scratchpad to test the connection to the FPGA - i.e. Is the casper FPGA connected?

Returns:Boolean - True/False - Success/Fail
upload_to_flash(binary_file, port=-1, force_upload=False, timeout=30, wait_complete=True)[source]

Upload the provided binary file to the flash filesystem.

Parameters:
  • binary_file – filename of the binary file to upload
  • port – host-side port, -1 means a random port will be used
  • force_upload – upload the binary even if it already exists on the host
  • timeout – upload timeout, in seconds
  • wait_complete – wait for the upload to complete, or just kick it off
upload_to_ram_and_program(filename, port=-1, timeout=10, wait_complete=True, skip_verification=False)[source]

Upload an FPG file to RAM and then program the FPGA.

  • Implemented in the child
Parameters:
  • filename – the file to upload
  • port – the port to use on the rx end, -1 means a random port
  • timeout – how long to wait, seconds
  • wait_complete – wait for the transaction to complete, return after upload if False
  • skip_verification – don’t verify the image after uploading it

transport_dummy

class transport_dummy.DummyTransport(**kwargs)[source]

A dummy transport for testing

__init__(**kwargs)[source]

Make a Dummy Transport

Parameters:host – IP Address should be 127.0.0.1 for a Dummy
blindwrite(device_name, data, offset=0)[source]
Parameters:
  • device_name
  • data
  • offset
connect(timeout=None)[source]
Parameters:timeout
deprogram()[source]

Deprogram the FPGA connected by this transport

disconnect()[source]
Returns:
get_system_information_from_transport()[source]
is_connected()[source]
is_running()[source]

Is the FPGA programmed and running?

Returns:True or False
listdev()[source]

Get a list of the memory bus items in this design.

Returns:a list of memory devices
static multicast_receive(gbename, ip, mask)[source]
Parameters:
  • gbename
  • ip
  • mask
ping()[source]

Use the ‘watchdog’ request to ping the FPGA host.

Returns:True or False
post_get_system_information()[source]

Cleanup run after get_system_information

read(device_name, size, offset=0)[source]
Parameters:
  • device_name
  • size
  • offset
read_wishbone(wb_address)[source]

Used to perform low level wishbone read from a Wishbone slave.

Parameters:wb_address – address of the wishbone slave to read from
Returns:Read Data or None
set_igmp_version(version)[source]
Parameters:version
test_connection()[source]

Write to and read from the scratchpad to test the connection to the FPGA

upload_to_flash(binary_file, port=-1, force_upload=False, timeout=30, wait_complete=True)[source]

Upload the provided binary file to the flash filesystem.

Parameters:
  • binary_file – filename of the binary file to upload
  • port – host-side port, -1 means a random port will be used
  • force_upload – upload the binary even if it already exists on the host
  • timeout – upload timeout, in seconds
  • wait_complete – wait for the upload to complete, or just kick it off
upload_to_ram_and_program(filename, port=-1, timeout=10, wait_complete=True, skip_verification=False)[source]

Upload an FPG file to RAM and then program the FPGA.

Parameters:
  • filename – the file to upload
  • port – the port to use on the rx end, -1 means a random port
  • timeout – how long to wait, seconds
  • wait_complete – wait for the transaction to complete, return after upload if False
  • skip_verification – don’t verify the image after uploading it
write_wishbone(wb_address, data)[source]

Used to perform low level wishbone write to a wishbone slave. Gives low level direct access to wishbone bus.

Parameters:
  • wb_address – address of the wishbone slave to write to
  • data – data to write
Returns:

response object

class transport_dummy.NamedFifo(maxlen=None)[source]
__init__(maxlen=None)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

pop(name=None)[source]
push(name, value)[source]

transport_katcp

exception transport_katcp.KatcpConnectionError[source]
exception transport_katcp.KatcpRequestError[source]

An error occurred processing a KATCP request.

exception transport_katcp.KatcpRequestFail[source]

A valid KATCP request failed.

exception transport_katcp.KatcpRequestInvalid[source]

An invalid KATCP request was made.

class transport_katcp.KatcpTransport(**kwargs)[source]

A katcp transport client for a casperfpga object

__init__(**kwargs)[source]
Parameters:
  • host
  • port
  • timeout
  • connect
blindwrite(device_name, data, offset=0)[source]

Unchecked data write. :param device_name: the memory device to which to write :param data: the byte string to write :param offset: the offset, in bytes, at which to write :return: <nothing>

bulkread(device_name, size, offset=0)[source]

Read size-bytes of binary data with carriage-return escape-sequenced. Uses much faster bulkread katcp command which returns data in pages using informs rather than one read reply, which has significant buffering overhead on the ROACH.

Parameters:
  • device_name – name of the memory device from which to read
  • size – how many bytes to read
  • offset – the offset at which to read
Returns:

binary data string

check_phy_counter()[source]
connect(timeout=None)[source]

Establish a connection to the KATCP server on the device.

Parameters:timeout – How many seconds should we wait? Use instance default if None.
deprogram()[source]

Deprogram the FPGA.

Unsubscribes all active tap devices from any multicast groups to avoid confusing switch IGMP snoop tables.

disconnect()[source]

Disconnect from the device server. :return:

get_system_information_from_transport()[source]
is_connected()[source]

Is the transport layer connected to the platform?

Returns:True or False
is_running()[source]

Is the FPGA programmed and running?

Returns:True or False
katcprequest(name, request_timeout=-1.0, require_ok=True, request_args=(), max_retries=3, retry_delay_s=0.5)[source]

Make a blocking request to the KATCP server and check the result. Raise an error if the reply indicates a request failure.

Parameters:
  • name – request message to send.
  • request_timeout – number of seconds after which the request must time out
  • require_ok – will we raise an exception on a response != ok
  • request_args – request arguments.
  • max_retries – maximum number of retries in the case of errors (3).
  • retry_delay_s – the delay between retries in the case of errors (0.5 seconds).
Returns:

tuple of reply and informs

listbof()[source]
Returns:a list of binary files stored on the host device.
listdev(getsize=False, getaddress=False)[source]

Get a list of the memory bus items in this design.

Returns:a list of memory devices
ping()[source]

Use the ‘watchdog’ request to ping the FPGA host.

Returns:True or False
program(filename=None)[source]

Program the FPGA with the specified binary file.

Parameters:filename – name of file to program, can vary depending on the formats supported by the device. e.g. fpg, bof, bin
read(device_name, size, offset=0)[source]

Read size-bytes of binary data with carriage-return escape-sequenced.

Parameters:
  • device_name – name of memory device from which to read
  • size – how many bytes to read
  • offset – start at this offset
Returns:

binary data string

sendfile(filename, targethost, port, result_queue, timeout=2)[source]

Send a file to a host using sockets. Place the result of the action in a Queue.Queue

Parameters:
  • filename – the file to send
  • targethost – the host to which it must be sent
  • port – the port the host should open
  • result_queue – the result of the upload, nothing ‘’ indicates success
  • timeout
set_igmp_version(version)[source]

Sets version of IGMP multicast protocol to use

Parameters:version – IGMP protocol version, 0 for kernel default, 1, 2 or 3

Note: won’t work if config keep file is present since the needed ?igmp-version request won’t exist on the KATCP interface.

status()[source]
Returns:FPGA status
tap_arp_reload()[source]

Have the tap driver reload its ARP table right now.

test_connection()[source]

Write to and read from the scratchpad to test the connection to the FPGA

static test_host_type(host_ip, timeout=5)[source]

Is this host_ip assigned to a Katcp board?

Parameters:
  • host_ip – as a String
  • timeout – as an Integer
unhandled_inform(msg)[source]

Overloaded from CallbackClient

What do we do with unhandled KATCP inform messages that this device receives?

Pass it onto the registered function, if it’s not None

upload_to_flash(binary_file, port=-1, force_upload=False, timeout=30, wait_complete=True)[source]

Upload the provided binary file to the flash filesystem.

Parameters:
  • binary_file – filename of the binary file to upload
  • port – host-side port, -1 means a random port will be used
  • force_upload – upload the binary even if it already exists on the host
  • timeout – upload timeout, in seconds
  • wait_complete – wait for the upload to complete, or just kick it off
upload_to_ram_and_program(filename, port=-1, timeout=10, wait_complete=True, skip_verification=False, **kwargs)[source]

Upload an FPG file to RAM and then program the FPGA.

Parameters:
  • filename – the file to upload
  • port – the port to use on the rx end, -1 means a random port
  • timeout – how long to wait, seconds
  • wait_complete – wait for the transaction to complete, return after upload if False
  • skip_verification – do not verify the uploaded file before reboot
wordread(device_name, size=1, word_offset=0, bit_offset=0)[source]
Parameters:
  • device_name – name of memory device from which to read
  • word_count – how many words to read
  • word_offset – start at this word offset
  • bit_offset – start at this bit offset
Returns:

value in hexadecimal

transport_skarab

transport_tapcp

class transport_tapcp.TapcpTransport(**kwargs)[source]

The network transport for a tapcp-type interface.

__init__(**kwargs)[source]

Initialized Tapcp FPGA object

Parameters:host – IP Address of the targeted Board
blindwrite(device_name, data, offset=0, use_bulk=True)[source]

Unchecked data write.

Parameters:
  • device_name – the memory device to which to write
  • data – the byte string to write
  • offset – the offset, in bytes, at which to write
  • use_bulk – Does nothing. Kept for API compatibility
deprogram()[source]

Deprogram the FPGA. This actually reboots & boots from the Golden Image

get_firmware_version()[source]

Read the version of the firmware

Returns:golden_image, multiboot, firmware_major_version, firmware_minor_version
get_metadata()[source]

Read meta data from user_flash_loc on the fpga flash drive

get_soc_version()[source]

Read the version of the soc

Returns:golden_image, multiboot, soc_major_version, soc_minor_version
get_temp()[source]
is_connected()[source]

Is the transport layer connected to the platform?

Returns:True or False
is_running()[source]

This is currently an alias for ‘is_connected’

listdev()[source]

Get a list of the memory bus items in this design.

Returns:a list of memory devices
listdev_pl()[source]
prog_user_image()[source]

(Re)Program the FPGA with the file already on flash

progdev(addr=0)[source]
read(device_name, size, offset=0, use_bulk=True)[source]

Return size_bytes of binary data with carriage-return escape-sequenced.

Parameters:
  • device_name – name of memory device from which to read
  • size – how many bytes to read
  • offset – start at this offset, offset in bytes
  • use_bulk – Does nothing. Kept for API compatibility
Returns:

binary data string

read_wishbone(wb_address)[source]

Used to perform low level wishbone read from a Wishbone slave.

Parameters:wb_address – address of the wishbone slave to read from
Returns:Read Data or None
static test_host_type(host_ip)[source]

Is this host_ip assigned to a Tapcp board?

Parameters:host_ip
upload_to_ram_and_program(filename, port=None, timeout=None, wait_complete=True, **kwargs)[source]

Upload an FPG file to RAM and then program the FPGA.

  • Implemented in the child
Parameters:
  • filename – the file to upload
  • port – the port to use on the rx end, -1 means a random port
  • timeout – how long to wait, seconds
  • wait_complete – wait for the transaction to complete, return after upload if False
  • skip_verification – don’t verify the image after uploading it
write_wishbone(wb_address, data)[source]

Used to perform low level wishbone write to a wishbone slave. Gives low level direct access to wishbone bus.

Parameters:
  • wb_address – address of the wishbone slave to write to
  • data – data to write
Returns:

response object

transport_tapcp.decode_csl(csl)[source]
transport_tapcp.decode_csl_pl(csl)[source]
transport_tapcp.get_core_info_payload(payload_str)[source]
transport_tapcp.get_log_level()[source]
transport_tapcp.set_log_level(level)[source]

utils

class utils.CheckCounter(name, must_change=True, required=False)[source]
__init__(name, must_change=True, required=False)[source]
Parameters:
  • name – the name of the counter
  • must_change – this counter should be changing
  • required – is this counter required?
utils.check_changing_status(counters, data_function, wait_time, num_checks)[source]

Check a changing set of status fields.

Parameters:
  • counters – a list of CheckCounters
  • data_function – a function that will return a single value for the fields from field_dict
  • wait_time – seconds to wait between calls to data_function
  • num_checks – times to run data_function
utils.create_meta_dictionary(metalist)[source]

Build a meta information dictionary from a provided raw meta info list.

Parameters:metalist – a list of all meta information about the system
Returns:a dictionary of device info, keyed by unique device name
utils.deprogram_hosts(host_list)[source]
Parameters:host_list
utils.get_git_info_from_fpg(fpg_file)[source]

Method to get git info from an fpg-file’s header :param fpg_file: filename as string :return: Dictionary of git_info

  • key = git-repo
  • value = git-version
utils.get_hostname(**kwargs)[source]
Parameters:kwargs
utils.get_kwarg(field, kwargs, default=None)[source]
utils.hosts_from_dhcp_leases(host_pref=None, leases_file='/var/lib/misc/dnsmasq.leases')[source]

Get a list of hosts from a leases file.

Parameters:
  • host_pref – the prefix of the hosts in which we’re interested
  • leases_file – the file to read
utils.parse_fpg(filename)[source]

Read the meta information from the FPG file.

Parameters:filename – the name of the fpg file to parse
Returns:device info dictionary, memory map info (coreinfo.tab) dictionary
utils.program_fpgas(fpga_list, progfile, timeout=10)[source]

Program more than one FPGA at the same time.

Parameters:
  • fpga_list – a list of objects for the FPGAs to be programmed
  • progfile – string, the file used to program the FPGAs
  • timeout – how long to wait for a response, in seconds
utils.pull_info_from_fpg(fpg_file, parameter)[source]

Pull available parameters about x-engine or f-engine from .fpg file. Available options for x-engine: ‘x_fpga_clock’, ‘xeng_outbits’, ‘xeng_accumulation_len’ Available options for f-engine: ‘n_chans’, ‘quant_format’, ‘spead_flavour’

Parameters:
  • fpg_file – bit file path
  • parameter – parameter string
Returns:

pattern value (string)

utils.threaded_create_fpgas_from_hosts(host_list, fpga_class=None, port=7147, timeout=10, best_effort=False, **kwargs)[source]

Create KatcpClientFpga objects in many threads, Moar FASTAAA!

Parameters:
  • fpga_class – the class to insantiate, usually CasperFpga
  • host_list – a comma-seperated list of hosts
  • port – the port on which to do network comms
  • timeout – how long to wait, in seconds
  • best_effort – return as many hosts as it was possible to make
utils.threaded_fpga_function(fpga_list, timeout, target_function)[source]

Thread the running of any CasperFpga function on a list of CasperFpga objects. Much faster.

Parameters:
  • fpga_list – list of KatcpClientFpga objects
  • timeout – how long to wait before timing out
  • target_function

    a tuple with three parts:

    1. string, the KatcpClientFpga function to run e.g. ‘disconnect’ for fpgaobj.disconnect()
    2. tuple, the arguments to the function
    3. dict, the keyword arguments to the function e.g. (func_name, (1,2,), {‘another_arg’: 3})
Returns:

a dictionary of the results, keyed on hostname

utils.threaded_fpga_operation(fpga_list, timeout, target_function)[source]

Thread any operation against many FPGA objects

Parameters:
  • fpga_list – list of KatcpClientFpga objects
  • timeout – how long to wait before timing out
  • target_function

    a tuple with three parts:

    1. reference, the function object that must be run - MUST take FPGA object as first argument
    2. tuple, the arguments to the function
    3. dict, the keyword arguments to the function e.g. (func_name, (1,2,), {‘another_arg’: 3})
Returns:

a dictionary of the results, keyed on hostname

utils.threaded_non_blocking_request(fpga_list, timeout, request, request_args)[source]

Make a non-blocking KatCP request to a list of KatcpClientFpgas, using the Asynchronous client.

Parameters:
  • fpga_list – list of KatcpClientFpga objects
  • timeout – the request timeout
  • request – the request string
  • request_args – the arguments to the request, as a list
Returns:

a dictionary, keyed by hostname, of result dictionaries containing reply and informs

wishbonedevice

class wishbonedevice.WishBoneDevice(interface, controller_name)[source]
__init__(interface, controller_name)[source]

x.__init__(…) initializes x; see help(type(x)) for signature