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

📄 sysserial.c

📁 MPC860 SCC UART BSP serial device initialization
💻 C
字号:
/* sysSerial.c -  MPC860 SCC UART BSP serial device initialization *//* Copyright 1984-1998 Wind River Systems, Inc. *//* Copyright 1997,1998 Motorola, Inc., All Rights Reserved */#include "copyright_wrs.h"/*modification history--------------------01d,30jan02,dtr  Removing diab warnings.01c,22may98,map  fixed COM1_BASE_ADRS, replaced N_UART_CHANNELS with                 N_I8250_CHANNELS [SPR# 21296]01b,20nov97,rhk  WRS code review cleanup.01a,26jun97,srr  created from ads860, version 01d.*//*DESCRIPTIONThis module provides code to initialize the serial port for the MBX.Two calls exist for the inialization, sysSerialHwInit and sysSerialHwInit2.  They are called by sysHwInit and sysHwInit2, respectivelyin sysLib.c.  The routine sysSerialHwInit sets up the necessary datastructures: PPC860SMC_CHAN and the tranmit and receive buffers. sysSerialHwInit2 connects the serial interrupt and enables it.The routine sysSerialChanGet is called by bootConfig.c and usrConfig.cas part of the generic serial driver setup ( when INCLUDE_TTY_DEV isdefined).  This instantiates a specific serial device configuration onthe MBX into the generic TTY driver.The routine sysSerialReset is called by sysToMonitor in sysLib.c and willreset the serial port.*/#include "vxWorks.h"#include "iv.h"#include "intLib.h"#include "config.h"#include "sysLib.h"#if (SERIAL_PORT == SERIAL_PORT_SMC)#include "drv/sio/ppc860Sio.h"#include "drv/multi/ppc860Cpm.h"static PPC860SMC_CHAN ppc860Chan;#endif /* SERIAL_PORT == SERIAL_PORT_SMC */#if (SERIAL_PORT == SERIAL_PORT_COM)#include "drv/sio/i8250Sio.h"IMPORT void             sysOutByte (UINT32, UINT8);IMPORT UCHAR            sysInByte (UINT32);/* device initialization structure */typedef struct    {    USHORT vector;                      /* Interrupt vector */    ULONG  baseAdrs;                    /* Register base address */    USHORT regSpace;                    /* Address Interval */    } I8250_CHAN_PARAS;/* forward declaration */IMPORT int intEnable (int vector);/* Local data structures */static I8250_CHAN  i8250Chan[N_I8250_CHANNELS];static I8250_CHAN_PARAS devParas[] =    {       {COM1_INT_VEC, COM1_BASE_ADRS, UART_REG_ADDR_INTERVAL},    };#define UART_REG(reg,chan) \                (devParas[chan].baseAdrs + reg * devParas[chan].regSpace)#endif /* SERIAL_PORT == SERIAL_PORT_COM *//******************************************************************************** sysSerialHwInit - initialize the BSP serial devices to a quiesent state** This routine initializes the BSP serial device descriptors and puts the* devices in a quiesent state.  It is called from sysHwInit() with* interrupts locked.** Data Parameter Ram layout:**.CS* -----------------------------* |                           | DPRAM base (address = 0x2000)* |                           |* |                           |* |---------------------------|* | 8 bytes per descriptor    | Tx Buffer Descriptor (0x2200)* |---------------------------|* |                           |* |---------------------------|* | 16 descriptors @          | Rx Buffer Descriptors (0x2210)* | 8 bytes per descriptor    | * |                           |* |---------------------------|* |                           | end Rx BDs (0x2290)* |                           |* |                           |* |---------------------------|* | 80 bytes allowed          | Tx Buffer (0x2300)* |---------------------------|* | one receive char/buffer   | Rx Buffer (0x2380)* |---------------------------|* |                           |* |                           |* |                           |* |                           |* |---------------------------|* | 3A hex bytes of parameter | SMC1 Parameter Area (0x3e80)* | info including Rx and Tx  | * | BD pointers, func codes   |* | etc...                    |* |---------------------------|**.CE** RETURNS: N/A*/ void sysSerialHwInit (void)    {#if (SERIAL_PORT == SERIAL_PORT_COM)    int i;    /* enable serial I/O using COM1 on the board */    *BCSR1 |= BCSR1_RS232_COM1;		/* Use COM1 instead of SMC1 */    *BCSR1 &= ~BCSR1_RS232_DT;          /* Enable Transceiver */	#endif#if (SERIAL_PORT == SERIAL_PORT_SMC)    /* enable serial I/O using SCC1 on the board */    *BCSR1 &= (~BCSR1_RS232_COM1 & ~BCSR1_RS232_DT);    /* intialize the chips device descriptors */    ppc860Chan.clockRate      = brgClkFreq;	    /* BRGCLK freq (Hz) */    ppc860Chan.regBase        = vxImmrIsbGet();  	    /* IMMR reg has base adr */    ppc860Chan.bgrNum         = 1;                  /* use BRG1 */    ppc860Chan.uart.smcNum    = 1;                  /* SMC1 wired for rs232 */    ppc860Chan.uart.txBdNum   = 1;                  /* use 1 transmit BD */    ppc860Chan.uart.rxBdNum   = 0x10;               /* use 16 receive BD */    /* setup the transmit buffer descriptor base addr */    ppc860Chan.uart.txBdBase  = (SMC_BUF *) TX_BUF_DESC_BA;    /* setup the receive buffer descriptor base addr */    ppc860Chan.uart.rxBdBase  = (SMC_BUF *) RX_BUF_DESC_BA;    ppc860Chan.uart.txBufBase = (u_char *) 		(MPC860_DPRAM_BASE(ppc860Chan.regBase) + TX_BUFFER);                                                    /* tx buf base */    ppc860Chan.uart.rxBufBase = (u_char *) 		(MPC860_DPRAM_BASE(ppc860Chan.regBase) + RX_BUFFER);                                                    /* rx buf base */    /* WE MAY WANT TO INCREASE THE BUFFER SIZES. */    ppc860Chan.uart.txBufSize = 0x1;                /* transmit buffer size */    ppc860Chan.uart.pSmc = (SMC *) ((UINT32) 	PPC860_DPR_SMC1( MPC860_DPRAM_BASE(ppc860Chan.regBase) ));                                                    /* SMC1 DPRAM addr params */    ppc860Chan.uart.pSmcReg =         (SMC_REG *) ((UINT32) MPC860_SMCMR1(ppc860Chan.regBase));						    /* SMCMR1 for SMC1 */    /* configure the port lines */    *MPC860_PBPAR(ppc860Chan.regBase) |= PORT_B_PINS_SER;    *MPC860_PBDIR(ppc860Chan.regBase) &= ~PORT_B_PINS_SER;    *MPC860_PBODR(ppc860Chan.regBase) &= ~PORT_B_PINS_SER;    ppc860Chan.pBaud = (VINT32 *) MPC860_BRGC1(ppc860Chan.regBase);    ppc860Chan.channelMode = 0;    *MPC860_SDCR(ppc860Chan.regBase) = 1;           /* */    /* reset the chip */    ppc860DevInit(&ppc860Chan);#endif /* SERIAL_PORT == SERIAL_PORT_SMC */#if (SERIAL_PORT == SERIAL_PORT_COM)    for (i = 0; i < N_I8250_CHANNELS; i++)        {	i8250Chan[i].int_vec	 = devParas[i].vector;	i8250Chan[i].channelMode = 0;	i8250Chan[i].lcr	 = UART_REG(UART_LCR, i);	i8250Chan[i].data	 = UART_REG(UART_RDR, i);	i8250Chan[i].brdl	 = UART_REG(UART_BRDL, i);	i8250Chan[i].brdh	 = UART_REG(UART_BRDH, i);	i8250Chan[i].ier	 = UART_REG(UART_IER, i);	i8250Chan[i].iid	 = UART_REG(UART_IID, i);	i8250Chan[i].mdc	 = UART_REG(UART_MDC, i);	i8250Chan[i].lst	 = UART_REG(UART_LST, i);	i8250Chan[i].msr	 = UART_REG(UART_MSR, i);	i8250Chan[i].outByte	 = (void (*) (int, char))  sysOutByte;	i8250Chan[i].inByte	 = (UCHAR (*) ()) sysInByte;	i8250HrdInit (&i8250Chan[i]);        }#endif /* SERIAL_PORT == SERIAL_PORT_COM */   }/******************************************************************************** sysSerialHwInit2 - connect BSP serial device interrupts** This routine connects the BSP serial device interrupts.  It is called from* sysHwInit2().  Serial device interrupts could not be connected in* sysSerialHwInit() because the kernel memory allocator was not initialized* at that point, and intConnect() calls malloc().** RETURNS: N/A*/ void sysSerialHwInit2 (void)    {    /* connect serial interrupts */#if (SERIAL_PORT == SERIAL_PORT_SMC)    (void) intConnect (IV_SMC1, (VOIDFUNCPTR) ppc860Int, (int) &ppc860Chan);    *CIMR(vxImmrIsbGet()) |= CIMR_SMC1;#endif /* SERIAL_PORT == SERIAL_PORT_SMC */#if (SERIAL_PORT == SERIAL_PORT_COM)    int i;    /* connect serial interrupts */     for (i = 0; i < N_I8250_CHANNELS; i++)         if (i8250Chan[i].int_vec)	     {             (void) intConnect (INUM_TO_IVEC ((int ) i8250Chan[i].int_vec),						i8250Int, (int)&i8250Chan[i] );             intEnable (devParas[i].vector);              }#endif /* SERIAL_PORT == SERIAL_PORT_COM */    }/******************************************************************************** sysSerialChanGet - get the SIO_CHAN device associated with a serial channel** This routine gets the SIO_CHAN device associated with a specified 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 */    )    {    switch (channel)	{	case SMC1_COM1_NUM:#if (SERIAL_PORT == SERIAL_PORT_SMC)            return ((SIO_CHAN *) &ppc860Chan);#endif#if (SERIAL_PORT == SERIAL_PORT_COM)            return ((SIO_CHAN *) &i8250Chan[channel]);#endif	default:	    return ((SIO_CHAN *) ERROR);        }    }/********************************************************************************* sysSerialReset - reset the serial device ** This function calls sysSerialHwInit() to reset the serial device** RETURNS: N/A**/void sysSerialReset (void)    {    sysSerialHwInit ();    }

⌨️ 快捷键说明

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