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

📄 sysserial.c.bak

📁 移植好的Ibm405ep bsp板极支持包
💻 BAK
字号:
/* sysSerial.c - IBM 405EP serial device initialization *//*******************************************************************************   This source and object code has been made available to you by IBM on an   AS-IS basis.   IT IS PROVIDED WITHOUT WARRANTY OF ANY KIND, INCLUDING THE WARRANTIES OF   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE OR OF NONINFRINGEMENT   OF THIRD PARTY RIGHTS.  IN NO EVENT SHALL IBM OR ITS LICENSORS BE LIABLE   FOR INCIDENTAL, CONSEQUENTIAL OR PUNITIVE DAMAGES.  IBM芐 OR ITS LICENSOR芐   DAMAGES FOR ANY CAUSE OF ACTION, WHETHER IN CONTRACT OR IN TORT, AT LAW OR   AT EQUITY, SHALL BE LIMITED TO A MAXIMUM OF $1,000 PER LICENSE.  No license   under IBM patents or patent applications is to be implied by the copyright   license.   Any user of this software should understand that neither IBM nor its   licensors will be responsible for any consequences resulting from the use   of this software.   Any person who transfers this source code or any derivative work must   include the IBM copyright notice, this paragraph, and the preceding two   paragraphs in the transferred software.   Any person who transfers this object code or any derivative work must   include the IBM copyright notice in the transferred software.   COPYRIGHT   I B M   CORPORATION 2000   LICENSED MATERIAL  -  PROGRAM PROPERTY OF  I B M"*******************************************************************************//* Copyright 1984-1997 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01a,18may02,mcg  created from walnut version 01c.*//*DESCRIPTIONThis library contains board-specific routines for serial devices.There are two serial ports integrated into the IBM 405EP.  Thesedevices are 16550-like. The evbNs16550Sio driver is used for both devices.*/#include "vxWorks.h"#include "config.h"#include "iv.h"#include "intLib.h"#include "sysLib.h"#include "drv/sio/evbNs16550Sio.h"/* device initialization structure */typedef struct    {    USHORT vector;    ULONG  baseAdrs;    USHORT regSpace;    USHORT intLevel;    } EVBNS16550_CHAN_PARAS;/* initialize the structure for each serial device */static EVBNS16550_CHAN_PARAS dev0Paras =      {0,UART0_BASE,UART_REG_ADDR_INTERVAL,INT_LVL_UART0};static EVBNS16550_CHAN_PARAS dev1Paras =      {0,UART1_BASE,UART_REG_ADDR_INTERVAL,INT_LVL_UART1};#define UART0_REG(reg)   (dev0Paras.baseAdrs + reg*dev0Paras.regSpace)#define UART1_REG(reg)   (dev1Paras.baseAdrs + reg*dev1Paras.regSpace)static EVBNS16550_CHAN  evbNs16550Chan0;static EVBNS16550_CHAN  evbNs16550Chan1;#ifndef UART_CLOCK_EXTERNAL/* forward declarations */STATUS sysSerialCalcDivisor(UINT freqInputMhz, UINT baudRate, UINT *divisor );/* Structure for internal serial clock array */typedef struct    {    UINT freqInputMhz;    UINT baudRate;    UINT uartClkDivisor;    } INT_SERIAL_INFO;/* * Table of PLLOUTA speeds and baud rates used to determine the PLLOUTA:UART divisor. * The PLLOUTA clock is divided by the PLLOUTA:UART divisor to get the UART clock which * is fed into the UARTs.  The UART clock is then divided again by the UART to * obtain the baud rate.  The table of PLLOUTA:UART divisors below helps to select * a value that will result in the lowest % error on the baud rate. * NOTE: * The PLLOUTA:UART divisor must be high enough so the resulting UART clock is * less than 1/2 of the OPB bus frequency. */INT_SERIAL_INFO uartClkTbl[] =    {      /* PLLAOUT      Baud   PLLOUTA:UART divisor */        {  133,       1200,     15  },        {  133,       2400,     16  },        {  133,       4800,     28  },        {  133,       9600,     14  },        {  133,      19200,     14  },        {  133,      28800,     17  },        {  133,      33600,     31  },        {  133,      38400,     31  },        {  133,      57600,     29  },        {  133,     115200,     12  },        {  133,     307200,     27  },        {  200,       1200,     11  },        {  200,       2400,     28  },        {  200,       4800,     28  },        {  200,       9600,     14  },        {  200,      19200,     31  },        {  200,      28800,     31  },        {  200,      33600,     31  },        {  200,      38400,     25  },        {  200,      57600,     31  },        {  200,     115200,     12  },        {  200,     307200,     20  },        {  266,       1200,     19  },        {  266,       2400,     31  },        {  266,       4800,     28  },        {  266,       9600,     28  },        {  266,      19200,     28  },        {  266,      28800,     29  },        {  266,      33600,     31  },        {  266,      38400,     31  },        {  266,      57600,     29  },        {  266,     115200,     29  },        {  266,     307200,     27  },        {  333,       1200,     27  },        {  333,       2400,     31  },        {  333,       4800,     31  },        {  333,       9600,     31  },        {  333,      19200,     31  },        {  333,      28800,     29  },        {  333,      33600,     31  },        {  333,      38400,     17  },        {  333,      57600,     30  },        {  333,     115200,     30  },        {  333,     307200,     17  },        {  400,       1200,     22  },        {  400,       2400,     31  },        {  400,       4800,     31  },        {  400,       9600,     31  },        {  400,      19200,     31  },        {  400,      28800,     31  },        {  400,      33600,     31  },        {  400,      38400,     31  },        {  400,      57600,     31  },        {  400,     115200,     31  },        {  400,     307200,     27  }    };#endif/******************************************************************************** sysSerialHwInit - initialize the BSP serial devices to a quiescent state** This routine initializes the BSP serial device descriptors and puts the* devices in a quiescent state.  It is called from sysHwInit() with* interrupts locked.** RETURNS: N/A** SEE ALSO: sysHwInit()*/void sysSerialHwInit    (    void    )    {    UINT   clkDivisor;    UINT32 ucr;    /*     * Disable and clear serial interrupts in the UIC for both UARTs     */     intDisable(INT_LVL_UART0);     intDisable(INT_LVL_UART1);    /*     * intialize serial device 0 descriptors (S0)     */    evbNs16550Chan0.int_vec = dev0Paras.vector;    evbNs16550Chan0.channelMode = 0;    evbNs16550Chan0.lcr =  UART0_REG(UART_LCR);    evbNs16550Chan0.data =  UART0_REG(UART_RDR);    evbNs16550Chan0.brdl = UART0_REG(UART_BRDL);    evbNs16550Chan0.brdh = UART0_REG(UART_BRDH);    evbNs16550Chan0.ier =  UART0_REG(UART_IER);    evbNs16550Chan0.iid =  UART0_REG(UART_IID);    evbNs16550Chan0.mdc =  UART0_REG(UART_MDC);    evbNs16550Chan0.lst =  UART0_REG(UART_LST);    evbNs16550Chan0.msr =  UART0_REG(UART_MSR);    evbNs16550Chan0.outByte = sysOutByte;    evbNs16550Chan0.inByte  = sysInByte;    /*     * intialize serial device 1 descriptors (S1)     */    evbNs16550Chan1.int_vec = dev1Paras.vector;    evbNs16550Chan1.channelMode = 0;    evbNs16550Chan1.lcr =  UART1_REG(UART_LCR);    evbNs16550Chan1.data =  UART1_REG(UART_RDR);    evbNs16550Chan1.brdl = UART1_REG(UART_BRDL);    evbNs16550Chan1.brdh = UART1_REG(UART_BRDH);    evbNs16550Chan1.ier =  UART1_REG(UART_IER);    evbNs16550Chan1.iid =  UART1_REG(UART_IID);    evbNs16550Chan1.mdc =  UART1_REG(UART_MDC);    evbNs16550Chan1.lst =  UART1_REG(UART_LST);    evbNs16550Chan1.msr =  UART1_REG(UART_MSR);    evbNs16550Chan1.outByte = sysOutByte;    evbNs16550Chan1.inByte  = sysInByte;    /*     * Only an internal serial clock source is supported in the 405EP.     * This clock source is the PLLOUTA frequency and must be divided     * down before being supplied to the UARTs.     * Determine what to divide the CPU clock by to get the     * the UARTx_SERIAL_CLK clocks.     */    sysSerialCalcDivisor(systemInfo.freqPLLOUTA / 1000000,                         CONSOLE_BAUD_RATE,                         &clkDivisor);    /* Set the divisors for both UARTs to be equal, but they don't have to be */    ucr = sysDcrInLong(CPC0_UCR);    ucr = ucr & ~(UCR_DIV_1_MASK | UCR_DIV_0_MASK);    sysDcrOutLong(CPC0_UCR, (ucr | (clkDivisor << 8) | clkDivisor));    evbNs16550Chan0.clkFreq = systemInfo.freqPLLOUTA / clkDivisor;    evbNs16550Chan1.clkFreq = systemInfo.freqPLLOUTA / clkDivisor;    /*     * Reset both devices     */    evbNs16550HrdInit(&evbNs16550Chan0);    evbNs16550HrdInit(&evbNs16550Chan1);    #ifdef INCLUDE_LCD    #ifndef PRJ_BUILD    #ifdef INCLUDE_SYSTEM_BOOT_PARA    if(0==CONSOLE_TTY){	evbNs16550Chan0.pDrvFuncs->txStartup=ca320240Startup;	    }    if(1==CONSOLE_TTY){	evbNs16550Chan0.pDrvFuncs->txStartup=ca320240Startup;	    }    #endif    #endif    #endif    }/******************************************************************************** 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()*/void sysSerialHwInit2    (    void    )    {    int intLevel = intLock ();    /*     * Connect serial interrupt handlers for S0 (UART 0)     * and enable serial interrupts for S0     */    (void) intConnect (INUM_TO_IVEC(INT_VEC_UART0), evbNs16550Int,                       (int) sysSerialChanGet(0));    intEnable (INT_LVL_UART0);    /*     * connect serial interrupt handlers for S1 (UART 1)     * and enable serial interrupts for S1     */    (void) intConnect (INUM_TO_IVEC(INT_VEC_UART1), evbNs16550Int,                       (int) sysSerialChanGet(1));    intEnable (INT_LVL_UART1);    intUnlock (intLevel);    }/******************************************************************************** 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 */    )    {    switch (channel)        {        case 0:                                 /* S0 */            return ((SIO_CHAN *)&evbNs16550Chan0);        case 1:                                 /* S1 */            return ((SIO_CHAN *)&evbNs16550Chan1);        default:            return ((SIO_CHAN *)ERROR);        }    }/******************************************************************************** sysSerialCalcDivisor - determines CPU clock to UART clock divisor** This routine determines the optimal CPU clock to UART clock divisor for a* given CPU frequency and desired baud rate.  This function is required only* when the serial clock is being derived from the CPU clock.** RETURNS: The optimal CPU to UART clock divisor, or ERROR**/STATUS sysSerialCalcDivisor    (    UINT freqInputMhz,    UINT baudRate,    UINT *divisor    )    {    int numEntries;    int i;    numEntries = sizeof(uartClkTbl) / sizeof(INT_SERIAL_INFO);    /*     * Search the table of processor frequencies and Baud rates to determine     * the optimal divisor for the UART clock speed     */    for (i=0; i < numEntries; i++)        {        if ((uartClkTbl[i].freqInputMhz == freqInputMhz) &&            (uartClkTbl[i].baudRate == baudRate))            {            *divisor = uartClkTbl[i].uartClkDivisor;            break;            }        }    if (i == numEntries)             /* not found */        return(ERROR);    return(OK);    }

⌨️ 快捷键说明

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