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

📄 usbpcistub.c

📁 Vxworks下BSP源码
💻 C
字号:
/*9200 USB host*//* Includes */#include "vxWorks.h"#include "string.h"#include "sysLib.h"#include "cacheLib.h"#include "iv.h"#include "intLib.h"/*#include "drv/pci/pciConfigLib.h"*/   /* VxWorks PCI funcs */#include "usb/usbPlatform.h"		/* Basic definitions */#include "usb/usbPciLib.h"			/* Our API */#include "drv/usb/usbOhci.h"                /* OHCI definitions */#define USB_BASE_ADDR		0x300000		/*USB host port :0x300000-0x3fffff*/#define USB_HOST_INT_NUM	23/*just for :)*/#define BUSNO	10#define DEVNO	10#define FUNCNO	10#define sysOutByte(addr,data)	(*((UINT8  *) (addr)) = ((UINT8)  (data)))#define sysOutWord(addr,data)   (*((UINT16 *) (addr)) = ((UINT16) (data)))#define sysOutLong(addr,data)   (*((UINT32 *) (addr)) = ((UINT32) (data)))#define sysInByte(addr)         (*((UINT8  *) (addr)))#define sysInWord(addr)         (*((UINT16 *) (addr)))#define sysInLong(addr)         (*((UINT32 *) (addr)))#define INT_CONNECT(intNo, func, param)	\	intConnect (INUM_TO_IVEC(intNo), (VOIDFUNCPTR) (func), (int) (param))#define INT_DISCONNECT(intNo, func, param)#define INT_ENABLE(i)		intEnable(i)#define INT_DISABLE(i)		intDisable(i)/* Map I/O functions to underlying system functions. */#define	USB_IN_BYTE(a)		sysInByte ((a) + USB_BASE_ADDR)#define	USB_IN_WORD(a)		sysInWord ((a) + USB_BASE_ADDR)#define	USB_IN_DWORD(a)		sysInLong ((a) + USB_BASE_ADDR)#define	USB_OUT_BYTE(a,v)	sysOutByte ((a) + USB_BASE_ADDR, (v))#define	USB_OUT_WORD(a,v)	sysOutWord ((a) + USB_BASE_ADDR, (v))#define	USB_OUT_DWORD(a,v)	sysOutLong ((a) + USB_BASE_ADDR, (v))/* locals */LOCAL UINT32 sysUsbInitialised;/********************************************************************************* sysUsbPciInit - perform low level pci init of all Ohci class pci devices** This routine discovers and assigns PCI resources to all installed* USB class devices. In the case of the OPTI chip, it is one device* per chip. The 4 Port Lucent chip is a multi-function device with* 4 single port USB devices/functions.** NOTE: This routine should not be called directly by the user.** RETURNS: N/A*/void sysUsbPciInit()    {    /*     * Initialise only once     */    if( sysUsbInitialised )        return;     sysUsbInitialised = 1;    }/***************************************************************************** usbPciClassFind - Locates PCI devices by class.** RETURNS: TRUE if matching device found*	   FALSE if device not found*/BOOL usbPciClassFind    (    UINT8 pciClass,		/* PCI device class */    UINT8 subClass,		/* PCI device sub-class */    UINT8 pgmIf,		/* Programming interface */    UINT16 index,		/* Caller wants nth matching dev */    pUINT8 pBusNo,		/* Bus number of matching dev */    pUINT8 pDeviceNo,		/* Device number of matching dev */    pUINT8 pFuncNo		/* Function number of matching dev */    )    {    	if(index > 0)    		return FALSE;    	else    	{			*pBusNo = (UINT8) BUSNO;			*pDeviceNo = (UINT8) DEVNO;			*pFuncNo = (UINT8) FUNCNO;	 		return TRUE;    		    		  		    	}    		    }/***************************************************************************** usbPciByteGet - Returns a UINT8 configuration value** This function returns the UINT8 value at offset <regOffset> ** RETURNS: UINT8 value read from device configuration space*/UINT8 usbPciByteGet     (    UINT8 busNo,		/* Bus number of device */    UINT8 deviceNo,		/* Device number of device */    UINT8 funcNo,		/* Function number of device */    UINT16 regOffset		/* Offset into PCI config space */    )    {    UINT8 value;    value = USB_IN_BYTE(regOffset);    return value;    }/***************************************************************************** usbPciWordGet - Returns a UINT16 configuration value** RETURNS: UINT16 value read from device configuration space*/UINT32 usbPciWordGet    (    UINT8 busNo,		/* Bus number of device */    UINT8 deviceNo,		/* Device number of device */    UINT8 funcNo,		/* Function number of device */    UINT16 regOffset		/* Offset into PCI config space */    )    {    UINT16 value;    value = USB_IN_WORD(regOffset);    return value;    }/***************************************************************************** usbPciDwordGet - Returns a UINT32 configuration value** This function returns the UINT32 value at offset <regOffset> from * the PCI configuration space of the device identified by <busNo>, * <deviceNo>, and <funcNo>.** NOTE: This function adjusts for big vs. little endian environments.** RETURNS: UINT32 value read from device configuration space*/UINT32 usbPciDwordGet    (    UINT8 busNo,		/* Bus number of device */    UINT8 deviceNo,		/* Device number of device */    UINT8 funcNo,		/* Function number of device */    UINT16 regOffset		/* Offset into PCI config space */    )    {    UINT32 value;    value = USB_IN_DWORD(regOffset);    return value;    }/***************************************************************************** usbPciConfigHeaderGet - Reads a device's PCI configuration header** This function reads the PCI configuration header for the device* identified by <busNo>, <deviceNo>, and <funcNo>.  The configuration* header is stored in the <pCfgHdr> buffer provided by the caller.** This function initializes the <pCfgHdr> structure to zeros.  Any * fields which cannot be read from the device's configuration header * will remain zero upon return.  This function does not attempt to read* fields defined as "reserved" in the PCI configuration header.** RETURNS: N/A*/VOID usbPciConfigHeaderGet    (    UINT8 busNo,		/* Bus number of device */    UINT8 deviceNo,		/* Device number of device */    UINT8 funcNo,		/* Function number of device */    pPCI_CFG_HEADER pCfgHdr	/* Buffer provided by caller */    )    {    int i;    /* Do nothing if CfgHdr is NULL */    if (pCfgHdr == NULL)	return;    /* Initialize the buffer to zeros. some parameters have no means....*/    memset (pCfgHdr, 0, sizeof (*pCfgHdr));    pCfgHdr->vendorId	= 0x1234;    pCfgHdr->deviceId	= 0x1234;    pCfgHdr->command	= 0x1234;    pCfgHdr->status	= 0x1234;    pCfgHdr->revisionId = 0x12;    pCfgHdr->pgmIf	= 0x12;    pCfgHdr->subClass	= 0x12;    pCfgHdr->pciClass	= 0x12;    pCfgHdr->cacheLineSize = 8;    pCfgHdr->latencyTimer = 0x12;    pCfgHdr->headerType = 0;		/*type 0*/    pCfgHdr->bist	= 0x12;         for (i = 0; i < PCI_CFG_NUM_BASE_REG; i++)    {		pCfgHdr->baseReg [0] = USB_BASE_ADDR;		/*base addr ,mem map,32addrs*/	        }        pCfgHdr->romBase	= 0;    pCfgHdr->intLine	= USB_HOST_INT_NUM;	/*INT no of usb*/	    pCfgHdr->intPin	= 0;    pCfgHdr->minGrant	= 0x1;    pCfgHdr->maxLatency = 0x10;       }/***************************************************************************** usbPciByteIn - input a byte from PCI I/O space** Inputs a byte from a PCI I/O address <address>.** RETURNS: byte input from i/o address*/UINT8 usbPciByteIn    (    UINT32 address		/* PCI I/O address */    )    {    return USB_IN_BYTE (address);    }/***************************************************************************** usbPciWordIn - input a word from PCI I/O space** Inputs a word from a PCI I/O address <address>.** NOTE: This function adjusts for big vs. little endian environments.** RETURNS: word input from i/o address*/UINT16 usbPciWordIn    (    UINT32 address		/* PCI I/O address */    )    {    UINT16 w = USB_IN_WORD (address);    return FROM_LITTLEW (w);    }/***************************************************************************** usbPciDwordIn - input a dword from PCI I/O space** Inputs a dword from a PCI I/O address <address>.** NOTE: This function adjusts for big vs. little endian environments.** RETURNS: dword input from i/o address*/UINT32 usbPciDwordIn    (    UINT32 address		/* PCI I/O address */    )    {    UINT32 l = USB_IN_DWORD (address);    return FROM_LITTLEL (l);    }/***************************************************************************** usbPciByteOut - output a byte to PCI I/O space** Outputs <value> to the PCI I/O address <address>.** RETURNS: N/A*/VOID usbPciByteOut    (    UINT32 address,		/* PCI I/O address */    UINT8 value 		/* value */    )    {    USB_OUT_BYTE (address, value);    CACHE_PIPE_FLUSH ();    }/***************************************************************************** usbPciWordOut - outputs a word to PCI I/O space** Outputs <value> to the PCI I/O address <address>.** NOTE: This function adjusts for big vs. little endian environments.** RETURNS: N/A*/VOID usbPciWordOut    (    UINT32 address,		/* PCI I/O address */    UINT16 value		/* value */    )    {    UINT16 w = TO_LITTLEW (value);    USB_OUT_WORD (address, w);    CACHE_PIPE_FLUSH ();    }/***************************************************************************** usbPciDwordOut - outputs a dword to PCI I/O space** Outputs <value> to the PCI I/O address <address>.** NOTE: This function adjusts for big vs. little endian environments.** RETURNS: N/A*/VOID usbPciDwordOut    (    UINT32 address,		/* PCI I/O address */    UINT32 value		/* value */    )    {    UINT32 l = TO_LITTLEL (value);    USB_OUT_DWORD (address, l);    CACHE_PIPE_FLUSH ();    }/***************************************************************************** usbPciMemioOffset - Return PCI MEMIO to CPU MEMIO offset** For memory-mapped I/O, the CPU's view of a memory address may not be the* same as that programmed into the base address register of a PCI adapter.* The CPU should add the value returned by this function to the BAR in order* to produce the correct CPU-visible memory address.** RETURNS: PCI_MEMIO_OFFSET*/UINT32 usbPciMemioOffset (void)    {    return 0;    }/***************************************************************************** usbMemToPci - Convert a memory address to a PCI-reachable memory address** Converts <pMem> to an equivalent 32-bit memory address visible from the * PCI bus.  This conversion is necessary to allow PCI bus masters to address* the same memory viewed by the processor.** RETURNS: converted memory address*/UINT32 usbMemToPci    (    pVOID pMem			/* memory address to convert */    )    {    pVOID pPhys;        pPhys = CACHE_DRV_VIRT_TO_PHYS (&cacheUserFuncs, pMem);    return ((UINT32) pPhys) ;    }/***************************************************************************** usbPciToMem - Convert a PCI-reachable address to a CPU-reachable pointer** Converts <pciAdrs> to an equivalent CPU memory address.  ** RETURNS: pointer to PCI memory*/pVOID usbPciToMem    (    UINT32 pciAdrs		/* 32-bit PCI address to be converted */    )    {		    return CACHE_DRV_PHYS_TO_VIRT (&cacheUserFuncs, 		(void *) pciAdrs);    	    }/***************************************************************************** usbPciMemInvalidate - Invalidate cache for a region of memory** When another bus master, such as a PCI bus master, writes to memory, the* cache may need to be invalidated for that region of memory.** NOTE: Returns immediately if size == 0.** RETURNS: N/A*/VOID usbPciMemInvalidate    (    pVOID pMem, 		/* base of memory region to invalidate */    UINT32 size 		/* size of region to invalidate */    )    {    if (size != 0)	CACHE_USER_INVALIDATE (pMem, size);    }/***************************************************************************** usbPciMemFlush - Flush a region of memory through the cache** In systems which implement a non-write-thru cache, the processor may have* written data to memory which has not yet been flushed to the actual system* memory.  Before other bus masters may interrogate this memory, it may be* necessary to flush the cache.** NOTE: Returns immediately if size == 0.** RETURNS: N/A*/VOID usbPciMemFlush    (    pVOID pMem, 		/* base of memory region to invalidate */    UINT32 size 		/* size of region to invalidate */    )    {    if (size != 0)	CACHE_USER_FLUSH (pMem, size);    }/***************************************************************************** usbPciIntConnect - Connect to a interrupt vector** Connects the <func> to the interrupt number <intNo>.	<param> is an* application-specific value which will be passed to <func> each time* the interrupt handler is invoked.  ** RETURNS: OK, or ERROR if unable to connect/enable interrupt*/STATUS usbPciIntConnect    (    INT_HANDLER_PROTOTYPE func,     /* new interrupt handler */    pVOID param,		    /* parameter for int handler */    UINT16 intNo		    /* interrupt vector number */    )    {    if(intNo != USB_HOST_INT_NUM)	return ERROR;	    if (INT_CONNECT ((int) intNo, func, param) != OK)	return ERROR;    if (INT_ENABLE (intNo) != OK)	{	INT_DISCONNECT (intNo, func, param);	return ERROR;	}    return OK;    }/***************************************************************************** usbPciIntDisconnect - Removes an interrupt handler** Removes an interrupt handler installed by usbPciIntConnect().  <func>,* <param>, and <intNo> must match the corresponding parameters from an earlier * call to usbPciIntConnect().** RETURNS: N/A*/VOID usbPciIntRestore    (    INT_HANDLER_PROTOTYPE func,     /* int handler to be removed */    pVOID param,		    /* parameter for int handler */    UINT16 intNo		    /* interrupt vector number */    )    {    	if (intNo == USB_HOST_INT_NUM)			{				INT_DISABLE (intNo);    		INT_DISCONNECT (intNo, func, param);    	}        }/* End of file. */

⌨️ 快捷键说明

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