1 /* 2 * Copyright 2024 Basalte bv 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_INCLUDE_DRIVERS_UART_EMUL_H_ 8 #define ZEPHYR_INCLUDE_DRIVERS_UART_EMUL_H_ 9 10 #include <zephyr/device.h> 11 #include <zephyr/drivers/emul.h> 12 #include <zephyr/drivers/uart.h> 13 #include <zephyr/sys/slist.h> 14 #include <zephyr/types.h> 15 16 /** 17 * @file 18 * 19 * @brief Public APIs for the UART device emulation drivers. 20 */ 21 22 /** 23 * @brief UART Emulation Interface 24 * @defgroup uart_emul_interface UART Emulation Interface 25 * @ingroup io_emulators 26 * @{ 27 */ 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 struct uart_emul_device_api; 34 35 /** 36 * @brief Define the emulation callback function signature 37 * 38 * @param dev UART device instance 39 * @param size Number of available bytes in TX buffer 40 * @param target pointer to emulation context 41 */ 42 typedef void (*uart_emul_device_tx_data_ready_t)(const struct device *dev, size_t size, 43 const struct emul *target); 44 45 /** Node in a linked list of emulators for UART devices */ 46 struct uart_emul { 47 sys_snode_t node; 48 /** Target emulator - REQUIRED for all emulated bus nodes of any type */ 49 const struct emul *target; 50 /** API provided for this device */ 51 const struct uart_emul_device_api *api; 52 }; 53 54 /** Definition of the emulator API */ 55 struct uart_emul_device_api { 56 uart_emul_device_tx_data_ready_t tx_data_ready; 57 }; 58 59 /** 60 * Register an emulated device on the controller 61 * 62 * @param dev Device that will use the emulator 63 * @param emul UART emulator to use 64 * @return 0 indicating success 65 */ 66 int uart_emul_register(const struct device *dev, struct uart_emul *emul); 67 68 #ifdef __cplusplus 69 } 70 #endif 71 72 /** 73 * @} 74 */ 75 76 #endif /* ZEPHYR_INCLUDE_DRIVERS_UART_EMUL_H_ */ 77