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

📄 ks_diag.c

📁 MICREL 网卡驱动 FOR CE 5.0
💻 C
📖 第 1 页 / 共 5 页
字号:


   /* Grab a Mblock\ClBlk\Cluster block */
#ifdef KS_PCI_BUS
   if ( (pMblk = (M_BLK_ID)ks884xAllocMblk(pDrvCtrl, &pCluster, NULL) ) == NULL )
#else
   if ( (pMblk = (M_BLK_ID)ks884xSHAllocMblk(pDrvCtrl, &pCluster, NULL) ) == NULL )
#endif
   {
        DisplayErrRetMsg( 5 ) ;
        return (totalRxPacket);
   }

   /* pMblk->mBlkHdr.mData = (char *)apbBuffer[BufNum]; */
   DBG_PRINT ("pMblk->mBlkHdr.mData=0x%08x\n",pMblk->mBlkHdr.mData);

   /* start vxWorks END driver polled mode operations */
#ifdef KS_PCI_BUS
   ks884xEndPollStart ( pDrvCtrl );
#else
   ks884xSHEndPollStart ( pDrvCtrl );
#endif

   while ( ( timeOutCount-- ) && ( BufNum < BUFFER_COUNT ) )
   {
        /* Copy received data from hardware packet memory to 'apbBuffer' */
#ifdef KS_PCI_BUS
        if ( ks884xEndPollReceive( pDrvCtrl, pMblk ) == 0 )
#else
        if ( ks884xSHEndPollReceive( pDrvCtrl, pMblk ) == TRUE )
#endif
        {
            /* Copy receive data to buffer */
            len  = netMblkToBufCopy (pMblk, (char *)apbBuffer[BufNum], NULL);
            /* len  = pMblk->mBlkHdr.mLen; */
            PrintPacketData ( (char *)&apbBuffer[BufNum][0], len, phw->m_bPortRX, 2);

           /* update counter */
           BufNum++;
           totalRxPacket++;
        }
        else
        {
           if (!timeOutCount)
               /* Fail if we're out of time */
               DisplayErrRetMsg( 4 ) ;
           else
               /* Delay in ms of time to check */
               DelayMillisec( DELAY_IN_nMS_TO_CHECK ) ;
        }
   } /* while ( ( timeOutCount-- ) && ( BufNum < BUFFER_COUNT ) ) */

   /* Done poll receive packet, free Mblk\ClBlk */
   netMblkClChainFree (pMblk);

   /* stop vxWorks END driver polled mode operations */
#ifdef KS_PCI_BUS
   ks884xEndPollStop ( pDrvCtrl );
#else
   ks884xSHEndPollStop ( pDrvCtrl );
#endif

   return (totalRxPacket);
}

#endif /* DEF_VXWORKS */

#ifdef M16C_62P
/*****************************************************************************
 *
 * hwbuftx_M16C - Tx packet to ks884X on Renesas M16C_62P platform.
 * hwbufrx_M16C - Rx packet from ks884X on Renesas M16C_62P platform .
 *
******************************************************************************/
static void hwbuftx_M16C
(
   unsigned long   Port,
   unsigned long   BufNum,
   unsigned long   BufLen,
   unsigned long   RepeatCount,
   BOOLEAN         SameBuf,
   unsigned long   ms_delay
)
{
   int              i ;


   if ( phw == NULL )
   {
        DisplayErrRetMsg( 3 ) ;
        return;
   }

   while (RepeatCount > 0)
   {
       /* Send frame to device */
#ifdef EARLY_TRANSMIT
       ksSendFrame ( &apbBuffer[BufNum][0], BufLen, Port );
#else
       if ( ksSendFrame ( (UINT8 * )&apbBuffer[BufNum][0], (UINT16)BufLen, (ULONG)Port ) )
#endif
            RepeatCount--;

       /* Find next buffer to transmit */
       if ( !SameBuf )
       {
           if (++BufNum >= BUFFER_COUNT)
              BufNum = 0 ;
       }
       /* else, use same buffer to repeat transmit */

       /* Delay in ms if requested */
       if ( ms_delay > 0 )
          DelayMillisec( ms_delay ) ;

   } /* while (RepeatCount) */

}

static unsigned long hwbufrx_M16C
(
   unsigned long   BufNum,
   long            timeOutCount
)
{
   unsigned short  InterruptMask;
   unsigned long   totalRxPacket=0;


   if ( phw == NULL )
   {
        DisplayErrRetMsg( 3 ) ;
        return (totalRxPacket);
   }

   /* Save the current interrupt mask and block all interrupts. */
   InterruptMask = HardwareBlockInterrupt( phw );

   while ( ( timeOutCount-- ) && ( BufNum < BUFFER_COUNT ) )
   {
       /* Copy received data from hardware packet memory to 'apbBuffer' */
       if ( NETWORK_CHECK_IF_RECEIVED() == TRUE )
       {
           /* Copy receive data to buffer */
           memcpy ( (char FAR *)&apbBuffer[BufNum][0], (char FAR *)&eth_pkt_hdr_rx_buf[0], ETH_HEADER_LEN );
           memcpy ( (char FAR *)&apbBuffer[BufNum][ETH_HEADER_LEN], (char FAR *)&eth_pkt_rx_buf[0],
                    (received_frame.frame_size - ETH_HEADER_LEN));

           /* dump received packet */
           PrintPacketData ( (UCHAR *)&apbBuffer[BufNum][0], (int)received_frame.frame_size,
                             (ULONG)phw->m_bPortRX, (ULONG)2);

           /* update counter */
           BufNum++;
           totalRxPacket++;

			/* discard received frame */
    		NETWORK_RECEIVE_END();
       }
       else
       {
           if (!timeOutCount)
               /* Fail if we're out of time */
               DisplayErrRetMsg( 4 ) ;
           else
               /* Delay in ms of time to check */
               DelayMillisec( DELAY_IN_nMS_TO_CHECK ) ;
       }
   } /* while ( ( timeOutCount-- ) && ( BufNum < BUFFER_COUNT ) ) */

   /* Restore the interrupt mask. */
   HardwareSetInterrupt( phw, InterruptMask );

   return (totalRxPacket);
}

#endif /* M16C_62P */

#ifdef _EZ80L92
/*****************************************************************************
 *
 * hwbuftx_EZ80L92 - Tx packet to ks884X on ZiLog eZ80L92 platform.
 * hwbuftx_EZ80L92 - Rx packet from ks884X on ZiLog eZ80L92 platform .
 *
******************************************************************************/
static void hwbuftx_EZ80L92
(
   unsigned long   Port,
   unsigned long   BufNum,
   unsigned long   BufLen,
   unsigned long   RepeatCount,
   BOOLEAN         SameBuf,
   unsigned long   ms_delay
)
{
   EMACFRAME     * xmit_packet;


   if ( phw == NULL )
   {
        DisplayErrRetMsg( 3 ) ;
        return;
   }

#if (0)
   /* Allocate a packet buffer  */
   xmit_packet = (EMACFRAME *)getmem ( BufLen+4 );
   if (xmit_packet == (EMACFRAME *) SYSERR)
   {
        DisplayErrRetMsg( 5 ) ;
        return ;
   }
#endif

   /*
    * Transmit the buffer data
    */

   while (RepeatCount > 0)
   {

#if (0)
       /* Copy data buffer to the EMACFRAME structure */
       memcpy ((char *)xmit_packet->DstAddr, (char *)apbBuffer[BufNum], BufLen);
       xmit_packet->Length = BufLen;
	   if ( send_packet( (EMACFRAME *) xmit_packet, Port ) == OK )
#endif
       if ( ksSendFrame ( &apbBuffer[BufNum][0], BufLen ) )
       {
            RepeatCount--;
       }

       /* Find next buffer to transmit */
       if ( !SameBuf )
       {
           if (++BufNum >= BUFFER_COUNT)
              BufNum = 0 ;
       }
       /* else, use same buffer to repeat transmit */

       /* Delay in ms if requested */
       if ( ms_delay > 0 )
          DelayMillisec( ms_delay ) ;

   } /* while (RepeatCount) */

   /* Done send packet, free packet buffer */
   freemem ( xmit_packet, (BufLen+4) );

}

static unsigned long hwbufrx_EZ80L92
(
   unsigned long   BufNum,
   long            timeOutCount
)
{
   unsigned long   totalRxPacket=0;
   EMACFRAME     * databuff=NULL;


   if ( phw == NULL )
   {
        DisplayErrRetMsg( 3 ) ;
        return (totalRxPacket);
   }

   /* Allocate a packet buffer  */
   databuff = (EMACFRAME *)getmem ( MAXIMUM_ETHERNET_PACKET_SIZE+4 );
   if (databuff == (EMACFRAME *) SYSERR)
   {
        DisplayErrRetMsg( 5 ) ;
        return (totalRxPacket);
   }


   /* start driver polled mode operations */
   ksPollStart ();

   while ( ( timeOutCount-- ) && ( BufNum < BUFFER_COUNT ) )
   {

        /* Copy received data from hardware packet memory to 'apbBuffer' */
        if ( ksPollReceive( databuff ) == TRUE )
        {
           /* Copy receive data to buffer */
           memcpy ( (char FAR *)&apbBuffer[BufNum][0], (char *)databuff->DstAddr, databuff->Length );
           PrintPacketData ( (unsigned char *)&apbBuffer[BufNum][0], (int)databuff->Length, phw->m_bPortRX, 2);

           /* update counter */
           BufNum++;
           totalRxPacket++;
        }
        else
        {
           if (!timeOutCount)
               /* Fail if we're out of time */
               DisplayErrRetMsg( 4 ) ;
           else
               /* Delay in ms of time to check */
               DelayMillisec( DELAY_IN_nMS_TO_CHECK ) ;
        }
   } /* while ( ( timeOutCount-- ) && ( BufNum < BUFFER_COUNT ) ) */

   /* Done send packet, free packet buffer */
   freemem ( databuff, (MAXIMUM_ETHERNET_PACKET_SIZE+4) );

   /* stop driver polled mode operations */
   ksPollStop ();

   return (totalRxPacket);
}

#endif /* _EZ80L92 */


/*****************************************************************
*
* Command: hwbuftx
*
* Format: "hwbuftx Port BufNum BufLen RepeatCount Delay"
*
******************************************************************/
int hwbuftx
(
   unsigned long   Port,
   unsigned long   BufNum,
   unsigned long   BufLen,
   unsigned long   RepeatCount,
   BOOLEAN         SameBuf,
   unsigned long   ms_delay
)
{


   if (BufferInit() != TRUE)
   {
      return FALSE ;
   }


   /*
    * Validate parameters
    */

#ifdef DEF_KS8842
   if ( Port > TOTAL_PORT_NUM )
#else
   if ( Port > 0 )
#endif
   {
      DisplayErrRetMsg( 1 ) ;
      return FALSE ;
   }

   if (BufNum >= BUFFER_COUNT)
   {
      DisplayErrRetMsg( 1 ) ;
      return FALSE ;
   }

   if (BufLen >= BUFFER_LENGTH)
   {
      DisplayErrRetMsg( 1 ) ;
      return FALSE ;
   }

   /*
    * Transmit the buffer data
    */

#ifdef DEF_VXWORKS
   hwbuftx_vxWorks ( Port, BufNum, BufLen, RepeatCount, SameBuf, ms_delay );
#endif /* DEF_VXWORKS */

#ifdef M16C_62P
   hwbuftx_M16C ( Port, BufNum, BufLen, RepeatCount, SameBuf, ms_delay );
#endif /* M16C_62P */

#ifdef _EZ80L92
   hwbuftx_EZ80L92 ( Port, BufNum, BufLen, RepeatCount, SameBuf, ms_delay );
#endif /* _EZ80L92 */

   DBG_PRINT( NEWLINE);

   return TRUE ;
}

/*****************************************************************
*
* Command: hwbufrx
*
* Format: "hwbufrx  Port BufNum"
*
******************************************************************/
int hwbufrx
(
   unsigned long   BufNum,
   unsigned long   TimeOut
)
{
   unsigned long   totalRxPacket=0;
   long            timeOutCount;




   if (BufferInit() != TRUE)
   {
      return FALSE ;
   }

   /*
    * Validate parameters
    */

   if (BufNum >= BUFFER_COUNT)
   {
      DisplayErrRetMsg( 1 ) ;
      return FALSE ;
   }

   timeOutCount = TimeOut /  DELAY_IN_nMS_TO_CHECK ; /* delay counter in the ms unit */
   if  (timeOutCount <= 0)
   {
      DisplayErrRetMsg( 1 ) ;
      return FALSE ;
   }

   /*
    * Receive the buffer data
    * Checking for newly-arrived Ehernet packets periodically by DELAY_IN_nMS_TO_CHECK ms
    * until Time out or received buffers are full ( BufNum < BUFFER_COUNT ).
    */


#ifdef DEF_VXWORKS
   totalRxPacket = hwbufrx_vxWorks ( BufNum, timeOutCount );
#endif /* DEF_VXWORKS */

#ifdef M16C_62P
   totalRxPacket = hwbufrx_M16C ( BufNum, timeOutCount );
#endif /* M16C_62P */

#ifdef _EZ80L92
   totalRxPacket = hwbufrx_EZ80L92 ( BufNum, timeOutCount );

⌨️ 快捷键说明

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