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

📄 sysserial.c

📁 MPC8241:本程序是freescale的824*系列的BSP源程序
💻 C
字号:
/* sysSerial.c - PrPMC600 BSP serial device initialization */

/* Copyright 1984-2000 Wind River Systems, Inc. */
/* Copyright 1996-2000 Motorola, Inc. All Rights Reserved */
#include "copyright_wrs.h"

/*
modification history
--------------------
01a,28feb00,rhk  created from version 01c, MV2100 BSP.
*/

/*
The sysSerial.c file is normally included as part of the sysLib.c file.
This code segment configures the serial ports for the BSP.

This BSP can support a single I8250 DUSART. 
*/

#include "vxWorks.h"
#include "logLib.h"
#include "iv.h"
#include "intLib.h"
#include "config.h"
#include "sysLib.h"
#include "st16552Sio.c"
#include "BspCpusApi.h"

/* externals */

IMPORT UCHAR	sysInByte(ULONG);
IMPORT void	sysOutByte(ULONG, UCHAR);
IMPORT int	intEnable (int intLevel);
IMPORT void    led11(unsigned short );
/* device initialization structures */

typedef struct
    {
    USHORT vector;			/* Interrupt vector */
    ULONG  baseAdrs;		/* Register base address */
    USHORT regSpace;		/* Address Interval */
    USHORT intLevel;		/* Interrupt level */
    } I8250_CHAN_PARAS;

/* Local data structures */
static ST16552_CHAN  st16552Chan[N_UART_CHANNELS];
static ST16552_MUX   st16552Mux;
/*static I8250_CHAN  i8250Chan[N_UART_CHANNELS];*/

static I8250_CHAN_PARAS devParas[] = 
    {
    	{COM1_INT_VEC, COM1_BASE_ADR, UART_REG_ADDR_INTERVAL, COM1_INT_LVL},/* in pmc8240 */
		{COM2_INT_VEC, COM2_BASE_ADR, UART_REG_ADDR_INTERVAL, COM2_INT_LVL},/* in PC97307, UART1 */
		{COM3_INT_VEC, COM3_BASE_ADR, UART_REG_ADDR_INTERVAL, COM3_INT_LVL} /* in PC97307, UART2 */
    };

#define UART_REG(reg,chan) \
		(devParas[chan].baseAdrs + reg * devParas[chan].regSpace)

/* globals */
    

void sysSerialHwInit (void)
{
    int i;
	
	/* 使能DUART模式,仅用于824x子卡 */
	*((unsigned char *)(COM1_BASE_ADR + 0x11)) = 0x01;
	
    for (i = 0; i < N_UART_CHANNELS; i++)
    {
		st16552Chan[i].regs = (char *)devParas[i].baseAdrs;
        st16552Chan[i].level	= devParas[i].intLevel;
        st16552Chan[i].regDelta = devParas[i].regSpace;
        st16552Chan[i].baudRate = CONSOLE_BAUD_RATE;
        /* st16552Chan[i].xtal = 66700000; */ /*devParas[i].xtal*/
		st16552Chan[i].xtal = sysGetBusSpdHertz();  /* modify by zou 03-3-1 10:48 */
		
        st16552Chan[i].channelMode = 0;
        
        st16552DevInit(&st16552Chan[i]);
    }
    
    st16552Mux.nextChan = 0;
    st16552Mux.pChan = st16552Chan;
    
    
	
}

/******************************************************************************
*
* sysSerialHwInit2 - connect BSP serial device interrupts
*
* This routine connects the BSP serial device interrupts.  It is called from
* sysHwInit2().  
* 
* Serial device interrupts cannot be connected in sysSerialHwInit() because
* the kernel memory allocator is not initialized at that point, and
* intConnect() calls malloc().
*
* RETURNS: N/A
*
* SEE ALSO: sysHwInit2()
*/

#if 1
void sysSerialHwInit2 (void)
{
    int i;

    /* connect serial interrupts N_UART_CHANNELS*/
    for (i = 0; i < 1; i++)
    {
        if (st16552Chan[i].level)
        {
            intConnect ( INUM_TO_IVEC ((unsigned int)(st16552Chan[i].level)),
                                st16552Int, (int)&st16552Chan[i] 
                               );

            intEnable (devParas[i].intLevel); 
        }
    }
}
#endif

/* ST16C552的两个通道共用一个中断 */
#if 0
void sysSerialHwInit2 (void)
    {
    /* Connect the multiplexed interrupt handler */

      intConnect (INUM_TO_IVEC((int)(devParas[0].vector)),
			st16552MuxInt, (int) &st16552Mux);
    
    intEnable (devParas[0].intLevel);
}
#endif
/******************************************************************************
*
* sysSerialChanGet - get the SIO_CHAN device associated with a serial channel
*
* This routine returns a pointer to the SIO_CHAN device associated
* with a specified serial channel.  It is called by usrRoot() to obtain 
* pointers when creating the system serial devices, `/tyCo/x'.  It
* is also used by the WDB agent to locate its serial channel.
*
* RETURNS: A pointer to the SIO_CHAN structure for the channel, or ERROR
* if the channel is invalid.
*/

SIO_CHAN * sysSerialChanGet
    (
    int channel		/* serial channel */
    )
{
    if ( (channel < 0) || (channel >= N_UART_CHANNELS) )
        return (SIO_CHAN *)ERROR;

    return ((SIO_CHAN *) &st16552Chan[channel]);
}

/******************************************************************************
*
* sysSerialReset - reset all serial devices to a quiescent state
*
* This routine resets all serial devices to a quiescent state.  It is called 
* by sysToMonitor().
*
* RETURNS: N/A
*
* SEE ALSO: sysToMonitor()
*/

void sysSerialReset (void)
{
    int i;

    for (i = 0; i < N_UART_CHANNELS; i++)
	{
        st16552DevInit(&st16552Chan[i]);
	}
}


/***************以下为测试代码****************************/
/* 使能自环方式 */
void EnableLoop(unsigned char ucChan )
{    
    ST16552_CHAN *	pChan = &st16552Chan[ucChan];
    ST16552_REG_WRITE(pChan, IER, 0); 
	/*    
    ioctl (STD_IN, FIOFLUSH, 0 );
    ioctl (STD_OUT, FIOFLUSH, 0 );
	*/    
    ST16552_REG_WRITE(pChan, MCR, MCR_INT | MCR_LOOP); 
    /* ST16552_REG_WRITE(pChan, IER, RxFIFO_BIT | TxFIFO_BIT); */

}

/* 非自环方式 */
void DisableLoop(unsigned char ucChan )
{
    ST16552_CHAN *	pChan = &st16552Chan[ucChan];
    ST16552_REG_WRITE(pChan, IER, 0); 
	/*    
    ioctl (STD_IN, FIOFLUSH, 0 );
    ioctl (STD_OUT, FIOFLUSH, 0 );
	*/    
    ST16552_REG_WRITE(pChan, MCR, MCR_INT | MCR_DTR); 
    /* ST16552_REG_WRITE(pChan, IER, RxFIFO_BIT | TxFIFO_BIT); */

}

⌨️ 快捷键说明

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