acrn-hypervisor/misc/services/life_mngr/uart.h
Xiangyang Wu 591998e956 misc: life_mngr: add uart module
In the uart module, the following functions are implemented:
- init_uart_dev
Allocate UART device instance and initialize UART device
according to device name.
- deinit_uart_dev
Close UART devcie and free UART device instance.
- send_message_by_uart
Set handler to handle received message.
- receive_message_by_uart
Receive message and retry RETRY_RECV_TIMES time to
avoid miss message in some cases.
- get_uart_dev_fd
Get the file descriptor of a UART device
- get_uart_dev_path
Get the name of a UART device

v1-->v2:
	Update sync logic between uart in service VM and uart in
	user VM, lifecycle manager will not depend on VM boot order.
	Add code comments.
v2-->v3:
	This module only includes UART device operations, move other
	logic into uart channel module.
v3-->v4:
	Add parameters check for interface and refine some names.
v4-->v5:
	Refine interface parameter type, error value.
v5-->v6:
	Update condition check format of deinit_uart_dev.

Tracked-On: #6652

Signed-off-by: Xiangyang Wu <xiangyang.wu@intel.com>
Reviewed-by: fei1.li@intel.com
2021-11-12 11:04:23 +08:00

63 lines
1.5 KiB
C

/*
* Copyright (C)2021 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _UART_H_
#define _UART_H_
#include <sys/types.h>
#include <stdint.h>
#include <sys/queue.h>
#include <pthread.h>
#include <semaphore.h>
#include <sys/un.h>
#define TTY_PATH_MAX 32U
#define SCECOND_TO_US 1000000
#define WAIT_RECV (SCECOND_TO_US>>2)
#define RETRY_RECV_TIMES 20U
struct uart_dev {
char tty_path[TTY_PATH_MAX]; /**< UART device name */
int tty_fd; /**< the FD of opened UART device */
};
/**
* @brief Allocate UART device instance and initialize UART
* device according to device name
*
* @param path UART device name
* @return struct uart_dev* Ponit to UART device instance
*/
struct uart_dev *init_uart_dev(char *path);
/**
* @brief Close UART devcie and free UART device instance
*
* @param dev Poin to UART device instance
*/
void deinit_uart_dev(struct uart_dev *dev);
/**
* @brief Set handler to handle received message
*/
ssize_t send_message_by_uart(struct uart_dev *dev, const void *buf, size_t len);
/**
* @brief Receive message and retry RETRY_RECV_TIMES time to
* avoid miss message in some cases.
*/
ssize_t receive_message_by_uart(struct uart_dev *dev, void *buf, size_t len);
/**
* @brief Get the file descriptor of a UART device
*/
static inline int get_uart_dev_fd(struct uart_dev *dev)
{
return dev->tty_fd;
}
/**
* @brief Get the name of a UART device
*/
static inline char *get_uart_dev_path(struct uart_dev *dev)
{
return dev->tty_path;
}
#endif