建立工程,成功创建两个虚拟串口

This commit is contained in:
ranchuan
2023-06-21 18:00:56 +08:00
commit 3604192d8f
872 changed files with 428764 additions and 0 deletions

View File

@@ -0,0 +1,128 @@
/**
******************************************************************************
* @file virt_uart.c
* @author MCD Application Team
* @brief UART HAL module driver.
* This file provides firmware functions to manage an rpmsg endpoint
* from user application
*
*
@verbatim
===============================================================================
##### How to use this driver #####
===============================================================================
[..]
The VIRTUAL UART driver can be used as follows:
(#) Initialize the Virtual UART by calling the VIRT_UART_Init() API.
(++) create an endpoint. listener on the OpenAMP-rpmsg channel is now enabled.
Receive data is now possible if user registers a callback to this VIRTUAL UART instance
by calling in providing a callback function when a message is received from
remote processor (VIRT_UART_read_cb)
OpenAMP MW deals with memory allocation/free and signal events
(#) Transmit data on the created rpmsg channel by calling the VIRT_UART_Transmit()
(#) Receive data in calling VIRT_UART_RegisterCallback to register user callback
@endverbatim
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "virt_uart.h"
#include "metal/utilities.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* this string will be sent to remote processor */
#define RPMSG_SERVICE_NAME "rpmsg-tty-channel"
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
static int VIRT_UART_read_cb(struct rpmsg_endpoint *ept, void *data,
size_t len, uint32_t src, void *priv)
{
VIRT_UART_HandleTypeDef *huart = metal_container_of(ept, VIRT_UART_HandleTypeDef, ept);
(void)src;
huart->pRxBuffPtr = data;
huart->RxXferSize = len;
if (huart->RxCpltCallback != NULL) {
huart->RxCpltCallback(huart);
}
return 0;
}
VIRT_UART_StatusTypeDef VIRT_UART_Init(VIRT_UART_HandleTypeDef *huart)
{
int status;
/* Create a endpoint for rmpsg communication */
status = OPENAMP_create_endpoint(&huart->ept, RPMSG_SERVICE_NAME, RPMSG_ADDR_ANY,
VIRT_UART_read_cb, NULL);
if(status < 0) {
return VIRT_UART_ERROR;
}
return VIRT_UART_OK;
}
VIRT_UART_StatusTypeDef VIRT_UART_DeInit (VIRT_UART_HandleTypeDef *huart)
{
OPENAMP_destroy_ept(&huart->ept);
return VIRT_UART_OK;
}
VIRT_UART_StatusTypeDef VIRT_UART_RegisterCallback(VIRT_UART_HandleTypeDef *huart,
VIRT_UART_CallbackIDTypeDef CallbackID,
void (* pCallback)(VIRT_UART_HandleTypeDef *_huart))
{
VIRT_UART_StatusTypeDef status = VIRT_UART_OK;
switch (CallbackID)
{
case VIRT_UART_RXCPLT_CB_ID :
huart->RxCpltCallback = pCallback;
break;
default :
/* Return error status */
status = VIRT_UART_ERROR;
break;
}
return status;
return VIRT_UART_OK;
}
VIRT_UART_StatusTypeDef VIRT_UART_Transmit(VIRT_UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
{
int res;
if (Size > (RPMSG_BUFFER_SIZE-16))
return VIRT_UART_ERROR;
res = OPENAMP_send(&huart->ept, pData, Size);
if (res <0) {
return VIRT_UART_ERROR;
}
return VIRT_UART_OK;
}

View File

@@ -0,0 +1,76 @@
/**
******************************************************************************
* @file virt_uart.h
* @author MCD Application Team
* @brief Header file of UART VIRT module.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __VIRT_UART_H
#define __VIRT_UART_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "openamp.h"
/* Exported structures --------------------------------------------------------*/
typedef struct __VIRT_UART_HandleTypeDef
{
struct rpmsg_endpoint ept; /*!< rpmsg endpoint */
struct rpmsg_virtio_device *rvdev; /*< pointer to the rpmsg virtio device */
uint8_t *pRxBuffPtr; /*!< Pointer to VIRTUAL UART Rx transfer Buffer */
uint16_t RxXferSize; /*!< VIRTUAL UART Rx Transfer size */
void (* RxCpltCallback)( struct __VIRT_UART_HandleTypeDef * hppp); /*!< RX CPLT callback */
}VIRT_UART_HandleTypeDef;
typedef enum
{
VIRT_UART_OK = 0x00U,
VIRT_UART_ERROR = 0x01U,
VIRT_UART_BUSY = 0x02U,
VIRT_UART_TIMEOUT = 0x03U
} VIRT_UART_StatusTypeDef;
typedef enum
{
VIRT_UART_RXCPLT_CB_ID = 0x00U, /*!< PPP event 1 callback ID */
}VIRT_UART_CallbackIDTypeDef;
/* Exported functions --------------------------------------------------------*/
/* Initialization and de-initialization functions ****************************/
VIRT_UART_StatusTypeDef VIRT_UART_Init(VIRT_UART_HandleTypeDef *huart);
VIRT_UART_StatusTypeDef VIRT_UART_DeInit (VIRT_UART_HandleTypeDef *huart);
VIRT_UART_StatusTypeDef VIRT_UART_RegisterCallback(VIRT_UART_HandleTypeDef *huart,
VIRT_UART_CallbackIDTypeDef CallbackID,
void (* pCallback)(VIRT_UART_HandleTypeDef *_huart));
/* IO operation functions *****************************************************/
VIRT_UART_StatusTypeDef VIRT_UART_Transmit(VIRT_UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
#ifdef __cplusplus
}
#endif
#endif /* __VIRT_UART_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/