📄 uart.h
字号:
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : uart.h
* Author : MCD Application Team
* Date First Issued : 16/05/2003
* Description : This file contains all the functions prototypes for the
* UART software library.
********************************************************************************
* History:
* 16/05/2003 : Created
*******************************************************************************/
#ifndef _UART_H
#define _UART_H
#include "71x_lib.h"
#ifndef _RCCU
#error _RCCU must be defined
#endif
#ifdef DEBUG
#ifndef _PCU
#error _PCU must be defined
#endif
#endif /* DEBUG */
typedef enum
{
UART_RxFIFO,
UART_TxFIFO
} UARTFIFO_TypeDef;
typedef enum
{
UART_EVEN_PARITY = 0x0000,
UART_ODD_PARITY = 0x0020,
UART_NO_PARITY
} UARTParity_TypeDef;
typedef enum
{
UART_0_5_StopBits = 0x00,
UART_1_StopBits = 0x08,
UART_1_5_StopBits = 0x10,
UART_2_StopBits = 0x18
} UARTStopBits_TypeDef;
typedef enum
{
UARTM_8D = 0x01,
UARTM_7D_P = 0x03,
UARTM_9D = 0x04,
UARTM_8D_W = 0x05,
UARTM_8D_P = 0x07
} UARTMode_TypeDef;
#define DUMMY 0
// UART flags definition
#define UART_TxFull 0x0200
#define UART_RxHalfFull 0x0100
#define UART_TimeOutIdle 0x0080
#define UART_TimeOutNotEmpty 0x0040
#define UART_OverrunError 0x0020
#define UART_FrameError 0x0010
#define UART_ParityError 0x0008
#define UART_TxHalfEmpty 0x0004
#define UART_TxEmpty 0x0002
#define UART_RxBufFull 0x0001
// CR regiter bit definition
#define UART_FIFOEnableBit 10
#define UART_RxEnableBit 8
#define UART_RunBit 7
#define UART_LoopBackBit 6
#define UART_ParityOddBit 5
#define UART_StopBits 3
// Stop bits definition
#define UART_05StopBits 0x00
#define UART_1StopBit (0x01<<3)
#define UART_15StopBits (0x02<<3)
#define UART_2StopBits (0x03<<3)
// Modes definition
#define UART_8BitsData 0x01
#define UART_7BitsData 0x03
#define UART_9BitsData 0x04
#define UART_8BitsDataWakeUp 0x05
#define UART_8BitsDataParity 0x07
/*******************************************************************************
* Function Name : UART_Init
* Description : This function initializes the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Output : None
* Return : None
*******************************************************************************/
void UART_Init(UART_TypeDef *UARTx);
/*******************************************************************************
* Function Name : UART_ModeConfig
* Description : This function configures the mode of the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : The UART mode
* Output : None
* Return : None
*******************************************************************************/
inline void UART_ModeConfig(UART_TypeDef *UARTx, UARTMode_TypeDef UART_Mode)
{
UARTx->CR = (UARTx->CR&0xFFF8)|(u16)UART_Mode;
}
/*******************************************************************************
* Function Name : UART_BaudRateConfig
* Description : This function configures the baud rate of the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : The baudrate value
* Output : None
* Return : None
*******************************************************************************/
void UART_BaudRateConfig(UART_TypeDef *UARTx, u32 BaudRate);
/*******************************************************************************
* Function Name : UART_ParityConfig
* Description : This function configures the data parity of the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : The parity type
* Output : None
* Return : None
*******************************************************************************/
inline void UART_ParityConfig(UART_TypeDef *UARTx, UARTParity_TypeDef Parity)
{
UARTx->CR = (UARTx->CR&0xFFDF)|(u16)Parity;
}
/*******************************************************************************
* Function Name : UART_StopBitsConfig
* Description : This function configures the number of stop bits of the
* selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : The number of stop bits
* Output : None
* Return : None
*******************************************************************************/
inline void UART_StopBitsConfig(UART_TypeDef *UARTx, UARTStopBits_TypeDef StopBits)
{
UARTx->CR = (UARTx->CR&0xFFE7)|(u16)StopBits;
}
/*******************************************************************************
* Function Name : UART_Config
* Description : This function configures the baudrate, the mode, the data
* parity and the number of stop bits of the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : The baudrate value
* Input 3 : The parity type
* Input 4 : The number of stop bits
* Input 5 : The UART mode
* Output : None
* Return : None
*******************************************************************************/
void UART_Config(UART_TypeDef *UARTx, u32 BaudRate, UARTParity_TypeDef Parity,
UARTStopBits_TypeDef StopBits, UARTMode_TypeDef Mode);
/*******************************************************************************
* Function Name : UART_ItConfig
* Description : This function enables or disables the interrupts of the
* selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : The new interrupt flag
* Input 3 : ENABLE or DISABLE
* Output : None
* Return : None
*******************************************************************************/
void UART_ItConfig(UART_TypeDef *UARTx, u16 UART_Flag, functionalstate NewStatus);
/*******************************************************************************
* Function Name : UART_FifoConfig
* Description : This function enables or disables the Rx and Tx FIFOs of
* the selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : ENABLE or DISABLE
* Output : None
* Return : None
*******************************************************************************/
void UART_FifoConfig(UART_TypeDef *UARTx, functionalstate NewStatus);
/*******************************************************************************
* Function Name : UART_FifoReset
* Description : This function resets the Rx and the Tx FIFOs of the
* selected UART.
* Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
* Input 2 : RxFIFO or TxFIFO
* Output : None
* Return : None
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -