wdbUlipPktDrv.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:5k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* wdbUlipPktDrv.c - WDB communication interface for the ULIP driver */
  2. /* Copyright 1994-2001 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01g,18oct01,jhw  Fixed documentation build errors.
  7. 01f,02dec96,dvs changed u_write to WriteUlip of SIMSPARCSOLARIS
  8. 01e,09nov96,pr  added simsolaris support.
  9. 01d,14oct95,jdi  doc: cleanup.
  10. 01c,15aug95,ms  locked ints around u_read. Added wdbUlipRcvFlush.
  11. 01b,27jun95,ms moved from BSP. wdbUlipPktDevInit now takes a device name.
  12. 01a,06oct94,ms  written.
  13. */
  14. /*
  15. DESCRIPTION
  16. This is a lightweight ULIP driver that interfaces with the WDB agent's
  17. UDP/IP interpreter.  It is the lightweight equivalent of the ULIP netif
  18. driver.  This module provides a communication path which supports
  19. both a task mode and an external mode WDB agent.
  20. */
  21. #include "vxWorks.h"
  22. #if (CPU_FAMILY==SIMSPARCSUNOS) || (CPU_FAMILY==SIMHPPA) || (CPU_FAMILY==SIMSPARCSOLARIS)
  23. #include "simLib.h"
  24. #include "u_Lib.h"
  25. #include "ioLib.h"
  26. #include "intLib.h"
  27. #include "iv.h"
  28. #include "wdb/wdbCommIfLib.h"
  29. #include "wdb/wdbMbufLib.h"
  30. #include "drv/wdb/wdbUlipPktDrv.h"
  31. /******************************************************************************
  32. *
  33. * wdbUlipPktFree - reset the receive packet state machine 
  34. */
  35. static void wdbUlipPktFree
  36.     (
  37.     WDB_ULIP_PKT_DEV * pDrv,
  38.     caddr_t buf
  39.     )
  40.     {
  41.     pDrv->inBufLocked = FALSE;
  42.     }
  43. /******************************************************************************
  44. *
  45. * wdbUlipRcvFlush - flush ULIP receive bufer
  46. */ 
  47. static void wdbUlipRcvFlush
  48.     (
  49.     int ulipFd /* ulip file desc */
  50.     )
  51.     {
  52.     char tmpBuf [ULIP_MTU];
  53.     int nBytes;
  54.     do
  55. {
  56. nBytes = u_read (ulipFd, tmpBuf, ULIP_MTU);
  57. }
  58.     while (nBytes > 0);
  59.     }
  60. /******************************************************************************
  61. *
  62. * wdbUlipIntRcv - receive an input packet in INT mode
  63. */
  64. static STATUS wdbUlipIntRcv
  65.     (
  66.     WDB_ULIP_PKT_DEV * pDrv
  67.     )
  68.     {
  69.     int nBytes;
  70.     struct mbuf * pMbuf;
  71.     /* if input buffer is full, drop all ULIP packets */
  72.     if (pDrv->inBufLocked || !(pMbuf = wdbMbufAlloc()))
  73. {
  74. wdbUlipRcvFlush (pDrv->ulipFd);
  75.         return (0);
  76. }
  77.     /* get the input packet */
  78.     nBytes = u_read (pDrv->ulipFd, pDrv->inBuf, ULIP_MTU);
  79.     /* flush the input queue to ensure the next SIGIO is sent properly */
  80.     if (nBytes > 0)
  81. wdbUlipRcvFlush (pDrv->ulipFd);
  82.     wdbMbufClusterInit (pMbuf, pDrv->inBuf, nBytes, (int (*)())wdbUlipPktFree,
  83. pDrv);
  84.     if (nBytes <= 0)
  85. {
  86. wdbMbufFree (pMbuf);
  87. return (0);
  88. }
  89.     pDrv->inBufLocked = TRUE;
  90.     (*pDrv->wdbDrvIf.stackRcv) (pMbuf);
  91.     return (nBytes);
  92.     }
  93. /******************************************************************************
  94. *
  95. * wdbUlipModeSet - Set the communication mode to POLL or INT.
  96. */
  97. static int wdbUlipModeSet
  98.     (
  99.     WDB_ULIP_PKT_DEV * pDrv,
  100.     uint_t  newMode
  101.     )
  102.     {
  103.     return (OK);
  104.     }
  105. /******************************************************************************
  106. *
  107. * wdbUlipWrite - write to the ULIP device
  108. */
  109. static int wdbUlipWrite
  110.     (
  111.     WDB_ULIP_PKT_DEV * pDrv,
  112.     struct mbuf *  pMbuf
  113.     )
  114.     {
  115.     struct mbuf * pFirstMbuf = pMbuf;
  116.     char data [ULIP_MTU];
  117.     int len = 0;
  118.     while (pMbuf != NULL)
  119. {
  120. bcopy (mtod (pMbuf, char *), &data[len], pMbuf->m_len);
  121. len += pMbuf->m_len;
  122. pMbuf = pMbuf->m_next;
  123. }
  124.     wdbMbufChainFree (pFirstMbuf);
  125.     
  126. #if     ( CPU==SIMSPARCSOLARIS )
  127.     return (WriteUlip (pDrv->ulipFd, data, len));
  128. #else /* ( CPU==SIMSPARCSOLARIS ) */
  129.     return (u_write (pDrv->ulipFd, data, len));
  130. #endif /* ( CPU==SIMSPARCSOLARIS ) */
  131.     }
  132. /******************************************************************************
  133. *
  134. * wdbUlipPktDevInit - initialize the communication functions for ULIP
  135. *
  136. * This routine initializes a ULIP device for use by the WDB debug agent.
  137. * It provides a communication path to the debug agent which can be
  138. * used with both a task and an external mode agent.
  139. * It is typically called by usrWdb.c when the WDB agent's lightweight
  140. * ULIP communication path is selected.
  141. *
  142. * RETURNS: N/A
  143. */
  144. void wdbUlipPktDevInit
  145.     (
  146.     WDB_ULIP_PKT_DEV * pDev, /* ULIP packet device to initialize */
  147.     char * ulipDev, /* name of UNIX device to use */
  148.     void (*stackRcv)() /* routine to call when a packet arrives */
  149.     )
  150.     {
  151.     pDev->wdbDrvIf.mode = WDB_COMM_MODE_POLL | WDB_COMM_MODE_INT;
  152.     pDev->wdbDrvIf.mtu = ULIP_MTU;
  153.     pDev->wdbDrvIf.stackRcv = stackRcv;
  154.     pDev->wdbDrvIf.devId = (void *)pDev;
  155.     pDev->wdbDrvIf.pollRtn = wdbUlipIntRcv;
  156.     pDev->wdbDrvIf.pktTxRtn = wdbUlipWrite;
  157.     pDev->wdbDrvIf.modeSetRtn = wdbUlipModeSet;
  158.     pDev->inBufLocked  = FALSE;
  159.     pDev->ulipFd = u_open (ulipDev, O_RDWR, 0);
  160.     intConnect (FD_TO_IVEC (pDev->ulipFd), (void (*)())wdbUlipIntRcv,
  161. (int)pDev);
  162.     s_fdint (pDev->ulipFd, 1);
  163.     }
  164. #endif /* (CPU_FAMILY==SIMSPARCSUNOS) || (CPU_FAMILY==SIMHPPA) || (CPU_FAMILY==SIMSPARCSOLARIS) */