uart.h
来自「嵌入式系统」· C头文件 代码 · 共 849 行 · 第 1/3 页
H
849 行
/*-----------------------------------------------------------------------------
@@
@@ (Summary) : LH7953x series UART Device Driver Header File
@@ (Comment) : UART Header File
@@ (Author) : Leow Yee Ling
@@ (RCS ID) :
@@
-----------------------------------------------------------------------------*/
#ifndef APD_UART_H
#define APD_UART_H
/*+include files*************************************************************/
/* */
/* */
/****************************************************************************/
#include "type_def.h"
#include "dev_def.h"
#include "uart_sys_def.h"
#include "uart_def.h"
/*+Public Macro definitions**************************************************/
/* */
/* */
/****************************************************************************/
/*+Public Type definitions***************************************************/
/* */
/* */
/****************************************************************************/
/* UART Interrupt Register Bit Definitions */
#define APD_UARTINT_UDINT 0x01
#define APD_UARTINT_MSINT 0x02
#define APD_UARTINT_TXINT 0x04
#define APD_UARTINT_RXINT 0x08
#define APD_UARTINT_ERRINT 0x10
/* UART Flag Register Bit Definitions */
#define APD_UARTFLG_RI 0x40
#define APD_UARTFLG_UTXFF 0x20
#define APD_UARTFLG_URXFE 0x10
#define APD_UARTFLG_UBUSY 0x08
#define APD_UARTFLG_DCD 0x04
#define APD_UARTFLG_DSR 0x02
#define APD_UARTFLG_CTS 0x01
/*----------------------------------------------------------------------------
@@ {Name} : APD_UART_NUM_TYPE
@@
@@ {Summary}: Indicate APD_UART Channel
@@
@@ {Desc} : Use to set UART Channel type as a constant
@@
@@ {End} :
-----------------------------------------------------------------------------*/
typedef enum {
APD_UART_CH1 = 1, /* UART Channel 1 */
APD_UART_CH0 = 0 /* UART Channel 0 */
} APD_UART_NUM_TYPE;
/*-----------------------------------------------------------------------------
@@ {Name} : APD_UART_DATAXFER_TYPE
@@
@@ {Summary}: Data transfer settings
@@
@@ {Desc} : Set the transfer type according to the length of words, stop bit
@@ and parity type.
@@
@@ {Comment}: 5W/6W/7W/8W refers to number of words
@@ NOXSTOP/1XSTOP refers whether extra stop bit is inserted
@@ NOPARITY/ODDPARITY/EVENPARITY refers to the parity setting
@@
@@ {End} :
-----------------------------------------------------------------------------*/
typedef enum {
APD_UART_5W_NOXSTOP_NOPARITY = 0x00, /* 5 words, 1 stop, no parity */
APD_UART_5W_1XSTOP_NOPARITY = 0x08, /* 5 words, 2 stop, no parity */
APD_UART_5W_NOXSTOP_ODDPARITY = 0x02, /* 5 words, 1 stop, odd parity */
APD_UART_5W_1XSTOP_ODDPARITY = 0x0A, /* 5 words, 2 stop, odd parity */
APD_UART_5W_NOXSTOP_EVENPARITY = 0x06, /* 5 words, 1 stop, even parity */
APD_UART_5W_1XSTOP_EVENPARITY = 0x0E, /* 5 words, 2 stop, even parity */
APD_UART_6W_NOXSTOP_NOPARITY = 0x20, /* 6 words, 1 stop, no parity */
APD_UART_6W_1XSTOP_NOPARITY = 0x28, /* 6 words, 2 stop, no parity */
APD_UART_6W_NOXSTOP_ODDPARITY = 0x22, /* 6 words, 1 stop, odd parity */
APD_UART_6W_1XSTOP_ODDPARITY = 0x2A, /* 6 words, 2 stop, odd parity */
APD_UART_6W_NOXSTOP_EVENPARITY = 0x26, /* 6 words, 1 stop, even parity */
APD_UART_6W_1XSTOP_EVENPARITY = 0x2E, /* 6 words, 2 stop, even parity */
APD_UART_7W_NOXSTOP_NOPARITY = 0x40, /* 7 words, 1 stop, no parity */
APD_UART_7W_1XSTOP_NOPARITY = 0x48, /* 7 words, 2 stop, no parity */
APD_UART_7W_NOXSTOP_ODDPARITY = 0x42, /* 7 words, 1 stop, odd parity */
APD_UART_7W_1XSTOP_ODDPARITY = 0x4A, /* 7 words, 2 stop, odd parity */
APD_UART_7W_NOXSTOP_EVENPARITY = 0x46, /* 7 words, 1 stop, even parity */
APD_UART_7W_1XSTOP_EVENPARITY = 0x4E, /* 7 words, 2 stop, even parity */
APD_UART_8W_NOXSTOP_NOPARITY = 0x60, /* 8 words, 1 stop, no parity */
APD_UART_8W_1XSTOP_NOPARITY = 0x68, /* 8 words, 2 stop, no parity */
APD_UART_8W_NOXSTOP_ODDPARITY = 0x62, /* 8 words, 1 stop, odd parity */
APD_UART_8W_1XSTOP_ODDPARITY = 0x6A, /* 8 words, 2 stop, odd parity */
APD_UART_8W_NOXSTOP_EVENPARITY = 0x66, /* 8 words, 1 stop, even parity */
APD_UART_8W_1XSTOP_EVENPARITY = 0x6E /* 8 words, 2 stop, even parity */
} APD_UART_DATAXFER_TYPE;
/*-----------------------------------------------------------------------------
@@ {Name} : APD_UART_INIT_TYPE
@@
@@ {Summary}: The setting of UART initialize bits.
@@
@@ {Desc} : A structure defining how each UART should be initialized to
@@ rate - baud rate eg 9600
@@ format - data transfer format
@@ intmask - interrupt mask register setting
@@
@@ {End} :
-----------------------------------------------------------------------------*/
typedef struct {
APD_USHORT rate; /* baud rate */
APD_UART_DATAXFER_TYPE format; /* data xfer format */
unsigned char intmask;/* interrupt mask */
} APD_UART_INIT_TYPE;
#ifdef APD_UART_C
/*-------------------------- Local context - START -------------------------*/
/*+include files*************************************************************/
/* */
/* */
/**************************************************************************-*/
#define VISIBLE /* Mark as LOCAL context */
/*+Local Type definitions****************************************************/
/* */
/* */
/**************************************************************************-*/
/*+Local Macro definitions***************************************************/
/* */
/* */
/****************************************************************************/
/*+Local function prototypes*************************************************/
/* */
/* Name Type Abstract */
/* ---- ---- -------- */
/* */
/**************************************************************************-*/
/*+Local data declarations***************************************************/
/* */
/* Name Description */
/* ---- ----------- */
/****************************************************************************/
VISIBLE APD_ULONG APD_UARTCLKDIV[2] = {APD_UART_CLK0, APD_UART_CLK1};
/*-------------------------- Local context - END ---------------------------*/
#else
#define VISIBLE extern /* Mark as GLOBAL context */
#endif
/*------------------------- Global context - START -------------------------*/
/*+Public data declarations**************************************************/
/* */
/* Name Description */
/* -------- --------------- */
/****************************************************************************/
/*+Public function prototypes************************************************/
/* */
/* Name Type Abstract */
/* --------- ------- ----------- */
/* */
/****************************************************************************/
VISIBLE void apd_UARTInit(APD_UART_NUM_TYPE uart_num, APD_UART_INIT_TYPE uart_init);
VISIBLE void apd_UARTSetBaudRate(APD_UART_NUM_TYPE uart_num, APD_ULONG brate);
VISIBLE void apd_UARTSetDataXferType(APD_UART_NUM_TYPE uart_num, APD_UART_DATAXFER_TYPE dxtype);
VISIBLE APD_BOOLEAN apd_UARTIsBitSetInFlag(APD_UART_NUM_TYPE uart_num, unsigned char bdata);
VISIBLE APD_BOOLEAN apd_UARTIsBitSetInIntr(APD_UART_NUM_TYPE uart_num, unsigned char bdata);
VISIBLE void apd_UARTDisable(APD_UART_NUM_TYPE uart_num);
VISIBLE void apd_UARTEnable(APD_UART_NUM_TYPE uart_num);
VISIBLE unsigned char apd_UARTGetRxData(APD_UART_NUM_TYPE uart_num);
VISIBLE void apd_UARTSetTxData(APD_UART_NUM_TYPE uart_num, unsigned char txdata);
VISIBLE void apd_UARTClrModemStatusChangeIntr(APD_UART_NUM_TYPE uart_num);
VISIBLE void apd_UARTSetHiLineCtrlReg(APD_UART_NUM_TYPE uart_num, unsigned char bdata);
VISIBLE void apd_UARTClrHiLineCtrlReg(APD_UART_NUM_TYPE uart_num, unsigned char bdata);
VISIBLE void apd_UARTSetModemCtrlReg(APD_UART_NUM_TYPE uart_num, unsigned char bdata);
VISIBLE void apd_UARTClrModemCtrlReg(APD_UART_NUM_TYPE uart_num, unsigned char bdata);
VISIBLE void apd_UARTSetIntrReg(APD_UART_NUM_TYPE uart_num, unsigned char bdata);
VISIBLE void apd_UARTClrIntrReg(APD_UART_NUM_TYPE uart_num, unsigned char bdata);
VISIBLE unsigned char apd_UARTReadFLG (APD_UART_NUM_TYPE uart_num);
VISIBLE unsigned char apd_UARTReadIntr (APD_UART_NUM_TYPE uart_num);
VISIBLE unsigned char apd_UARTReadRxStatus(APD_UART_NUM_TYPE uart_num);
VISIBLE void apd_UARTSIRDisable(APD_UART_NUM_TYPE uart_num);
VISIBLE void apd_UARTSIREnable(APD_UART_NUM_TYPE uart_num);
VISIBLE void apd_UARTSetIRTXM(APD_UART_NUM_TYPE uart_num);
VISIBLE void apd_UARTClearIRTXM(APD_UART_NUM_TYPE uart_num);
VISIBLE void apd_UARTSetSIRPOL(APD_UART_NUM_TYPE uart_num);
VISIBLE void apd_UARTClearSIRPOL(APD_UART_NUM_TYPE uart_num);
VISIBLE void apd_UARTERINTDisable(APD_UART_NUM_TYPE uart_num);
VISIBLE void apd_UARTERINTEnable(APD_UART_NUM_TYPE uart_num);
VISIBLE void apd_SIOWrite(APD_UART_NUM_TYPE uart_num,unsigned char txdata);
VISIBLE unsigned char apd_SIORead(APD_UART_NUM_TYPE uart_num);
VISIBLE void apd_SIOClose(APD_UART_NUM_TYPE uart_num,unsigned long interrupt_src);
VISIBLE void apd_SIOOpen(APD_UART_NUM_TYPE uart_num,unsigned long interrupt_src);
/******************************************************************************
@@
@@ [Name] : apd_UARTDisableFIFO
@@
@@ [Summary] : This function disables FIFO buffering of receive and transmit data
@@
@@ [Argument] : uart_num: Specify the UART channel number
@@ APD_UART_CH0 for channel 0
@@ APD_UART_CH1 for channel 1
@@
@@ [Return] : None
@@
@@ [Desc] : Disables FIFO buffering for given UART channel
@@
@@ [END]
******************************************************************************/
#define apd_UARTDisableFIFO(uart_num) \
apd_UARTClrHiLineCtrlReg(uart_num, APD_UARTHUBRLCR_UFIFOEN)
/******************************************************************************
@@
@@ [Name] : apd_UARTEnableFIFO
@@
@@ [Summary] : This function enables FIFO buffering of receive and transmit data
@@
@@ [Argument] : uart_num: Specify the UART channel number
@@ APD_UART_CH0 for channel 0
@@ APD_UART_CH1 for channel 1
@@
@@ [Return] : None
@@
@@ [Desc] : Enables FIFO buffering for given UART channel
@@
@@ [END]
******************************************************************************/
#define apd_UARTEnableFIFO(uart_num) \
apd_UARTSetHiLineCtrlReg(uart_num, APD_UARTHUBRLCR_UFIFOEN)
/******************************************************************************
@@
@@ [Name] : apd_UARTGenerateBreak
@@
@@ [Summary] : This function generates a break for the selected UART channel
@@
@@ [Argument] : uart_num: Specify the UART channel number
@@ APD_UART_CH0 for channel 0
@@ APD_UART_CH1 for channel 1
@@
@@ [Return] : None
@@
@@ [Desc] : Generate a break for the selected UART channel. Tx output driven high.
@@
@@ [END]
******************************************************************************/
#define apd_UARTGenerateBreak(uart_num) \
apd_UARTSetHiLineCtrlReg(uart_num, APD_UARTHUBRLCR_BREAK)
/******************************************************************************
@@
@@ [Name] : apd_UARTStopBreak
@@
@@ [Summary] : This function stops the generation of break
@@
@@ [Argument] : uart_num: Specify the UART channel number
@@ APD_UART_CH0 for channel 0
@@ APD_UART_CH1 for channel 1
@@
@@ [Return] : None
@@
@@ [Desc] : Stops the generation of break for the selected UART channel
@@
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?