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

📄 ser_drv.c

📁 nucleus 文件系统,内核和彩色图形系统,在小系统上非常好用
💻 C
字号:
#include "plus\nucleus.h"
#include "net\target.h"
#include "ppp\urt_defs.h"
#include "ppp\urt_extr.h"
#include "plus\ser_drv.h"
#include "plus\MC68EZ328.h"


void URT_Put_String(unsigned char *bufPtr);
void URT_Put_Char(unsigned char ch);

UNSIGNED UART_Parity_Error = 0;
UNSIGNED UART_Frame_Error = 0;
UNSIGNED UART_Overrun_Error = 0;
//URT_LAYER *urt;

VOID  URT_LISR();
STATUS URT_Init_Port()
{
STATUS  status;
URX_REG urx;
INT             old_state, vector;
VOID    (*old_lisr)(INT);
	old_state = TCT_Local_Control_Interrupts(NU_DISABLE_INTERRUPTS);
	
    status = TCC_Register_LISR(0x44, URT_LISR, &old_lisr);
    if (status != NU_SUCCESS)
	return(-1);
	
	/* initialize UART */
	USTCNT.all = 0xE108;
	
	/* UBAUD configuration  */
/*      UART_Set_Baud_Rate(19200);  */
	UBAUD.all = 0x1126;
	
	/* assign RXD (BIT4) and TXD (BIT5) for UART in Port E select register */
	BCLR (PESEL, BIT5|BIT4);

	/* read the UART receive register to initialize the FIFO status */
	urx.all = URX.all;

	IMR        &= ~DBIRQ_IM_MUART;  // enable the RTC interrupt

	IWR        |= DBIRQ_IM_MUART;   // enable the RTC interrupt
	
	TCT_Local_Control_Interrupts(old_state);
}


void URT_Put_String(unsigned char *bufPtr)
{
	unsigned int i = 0;

	/* for each write value */
	while(bufPtr[i] != 0)
	{
		URT_Put_Char(bufPtr[i++]);
	}

}

void URT_Put_Char(unsigned char ch)
{
		UTX.bits.txData = ch;
	while(UTX.bits.busy);
}

/****************************************************************************/
/* FUNCTION                                                                 */
/*                                                                          */
/*    UART_Set_Baud_Rate                                                    */
/*                                                                          */
/* DESCRIPTION                                                              */
/*                                                                          */
/*    This function sets the UART buad rate.                                */
/*                                                                          */
/* CALLED BY                                                                */
/*                                                                          */
/*    UART_Init_Port                                                        */
/*                                                                          */
/* CALLS                                                                    */
/*                                                                          */
/*    Serial port macros                                                    */
/*    NU_Local_Control_Interrupts                                           */
/*                                                                          */
/* INPUTS                                                                   */
/*                                                                          */
/*    UNSIGNED   :  The new baud rate.                                      */
/*                                                                          */
/* OUTPUTS                                                                  */
/*                                                                          */
/*    none                                                                  */
/*                                                                          */
/* HISTORY                                                                  */
/*                                                                          */
/*    NAME             DATE           REMARKS                               */
/*                                                                          */
/*    K. Pontzloff     03/22/99       Created initial version.              */
/*                                                                          */
/****************************************************************************/
VOID  URT_Set_Baud_Rate(UNSIGNED baud_rate)
{

volatile long   *b_rate_address;
    /* Set the baud rate */
    if ((baud_rate >= 9600) || (baud_rate <= 115200))
	switch (baud_rate) {
	case 9600:
	    UBAUD.all = 0x0226;
	    break;
	case 19200:
		UBAUD.all = 0x0126;
	    break;
	case 38400:
	    UBAUD.all = 0x0026;
	    break;
	case 57600:
	    UBAUD.all = 0x0138;
	    break;
	case 15200:
	    default:
	    UBAUD.all = 0x0038;
	    break;
    }
}

CHAR  URT_Get_Char()
{
INT             int_level;          /* old interrupt level */
CHAR    in_ch;
  /* Lockout interrupts */
    int_level = NU_Local_Control_Interrupts(NU_DISABLE_INTERRUPTS);
    /* Wait until a character is available in the buffer */
    if(URX.bits.dataReady)
    /* Read and return the character */
		in_ch = (CHAR ) URX.bits.rxData;
	else
		in_ch = -1;
    /* Restore interrupts to previous level */
    NU_Local_Control_Interrupts(int_level);
	return(in_ch);
}

VOID  URT_LISR()
{
CHAR ch;
UART_INIT   *uart;
	
/* Process every character in the receive FIFO */
/*    while (URX.bits.dataReady)  */
    
			ch = URT_Get_Char();
			if(ch != -1 )
			URT_Put_Char(ch);      
    
}

VOID URT_Change_Communication_Mode(INT mode)
{

   /* URT_Communication_Mode = mode;  */

} /* URT_Change_Communication_Mode */


/************************************************/

STATUS  URT_Carrier()
{

    return (NU_TRUE);

}
VOID URT_Reset()
{


}

⌨️ 快捷键说明

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