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

📄 uart.c

📁 一款交换机BSP开发代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************/
/*                                                                          */
/*      Copyright (c) 1999 by Accelerated Technology, Inc.                  */
/*                                                                          */
/* PROPRIETARY RIGHTS of Accelerated Technology 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 implicity accepts the terms   */
/* of the license.                                                          */
/*                                                                          */
/****************************************************************************/
/****************************************************************************/
/*                                                                          */
/* FILENAME                                                 VERSION         */
/*                                                                          */
/*    UART.C                                                 1.7            */
/*                                                                          */
/* DESCRIPTION                                                              */
/*                                                                          */
/*    This file contains the UART specific functions.                       */
/*                                                                          */
/* AUTHOR                                                                   */
/*                                                                          */
/*    Barry Sellew, Accelerated Technology, Inc.                            */
/*                                                                          */
/* DATA STRUCTURES                                                          */
/*                                                                          */
/*                                                                          */
/* FUNCTIONS                                                                */
/*                                                                          */
/*     UART_Init_Port                                                       */
/*     UART_Date_Ready                                                      */
/*     UART_Put_String                                                      */
/*     UART_LISR                                                            */
/*     UART_Get_Char                                                        */
/*     UART_Put_Char                                                        */
/*     UART_Set_Baud_Rate                                                   */
/*                                                                          */
/* DEPENDENCIES                                                             */
/*                                                                          */
/*     nucleus.h                                                            */
/*     urt_defs.h                                                           */
/*     urt_extr.h                                                           */
/*                                                                          */
/* HISTORY                                                                  */
/*                                                                          */
/*  NAME               DATE              REMARKS                            */
/*                                                                          */
/*  B. Sellew         04/23/98     Created initial version.                 */
/*  B. Sellew         01/07/99     Added to 1.7 release of PLUS             */
/*                                                                          */
/****************************************************************************/
//#include "mcf5206e.h"
#include "urt_extr.h"

UART_BUFFER     uart_buf;      /* UART buffer */
int VER_FLAG;
extern	void UART2_Int(INT);
extern	void Wait_10ms(void);


void cmp_ver()
{
	unsigned char a,b,c;
	a=*(unsigned char*)(MBAR+0x14);
	b=*(unsigned char*)(MBAR+0x15);
	c=*(unsigned char*)(MBAR+0x16);
	if(a==0x85 && b==0x8b && c==0x8e)
		VER_FLAG=0;
	else
		VER_FLAG=1;
}

/****************************************************************************/
/* FUNCTION                                                                 */
/*                                                                          */
/*    UART_Init_Port                                                        */
/*                                                                          */
/* DESCRIPTION                                                              */
/*                                                                          */
/*    This function intializes the COM port that will be used for PPP       */
/*    communications.                                                       */
/*                                                                          */
/* CALLED BY                                                                */
/*                                                                          */
/*    Application                                                           */
/*                                                                          */
/* CALLS                                                                    */
/*                                                                          */
/*    NU_Local_Control_Interrupts                                           */
/*    UART_Set_Baud_Rate                                                    */
/*                                                                          */
/* INPUTS                                                                   */
/*                                                                          */
/*    UART_INIT * :   device initialization structure.                      */
/*                                                                          */
/* OUTPUTS                                                                  */
/*                                                                          */
/*    STATUS      :   Returns UART_SUCCESS if successful initialization,    */
/*                    else a negative value is returned.                    */
/*                                                                          */
/* HISTORY                                                                  */
/*                                                                          */
/*   NAME               DATE          REMARKS                               */
/*                                                                          */
/*  B. Sellew         04/23/98     Created initial version.                 */
/*  X. Zhang		  10/23/00     Changed for SBSP Boot.                   */
/*                                                                          */
/****************************************************************************/
STATUS  UART_Init_Port_1(UART_INIT *uart)
{

//MCF5206e_IMM 	*imm;					/* 5206e registers */
VOID            (*func_ptr)(INT);   	/* LISR ptr */
void 			**ptr;

    /* Setup the UART buffer */
    uart_buf.read = uart_buf.write = uart_buf.head = uart_buf.buffer;
    uart_buf.tail = uart_buf.head + BUFFER_SIZE - 1;
    uart_buf.status = UART_BUFFER_EMPTY;

	// Setup ICR3
	SET_ICR13_1(ICR13_INT_LEVEL_1);
	// Disable UART2
	SET_IMR_1(READ_IMR_1() | 0x2000);
	
    /* Disable all interrupts */
    SET2_UIMR_1(UIMR_DISABLE);

    /* Reset the receiver */
    SET2_UCR_1(UCR_RST_RX);

    /* Reset the transmitter */
    SET2_UCR_1(UCR_RST_TX);

    /* Point to UMR1 register */
    SET2_UCR_1(UCR_RST_MODE_REG);

    /* Setup parity and data bits */
    SET2_UMR1_1(uart->parity | uart->data_bits);

    /* Setup mode and stop bits */
    SET2_UMR2_1(uart->data_mode | uart->stop_bits);

    /* Setup system clock as time source */
    SET2_UCSR_1(UCSR_TIMER);

	// Init the IEC bit in UACR
	SET2_UACR_1(0);

    /* Setup baud rate */
    UART_Set_Baud_Rate(uart->baud_rate);

    /* Setup vector number to be generated by UART1 */
    SET2_UIVR_1(UIVR_VECTOR);


	func_ptr = UART2_Int;			// set INT64 Vector, modify vector table
	ptr = (void **)(VBR+0x100);		// VBR + 64*4
	*ptr = func_ptr;

	// enable UART2
	SET_IMR_1(READ_IMR_1() & 0xdfff);

    /* Enable receive interrupt */
    SET2_UIMR_1(UIMR_RX_ENABLE);

    /* Enable the receiver */
    SET2_UCR_1(UCR_RX_ENABLE);

    /* Enable the transmitter */
    SET2_UCR_1(UCR_TX_ENABLE);

    return (0);
}

/*uart init 5307*/
STATUS  UART_Init_Port_2(UART_INIT *uart)
{

//MCF5206e_IMM 	*imm;					/* 5206e registers */
VOID            (*func_ptr)(INT);   	/* LISR ptr */
void 			**ptr;

    /* Setup the UART buffer */
    uart_buf.read = uart_buf.write = uart_buf.head = uart_buf.buffer;
    uart_buf.tail = uart_buf.head + BUFFER_SIZE - 1;
    uart_buf.status = UART_BUFFER_EMPTY;
	
	// Setup ICR5
	SET_ICR5_2(ICR5_INT_LEVEL_2);
	// Disable UART2
	SET_IMR_2(READ_IMR_2() | 0x2000);
	
    /* Disable all interrupts */
    SET2_UIMR_2(UIMR_DISABLE);

    /* Reset the receiver */
    SET2_UCR_2(UCR_RST_RX);

    /* Reset the transmitter */
    SET2_UCR_2(UCR_RST_TX);

    /* Point to UMR1 register */
    SET2_UCR_2(UCR_RST_MODE_REG);

    /* Setup parity and data bits */
    SET2_UMR1_2(uart->parity | uart->data_bits);

    /* Setup mode and stop bits */
    SET2_UMR2_2(uart->data_mode | uart->stop_bits);

    /* Setup system clock as time source */
    SET2_UCSR_2(UCSR_TIMER);

	// Init the IEC bit in UACR
	SET2_UACR_2(0x60);		//看厂家提供的代码设为0x60

    /* Setup baud rate */
    UART_Set_Baud_Rate(uart->baud_rate);

    /* Setup vector number to be generated by UART1 */
    SET2_UIVR_2(UIVR_VECTOR2);


	func_ptr = UART2_Int;			// set INT64 Vector, modify vector table
	ptr = (void **)(VBR+0x104);		// VBR + 64*4
	*ptr = func_ptr;

	// enable UART2
	SET_IMR_2(READ_IMR_2() & 0xdfff);

    /* Enable receive interrupt */
    SET2_UIMR_2(UIMR_RX_ENABLE);

    /* Enable the receiver */
    SET2_UCR_2(UCR_RX_ENABLE);

    /* Enable the transmitter */
    SET2_UCR_2(UCR_TX_ENABLE);

    return (0);
}



/****************************************************************************/
/* FUNCTION                                                                 */
/*                                                                          */
/*    UART_Put_Char                                                         */
/*                                                                          */
/* DESCRIPTION                                                              */
/*                                                                          */
/*    This writes a character out to the serial port.                       */
/*                                                                          */
/* CALLED BY                                                                */
/*                                                                          */
/*    UART_Put_String                                                       */
/*    Applicatoin                                                           */
/*                                                                          */
/* CALLS                                                                    */
/*                                                                          */
/*    Serial port macros                                                    */
/*                                                                          */
/* INPUTS                                                                   */
/*                                                                          */
/*    UNSIGNED_CHAR  :   Character to to be written to the serial port.     */
/*                                                                          */
/* OUTPUTS                                                                  */
/*                                                                          */
/*    none                                                                  */
/*                                                                          */
/* HISTORY                                                                  */
/*                                                                          */
/*    NAME             DATE           REMARKS                               */
/*                                                                          */

⌨️ 快捷键说明

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