rt-thread/bsp/essemi/es8p508x/libraries/Library/Include/lib_uart.h

172 lines
5.4 KiB
C
Raw Normal View History

2019-11-07 10:00:14 +08:00
/***************************************************************
*Copyright (C), 2017, Shanghai Eastsoft Microelectronics Co., Ltd.
*<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lib_uart.h
*<EFBFBD><EFBFBD> <EFBFBD>ߣ<EFBFBD> Liut
*<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> V1.00
*<EFBFBD><EFBFBD> <EFBFBD>ڣ<EFBFBD> 2017/07/14
*<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> UARTģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
*<EFBFBD><EFBFBD> ע<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ES8P508xоƬ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧϰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾʹ<EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><EFBFBD>ջ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>κη<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ρ<EFBFBD>
***************************************************************/
#ifndef __LIBUART_H__
#define __LIBUART_H__
#include "ES8P508x.h"
#include "type.h"
#include "system_ES8P508x.h"
/* <20><><EFBFBD><EFBFBD>ֹ֡ͣλѡ<CEBB><D1A1> */
typedef enum
{
UART_StopBits_1 = 0x0 , //<2F><><EFBFBD><EFBFBD>ֹ֡ͣλ<D6B9><CEBB>
UART_StopBits_2 = 0x1 , //<2F><><EFBFBD><EFBFBD>ֹ֡ͣλ<D6B9><CEBB>
}UART_TYPE_TXFS;
/* <20><><EFBFBD>ݸ<EFBFBD>ʽ */
typedef enum
{
UART_DataMode_7 = 0x0 , //<2F><><EFBFBD>ݸ<EFBFBD>ʽ:7λ<37><CEBB><EFBFBD><EFBFBD>
UART_DataMode_8 = 0x1 , //<2F><><EFBFBD>ݸ<EFBFBD>ʽ:8λ<38><CEBB><EFBFBD><EFBFBD>
UART_DataMode_9 = 0x2 , //<2F><><EFBFBD>ݸ<EFBFBD>ʽ:9λ<39><CEBB><EFBFBD><EFBFBD>
UART_DataMode_7Odd = 0x4 , //<2F><><EFBFBD>ݸ<EFBFBD>ʽ:7λ<37><CEBB><EFBFBD><EFBFBD>+<2B><>У<EFBFBD><D0A3>
UART_DataMode_7Even = 0x5 , //<2F><><EFBFBD>ݸ<EFBFBD>ʽ:7λ<37><CEBB><EFBFBD><EFBFBD>У<C5BC><D0A3>
UART_DataMode_8Odd = 0x6 , //<2F><><EFBFBD>ݸ<EFBFBD>ʽ:8λ<38><CEBB><EFBFBD><EFBFBD>+<2B><>У<EFBFBD><D0A3>
UART_DataMode_8Even = 0x7 , //<2F><><EFBFBD>ݸ<EFBFBD>ʽ:8λ<38><CEBB><EFBFBD><EFBFBD>У<C5BC><D0A3>
}UART_TYPE_DATAMOD;
/* <20>˿ڼ<CBBF><DABC><EFBFBD> */
typedef enum
{
UART_Polar_Normal = 0x0 , //<2F><><EFBFBD>Ͷ˿ڼ<CBBF><DABC><EFBFBD>:<3A><><EFBFBD><EFBFBD>
UART_Polar_Opposite = 0x1 , //<2F><><EFBFBD>Ͷ˿ڼ<CBBF><DABC><EFBFBD>:<3A><><EFBFBD><EFBFBD>
}UART_TYPE_RTXP;
/* <20><><EFBFBD><EFBFBD><EFBFBD>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ѡ<EFBFBD><D1A1> */
typedef enum
{
UART_Clock_1 = 0x1 , //<2F><><EFBFBD><EFBFBD><EFBFBD>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>:PCLK
UART_Clock_2 = 0x2 , //<2F><><EFBFBD><EFBFBD><EFBFBD>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>:PCLK/2
UART_Clock_4 = 0x3 , //<2F><><EFBFBD><EFBFBD><EFBFBD>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>:PCLK/4
UART_Clock_8 = 0x4 , //<2F><><EFBFBD><EFBFBD><EFBFBD>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>:PCLK/8
}UART_TYPE_BCS;
/* UART<52><54>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ýṹ<C3BD><EFBFBD><E5B6A8> */
typedef struct
{
UART_TYPE_TXFS UART_StopBits; //<2F><><EFBFBD><EFBFBD>ֹ֡ͣλѡ<CEBB><D1A1>
UART_TYPE_DATAMOD UART_TxMode; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>ʽ
UART_TYPE_RTXP UART_TxPolar; //<2F><><EFBFBD>Ͷ˿ڼ<CBBF><DABC><EFBFBD>
UART_TYPE_DATAMOD UART_RxMode; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>ʽ
UART_TYPE_RTXP UART_RxPolar; //<2F><><EFBFBD>ն˿ڼ<CBBF><DABC><EFBFBD>
uint32_t UART_BaudRate; //<2F><><EFBFBD><EFBFBD><E4B2A8><EFBFBD><EFBFBD>
UART_TYPE_BCS UART_ClockSet; //<2F><><EFBFBD><EFBFBD><EFBFBD>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ѡ<EFBFBD><D1A1>
}UART_InitStruType;
/* <20>ж<EFBFBD>ѡ<EFBFBD><D1A1> */
typedef enum
{
UART_IT_TB = 0x0001 ,
UART_IT_RB = 0x0002 ,
UART_IT_RO = 0x0004 ,
UART_IT_FE = 0x0008 ,
UART_IT_PE = 0x0010 ,
UART_IT_TBWE = 0x0020 ,
UART_IT_TXIDLE = 0x1000 ,
UART_IT_RXIDLE = 0x2000 ,
}UART_TYPE_IT;
/* <20><>־λ */
typedef enum
{
UART_FLAG_TB = 0x0001 ,
UART_FLAG_RB = 0x0002 ,
UART_FLAG_RO = 0x0004 ,
UART_FLAG_FE = 0x0008 ,
UART_FLAG_PE = 0x0010 ,
UART_FLAG_TBWE = 0x0020 ,
UART_FLAG_TXIDLE = 0x1000 ,
UART_FLAG_RXIDLE = 0x2000 ,
}UART_TYPE_FLAG;
/* <20><><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־λ */
typedef enum
{
UART_Clr_RO = 0x0004 ,
UART_Clr_FE = 0x0008 ,
UART_Clr_PE = 0x0010 ,
UART_Clr_TBWE = 0x0020 ,
}UART_CLR_IF;
/* <20><><EFBFBD>͡<EFBFBD><CDA1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ģʽ */
typedef enum
{
UART_TRBIM_Byte = 0x0 , //<2F>ж<EFBFBD>:<3A>ֽ<EFBFBD>
UART_TRBIM_HalfWord = 0x1 , //<2F>ж<EFBFBD>:<3A><><EFBFBD><EFBFBD>
UART_TRBIM_Word = 0x2 , //<2F>ж<EFBFBD>:<3A><>
}UART_TYPE_TRBIM;
/*************UARTģ<54><C4A3><EFBFBD><EFBFBD><EAB6A8>************/
/* <20><><EFBFBD><EFBFBD>ʹ<EFBFBD>ܿ<EFBFBD><DCBF><EFBFBD> */
#define UART0_TxEnable() (UART0->CON.TXEN = 1)
#define UART1_TxEnable() (UART1->CON.TXEN = 1)
#define UART2_TxEnable() (UART2->CON.TXEN = 1)
#define UART3_TxEnable() (UART3->CON.TXEN = 1)
#define UART4_TxEnable() (UART4->CON.TXEN = 1)
#define UART5_TxEnable() (UART5->CON.TXEN = 1)
#define UART0_TxDisable() (UART0->CON.TXEN = 0)
#define UART1_TxDisable() (UART1->CON.TXEN = 0)
#define UART2_TxDisable() (UART2->CON.TXEN = 0)
#define UART3_TxDisable() (UART3->CON.TXEN = 0)
#define UART4_TxDisable() (UART4->CON.TXEN = 0)
#define UART5_TxDisable() (UART5->CON.TXEN = 0)
/* <20><><EFBFBD><EFBFBD>ʹ<EFBFBD>ܿ<EFBFBD><DCBF><EFBFBD> */
#define UART0_RxEnable() (UART0->CON.RXEN = 1)
#define UART1_RxEnable() (UART1->CON.RXEN = 1)
#define UART2_RxEnable() (UART2->CON.RXEN = 1)
#define UART3_RxEnable() (UART3->CON.RXEN = 1)
#define UART4_RxEnable() (UART4->CON.RXEN = 1)
#define UART5_RxEnable() (UART5->CON.RXEN = 1)
#define UART0_RxDisable() (UART0->CON.RXEN = 0)
#define UART1_RxDisable() (UART1->CON.RXEN = 0)
#define UART2_RxDisable() (UART2->CON.RXEN = 0)
#define UART3_RxDisable() (UART3->CON.RXEN = 0)
#define UART4_RxDisable() (UART4->CON.RXEN = 0)
#define UART5_RxDisable() (UART5->CON.RXEN = 0)
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ */
#define UART0_TxRst() (UART0->CON.TRST = 1)
#define UART1_TxRst() (UART1->CON.TRST = 1)
#define UART2_TxRst() (UART2->CON.TRST = 1)
#define UART3_TxRst() (UART3->CON.TRST = 1)
#define UART4_TxRst() (UART4->CON.TRST = 1)
#define UART5_TxRst() (UART5->CON.TRST = 1)
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ */
#define UART0_RxRst() (UART0->CON.RRST = 1)
#define UART1_RxRst() (UART1->CON.RRST = 1)
#define UART2_RxRst() (UART2->CON.RRST = 1)
#define UART3_RxRst() (UART3->CON.RRST = 1)
#define UART4_RxRst() (UART4->CON.RRST = 1)
#define UART5_RxRst() (UART5->CON.RRST = 1)
/************UARTģ<54><EFBFBD><E9BAAF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>***********/
void UART_Init(UART_TypeDef* UARTx,UART_InitStruType* UART_InitStruct);
void UART_ITConfig(UART_TypeDef* UARTx,UART_TYPE_IT UART_IT,TYPE_FUNCEN NewState);
void UART_TBIMConfig(UART_TypeDef* UARTx,UART_TYPE_TRBIM Type);
void UART_RBIMConfig(UART_TypeDef* UARTx,UART_TYPE_TRBIM Type);
void UART_SendByte(UART_TypeDef* UARTx,uint8_t Temp08);
void UART_SendHalfWord(UART_TypeDef* UARTx,uint16_t Temp16);
void UART_SendWord(UART_TypeDef* UARTx,uint32_t Temp32);
uint8_t UART_RecByte(UART_TypeDef* UARTx);
uint16_t UART_RecHalfWord(UART_TypeDef* UARTx);
uint32_t UART_RecWord(UART_TypeDef* UARTx);
FlagStatus UART_GetFlagStatus(UART_TypeDef* UARTx,UART_TYPE_FLAG UART_Flag);
ITStatus UART_GetITStatus(UART_TypeDef* UARTx,UART_TYPE_IT UART_Flag);
void UART_ClearITPendingBit(UART_TypeDef* UARTx,UART_CLR_IF UART_Flag);
#endif
/*************************END OF FILE**********************/