drivers: console: uart_mux: Initial UART muxing support
Create support for muxed UARTs which are attached to a real UART and which use GSM 07.10 muxing protocol to create virtual channels that can be run on top of the real UART. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
b5525a0f91
commit
420b195b5e
7 changed files with 1049 additions and 0 deletions
117
include/drivers/console/uart_mux.h
Normal file
117
include/drivers/console/uart_mux.h
Normal file
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright (c) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Public APIs for UART MUX drivers
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_DRIVERS_UART_MUX_H_
|
||||
#define ZEPHYR_INCLUDE_DRIVERS_UART_MUX_H_
|
||||
|
||||
/**
|
||||
* @brief UART Mux Interface
|
||||
* @defgroup uart_mux_interface UART Mux Interface
|
||||
* @ingroup io_interfaces
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <device.h>
|
||||
#include <drivers/uart.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct gsm_dlci;
|
||||
|
||||
/**
|
||||
* @typedef uart_mux_attach_cb_t
|
||||
*
|
||||
* @brief Define the user callback function which is called when
|
||||
* the UART mux is attached properly.
|
||||
*
|
||||
* @param mux UART mux device
|
||||
* @param dlci_address DLCI id for the virtual muxing channel
|
||||
* @param connected True if DLCI is connected, false otherwise.
|
||||
* @param user_data Arbitrary user data.
|
||||
*/
|
||||
typedef void (*uart_mux_attach_cb_t)(struct device *mux, int dlci_address,
|
||||
bool connected, void *user_data);
|
||||
|
||||
/** @brief UART mux driver API structure. */
|
||||
__subsystem struct uart_mux_driver_api {
|
||||
/**
|
||||
* The uart_driver_api must be placed in first position in this
|
||||
* struct so that we are compatible with uart API. Note that currently
|
||||
* not all of the UART API functions are implemented.
|
||||
*/
|
||||
struct uart_driver_api uart_api;
|
||||
|
||||
/**
|
||||
* Attach the mux to this UART. The API will call the callback after
|
||||
* the DLCI is created or not.
|
||||
*/
|
||||
int (*attach)(struct device *mux, struct device *uart,
|
||||
int dlci_address, uart_mux_attach_cb_t cb,
|
||||
void *user_data);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Attach physical/real UART to UART muxing device.
|
||||
*
|
||||
* @param mux UART mux device structure.
|
||||
* @param uart Real UART device structure.
|
||||
* @param dlci_address DLCI id for the virtual muxing channel
|
||||
* @param cb Callback is called when the DLCI is ready and connected
|
||||
* @param user_data Caller supplied optional data
|
||||
*
|
||||
* @retval 0 No errors, the attachment was successful
|
||||
* @retval <0 Error
|
||||
*/
|
||||
static inline int uart_mux_attach(struct device *mux, struct device *uart,
|
||||
int dlci_address, uart_mux_attach_cb_t cb,
|
||||
void *user_data)
|
||||
{
|
||||
const struct uart_mux_driver_api *api =
|
||||
(const struct uart_mux_driver_api *)mux->driver_api;
|
||||
|
||||
return api->attach(mux, uart, dlci_address, cb, user_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get UART related to a specific DLCI channel
|
||||
*
|
||||
* @param dlci_address DLCI address, value >0 and <63
|
||||
*
|
||||
* @return UART device if found, NULL otherwise
|
||||
*/
|
||||
__syscall struct device *uart_mux_find(int dlci_address);
|
||||
|
||||
/**
|
||||
* @brief Allocate muxing UART device.
|
||||
*
|
||||
* @details This will return next available uart mux driver that will mux the
|
||||
* data when read or written. This device corresponds to one DLCI channel.
|
||||
* User must first call this to allocate the DLCI and then call the attach
|
||||
* function to fully enable the muxing.
|
||||
*
|
||||
* @retval device New UART device that will automatically mux data sent to it.
|
||||
* @retval NULL if error
|
||||
*/
|
||||
struct device *uart_mux_alloc(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#include <syscalls/uart_mux.h>
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_DRIVERS_UART_MUX_H_ */
|
|
@ -165,6 +165,16 @@
|
|||
__net_l2_data_end = .;
|
||||
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
|
||||
|
||||
#if defined(CONFIG_UART_MUX)
|
||||
SECTION_DATA_PROLOGUE(uart_mux,,SUBALIGN(4))
|
||||
{
|
||||
__uart_mux_start = .;
|
||||
*(".uart_mux.*")
|
||||
KEEP(*(SORT_BY_NAME(".uart_mux.*")))
|
||||
__uart_mux_end = .;
|
||||
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_USB_DEVICE_STACK)
|
||||
SECTION_DATA_PROLOGUE(usb_descriptor,,SUBALIGN(1))
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue