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

📄 interrupt.c

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 C
📖 第 1 页 / 共 2 页
字号:
//------------------------------------------------------------------------------
//
//  Copyright (C) 2006, Freescale Semiconductor, Inc. All Rights Reserved.
//  THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
//  AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT 
//
//------------------------------------------------------------------------------
//
//  File:  interrupt.c
//
//  Implementation of FEC Driver
//
//  This file implements the interrupt handler functions  for FEC.
//
//-----------------------------------------------------------------------------

#include "fec.h"

//------------------------------------------------------------------------------
// External Functions
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Defines
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Global Variables
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Local Variables
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// External Variables
//------------------------------------------------------------------------------
extern PCSP_FEC_REGS    gpFECReg;

extern PFEC_MII_LIST    gMIIFree;
extern PFEC_MII_LIST    gMIIHead;

extern CRITICAL_SECTION gFECRegCs;
extern CRITICAL_SECTION gFECBufCs;

//------------------------------------------------------------------------------
// Functions
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//
// Function: FECIsr
//
// The FEC adapter driver should do as little work as possible in the FECIsr,
// deferring I/O operations for each interrupt the FEC adapter generates to 
// the FECHandleInterrupt function.
//
// Parameters:
//		InterruptRecognized
//			[out] Points to a variable in which FECISR returns whether
//				  the FEC adapter actually generated the interrupt.
//
//		QueueMiniportHandleInterrupt
//			[out] Points to a variable that FECISR sets to TRUE if the 
//				  FECHandleInterrupt function should be called to complete
//				  the interrupt-driven I/O operation.
//
//		MiniportAdapterContext
//			[in]  Specifies the handle to the driver allocated context area in
//				  which the driver maintains FEC adapter state, set up by
//				  FECInitialize.
//
// Return Value:
//		None.
//
//------------------------------------------------------------------------------
void FECIsr(
	OUT PBOOLEAN InterruptRecognized,
	OUT PBOOLEAN QueueMiniportHandleInterrupt,
	IN  NDIS_HANDLE MiniportAdapterContext
	)
{
	DEBUGMSG(ZONE_FUNCTION, (TEXT("+FEC: FECIsr\r\n")));
	
	// Set to TRUE, FEC IRQ is not shared with other network
	// adapter
	*InterruptRecognized = TRUE;
	
	// FECHandleInterrupt will be called to complete the
	// operation
	*QueueMiniportHandleInterrupt = TRUE;
	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("-FEC: FECIsr\r\n")));
	
	return;
}

//------------------------------------------------------------------------------
//
// Function: FECHandleInterrupt
//
// This function handles the interrupt events and calls the respective subroutines
// according to event.
//
// Parameters:
//		MiniportAdapterContext
//			[in]  Specifies the handle to the driver allocated context area in
//				  which the driver maintains FEC adapter state, set up by
//				  FECInitialize.
//
// Return Value:
//		None
//
//------------------------------------------------------------------------------
void FECHandleInterrupt(IN NDIS_HANDLE MiniportAdapterContext)
{
	UINT InterruptEvent;
	pFEC_t pEthernet = ((pFEC_t)(MiniportAdapterContext));
	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: +FECHandleInterrupt\r\n")));
	
	// Check the hardware status of the FEC adapter, 
	// if not ready, return
	if( pEthernet->CurrentState != NdisHardwareStatusReady )
	{
		return;
	}
	
	pEthernet->ReceiveCompleteNotifyFlag = FALSE;
	
	// Check which interrupt
	while( (InterruptEvent = INREG32(&gpFECReg->EIR)) != 0 )
	{
		// Clear the EIR
		OUTREG32(&gpFECReg->EIR, InterruptEvent);
		
		// Handle receive packet event
		if(InterruptEvent & CSP_BITFVAL(FEC_EIR_RXF, 1))
			ProcessReceiveInterrupts(pEthernet);
			
		// Handle transmit packet interrupt
		if(InterruptEvent & CSP_BITFVAL(FEC_EIR_TXF, 1))
			ProcessTransmitInterrupts(pEthernet);
			
		// Handle MII interrupt
		if(InterruptEvent & CSP_BITFVAL(FEC_EIR_MII, 1))
			ProcessMIIInterrupts(pEthernet);
	}
	
	 // check for ReceiveCompleteNotifyFlag
    if (pEthernet->ReceiveCompleteNotifyFlag == TRUE)
    {
        NdisMEthIndicateReceiveComplete( pEthernet->ndisAdapterHandle );
    }

    // Handle packets that have not been transmit yet
    if ((pEthernet->StartTx == TRUE) && (pEthernet->HeadPacket != NULL))
    {
        pEthernet->StartTx = FALSE;
        FECStartXmit(pEthernet);
    }
    else
    {
        pEthernet->StartTx = FALSE;
    }

	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: -FECHandleInterrupt\r\n")));
}

//------------------------------------------------------------------------------
//
// Function: FECDisableInterrupt
//
// This function accesses the interrupt mask register to disable the RxF, TxF
// and MII interrupts.
//
// Parameters:
//		MiniportAdapterContext
//			[in] Specifies the handle to the driver allocated context area in
//				 which the driver maintains FEC adapter state, set up by
//				 FECInitialize.
//
// Return Value:
//		None.
//
//------------------------------------------------------------------------------
void FECDisableInterrupt(IN NDIS_HANDLE MiniportAdapterContext)
{
	pFEC_t pEthernet = ((pFEC_t)(MiniportAdapterContext));
	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: +FECDisableInterrupt\r\n")));
	
	// Check current hardware status
	if(pEthernet->CurrentState != NdisHardwareStatusReady)
	{
		return;
	}
	
	// Disable TxF, RxF and MII interrupts
	OUTREG32(&gpFECReg->EIMR,
					CSP_BITFVAL(FEC_EIMR_TXF, FEC_EIMR_TXF_MASK) |
					CSP_BITFVAL(FEC_EIMR_RXF, FEC_EIMR_RXF_MASK) |
					CSP_BITFVAL(FEC_EIMR_MII, FEC_EIMR_MII_MASK));
					
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: -FECDisableInterrupt\r\n")));
	
	return;
}

//------------------------------------------------------------------------------
//
// Function: FECEnableInterrupt
//
// This function accesses the interrupt mask register to enable the RxF, TxF
// and MII interrupts.
//
// Parameters:
//		MiniportAdapterContext
//			[in] Specifies the handle to the driver allocated context area in
//				 which the driver maintains FEC adapter state, set up by
//				 FECInitialize.
//
// Return Value:
//		None.
//
//------------------------------------------------------------------------------
void FECEnableInterrupt(IN NDIS_HANDLE MiniportAdapterContext)
{
	pFEC_t pEthernet = ((pFEC_t)(MiniportAdapterContext));
	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: +FECEnableInterrupt\r\n")));
	
	// Check current hardware status
	if(pEthernet->CurrentState != NdisHardwareStatusReady)
	{
		return;
	}
	
	// Enable TxF, RxF and MII interrupts
	OUTREG32(&gpFECReg->EIMR,
					CSP_BITFVAL(FEC_EIMR_TXF, FEC_EIMR_TXF_UNMASK) |
					CSP_BITFVAL(FEC_EIMR_RXF, FEC_EIMR_RXF_UNMASK) |
					CSP_BITFVAL(FEC_EIMR_MII, FEC_EIMR_MII_UNMASK));
					
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: -FECEnableInterrupt\r\n")));
	
	return;
}


//------------------------------------------------------------------------------
//
// Function: ProcessReceiveInterrupts
//
// This function is the interrupt handler when a ethernet packet is received by
// the FEC hardware.
//
// Parameters:
//		pEthernet
//			[in]  Specifies the pointer to the driver allocated context area in

⌨️ 快捷键说明

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