HAL Communication Interface
A communication interface is represented by chi_interface_t and exposes open, close, read, and write methods for UART, SPI, etc.
-
typedef bool (*chi_interface_callback_t)(const chi_interface_t *iface)
Callback function type for asynchronous interface operations.
- Param iface:
Pointer to the interface instance.
- Return:
true if the operation was successful, false otherwise.
-
int iface_open(const chi_interface_t *iface)
Wrapper functions for interface operations.
These functions call the corresponding function pointers in the chi_interface_api structure.
- Parameters:
iface – Pointer to the interface instance
- Returns:
int Return 0 on success, negative value on failure.
-
int iface_close(const chi_interface_t *iface)
Wrapper functions for interface operations.
These functions call the corresponding function pointers in the chi_interface_api structure.
- Parameters:
iface – Pointer to the interface instance.
- Returns:
int Return 0 on success, negative value on failure.
-
ssize_t iface_read(const chi_interface_t *iface, void *buffer, uint32_t size, chi_interface_callback_t cb)
Wrapper functions for interface operations.
These functions call the corresponding function pointers in the chi_interface_api structure.
- Parameters:
iface – Pointer to the interface instance.
buffer – Pointer to the buffer for incoming data.
size – Number of bytes to read.
cb – Callback when the operation completes.
- Returns:
ssize_t Number of bytes read on success, negative on failure.
-
ssize_t iface_write(const chi_interface_t *iface, const void *buffer, uint32_t size, chi_interface_callback_t cb)
Wrapper functions for interface operations.
These functions call the corresponding function pointers in the chi_interface_api structure.
- Parameters:
iface – Pointer to the interface instance.
buffer – Pointer to the data to send.
size – Number of bytes to write.
cb – Callback when the operation completes.
- Returns:
ssize_t Number of bytes written on success, negative on failure.
-
int iface_flush(const chi_interface_t *iface)
Wrapper function to flush the interface buffers.
This function calls the corresponding function pointer in the chi_interface_api structure.
- Parameters:
iface – Pointer to the interface instance.
- Returns:
int Return 0 on success, negative value on failure.
-
struct chi_interface_t
- #include <interface_api.h>
Communication interface instance.
This structure represents a generic communication interface (e.g. UART, SPI) and holds the API pointer, the MMIO base, and a driver‑specific configuration pointer.
-
struct chi_interface_api
- #include <interface_api.h>
API structure defining function pointers for communication interfaces.
Forward declaration of chi_interface_api_t.
This structure contains the
open,close,read, andwritefunction pointers, enabling a standardized interface for UART, SPI, etc.Public Members
-
int (*open)(const chi_interface_t *iface)
Opens the interface.
This function initializes the hardware and prepares it for use.
- Param iface:
Pointer to the interface instance.
- Return:
0 on success, negative value on failure.
-
int (*close)(const chi_interface_t *iface)
Closes the interface.
This function releases any resources held by the interface.
- Param iface:
Pointer to the interface instance.
- Return:
0 on success, negative value on failure.
-
ssize_t (*read)(const chi_interface_t *iface, void *buffer, uint32_t size, chi_interface_callback_t cb)
Reads data from the interface.
Performs an asynchronous or blocking read, depending on the driver.
- Param iface:
Pointer to the interface instance.
- Param buffer:
Pointer to the buffer for incoming data.
- Param size:
Number of bytes to read.
- Param cb:
Callback when the operation completes.
- Return:
Number of bytes read on success, negative on failure.
-
ssize_t (*write)(const chi_interface_t *iface, const void *buffer, uint32_t size, chi_interface_callback_t cb)
Writes data to the interface.
Performs an asynchronous or blocking write, depending on the driver.
- Param iface:
Pointer to the interface instance.
- Param buffer:
Pointer to the data to send.
- Param size:
Number of bytes to write.
- Param cb:
Callback when the operation completes.
- Return:
Number of bytes written on success, negative on failure.
-
int (*flush)(const chi_interface_t *iface)
Flushes the interface buffers.
- Param iface:
Pointer to the interface instance.
- Return:
0 on success, negative value on failure.
-
int (*open)(const chi_interface_t *iface)