?? uart0.c
字號:
/****************************************Copyright (c)**************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http://www.embedtools.com
**
**--------------File Info-------------------------------------------------------------------------------
** File Name: Uart0.c
** Last modified Date: 2006-11-18
** Last Version: v1.0
** Description: 串口驅(qū)動(dòng)源文件
**
**------------------------------------------------------------------------------------------------------
** Created By: Zhou Shaogang
** Created date: 2006-11-18
** Version: v1.0
** Descriptions:
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Description:
**
********************************************************************************************************/
#include "../config.h"
uint8 Uart0_Rec_Queue[UART0_REC_QUEUE_LEN];
/************************************************************************************
** Function name: Uart0Init
** Descriptions: 初始化Uart0
** Input: BaudRate: 波特率
** Prio: 中斷優(yōu)先級
** Output: TRUE :成功
** FALSE:失敗
** Created by: Zhou Shaogang
** Created Date: 2006-11-18
**----------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**----------------------------------------------------------------------------------
************************************************************************************/
uint8 Uart0Init(uint32 BaudRate, uint8 Prio)
{
if(BaudRate>115200) //波特率太高,錯(cuò)誤返回
return(FALSE);
if (QueueCreate(Uart0_Rec_Queue, //初且化接收隊(duì)列失敗,錯(cuò)誤返回
UART0_REC_QUEUE_LEN,
0,
0)==NOT_OK)
return(FALSE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); //使能串口0外圍設(shè)備
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); //使能GPIOA
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); //設(shè)置PA0,PA1為RXD0,TXD0
UARTConfigSet(UART0_BASE, BaudRate, (UART_CONFIG_WLEN_8 | //配置串口0,8位數(shù)據(jù),1位起始位,1位停止位,用戶波特率
UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE) & 0xFFFFFFEF);
UARTFifoLevelSet(UART0_BASE, 8, 8);
IntEnable(INT_UART0); //使能串口0系統(tǒng)中斷
UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); //使能串口0接收中斷和接收超時(shí)中斷
IntPrioritySet(INT_UART0, Prio); //設(shè)置中斷優(yōu)先級
UARTEnable(UART0_BASE);
return(TRUE);
}
/************************************************************************************
** Function name: Uart0Send
** Descriptions: 發(fā)送多個(gè)字節(jié)數(shù)據(jù)
** Input: Buffer:發(fā)送數(shù)據(jù)存儲(chǔ)位置
** NByte:發(fā)送數(shù)據(jù)個(gè)數(shù)
** Output: 無
** Created by: Zhou Shaogang
** Created Date: 2006-11-18
**----------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**----------------------------------------------------------------------------------
************************************************************************************/
void Uart0Send(uint8 *Buffer, uint16 NByte)
{
while(NByte)
{
if( UARTSpaceAvail(UART0_BASE) )
{
UARTCharNonBlockingPut(UART0_BASE, *Buffer++);
NByte--;
}
}
while( !UARTTraFifoEmp(UART0_BASE) );
}
/*********************************************************************************************************
** 函數(shù)名稱: UART0_ISR
** 功能描述: 串口0中斷服務(wù)函數(shù)
** 輸 入: 無
** 輸 出: 無
** 全局變量: Uart0_Rec_Queue
** 調(diào)用模塊: QueueWrite
**
** 作 者: 周紹剛
** 日 期: 2006年10月12日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
/************************************************************************************
** Function name: UART0_ISR
** Descriptions: 串口0中斷服務(wù)函數(shù)
** Input: 無
** Output: 無
** Created by: Zhou Shaogang
** Created Date: 2006-11-18
**----------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**----------------------------------------------------------------------------------
************************************************************************************/
void UART0_ISR(void)
{
unsigned long ulStatus;
ulStatus = UARTIntStatus(UART0_BASE, true); //讀取已使能的串口0中斷狀態(tài)
UARTIntClear(UART0_BASE, ulStatus); //清除當(dāng)前的串口0中斷
if((ulStatus & UART_INT_RX) || (ulStatus & UART_INT_RT)) //接收中斷
{
while( UARTCharsAvail(UART0_BASE) )
{
QueueWrite(Uart0_Rec_Queue, (uint8)UARTCharNonBlockingGet(UART0_BASE));//FIFO中的數(shù)據(jù)入隊(duì)列
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -