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

📄 syslib.c

📁 MPC8241:本程序是freescale的824*系列的BSP源程序
💻 C
📖 第 1 页 / 共 5 页
字号:
* sysPhysMemTop - get the address of the top of physical memory
*
* This routine returns the address of the first missing byte of memory,
* which indicates the top of memory.
*
* Normally, the user specifies the amount of physical memory with the
* macro LOCAL_MEM_SIZE in config.h.  BSPs that support run-time
* memory sizing do so only if the macro LOCAL_MEM_AUTOSIZE is defined.
* If not defined, then LOCAL_MEM_SIZE is assumed to be, and must be, the
* true size of physical memory.
*
* NOTE: Do no adjust LOCAL_MEM_SIZE to reserve memory for application
* use.  See sysMemTop() for more information on reserving memory.
*
* RETURNS: The address of the top of physical memory.
*
* SEE ALSO: sysMemTop()
*/

char * sysPhysMemTop (void)
    {

    static char * sysPhysMemSize = NULL;	/* ptr to top of mem + 1 */

    if (sysPhysMemSize == NULL)
	{
	/* Don't do auto-sizing, use defined constants. */
	sysPhysMemSize = (char *)(LOCAL_MEM_LOCAL_ADRS + LOCAL_MEM_SIZE);
	}

    return sysPhysMemSize;
    }


/*******************************************************************************
*
* sysMemTop - get the address of the top of VxWorks memory
*
* This routine returns a pointer to the first byte of memory not
* controlled or used by VxWorks.
*
* The user can reserve memory space by defining the macro USER_RESERVED_MEM
* in config.h.  This routine returns the address of the reserved memory
* area.  The value of USER_RESERVED_MEM is in bytes.
*
* RETURNS: The address of the top of VxWorks memory.
*/

char * sysMemTop (void)
    {
    static char * memTop = NULL;

    if (memTop == NULL)
	{
	memTop = sysPhysMemTop () - USER_RESERVED_MEM;
	}

    return memTop;
    }


/******************************************************************************
*
* sysToMonitor - transfer control to the ROM monitor
*
* This routine transfers control to the ROM monitor.  Normally, it is called
* only by reboot()--which services ^X--and by bus errors at interrupt level.
* However, in some circumstances, the user may wish to introduce a
* <startType> to enable special boot ROM facilities.
*
* RETURNS: Does not return.
*/

STATUS sysToMonitor
    (
    int startType	/* parameter passed to ROM to tell it how to boot */
    )
    {
    FUNCPTR pRom = (FUNCPTR) (ROM_TEXT_ADRS + 4); /* Warm reboot */

    cacheDisable (0);   	/* Disable the Instruction Cache */
    cacheDisable (1);   	/* Disable the Data Cache */

#if     (CPU == PPC604)
    vxHid0Set (vxHid0Get () & ~_PPC_HID0_SIED);	/* Enable Serial Instr Exec */
#endif  /* (CPU == PPC604) */

    sysSerialReset ();		/* reset serial devices */

    /* Clear the MSR */

    vxMsrSet (0);

    /* Reset the EPIC */

    sysPciOutLong((UINT32)EPIC_GLOBAL_CONFIG_REG, EPIC_GC_RESET);

/*7.28*/
#if(0)
    /* set the Board Fail LED */

    *(UINT8 *)PRPMC600_SYS_STAT_REG2 |= PRPMC600_BD_FAIL;
#endif
    (*pRom) (startType);

    return (OK);	/* in case we ever continue from ROM monitor */
    }


/******************************************************************************
*
* sysHwInit2 - initialize additional system hardware
*
* This routine connects system interrupt vectors and configures any 
* required features not configured by sysHwInit().
*
* RETURNS: N/A
*/

void sysHwInit2 (void)
    {
    static BOOL configured = FALSE;

    /* Int connects for various devices */

    if (!configured)
	{
#ifdef INCLUDE_AUXCLK
        sysAuxClkInit ();
        intConnect (INUM_TO_IVEC(TIMER0_INT_VEC), sysAuxClkInt, 0);
        intEnable (TIMER0_INT_LVL);
#endif /* INCLUDE_AUXCLK */

/* add by zoutl for BSP test 2003-5-30 14:31 */
#ifdef BSP_TEST
		sysAuxClk1Init();
		/* add by zoutl for really enable interrupt */
    	intConnect (INUM_TO_IVEC((int)TIMER1_INT_LVL),sysAuxClk1Int, (int) 0);    
    	intEnable (TIMER1_INT_LVL);   
#endif

	/* initialize serial interrupts */

	sysSerialHwInit2();
    /*in sysnet.c*/


#ifdef INCLUDE_NETWORK

	/* configure the interrupts for the network hardware. */

	sysNetHwInit2 ();
#endif

#ifdef INCLUDE_SM_NET
        sysSmParamsCompute ();
#endif

	configured = TRUE;
	}
    }


/******************************************************************************
*
* sysProcNumGet - get the processor number
*
* This routine returns the processor number for the CPU board, which is
* set with sysProcNumSet().
*
* RETURNS: The processor number for the CPU board.
*
* SEE ALSO: sysProcNumSet()
*/

int sysProcNumGet (void)
    {
    return (sysProcNum);
    }


/******************************************************************************
*
* sysProcNumSet - set the processor number
*
* This routine sets the processor number for the CPU board.  Processor numbers
* should be unique on a single backplane.  It also maps local resources onto
* the VMEbus.
*
* RETURNS: N/A
*
* SEE ALSO: sysProcNumGet()
*
*/

void sysProcNumSet
    (
    int 	procNum			/* processor number */
    )
    {

    /*  Init the global variable */

    sysProcNum = procNum;

    }


/* miscellaneous support routines */

/******************************************************************************
*
* sysMpc8240TransAdrs - translate an address that passes through the mpc8240.
*
* This routine converts an address from a cpu to pci address or vice versa. It
* uses a pair of window arrays built during hardware init2 to guide the
* translation. The adrs parameter is the address to convert.
*
* RETURNS: OK, or ERROR if the address space is unknown or the mapping is not
* possible.
*
* SEE ALSO: sysMpc8240Capt()
*
*/

LOCAL STATUS sysMpc8240TransAdrs
    (
    UINT32            adrsSpace,    /* address space (memory or i/o ) */
    UINT32            adrs,         /* known address */
    UINT32 *          pTransAdrs,   /* pointer to the translated address */
    UINT32            winCnt,       /* number of open windows */
    MPC8240_WIN_STRUCT * pSrc,         /* pointer to the source windows */
    MPC8240_WIN_STRUCT * pDest         /* pointer to the destination windows */
    )
    {

    while (winCnt--)
        {

        /* check for a match on window type and in bounds */

        if ( (pSrc->winType == adrsSpace) &&
             (adrs >= pSrc->winBase) &&
             (adrs <= pSrc->winLimit) )
            {
            *pTransAdrs = ( adrs - pSrc->winBase + pDest->winBase );

            return (OK);
            };

        /* advance to next window */

        pSrc++;
        pDest++;
        }

    /*
     * no window was found to contain adrs. indicate that translation was
     * not possible.
     */

    return (ERROR);

    }


/******************************************************************************
*
* sysCpuToPciAdrs - translate a cpu address to a pci bus address
*
* This routine converts an address as seen from the cpu to the equivalent pci
* address, if it exists. The input address is the address as seen by the cpu.
*
* RETURNS: OK, or ERROR if the address space is unknown or the mapping is not
* possible.
*
* SEE ALSO: sysPciToCpuAdrs()
*/

LOCAL STATUS sysCpuToPciAdrs
    (
    int     adrsSpace,  /* bus address space where busAdrs resides */
    char *  localAdrs,  /* local address to convert */
    char ** pBusAdrs    /* where to return bus address */
    )
    {
    return (sysMpc8240TransAdrs (adrsSpace, (UINT32)localAdrs, 
				(UINT32 *)pBusAdrs, MPC8240_WIN_CNT,
                                &sysMpc8240CpuToPciWin[0],
                                &sysMpc8240PciToCpuWin[0]) );
    }


/******************************************************************************
*
* sysPciToCpuAdrs - translate a pci bus address to a cpu address
*
* This routine converts an address as seen from the pci bus to the equivalent
* cpu address, if it exists. The input address is the address as seen by the
* pci bus.
*
* RETURNS: OK, or ERROR if the address space is unknown or the mapping is not
* possible.
*
* SEE ALSO: sysCpuToPciAdrs()
*/

LOCAL STATUS sysPciToCpuAdrs
    (
    int     adrsSpace,  /* bus address space where busAdrs resides */
    char *  localAdrs,  /* local address to convert */
    char ** pBusAdrs    /* where to return bus address */
    )
    {
    return (sysMpc8240TransAdrs (adrsSpace, (UINT32)localAdrs, 
				(UINT32 *)pBusAdrs, MPC8240_WIN_CNT,
                                &sysMpc8240PciToCpuWin[0],
                                &sysMpc8240CpuToPciWin[0]) );
    }


/******************************************************************************
*
* sysLocalToBusAdrs - convert a local CPU address to a PCI bus address
*
* Given a CPU address, this routine returns a corresponding local PCI bus
* or Compact (backpanel) PCI bus address provided that such an address exists.
* The target PCI bus (local or backpanel) is selected by the adrsSpace
* parameter. Legal values for this parameter are found in "pci.h". If a
* transparent bridge is used to access the Compact PCI bus, the local PCI bus
* and the backpanel PCI bus share the same address space. In this case, the
* local and backpanel address space designators are synonomous.
*
* RETURNS: OK, or ERROR if the address space is unknown or the mapping is not
* possible.
*
* SEE ALSO: sysBusToLocalAdrs()
*/

STATUS sysLocalToBusAdrs
    (
    int     adrsSpace,  /* bus address space where busAdrs resides */
    char *  localAdrs,  /* local address to convert */
    char ** pBusAdrs    /* where to return bus address */
    )
    {

    switch (adrsSpace)
        {

        case PCI_SPACE_IO_PRI:
        case PCI_SPACE_IO_SEC:

            /* convert from cpu address space to local pci space */

            if ( sysCpuToPciAdrs (PCI_BAR_SPACE_IO, localAdrs, pBusAdrs) != OK )
                return (ERROR);


#ifdef INCLUDE_DEC2155X

            /*
             * if continuing on to the backpanel using the dec2155x, translate
             * from local pci space to compact pci space.
             */

            if ( PCI_SPACE_IS_CPCI(adrsSpace) )
                return ( sysPciToCpciAdrs (PCI_BAR_SPACE_IO, *pBusAdrs,
                                           pBusAdrs) );

#endif /* INCLUDE_DEC2155X */
            break;

        case PCI_SPACE_MEMIO_PRI:
        case PCI_SPACE_MEM_PRI:
        case PCI_SPACE_MEMIO_SEC:
        case PCI_SPACE_MEM_SEC:

            /* convert from cpu address space to local pci address space */

            if (sysCpuToPciAdrs (PCI_BAR_SPACE_MEM, localAdrs, pBusAdrs) != OK )
                return (ERROR);

#ifdef INCLUDE_DEC2155X

            /*
             * if continuing on to the backpanel using the dec2155x, translate
             * from local pci space to compact pci space.
             */

            if ( PCI_SPACE_IS_CPCI(adrsSpace) )
                return ( sysPciToCpciAdrs(PCI_BAR_SPACE_MEM, *pBusAdrs,
                                          pBusAdrs) );

#endif /* INCLUDE_DEC2155X */
            break;

        default:
            return (ERROR);
            break;
        }
    return (OK);

    }


/******************************************************************************
*
* sysBusToLocalAdrs - convert a PCI bus address to a local CPU address
*
* Given a local or Compact (backpanel) PCI address, this routine returns a
* corresponding local CPU bus address provided such an address exists. The
* originating PCI bus (local or backpanel) is selected by the adrsSpace
* parameter. Legal values for this parameter are found in "pci.h". If a
* transparent bridge is used to access the Compact PCI bus, the local PCI bus
* and the Compact PCI bus share the same address space. In this case, the
* local and backpanel address space designators are synonomous.
*
* RETURNS: OK, or ERROR if the address space is unknown or the mapping is not
* possible.
*
* SEE ALSO: sysLocalToBusAdrs()
*/

STATUS sysBusToLocalAdrs
    (
    int     adrsSpace,  /* bus address space where busAdrs resides */
    char *  busAdrs,    /* bus address to convert */
    char ** pLocalAdrs  /* where to return local address */
    )
    {

    switch (adrsSpace)
        {

        case PCI_SPACE_IO_SEC:

⌨️ 快捷键说明

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