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

📄 wdbvisiondrv.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* wdbVisionDrv.c - Wind River Vision Driver *//* Copyright 1988-2002 Wind River Systems Inc. *//*modification history--------------------01e,29nov01,g_h  Cleaning for T2.201d,05may01,g_h  rename to wdbVisionDrv.c and cleaning01c,09apr01,rnr  Changed to generic driver that calls different IO packages01b,07feb01,g_h  renaming module name and cleaning01a,07may97,est  Adapted from memdrv.c*//*DESCRIPTIONThis driver provides a Vision Communications Channelbetween the I/O system and a host. The system requires an Wind Riverbackground mode emulator equiped with a TGTCONS TransparentMode.USER-CALLABLE ROUTINESMost of the routines in this driver are accessible only through the I/Osystem.  Two routines, however, must be called directly:  visionDriverInit() to initialize the driver, and visionDriverCreate() to create devices.Before using the driver, it must be initialized by calling vDriverInit().This routine should be called only once, before any reads, writes, or visionDriverCreate() calls.  The use and functions provided by the driver vary depending on the target microprocessor: ColdFire, PowerPC, ARM, XSCALE, MIPS and SH. IOCTLThe memory driver responds to the ioctl() codesSEE ALSO:.pG "I/O System"*//* includes */#include "vxWorks.h"#include "ioLib.h"#include "iosLib.h"#include "memLib.h"#include "cacheLib.h"#include "errnoLib.h"#include "string.h"#include "stdlib.h"#include "stdio.h"#include "taskLib.h"#include "configAll.h"#include "drv/wdb/vision/wdbVisionDrvIF.h"#include "drv/wdb/vision/wdbVisionDrv.h"/* defines */#undef VISION_DEBUG_VERSION     /* undef for released version */     /* externals */#if defined (INCLUDE_WDB_COMM_VTMD)IMPORT VDR_ULONG  tmdLowLevelIOInit (V_DRIVER_INTERFACE *pInterfaceData);#endif /* (INCLUDE_WDB_COMM_VTMD) */IMPORT VDR_ULONG visionLowLevelIOInit (V_DRIVER_INTERFACE *pInterfaceData);/* locals */LOCAL int vDrivNum  = 0; /* driver number          */LOCAL int vDrivOpen = 0; /* number of open devices */#if defined (INCLUDE_WDB_COMM_VTMD)LOCAL VDR_INIT_PTR pIOEntryRoutine = (VDR_INIT_PTR) tmdLowLevelIOInit; /* visionTMD I/O subsystem entry  */#else LOCAL VDR_INIT_PTR pIOEntryRoutine = NULL;#endif /* (INCLUDE_WDB_COMM_VTMD) *//* forward declarations */int visionDriverOpen (VDRIV_DEV *pFd, char *pName, int mode);int visionDriverRead (VDRIV_DEV *pFd, char *pBuffer ,int maxbytes);int visionDriverWrite (VDRIV_DEV *pFd, char *pBuffer, int nbytes);int visionDriverIoctl (VDRIV_DEV *pFd, int function, int arg);int visionDriverClose (VDRIV_DEV *pFd);LOCAL void visionDrvPollTask (VDRIV_DEV *pFd);LOCAL int  visionPoll (VDRIV_DEV *pFd);LOCAL int  visionStartPollTask (VDRIV_DEV *pFd, int priority);LOCAL int  visionFillRxQueue (VDRIV_DEV *pFd);LOCAL int visionInitQueue (volatile VISION_QUEUE *pQueue, int size);LOCAL int visionBytesInQueue (volatile VISION_QUEUE *pQueue);LOCAL int visionAddToQueue (volatile VISION_QUEUE *pQueue, char *pDt, int sz);LOCAL int visionRemoveFromQueue (volatile VISION_QUEUE *pQueue, char *pDt, int sz);LOCAL int visionFlushQueue (volatile VISION_QUEUE *pQueue);LOCAL int visionSpaceInQueue (volatile VISION_QUEUE *pQueue);/***************************************************************************** visionDriverInit - install Wind River Vision Driver** This routine initializes the driver.  It must be called first,* before any other routine in the driver.** RETURNS: OK, or ERROR if the I/O system cannot install the driver.*/int visionDriverInit    (    void     )    {    /* Exit if driver has already been installed */     if (vDrivNum > 0)        {        return (OK);        }    vDrivNum = iosDrvInstall(visionDriverOpen,                             (FUNCPTR) NULL,                             visionDriverOpen,                             visionDriverClose,                             visionDriverRead,                             visionDriverWrite,                             visionDriverIoctl);    vDrivOpen = (vDrivNum == ERROR) ? 0 : 1;    return ((vDrivNum == ERROR) ? ERROR : OK);    }/***************************************************************************** visionDriverCreate - create an instance of Wind River Virtual Mode Driver. ** This routine create an instance of Wind River Virtual Mode Driver*   * RETURNS: OK, ERROR/errno** NOTE: currently only a single device is supported*/int visionDriverCreate    (      char *pName,             int   opMode,    int   blockMode,    int   bufferMode,    int   taskDelay,    int   taskPriority    )    {    VDRIV_DEV *pFd      = (VDRIV_DEV*)NULL;    VDR_ULONG  ioStatus = VDR_FAILURE;        /* sanity check on taskDelay and taskPriority */    if ((taskDelay < 0) || (taskDelay > VISION_MAX_PTASK_DELAY))	{        return (ERROR);        }    if ((taskPriority < VISION_MIN_PTASK_PRIOR) ||         (taskPriority > VISION_MAX_PTASK_PRIOR))        {	return(ERROR);        }    /*     *   If device has not been installed or more than one device      *   has been opened, return an ERROR.     */    if ((vDrivNum < 1) || (vDrivOpen > 1))        {        return(ERROR);        }    /* Create the device descriptor */    if ((pFd = (VDRIV_DEV*)cacheDmaMalloc (sizeof(VDRIV_DEV))) == NULL)        {        return (ERROR);        }    /* Initialize descriptor values */    pFd->state       = VISION_STATE_CLOSED;     pFd->pollTaskId  = ERROR;    pFd->pDeviceName = pName;    pFd->opMode      = opMode;    pFd->rdWrMode    = O_RDWR;    pFd->bufferMode  = bufferMode;    pFd->blockMode   = blockMode;    pFd->loopMode    = VISION_NORMAL_MODE;    pFd->pollDelay   = taskDelay;    pFd->inter.openFunc        = (VDR_OPEN_PTR) NULL;    pFd->inter.closeFunc       = (VDR_CLOSE_PTR) NULL;    pFd->inter.readFunc        = (VDR_READ_PTR) NULL;    pFd->inter.writeFunc       = (VDR_WRITE_PTR) NULL;    pFd->inter.readStatusFunc  = (VDR_READ_STATUS_PTR) NULL;    pFd->inter.writeStatusFunc = (VDR_WRITE_STATUS_PTR) NULL;    pFd->inter.privateData     = (VDR_PDATA) NULL;    /* Try and initialize the low-level I/O driver. */    ioStatus = (*(VDR_INIT_PTR)pIOEntryRoutine)(&pFd->inter);    if (ioStatus == VDR_FAILURE)        {        return (ERROR);        }    /* Add device to device table */    if ((iosDevAdd ((DEV_HDR*)pFd ,pName ,vDrivNum)) == ERROR)        {        return (ERROR);        }    /* Create a LOOPBACK queueu */    if (visionInitQueue (&pFd->loopQueue ,LOOP_BUFFER_SIZE) == ERROR)        {        return (ERROR);        }    /* If buffered operation is selected, set up initial buffer queues */    if (bufferMode == VISION_BUFFERED_MODE)        {        if (visionInitQueue (&pFd->txQueue ,TX_BUFFER_SIZE) == ERROR)            {            return (ERROR);            }        if (visionInitQueue (&pFd->rxQueue ,RX_BUFFER_SIZE) == ERROR)            {            return (ERROR);            }        }    /* Create a Tx and Rx Critical Section mutual exclusion construct */    CREATE_CRITSECT(pFd->txCrSection);    CREATE_CRITSECT(pFd->rxCrSection);    CREATE_CRITSECT(pFd->loopCrSection);    /*      *   If the operation mode specified is pseudo-interrupt, start     *   a background polling task to simulate Tx and Rx interrupts.     */    if (opMode == VISION_PINTR_MODE)        {        if (visionStartPollTask(pFd ,taskPriority) == ERROR)            {            return(ERROR);            }        }    pFd->state = VISION_STATE_OPEN;    return (OK);    }/***************************************************************************** visionDriverOpen - open a connection ** This routine open a connection between the high level driver and the low* level driver** RETURNS: The file descriptor number, or ERROR if the name is not a valid *          number.*/int visionDriverOpen     (    VDRIV_DEV *pDev,       /* pointer to device descriptor           */    char      *pRemainder, /* stuff after /vtd0 not valid            */    int        mode        /* access mode (O_RDONLY,O_WRONLY,O_RDWR) */    )               {    volatile VDRIV_DEV *pFd      = pDev;     VDR_ULONG           ioStatus = VDR_SUCCESS;       if (pRemainder[0] != 0)        {        return (ERROR);        }    pFd->rdWrMode = mode;    /*     *   Invoke the lower level driver's open function to perform any     *   intialization or allocation of resources.     */    ioStatus = pFd->inter.openFunc (pFd->inter.privateData);      if (ioStatus != VDR_SUCCESS)        {        return (ERROR);        }    return ((int)pFd);    }/***************************************************************************** visionDriverClose - close a connection ** This routine close the connection between the high level driver and the low* level driver* RETURNS: OK, or ERROR */int visionDriverClose     (    VDRIV_DEV *pDev /* pointer to device descriptor */    )               {    volatile VDRIV_DEV *pFd = pDev;     VDR_ULONG           ioStatus;    /*     *   Invoke the lower level driver's close function to cleanup and      *   resources they may have allocated.     */    ioStatus = pFd->inter.closeFunc (pFd->inter.privateData);      if (ioStatus == VDR_SUCCESS)        {        return (OK);        }    else        {        return(ERROR);        }    }/***************************************************************************** visionDriverRead - read from a memory file** This routine read data from the low level driver.** RETURNS: The number of bytes read, or ERROR if past the end of memory or *          is O_WRONLY only.*/int visionDriverRead     (    VDRIV_DEV *pDev,    /* file descriptor of file to close */    char      *pBuffer, /* buffer to receive data           */    int        maxbytes /* max bytes to read in to buffer   */    )    {    volatile VDRIV_DEV *pFd = pDev;    int                 bytesRead = 0;    VDR_ULONG           ioStatus;    VDR_ULONG           readStatus;    VDR_ULONG           recvBytes;    /* Insure proper rwMode */    if (pFd->rdWrMode == O_WRONLY)        {        return (ERROR);        }    /*      *   Sanity check on maxbytes, zero is a legal value,      *   it is used to indicate a status poll is requested.     */    if (maxbytes < 0)        {        return (ERROR);        }    /*      *    Polled verses Pseudo-Interrupt, Blocking verses Non-Blocking,     *    and Buffered verses Non-Buffered are handled slightly different.      *    (see Application Note, Mode Matrix for details)     */    if (pFd->opMode == VISION_POLL_MODE)        {        if (pFd->blockMode == VISION_BLOCKED_MODE)            {            /*             *   (This mode has to be VISION_NONBUFFERED_MODE)             *             *   Wait for available data from emulator              */            readStatus = VDR_DATA_NONE;            while (readStatus == VDR_DATA_NONE)                {                ioStatus = pFd->inter.readStatusFunc (pFd->inter.privateData,                                                      &readStatus);                if (ioStatus == VDR_FAILURE)                    {                    return (ERROR);                    }                }            ioStatus = pFd->inter.readFunc(pFd->inter.privateData,                                           (VDR_UCHAR*)pBuffer,                                           (VDR_ULONG)maxbytes,                                           &recvBytes);            if (ioStatus == VDR_FAILURE)                {                return (ERROR);                }            bytesRead = recvBytes;            }        else /* POLL_MODE & NONBLOCKED_MODE */            {            if (pFd->bufferMode == VISION_NONBUFFERED_MODE)                {                ioStatus = pFd->inter.readFunc (pFd->inter.privateData,                                                (VDR_UCHAR*) pBuffer,                                                (VDR_ULONG) maxbytes,                                                &recvBytes);                if (ioStatus == VDR_FAILURE)                    {                    return (ERROR);                    }                bytesRead = recvBytes;                }            else /* POLL_MODE, NONBLOCKED_MODE, BUFFERED_MODE */                {                /*                  *   This is a possible mode, but not a practical mode. The                  *   buffered mode was intended to be used with a pTask running.                 */                return (ERROR);                }            }        }    else if (pFd->opMode == VISION_PINTR_MODE)        {        if (pFd->blockMode == VISION_BLOCKED_MODE)            {            /* (This mode has to be VISION_BUFFERED_MODE) */            /*              * In this mode, the visionDriverRead() function will block until             * data is available. The background pTask is responsible             * for monitoring the Rx descriptor buffer and filling the             * Rx Queue.             */            /* Wait for data to be available in the Rx queue */            do  {                ENTER_CRITSECT (pFd->rxCrSection);                bytesRead = visionRemoveFromQueue (&pFd->rxQueue ,pBuffer ,maxbytes);                EXIT_CRITSECT (pFd->rxCrSection);                if (bytesRead == 0)                    {                    DELAY_TASK (pFd->pollDelay);                    }                } while(bytesRead == 0);            return(bytesRead);            }        else /* PINTR_MODE, NONBLOCKED_MODE, BUFFERED_MODE */            {            /* (This mode has to be VISION_BUFFERED_MODE) */            ENTER_CRITSECT (pFd->rxCrSection);            bytesRead = visionRemoveFromQueue (&pFd->rxQueue ,pBuffer ,maxbytes);

⌨️ 快捷键说明

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