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

📄 interrupt.c

📁 IMX开发板
💻 C
📖 第 1 页 / 共 2 页
字号:
//-----------------------------------------------------------------------------
//
//  Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
//  Use of this source code is subject to the terms of the Microsoft end-user
//  license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
//  If you did not accept the terms of the EULA, you are not authorized to use
//  this source code. For a copy of the EULA, please see the LICENSE.RTF on
//  your install media.
//
//-----------------------------------------------------------------------------
//
//  Copyright (C) 2004, Motorola Inc. All Rights Reserved
//
//------------------------------------------------------------------------------
//
// Copyright (C) 2004, 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 CS8900 Driver
//
//  This file implements the interrupt handler functions for CS8900
//
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
#include "cs8900a.h"

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

//------------------------------------------------------------------------------
// External Variables
//------------------------------------------------------------------------------
extern PBSP_CS8900_REG g_pCS8900Reg;

extern CRITICAL_SECTION gCS8900RegCs;
extern CRITICAL_SECTION gCS8900BufCs;
//------------------------------------------------------------------------------
// Defines
//------------------------------------------------------------------------------

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

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

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

//------------------------------------------------------------------------------
// Local Functions
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
//
// Function: Cs8900aIsr
//
// This function is the ISR handle.
//
// Parameters:
//      InterruptRecognized
//          [out] Boolean value which returns TRUE if the ISR recognizes the interrupt as coming from this adapter.
//
//      QueueDpc
//          [out] TRUE if a DPC should be queued.
//
//      Context
//          [in] Pointer to adapter.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
VOID Cs8900aIsr(OUT PBOOLEAN InterruptRecognized, OUT PBOOLEAN QueueDpc,IN  PVOID Context)

{
    DEBUGMSG(ZONE_FUNCTION, (TEXT("CS8900A: +Cs8900aIsr\r\n")));
    *InterruptRecognized = TRUE;  // can set to TRUE as it is not shared. Only one chip
    *QueueDpc = TRUE;           // MiniportHandleInterrupt will be called to complete the operation
    DEBUGMSG(ZONE_FUNCTION, (TEXT("CS8900A: -Cs8900aIsr\r\n")));
    return;

}

//------------------------------------------------------------------------------
//
// Function: Cs8900aHandleInterrupt
//
// This function handles the interrupt events and calls the respective subroutines according to event.
//
// Parameters:
//      MiniportAdapterContext
//          [in] pointer to the adapter.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
VOID Cs8900aHandleInterrupt(IN NDIS_HANDLE MiniportAdapterContext)
{
    WORD InterruptEvent, Counter;
    WORD InterruptRegister, ReadyFlag;

    pCs8900_t pEthernet = ((pCs8900_t)(MiniportAdapterContext));

    DEBUGMSG(ZONE_FUNCTION, (TEXT("CS8900A: +Cs8900aHandleInterrupt\r\n")));

    // Check the hardware status of the CS8900A chip, if not ready, exit
    if(pEthernet->CurrentState!=NdisHardwareStatusReady)
    {
        return;
    }
    pEthernet->ReceiveCompleteNotifyFlag = FALSE;
    // Check which interrupt
    do{
        // Read Interrupt ISQ
        NdisRawReadPortUshort( (unsigned long)&(g_pCS8900Reg->CS8900_ISQ), &InterruptEvent );

        // Extract register information
        InterruptRegister = InterruptEvent & REG_NUM_MASK;

        if(InterruptEvent != 0)
        {
            switch(InterruptRegister)
            {
                case REG_NUM_RX_EVENT:
                            // do receive event
                            ProcessReceiveInterrupts( pEthernet, InterruptEvent );
                            break;
                case REG_NUM_TX_EVENT:
                            // do transmit event
                            ProcessTransmitInterrupts( pEthernet, InterruptEvent );
                            break;
                case REG_NUM_BUF_EVENT:
                            // do buffer event
                            ProcessBufferInterrupts( pEthernet, InterruptEvent );
                            break;

                case REG_NUM_RX_MISS:
                            // do receive miss;
                            // Get the Receive Miss Count
                            Counter = (InterruptEvent|(~REG_NUM_MASK))>>6;
                            pEthernet->RcvOverrun += Counter;
                            break;
                case REG_NUM_TX_COL:
                            // do transmit collisions
                            // Get the Transmit Collisions Count
                            Counter = (InterruptEvent|(~REG_NUM_MASK))>>6;
                            pEthernet->XmitMaxCollisions += Counter;
                            break;
                default:
                            //DEBUGMSG(ZONE_INTERRUPTS, (TEXT("CS8900A: Unhandler Interrupt. \r\n")));
                            break;

            }

        }

    }while(InterruptEvent != 0);

    // check for ReceiveCompleteNotifyFlag
    if (pEthernet->ReceiveCompleteNotifyFlag== TRUE)
    {
        NdisMEthIndicateReceiveComplete( pEthernet->ndisAdapterHandle );
    }

    // Handle packets that have not been transmit yet
    if ((pEthernet->StartTX) && (pEthernet->HeadPacket != NULL))
    {
        pEthernet->StartTX = FALSE;
        if (!(pEthernet->TransmitBidPending))
        {
            ReadyFlag = CheckReadyForTransmit(pEthernet);
        }
        if ((pEthernet->TransmitBidPending) || (ReadyFlag == TRUE)) // txm with no regards
        {
            pEthernet->TransmitBidPending = FALSE;
            TransferPacketToChip(pEthernet);
        }
    }
    else
    {
        pEthernet->StartTX = FALSE;
    }

    DEBUGMSG(ZONE_FUNCTION, (TEXT("CS8900A: -Cs8900aHandleInterrupt\r\n")));
    return;

}

//------------------------------------------------------------------------------
//
// Function: Cs8900aDisableInterrupt
//
// This function disables interrupt on CS8900 chip.
//
// Parameters:
//      MiniportAdapterContext
//          [in] pointer to adapter.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
void Cs8900aDisableInterrupt(IN  NDIS_HANDLE MiniportAdapterContext )
{

    pCs8900_t pEthernet = ((pCs8900_t)(MiniportAdapterContext));
    DEBUGMSG(ZONE_FUNCTION, (TEXT("CS8900A: +Cs8900aDisableInterrupt\r\n")));
    if(pEthernet->CurrentState != NdisHardwareStatusReady)
    {
        return;
    }

    InterruptChip(pEthernet, FALSE);
    DEBUGMSG(ZONE_FUNCTION, (TEXT("CS8900A: -Cs8900aDisableInterrupt\r\n")));
    return;
}

//------------------------------------------------------------------------------
//
// Function: Cs8900aEnableInterrupt
//
// This function enables interrupt on CS8900 chip.
//
// Parameters:
//      MiniportAdapterContext
//          [in] pointer to adapter.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
void Cs8900aEnableInterrupt(IN  NDIS_HANDLE MiniportAdapterContext )
{

⌨️ 快捷键说明

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