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

📄 usbpcistub.c

📁 MPC5200 BSP 支持ATA,USB, I2C,扩展网口
💻 C
字号:
#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 */#define USB_PCI_IO_OFFSET	0x0/* #define USB_PCI_MEMIO_OFFSET	0x0 */#define USB_PCI_MEM_OFFSET	0x0#define USB_INT_CONNECT(intNo, func, param) \    intConnect (INUM_TO_IVEC(intNo), (VOIDFUNCPTR) func, (int) param)#define USB_INT_DISCONNECT(intNo, func, param) \    pciIntDisconnect2 (INUM_TO_IVEC(intNo), (VOIDFUNCPTR) func, (int) param)#define USB_INT_ENABLE(i)	intEnable (i)#define USB_INT_DISABLE(i)	intDisable (i)#define	USB_PCI_IN_BYTE(a)	sysInByte ((a) + USB_PCI_IO_OFFSET)#define	USB_PCI_IN_WORD(a)	sysInWord ((a) + USB_PCI_IO_OFFSET)#define	USB_PCI_IN_DWORD(a)	sysInLong ((a) + USB_PCI_IO_OFFSET)#define	USB_PCI_OUT_BYTE(a,v)	sysOutByte ((a) + USB_PCI_IO_OFFSET, (v))#define	USB_PCI_OUT_WORD(a,v)	sysOutWord ((a) + USB_PCI_IO_OFFSET, (v))#define	USB_PCI_OUT_DWORD(a,v)	sysOutLong ((a) + USB_PCI_IO_OFFSET, (v))#define USB_MAX_INT_NO		16/* locals */LOCAL UINT16 intUsage [USB_MAX_INT_NO] = {0};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 */    )    {    int intBusNo;		/* VxWorks returns "int" values */    int intDeviceNo;    int intFuncNo;        /* Use the VxWorks PCI config. library to find a device within the    specified class. */    if (pciFindClass ((pciClass << 16) | (subClass << 8) | pgmIf, index,	&intBusNo, &intDeviceNo, &intFuncNo) != OK)	{	return FALSE;	}    else	{	if (pBusNo)	     *pBusNo = (UINT8) intBusNo;	if (pDeviceNo)	     *pDeviceNo = (UINT8) intDeviceNo;	if (pFuncNo)	     *pFuncNo = (UINT8) intFuncNo;	}    return TRUE;    }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;    if (pciConfigInByte (busNo, deviceNo, funcNo, regOffset, &value) != OK)	return 0;    return value;    }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;    if (pciConfigInWord (busNo, deviceNo, funcNo, regOffset, &value) != OK)	return 0;    return value;    }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;    if (pciConfigInLong (busNo, deviceNo, funcNo, regOffset, &value) != OK)	return 0;    return value;    }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. */    memset (pCfgHdr, 0, sizeof (*pCfgHdr));    /* Read and store each field in the PCI configuration header. */    pCfgHdr->vendorId	= usbPciWordGet (busNo, deviceNo, funcNo, PCI_CFG_VENDOR_ID);    pCfgHdr->deviceId	= usbPciWordGet (busNo, deviceNo, funcNo, PCI_CFG_DEVICE_ID);    pCfgHdr->command	= usbPciWordGet (busNo, deviceNo, funcNo, PCI_CFG_COMMAND);    pCfgHdr->status	= usbPciWordGet (busNo, deviceNo, funcNo, PCI_CFG_STATUS);    pCfgHdr->revisionId = usbPciByteGet (busNo, deviceNo, funcNo, PCI_CFG_REVISION);    pCfgHdr->pgmIf	= usbPciByteGet (busNo, deviceNo, funcNo, PCI_CFG_PROGRAMMING_IF);    pCfgHdr->subClass	= usbPciByteGet (busNo, deviceNo, funcNo, PCI_CFG_SUBCLASS);    pCfgHdr->pciClass	= usbPciByteGet (busNo, deviceNo, funcNo, PCI_CFG_CLASS);    pCfgHdr->cacheLineSize = usbPciByteGet (busNo, deviceNo, funcNo, PCI_CFG_CACHE_LINE_SIZE);    pCfgHdr->latencyTimer = usbPciByteGet (busNo, deviceNo, funcNo, PCI_CFG_LATENCY_TIMER);    pCfgHdr->headerType = usbPciByteGet (busNo, deviceNo, funcNo, PCI_CFG_HEADER_TYPE);    pCfgHdr->bist	= usbPciByteGet (busNo, deviceNo, funcNo, PCI_CFG_BIST);    for (i = 0; i < PCI_CFG_NUM_BASE_REG; i++)	pCfgHdr->baseReg [i] = usbPciDwordGet (busNo, deviceNo, funcNo, 	    PCI_CFG_BASE_ADDRESS_0 + i * sizeof (UINT32));    pCfgHdr->romBase	= usbPciDwordGet (busNo, deviceNo, funcNo, PCI_CFG_EXPANSION_ROM);    pCfgHdr->intLine	= usbPciByteGet (busNo, deviceNo, funcNo, PCI_CFG_DEV_INT_LINE);    pCfgHdr->intPin	= usbPciByteGet (busNo, deviceNo, funcNo, PCI_CFG_DEV_INT_PIN);    pCfgHdr->minGrant	= usbPciByteGet (busNo, deviceNo, funcNo, PCI_CFG_MIN_GRANT);    pCfgHdr->maxLatency = usbPciByteGet (busNo, deviceNo, funcNo, PCI_CFG_MAX_LATENCY);    }UINT8 usbPciByteIn    (    UINT32 address		/* PCI I/O address */    )    {    return USB_PCI_IN_BYTE (address);    }UINT16 usbPciWordIn    (    UINT32 address		/* PCI I/O address */    )    {    UINT16 w = USB_PCI_IN_WORD (address);    return FROM_LITTLEW (w);    }UINT32 usbPciDwordIn    (    UINT32 address		/* PCI I/O address */    )    {    UINT32 l = USB_PCI_IN_DWORD (address);    return FROM_LITTLEL (l);    }VOID usbPciByteOut    (    UINT32 address,		/* PCI I/O address */    UINT8 value 		/* value */    )    {    USB_PCI_OUT_BYTE (address, value);    CACHE_PIPE_FLUSH ();    }VOID usbPciWordOut    (    UINT32 address,		/* PCI I/O address */    UINT16 value		/* value */    )    {    UINT16 w = TO_LITTLEW (value);    USB_PCI_OUT_WORD (address, w);    CACHE_PIPE_FLUSH ();    }VOID usbPciDwordOut    (    UINT32 address,		/* PCI I/O address */    UINT32 value		/* value */    )    {    UINT32 l = TO_LITTLEL (value);    USB_PCI_OUT_DWORD (address, l);    CACHE_PIPE_FLUSH ();    }UINT32 usbPciMemioOffset (void)    {    	return 0;    /*return USB_PCI_MEMIO_OFFSET;*/    }UINT32 usbMemToPci    (    pVOID pMem			/* memory address to convert */    )    {    pVOID pPhys;           pPhys = CACHE_DRV_VIRT_TO_PHYS (&cacheUserFuncs, pMem);    return ((UINT32) pPhys) + USB_PCI_MEM_OFFSET;    }pVOID usbPciToMem    (    UINT32 pciAdrs		/* 32-bit PCI address to be converted */    )    {    return CACHE_DRV_PHYS_TO_VIRT (&cacheUserFuncs, 	(void *) (pciAdrs - USB_PCI_MEM_OFFSET));    }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);    }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);    }STATUS usbPciIntConnect    (    INT_HANDLER_PROTOTYPE func,     /* new interrupt handler */    pVOID param,		    /* parameter for int handler */    UINT16 intNo		    /* interrupt vector number */    )    {    if (USB_INT_CONNECT ((int)intNo, (VOIDFUNCPTR)func, (int)param) != OK)	return ERROR;    if (USB_INT_ENABLE (intNo) != OK)	{	/* USB_INT_DISCONNECT (intNo, func, param); */	return ERROR;	}    if (intNo < USB_MAX_INT_NO) 	intUsage [intNo]++;    return OK;    }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_MAX_INT_NO || 	(intUsage [intNo] != 0 && --intUsage [intNo] == 0))	{	USB_INT_DISABLE (intNo);	}      }

⌨️ 快捷键说明

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