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

📄 vchip8950.c

📁 Cirrus EP9315 wince bsp
💻 C
📖 第 1 页 / 共 5 页
字号:
* VchipMulticastAddAll()
*
******************************************************************************/

void VchipMulticastAddAll( PCHIP pChip )
{
    DWORD RxControl;

 
    /* Get the current settings of the receiver control register */
    RxControl=ReadDWord( OpReg_RxCTL );

    /* Turn off the receiver while changing the hash table */
    WriteDWord( OpReg_RxCTL, RxControl & ~RxCTL_SerRxON );
    
    /* Set all the bits in the hash table */
    WriteByte( OpReg_AFP, AFP_Hash );
    WriteDWord( OpReg_HashTb , 0xFFFFFFFF );
    WriteDWord( OpReg_HashTb+4, 0xFFFFFFFF );

    /* Turn the receiver back on */
    WriteDWord(OpReg_RxCTL, RxControl );

}


/******************************************************************************
*
* VchipMulticastDeleteAll()
*
******************************************************************************/

void VchipMulticastDeleteAll( PCHIP pChip )
{
    DWORD RxControl;


    /* Get the current settings of the receiver control register */
    RxControl=ReadDWord( OpReg_RxCTL );

    /* Turn off the receiver while changing the hash table */
    WriteDWord( OpReg_RxCTL, RxControl & ~RxCTL_SerRxON );

    /* Clear all the bits in the hash table */
    WriteByte(OpReg_AFP, AFP_Hash );
    WriteDWord( OpReg_HashTb , 0 );
    WriteDWord( OpReg_HashTb+4, 0 );

    /* Turn the receiver back on */
    WriteDWord( OpReg_RxCTL, RxControl );
}


/******************************************************************************
*
* VchipMulticastAdd()
*
******************************************************************************/

void VchipMulticastAdd( PCHIP pChip, PEA pMulticastAddr )
{
    DWORD RxControl;
    DWORD  HashTable;
    BYTE  HashIndex;
    DWORD HashValue;

    HashTable = OpReg_HashTb;

    /* Calculate the hash index for this multicast address */
    HashIndex = CalculateHashIndex( (BYTE  *)pMulticastAddr );

    /* If the hash index is in the second double word of the hash table */
    if ( HashIndex >= 32 )
    {
      HashTable += 4;
      HashIndex -= 32;
    }

    /* Get the current settings of the receiver control register */
    RxControl=ReadDWord( OpReg_RxCTL );

    /* Turn off the receiver while changing the hash table */
    WriteDWord( OpReg_RxCTL, RxControl & ~RxCTL_SerRxON );

    /* Set the hash bit in the hash table */
    WriteByte( OpReg_AFP, AFP_Hash );
    HashValue = ReadDWord( HashTable);
    WriteDWord( HashTable, HashValue | (1L<<HashIndex) );

    /* Turn the receiver back on */
    WriteDWord( OpReg_RxCTL, RxControl );
}


/******************************************************************************
*
* VchipMulticastDelete()
*
******************************************************************************/

void VchipMulticastDelete( PCHIP pChip, PEA pMulticastAddr )
{
    DWORD RxControl;
    DWORD  HashTable;
    BYTE  HashIndex;
    DWORD HashValue;

    HashTable =  OpReg_HashTb;

    /* Calculate the hash index for this multicast address */
    HashIndex = CalculateHashIndex( (BYTE *)pMulticastAddr );

    /* If the hash index is in the second double word of the hash table */
    if ( HashIndex >= 32 )
    {
        HashTable += 4;
        HashIndex -= 32;
    }

    /* Get the current settings of the receiver control register */
    RxControl=ReadDWord( OpReg_RxCTL );

    /* Turn off the receiver while changing the hash table */
    WriteDWord( OpReg_RxCTL, RxControl & ~RxCTL_SerRxON );

    /* Clear the hash bit in the hash table */
    WriteByte(OpReg_AFP, AFP_Hash );
    HashValue=ReadDWord( HashTable );
    WriteDWord( HashTable, HashValue & ~(1L<<HashIndex) );

    /* Turn the receiver back on */
    WriteDWord( OpReg_RxCTL, RxControl );

}


/******************************************************************************
*
* CalculateHashIndex()
***********************************************************************/
static BYTE CalculateHashIndex( BYTE  *pMulticastAddr )
{
    DWORD CRC;
    BYTE  HashIndex;
    BYTE  AddrByte;
    DWORD HighBit;
    int   Byte;
    int   Bit;

    /* Prime the CRC */
    CRC = CRC_PRIME;

    /* For each of the six bytes of the multicast address */
    for ( Byte=0; Byte<6; Byte++ )
    {
        AddrByte = *pMulticastAddr++;

        /* For each bit of the byte */
        for ( Bit=8; Bit>0; Bit-- )
        {
            HighBit = CRC >> 31;
            CRC <<= 1;

            if ( HighBit ^ (AddrByte & 1) )
            {
                CRC ^= CRC_POLYNOMIAL;
                CRC |= 1;
            }

            AddrByte >>= 1;
        }
    }

    /* Take the least significant six bits of the CRC and copy them */
    /* to the HashIndex in reverse order.                           */
    for( Bit=0,HashIndex=0; Bit<6; Bit++ )
    {
        HashIndex <<= 1;
        HashIndex |= (BYTE)(CRC & 1);
        CRC >>= 1;
    }

    return HashIndex;
}

/******************************************************************************
*
* VchipShutdown()
*
******************************************************************************/

void VchipShutdown( PCHIP pChip )
{
   PCD pCD;


   pCD = pChip->pData;

   VominiStopTimer( pChip, pCD->DaemonTimer );
   VchipReset( pChip );

}

/******************************************************************************
*
* GetMACAddrFromEEPROM()
*
******************************************************************************/
static BOOL   GetMACAddrFromEEPROM(WORD *MAC_ADDRESS)
{
    int i;
    DWORD status;

    /* check if EEPROM engine is inactive (0) ? If active(1), wait for inactive.*/

    for ( i=0; i<MAXLOOP; i++) 
    {
        status=(*(volatile PDWORD const)( OpReg_EEPROM_CTL));
        if ( status & EEPROM_EEST == 0 ) 
        {
            break;
        } 
    }

    if ( status & EEPROM_EEST) 
    {
        return FALSE;  /* EEPROM Error?*/
    }

    status=(*(volatile PDWORD const)( OpReg_EEPROM_CTL));
    if ( status & EEPROM_EELD == 0) 
    {
        return FALSE;  /* EEPROM Load Error?*/
    }

    MAC_ADDRESS[0]=ReadWord(OpReg_IndAd );
    MAC_ADDRESS[1]=ReadWord(OpReg_IndAd+2);
    MAC_ADDRESS[2]=ReadWord(OpReg_IndAd+4);

    return TRUE;
}
/***************************************************************************
*
*   DumpRegisters(): 
*
***************************************************************************/
static void DumpRegisters(void) 
{
    volatile DWORD b32;
    volatile WORD b16;
    volatile BYTE b8;
    int i;


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#if 0

    pb32=(unsigned long *)gCD.pRxDesc;
    DbgPrint("\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++;
        DbgPrint(" Index %d: DW1=0x%x  DW2=0x%x\r\n", i, b32, b32b);
    }

    pb32=(unsigned long *)gCD.pRxStat;
    DbgPrint("\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++;
        DbgPrint(" Index %d: DW1=0x%x  DW2=0x%x\r\n", i, b32, b32b);
    }

    pb32=(unsigned long *)gCD.pTxStat;
    DbgPrint("\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++;
        DbgPrint(" Index %d: 0x%x  \r\n", i, b32);
    }

    pb32=(unsigned long *)gCD.pTxDesc;
    DbgPrint("\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++;
  

⌨️ 快捷键说明

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