⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lpc_uart.h

📁 给大家提供一个在inram/exram中调试的示例,在周公的lpc2200上调试过.
💻 H
字号:
#ifndef __LPC_UART_H
#define __LPC_UART_H

/***********************************************************************
 *         BU MMS China, Philips Semiconductor Software Support
 *         Embest info&Tech Co. Software Support
 *---------------------------------------------------------------------------
 * The software is delivered "AS IS" without warranty or condition of any
 * kind, either express, implied or statutory.  Everybody can use it as 
 * it is opened and without copyright. We will not take any law responsibility
 * for any problem produced by using this software.
 *---------------------------------------------------------------------------                                                          
 *    File name: 	LPC_Uart.h                                                          
 *    Description: 	Define Uart structure and relative micro
 *                                                                                      
 *    History:                                                                     
 *    1. Date: 		Jul 13, 2004                                              
 *       Author: 	Shawn Zhang                                                    
 *       Description: Create  
 *
 *	$Revision: 1.0$
 **********************************************************************/

#include "LPC_Base.h"
#include "LPC_Type.h"

#include "LPC_SysControl.h"

/* The micro are configurable */
#define UART_RXBUFSIZE    64
#define UART_TXBUFSIZE    128

#define FIFODEEP    16

#define BD115200     115200
#define BD38400     38400
#define BD9600    9600

#define CR     0x0D
#define LF     0x0A

/* Uart line control register bit descriptions */
#define LCR_WORDLENTH_BIT         0
#define LCR_STOPBITSEL_BIT         2
#define LCR_PARITYENBALE_BIT         3
#define LCR_PARITYSEL_BIT         4
#define LCR_BREAKCONTROL_BIT         6
#define LCR_DLAB_BIT         7

/* Uart line status register bit descriptions */
#define LSR_RDR_BIT         0
#define LSR_OE_BIT         1
#define LSR_PE_BIT         2
#define LSR_FE_BIT         3
#define LSR_BI_BIT         4
#define LSR_THRE_BIT         5
#define LSR_TEMT_BIT         6
#define LSR_RXFE_BIT         7

/* Uart Interrupt Identification */
#define IIR_RSL         0x3
#define IIR_RDA        0x2
#define IIR_CTI         0x6
#define IIR_THRE      0x1

/* Uart Interrupt Enable Type*/
#define IER_RBR         0x1
#define IER_THRE       0x2
#define IER_RLS        0x4

/* Uart Receiver Errors */
#define RC_FIFO_OVERRUN_ERR       0x1
#define RC_OVERRUN_ERR            0x2
#define RC_PARITY_ERR             0x4
#define RC_FRAMING_ERR            0x8
#define RC_BREAK_IND              0x10

/* Device number */
typedef enum {
  UART0 = 0,
  UART1
} LPC_Uart_Channel_t;

/* Word Lenth type */
typedef enum {
    WordLength5 = 0,
    WordLength6,
    WordLength7,
    WordLength8
} LPC_Uart_WordLenth_t;

/* Parity Select type */
typedef enum {
    ParitySelOdd = 0,
    ParitySelEven,
    ParitySelStickHigh,
    ParitySelEvenLow
} LPC_Uart_ParitySelect_t;

 /* FIFO Rx Trigger Level type */
typedef enum {
    FIFORXLEV0 = 0,	// 0x1
    FIFORXLEV1,		// 0x4
    FIFORXLEV2,		// 0x8
    FIFORXLEV3		// 0xe
} LPC_Uart_FIFORxTriggerLevel_t;

typedef struct {
	char RxBuf[UART_RXBUFSIZE];
	char TxBuf[UART_TXBUFSIZE];
	
	int RxHeadPoint;
	int RxTailPoint;
	
	int TxHeadPoint;
	int TxTailPoint;
	
	int RxCount;
	volatile int TxCount;

	volatile int RxFlag;
}LPC_Uart_Buffer_t;

typedef struct {
	unsigned long BaudRate;	// Baud Rate
	
	LPC_Uart_WordLenth_t WordLenth;	// Frame format
	bool TwoStopBitsSelect;
	bool ParityEnable;
	LPC_Uart_ParitySelect_t ParitySelect;
	bool BreakEnable;

	bool FIFOEnable;
	int FIFORxTriggerLevel;

	bool IntEnable;
	unsigned long IntType;	// Interrupt Type: RBR, THRE, RLS

	LPC_Uart_Buffer_t  UartBuffer;
	
} LPC_Uart_Config_t;

/* Declare functions */
int UART_PutStringByPolling(LPC_Uart_Channel_t DevNum, char *Buf);

int UART_Init (LPC_Uart_Channel_t DevNum, unsigned long BaudRate, 
		LPC_Uart_WordLenth_t WordLenth, bool TwoStopBitsSelect, 
		bool ParityEnable, LPC_Uart_ParitySelect_t ParitySelect, 
		bool BreakEnable, bool FIFOEnable, LPC_Uart_FIFORxTriggerLevel_t FIFORxTriggerLevel,
		bool IntEnable, unsigned long IntType);

int UART_PutString(LPC_Uart_Channel_t DevNum, char *Buf);
char UART_GetChar(LPC_Uart_Channel_t DevNum);

__irq void UART0_ISR (void);
void UART1_ISR (void);

extern UART0_VectISR (void);
extern UART1_VectISR (void);

#endif //__LPC_UART_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -