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

📄 syslib.c

📁 cpc-1631的BSP包for VxWorks操作系统
💻 C
📖 第 1 页 / 共 5 页
字号:
	PPC_EIEIO_SYNC;
    }
    }

/*******************************************************************************
*
* sysOutByteString - writes a string of bytes to an io address.
*
* This function writes a byte string to a specified io address.
*
* RETURNS: N/A
*/

void sysOutByteString
    (
    ULONG 	ioAddr,
    char * 	bufPtr,
    int   	nBytes
    )
    {
    int loopCtr;

    for (loopCtr = 0; loopCtr < nBytes; loopCtr++)
    {
	PPC_EIEIO_SYNC;
	*(char *)ioAddr = *bufPtr++;
	PPC_EIEIO_SYNC;
    }
    }

/*******************************************************************************
*
* sysInWordString - reads a string of words from an io address.
*
* This function reads a word string from a specified io address.
*
* RETURNS: N/A
*/

void sysInWordString
    (
    ULONG	ioAddr,
    UINT16 *	bufPtr,
    int		nWords
    )
    {
    int loopCtr;

    for (loopCtr = 0; loopCtr < nWords; loopCtr++)
    {
    	PPC_EIEIO_SYNC;
	*bufPtr++ = *(short *)ioAddr;
	PPC_EIEIO_SYNC;
    }
	
    }

/*******************************************************************************
*
* sysInWordStringRev - reads a string of words that are byte reversed
*
* This function reads a string of words that are byte reversed from a
* specified io address.
*
* RETURNS: N/A
*/

void sysInWordStringRev
    (
    ULONG      ioAddr,
    UINT16 *   bufPtr,
    int        nWords
    )
    {
    int loopCtr;

    for (loopCtr = 0; loopCtr < nWords; loopCtr++)
        *bufPtr++ = sysInWord (ioAddr);
    }

/*******************************************************************************
*
* sysOutWordString - writes a string of words to an io address.
*
* This function writes a word string from a specified io address.
*
* RETURNS: N/A
*/

void sysOutWordString
    (
    ULONG	ioAddr,
    UINT16 *	bufPtr,
    int		nWords
    )
    {
    int loopCtr;
	
    for (loopCtr = 0; loopCtr < nWords; loopCtr++)
    {
	PPC_EIEIO_SYNC;
	*(short *)ioAddr = *bufPtr++;
	PPC_EIEIO_SYNC;
    }
    
    }

/*******************************************************************************
*
* sysInLongString - reads a string of longwords from an io address.
*
* This function reads a longword string from a specified io address.
*
* RETURNS: N/A
*/

void sysInLongString
    (
    ULONG    ioAddr,
    ULONG *  bufPtr,
    int      nLongs
    )
    {
    int loopCtr;

    for (loopCtr = 0; loopCtr < nLongs; loopCtr++)
    {
	PPC_EIEIO_SYNC;
	*bufPtr++ = *(int *)ioAddr;
	PPC_EIEIO_SYNC;
    }
    }

/*******************************************************************************
*
* sysOutLongString - writes a string of longwords to an io address.
*
* This function writes a longword string from a specified io address.
*
* RETURNS: N/A
*/

void sysOutLongString
    (
    ULONG	ioAddr,
    ULONG *	bufPtr,
    int		nLongs 
    )
    {
    int loopCtr;

    for (loopCtr = 0; loopCtr < nLongs; loopCtr++)
    {
	PPC_EIEIO_SYNC;
	*(int *)ioAddr = *bufPtr++;
	PPC_EIEIO_SYNC;
    }

    }
#endif	/* INCLUDE_ATA_686 */



/*******************************************************************************
*
* sys107RegRead - read a 32-bit address MPC107 register
*
* Read a 32-bit address MPC107 register and returns
* a 32 bit value.  Swap the address to little endian before  
* writing it to config address since it is PCI, and swap the 
* value to big endian before returning to the caller.
*
* RETURNS: The contents of the specified MPC107 register.
*/

ULONG sys107RegRead
    ( 
    ULONG regNum 
    )
    {
    ULONG temp;

    /* swap the value to little endian */

    *(ULONG *) sysPciConfAddr = LONGSWAP(regNum); 

    PPC_EIEIO_SYNC;

    temp = *(ULONG *) sysPciConfData;

    PPC_EIEIO_SYNC;

    /* swap the data & return */

    return (LONGSWAP (temp));		
    }

/*******************************************************************************
*
* sys107RegWrite - write a 32-bit MPC107 register
*
* write a 32-bit address MPC107 register.
* Swap the address to little endian before writing it to config 
* address, and swap the value to little endian before writing.
*
* RETURNS: N/A
*/

void sys107RegWrite
    ( 
    ULONG regNum,
    ULONG value
    )
    {
    ULONG temp;

    /* swap the value to little endian */

    *(ULONG *) sysPciConfAddr = LONGSWAP(regNum); 

    PPC_EIEIO_SYNC;

    temp = LONGSWAP (value);

    *(ULONG *) sysPciConfData = temp;

    PPC_EIEIO_SYNC;

    }


/*******************************************************************************
*
* sysMemMapDetect - detect PCI address map A or B
* 
* This procedure detects the address map (A or B) on the Sandpoint and
* assigns proper values to some global variables.  First it assumes
* that the memory map is of Map B, then reads the Vendor and Device
* ids.  If the value does not match with what is expected, all global
* variables are then set for Map A.
*
* The following global variables are set to reflect the PCI address map:
* .CS
*    sysPciConfAddr
*    sysPciConfData 	
*    sysPciMstrCfgAdrs	
*    sysPciMstrIoLocal
*    sysPciMstrIackLocal	
*    sysPciMstrIsaMemLocal
*    sysPciMstrMemIoLocal
*    sysPciSlvMemLocal	
*    sysPciMstrMemIoBus	
* .CE
*
* RETURNS: N/A
*/

void sysMemMapDetect
    (
    void
    )
    {
    ULONG retVal;

    sysPciConfAddr              = MPC107_CFG_ADDR_CHRP;
    sysPciConfData              = MPC107_CFG_DATA_CHRP;
    sysPciMstrIsaIoLocal	= PCI_MSTR_ISA_IO_LOCAL_B;
    sysPciMstrCfgAdrs		= PCI_MSTR_CNFG_ADRS_B;
    sysPciMstrIoLocal		= PCI_MSTR_IO_LOCAL_B;
    sysPciMstrIackLocal		= PCI_MSTR_IACK_LOCAL_B;
    sysPciMstrIsaMemLocal	= PCI_MSTR_ISA_MEM_LOCAL_B;
    sysPciMstrMemIoLocal	= PCI_MSTR_MEMIO_LOCAL_B;
    sysPciSlvMemLocal		= PCI_SLV_MEM_LOCAL_B;
    sysPciMstrMemIoBus		= PCI_MSTR_MEMIO_BUS_B;

    retVal = sys107RegRead(MPC107_CFG_BASE);	/* Read Device & Vendor Ids */

    if ((retVal == MPC107_DEV_VEN_ID) ||	/* cmp with expected value */
        (retVal == PPMC8245_ID)     ||
        (retVal == MPC107_DEV_ID))
        {
        return;
        }
    else
        {
	sysPciConfAddr 		= MPC107_CFG_ADDR_PREP;
	sysPciConfData 		= MPC107_CFG_DATA_PREP;
	sysPciMstrIsaIoLocal	= PCI_MSTR_ISA_IO_LOCAL_A;
	sysPciMstrCfgAdrs	= PCI_MSTR_CNFG_ADRS_A;
        sysPciMstrIoLocal	= PCI_MSTR_IO_LOCAL_A;
	sysPciMstrIackLocal	= PCI_MSTR_IACK_LOCAL_A;
	sysPciMstrIsaMemLocal	= PCI_MSTR_ISA_MEM_LOCAL_A;
	sysPciMstrMemIoLocal	= PCI_MSTR_MEMIO_LOCAL_A;
        sysPciSlvMemLocal	= PCI_SLV_MEM_LOCAL_A;
	sysPciMstrMemIoBus	= PCI_MSTR_MEMIO_BUS_A;
        }

    PPC_EIEIO_SYNC;  
    }

/*******************************************************************************
*
* sysEUMBBARRead - read a register from the EPIC address space
*
* This function reads a register from the EPIC address space. The
* register number <regNum> is added to the offset of the EPIC base address
*
* NOMANUAL
*
* RETURNS:  the 32 bit little endian value of the register.
*/

ULONG sysEUMBBARRead
    (
    ULONG regNum
    )
    {
    ULONG temp;

    PPC_EIEIO_SYNC;  
    temp = *(ULONG *) (EUMBBAR_VAL + regNum) ;
    return (LONGSWAP(temp));
    }
	
/*******************************************************************************
*
* sysEUMBBARWrite -  write a register to the EPIC address space
*
* This function wrties a register to the EPIC address space. The
* register number <regNum> is added to the offset of the EPIC base address
* and the resulting address is loaded with <regVal>
*
* NOMANUAL
*
* RETURNS: N/A
*/

void sysEUMBBARWrite
    (
    ULONG regNum,
    ULONG regVal
    )
    {
  
    *(ULONG *) (EUMBBAR_VAL + regNum) = LONGSWAP(regVal);
    PPC_EIEIO_SYNC;  
    return ;
    }

#if  defined(INCLUDE_NVRAM)
/*******************************************************************************
*
* sysNvramHwInit - initialize the NVRAM to use for boot string
*
* This routine initializes the NVRAM on the Sandpoint BBSRAM.
*
* RETURNS: N/A
*/

void sysNvramHwInit 
    (
    void
    )
    {
    /* Enable the RTC and PWR registers */
#if 0
    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_LUNINDEX, SIO_LUN_RTC);
    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_ACTIVATE, SIO_LUNDISABLE);
    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_IOBASEHI, SUPER_IO_RTC_BASEHI);
    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_IOBASELO, SUPER_IO_RTC_BASELO);
    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_ACTIVATE, SIO_LUNENABLE);
    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_LUNINDEX, SIO_LUN_PWR);
    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_ACTIVATE, SIO_LUNENABLE);

    /* Init the card control/Chip select registers */

    /* CS0 Base Address MSB Register */

    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_PCSCI, SIO_CS0_MSB);
    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_PCSCD, MSB(DATA_REG));

    /* CS0 Base Address LSB Register */

    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_PCSCI, SIO_CS0_LSB);
    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_PCSCD, LSB(DATA_REG));

    /* CS0 Configuration Register */

    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_PCSCI, SIO_CS0_CFG);
    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_PCSCD, NV_RAM_CSX_CNFG);

    /* CS1 Base Address MSB Register */

    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_PCSCI, SIO_CS1_MSB);
    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_PCSCD, MSB(LSB_INDX_REG));

    /* CS1 Base Address LSB Register */

    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_PCSCI, SIO_CS1_LSB);
    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_PCSCD, LSB(LSB_INDX_REG));

    /* CS1 Configuration Register */

    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_PCSCI, SIO_CS1_CFG);
    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_PCSCD, NV_RAM_CSX_CNFG);

    /* CS2 Base Address MSB Register */

    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_PCSCI, SIO_CS2_MSB);
    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_PCSCD, MSB(MSB_INDX_REG));

    /* CS2 Base Address LSB Register */

    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_PCSCI, SIO_CS2_LSB);
    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_PCSCD, LSB(MSB_INDX_REG)); 

    /* CS2 Configuration Register */   

    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_PCSCI, SIO_CS2_CFG);
    sysSioWrite (SUPER_IO_BASE_ADRS, SIO_PCSCD, NV_RAM_CSX_CNFG); 
#endif
    }

#endif

/*******************************************************************************
*
* sysNvRead - read one byte from NVRAM
*
* This routine reads a single byte from a specified offset in NVRAM.
*
* RETURNS: The byte from the specified NVRAM offset.
*/

UCHAR sysNvRead
    (
    ULONG	offset	/* NVRAM offset to read the byte from */
    )
    {
#if  defined(INCLUDE_NVRAM)
    sysOutByte (NV_RAM_MSB_REG, MSB(offset));
    sysOutByte (NV_RAM_LSB_REG, LSB(offset));
    return (sysInByte (NV_RAM_DAT_REG));
#endif /* INCLUDE_NVRAM */
    }

/*******************************************************************************
*
* sysNvWrite - write one byte to NVRAM
*
* This routine writes a single byte to a specified offset in NVRAM. 
*
* RETURNS: N/A
*/

void sysNvWrite
    (
    ULONG	offset,	/* NVRAM offset to write the byte to */
    UCHAR	data	/* datum byte */
    )
    {
#if  defined(INCLUDE_NVRAM)
    sysOutByte (NV_RAM_MSB_REG, MSB(offset));
    sysOutByte (NV_RAM_LSB_REG, LSB(offset));
    sysOutByte (NV_RAM_DAT_REG, data);
#end

⌨️ 快捷键说明

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