Public Interfaces

Module init code.

class ska_low_cbf_fpga.AmiInfo(hwmon_dir, sys_dir_0)[source]

Hardware monitoring for AMI devices via sysfs.

property fpga_power: IclField[float]

Get FPGA power consumption in Watts.

property fpga_temperature: IclField[int]

Get FPGA temperature in degrees Celsius.

property hbm_temperature: IclField[int]

Get HBM temperature in degrees Celsius.

property mac_addresses: IclField[str]

Get Ethernet MAC addresses.

Returns:

Array of str, formatted like “00:01:02:03:04:05”.

property pcie_12v_current: IclField[float]

Get PCIe 12V power rail’s current.

property pcie_12v_voltage: IclField[float]

Get PCIe 12V power rail voltage reading.

property power_supply_12v_current: IclField[float]

Get 12V AUX total current (sum of two).

property power_supply_12v_voltage: IclField[float]

Get 12V AUX voltage (one of the two that deviates furthest from 12V).

class ska_low_cbf_fpga.ArgsAmi(logger=None, mem_config='', **kwargs)[source]

FPGA driver that wraps ami_tool.

property n_partitions: int

Number of Flash Partition Table (FPT) entries.

read(source, length=1)[source]

Read FPGA registers.

Return type:

Union[ndarray, int]

read_memory(index, size_bytes=None, offset_bytes=0)[source]

Read from HBM.

Note: Unlike ArgsXrt, we do not care if the memory buffer is marked as ‘shared’ in the memory configuration string.

Parameters:
  • size_bytes (Optional[int]) – Number of bytes to transfer. Should be a multiple of WORD_SIZE, will be rounded down to a multiple of WORD_SIZE. (transfers the whole buffer if not specified or None)

  • offset_bytes (int) – Starting address.

  • index (int) – Index of the HBM buffer to read. For compatibility with ArgsXrt, the index of the first HBM buffer is 1.

Return type:

ndarray

Returns:

HBM contents, as ArgsWordType

write(destination, values)[source]

Write to FPGA registers.

Return type:

None

write_memory(index, values, offset_bytes=0)[source]

Write to HBM.

Note: Unlike ArgsXrt, we do not care if the memory buffer is marked as ‘shared’ in the memory configuration string.

Parameters:
  • index (int) – Index of the HBM buffer to write to. For compatibility with ArgsXrt, the index of the first HBM buffer is 1.

  • values (ndarray) – Data to write.

  • offset_bytes (int) – Starting address.

class ska_low_cbf_fpga.ArgsFieldInfo(description=None, address=None, length=1, bit_offset=None, width=None)[source]
class ska_low_cbf_fpga.ArgsFpgaDriver(logger=None, mem_config='', **kwargs)[source]

Base class for ARGS FPGA Drivers.

Extends interface class with startup steps common to all ARGS FPGAs.

get_map_build()[source]

Get the ARGS map build timestamp from the FPGA.

exception ska_low_cbf_fpga.ArgsMagicError[source]

Exception raised when FPGA does not report ARGS magic number.

class ska_low_cbf_fpga.ArgsMap(spec)[source]

ARGS FPGA map file decoder.

classmethod create_from_file(build, map_dir)[source]
Parameters:
  • build (int) – ARGS map build timestamp

  • map_dir (str) – directory to find ARGS map file in

class ska_low_cbf_fpga.ArgsSimulator(logger=None, mem_config='', **kwargs)[source]

FPGA Simulation driver.

classmethod create_from_file(fpgamap_path, mem_config=[], **kwargs)[source]
Parameters:
  • fpgamap_path (str) – Path to fpgamap_<numbers>.py file to be simulated.

  • mem_config (list) – a list of MemConfig tuples (<size in bytes>, <shared?>). The first list item is the ARGS interchange buffer (which would be used to send/receive register values in a real FPGA).

read(source, length=1)[source]

Read values from simulated FPGA register space

Parameters:
  • source – Byte address to start reading from

  • length (int) – Number of words to read

Returns:

value(s) from simulated registers

read_memory(index, size_bytes=None, offset_bytes=0)[source]

Read a shared memory buffer.

Parameters:
  • size_bytes (Optional[int]) – number of bytes to transfer (transfers the whole buffer if not specified or None)

  • offset_bytes (int) – starting address

  • index (int) – Index of the shared buffer to save. Zero is the ARGS interchange buffer, which you probably don’t want.

Return type:

ndarray

Returns:

shared memory buffer

write(destination, values)[source]

Write values to simulated FPGA registers

Parameters:
  • destination – FPGA byte address where writes should start

  • values – value(s) to write, if more than one value they must be words, to be written to consecutive words (i.e. byte addresses increment by WORD_SIZE)

write_memory(index, values, offset_bytes=0)[source]

Write to a shared memory buffer.

Parameters:
  • index (int) – Index of the shared buffer to write to. Zero is the ARGS interchange buffer, which you probably don’t want.

  • values (ndarray) – Data to write.

  • offset_bytes (int) – Byte-based offset where values should start in buffer.

class ska_low_cbf_fpga.ArgsWordType[source]

Data type used for ARGS words.

class ska_low_cbf_fpga.ArgsXrt(logger=None, mem_config='', **kwargs)[source]

pyxrt-based FPGA Driver. Requires a .xclbin file.

MINUS_ONE_16BIT = 65535

-1 as a 16 bit signed integer (0xFFFF)

read(source, length=1)[source]

Read values from FPGA.

Parameters:
  • source (int) – Byte address to start reading from

  • length (int) – Number of words to read

Returns:

value(s) from FPGA

read_memory(index, size_bytes=None, offset_bytes=0)[source]

Read a shared memory buffer.

Parameters:
  • size_bytes (Optional[int]) – number of bytes to transfer (transfers the whole buffer if not specified or None)

  • offset_bytes (int) – starting address

  • index (int) – Index of the shared buffer to save. Zero is the ARGS interchange buffer, which you probably don’t want.

Return type:

ndarray

Returns:

shared memory buffer

write(destination, values)[source]

Write values to FPGA.

Parameters:
  • destination (int) – FPGA byte address where writes should start

  • values (Union[int, ndarray]) – value(s) to write, if more than one value they must be words, to be written to consecutive words (i.e. byte addresses increment by WORD_SIZE)

write_memory(index, values, offset_bytes=0)[source]

Write to a shared memory buffer.

Parameters:
  • index (int) – Index of the shared buffer to write to. Zero is the ARGS interchange buffer, which you probably don’t want.

  • values (ndarray) – Data to write.

  • offset_bytes (int) – Byte-based offset where values should start in buffer.

class ska_low_cbf_fpga.BootDeviceType(value)[source]

AMI boot device types.

class ska_low_cbf_fpga.FpgaHardwareInfo[source]

Hardware monitoring interface definition.

The properties defined here must be implemented in driver-specific derived classes.

abstract property fpga_power: IclField[float]

Get FPGA power consumption in Watts.

abstract property fpga_temperature: IclField[int]

Get FPGA temperature in degrees Celsius.

abstract property hbm_temperature: IclField[int]

Get HBM temperature in degrees Celsius.

abstract property mac_addresses: IclField[str]

Get Ethernet MAC addresses.

Returns:

Array of str, formatted like “00:01:02:03:04:05”.

abstract property pcie_12v_current: IclField[float]

Get PCIe 12V power rail’s current.

abstract property pcie_12v_voltage: IclField[float]

Get PCIe 12V power rail voltage reading.

abstract property power_supply_12v_current: IclField[float]

Get 12V power rail’s current.

abstract property power_supply_12v_voltage: IclField[float]

Get power rail 12 volt reading.

class ska_low_cbf_fpga.FpgaPeripheral(driver, map_field_info, fpga_personality=None)[source]
class ska_low_cbf_fpga.FpgaPersonality(driver, map_, hardware_info=None, logger=None)[source]
property default_interface: ArgsFpgaDriver

Temporary backwards-compatibility layer

property driver: ArgsFpgaDriver

Access to underlying ArgsFpgaDriver

property fw_personality: IclField[str]

Get the FPGA Firmware personality, decoded to a string

property fw_version: IclField[str]

Get the FPGA Firmware Version.

Returns:

version string formatted like the firmware packages: <major>.<minor>.<patch>[-<dev|main|pre|sim>.<commit hash>] “sim” indicates build type was zero (probably we are in simulation)

property peripherals: List[str]
Returns:

List of peripheral names

property read_memory: Callable

Access to read_memory function of underlying ArgsFpgaDriver

property write_memory: Callable

Access to write_memory function of underlying ArgsFpgaDriver

exception ska_low_cbf_fpga.FpgaRegisterError[source]

Exception raised when FPGA register read fails.

class ska_low_cbf_fpga.FpgaUserInterface[source]

A common interface used by FpgaPeripheral and FpgaPersonality for exposing attributes and methods to the control system.

property user_attributes: Set[str]

Attributes to be exposed to the control system.

property user_methods: Set[str]

Methods to be exposed to the control system.

class ska_low_cbf_fpga.IclField(description=None, address=None, length=1, bit_offset=None, width=None, type_=~T, format='%i', user_write=True, user_error=False, value=None)[source]

ICL field, probably derived from one or more IclFpgaField s

user_error: bool = False

Should the control system treat a non-zero value as an error/alarm?

user_write: bool = True

Should the control system allow writing to this field? Note: not enforced at ICL!

class ska_low_cbf_fpga.IclFpgaField(description=None, address=None, length=1, bit_offset=None, width=None, type_=<class 'ska_low_cbf_fpga.args_fpga.ArgsWordType'>, format='%i', user_write=True, user_error=False, value=<property object>, driver=None)[source]

An ICL field that is linked to an ArgsFpgaDriver .

type_

alias of ArgsWordType

property value: int | ndarray | bool

Read current value from FPGA interface

class ska_low_cbf_fpga.PartitionSpec(boot_type, partition)[source]

AMI Partition Specifier.

class ska_low_cbf_fpga.XrtInfo(device)[source]

Hardware info monitoring via pyxrt xrt_info_device.

Access via item index, e.g. my_xrt_info["thermal"]. Some flattening of data structures is performed.

property fpga_power: IclField[float]

Get FPGA power consumption in Watts.

property fpga_temperature: IclField[int]

Get FPGA temperature in degrees Celsius.

property hbm_temperature: IclField[int]

Get HBM temperature in degrees Celsius.

property mac_addresses: IclField[str]

Get Ethernet MAC addresses.

Returns:

Array of str, formatted like “00:01:02:03:04:05”.

property pcie_12v_current: IclField[float]

Get PCIe 12V power rail’s current.

property pcie_12v_voltage: IclField[float]

Get PCIe 12V power rail voltage reading.

property power_supply_12v_current: IclField[float]

Get 12V power rail’s current.

property power_supply_12v_voltage: IclField[float]

Get power rail 12 volt reading.

property xclbin_uuid: str

Get the UUID of the active xclbin firmware.

ska_low_cbf_fpga.create_driver_map_info(logger=None, mem_config='', fpgamap_path=None, firmware_path=None, device='0', partition=None, simulate=None, verify_registers=None, qdma_read=None, qdma_write=None)[source]

Create ArgsFpgaDriver, ArgsMap, FpgaHardwareInfo

Will use real FPGA hardware if present, unless simulate is explicitly set to True. If simulate is True or no FPGA is present, fpgamap_path must be provided for ArgsSimulator to use.

Parameters:
  • logger (Optional[Logger]) – Logger object to pass along for log outputs

  • mem_config (Union[list, str]) – FPGA memory access configuration

  • fpgamap_path (Optional[str]) – Path to fpgamap_<numbers>.py file to be used

  • firmware_path (Optional[str]) – path to a .pdi FPGA image (for AMI FPGA cards), or .xclbin FPGA kernel (for XRT FPGA cards). Optional for AMI FPGA cards (will use whatever is active on the card), required for XRT FPGA cards.

  • device (str) – PCIe Board:Device.Function address

  • partition (Optional[PartitionSpec]) – Partition number and boot device type to use for AMI FPGA cards.

  • simulate (Optional[bool]) – if True, simulate FPGA register/memory access

  • verify_registers (Optional[dict[str, dict[str, int]]]) – Register values used to verify that we have loaded the correct firmware image. Allows bypassing the long programming step for AMI cards without relying on UUIDs. e.g. {"system": {"commit_short_hash": 0x12345678} } This option may disappear if we can get the .pdi file UUID working. Not checked for XRT FPGAs - underlying driver relies on UUID.

  • qdma_read (Optional[str]) – Path to QDMA read (c2h) character device. AMI only.

  • qdma_write (Optional[str]) – Path to QDMA write (h2c) character device. AMI only.

Return type:

tuple[ArgsFpgaDriver, Optional[ArgsMap], Optional[FpgaHardwareInfo]]

Returns:

(driver, map, info)

driver is only created when either:
  • fpgamap_path is supplied or

  • an FPGA is present, firmware_path is supplied, and simulate is False.

To guarantee creation of driver, supply both fpgamap_path and a firmware file!

map is only created when an fpgamap is present (either explicitly specified or implicitly in the firmware directory). If no fpgamap provided or found, the return value of map will be None.

info is only created if XRT FPGA hardware is present. If no XRT FPGA, the return value of info will be None. simulate has no effect here, if info is not None then it is real hardware info.

Raises:
  • ValueError – if both types of firmware are given

  • RuntimeError – if supplied firmware not suitable for detected FPGA (AMI and XRT are mutually exclusive), unknown file extension in firmware_path, or mismatch between verify_registers and FPGA

ska_low_cbf_fpga.describe_firmware(driver, map_dir='./', personality_to_package=<function <lambda>>)[source]

Describe the firmware in use by an FPGA driver.

Parameters:
  • driver (ArgsFpgaDriver) – An instance of ArgsFpgaDriver used to interact with the FPGA.

  • map_dir (str) – The directory to check for the ARGS FPGA register map file. Defaults to the current working directory. Note that subdirectories will be searched as well.

  • personality_to_package (Callable[[str], str]) – A callable that converts the FPGA personality four-letter code to the corresponding canonical package name. Defaults to a no-op lambda function that returns the input value unchanged.

Return type:

dict[str, UnionType[str, int, bool, None]]

Returns:

A dictionary containing entries:

  • ”available”: A boolean indicating if the firmware is ready to use.

  • ”map_build”: The ARGS map build timestamp, as a hexadecimal string. This value identifies the corresponding FPGA map file, which is required to access FPGA registers. If the driver fails to read the map build register, this value will be None (suggests an error in the underlying FPGA driver or hardware).

  • ”package”: The package name for the firmware image, or None if unavailable (probably caused by a missing map file).

  • ”version”: The firmware version or None if unavailable (probably caused by a missing map file).

ska_low_cbf_fpga.describe_partitions(device, map_dir='./', personality_to_package=<function <lambda>>)[source]

Describe the firmware in each partition of a given AMI-based FPGA device.

This function inspects the partitions of an FPGA device, attempting to read information about the firmware in each partition. It compiles this data into a list of dictionaries, with one dictionary representing each partition’s details.

Warning

All partitions must be programmed with a valid ARGS firmware image. This function will boot from each partition to inspect it, and booting from an un-programmed flash partition can make the card unusable. A host reboot will be required to recover in this circumstance.

Parameters:
  • device (str) – The PCIe device identifier of the FPGA to inspect.

  • map_dir (str) – The directory containing ARGS FPGA register map files. Defaults to the current working directory.

  • personality_to_package (Callable[[str], str]) – A callable that converts the FPGA personality four-letter code to the corresponding canonical package name. Defaults to a no-op lambda function that returns the input value unchanged.

Return type:

list[dict[str, UnionType[str, int, bool, None]]]

Returns:

A list of dictionaries, each containing information about a partition on the device. Each dictionary contains entries:

  • ”partition”: The partition index.

  • ”available”: A boolean indicating if the firmware is ready to use.

  • ”map_build”: The ARGS map build timestamp, as a hexadecimal string. This value identifies the corresponding FPGA map file, which is required to access FPGA registers. If the driver fails to read the map build register, this value will be None (suggests an error in the underlying FPGA driver or hardware).

  • ”package”: The package name for the firmware image, or None if unavailable (probably caused by a missing map file).

  • ”version”: The firmware version or None if unavailable (probably caused by a missing map file).

ska_low_cbf_fpga.log_to_file(logger, filename, level=10, hex_vals=False)[source]

Add a file handler to a logger, with our predefined log format, and configure numpy to ensure full arrays are printed on a single line. Warning: numpy print options are a global setting!

Parameters:
  • logger (Logger) – Logger to configure

  • filename (str) – File name to write (append) to

  • level (int) – Logging level, defaults to DEBUG to capture driver read/write

  • hex_vals (bool) – convert values to hexadecimal?

Return type:

None

ska_low_cbf_fpga.mem_parse(memory_config='')[source]

Convert a string-formatted list of memory configurations to a list of MemConfigs.

The register interchange buffer is automatically included as the first element. Do not list the register buffer in the input string!

Parameters:

memory_config (str) – a colon-separated string <size><unit><s|i> size: int unit: k, M, G (powers of 1024) s: shared i: FPGA internal e.g. ‘128Ms:1Gi’

Return type:

List[MemConfig]

Returns:

list of MemConfigs, decoded from the string

ska_low_cbf_fpga.parse_hbm_addresses_file(filename)[source]

Read HBM address offsets from a file.

Parameters:

filename (Path | str) – Path to an HBM address map file. The File must contain one integer value per line, which is used as the QDMA address offset for the respective HBM buffer.

Return type:

tuple[int, ...]

ska_low_cbf_fpga.stop_log_to_file(logger)[source]

Stop register logging.

Parameters:

logger (Logger) – Logger to configure

Return type:

None

ska_low_cbf_fpga.str_from_int_bytes(n_bytes, precision=2)[source]

Automatically scale a number of bytes for printing.

No decimals are shown for exact conversions, e.g. 1024 -> “1 KiB”

Parameters:
  • n_bytes (int) – Number of bytes

  • precision (int) – decimal places to show

Return type:

str

Returns:

A number and units, e.g. ‘1.5 KiB’