stm32f7: serial: add interface to get uart_dev_t by USART number, stm32_serial_get_uart
This commit is contained in:
parent
95941b4908
commit
e180522854
@ -228,6 +228,10 @@ struct up_dev_s
|
||||
uint16_t ie; /* Saved interrupt mask bits value */
|
||||
uint16_t sr; /* Saved status bits */
|
||||
|
||||
/* Has been initialized and HW is setup. */
|
||||
|
||||
bool initialized;
|
||||
|
||||
/* If termios are supported, then the following fields may vary at
|
||||
* runtime.
|
||||
*/
|
||||
@ -1460,6 +1464,11 @@ static int up_setup(struct uart_dev_s *dev)
|
||||
/* Set up the cached interrupt enables value */
|
||||
|
||||
priv->ie = 0;
|
||||
|
||||
/* Mark device as initialized. */
|
||||
|
||||
priv->initialized = true;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@ -1539,6 +1548,10 @@ static void up_shutdown(struct uart_dev_s *dev)
|
||||
struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
|
||||
uint32_t regval;
|
||||
|
||||
/* Mark device as uninitialized. */
|
||||
|
||||
priv->initialized = false;
|
||||
|
||||
/* Disable all interrupts */
|
||||
|
||||
up_disableusartint(priv, NULL);
|
||||
@ -2529,6 +2542,31 @@ static int up_pm_prepare(struct pm_callback_s *cb, int domain,
|
||||
|
||||
#ifdef USE_SERIALDRIVER
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_serial_get_uart
|
||||
*
|
||||
* Description:
|
||||
* Get serial driver structure for STM32 USART
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR uart_dev_t *stm32_serial_get_uart(int uart_num)
|
||||
{
|
||||
int uart_idx = uart_num - 1;
|
||||
|
||||
if (uart_idx < 0 || uart_idx >= STM32_NSERIAL || !uart_devs[uart_idx])
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!uart_devs[uart_idx]->initialized)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &uart_devs[uart_idx]->dev;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_earlyserialinit
|
||||
*
|
||||
|
@ -41,6 +41,7 @@
|
||||
************************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/serial/serial.h>
|
||||
|
||||
#include "chip/stm32_uart.h"
|
||||
|
||||
@ -319,6 +320,16 @@ extern "C"
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_serial_get_uart
|
||||
*
|
||||
* Description:
|
||||
* Get serial driver structure for STM32 USART
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
FAR uart_dev_t *stm32_serial_get_uart(int uart_num);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_serial_dma_poll
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user