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

📄 xllp_ethernet.c

📁 Xcale270Bsp包,wince平台
💻 C
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************
**
**  COPYRIGHT (C) 2000, 2001 Intel Corporation.
**
**  This software as well as the software described in it is furnished under 
**  license and may only be used or copied in accordance with the terms of the 
**  license. The information in this file is furnished for informational use 
**  only, is subject to change without notice, and should not be construed as 
**  a commitment by Intel Corporation. Intel Corporation assumes no 
**  responsibility or liability for any errors or inaccuracies that may appear 
**  in this document or any software that may be provided in association with 
**  this document. 
**  Except as permitted by such license, no part of this document may be 
**  reproduced, stored in a retrieval system, or transmitted in any form or by 
**  any means without the express written consent of Intel Corporation. 
**
**  FILENAME:      xllp_ethernet.c
**
**  PURPOSE:       This file contains the LAN91C111 device driver. This module
**                 is common for all platforms supporting this device.
**
**  LAST MODIFIED:  $Modtime: 3/04/03 12:31p $
******************************************************************************/

/*
*******************************************************************************
*   HEADER FILES
*******************************************************************************
*/
#include "xllp_ethernet.h"
#include "xllp_ost.h"

/*
*******************************************************************************
*   LOCAL DEFINITIONS
*******************************************************************************
*/
static XLLP_BOOL_T dumpFlag = 0;
static XLLP_BOOL_T RxFlag = 0;
static XLLP_UINT32_T loggedError = 0;   // Error log
static P_XLLP_VUINT32_T LAN91C111IoP;   // I/O space


XLLP_UINT8_T wIntMask = 0;


#define FRAME_FILTER  0xAC00   // Allow broadcast

typedef struct EthernetFrameHeaderlab 
{
  XLLP_UINT16_T  wDestMAC[3];
  XLLP_UINT16_T  wSrcMAC[3];
  XLLP_UINT16_T  wFrameType;
} EthernetFrameHeader;

static volatile P_XLLP_OST_T TimerRegBaseP = (P_XLLP_OST_T)OST_REGISTER_BASE;

static
int getTimebase (void)
{
    return 13000000;
}

static
XLLP_UINT32_T getDelta (P_XLLP_OST_T regsP, unsigned start)
{
    volatile P_XLLP_OST_T OstControlRegsP = regsP;

    unsigned stop = OstControlRegsP->oscr0;
    if (stop < start)
        return stop + (start^0xffffffff) + 1;
    return stop - start;
}

/******************************************************************************

  Function Name: 
    XllpEthernetGetPointerToIORegistersBase

  Description: 
    This function returns the pointer to the Ethernet Controller register base.

  Global Register Modified: 
    None. 

  Input Arguments:
    None

  Output Arguments:
    None
          
  Return Value: 
    P_XLLP_UINT32_T - the pointer to the Ethernet Controller register base

*******************************************************************************/
static
P_XLLP_VUINT32_T XllpEthernetGetPointerToIORegistersBase (void)
{
    return LAN91C111IoP;
}
 
/******************************************************************************

  Function Name: 
    XllpEthernetSelectRegisterBank

  Description: 
    This function loads the bank number into the Ethernet Controller 
    bank select register.
    Note: The bank select register MUST be accessed as a doubleword at offset 0x0C.
          A double word write to offset 0x0C will only write the bank select register
          at offset 0x0E but will not write the registers 0x0C and 0x0D.
          The word access at the offset 0x0E can not be used to modify bank select
          register, because the specifics of implementation the Ethernet Controller
          on the Mainstone board.
          
  Global Register Modified: 
    None. 

  Input Arguments:
    XLLP_UINT32_T bank - a bank number 0-3, and 7

  Output Arguments:
    None
              
  Return Value: 
    None

*******************************************************************************/

static
void XllpEthernetSelectRegisterBank (XLLP_UINT32_T bank)
{
    P_XLLP_VUINT32_T ioRegsP = XllpEthernetGetPointerToIORegistersBase();     // Get pointer to I/O space
	*(ioRegsP + XLLP_LAN91C111_BANK_SELECT_32) = 
	            ((bank & XLLP_LAN91C111_BANKSEL_MASK) << XLLP_LAN91C111_BANKSEL_SHIFT);
}

/******************************************************************************

  Function Name: 
    XllpEthernetReadDoubleWord

  Description: 
    This function reads a doubleword from the Ethernet Controller's registers 
    using 32-bit access

  Global Register Modified: 
    None. 

  Input Arguments:
    XLLP_UINT32_T offset - offset to the register

  Output Arguments:
    None
          
  Return Value: 
    XLLP_UINT32_T - the doubleword of data read from the register

*******************************************************************************/

static
XLLP_UINT32_T XllpEthernetReadDoubleWord(XLLP_UINT32_T offset)
{
    P_XLLP_VUINT32_T ioRegsP = XllpEthernetGetPointerToIORegistersBase();     // Get pointer to I/O space

    if (offset > 0)
      offset = offset >> 2;

    return ( *(ioRegsP + offset));
}

/******************************************************************************

  Function Name: 
    XllpEthernetReadWord

  Description: 
    This function reads a word value from the Ethernet Controller's registers using 32-bit
    access

  Global Register Modified: 
    None. 

  Input Arguments:
    XLLP_UINT32_T offset - offset to the register

  Output Arguments:
    None
          
  Return Value: 
    XLLP_UINT16_T - the word of data read from the register

*******************************************************************************/

static
XLLP_UINT16_T XllpEthernetReadWord(XLLP_UINT32_T offset)
{
	XLLP_UINT32_T tempValue;
    P_XLLP_VUINT32_T ioRegsP = XllpEthernetGetPointerToIORegistersBase ();     // Get pointer to I/O space

	tempValue = offset;
    if (offset > 0)
      offset = offset >> 2;

    if (tempValue & 0x2)
	{
		// Upper half word
		return (XLLP_UINT16_T)(*(ioRegsP + offset) >> 16);
	}
	else
	{
		// Lower half word
		return (XLLP_UINT16_T)(*(ioRegsP + offset) & 0x0000FFFF);
	}
}


/******************************************************************************

  Function Name: 
    XllpEthernetReadWord16

  Description: 
    This function reads a word value from the Ethernet Controller's registers using 16-bit
    access.

  Global Register Modified: 
    None. 

  Input Arguments:
    XLLP_UINT32_T offset - offset to the register

  Output Arguments:
    None
          
  Return Value: 
    XLLP_UINT16_T - the word of data read from the register

*******************************************************************************/

static
XLLP_UINT16_T XllpEthernetReadWord16(XLLP_UINT32_T offset)
{
    P_XLLP_VUINT16_T ioRegsP = (P_XLLP_VUINT16_T)XllpEthernetGetPointerToIORegistersBase (); // Get pointer to I/O space

    if (offset > 0)
      offset = offset >> 1;

	return (*(ioRegsP + offset));
}

/******************************************************************************

  Function Name: 
    XllpEthernetReadByte

  Description: 
    This function reads a byte value from the Ethernet Controller's registers using 32-bit
    access.

  Global Register Modified: 
    None. 

  Input Arguments:
    XLLP_UINT32_T offset - offset to the register

  Output Arguments:
    None
          
  Return Value: 
    XLLP_UINT8_T - the byte of data read from the register

*******************************************************************************/

static
XLLP_UINT8_T XllpEthernetReadByte(XLLP_UINT32_T offset)
{
    P_XLLP_VUINT8_T ioRegsP = (P_XLLP_VUINT8_T)XllpEthernetGetPointerToIORegistersBase();     // Get pointer to I/O space

    return ( *(ioRegsP + offset));
}
/******************************************************************************

  Function Name: 
    XllpEthernetWriteDoubleWord

  Description: 
    This function writes a doubleword to the Ethernet Controller's registers 
    using 32-bit access
    Note: This function CAN NOT be used to write to the Ethernet Controller registers
          at the offset 0x0C, because it will write only to the Bank select register
          at the offset 0x0E.

  Global Register Modified: 
    None 

  Input Arguments:
    XLLP_UINT32_T value  - the value that will be written to the registers
    XLLP_UINT32_T offset - offset to the register

  Output Arguments:
    None
          
  Return Value: 
    None

*******************************************************************************/

static
void XllpEthernetWriteDoubleWord(XLLP_UINT32_T value, XLLP_UINT32_T offset)
{
    P_XLLP_VUINT32_T ioRegsP = XllpEthernetGetPointerToIORegistersBase();     // Get pointer to I/O space

    if (offset > 0)
      offset = offset >> 2;
    *(ioRegsP + offset) = value;
}

/******************************************************************************

  Function Name: 
    XllpEthernetWriteWord

  Description: 
    This function writes a word value to the Ethernet Controller's registers using 32-bit
    access.
    Note: This function MUST be used to write to the Ethernet Controller registers
          at the odd offsets (0x02, 0x06, 0x0A, and 0x0E) of the doubleword.
          16-bit access can not be used to write to those registers,
          because the specifics of implementation the Ethernet Controller
          on the Mainstone board and the way how the XScale chip executes the 16-bit
          writes on the bus.

  Global Register Modified: 
    None. 

  Input Arguments:
    XLLP_UINT16_T value  - the value that will be written to the register
    XLLP_UINT32_T offset - offset to the register

  Output Arguments:
    None
          
  Return Value: 
    None

*******************************************************************************/

static
void XllpEthernetWriteWord(XLLP_UINT16_T value, XLLP_UINT32_T offset)
{
	XLLP_UINT32_T tempValue;
    P_XLLP_VUINT32_T ioRegsP = XllpEthernetGetPointerToIORegistersBase ();     // Get pointer to I/O space

	tempValue = offset;
    if (offset > 0)
      offset = offset >> 2;
    if (tempValue & 0x2)
	{
		// Upper half word
		*(ioRegsP + offset) = (*(ioRegsP + offset) & 0x0000FFFF) | (value << 16);
	}
	else
	{
		// Lower half word
		*(ioRegsP + offset) = (*(ioRegsP + offset) & 0xFFFF0000) | value;
	}
}

/******************************************************************************

  Function Name: 
    XllpEthernetWriteWord16

  Description: 
    This function writes a word value to the Ethernet Controller's registers using 16-bit
    access.
    Note: This function CAN NOT be used to write to the Ethernet Controller registers
          at the odd offsets (0x02, 0x06, 0x0A, and 0x0E) of the doubleword,
          because the specifics of implementation the Ethernet Controller
          on the Mainstone board and the way how the XScale chip executes the 16-bit
          writes on the bus. 
          This function MUST be used to write to the registers
          at the offsets 0xC, that require a word access.

  Global Register Modified: 
    None. 

  Input Arguments:
    XLLP_UINT16_T value  - the value that will be written to the register
    XLLP_UINT32_T offset - offset to the register

  Output Arguments:
    None
          
  Return Value: 
    None

*******************************************************************************/

static
void XllpEthernetWriteWord16(XLLP_UINT16_T value, XLLP_UINT32_T offset)
{
    P_XLLP_VUINT16_T ioRegsP = (P_XLLP_VUINT16_T)XllpEthernetGetPointerToIORegistersBase (); // Get pointer to I/O space

    if (offset > 0)
      offset = offset >> 1;
	*(ioRegsP + offset) = value;
}

/******************************************************************************

  Function Name: 
    XllpEthernetWriteByte

  Description: 
    This function writes a byte value to the Ethernet Controller's registers using 8-bit

⌨️ 快捷键说明

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