📄 lan91c96.c
字号:
/********************************************************************************** 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: lan91c96.c**** PURPOSE: This file contains the LAN91C96 device driver. This module** is common for all platforms supporting this device.**** LAST MODIFIED: $Modtime: 3/26/02 12:35a $******************************************************************************//********************************************************************************* HEADER FILES********************************************************************************/#include <redboot.h>#include <cyg/infra/cyg_type.h>#include "../include/lan91c96API.h"#include "../include/lan91c96.h"#define __TIMEOUT 100000#define __TIMEBASE 3686400extern void hal_clock_read(cyg_uint32 *) ;extern unsigned long hal_elapsed_ticks(unsigned long *) ;extern void hal_delay_us(cyg_uint32) ;extern LAN91C96_ContextT ctxSLan91c96;/********************************************************************************* LOCAL DEFINITIONS********************************************************************************///static OSTContextT *ostCtxP = &Ost;/********************************************************************************** FUNCTION:* ReadWord** DESCRIPTION:* Read 16-Bit Word from LAN91C96** INPUT PARAMETERS:* PVUINT32 offset - Pointer to value to read.** RETURNS:* Value read.** GLOBAL EFFECTS:* None.** ASSUMPTIONS:* None.** CALLS:* None.** CALLED BY:* All routines needed to access the LAN91C96 on board registers.** PROTOTYPE:* static* UINT16 ReadWord(PVUINT32 offset);*********************************************************************************/staticUINT16 ReadWord(PVUINT32 offset){ return((*offset & 0xFF) | ((*(offset + 1) & 0xFF) << 8));}/********************************************************************************** FUNCTION:* ReadByte** DESCRIPTION:* Read 8-bit byte from LAN91C96** INPUT PARAMETERS:* PVUINT32 offset - Pointer to value to read.** RETURNS:* Value read.** GLOBAL EFFECTS:* None.** ASSUMPTIONS:* None.** CALLS:* None.** CALLED BY:* All routines needed to access the LAN91C96 on board registers.** PROTOTYPE:* static* UINT16 ReadByte(PVUINT32 offset);*********************************************************************************/staticUINT16 ReadByte(PVUINT32 offset){ return(*offset & 0xFF);}/********************************************************************************** FUNCTION:* WriteWord** DESCRIPTION:* Write 16-Bit Word to LAN91C96** INPUT PARAMETERS:* UINT16 value - Value to write* PVUINT32 offset - Pointer of offset** RETURNS:* None.** GLOBAL EFFECTS:* None.** ASSUMPTIONS:* None.** CALLS:* None.** CALLED BY:* All routines needed to access the LAN91C96 on board registers.** PROTOTYPE:* static* VOID WriteWord(UINT16 value, PVUINT32 offset);*********************************************************************************/staticVOID WriteWord(UINT16 value, PVUINT32 offset){ *offset = value & 0xFF ; *(offset + 1) = (unsigned long)((value & 0xFF00) >> 8);}/********************************************************************************** FUNCTION:* WriteByte** DESCRIPTION:* Write 8-Bit byte to LAN91C96** INPUT PARAMETERS:* UINT16 value - Value to write* PVUINT32 offset - Pointer of offset** RETURNS:* None.** GLOBAL EFFECTS:* None.** ASSUMPTIONS:* None.** CALLS:* None.** CALLED BY:* All routines needed to access the LAN91C96 on board registers.** PROTOTYPE:* static* VOID WriteByte(UINT16 value, PVUINT32 offset);*********************************************************************************/staticVOID WriteByte(UINT16 value, PVUINT32 offset){ *offset = (value & 0xFF);}/********************************************************************************** FUNCTION:* GetTimeStamp** DESCRIPTION:* Get a time reference.** INPUT PARAMETERS:* LAN91C96_ContextT *ctxP - Pointer to the LAN91C96 Device Context Structure** RETURNS:* None.** GLOBAL EFFECTS:* The time stamp is updated in the DCS.** ASSUMPTIONS:* None.** CALLS:* None.** CALLED BY:* Any LAN91C96 internal routine.** PROTOTYPE:* VOID GetTimeStamp(LAN91C96_ContextT *ctxP);** NOTE:* static* This routine should be called prior to calling GetDeltaTimeStamp.*********************************************************************************/staticVOID GetTimeStamp(LAN91C96_ContextT *ctxP){ if (ctxP->timeFlag) { // Get starting poll start timestamp. ctxP->timeStamp = 0 ;//ostCtxP->getTimer_fnp(ostCtxP); } else { ctxP->timeStamp = 0; ctxP->deltaTime = 0; }}/********************************************************************************** FUNCTION:* GetDeltaTimeStamp** DESCRIPTION:* Get a delta time reference.** INPUT PARAMETERS:* LAN91C96_ContextT *ctxP - Pointer to the LAN91C96 Device Context Structure** RETURNS:* None.** GLOBAL EFFECTS:* The delta time stamp is updated in the DCS.** ASSUMPTIONS:* None.** CALLS:* None.** CALLED BY:* Any LAN91C96 internal routine.** PROTOTYPE:* VOID GetDeltaTimeStamp(LAN91C96_ContextT *ctxP);** NOTE:* static* This routine should be called after calling GetTimeStamp.*********************************************************************************/staticVOID GetDeltaTimeStamp(LAN91C96_ContextT *ctxP, PCHAR title){ if (ctxP->timeFlag) { ctxP->deltaTime = 0 ; //ostCtxP->getDelta_fnp(ostCtxP, ctxP->timeStamp); }}/********************************************************************************** FUNCTION:* DisplayTxStatus** DESCRIPTION:* Display the bit settings for the Transmit Status Word.** INPUT PARAMETERS:* LAN91C96_ContextT *ctxP - Pointer to the LAN91C96 Device Context Structure.** RETURNS:* None.** GLOBAL EFFECTS:* None.** ASSUMPTIONS:* None.** CALLS:* WriteByte - To write a byte to either the attribute or I/O space.* WriteWord - To write a word to either the attribute or I/O space.* DM_CWDbgPrintf - Display debug messages for this device.** CALLED BY:* LAN91C96TransmitPacket** PROTOTYPE:* static* VOID DisplayTxStatus(LAN91C96_ContextT *ctxP);*********************************************************************************/staticVOID DisplayTxStatus(LAN91C96_ContextT *ctxP){ PVUINT32 ioRegsP = ctxP->LAN91C96IoP; // Get pointer to I/O space volatile UINT16 ephSR; volatile unsigned char bankActiveOnEntry ; //Read the current bank and store so it can be restored upon exiting this function bankActiveOnEntry = ReadByte(&ioRegsP[LAN91C96_BANK_SELECT]) ; // Select Bank 0 WriteByte(BANK0, &ioRegsP[LAN91C96_BANK_SELECT]); // Get the transmit status. //WriteWord(LAN91C96_PTR_READ, &ioRegsP[LAN91C96_POINTER]); ephSR = ReadWord(&ioRegsP[LAN91C96_EPH_STATUS]); // Display the error bits. if (ephSR & LAN91C96_EPHSR_ERRORS) {//printf("LAN91C96_EPHSR_ERRORS\n") ; } if (ephSR & LAN91C96_EPHSR_SNGL_COL) { printf("LAN91C96_EPHSR_SNGL_COL\n") ; } if (ephSR & LAN91C96_EPHSR_MUL_COL) { printf("LAN91C96_EPHSR_MUL_COL\n") ; } if (ephSR & LAN91C96_EPHSR_16COL) { printf("LAN91C96_EPHSR_16COL\n") ; } if (ephSR & LAN91C96_EPHSR_SQET) { printf("LAN91C96_EPHSR_SQET\n") ; } if (ephSR & LAN91C96_EPHSR_TX_DEFR) { printf("LAN91C96_EPHSR_TX_DEFR\n") ; } if (ephSR & LAN91C96_EPHSR_LATCOL) { printf("LAN91C96_EPHSR_LATCOL\n") ; } if (ephSR & LAN91C96_EPHSR_LOST_CARR) { printf("LAN91C96_EPHSR_LOST_CARR\n") ; } if (ephSR & LAN91C96_EPHSR_EXC_DEF) { printf("LAN91C96_EPHSR_EXC_DEF\n") ; } if (ephSR & LAN91C96_EPHSR_LINK_OK) { printf("LAN91C96_EPHSR_LINK_OK\n") ; } if (ephSR & LAN91C96_EPHSR_TX_UNRN) { printf("LAN91C96_EPHSR_TX_UNRN\n") ; } if (ephSR & LAN91C96_EPHSR_LTX_MULT) { printf("LAN91C96_EPHSR_LTX_MULT\n"); } if (ephSR & LAN91C96_EPHSR_LTX_BRD) { printf("LAN91C96_EPHSR_LTX_BRD\n") ; } //restore the bank to htat whic was active when this function was entered WriteByte(bankActiveOnEntry, &ioRegsP[LAN91C96_BANK_SELECT]);}/********************************************************************************** FUNCTION:* ReadEEPROM** DESCRIPTION:* This routine reads a value from the LAN91C98 EEPROM
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -