HAL Accelerator Device

An accelerator device is represented by the chi_device_t structure and provides open, close, read, and write operations for offloaded hardware.

typedef bool (*chi_device_callback_t)(chi_device_t *device)

Callback function type for asynchronous device operations.

Param device:

Pointer to the device structure.

Return:

true if the operation was successful, false otherwise.

struct chi_device_t
#include <device_api.h>

Device structure.

This structure represents a device in the system.

Public Members

chi_device_api_t *api

Device API (function pointers).

uint32_t *device_addr

Device address.

void *cfg

Device configuration.

struct chi_device_api
#include <device_api.h>

Device API structure defining function pointers for a device.

Forward declaration of chi_device_api_t.

This structure contains function pointers for device operations, enabling a standardized interface for device drivers.

Public Members

int (*open)(chi_device_t *device)

Opens the device.

This function initializes the device and prepares it for communication.

Param device:

Pointer to the device structure.

Return:

0 on success, negative value on failure.

int (*close)(chi_device_t *device)

Closes the device.

This function releases resources associated with the device.

Param device:

Pointer to the device structure.

Return:

0 on success, negative value on failure.

ssize_t (*read)(chi_device_t *device, void *buffer, uint32_t size, chi_device_callback_t cb)

Reads data from the device.

This function performs an asynchronous read operation on the device.

Param device:

Pointer to the device structure.

Param buffer:

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

Param size:

Number of bytes to read.

Param cb:

Callback function to be called when the read completes.

Return:

Number of bytes read on success, negative value on failure.

ssize_t (*write)(chi_device_t *device, const void *buffer, uint32_t size, chi_device_callback_t cb)

Writes data to the device.

This function performs an asynchronous write operation on the device.

Param device:

Pointer to the device structure.

Param buffer:

Pointer to the buffer containing the data to write.

Param size:

Number of bytes to write.

Param cb:

Callback function to be called when the write completes.

Return:

Number of bytes written on success, negative value on failure.