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

📄 uart0.c

📁 arm7 sample code, some demo for arm7 of linux
💻 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:        串口驱动源文件
** 
**------------------------------------------------------------------------------------------------------
** 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:     中断优先级
** 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)                                        //波特率太高,错误返回   
    return(FALSE);
  
  if (QueueCreate(Uart0_Rec_Queue,                           //初且化接收队列失败,错误返回
                  UART0_REC_QUEUE_LEN,
                  0,
                  0)==NOT_OK)
  	return(FALSE);                                           
    
  SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);               //使能串口0外围设备
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);               //使能GPIOA

  GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); //设置PA0,PA1为RXD0,TXD0
  
  UARTConfigSet(UART0_BASE, BaudRate, (UART_CONFIG_WLEN_8 |  //配置串口0,8位数据,1位起始位,1位停止位,用户波特率
                                       UART_CONFIG_STOP_ONE |
                                       UART_CONFIG_PAR_NONE) & 0xFFFFFFEF);

  UARTFifoLevelSet(UART0_BASE, 8, 8);
  IntEnable(INT_UART0);                                      //使能串口0系统中断
  UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);      //使能串口0接收中断和接收超时中断
  IntPrioritySet(INT_UART0, Prio);                           //设置中断优先级     
  UARTEnable(UART0_BASE);                                
  
  return(TRUE);
}


/************************************************************************************
** Function name: Uart0Send
** Descriptions:  发送多个字节数据
** Input:         Buffer:发送数据存储位置
**                NByte:发送数据个数
** 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) );
}


/*********************************************************************************************************
** 函数名称: UART0_ISR
** 功能描述: 串口0中断服务函数
** 输 入:   无
** 输 出:   无
** 全局变量: Uart0_Rec_Queue
** 调用模块: QueueWrite
**
** 作 者: 周绍刚
** 日 期: 2006年10月12日
**-------------------------------------------------------------------------------------------------------
** 修改人: 
** 日 期: 
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/

/************************************************************************************
** Function name: UART0_ISR
** Descriptions:  串口0中断服务函数
** 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中断状态
  UARTIntClear(UART0_BASE, ulStatus);           //清除当前的串口0中断

  if((ulStatus & UART_INT_RX) || (ulStatus & UART_INT_RT))               //接收中断
  {
   while( UARTCharsAvail(UART0_BASE) )
   {
    QueueWrite(Uart0_Rec_Queue, (uint8)UARTCharNonBlockingGet(UART0_BASE));//FIFO中的数据入队列
   }
  }
  
}

⌨️ 快捷键说明

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