jaylink

package module
v0.0.0-...-7373577 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2020 License: GPL-3.0 Imports: 6 Imported by: 0

README

Go Report Card GoDoc

Go bindings for the libjaylink library.

What Is It?

Segger makes J-Link devices. These are USB or network connected JTAG/SWD interfaces.

Devices: https://www.segger.com/products/debug-probes/j-link/

libjaylink is a C-based library providing an API for controlling J-Link devices. This package provides a Go wrapper for the C-library API so the library can be called from Go programs.

Dependencies

Notes

All C-API functions have Go wrappers. The public interface of this package is a 1-1 mapping from the C-API to a Go style function prototypes. There are a couple of novel functions added as helper routines, but in general any C usage of the library has a simple mapping to Go.

Status

  • Some testing has been done, mostly using USB based J-Link devices.
  • Version 0.2.0 of the libjaylink library has been tested.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LibraryHasCap

func LibraryHasCap(capability uint) bool

LibraryHasCap checks for a capability of libjaylink.

func StrError

func StrError(code int) string

StrError returns a human-readable description of the error code.

func StrErrorName

func StrErrorName(code int) string

StrErrorName returns the name of the error code.

func VersionLibraryGetAge

func VersionLibraryGetAge() int

VersionLibraryGetAge gets the age version number of the libjaylink libtool interface.

func VersionLibraryGetCurrent

func VersionLibraryGetCurrent() int

VersionLibraryGetCurrent gets the current version number of the libjaylink libtool interface.

func VersionLibraryGetRevision

func VersionLibraryGetRevision() int

VersionLibraryGetRevision gets the revision version number of the libjaylink libtool interface.

func VersionLibraryGetString

func VersionLibraryGetString() string

VersionLibraryGetString gets the version number string of the libjaylink libtool interface.

func VersionPackageGetMajor

func VersionPackageGetMajor() int

VersionPackageGetMajor gets the major version number of the libjaylink package.

func VersionPackageGetMicro

func VersionPackageGetMicro() int

VersionPackageGetMicro gets the micro version number of the libjaylink package.

func VersionPackageGetMinor

func VersionPackageGetMinor() int

VersionPackageGetMinor gets the minor version number of the libjaylink package.

func VersionPackageGetString

func VersionPackageGetString() string

VersionPackageGetString gets the version number string of the libjaylink package.

Types

type Capabilities

type Capabilities []byte

Capabilities is a bitmap of device capabilities.

func (Capabilities) HasCap

func (caps Capabilities) HasCap(dc DeviceCapability) bool

HasCap returns true if a capability is present within the capabilities set.

func (Capabilities) String

func (caps Capabilities) String() string

type Connection

type Connection struct {
	Handle    uint16                  // handle
	Pid       uint32                  // client process id
	Hid       [C.INET_ADDRSTRLEN]byte // host id
	Iid       uint8                   // IID
	Cid       uint8                   // CID
	Timestamp uint32                  // Timestamp of the last registration in milliseconds.
}

Connection is a device connection.

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context is a structure representing a libjaylink context.

func Init

func Init() (*Context, error)

Init initializes libjaylink.

func (*Context) DiscoveryScan

func (ctx *Context) DiscoveryScan(ifaces HostInterface) error

DiscoveryScan scans for devices.

func (*Context) Exit

func (ctx *Context) Exit() error

Exit shutdowns libjaylink.

func (*Context) FreeDevices

func (ctx *Context) FreeDevices(dev []Device, unref bool)

FreeDevices frees devices.

func (*Context) GetDevices

func (ctx *Context) GetDevices() ([]Device, error)

GetDevices gets available devices.

func (*Context) LogGetDomain

func (ctx *Context) LogGetDomain() string

LogGetDomain gets the log domain.

func (*Context) LogGetLevel

func (ctx *Context) LogGetLevel() (LogLevel, error)

LogGetLevel gets the log level.

func (*Context) LogSetCallback

func (ctx *Context) LogSetCallback(cb LogFunc, user interface{}) error

LogSetCallback sets the logging callback function.

func (*Context) LogSetDomain

func (ctx *Context) LogSetDomain(domain string) error

LogSetDomain sets the log domain.

func (*Context) LogSetLevel

func (ctx *Context) LogSetLevel(level LogLevel) error

LogSetLevel sets the log level.

type Counter

type Counter uint32

Counter is a device counters bitmap.

const (
	COUNTER_TARGET_TIME        Counter = C.JAYLINK_COUNTER_TARGET_TIME        // Time the device is connected to a target in milliseconds.
	COUNTER_TARGET_CONNECTIONS Counter = C.JAYLINK_COUNTER_TARGET_CONNECTIONS // Number of times the device was connected or disconnected from a target.
)

Counter bitmap values.

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device is a structure representing a device.

func (*Device) GetHardwareVersion

func (dev *Device) GetHardwareVersion() (*HardwareVersion, error)

GetHardwareVersion gets the hardware version of a device.

func (*Device) GetHostInterface

func (dev *Device) GetHostInterface() (HostInterface, error)

GetHostInterface gets the host interface of a device.

func (*Device) GetIPv4Address

func (dev *Device) GetIPv4Address() (string, error)

GetIPv4Address gets the IPv4 address string of a device.

func (*Device) GetMacAddress

func (dev *Device) GetMacAddress() ([]byte, error)

GetMacAddress gets the MAC address of a device.

func (*Device) GetNickName

func (dev *Device) GetNickName() (string, error)

GetNickName gets the nickname of a device.

func (*Device) GetProductName

func (dev *Device) GetProductName() (string, error)

GetProductName gets the product name of a device.

func (*Device) GetSerialNumber

func (dev *Device) GetSerialNumber() (uint, error)

GetSerialNumber gets the serial number of a device.

func (*Device) GetUsbAddress

func (dev *Device) GetUsbAddress() (UsbAddress, error)

GetUsbAddress gets the USB address of a device.

func (*Device) GetUsbPorts

func (dev *Device) GetUsbPorts() (uint8, []uint8, error)

GetUsbPorts gets the USB bus and port numbers of a device.

func (*Device) Open

func (dev *Device) Open() (*DeviceHandle, error)

Open opens a device.

func (*Device) RefDevice

func (dev *Device) RefDevice() *Device

RefDevice increments the reference count of a device.

func (*Device) UnrefDevice

func (dev *Device) UnrefDevice()

UnrefDevice decrements the reference count of a device.

type DeviceCapability

type DeviceCapability uint

DeviceCapability is a bit position within the capabilities bitmap.

const (
	// libjaylink values
	DEV_CAP_GET_HW_VERSION    DeviceCapability = C.JAYLINK_DEV_CAP_GET_HW_VERSION
	DEV_CAP_ADAPTIVE_CLOCKING DeviceCapability = C.JAYLINK_DEV_CAP_ADAPTIVE_CLOCKING
	DEV_CAP_READ_CONFIG       DeviceCapability = C.JAYLINK_DEV_CAP_READ_CONFIG
	DEV_CAP_WRITE_CONFIG      DeviceCapability = C.JAYLINK_DEV_CAP_WRITE_CONFIG
	DEV_CAP_GET_SPEEDS        DeviceCapability = C.JAYLINK_DEV_CAP_GET_SPEEDS
	DEV_CAP_GET_FREE_MEMORY   DeviceCapability = C.JAYLINK_DEV_CAP_GET_FREE_MEMORY
	DEV_CAP_GET_HW_INFO       DeviceCapability = C.JAYLINK_DEV_CAP_GET_HW_INFO
	DEV_CAP_SET_TARGET_POWER  DeviceCapability = C.JAYLINK_DEV_CAP_SET_TARGET_POWER
	DEV_CAP_SELECT_TIF        DeviceCapability = C.JAYLINK_DEV_CAP_SELECT_TIF
	DEV_CAP_GET_COUNTERS      DeviceCapability = C.JAYLINK_DEV_CAP_GET_COUNTERS
	DEV_CAP_SWO               DeviceCapability = C.JAYLINK_DEV_CAP_SWO
	DEV_CAP_FILE_IO           DeviceCapability = C.JAYLINK_DEV_CAP_FILE_IO
	DEV_CAP_REGISTER          DeviceCapability = C.JAYLINK_DEV_CAP_REGISTER
	DEV_CAP_GET_EXT_CAPS      DeviceCapability = C.JAYLINK_DEV_CAP_GET_EXT_CAPS
	DEV_CAP_EMUCOM            DeviceCapability = C.JAYLINK_DEV_CAP_EMUCOM
	DEV_CAP_ETHERNET          DeviceCapability = C.JAYLINK_DEV_CAP_ETHERNET
	// from Segger J-Link docs
	DEV_CAP_RESERVED_1         DeviceCapability = 0
	DEV_CAP_WRITE_DCC          DeviceCapability = 2
	DEV_CAP_TRACE              DeviceCapability = 6
	DEV_CAP_WRITE_MEM          DeviceCapability = 7
	DEV_CAP_READ_MEM           DeviceCapability = 8
	DEV_CAP_EXEC_CODE          DeviceCapability = 10
	DEV_CAP_RESET_STOP_TIMED   DeviceCapability = 14
	DEV_CAP_RESERVED_2         DeviceCapability = 15
	DEV_CAP_MEASURE_RTCK_REACT DeviceCapability = 16
	DEV_CAP_RW_MEM_ARM79       DeviceCapability = 18
	DEV_CAP_READ_DCC           DeviceCapability = 20
	DEV_CAP_GET_CPU_CAPS       DeviceCapability = 21
	DEV_CAP_EXEC_CPU_CMD       DeviceCapability = 22
	DEV_CAP_WRITE_DCC_EX       DeviceCapability = 24
	DEV_CAP_UPDATE_FIRMWARE_EX DeviceCapability = 25
	DEV_CAP_INDICATORS         DeviceCapability = 28
	DEV_CAP_TEST_NET_SPEED     DeviceCapability = 29
	DEV_CAP_RAWTRACE           DeviceCapability = 30
)

DeviceCapability values.

func (DeviceCapability) String

func (dc DeviceCapability) String() string

type DeviceHandle

type DeviceHandle struct {
	// contains filtered or unexported fields
}

DeviceHandle is a structure representing a handle of a device.

func (*DeviceHandle) ClearReset

func (hdl *DeviceHandle) ClearReset() error

ClearReset clears the target reset signal.

func (*DeviceHandle) Close

func (hdl *DeviceHandle) Close() error

Close closes a device.

func (*DeviceHandle) EmuComRead

func (hdl *DeviceHandle) EmuComRead(channel uint32, length int) ([]byte, error)

EmuComRead reads from an EMUCOM channel.

func (*DeviceHandle) EmuComWrite

func (hdl *DeviceHandle) EmuComWrite(channel uint32, buffer []byte) (int, error)

EmuComWrite writes to an EMUCOM channel.

func (*DeviceHandle) FileDelete

func (hdl *DeviceHandle) FileDelete(filename string) error

FileDelete deletes a file.

func (*DeviceHandle) FileGetSize

func (hdl *DeviceHandle) FileGetSize(filename string) (uint32, error)

FileGetSize retrieves the size of a file.

func (*DeviceHandle) FileRead

func (hdl *DeviceHandle) FileRead(filename string, offset uint32, length int) ([]byte, error)

FileRead reads from a file.

func (*DeviceHandle) FileWrite

func (hdl *DeviceHandle) FileWrite(filename string, buffer []byte, offset uint32) (int, error)

FileWrite writes to a file.

func (*DeviceHandle) GetAllCaps

func (hdl *DeviceHandle) GetAllCaps() (Capabilities, error)

GetAllCaps returns all device capabilities (normal or extended).

func (*DeviceHandle) GetAvailableInterfaces

func (hdl *DeviceHandle) GetAvailableInterfaces() (uint32, error)

GetAvailableInterfaces retrieves the available target interfaces.

func (*DeviceHandle) GetCaps

func (hdl *DeviceHandle) GetCaps() (Capabilities, error)

GetCaps retrieves the capabilities of a device.

func (*DeviceHandle) GetCounters

func (hdl *DeviceHandle) GetCounters(mask Counter) ([]uint32, error)

GetCounters retrieves the counter values of a device.

func (*DeviceHandle) GetDevice

func (hdl *DeviceHandle) GetDevice() *Device

GetDevice gets the device instance from a device handle.

func (*DeviceHandle) GetExtendedCaps

func (hdl *DeviceHandle) GetExtendedCaps() (Capabilities, error)

GetExtendedCaps retrieves the extended capabilities of a device. Extended capabilties are a superset of normal capabilities.

func (*DeviceHandle) GetFirmwareVersion

func (hdl *DeviceHandle) GetFirmwareVersion() (string, error)

GetFirmwareVersion retrieves the firmware version of a device.

func (*DeviceHandle) GetFreeMemory

func (hdl *DeviceHandle) GetFreeMemory() (uint32, error)

GetFreeMemory retrieves the size of free memory of a device.

func (*DeviceHandle) GetHardwareInfo

func (hdl *DeviceHandle) GetHardwareInfo(mask HardwareInfo) ([]uint32, error)

GetHardwareInfo retrieves the hardware information of a device.

func (*DeviceHandle) GetHardwareStatus

func (hdl *DeviceHandle) GetHardwareStatus() (*HardwareStatus, error)

GetHardwareStatus retrieves the hardware status of a device.

func (*DeviceHandle) GetHardwareVersion

func (hdl *DeviceHandle) GetHardwareVersion() (*HardwareVersion, error)

GetHardwareVersion gets the hardware version of a device.

func (*DeviceHandle) GetJtagCommandVersion

func (hdl *DeviceHandle) GetJtagCommandVersion() (JtagVersion, error)

GetJtagCommandVersion gets the JTAG command version for the device.

func (*DeviceHandle) GetMaxSpeed

func (hdl *DeviceHandle) GetMaxSpeed() (uint16, error)

GetMaxSpeed returns the maximum interface speed.

func (*DeviceHandle) GetSelectedInterface

func (hdl *DeviceHandle) GetSelectedInterface() (TargetInterface, error)

GetSelectedInterface retrieves the selected target interface.

func (*DeviceHandle) GetSpeeds

func (hdl *DeviceHandle) GetSpeeds() (*Speed, error)

GetSpeeds retrieves target interface speeds.

func (*DeviceHandle) JtagClearTrst

func (hdl *DeviceHandle) JtagClearTrst() error

JtagClearTrst clears the JTAG test reset (TRST) signal.

func (*DeviceHandle) JtagIO

func (hdl *DeviceHandle) JtagIO(tms, tdi []byte, n uint16, version JtagVersion) ([]byte, error)

JtagIO performs a JTAG I/O operation.

func (*DeviceHandle) JtagSetTrst

func (hdl *DeviceHandle) JtagSetTrst() error

JtagSetTrst sets the JTAG test reset (TRST) signal.

func (*DeviceHandle) ReadRawConfig

func (hdl *DeviceHandle) ReadRawConfig() (*RawConfig, error)

ReadRawConfig reads the raw configuration data of a device.

func (*DeviceHandle) Register

func (hdl *DeviceHandle) Register(connection *Connection) ([]Connection, error)

Register registers a connection on a device.

func (*DeviceHandle) SelectInterface

func (hdl *DeviceHandle) SelectInterface(iface TargetInterface) (TargetInterface, error)

SelectInterface selects the target interface.

func (*DeviceHandle) SetReset

func (hdl *DeviceHandle) SetReset() error

SetReset sets the target reset signal.

func (*DeviceHandle) SetSpeed

func (hdl *DeviceHandle) SetSpeed(speed uint16) error

SetSpeed sets the target interface speed (in kHz units).

func (*DeviceHandle) SetTargetPower

func (hdl *DeviceHandle) SetTargetPower(enable bool) error

SetTargetPower sets the target power supply.

func (*DeviceHandle) SwdIO

func (hdl *DeviceHandle) SwdIO(direction, out []byte, n uint16) ([]byte, error)

SwdIO performs a SWD I/O operation.

func (*DeviceHandle) SwoGetSpeeds

func (hdl *DeviceHandle) SwoGetSpeeds(mode SwoMode) (*SwoSpeed, error)

SwoGetSpeeds retrieves SWO speeds.

func (*DeviceHandle) SwoRead

func (hdl *DeviceHandle) SwoRead(length int) ([]byte, error)

SwoRead reads SWO trace data.

func (*DeviceHandle) SwoStart

func (hdl *DeviceHandle) SwoStart(mode SwoMode, baudrate, size uint32) error

SwoStart starts SWO capture.

func (*DeviceHandle) SwoStop

func (hdl *DeviceHandle) SwoStop() error

SwoStop stops SWO capture.

func (*DeviceHandle) Unregister

func (hdl *DeviceHandle) Unregister(connection *Connection) ([]Connection, error)

Unregister unregisters a connection from a device.

func (*DeviceHandle) WriteRawConfig

func (hdl *DeviceHandle) WriteRawConfig(config *RawConfig) error

WriteRawConfig writes the raw configuration data of a device.

type Error

type Error struct {
	Name string // function name
	Code int    // C return code
}

Error stores error information.

func (*Error) Error

func (e *Error) Error() string

type HardwareInfo

type HardwareInfo uint32

HardwareInfo is a hardware information bitmap.

HardwareInfo bitmap values.

type HardwareStatus

type HardwareStatus struct {
	TargetVoltage uint16 // Target reference voltage in mV
	Tck           bool   // TCK pin state
	Tdi           bool   // TDI pin state
	Tdo           bool   // TDO pin state
	Tms           bool   // TMS pin state
	Tres          bool   // TRES pin state
	Trst          bool   // TRST pin state
}

HardwareStatus stores the device hardware status.

func (*HardwareStatus) String

func (hs *HardwareStatus) String() string

type HardwareType

type HardwareType uint32

HardwareType is the device hardware type.

const (
	// libjaylink values
	HW_TYPE_JLINK     HardwareType = C.JAYLINK_HW_TYPE_JLINK
	HW_TYPE_FLASHER   HardwareType = C.JAYLINK_HW_TYPE_FLASHER
	HW_TYPE_JLINK_PRO HardwareType = C.JAYLINK_HW_TYPE_JLINK_PRO
	// other values
	HW_TYPE_JTRACE             HardwareType = 1
	HW_TYPE_JLINK_LITE_ADI     HardwareType = 5
	HW_TYPE_JLINK_LITE_XMC4000 HardwareType = 16
	HW_TYPE_JLINK_LITE_XMC4200 HardwareType = 17
	HW_TYPE_LPCLINK2           HardwareType = 18
)

HardwareType values.

func (HardwareType) String

func (h HardwareType) String() string

type HardwareVersion

type HardwareVersion struct {
	Hwtype   HardwareType
	Major    uint8
	Minor    uint8
	Revision uint8
}

HardwareVersion is the hardware type and version.

func (HardwareVersion) String

func (h HardwareVersion) String() string

type HostInterface

type HostInterface uint32

HostInterface is the host interface bitmap. When used for device discovery multiple bits are set. When used for specific devices one bit is set for the interface type.

HostInterface bitmap values.

func (HostInterface) String

func (h HostInterface) String() string

type JtagVersion

type JtagVersion uint32

JtagVersion is the JTAG command version.

const (
	JTAG_VERSION_2 JtagVersion = C.JAYLINK_JTAG_VERSION_2
	JTAG_VERSION_3 JtagVersion = C.JAYLINK_JTAG_VERSION_3
)

JtagVersion values.

type LogFunc

type LogFunc func(domain, msg string, user interface{})

LogFunc is a logging callback function.

type LogLevel

type LogLevel uint32

LogLevel is the log level.

const (
	LOG_LEVEL_NONE     LogLevel = C.JAYLINK_LOG_LEVEL_NONE     // no messages
	LOG_LEVEL_ERROR    LogLevel = C.JAYLINK_LOG_LEVEL_ERROR    // error messages
	LOG_LEVEL_WARNING  LogLevel = C.JAYLINK_LOG_LEVEL_WARNING  // warnings
	LOG_LEVEL_INFO     LogLevel = C.JAYLINK_LOG_LEVEL_INFO     // informational messages
	LOG_LEVEL_DEBUG    LogLevel = C.JAYLINK_LOG_LEVEL_DEBUG    // debug messages
	LOG_LEVEL_DEBUG_IO LogLevel = C.JAYLINK_LOG_LEVEL_DEBUG_IO // I/O debug messages
)

LogLevel values.

type RawConfig

type RawConfig [C.JAYLINK_DEV_CONFIG_SIZE]byte

RawConfig is the raw device configuration.

type Speed

type Speed struct {
	Freq uint32 // Base frequency in Hz.
	Div  uint16 // Minimum frequency divider.
}

Speed stores the target interface speed information.

type SwoMode

type SwoMode uint32

SwoMode is the Serial Wire Output (SWO) capture mode.

const (
	SWO_MODE_UART SwoMode = C.JAYLINK_SWO_MODE_UART // Universal Asynchronous Receiver Transmitter (UART).
)

SwoMode values.

type SwoSpeed

type SwoSpeed struct {
	Freq         uint32 // Base frequency in Hz
	MinDiv       uint32 // Minimum frequency divider
	MaxDiv       uint32 // Maximum frequency divider
	MinPrescaler uint32 // Minimum prescaler
	MaxPrescaler uint32 // Maximum prescaler
}

SwoSpeed store Serial Wire Output (SWO) speed information.

type TargetInterface

type TargetInterface uint32

TargetInterface is a bitmap of target interfaces.

const (
	TIF_JTAG          TargetInterface = C.JAYLINK_TIF_JTAG          // Joint Test Action Group, IEEE 1149.1 (JTAG).
	TIF_SWD           TargetInterface = C.JAYLINK_TIF_SWD           // Serial Wire Debug (SWD).
	TIF_BDM3          TargetInterface = C.JAYLINK_TIF_BDM3          // Background Debug Mode 3 (BDM3).
	TIF_FINE          TargetInterface = C.JAYLINK_TIF_FINE          // Renesas’ single-wire debug interface (FINE).
	TIF_2W_JTAG_PIC32 TargetInterface = C.JAYLINK_TIF_2W_JTAG_PIC32 // 2-wire JTAG for PIC32 compliant devices.
)

TargetInterface bit values

type UsbAddress

type UsbAddress uint32

UsbAddress stores the USB address number (Product ID).

const (
	USB_ADDRESS_0 UsbAddress = C.JAYLINK_USB_ADDRESS_0 // USB address 0 (Product ID 0x0101)
	USB_ADDRESS_1 UsbAddress = C.JAYLINK_USB_ADDRESS_1 // USB address 1 (Product ID 0x0102)
	USB_ADDRESS_2 UsbAddress = C.JAYLINK_USB_ADDRESS_2 // USB address 2 (Product ID 0x0103)
	USB_ADDRESS_3 UsbAddress = C.JAYLINK_USB_ADDRESS_3 // USB address 3 (Product ID 0x0104)
)

UsbAddress values.

func (UsbAddress) String

func (u UsbAddress) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL