Usermode C-API

API for interacting with the THANNA kernel module.

This library provides a high-level interface to communicate with the THANNA kernel module, enabling efficient data exchange between user space and the FPGA. It supports direct access to the device’s AXI registers and memory regions using IOCTL system calls, along with file operations for reading, writing, and memory mapping.

Key Features:

  • Register Access via IOCTL: Functions such as thanna_read_reg, thanna_write_reg, and thanna_update_reg_bits allow users to interact with the AXI slave registers of the FPGA through IOCTL calls. These functions enable reading, writing, and bit-masking operations on specified registers.

  • Memory Access: The library provides thanna_read_mem and thanna_write_mem functions to read and write arbitrary memory regions, facilitating data transfer between user space and the FPGA’s DMA region.

  • Device Management: The thanna_open and thanna_close functions handle opening and closing of the Thanna device at /dev/thanna.

  • Integration with User Applications: The library can be used to simplify interactions with the Thanna kernel module from user-space applications, making it easier to implement high-level logic for FPGA control and data exchange.

Example Usage:

This library abstracts low-level operations, allowing developers to focus on application logic without worrying about direct kernel interactions.

Defines

DEVNAME

Name of the thanna-Device.

This is the path to the thanna-Device in the linux-filesystem

READ_REG

Macro to read from a register via IOCTL.

Used with ioctl to read from a register.

WRITE_REG

Macro to write to a register via IOCTL.

Used with ioctl to write to a register.

UPDATE_REG_BITS

Macro to update specific bits in a register via IOCTL.

Used with ioctl to update specific bits in a register, defined by a mask.

FLUSH_CACHE

Functions

uint32_t thanna_read_reg(uint32_t offset)

Reads the content of the register at offset.

Parameters:

offset – The offset of the register to be read.

Returns:

The content of the register at the given offset, or -1 on error.

int thanna_write_reg(uint32_t offset, uint32_t data)

Writes to the register at offset.

Parameters:
  • offset – The offset of the register to be written.

  • data – The data to be written to the register.

Returns:

0 on success, or -1 on error.

int thanna_update_reg_bits(uint32_t offset, uint32_t mask, uint32_t data)

Updates specific bits in a register at offset.

Parameters:
  • offset – The offset of the register to be updated.

  • mask – The mask specifying which bits to update.

  • data – The data to be written to the masked bits.

Returns:

0 on success, or -1 on error.

int thanna_read_mem(uint32_t offset, void *data, uint32_t size)

Reads memory starting from a given offset.

Parameters:
  • offset – The offset from which memory will be read.

  • data – Pointer to the buffer where the read data will be stored.

  • size – The number of bytes to read.

Returns:

0 on success, or -1 on error.

int thanna_write_mem(uint32_t offset, void *data, uint32_t size)

Writes to memory starting from a given offset.

Parameters:
  • offset – The offset from which memory will be written.

  • data – Pointer to the buffer containing the data to write.

  • size – The number of bytes to write.

Returns:

0 on success, or -1 on error.

int thanna_open()

Opens the thanna device.

Returns:

File descriptor on success, or -1 on error.

int thanna_close()

Closes the thanna device.

Returns:

0 on success, or -1 on error.

int thanna_flush_cache()

Flushes the cach.

Returns:

0 on success, or -1 on error.

struct thanna_ioctl_reg_args
#include <libthanna.h>

Structure for register operations using IOCTL.

This structure is used to specify the offset, data, and mask for register operations performed via the ioctl interface.

Public Members

uint32_t offset

Offset of the register

uint32_t data

Data to be written or read

uint32_t mask

Mask to apply for update operations