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

📄 uart_function.c

📁 DSP开发可以用来看外设情况的程序
💻 C
字号:

/************************************************************************/
/* FileName:	Uart_Function.c											*/
/* Function: 	Define  writting function of uart on chip				*/
/************************************************************************/

#include <stdio.h>
#include <csl.h>
#include <csl_chip.h>
#include <csl_uart.h>
#include <csl_gpt.h>
#include <csl_pll.h>
#include <csl_irq.h>

#include "Timer.h"
#include "Esam_Function.h"

/****************************************************************/
/*	函数名:		Uart_Config() 									*/
/* 	功能:		配置UART控制寄存器								*/
/*	参数:														*/
/*				无												*/
/*  返回值:														*/
/*				无												*/
/****************************************************************/
extern void Uart_Config(void)
{
	/* Set BSR to disable SP2MODE */
    CHIP_FSET(XBSR, SP2MODE,0) ;

    /* Disable all UART events */
    UART_FSET(URLCR,DLAB,0);
    UART_RSET(URIER, UART_NOINT);

    /* Reset and  disable FIFOs */
    UART_RSET(URFCR, 0x7);
    UART_RSET(URFCR, 0); 

    /* Set DLL and DLM to values appropriate for the required baudrate */
   	UART_FSET(URLCR, DLAB, 1);	// DLAB = 1
    //UART_RSET(URDLL, 0x45);	// 当dsp的主频为200MHz
    UART_RSET(URDLL, 0xE8);		// 9600bps(主频300MHz)
    UART_RSET(URDLM, 0x01);
    UART_FSET(URLCR, DLAB, 0);  // DLAB = 0

    /* Setup word size, stop bits, parity */
    UART_RSET(URLCR, 0x1F);

    /* Disable loopback control */
    UART_RSET(URMCR, 0); 
               
    /* UART out of reset */
    UART_FSET(URPECR,URST,1);
}

/****************************************************************/
/*	函数名:		Delay_Time() 									*/
/* 	功能:		实现系统的延时,用来满足访问时序的要求 			*/
/*	参数:														*/
/*				Length---延时长度								*/
/*  返回值:														*/
/*              无									  			*/
/****************************************************************/
extern void Delay_Time(Uint32 Length)
{   
    Uint32 j;						
   	for(j=0; j<Length; j++)
	{
	}
}

/****************************************************************/
/*	函数名:		Write_Esam() 									*/
/* 	功能:		通过UART向ESAM发指定长度的命令					*/
/*	参数:														*/
/*				无												*/
/*  返回值:														*/
/*				无												*/
/****************************************************************/
extern void Write_Esam(void) 
{
	UART_FSET(URLCR, DLAB, 0);				
	Counter = 0;						// 字符发送计数器清0
	GPT_start(hGpt);					// 启动定时器,开始计时
	  
    while(!(Counter>=CommandLength));	// 等待命令报文发送完毕	
    
    GPT_stop(hGpt);						// 停止定时器
    //GPT_close(hGpt);					// 关闭定时器
    Delay_Time(0x5D0E);					// 延时一段时间,让命令报文
    									// 的最后一个字节发送到ESAM
    									// 0x6FFFF
}	

/****************************************************************/
/*	函数名:		Read_Esam() 									*/
/* 	功能:		通过UART向ESAM读取应答信息 						*/
/*	参数:														*/
/*				DataBuffer--指向接收数据缓冲区的指针			*/
/*				Length------延时长度							*/
/*  返回值:														*/
/*              无									  			*/
/****************************************************************/
extern void Read_Esam(Uint16 *DataBuffer, Uint16 Length)
{
	UART_FSET(URLCR, DLAB, 0);
 	while( Length-- )
    {
       	/* wait for RX empty */
       	while(!UART_FGET(URLSR,DR));
     	*DataBuffer++ = UART_RGET(URRBR);
    }
}

/******************************************************************************/
/*	No more																	  */
/******************************************************************************/

⌨️ 快捷键说明

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