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

📄 lan9118.h

📁 Lan9118以太网芯片linux驱动程序
💻 H
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************
   
Copyright (c) 2004-2005, SMSC
 
This code and information is provided as is without warranty of any kind,
either expressed or implied, including but not limited to the implied
warranties of merchantability and/or fitness for a particular purpose.
 
File name   :  lan9118.c  

Description :  Declares chip layer functions and defines.

Date            Modification                	Name        	
----            ------------                	-------				
18/02/05	Initial release V1.16		Phong Le
*****************************************************************************/

#ifndef LAN9118_H
#define LAN9118_H

/*------- includes files ----------------------------------------------------*/
// lint suppressions for StMicro/NexGen headers

// -e537	// Repeated include file



// -e607	// Parameter 'type' of macro found within string

// -e659	// Nothing follows '}' on line within struct/union/enum declaration



// -e773	// Expression-like macro not parenthesized



// -e935	// int within struct

// -e941	// Result 0 due to operand(s) equaling 0 in operation '<<'

// -e955	// Parameter name missing from prototype for function

// -e956	// Non const, non volatile static or external variable 'ngProtoList'

// -e958	// Padding is required to align member on 'n' byte boundary

// -e959	// Nominal struct size is not an even multiple of the maximum member alignment

// -e960	// a whole group of MISRA Required rules

// -e961	// a whole group of MISRA Advisory rules

// -e973	// Unary operator in macro not parenthesized



// -e1916	// Ellipsis encountered



/*lint -save*/

/*lint -e537 -e607 -e659 -e773 -e935 -e941 -e955 -e956 -e958 -e959 -e960 -e961 -e973 -e1916*/

#include <string.h>
#include <interrup.h>
#include <stdlib.h>
#include <stdio.h>
#include <ngnet.h>
#include <ngip/buf.h>
#include <ngeth.h>  
#include <ngip/ethernet.h>
#include <debug.h>
#include <stddefs.h>
#include <ngos.h>

/*
 **************************************************************
 *	BUGBUG (nw)  Dec. 16, 2004
 *
 *	When the above #include's ngnet.h, it indirectly #includes macros.h as follows:
 *      Including file ..\..\include\ngnet.h (library)
 *          Including file ..\..\include\ngos.h (library)
 *              Including file ..\..\include\ngos\cpu\st20\macros.h (library)
 *
 *	The problem is that macros.h incorrectly re-define's NULL, and there does
 *	not appear to be any good way to avoid that without changing macros.h.
 **************************************************************
 */
#ifdef _lint
#ifdef NULL
#undef NULL  /* lint -e{961,92} MISRA advisory rule 92 doesn't like undef*/
#define NULL ((void *)0)
#endif
#endif
/*lint -restore*/

typedef unsigned long DWORD;
typedef int BOOLEAN;

/* FUNCTION: 
 *   SetRegDW
 * DESCRIPTION: 
 *   Write to a memory mapped register
 * PARAMETERS:
 *   dwBase,   virtual base address of the register set.
 *	 dwOffset, offset from dwBase of register in the register set.
 *   dwVal,    the value to write to the register.
 * RETURN VALUE:
 *   none.
 */
#define SetRegDW(dwBase,dwOffset,dwVal) \
{	\
	(*(volatile DWORD *)((dwBase) + (dwOffset))) = (dwVal);	\
}

/* FUNCTION:
 *   GetRegDW
 * DESCRIPTION:
 *   Reads from a memory mapped register
 * PARAMETERS:
 *   dwBase,   virtual base address of the registers set.
 *   dwOffset, offset from dwBase of register in the register set.
 * RETURN VALUE:
 *   DWORD,    value read from register.
 */
#define GetRegDW(dwBase,dwOffset) \
	((DWORD)(*(volatile DWORD *)(dwBase + dwOffset)))

/* 
 * WriteFifo (dwBase, dwOffset, pdwBuf, dwDwordCount)
 *	Writes 'dwDwordCount' 4-byte integers starting at address 'pdwBuf'
 *	into TX fifo at address (dwBase + dwOffset)
 */
void WriteFifo(
	const DWORD dwBase,
	const DWORD dwOffset,
	const DWORD *pdwBuf,
	DWORD dwDwordCount);

/*
 * ReadFifo (dwBase, dwOffset, pdwBuf, dwDwordCount)
 * 	Reads 'dwDwordCount' 4-byte integers from RX fifo at address
 * 	(dwBase + dwOffset) and stores in memory buffer at address
 * 	pdwBuf
 */
void ReadFifo(
	const DWORD dwBase,
	const DWORD dwOffset,
	DWORD *pdwBuf,
	DWORD dwDwordCount);

/*
STRUCTURE: LAN9118_DATA
	This structure is used by the chip layer.
	It remembers where to access registers.
	It remembers revision IDs if there are subtle
	  differences between them.
	It remembers modes of operation.
	It will start tx and rx queue information
	And it may be used for other things that
	  have not been conceived yet.
	The members of this structure should be 
	considered private and only excessable from 
	the Lan_xxx functions
*/
typedef struct _LAN9118_DATA {
	NGbuf *saved_buf;	// store buffer taken out of queue but haven't
				// putted to TX fifo
	DWORD dwIdRev;

	DWORD dwPhyAddress;

	DWORD GpioSetting;

	NGushort  wLastADVatRestart;
	NGushort  wLastADV;

	NGushort eif_linkadv;
	NGubyte eif_link;
	NGubyte eif_linkcfg;

} LAN9118_DATA, * PLAN9118_DATA;

/* returns member variable 'eif_linkadv' within driver structure */
NGushort GetLinkAdv (const NGifnet * const netp);

/* sets member variable 'eif_linkadv' within driver structure */
void SetLinkAdv (const NGifnet * const netp, const NGushort value);

/* returns member variable 'eif_linkcfg' within driver structure */
NGubyte GetLinkCfg (const NGifnet * const netp);

/* sets member variable 'eif_linkcfg' within driver structure */
void SetLinkCfg (const NGifnet * const netp, const NGubyte value);

/* returns member variable 'eif_link' within driver structure */
NGubyte GetLink (const NGifnet * const netp);

/* sets member variable 'eif_link' within driver structure */
void SetLink (const NGifnet * const netp, const NGubyte value);

/* Phy_GetRegW () reads a 16-bit phy register values */
NGushort Phy_GetRegW(const NGifnet * const netp, const DWORD dwRegIndex);

/* Phy_SetRegW () writes a 16-bit phy register values */
void Phy_SetRegW(const NGifnet * const netp, DWORD dwRegIndex,NGushort wVal);

/* Phy_SetLink(netp) does link management settings */
void Phy_SetLink(const NGifnet * const netp);

/* Phy_GetLinkMode(netp) reads the current link settings */
void Phy_GetLinkMode(const NGifnet * const netp);

/* Phy_UpdateLinkMode(netp) detects any link changes */
void Phy_UpdateLinkMode(const NGifnet * const netp);

/*
 * LanDetectChipId () returns the ID of the Concord Ethernet chip.
 * 	Possible valid values are 0x115, 0x116, 0x117, 0x118
 */
DWORD LanDetectChipId (const DWORD dwLanBase);

/*
FUNCTION: Lan_WriteTxFifo
	This function is used to write a buffer to the
	Tx Fifo in PIO mode.
	This function is only intended to be called 
	  from with in other Lan_xxx functions.
*/
void Lan_WriteTxFifo(
	const DWORD dwLanBase, 
	const DWORD *pdwBuf, 
	DWORD dwDwordCount);

/*
FUNCTION: Lan_ReadRxFifo
    This function is used to read a buffer to the 
	Rx Fifo in PIO mode.
	This function is only intended to be called
	  from with in other Lan_xxx functions.
*/
void Lan_ReadRxFifo(
	const DWORD dwLanBase, 
	DWORD * pdwBuf, 
	DWORD dwDwordCount);

/*
FUNCTION: Lan_GetMacRegDW
    This function is used to read a Mac Register.
	This function is only intended to be called
	  from with in other Lan_xxx functions.
*/
DWORD Lan_GetMacRegDW(
	const DWORD dwLanBase, 
	const DWORD dwOffset);

/*
FUNCTION: Lan_SetMacRegDW
	This function is used to write a Mac register.
	This function is only intended to be called
	  from with in other Lan_xxx functions.
*/
void Lan_SetMacRegDW(
	const DWORD dwLanBase, 
	const DWORD dwOffset, 
	const DWORD dwVal);

/*
FUNCTION: Lan_GetPhyRegW
    This function is used to read a Mii/Phy register.
	This function is only intended to be called 
	  from with in other Lan_xxx functions.
*/
NGushort Lan_GetPhyRegW(
	const DWORD dwLanBase,
	const DWORD dwPhyAddress,
	const DWORD dwMiiIndex);

/*
FUNCTION: Lan_SetPhyRegW
    This function is used to write a Mii/Phy register.
	This function is only intended to be called
	  from with in other Lan_xxx functions.
*/
void Lan_SetPhyRegW(
	const DWORD dwLanBase,
	const DWORD dwPhyAddress,
	const DWORD dwMiiIndex,
	const NGushort wVal);

/*
FUNCTION: Lan_ShowRegs
    This function is used to display the registers. 
	Except the phy.
*/
void Lan_ShowRegs(const DWORD dwLanBase);

/*
FUNCTION: Lan_StopGptTimer
    This function disables Lan9118 GPT timer
*/
void Lan_StopGptTimer (const DWORD dwLanBase);

/*
FUNCTION: Lan_Initialize
  This function should be the first Lan_xxx function called
  It begins to initialize the LAN9118_DATA structure.
  It reads some ID values from the chip.
  It resets the chip.

RETURN VALUE:
	returns TRUE on Success,
	returns FALSE on Failure,
*/
BOOLEAN Lan_Initialize(const NGifnet * const netp);

/*
FUNCTION: Phy_Initialize
  This function should be called after Lan_InitializeInterrupts.
  Continues to initialize the LAN9118_DATA structure.
  It reads some phy ID values from the phy
  It resets the phy.
RETURN VALUE:
	returns TRUE on Success,
	returns FALSE on Failure,
*/
BOOLEAN Phy_Initialize(const NGifnet * const netp, DWORD dwPhyAddr);

/*
FUNCTION: Lan_EnableInterrupt
  Enables bits in INT_EN according to the set bits in dwMask
  WARNING this has thread synchronization issues. Use with caution.
*/
void Lan_EnableInterrupt(const DWORD dwLanBase,DWORD dwMask);

/*
FUNCTION: Lan_GetInterruptStatus
  Reads and returns the value in the INT_STS register.
*/
DWORD Lan_GetInterruptStatus(const DWORD dwLanBase);

/*
FUNCTION: Lan_ClearInterruptStatus
  Clears the bits in INT_STS according to the bits set in dwMask
*/
void Lan_ClearInterruptStatus(const DWORD dwLanBase,DWORD dwMask);

/*
FUNCTION: Lan_InitializeInterrupts
  Should be called after Lan_Initialize
  Should be called before the ISR is registered.
*/
void Lan_InitializeInterrupts(const DWORD dwLanBase,DWORD dwIntCfg);

/*
FUNCTION: Lan_EnableSoftwareInterrupt
  Clears a flag in the LAN9118_DATA structure
  Sets the SW_INT_EN bit of the INT_EN register
  WARNING this has thread sychronization issues. Use with caution.
*/
void Lan_EnableSoftwareInterrupt(const DWORD dwLanBase);

/*
FUNCTION: Lan_HandleSoftwareInterrupt
  Disables the SW_INT_EN bit of the INT_EN register,
  Clears the SW_INT in the INT_STS,
  Sets a flag in the LAN9118_DATA structure
*/
void Lan_HandleSoftwareInterrupt(const DWORD dwLanBase);

/*
FUNCTION: Lan_SetMacAddress sets the Mac Address
*/
void Lan_SetMacAddress(const DWORD dwLanBase,DWORD dwHigh16,DWORD dwLow32);

/*
FUNCTION: Lan_GetMacAddress gets the Mac Address
*/
void Lan_GetMacAddress(const DWORD dwLanBase,DWORD * dwHigh16,DWORD * dwLow32);

/*
FUNCTION: Lan_InitializeTx
  Prepares the LAN9118 for transmission of packets
  must be called before 
	Lan_SendPacketPIO
	Lan_CompleteTx
*/
void Lan_InitializeTx(const DWORD dwLanBase);

/*
FUNCTION: Lan_SendPacketPIO
  Sends a specified packet out on the ethernet line.
  Must first call Lan_InitializeTx
  WARNING: wPacketTag must not be 0. Zero is reserved.
*/
void Lan_SendPacketPIO(
		const DWORD dwLanBase,
		NGushort wPacketTag, 
		NGushort wPacketLength,
		NGubyte *pbPacketData);

/*
FUNCTION: Lan_CompleteTx
  Gets the Status DWORD of a previous transmission from the TX status FIFO
  If the TX Status FIFO is empty as indicated by TX_FIFO_INF then this
    function will return 0
*/
DWORD Lan_CompleteTx(const DWORD dwLanBase);

/*
FUNCTION: Lan_GetTxDataFreeSpace
  Gets the free space available in the TX fifo
*/
DWORD Lan_GetTxDataFreeSpace(const DWORD dwLanBase);

/*
FUNCTION: Lan_GetTxStatusCount
  Gets the number of TX completion status' available on the TX_STATUS_FIFO
  These can be read from Lan_CompleteTx
*/
DWORD Lan_GetTxStatusCount(const DWORD dwLanBase);

/*
FUNCTION: Lan_InitializeRx
  Prepares the LAN9118 for reception of packets
  Must be called After Lan_InitializeInterrupts
*/
void Lan_InitializeRx(const DWORD dwLanBase,DWORD dwRxCfg);

/*
FUNCTION: Lan_PopRxStatus
  If an Rx Status DWORD is available it will return it.
*/
DWORD Lan_PopRxStatus(const DWORD dwLanBase);

/* Phy_CheckLink(netp) is called periodically at every 100 msec
 * 	to check and update current link status.
 */
void Phy_CheckLink (const NGifnet * const netp);

/*
FUNCTION: Rx_FastForward
This function skips the current packet in RX fifo.
*/
void Rx_FastForward(const DWORD dwLanBase);

/*
 * LanDelayUS (dwLanBase, dwUS) delays 'dwUS' microseconds in this
 * 	function.
 */
void LanDelayUS(const DWORD dwLanBase, const DWORD dwUS);

/*
FUNCTION: update_tx_counters

⌨️ 快捷键说明

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