📄 pc1394drv.c
字号:
/* file number */
/*
modification history
-, 2004, November, 10th Release
*/
/****************************************************************
Module: pc1394Drv.c
Author:
Description: driver of PC 1394 Card
****************************************************************/
/* Included Files */
#include <vxWorks.h>
#include <logLib.h>
#include <iv.h>
#include <ioLib.h>
#include <iosLib.h>
#include <semLib.h>
#include <stdlib.h>
#include <stdio.h>
#include <sysLib.h>
#include <taskLib.h>
#include <intLib.h>
#include <iv.h>
#include <logLib.h>
#include <memLib.h>
#include <errnoLib.h>
#include <string.h>
#include "config.h"
#include "arch/i86/pentiumLib.h"
#include "../../../include/drv/pc1394Card/pc1394Drv.h"
#include "../../../include/drv/pc1394Card/OHCIreg.h"
#include "../../../include/drv/pc1394Card/pciCfgSpace.h"
/* define some macro */
/* Global Variables */
int pc1394_Debug = 1;
static int pc1394IntValue = 0;
static int pc1394IntVector = 0;
static int DriverNumber = 0; /* driver number specified by iosDrvInstall() */
static int NumberOfDevices = 0; /* number of devices created */
/* Forward Declaration */
LOCAL int PC1394Open(PC1394_DEV *pPc1394Dev);
LOCAL int PC1394Close(PC1394_DEV *pPc1394Dev);
LOCAL int PC1394Read(PC1394_DEV *pPc1394Dev, char *pRevBuf, int iNum);
LOCAL int PC1394Write(PC1394_DEV *pPc1394Dev, char *pSrcBuf, int iNum);
LOCAL int PC1394Ioctl (PC1394_DEV *pPc1394Dev, int iFunCode, int iParam);
LOCAL void PC1394IntHandle(PC1394_DEV *pPc1394Dev);
STATUS pc1394DevSearch(PC1394_DEV *pPc1394Dev, int instance);
unsigned long pciReadLong (int iPciAddr);
void pciWriteLong(int iPciAddr, unsigned long ulData);
/* Forward Declaration */
/******************************************************************************
TITLE: PC1394Drv
DESC: setup routine of PC 1394 Card
PARAM: none
RETURN: DriverNumber - driver number for freq control PMC Card driver
NOTE: the routine should run only one time.
******************************************************************************/
int PC1394Drv (void)
{
if (DriverNumber > 0)
{
return (DriverNumber);
}
DriverNumber = iosDrvInstall((FUNCPTR) NULL, (FUNCPTR) NULL,
PC1394Open, PC1394Close,
PC1394Read, PC1394Write,
PC1394Ioctl);
return(DriverNumber);
}
/******************************************************************************
TITLE: PC1394DevCreate
DESC: device initialization of PC 1394 Card
PARAM: name - device name
pHfctlDev - pointer to HFCTL_DEV device structure
RETURN: OK - device initialize successfully
ERROR - device initialize failed with error
******************************************************************************/
int PC1394DevCreate (char *name, PC1394_DEV *pPc1394Dev)
{
unsigned long ulTempData;
unsigned long ulRegData;
unsigned long *pRegAdrs;
if (DriverNumber <= 0) /* driver not installed */
{
errnoSet(S_ioLib_NO_DRIVER);
return(ERROR);
}
if (NumberOfDevices >= PC1394_MAX_DEV) /* too many devices created */
{
errnoSet(PC1394_ALLOCATE_DEVICE_FAILED);
return(ERROR);
}
if ((iosDevAdd(&(pPc1394Dev->devHdr), name, DriverNumber)) != OK)
{
/* Specified device already exists */
errnoSet(PC1394_DEVICE_ALREADY_CREATED);
return(ERROR);
}
/*
logMsg("PC1394DevCreate: run to here.\n", 0, 0, 0, 0, 0, 0);
*/ /* comment by chenxuhao at 2004-11-16 */
/* search the card and read the base addr registers */
if (pc1394DevSearch(pPc1394Dev, NumberOfDevices) != OK)
{
errnoSet(PC1394_HARDWARE_INIT_FAILED);
return(ERROR);
}
/***************************/
/* creaete semphore for driver */
/* end of semphore creation */
/***************************/
if (pc1394_Debug)
{
printf("PC1394DevCreate: pci base adrs = 0x%8x\n", pPc1394Dev->pciControllerSpace0);
}
/***************************/
/* configure the board */
ulTempData = pciReadLong((int)(pPc1394Dev->pciControllerSpace0 + HC_CTR_SET_ADR));
if (pc1394_Debug)
{
printf("PC1394DevCreate: HCControl reg = 0x%8x\n", ulTempData);
}
ulTempData = DATA_BIT19;
/* enable LPS */
pciWriteLong((int)(pPc1394Dev->pciControllerSpace0 + HC_CTR_SET_ADR), ulTempData);
if (pc1394_Debug)
{
printf("PC1394DevCreate: HCControl reg = 0x%8x\n", ulTempData);
}
/* configure the link/PHY register */
/* end of board configuration */
/***************************/
/***************************/
/* interrupt clear and install */
ulRegData = 0xffffffff;
pciWriteLong((int)pPc1394Dev->pciControllerSpace0 + INTEVENT_REG_CLR_ADR, ulRegData);
if (pc1394_Debug)
{
printf("PC1394DevCreate: pci int number = %d\n", pc1394IntValue);
}
pc1394IntVector = INT_VEC_GET(pc1394IntValue);
if (pc1394_Debug)
{
printf("PC1394DevCreate: INT_NUM_IRQ0 = %d\n", INT_NUM_IRQ0);
}
if ((pciIntConnect(INUM_TO_IVEC(pc1394IntValue + INT_NUM_IRQ0),
PC1394IntHandle, (int) pPc1394Dev)) == ERROR)
{
/*
semDelete(pPc1394Dev->);
semDelete(pPc1394Dev->);
semDelete(pPc1394Dev->);
*/ /* comment by chenxuhao at 2004-11-16 */
logMsg("Failed to connect interrupt\n", 0, 0, 0, 0, 0, 0);
errnoSet(PC1394_INT_HANDLER_INSTALL_FAILED);
return(ERROR);
}
ulRegData = DATA_BIT17;
pciWriteLong((int)pPc1394Dev->pciControllerSpace0 + INTMASK_REG_SET_ADR, ulRegData);
/* Enable interrupts */
sysIntEnablePIC(pc1394IntValue);
/* Enable interrupts */
/* end of interrupt install */
/***************************/
NumberOfDevices++;
if (pc1394_Debug)
{
fprintf(stdout, "\n\rNumberOfDevices = 0x%d", NumberOfDevices);
}
pPc1394Dev->devCreated = 1; /* device created */
pPc1394Dev->devBusy = 0; /* device available to be used */
return (OK);
}
/******************************************************************************
TITLE: PC1394Open
DESC: routine to open a PC 1394 card device
PARAM: pPc1394Dev - pointer to PC1394_DEV device structure
RETURN: pPc1394Dev - file descriptor for opened device
ERROR - device cannot be open with error
******************************************************************************/
int PC1394Open(PC1394_DEV *pPc1394Dev)
{
}
/******************************************************************************
TITLE: PC1394Close
DESC: routine to close a PC 1394 card device
PARAM: pPc1394Dev - pointer to PC1394_DEV device structure
RETURN: OK - close the device successfully
ERROR - close the device failed with error
******************************************************************************/
int PC1394Close(PC1394_DEV *pPc1394Dev)
{
}
/******************************************************************************
TITLE: PC1394Read
DESC: routine to read data from PC 1394 card
PARAM: pPc1394Dev - pointer to PC1394_DEV device structure
pRevBuf - pointer to receive buffer
iNum - bytes number to read, should be multiple of 4
RETURN: iNum - bytes number have been read
******************************************************************************/
int PC1394Read(PC1394_DEV *pPc1394Dev, char *pRevBuf, int iNum)
{
}
/******************************************************************************
TITLE: PC1394Write
DESC: routine to write data to hop freq control PMC card
PARAM: pPc1394Dev - pointer to PC1394_DEV device structure
pSrcBuf - pointer to source buffer
iNum - bytes number to write, should be multiple of 4
RETURN: iNum - bytes number have been written
******************************************************************************/
int PC1394Write(PC1394_DEV *pPc1394Dev, char *pSrcBuf, int iNum)
{
}
/******************************************************************************
TITLE: PC1394Ioctl
DESC: Routine to configure and control PC 1394 card
PARAM: pPc1394Dev - pointer to PC1394_DEV device structure
iFunCode - code for the desired action
iParam - data supplied to or from routine
RETURN: OK - operation was successful
ERROR - operation failed
******************************************************************************/
int PC1394Ioctl (PC1394_DEV *pPc1394Dev, int iFunCode, int iParam)
{
}
/******************************************************************************
TITLE: PC1394IntHandle
DESC: PCI interrupt handler for PC 1394 card
PARAM: pPc1394Dev - pointer to PC1394_DEV device structure
RETURN: none
******************************************************************************/
void PC1394IntHandle(PC1394_DEV *pPc1394Dev)
{
unsigned long ulIntEventReg;
logMsg("PC1394IntHandle: detect a interrupt.\n", 0, 0, 0, 0, 0, 0);
ulIntEventReg = pciReadLong((int)(pPc1394Dev->pciControllerSpace0 + INTEVENT_REG_SET_ADR));
if (ulIntEventReg & DATA_BIT17)
{
logMsg("PC1394IntHandle: detect a BusReset interrupt.\n", 0, 0, 0, 0, 0, 0);
}
}
/******************************************************************************
TITLE: pc1394DevSearch
DESC: search PC 1394 Card
PARAM: none
RETURN: OK - operation run successfully
ERROR - operation run failed
******************************************************************************/
STATUS pc1394DevSearch(PC1394_DEV *pPc1394Dev, int instance)
{
STATUS iStatus;
int iTempData;
int iPciBusNo; /* PCI bus number */
int iPciDevNo; /* PCI device number */
int iPciFuncNo; /* PCI function number */
unsigned short ulTemp;
/* Search for device on PCI Bus */
iPciBusNo = 0xFF;
iPciDevNo = 0xFF;
iPciFuncNo = 0xFF;
iStatus = pciFindDevice((PC1394_PCI_ID & 0xFFFF), (PC1394_PCI_ID >> 16) & 0xFFFF, instance,
&iPciBusNo, &iPciDevNo, &iPciFuncNo);
if ((iPciBusNo == 0xFF) && (iPciDevNo == 0xFF) && (iPciFuncNo == 0xFF))
{
logMsg("\n\rNo device found!!", 0, 0, 0, 0, 0, 0);
return(ERROR);
}
if (pc1394_Debug)
{
/* Show the configuration settings */
pciHeaderShow(iPciBusNo, iPciDevNo, iPciFuncNo);
}
pPc1394Dev->iPciBusNo = iPciBusNo;
pPc1394Dev->iPciDevNo = iPciDevNo;
pPc1394Dev->iPciFuncNo = iPciFuncNo;
iTempData = 0;
pciConfigInLong(iPciBusNo, iPciDevNo, iPciFuncNo, PCI_CFG_REG_BAR0, &iTempData);
pPc1394Dev->pciControllerSpace0 = iTempData;
if (pc1394_Debug)
{
printf("PCI_CFG_REG_BAR0 = 0x%8x\n", iTempData);
}
pciConfigInLong(iPciBusNo, iPciDevNo, iPciFuncNo, PCI_CFG_REG_INT_LINE, &iTempData);
pc1394IntValue = iTempData & 0xff;
if (pc1394_Debug)
{
printf("PCI_CFG_REG_INT_LINE = 0x%8x\n", pc1394IntValue);
}
pciConfigInWord(iPciBusNo, iPciDevNo, iPciFuncNo, PCI_CFG_REG_PCI_CMD, &ulTemp);
if (pc1394_Debug)
{
printf("PCI_CFG_REG_PCI_CMD = 0x%4x\n", ulTemp);
}
ulTemp = ulTemp | DATA_BIT6 | DATA_BIT8;
pciConfigOutWord(iPciBusNo, iPciDevNo, iPciFuncNo, PCI_CFG_REG_PCI_CMD, ulTemp);
if (pc1394_Debug)
{
taskDelay(1);
pciConfigInWord(iPciBusNo, iPciDevNo, iPciFuncNo, PCI_CFG_REG_PCI_CMD, &ulTemp);
printf("PCI_CFG_REG_PCI_CMD = 0x%4x\n", ulTemp);
}
return(OK);
}
/******************************************************************************
TITLE: pciReadLong
DESC: routine to read Long data from a pci address
PARAM: iPciAddr - pci address to be read
RETURN: ulTemp - data read from specified PCI address
******************************************************************************/
unsigned long pciReadLong (int iPciAddr)
{
unsigned int * pPciAddr;
unsigned long ulData;
unsigned long ulTemp;
ulTemp = 0;
pPciAddr = ((unsigned int *)iPciAddr);
ulData = *pPciAddr;
#ifdef HOST_LITTLE_ENDIAN
ulTemp = ulData;
#else
ulTemp = ulTemp | ((ulData << 24) & 0xFF000000);
ulTemp = ulTemp | ((ulData << 8) & 0x00FF0000);
ulTemp = ulTemp | ((ulData >> 8) & 0x0000FF00);
ulTemp = ulTemp | ((ulData >> 24) & 0x000000FF);
#endif
return(ulTemp);
}
/******************************************************************************
TITLE: pciWriteLong
DESC: routine to write Long data to a pci address
PARAM: iPciAddr - pci address to be written
ulData - data to be written into the pci space
RETURN: none
******************************************************************************/
void pciWriteLong(int iPciAddr, unsigned long ulData)
{
unsigned int * pPciAddr;
unsigned long ulTemp;
ulTemp = 0;
#ifdef HOST_LITTLE_ENDIAN
ulTemp = ulData;
#else
ulTemp = ulTemp | ((ulData << 24)& 0xFF000000);
ulTemp = ulTemp | ((ulData << 8)& 0x00FF0000);
ulTemp = ulTemp | ((ulData >> 8)& 0x0000FF00);
ulTemp = ulTemp | ((ulData >> 24)& 0x000000FF);
#endif
pPciAddr = ((unsigned int *) iPciAddr);
*pPciAddr = ulTemp;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -