📄 syslib.c
字号:
* configuration register. This is why the sysPciTrap routine* is essential.** RETURNS: N/A*/void sysPciTrap ( ESFPPC * pEsf /* pointer to exception stack frame */ ) { REG_SET *pRegSet = &pEsf->regSet; pRegSet->pc = (_RType)sysPciErr; /* sysPciErr forces a -1 return */ }/******************************************************************************** sysMsDelay - delay for the specified amount of time (MS)** This routine will delay for the specified amount of time by counting* decrementer ticks.** This routine is not dependent on a particular rollover value for* the decrementer, it should work no matter what the rollover* value is.** A small amount of count may be lost at the rollover point resulting in* the sysMsDelay() causing a slightly longer delay than requested.** This routine will produce incorrect results if the delay time requested* requires a count larger than 0xffffffff to hold the decrementer* elapsed tick count. For an MBX860 40MHz board that amounts to about* 1716 seconds (thus not considered too severe a restriction).** RETURNS: N/A*/void sysMsDelay ( UINT delay /* length of time in MS to delay */ ) { register UINT oldval; /* decrementer value */ register UINT newval; /* decrementer value */ register UINT totalDelta; /* Dec. delta for entire delay period */ register UINT decElapsed; /* cumulative decrementer ticks */ /* Calculate delta of decrementer ticks for desired elapsed time. */ totalDelta = ((sysMbxIntClkSpd / DEC_CLK_TO_INC) / 1000) * delay; /* * Now keep grabbing decrementer value and incrementing "decElapsed" until * we hit the desired delay value. Compensate for the fact that we may * read the decrementer at 0xffffffff before the interrupt service * routine has a chance to set in the rollover value. */ decElapsed = 0; oldval = sysDecGet (); while (decElapsed < totalDelta) { newval = sysDecGet (); if ( DELTA(oldval,newval) < 1000 ) decElapsed += DELTA(oldval,newval); /* no rollover */ else if (newval > oldval) decElapsed += abs((int)oldval); /* rollover */ oldval = newval; } }/********************************************************************************* sysIntEnablePIC - enable an ISA/PCI interrupt** This function call is used by certain vxWorks device drivers. It * calls the system routine intConnect.** RETURNS: OK or ERROR*/STATUS sysIntEnablePIC ( int intNum ) { return (intEnable (intNum) == 0 ? OK : ERROR); }/******************************************************************************** sysDelay - delay for approx. 1ms** This implements an unsupported system call to support drivers* ported from Intel platforms.** RETURNS: N/A*/void sysDelay (void) { sysMsDelay (1); }/******************************************************************************** sysAtaInit - initialize the EIDE/ATA interface** Perform the necessary initialization required before starting up the* ATA/EIDE driver.*/void sysAtaInit ( int pciBusNo, /* PCI bus number */ int pciDevNo, /* PCI device number */ int pciFuncNo /* PCI function number */ ) {#ifdef INCLUDE_ATA UINT16 readValue; int baseAddr; /* read the WINBOND IDE Device Control register */ pciConfigInWord (pciBusNo, pciDevNo, pciFuncNo, PCI_CFG_COMMAND, &readValue); /* enable the IDE I/O decodes */ readValue |= PCI_CMD_IO_ENABLE; /* disable bus master mode, memory write and invalidate bits */ readValue &= ~(PCI_CMD_MASTER_ENABLE | PCI_CMD_WI_ENABLE); pciConfigOutWord (pciBusNo, pciDevNo, pciFuncNo, PCI_CFG_COMMAND, readValue ); /* read the Port0 and Port1 Primary/Auxillary Register addresses */ pciConfigInLong (pciBusNo, pciDevNo, pciFuncNo, PCI_CFG_BASE_ADDRESS_0, &baseAddr); ataResources[0].resource.ioStart[0] = (CPU_PCI_IO_BA | (baseAddr & PCI_IOBASE_MASK)); pciConfigInLong (pciBusNo, pciDevNo, pciFuncNo, PCI_CFG_BASE_ADDRESS_1, &baseAddr); /* Base Address Reg 1 only decodes byte lane 2 */ ataResources[0].resource.ioStart[1] = (CPU_PCI_IO_BA | ((baseAddr & PCI_IOBASE_MASK) + 2)); pciConfigInLong (pciBusNo, pciDevNo, pciFuncNo, PCI_CFG_BASE_ADDRESS_2, &baseAddr); ataResources[1].resource.ioStart[0] = (CPU_PCI_IO_BA | (baseAddr & PCI_IOBASE_MASK)); pciConfigInLong (pciBusNo, pciDevNo, pciFuncNo, PCI_CFG_BASE_ADDRESS_3, &baseAddr); /* Base Address Reg 3 only decodes byte lane 2 */ ataResources[1].resource.ioStart[1] = (CPU_PCI_IO_BA | ((baseAddr & PCI_IOBASE_MASK) + 2)); pciConfigInLong (pciBusNo, pciDevNo, pciFuncNo, PCI_CFG_BASE_ADDRESS_3, &baseAddr); /* * initialize the remainder of the ataRsources structure * * initialize the Controller 0 data structure */ ataResources[0].ctrlType = IDE_LOCAL; ataResources[0].drives = 2; ataResources[0].intVector = IVEC_TO_INUM (IV_IDE0); /* Interrupt number */ ataResources[0].intLevel = IVEC_TO_ILVL (IV_IDE0); /* Interrupt level */ ataResources[0].configType = (ATA_PIO_AUTO | ATA_GEO_PHYSICAL); ataResources[0].semTimeout = 0; ataResources[0].wdgTimeout = 0; /* initialize the Controller 1 data structure */ ataResources[1].ctrlType = IDE_LOCAL; ataResources[1].drives = 2; ataResources[1].intVector = IVEC_TO_INUM (IV_IDE1); /* Interrupt Number */ ataResources[1].intLevel = IVEC_TO_ILVL (IV_IDE1); /* Interrupt Level */ ataResources[1].configType = (ATA_PIO_AUTO | ATA_GEO_PHYSICAL); ataResources[1].semTimeout = 0; ataResources[1].wdgTimeout = 0;#endif /* INCLUDE_ATA */ }/******************************************************************************** sysMbxIntConnect - generic interrupt connect call for MBX860** This functions intercepts the system call: intConnect and determines* which of the specific interrupt connect routines to call, either the* ppc860IntrCtl or the w83c553f.** RETURNS: OK or ERROR if interrupt is not for SIU, CPM, PCI or ISA */LOCAL STATUS sysMbxIntConnect ( VOIDFUNCPTR * vector, /* interrupt vector to attach to */ VOIDFUNCPTR routine, /* routine to be called */ int parameter /* parameter to be passed to routine */ ) { STATUS result; int int_class = INT_CLASS((int)vector); switch (int_class) { case INT_CLASS_PPC860: case INT_CLASS_CPM: result = ppc860IntConnect (vector, routine, parameter); break; case INT_CLASS_RES: result = ERROR; break; case INT_CLASS_ISA_PCI: result = sysIbcIntConnect (vector, routine, parameter); break; default: result = ERROR; } return (result); }/********************************************************************************* sysMbxIntEnable - enable an MBX interrupt level** This routine enables a specified MBX interrupt level.** RETURNS: OK or ERROR if interrupt level not supported*/LOCAL int sysMbxIntEnable ( int intLevel /* interrupt level to enable */ ) { int ret_val; int int_class = INT_CLASS(intLevel); switch (int_class) { case INT_CLASS_PPC860: ppc860IntEnable (intLevel); ret_val = OK; break; case INT_CLASS_RES: ret_val = ERROR; break; case INT_CLASS_CPM: ret_val = ERROR; break; case INT_CLASS_ISA_PCI: intLevel = (intLevel - IVEC_TO_INUM(IV_ISA_INT0)); sysIbcIntEnable (intLevel); ret_val = OK; break; default: ret_val = ERROR; } return (ret_val); }/********************************************************************************* sysMbxIntDisable - disable an MBX interrupt level** This routine disables a specified MBX interrupt level.** RETURNS: OK or ERROR if interrupt level not supported*/LOCAL int sysMbxIntDisable ( int (intLevel) /* interrupt level to disable */ ) { int ret_val; int int_class = INT_CLASS(intLevel); switch (int_class) { case INT_CLASS_PPC860: ppc860IntDisable (intLevel); ret_val = OK; break; case INT_CLASS_RES: ret_val = ERROR; break; case INT_CLASS_CPM: ret_val = ERROR; break; case INT_CLASS_ISA_PCI: intLevel = (intLevel - IVEC_TO_INUM (IV_ISA_INT0)); sysIbcIntDisable (intLevel); ret_val = OK; break; default: ret_val = ERROR; } return (ret_val); }/******************************************************************************* sysInByteString - reads a string of bytes from an io address.** This function reads a byte string from a specified io address.** RETURNS: N/A*/void sysInByteString ( ULONG ioAddr, /* I/O address */ UCHAR * bufPtr, /* pointer to data buffer */ int nBytes /* number of bytes to read */ ) { int loopCtr; for (loopCtr = 0; loopCtr < nBytes; loopCtr++) *bufPtr++ = *(char *)ioAddr; }/******************************************************************************* 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, /* I/O address */ UCHAR * bufPtr, /* pointer to data buffer */ int nBytes /* number of bytes to write */ ) { int loopCtr; for (loopCtr = 0; loopCtr < nBytes; loopCtr++) *(char *)ioAddr = *bufPtr++; }/******************************************************************************* 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, /* I/O address */ UINT16 * bufPtr, /* pointer to data buffer */ int nWords /* number of 2 byte words to read */ ) { int loopCtr; for (loopCtr = 0; loopCtr < nWords; loopCtr++) *bufPtr++ = *(short *)ioAddr; }/******************************************************************************* sysInWordStringRev - byte reversed word read. ** This function reads a byte reversed word string from a specified io address.** RETURNS: N/A*/void sysInWordStringRev ( ULONG ioAddr, /* I/O address */ UINT16 * bufPtr, /* pointer to data buffer */ int nWords /* number of 2 byte words to read */ ) { int loopCtr; for (loopCtr = 0; loopCtr < nWords; loopCtr++) *bufPtr++ = sysInWordRev(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, /* I/O address */ UINT16 * bufPtr, /* pointer to data buffer */ int nWords /* number of 2 byte words to write */ ) { int loopCtr; for (loopCtr = 0; loopCtr < nWords; loopCtr++) *(short *)ioAddr = *bufPtr++; }/******************************************************************************* 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, /* I/O address */ ULONG * bufPtr, /* pointer to data buffer */ int nLongs /* number of 4 byte words to read */ ) { int loopCtr; for (loopCtr = 0; loopCtr < nLongs; loopCtr++) *bufPtr++ = *(int *)ioAddr; }/******************************************************************************* 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, /* I/O address */ ULONG * bufPtr, /* pointer to data buffer */ int nLongs /* number of 4 byte words to write */ ) { int loopCtr; for (loopCtr = 0; loopCtr < nLongs; loopCtr++) *(int *)ioAddr = *bufPtr++; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -