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

📄 cs8950.c

📁 wince.net板级支持包BSP for EP9315
💻 C
📖 第 1 页 / 共 4 页
字号:
    if (Errors & RX_ERR_NO_BUFFER)
    {
        EdbgOutputDebugString("VpsRecvError(): RX_ERR_NO_BUFFER\n");
    }
}

/******************************************************************************
*
* ProcessTxStatusQueue()
*
******************************************************************************/

static int ProcessTxStatusQueue( PCHIP pChip )
{
    PCD   pCD;
    volatile WORD  Status;
    PTXREQ pTxReq;
    unsigned int loopCnt=0;
 
    pCD    = (PCD)pChip->pData;

    /* While the transmit status entry is not processed */
    while ( 1 )
    {
        Status=pCD->pTxStatNext->TxStat;

        if (Status & TxStat_TxFP ) 
        {
            break; //break the while loop
        } //end if
       
        /* 02/14/02 @melody It doesn't matter whether Suicide bit is set or not.
        if(ReadDWord( OpReg_MacCfg0) & 0x00000008)
        {
            EdbgOutputDebugString("ProcessTxStatusQueue: Suicide bit has turned on!\r\n");
            DumpRegisters();
        }
        */
        
        loopCnt++;
        DelayInuSec(1);
        if ( loopCnt > 90000 ) 
        { 
            EdbgOutputDebugString("CS8950 ProcessTxStatusQueue(): Error Tx not complete!\n");
            // QQQQQQQQQQQQQQQ           DumpRegisters();
            return FALSE;
        }
    }//end while

    /* Find the associated transmit request */
    pTxReq = &pCD->TxReq[pCD->pTxStatNext->BufIndx];
 
    /* The transmit descriptors for this frame are now available */
    pCD->TxDescAvail += pTxReq->DescCount;

    /* The transmit status entry is now processed */
    pCD->pTxStatNext->TxStat = 0;

    /* Increment to the next transmit status entry (with wrap-around) */
    pCD->pTxStatNext++;
    if ( pCD->pTxStatNext == pCD->pTxStatLimit )
       pCD->pTxStatNext = pCD->pTxStat;

    pCD->TxQueueDepth--;
    if (pCD->TxQueueDepth < 0 ) {
       EdbgOutputDebugString(
           "CS8950 ProcessTxStatusQueue(): Error TxQueueDepth is less than 0!\n");
    }

    /* If the frame was not sent without errors */
    if ( !(Status & TxStat_TxWE) )  
    {
        /* Report the errors */
        VpsSendError( pChip,  (WORD)(Status&TxStat_Error_Mask));
        return FALSE;
    } 
    
    else 
    {
        /* Another frame has been transmitted without an error */
        pCD->TxGoodCount++;
        Global_TxOkCnt++;
    }
    return TRUE;
}

//****************************************************************************
// AvaliableRecieveBuffers
//****************************************************************************
// 
// 
//
ULONG AvaliableRecieveBuffers(void)
{
    ULONG           ulCount;
    ULONG           ulAvailable = 0;

    for(ulCount = 0; ulCount < RXSTATCOUNT ; ulCount++)
    {
        if(!pCS8950Buffer->RxStat[ulCount].RxStat)
        {
            ulAvailable++;
        }
    }
    return ulAvailable;
}    
    

/******************************************************************************
*
* VpsSendError(()
*
******************************************************************************/
static void VpsSendError( PCHIP pChip,  WORD Errors )
{
          Global_TxNotOkCnt++;

      if (Errors & TX_ERR_EXCESS_COLL){
         EdbgOutputDebugString("VpsSendError(): TX_ERR_EXCESS_COLL!\n");
      }
      if (Errors & TX_ERR_UNDERRUN){
         EdbgOutputDebugString("VpsSendError(): TX_ERR_UNDERRUN!\n");
      }
      if (Errors & TX_ERR_LOSS_CRS){
         EdbgOutputDebugString("VpsSendError(): TX_ERR_EXCESS_LOSS_CRS!\n");
      }
    
}




/******************************************************************************
*
* VchipSend()
*
* The return code indicates if the VCHIP held on the the transmit buffers.
* If the return code is MAC_SUCCESSFUL, then the VCHIP held on to the transmit buffers
* and the VPS can not reuse the buffers until the VCHIP calls the
* ChipFreeSendBuff() routine.  If the return code is MAC_FAILED, then the VCHIP
* did not hold on to the transmit buffers and the VPS may immediately reuse
* them.
*
******************************************************************************/

static void VchipSend( PCHIP pChip, WORD TotalLength, BYTE *pBuff )
{
    PCD    pCD;
    PTXREQ pTxReq;
    WORD   DescCount;
    TxDesc_t *pTxDesc;
    BYTE  *pTxBuff;

    
  
    //EdbgOutputDebugString
    //(
    //    "VchipSend pChip = 0x%x, TotalLength = 0x%x, pBuff = 0x%x \r\n",
    //    (ULONG)pChip,
    //    (ULONG)TotalLength,
    //    (ULONG)pBuff
    //);
  
    pCD    = (PCD)pChip->pData;
  
    pTxDesc= pCD->pTxDescNext;


    
    /* Only one transmit descriptor is used */
    DescCount=1;

    /* Fill in the transmit descriptor */
    
    pTxDesc->TxBufAdr  = pCD->TxBuff[pCD->TxReqIndex].PhysAddr;
    pTxDesc->BufLength = TotalLength;
    pTxDesc->BufIndx   = pCD->TxReqIndex;

    /* Start copying at the beginning of the next transmit buffer */
    pTxBuff = pCD->TxBuff[pCD->TxReqIndex].pBuff;

    /* Copy the contents of the data buffers to the transmit buffer */
    memcpy( pTxBuff, pBuff,TotalLength );

    /* Increment to the next transmit descriptor (with wrap-around) */
    pTxDesc++;
    if ( pTxDesc == pCD->pTxDescLimit )
        pTxDesc = pCD->pTxDesc;
  
    /* Save the transmit request in the transmit request table */
    pTxReq = &pCD->TxReq[pCD->TxReqIndex];
    pTxReq->StartIndex = (WORD)(pCD->pTxDescNext - pCD->pTxDesc);
    pTxReq->DescCount  = DescCount;

    /* Increment to the next entry in the transmit request table */
    pCD->TxReqIndex++;
    if ( pCD->TxReqIndex == TXREQCOUNT )
       pCD->TxReqIndex = 0;

    /* Update the pointer to the next transmit descriptor */
    pCD->pTxDescNext = pTxDesc;

    /* Update the number of transmit descriptors available */
    pCD->TxDescAvail -= DescCount;

    /* Set the End-of-Frame bit in the last transmit descriptor */
    if ( pTxDesc == pCD->pTxDesc )
       pTxDesc = pCD->pTxDescLimit;
    pTxDesc--;
    pTxDesc->BufIndx |= TxDesc_EOF;
    
    /* The number of Tx frames enqueued but needs to process statuses.*/
    pCD->TxQueueDepth++;
    if (pCD->TxQueueDepth > TXBUFFCOUNT ) 
    {
        EdbgOutputDebugString
        (
           "CS8950 VchipSend(): Error TxQueueDepth is larger than TXBUFFCOUNT!\n"
        );
    }

    //DumpRegisters();
    
    //__emit(0xEEEEEEEE);

    /* Enqueue the transmit descriptors to the chip */
    WriteDWord(OpReg_TxDEQ, DescCount );

    return; 
}

//#define INTR_TYPE_RX   0x0001   // EDBG lib only cares about RX intrs, others handled internally




/***************************************************************************
*
*   DumpRegisters(): 
*
***************************************************************************/
static void DumpRegisters(void) 
{
    volatile DWORD b32, b32b, *pb32;
    volatile WORD b16;
    volatile BYTE b8;
    int i;


    b32=ReadDWord( OpReg_RxCTL);
    EdbgOutputDebugString("RxCTL (0x0000): 0x%x \r\n",   b32);

    b8=ReadByte( OpReg_TxCTL);
    EdbgOutputDebugString("TxCTL (0x0004): 0x%x \r\n",   b8);

    b8=ReadByte( OpReg_TestCTL);
    EdbgOutputDebugString("TestCTL (0x0008): 0x%x \r\n", b8);

    b16=ReadWord( OpReg_MIICmd);
    EdbgOutputDebugString("MIICmd (0x0010): 0x%x \r\n",  b16);

    b16=ReadWord( OpReg_MIIData);
    EdbgOutputDebugString("MIIData (0x0014): 0x%x \r\n", b16);

    b8=ReadByte( OpReg_MIISts);
    EdbgOutputDebugString("MIISts (0x0018): 0x%x \r\n\r\n",    b8);

    b8=ReadByte( OpReg_SelfCTL);
    EdbgOutputDebugString("SelfCTL (0x0020): 0x%x \r\n", b8);

    b32=ReadDWord( OpReg_IntEn);
    EdbgOutputDebugString("IntEn (0x0024): 0x%x \r\n",   b32);

    b32=ReadDWord( OpReg_IntStsP);
    EdbgOutputDebugString("IntStsPreserve (0x0028): 0x%x \r\n",  b32);

    b32=ReadDWord( OpReg_IntStsC);
    EdbgOutputDebugString("IntStsClear (0x002C): 0x%x \r\n\r\n",   b32);

    b32=ReadDWord( OpReg_GT);
    EdbgOutputDebugString("GeneralTimer (0x0040): 0x%x \r\n\r\n",  b32);

    b32=ReadDWord( OpReg_FCT);
    EdbgOutputDebugString("FlowCtlTimer (0x0044): 0x%x \r\n",    b32);

    b32=ReadDWord( OpReg_FCF);
    EdbgOutputDebugString("FlowCtlFormat (0x0048): 0x%x \r\n\r\n", b32);

    b32=ReadDWord( OpReg_FERMask);
    EdbgOutputDebugString("FlowCtlFormat (0x0064): 0x%x \r\n",   b32);

    b16=ReadWord( OpReg_TxCollCnt);
    EdbgOutputDebugString("TxCollCnt (0x0070): 0x%x \r\n",   b16);

    b16=ReadWord( OpReg_RxMissCnt);
    EdbgOutputDebugString("RxMissCnt (0x0074): 0x%x \r\n",   b16);

    b16=ReadWord( OpReg_RxRuntCnt);
    EdbgOutputDebugString("RxRuntCnt (0x0078): 0x%x \r\n\r\n", b16);

    b16=ReadWord( OpReg_BMCTL);
    EdbgOutputDebugString("BMCTL (0x0080): 0x%x \r\n",   b16);

    b8=ReadByte( OpReg_BMSts);
    EdbgOutputDebugString("BusMasterSts (0x0084): 0x%x \r\n\r\n",  b8);

    b32=ReadDWord( OpReg_RxBCA);
    EdbgOutputDebugString("RxBuffCurrAddr (0x0088): 0x%x \r\n",  b32);

    b32=ReadDWord( OpReg_TxBCA);
    EdbgOutputDebugString("TxBuffCurrAddr (0x008c): 0x%x \r\n\r\n",    b32);

    b32=ReadDWord( OpReg_RxDBA);
    EdbgOutputDebugString("RxDescQBaseAddr (0x0090): 0x%x \r\n", b32);

    b16=ReadWord( OpReg_RxDBL);
    EdbgOutputDebugString("RxDescQBaseLen (0x0094): 0x%x \r\n",  b16);

    b16=ReadWord( OpReg_RxDCL);
    EdbgOutputDebugString("RxDescQCurrLen (0x0096): 0x%x \r\n",  b16);

    b32=ReadDWord( OpReg_RxDCA);
    i= (b32 -(unsigned long)gCD.RxDescPhysAddr)/8;
    EdbgOutputDebugString("RxDescCurrAddr (0x0098): 0x%x index=%d\r\n",  b32, i);

    b32=ReadDWord( OpReg_RxDEQ);
    EdbgOutputDebugString("RxDescEnQ (0x009c): 0x%x \r\n\r\n", b32);

    b32=ReadDWord( OpReg_RxSBA);
    EdbgOutputDebugString("RxStsBaseAddr (0x00a0): 0x%x \r\n",b32);

    b16=ReadWord( OpReg_RxSBL);
    EdbgOutputDebugString("RxStsBaseLen (0x00a4): 0x%x \r\n",    b16);

    b16=ReadWord( OpReg_RxSCL);
    EdbgOutputDebugString("RxStsCurrLen (0x00a6): 0x%x \r\n",    b16);

    b32=ReadDWord( OpReg_RxSCA);
    i= (b32 -(unsigned long)gCD.RxStatPhysAddr)/8;
    EdbgOutputDebugString("RxStsCurrAddr (0x00a8): 0x%x index=%d\r\n",   b32, i);

    b32=ReadDWord( OpReg_RxSEQ);
    EdbgOutputDebugString("RxStsEnQ (0x00ac): 0x%x \r\n\r\n",  b32);

    b32=ReadDWord( OpReg_TxDBA);
    EdbgOutputDebugString("TxDescQBaseAddr (0x00b0): 0x%x \r\n", b32);

    b16=ReadWord( OpReg_TxDBL);
    EdbgOutputDebugString("TxDescBaseLen (0x00b4): 0x%x \r\n",   b16);

    b16=ReadWord( OpReg_TxDCL);
    EdbgOutputDebugString("TxDescQCurrLen (0x00b6): 0x%x \r\n",  b16);

    b32=ReadDWord( OpReg_TxDCA);
    i= (b32 -(unsigned long)gCD.TxDescPhysAddr)/8;
    EdbgOutputDebugString("TxDescCurrAddr (0x00b8): 0x%x index=%d\r\n",  b32, i);

    b32=ReadDWord( OpReg_TxDEQ);
    EdbgOutputDebugString("TxDescEnQ (0x00bc): 0x%x \r\n\r\n", b32);

    b32=ReadDWord( OpReg_TxSBA);
    EdbgOutputDebugString("TxStsQBaseAddr (0x00c0): 0x%x \r\n",  b32);

    b16=ReadWord( OpReg_TxSBL);
    EdbgOutputDebugString("TxStsQBaseLen (0x00c4): 0x%x \r\n",   b16);

    b16=ReadWord( OpReg_TxSCL);
    EdbgOutputDebugString("TxStsQCurrLen (0x00c6): 0x%x \r\n",   b16);

    b32=ReadDWord( OpReg_TxSCA);
    i= (b32 -(unsigned long)gCD.TxStatPhysAddr)/4;
    EdbgOutputDebugString("TxStsCurrAddr (0x00c8): 0x%x index=%d \r\n\r\n", b32, i);

    b32=ReadDWord( OpReg_RxBTH);
    EdbgOutputDebugString("RxBuffTH (0x00d0): 0x%x \r\n",    b32);

    b32=ReadDWord( OpReg_TxBTH);
    EdbgOutputDebugString("TxBuffTH (0x00d4): 0x%x \r\n",    b32);

    b32=ReadDWord( OpReg_RxSTH);
    EdbgOutputDebugString("RxStsTH (0x00d8): 0x%x \r\n", b32);

    b32=ReadDWord( OpReg_TxSTH);
    EdbgOutputDebugString("TxStsTH (0x00dc): 0x%x \r\n", b32);

    b32=ReadDWord( OpReg_RxDTH);
    EdbgOutputDebugString("RxDescTH (0x00e0): 0x%x \r\n",    b32);

    b32=ReadDWord( OpReg_TxDTH);
    EdbgOutputDebugString("TxDescTH (0x00e4): 0x%x \r\n\r\n",  b32);

    b32=ReadDWord( OpReg_MaxFL);
    EdbgOutputDebugString("MaxFrameLen (0x00e8): 0x%x \r\n", b32);

    b32=ReadDWord( OpReg_RxHLen);
    EdbgOutputDebugString("RxHeaderLen (0x00ec): 0x%x \r\n", b32);
    
    b32 = ReadDWord(OpReg_MacCfg0);
    EdbgOutputDebugString("RxHeaderLen (0x0100): 0x%x \r\n", b32);

#if 0

    pb32=(unsigned long *)gCD.pRxDesc;
    EdbgOutputDebugString("\r\n\r\n******** Rx Descript Q address = 0x%x ***********\r\n", (unsigned long)gCD.pRxDesc);
    for ( i=0; i<RXDESCCOUNT ;i++) {
        b32=*pb32;
        pb32++;
        b32b=*pb32;
        pb32++;
        EdbgOutputDebugString(" Index %d: DW1=0x%x  DW2=0x%x\r\n", i, b32, b32b);
    }

    pb32=(unsigned long *)gCD.pRxStat;
    EdbgOutputDebugString("\r\n\r\n******** Rx Status Q address = 0x%x ***********\r\n", (unsigned long)gCD.pRxStat);
    for ( i=0; i<RXSTATCOUNT ;i++) {
        b32=*pb32;
        pb32++;
        b32b=*pb32;
        pb32++;
        EdbgOutputDebugString(" Index %d: DW1=0x%x  DW2=0x%x\r\n", i, b32, b32b);
    }
#endif // 0
    pb32=(unsigned long *)gCD.pTxStat;
    EdbgOutputDebugString("\r\n\r\n******** Tx Status Q address = 0x%x ***********\r\n", (unsigned long)gCD.pTxStat);
    for ( i=0; i<TXSTATCOUNT ;i++) {
        b32=*pb32;
        pb32++;
        EdbgOutputDebugString(" Index %d: 0x%x  \r\n", i, b32);
    }

    pb32=(unsigned long *)gCD.pTxDesc;
    EdbgOutputDebugString("\r\n\r\n******** Tx Descript Q address = 0x%x ***********\r\n", (unsigned long)gCD.pTxDesc);
    for ( i=0; i<TXDESCCOUNT ;i++) {
        b32=*pb32;
        pb32++;
        b32b=*pb32;
        pb32++;
        EdbgOutputDebugString(" Index %d: DW1=0x%x  DW2=0x%x\r\n", i, b32, b32b);
    }


#if 0
    EdbgOutputDebugString("\r\n\r\n************* FIFO Rx Data  ****************\r\n");
    for ( pb32=(unsigned long *)&pCS8950Buffer->RxBuff[0]; pb32<(unsigned long *)&pCS8950Buffer->RxBuff[RXBUFFSIZE];pb32++) {
        b32=*pb32;
        EdbgOutputDebugString(" addr 0x%x:  0x%x  \r\n", (unsigned long)pb32, b32);
    }

    EdbgOutputDebugString("\r\n\r\n************* FIFO Tx Data ****************\r\n");
    for ( pb32=(unsigned long *)&pCS8950Buffer->TxBuff[0]; pb32<(unsigned long *)&pCS8950Buffer->TxBuff[RXBUFFSIZE];pb32++) {
        b32=*pb32;
        EdbgOutputDebugString(" addr 0x%x:  0x%x  \r\n", (unsigned long)pb32, b32);
    }
#endif // 0    

#if 0
    EdbgOutputDebugString("\r\n\r\n************* FIFO Rx Descript ****************\r\n");
    for ( pb32=(unsigned long *)&pCS8950Buffer->RxDesc[0]; pb32<(unsigned long *)(&pCS8950Buffer->RxDesc[RXDESCCOUNT]);pb32++) {
        b32=*pb32;
        EdbgOutputDebugString(" addr 0x%x:  0x%x  \r\n", (unsigned long)pb32, b32);
    }

    EdbgOutputDebugString("\r\n\r\n************* FIFO Rx Status ****************\r\n");
    for ( pb32=(unsigned long *)&pCS8950Buffer->RxStat[0]; pb32<(unsigned long *)(&pCS8950Buffer->RxStat[RXSTATCOUNT]);pb32++) {
        b32=*pb32;
        EdbgOutputDebugString(" addr 0x%x:  0x%x  \r\n", (unsigned long)pb32, b32);
    }
#endif // 0
    EdbgOutputDebugString("\r\n\r\n************* FIFO Tx Status ****************\r\n");
    for ( pb32=(unsigned long *)&pCS8950Buffer->TxStat[0]; pb32<(unsigned long *)(&pCS8950Buffer->TxStat[TXSTATCOUNT]);pb32++) {
        b32=*pb32;
        EdbgOutputDebugString(" addr 0x%x:  0x%x  \r\n", (unsigned long)pb32, b32);
    }


    EdbgOutputDebugString("\r\n\r\n************* FIFO Tx Descript ****************\r\n");
    for ( pb32=(unsigned long *)&pCS8950Buffer->TxDesc[0]; pb32<(unsigned long *)(&pCS8950Buffer->TxDesc[TXDESCCOUNT]);pb32++) {
        b32=*pb32;
        EdbgOutputDebugString(" addr 0x%x:  0x%x  \r\n", (unsigned long)pb32, b32);
    }
}

⌨️ 快捷键说明

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