KATCP.jl Documentation

KATCP.jl is a Julia package for communicating via the Karoo Array Telescope Control Protocol (KATCP). More information about KATCP can be found at the CASPER Wiki, including the KATCP specification in PDF format.

Connecting to a KATCP server

To communicate with a KATCP server you need to construct a KATCP.Client object. You will pass this object to other functions to read/write from/to your KATCP-enabled device.

KATCP.ClientType
Client(host, port::Integer=7147)

Construct a Client object for communicating with a KATCP server running on port port of host.

source

Example

client = KATCP.Client("katcphost") # Use default port 7147
client = KATCP.Client("katcphost", 7147) # Specify port explicitly

Get list of devices

The listdev function returns a Dict that maps device names to device sizes (in bytes).

KATCP.listdevFunction
listdev(client) -> Dict{String,Int}

Return a Dict mapping device names to device byte sizes.

source

Example

julia> devmap = listdev(client)
Dict{String, Int64} with 51 entries:
  "onehundred_gbe_gmac_reg_arp_size"             => 4
  "onehundred_gbe_gmac_reg_word_size"            => 4
  "onehundred_gbe_gmac_reg_local_ip_netmask"     => 4
  "sys"                                          => 32
  "onehundred_gbe_gmac_arp_cache_read_data"      => 4
  "onehundred_gbe_gmac_reg_bytes_rdy"            => 4
  "onehundred_gbe_gmac_reg_core_type"            => 4
  "onehundred_gbe_gmac_reg_tx_almost_full_count" => 4
  "onehundred_gbe_gmac_arp_cache_write_address"  => 4
  "lpmode"                                       => 4
  "sys_scratchpad"                               => 4
  "onehundred_gbe_gmac_arp_cache_read_address"   => 4
  "onehundred_gbe_gmac_reg_mac_address_h"        => 4
  "onehundred_gbe_gmac_reg_tx_packet_rate"       => 4
  "onehundred_gbe_gmac_reg_phy_status_h"         => 4
  "qsfp_rst"                                     => 4
  "onehundred_gbe"                               => 65536
  ⋮                                              => ⋮

Reading and writing registers

You can use the regread and regwrite function to read/write registers.

KATCP.regreadFunction
regread(client::Client, name)

Read 32-bit regsiter named name from client.

source
KATCP.regwriteFunction
regwrite(client::Client, name, data)

Writes data to 32-bit regsiter named name using client.

source

Example

julia> regread(client, "sys_scratchpad")
0x00000000

julia> regwrite(client, "sys_scratchpad", 12345678)

julia> regread(client, "sys_scratchpad")
0x00bc614e

julia> regwrite(client, "sys_scratchpad", 0x12345678)

julia> regread(client, "sys_scratchpad")
0x12345678

julia> regwrite(client, "sys_scratchpad", 0)

julia> regread(client, "sys_scratchpad")
0x00000000

Reading and writing memory devices

The memory space of Block RAMs and Yellow Blocks can be read from and written to using read and write. This also works for registers, which are essentially just 4 byte memories.

Info

All reads and writes in KATCP.jl must be aligned on 4 byte boundaries. Currently, read only returns UInt32 values. Some conversion from other Integer types are supported by write, but this is subject to change. You are strongly encouraged to reinterpret or convert your data as needed if you desire a different numerical type.

Base.readMethod
Base.read(client::Client, name, offset, length)
Base.read(client::Client, name; offset=0, length=4)

Use client to read length bytes from device name starting at offset.

Both offset and length are byte counts and must be a multiple of 4.

source
Base.writeMethod
Base.write(client::Client, name, data, offset=0)

Use client to write data to device name starting at offset.

offset is a byte counts and must be a multiple of 4.

source

Example

julia> write(client, "sys_scratchpad", 0x11223344)

julia> read(client, "sys_scratchpad", 0, 4)
1-element Vector{UInt32}:
 0x11223344

Estimate FPGA clock frequency

KATCP.estimate_fpga_clockFunction
estimate_fpga_clock(client, interval=1) -> Estimated clock frequency in MHz

Return an estimate of the FPGA clock frequency in MHz.

Read sys_clkcounter twice, sleeping interval seconds between the readings, and compute the FPGA clock frequency.

source

Example

julia> estimate_fpga_clock(client)
257.542124

Index