📄 uart.c
字号:
/*************************************************************************************
* Copyright (c) 2005 by National ASIC System Engineering Research Center.
* PROPRIETARY RIGHTS of ASIC are involved in the subject matter of this
* material. All manufacturing, reproduction, use, and sales rights
* pertaining to this subject matter are governed by the license agreement.
* The recipient of this software implicitly accepts the terms of the license.
*
* File Name: uart.c
*
* File Description:
* The file consists of the function used to config uart
*
* Function Description:
* uart_reset_value_test()
* check uart registers reset value
*
* HA_InitUart1(U32 clk, U32 baud, U32 bits, U32 triger)
* initiate UART
*
*
* ER en_re_int(U32)
* enable and disable the recieve int and the transmit int
* thr_isr_uart0(void)
interrupt handler for UART1
rda_isr_uart0(void)
interrupt handler
int_serv_uart0()
UART0 interrupt service
* Created by Michael <yuyu_zh@seu.edu.cn>, 2005-03-21
**************************************************************************************/
#include "includes.h"
//定义串口缓冲区
static uint8 Uart0SendBuf[UART0_SEND_QUEUE_LENGTH];
static uint8 Uart0RecvBuf[UART0_RECV_QUEUE_LENGTH];
//static uint8 Uart1SendBuf[UART1_SEND_QUEUE_LENGTH];
//static uint8 Uart1RecvBuf[UART1_RECV_QUEUE_LENGTH];
/*********************************************************************************************************
** 函数名称: UartWriteFull
** 功能描述: 数据队列写满处理程序
** 输 入: Buf:指向数据队列
** Data:将要入队的数据
** Mod: 入队方式
** 输 出:NOT_OK :参数错误
** OS_Q_FULL:队列满
** OS_Q_OK :发送成功
** 全局变量: 无
** 调用模块: 无
**
** 作 者: 陈明计
** 日 期: 2003年7月4日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint8 UartWriteFull(DataQueue *Buf, QUEUE_DATA_TYPE Data, uint8 Mod)
{
uint16 temp;
Mod = Mod;
temp = QueueSize((void *)Buf);
while (temp <= QueueNData((void *)Buf)) /* 等待数据队列不满 */
{
OSTimeDly(2);
}
return QueueWrite((void *)Buf, Data); /* 数据重新入队 */
}
/*********************************************************************************************************
** 函数名称: UartReadEmpty
** 功能描述: 数据队列读空处理程序
** 输 入: Buf:指向数据队列
** Ret:将要读出的数据地址
** 输 出:NOT_OK :参数错误
** QUEUE_OK :收到消息
** QUEUE_EMPTY:无消息
** 全局变量: 无
** 调用模块: 无
**
** 作 者: Zbj
** 日 期: 2007.11.27
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint8 UartReadEmpty(QUEUE_DATA_TYPE *Ret, DataQueue *Buf)
{
while (QueueNData((void *)Buf)==0) /* 等待数据队列不满 */
{
OSTimeDly(2);
}
return QueueRead(Ret,(void *)Buf,QUEUE_PEND); /* 数据重新入队 */
}
/*********************************************************************************************************
** 函数名称: UART0Init
** 功能描述: 初始化UART0
** 输 入: bps:波特率
**
** 输 出:TRUE :成功
** FALSE:失败
** 全局变量:
** 调用模块: QueueCreate
**
** 作 者: 陈明计
** 日 期: 2003年7月4日
**-------------------------------------------------------------------------------------------------------
** 修改人: Zbj
** 日 期: 2007.11.27
********************************************************************************************************/
/*********************************************************************************************************
** 函数名称: UART0Putch
** 功能描述: 发送一个字节数据
** 输 入: Data:发送的数据数据
** 输 出:无
** 全局变量: 无
** 调用模块: 无
**
** 作 者: 陈明计
** 日 期: 2003年7月4日
**------------------------------------------------------------------------------------------------------
** 修改人: Zbj
** 日 期: 2007.11.27
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void Uart0Putch(uint8 Data)
{
uint8 temp;
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
QueueWrite((void *)Uart0SendBuf, Data); /* 数据入队 */
OS_ENTER_CRITICAL();
if ((read_reg(UART0_LSR)& 0x00000020) != 0)
{ /* UART0发送保持寄存器空 */
QueueRead(&temp, (void *)Uart0SendBuf,QUEUE_ACCEPT); /* 发送最初入队的数据 */
write_reg(UART0_THR,temp);
read_reg(UART0_IER) |= (0x02); /* 允许发送中断 */
}
OS_EXIT_CRITICAL();
}
/*********************************************************************************************************
** 函数名称: UART0WriteNbyte
** 功能描述: 发送多个字节数据
** 输 入: Data:发送数据存储位置
** NByte:发送数据个数
** 输 出:无
** 全局变量: 无
** 调用模块: UART0Putch
**
** 作 者: 陈明计
** 日 期: 2003年7月4日
**-------------------------------------------------------------------------------------------------------
** 修改人: Zbj
** 日 期: 2007.11.27
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void Uart0WriteNbyte(uint8 *Data, uint16 NByte)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
OS_ENTER_CRITICAL();
while (NByte-- > 0)
{
Uart0Putch(*Data++);
}
OS_EXIT_CRITICAL();
}
/*********************************************************************************************************
** 函数名称: Uart0WriteStr
** 功能描述: 向Uart0发送字符串
** 输 入: str :指向字符串的指针
** 输 出: 无
** 全局变量: 无
** 调用模块: Uart0Putch
**------------------------------------------------------------------------------------------------------
** 作 者: Zbj
** 日 期: 2007.11.27
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void Uart0WriteStr(char *str)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
OS_ENTER_CRITICAL();
while ((*str)!='\0')
{
Uart0Putch(*(QUEUE_DATA_TYPE *)str++);
}
OS_EXIT_CRITICAL();
}
void Uart0WriteStatic(void)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
OS_ENTER_CRITICAL();
Uart0Putch(0x50);
Uart0Putch(0x50);
Uart0Putch(0x50);
Uart0Putch(0x50);
OS_EXIT_CRITICAL();
}
/*********************************************************************************************************
** 函数名称: Uart1WriteStr
** 功能描述: 向Uart1发送字符串
** 输 入: str :指向字符串的指针
** 输 出:无
** 全局变量: 无
** 调用模块: Uart1Putch
**------------------------------------------------------------------------------------------------------
** 作 者: Zbj
** 日 期: 2007.11.27
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint16 Uart0GetNbyte(char *Ret, uint16 Size)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -