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

📄 wdbpipepktdrv.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    timeout.tv_usec = 0;    FD_ZERO (&readFds);    FD_SET (pDev->h2t_fd, &readFds);    if (SELECT (FD_SETSIZE, &readFds, (fd_set *)NULL,            (fd_set *)NULL, &timeout) > 0)        {        key = intLock();        wdbPipeInt (pDev);        intUnlock (key);        }    wdStart (wdPipeId, WD_TIMEOUT, (FUNCPTR) wdbPipeInputChk, (int)pDev);    }#endif /* CPU == SIMHPPA *//******************************************************************************** wdbPipeInt - pipe driver interrupt handler** RETURNS: N/A*/static STATUS wdbPipeInt    (    WDB_PIPE_PKT_DEV * pPktDev#if CPU==SIMNT    ,    int byteRead#endif    )    {#if CPU!=SIMNT    int 	byteRead;    short 	packetSize = 0;    char 	szPacketSize [sizeof(short)] = {0};#endif    struct 	mbuf * pMbuf;#if CPU==SIMNT    if ( polledPackets && !pollingInt )        {        polledPackets--;	return(ERROR);        }#endif            /*     * The code below is for handling a packet-recieved interrupt.     * A real driver may also have to check for other interrupting     * conditions such as DMA errors, etc.     */#if CPU != SIMNT	/* SIMNT Fake device does all of this */    /* input buffer already in use - drop this packet */    if (pPktDev->inputBusy)	{        wdbPipeFlush (pPktDev->h2t_fd);        DRIVER_DROP_PACKET(pPktDev);	return FALSE;	}    /*      * get the packet size     */        byteRead = READ (pPktDev->h2t_fd, szPacketSize, sizeof(short));    if (byteRead < sizeof(short))        {	/*	 * Flush the pipe only if we have received something. This is	 * usefull for polling mode if a packet was received between	 * READ() call and this test.	 */	    	if (byteRead > 0)	    wdbPipeFlush (pPktDev->h2t_fd);        return FALSE;        }    packetSize = * (short *) szPacketSize;    if (packetSize > WDB_PIPE_PKT_MTU)         {        wdbPipeFlush (pPktDev->h2t_fd);        return FALSE;        }    /*     * Fill the input buffer with the packet. Use an mbuf cluster to pass     * the packet on to the agent.     */    byteRead = READ (pPktDev->h2t_fd, pPktDev->inBuf, packetSize);    if (byteRead != packetSize)        {        wdbPipeFlush (pPktDev->h2t_fd);        return FALSE;        }#endif /* CPU != SIMNT */    pMbuf = wdbMbufAlloc();    if (pMbuf == NULL)	{	DRIVER_DROP_PACKET(pPktDev);	return FALSE;	}    wdbMbufClusterInit (pMbuf, pPktDev->inBuf, byteRead, \			(int (*)())wdbPipeFree, (int)pPktDev);    pPktDev->inputBusy = TRUE;    (*pPktDev->wdbDrvIf.stackRcv) (pMbuf);  /* invoke callback */    return TRUE;    }/******************************************************************************** wdbPipeTx - transmit a packet.** The packet is realy a chain of mbufs. We may have to just queue up* this packet is we are already transmitting.** RETURNS: OK or ERROR*/static STATUS wdbPipeTx    (    void 	* pDev,    struct mbuf * pMbuf    )    {    WDB_PIPE_PKT_DEV * 	pPktDev = pDev;    int 		lockKey;    struct mbuf * 	pFirstMbuf = pMbuf;    char 		data [WDB_PIPE_PKT_MTU + sizeof(short)];    int           	len;    int 		byteWritten = -1;    /* if we are in polled mode, transmit the packet in a loop */    if (pPktDev->mode == WDB_COMM_MODE_POLL)	{	DRIVER_POLL_TX(pPktDev, pMbuf);	return (OK);	}    lockKey = intLock();    /* if the txmitter isn't cranking, queue the packet and start txmitting */    if (pPktDev->outputBusy == FALSE)	{	pPktDev->outputBusy = TRUE;#if CPU==SIMNT	/* SIMNT doesn't need to prepend length */ 	len = 0;#else        len = 2;#endif        while (pMbuf != NULL)            {            bcopy (mtod (pMbuf, char *), &data[len], pMbuf->m_len);            len += pMbuf->m_len;            pMbuf = pMbuf->m_next;            }        wdbMbufChainFree (pFirstMbuf);#if CPU != SIMNT        * (short *) &data [0]  = (short) len - 2;         byteWritten = WRITE (pPktDev->t2h_fd, data, len);#else        if(pPktDev->t2h_fd)            {            byteWritten = mailslotWrite (pPktDev->t2h_fd, data, len);            }        if(byteWritten == -2)            {            mailslotClose( pPktDev->t2h_fd );            pPktDev->t2h_fd = mailslotConnect(TGTSVR_MAIL_SLOT,2);            if (pPktDev->t2h_fd == -1 )                {	        pPktDev->outputBusy = FALSE;                intUnlock (lockKey);                return(ERROR);                }            else                {                byteWritten = mailslotWrite (pPktDev->t2h_fd, data, len);                }            }#endif /* CPU != SIMNT */        /* Write has failed, treat the error for all arch */        if(byteWritten == -1)            {	    pPktDev->outputBusy = FALSE;            intUnlock (lockKey);            return(ERROR);            }	pPktDev->outputBusy = FALSE;	}    intUnlock (lockKey);    return (OK);    }/******************************************************************************** wdbPipeFree - free the input buffer** This is the callback used to let us know the agent is done with the* input buffer we loaded it.** RETURNS: N/A*/static void wdbPipeFree    (    void *	pDev    )    {    WDB_PIPE_PKT_DEV *	pPktDev = pDev;    pPktDev->inputBusy = FALSE;    }/******************************************************************************** wdbPipeModeSet - switch driver modes** RETURNS: OK for a supported mode, else ERROR*/static STATUS wdbPipeModeSet    (    void *	pDev,    uint_t	newMode    )    {    WDB_PIPE_PKT_DEV * pPktDev = pDev;    DRIVER_RESET_INPUT  (pPktDev);    DRIVER_RESET_OUTPUT (pPktDev);    if (newMode == WDB_COMM_MODE_INT) 	DRIVER_MODE_SET (pPktDev, WDB_COMM_MODE_INT);    else if (newMode == WDB_COMM_MODE_POLL)	DRIVER_MODE_SET (pPktDev, WDB_COMM_MODE_POLL);    else	return (ERROR);    return (OK);    }/******************************************************************************** wdbPipePoll - poll for a packet** This routine polls for a packet. If a packet has arrived it invokes* the agents callback.** RETURNS: OK if a packet has arrived, else ERROR.*/ static STATUS wdbPipePoll    (    void *	pDev    )    {    WDB_PIPE_PKT_DEV	* pPktDev = (WDB_PIPE_PKT_DEV *) pDev;#if CPU == SIMNT    if(pPktDev->inputBusy)        {        pollingInt = 1;        polledPackets++;	wdbPipeInt(pPktDev,simLastMailSize);        pollingInt = 0;        return( 0 );        }    simDelay(1);    return(ERROR);#else    if (wdbPipeInt (pPktDev))        return (OK);    else         return (ERROR);#endif /* CPU == SIMNT */    }#if CPU != SIMNT#if CPU != SIMHPPA/******************************************************************************** wdbPipeDrvModeSet - switch driver modes** RETURNS: N/A*/static void wdbPipeDrvModeSet    (    WDB_PIPE_PKT_DEV *	pPktDev,    uint_t		newMode    )    {    if (newMode == WDB_COMM_MODE_INT) 	{	s_fdint (pPktDev->h2t_fd, 1);	/*	 * XXX - DBT flush the pipe before entering interrupt mode. If the	 * pipe is not empty, it won't generate any interrupt when a packet	 * is received.	 */	wdbPipeFlush (pPktDev->h2t_fd);	}    else	/* poll mode */	s_fdint (pPktDev->h2t_fd, 0);    }#endif	/* CPU != SIMHPPA *//******************************************************************************** wdbPipeFlush - flush pipe receive bufer*/static void wdbPipeFlush    (    int pipeFd		/* pipe file desc */    )    {    char tmpBuf [WDB_PIPE_PKT_MTU];    int  nBytes;    do	{	nBytes = u_read (pipeFd, tmpBuf, WDB_PIPE_PKT_MTU);	}    while (nBytes > 0);    }#endif /* CPU != SIMNT */#endif /* CPU_FAMILY==SIMHPPA || CPU_FAMILY==SIMSPARCSOLARIS || ... */

⌨️ 快捷键说明

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