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

📄 sysserial.c

📁 该源码为mpc8248处理器的BSP
💻 C
字号:
/* sysSerial.c -  MPC827x SCC UART BSP serial device initialization *//* Copyright 1984-2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01k,03oct04,dtr  SPR 98762.01j,23dec03,dtr  modified to use dpram mem alloc library calls and                  SCC4 support.01i,01oct03,dee  removed hardcoding of internal map base, use immrVal01h,17oct01,jrs  Upgrade to veloce		 corrected SCC2 initialization in sysSerialHwInit() - SPR #64407		 removed useless init of baud rate generators - SPR #8898901g,09sep99,ms_  change bsp name from vads8260 to ads826001f,15jul99,ms_  make compliant with our coding standards01e,19apr99,ms_  adhere to coding conventions01d,14apr99,ms_  switch from using interrupt vectors to interrupt numbers01c,08apr99,ms_  upgrade to multiple channels01b,05apr99,ms_  upgrade to support two channels01a,21jan99,ms_  adapted from sysSerial.c for ads860 *//*DESCRIPTIONThis library contains routines for M8260 SMC UART BSP serial deviceinitialization*/#include "vxWorks.h"#include "iv.h"#include "intLib.h"#include "config.h"#include "sysLib.h"#include "drv/sio/m8260Scc.h"#include "drv/sio/m8260Sio.h"#include "drv/parallel/m8260IOPort.h"#include "drv/sio/m8260Brg.h"IMPORT    UINT32  vxImmrGet (void);#if (UART_DEVICE == SCC_DEVICE)LOCAL M8260_SCC_CHAN m8260SccChan1;LOCAL M8260_SCC_CHAN m8260SccChan2;/******************************************************************************** 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.** Buffers and Buffer Descriptors for the two channels:* * .CS*                                                   Address per SCC*                                                ---------------------------* field                                 size        SCC1            SCC2* ------                                -------  -----------     -----------* Receive Buffer Descriptor             8 bytes IMMAP+0x0000    IMMAP+0x0100* Receive Buffer Status                 2 bytes IMMAP+0x0000    IMMAP+0x0100* Receive Buffer Length                 2 bytes IMMAP+0x0002    IMMAP+0x0102* Pointer to Receive Buffer             4 bytes IMMAP+0x0004    IMMAP+0x0104* Receive Buffer                        1 bytes IMMAP+0x0040    IMMAP+0x0140** Transmit Buffer Descriptor            8 bytes IMMAP+0x0008    IMMAP+0x0108* Transmit Buffer Status                2 bytes IMMAP+0x0008    IMMAP+0x0108* Transmit Buffer Length                2 bytes IMMAP+0x000A    IMMAP+0x010A* Transmit to Receive Buffer            4 bytes IMMAP+0x000C    IMMAP+0x010C* Transmit Buffer                       1 bytes IMMAP+0x0060    IMMAP+0x0160* .CE**** RETURNS: N/A*/ void sysSerialHwInit (void)    {    int immrVal = vxImmrGet();    char * bufferBase;    /* SCC1 */    * M8260_IOP_PDDIR(immrVal) &= ~(PD31 | PC30);      * M8260_IOP_PDDIR(immrVal) |= (PD30);   	    * M8260_IOP_PDPAR(immrVal) |= (PD31 | PD30);     * M8260_IOP_PDSO(immrVal) &= ~(PD31 | PD30); 	    * M8260_IOP_PDSO(immrVal) |= PD30;     /* SCC 4 */    * M8260_IOP_PDSO(immrVal) &= ~(PD22 );    * M8260_IOP_PDDIR(immrVal) &= ~(PD22);    * M8260_IOP_PDDIR(immrVal) |= (PD21);    * M8260_IOP_PDPAR(immrVal) |= (PD22 | PD21);    /* CPM muxs */    /* for the value of 0x0009121B:     * field    description     SCC1    SCC2    SCC3    SCC4     * GR       Grant Support   <-----always asserted------>     * SC       SCC connection  <---not connected to TSA--->     * RSxCS    Rcv Clk Source  BRG1    BRG2    BRG3    BRG4     * TSxCS    Tx Clk Source   BRG1    BRG2    BRG3    BRG4     */    * M8260_CMXSCR(immrVal) = 0x0009121B;    /* enable both RS232 ports on the board */    /* intialize the two serial channels */    /* this is in order of the structure contents */    /* indicate that this is a fresh device */    m8260SccChan1.channelMode = 0;    m8260SccChan2.channelMode = 0;    m8260SccChan1.baudRate = DEFAULT_BAUD;    m8260SccChan2.baudRate = DEFAULT_BAUD;    m8260SccChan1.sccNum = 1;    m8260SccChan2.sccNum = 4;    m8260SccChan1.immrVal = immrVal;    m8260SccChan2.immrVal = immrVal;   bufferBase = (char *)m82xxDpramAlignedMalloc(0x200,0x100);    memset ((char*)bufferBase,0x0,0x200);    m8260SccChan1.pBdBase = (char *) ((UINT32)bufferBase + 0x000);    m8260SccChan1.rcvBufferAddr = (char *) ((UINT32)bufferBase + 0x040);    m8260SccChan1.txBufferAddr = (char *) ((UINT32)bufferBase + 0x060);    m8260SccChan2.pBdBase = (char *) ((UINT32)bufferBase + 0x100);    m8260SccChan2.rcvBufferAddr = (char *) ((UINT32)bufferBase + 0x140);    m8260SccChan2.txBufferAddr = (char *) ((UINT32)bufferBase + 0x160);    /* disable interrupts from SCC1 and SCC2 */    m8260IntDisable(INUM_SCC1);    if (NUM_TTY >= 2)		m8260IntDisable(INUM_SCC4);    /* reset the channel */    m8260SioDevInit(&m8260SccChan1);    if (NUM_TTY >= 2)		m8260SioDevInit(&m8260SccChan2);    }/******************************************************************************** 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 */    (void) intConnect (INUM_TO_IVEC(INUM_SCC1), 		      (VOIDFUNCPTR) m8260SioInt, (int) &m8260SccChan1);    if (NUM_TTY >= 2)		(void) intConnect (INUM_TO_IVEC(INUM_SCC4), 			  (VOIDFUNCPTR) m8260SioInt, (int) &m8260SccChan2);    }/******************************************************************************** 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 */    )    {    if (channel == 0)		return ((SIO_CHAN *) &m8260SccChan1);     else if (channel == 1)		return ((SIO_CHAN *) &m8260SccChan2);     else 		return ((SIO_CHAN *) ERROR);    }/********************************************************************************* sysSerialReset - reset the serail device ** This function calls sysSerialHwInit() to reset the serail device** RETURNS: N/A**/void sysSerialReset (void)    {    sysSerialHwInit ();    }#else    #include "m8260Smc.h"    #include "m8260Smc.c"    LOCAL M8260_SMC_CHAN m8260SmcChan1;    LOCAL M8260_SMC_CHAN m8260SmcChan2;/******************************************************************************** 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.** Buffers and Buffer Descriptors for the two channels:* * .CS*                                                   Address per SCC*                                               ---------------------------* field                                 size    SCC1            SCC2* ------                                ------- -----------     -----------* Receive Buffer Descriptor             8 bytes 0x0470_0000     0x0470_0100* Receive Buffer Status                 2 bytes 0x0470_0000     0x0470_0100* Receive Buffer Length                 2 bytes 0x0470_0002     0x0470_0102* Pointer to Receive Buffer             4 bytes 0x0470_0004     0x0470_0104* Receive Buffer                        1 bytes 0x0470_0040     0x0470_0140** Transmit Buffer Descriptor            8 bytes 0x0470_0008     0x0470_0108* Transmit Buffer Status                2 bytes 0x0470_0008     0x0470_0108* Transmit Buffer Length                2 bytes 0x0470_000A     0x0470_010A* Transmit to Receive Buffer            4 bytes 0x0470_000C     0x0470_010C* Transmit Buffer                       1 bytes 0x0470_0060     0x0470_0160* .CE**** RETURNS: N/A*/ void sysSerialHwInit (void)    {    char * bufferBase;    int immrVal = vxImmrGet();    /* Initial SMC1,SMC2 PORT */    /* SMC1_TXD PC5 SMC1_RXD PC4 */    /* SMC2_TXD PA9    SMC2_RXD PA8 */    * M8260_IOP_PCPAR(immrVal) |= 0x0C000000;    * M8260_IOP_PCSO(immrVal)  &= ~(0x0C000000);    * M8260_IOP_PCDIR(immrVal)  &= ~(0x08000000);    * M8260_IOP_PCDIR(immrVal)  |= (0x04000000);    /* SMC1 use BRG1; SMC2 use BRG2 */    * M8260_CMXSMR(immrVal) = 0x0;    /* Initialize m8260SmcChannel1 */    m8260SmcChan1.baudRate = CONSOLE_BAUD_RATE;    m8260SmcChan2.baudRate = CONSOLE_BAUD_RATE;    /* BRGCLK freq (Hz) */    m8260SmcChan1.clockRate      = OSCILLATOR_FREQ;     /* IMMR reg has base adr */    m8260SmcChan1.regBase        = vxImmrGet();    /* use BRG1 */    /* SMC1 must use BRG1 */    m8260SmcChan1.bgrNum         = 1;    /* SMC1 wired for rs232 */    m8260SmcChan1.uart.smcNum    = 1;/*------------------------------------------------------------------------------*//* BSP_LABEL :(BSP_SERIAL)config BDs and BUUFERs address in DPRAM               *//*------------------------------------------------------------------------------*/    /* use 1 transmit BD */    m8260SmcChan1.uart.txBdNum   = 1;                   /* have  "1" TXBD */    /* use 16 receive BD */    m8260SmcChan1.uart.rxBdNum   = 12;                  /* have "12" RXBDs *//*    bufferBase = 0x9E00;*/    bufferBase = (char *)m82xxDpramAlignedMalloc(0x200,0x100)-CFG_IMMR;     /* receive BD base adrs */    m8260SmcChan1.uart.rxBdBase  = (SMC_BUF *) (bufferBase+0x100);  /* the same as above */    /* transmit BD base adrs */    m8260SmcChan1.uart.txBdBase  = (SMC_BUF *) (bufferBase+0x160);  /* should add to 'm8260SmcChan1.regbase' in the smc driver */    /* rx buf base */    m8260SmcChan1.uart.rxBufBase = (u_char *)(m8260SmcChan1.regBase + (bufferBase+0x170));    /* tx buf base */    m8260SmcChan1.uart.txBufBase = (u_char *)(m8260SmcChan1.regBase + (bufferBase+0x17c));    /* transmit buffer size */    m8260SmcChan1.uart.txBufSize = 0x1;    * (VINT16 *)(m8260SmcChan1.regBase + 0x87fc) = bufferBase+0x80;  /* set SMC1 PARA RAM start address, must 64byte-align */    CACHE_PIPE_FLUSH();    /* DPRAM addr of SMC1 params */    m8260SmcChan1.uart.pSmc = (SMC *) ((UINT32)(m8260SmcChan1.regBase + (bufferBase+0x80))); /* SMC1 PARA RAM starts at 0x3180 from IMMR,must 64byte-align, by kyf*/    /* SMCMR1 for SMC1 */    m8260SmcChan1.uart.pSmcReg = (SMC_REG *) ((UINT32)(m8260SmcChan1.regBase + 0x11a82));    m8260SmcChan1.pBaud = (UINT32 *) (m8260SmcChan1.regBase + 0x119f0);    m8260SmcChan1.channelMode = 0;/* Initialize m8260SmcChannel2 */    /* BRGCLK freq (Hz) */    m8260SmcChan2.clockRate      = OSCILLATOR_FREQ;    /* IMMR reg has base adr */    m8260SmcChan2.regBase        = vxImmrGet();    /* use BRG2 */    /* SMC2 must use BRG2 */    m8260SmcChan2.bgrNum         = 2;    /* SMC2 wired for rs232 */    m8260SmcChan2.uart.smcNum    = 2;/*------------------------------------------------------------------------------*//* BSP_LABEL :(BSP_SERIAL)config BDs and BUUFERs address in DPRAM               *//*------------------------------------------------------------------------------*/    /* use 1 transmit BD */    m8260SmcChan2.uart.txBdNum   = 1;    /* use 16 receive BD */    m8260SmcChan2.uart.rxBdNum   = 12;    /* receive BD base adrs */    m8260SmcChan2.uart.rxBdBase  = (SMC_BUF *) (bufferBase+0x180);    /* transmit BD base adrs */    m8260SmcChan2.uart.txBdBase  = (SMC_BUF *) (bufferBase+0x1e0);    /* rx buf base */    m8260SmcChan2.uart.rxBufBase = (u_char *)(m8260SmcChan2.regBase + (bufferBase+0x1f0));    /* tx buf base */    m8260SmcChan2.uart.txBufBase = (u_char *)(m8260SmcChan2.regBase + (bufferBase+0x1fc));    /* transmit buffer size */    m8260SmcChan2.uart.txBufSize = 0x1;     * (VINT16 *)(m8260SmcChan2.regBase + 0x88fc) = bufferBase+0xc0; /* set SMC2 PARA RAM start address, must 64byte-align */    CACHE_PIPE_FLUSH();    /* DPRAM addr of SMC2 params */    m8260SmcChan2.uart.pSmc = (SMC *) ((UINT32)(m8260SmcChan2.regBase + (bufferBase+0xc0))); /* must 64byte-align by kyf*/    /* SMCMR2 for SMC2 */    m8260SmcChan2.uart.pSmcReg = (SMC_REG *) ((UINT32)(m8260SmcChan2.regBase + 0x11a92));    m8260SmcChan2.pBaud = (UINT32 *) (m8260SmcChan2.regBase + 0x119f4);    m8260SmcChan2.channelMode = 0;    m8260IntDisable(INUM_SMC1);    if (NUM_TTY >= 2)    m8260IntDisable(INUM_SMC2);    /* reset the chip */    m8260SmcDevInit(&m8260SmcChan1);    /* reset the chip */    if (NUM_TTY >= 2)        m8260SmcDevInit(&m8260SmcChan2);    }/******************************************************************************** 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 */    (void) intConnect (INUM_TO_IVEC(INUM_SMC1),              (VOIDFUNCPTR) m8260SmcInt, (int) &m8260SmcChan1);    if (NUM_TTY >= 2)        (void) intConnect (INUM_TO_IVEC(INUM_SMC2),                  (VOIDFUNCPTR) m8260SmcInt, (int) &m8260SmcChan2);    }/******************************************************************************** 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 */    )    {    if (channel == 0)    return ((SIO_CHAN *) &m8260SmcChan1);    else if (channel == 1)    return ((SIO_CHAN *) &m8260SmcChan2);    else    return ((SIO_CHAN *) ERROR);    }/********************************************************************************* sysSerialReset - reset the serail device ** This function calls sysSerialHwInit() to reset the serail device** RETURNS: N/A**/void sysSerialReset (void)    {    sysSerialHwInit ();    }    #endif

⌨️ 快捷键说明

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