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

📄 card.c

📁 这是一个56K MODEM的驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************\
|* Copyright (c) 1994  Microsoft Corporation                               *|
|* Developed for Microsoft by TriplePoint, Inc. Beaverton, Oregon          *|
|*                                                                         *|
|* This file is part of the HT Communications DSU41 WAN Miniport Driver.   *|
\***************************************************************************/
#include "version.h"
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Module Name:

    card.c

Abstract:

    This module implements the low-level hardware control functions used by
    the NDIS Minport driver on the HT DSU41 controller.  You will need to 
    replace this module with the control functions required to support your 
    hardware.
        CardIdentify()
        CardDoCommand()
        CardInitialize()
        CardLineConfig()
        CardLineDisconnect()
        CardLineDisconnect()
        CardPrepareTransmit()
        CardGetReceiveInfo()
        CardDialNumber()

    This driver conforms to the NDIS 3.0 Miniport interface.

Author:

    Larry Hattery - TriplePoint, Inc. (larryh@tpi.com) Jun-94

Environment:

    Windows NT 3.5 kernel mode Miniport driver or equivalent.

Revision History:

---------------------------------------------------------------------------*/

#define  __FILEID__     2       // Unique file ID for error logging

#include "htdsu.h"


NDIS_STATUS
CardIdentify(
    IN PHTDSU_ADAPTER       Adapter
    )

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Functional Description:

    This routine will attempt to verify that the controller is located in
    memory where the driver has been configured to expect it.

Parameters:

    Adapter _ A pointer ot our adapter information structure.

Return Values:

    NDIS_STATUS_SUCCESS
    NDIS_STATUS_ADAPTER_NOT_FOUND

---------------------------------------------------------------------------*/

{
    DBG_FUNC("CardIdentify")

    NDIS_STATUS Status;

    /*
    // These values are read from the adapter to make sure this driver will
    // work with the firmware on the adapter.
    */
    USHORT CoProcessorId;
    USHORT CoProcessorVersion;
    USHORT DsuId;
    USHORT DsuVersion;

    DBG_ENTER(Adapter);

    /*
    // Read the configuration values from the card.
    */
    CoProcessorId      = READ_REGISTER_USHORT(&Adapter->AdapterRam->CoProcessorId);
    CoProcessorVersion = READ_REGISTER_USHORT(&Adapter->AdapterRam->CoProcessorVersion);
    DsuId              = READ_REGISTER_USHORT(&Adapter->AdapterRam->DsuId);
    DsuVersion         = READ_REGISTER_USHORT(&Adapter->AdapterRam->DsuVersion);

    /*
    // Make sure these values are what we expect.
    */
    if ((CoProcessorId      == HTDSU_COPROCESSOR_ID) &&
        (CoProcessorVersion >= HTDSU_COPROCESSOR_VERSION) &&
        ((DsuId & 0x00FF)   == HTDSU_DSU_ID) &&
        (DsuVersion         >= HTDSU_DSU_VERSION))
    {
        /*
        // Record the number of lines on this adapter.
        */
        Adapter->NumLineDevs = HTDSU_NUM_LINKS;
        if ((DsuId & 0xFF00) == 0)
        {
            --Adapter->NumLineDevs;
        }
        DBG_NOTICE(Adapter,("NumLineDevs=%d\n",Adapter->NumLineDevs));

        Status = NDIS_STATUS_SUCCESS;
    }
    else
    {
        DBG_ERROR(Adapter,("Adapter not found or invalid firmware:\n"
                  "CoProcessorId      = %Xh\n"
                  "CoProcessorVersion = %Xh\n"
                  "DsuId              = %Xh\n"
                  "DsuVersion         = %Xh\n",
                  CoProcessorId,
                  CoProcessorVersion,
                  DsuId,
                  DsuVersion
                  ));

        Status = NDIS_STATUS_ADAPTER_NOT_FOUND;
        /*
        // Log error message and return.
        */
        NdisWriteErrorLogEntry(
                Adapter->MiniportAdapterHandle,
                NDIS_ERROR_CODE_ADAPTER_NOT_FOUND,
                7,
                CoProcessorId,
                CoProcessorVersion,
                DsuId,
                DsuVersion,
                Status,
                __FILEID__,
                __LINE__
                );
    }

    DBG_LEAVE(Adapter);

    return (Status);
}


NDIS_STATUS
CardDoCommand(
    IN PHTDSU_ADAPTER       Adapter,
    IN USHORT               CardLine,   /* HTDSU_CMD_LINE1 or HTDSU_CMD_LINE2 */
    IN USHORT               CommandValue
    )

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Functional Description:

    This routine routine will execute a command on the card after making
    sure the previous command has completed properly.

Parameters:

    Adapter _ A pointer ot our adapter information structure.

    CardLine _ Specifies which line to use for the transmit (HTDSU_LINEx_ID).

    CommandValue _ HTDSU_CMD_??? command to be executed.

Return Values:

    NDIS_STATUS_SUCCESS
    NDIS_STATUS_HARD_ERRORS

---------------------------------------------------------------------------*/
{
    DBG_FUNC("CardDoCommand")

    ULONG       TimeOut = 0;

    DBG_ENTER(Adapter);
    DBG_FILTER(Adapter, DBG_PARAMS_ON,("Line=%d, Command=%04X, LineStatus=%Xh\n",
                CardLine, CommandValue,
                READ_REGISTER_USHORT(&Adapter->AdapterRam->StatusLine1)
                ));

    /*
    // Wait for command register to go idle - but don't wait too long.
    // If we timeout here, there's gotta be something wrong with the adapter.
    */
    while ((READ_REGISTER_USHORT(&Adapter->AdapterRam->Command) != 
                    HTDSU_CMD_NOP) ||
           (READ_REGISTER_USHORT(&Adapter->AdapterRam->CoProcessorId) != 
                    HTDSU_COPROCESSOR_ID))
    {
        if (TimeOut++ > HTDSU_SELFTEST_TIMEOUT)
        {
            DBG_ERROR(Adapter,("Timeout waiting for %04X command to clear\n",
                      READ_REGISTER_USHORT(&Adapter->AdapterRam->Command)));
            /*
            // Ask for reset, and disable interrupts until we get it.
            */
            Adapter->NeedReset = TRUE;
            Adapter->InterruptEnableFlag = HTDSU_INTR_DISABLE;
            CardDisableInterrupt(Adapter);
            
            return (NDIS_STATUS_HARD_ERRORS);
        }
        NdisStallExecution(_100_MICROSECONDS);
    }
    DBG_NOTICE(Adapter,("Timeout=%d waiting to submit %04X\n",
               TimeOut, CommandValue));

    /*
    // Before starting a reset command, we clear the the co-processor ID
    // which then gets set to the proper value when the reset is complete.
    */
    if (CommandValue == HTDSU_CMD_RESET)
    {
        WRITE_REGISTER_USHORT(&Adapter->AdapterRam->CoProcessorId, 0);
    }

    /*
    // Send the command to the adapter.
    */
    WRITE_REGISTER_USHORT(
            &Adapter->AdapterRam->Command,
            (USHORT) (CommandValue + CardLine)
            );

    DBG_LEAVE(Adapter);

    return (NDIS_STATUS_SUCCESS);
}


NDIS_STATUS
CardInitialize(
    IN PHTDSU_ADAPTER       Adapter,
    IN BOOLEAN              PerformSelfTest
    )

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Functional Description:

    This routine will attempt to initialize the controller, but will not
    enable transmits or receives.

Parameters:

    Adapter _ A pointer ot our adapter information structure.

    PerformSelfTest _ TRUE if caller wants to run selftest diagnostics.
                      This normally takes about 4 seconds to complete, so you
                      wouldn't want to do it every time you start up.

Return Values:

    NDIS_STATUS_HARD_ERRORS
    NDIS_STATUS_SUCCESS

---------------------------------------------------------------------------*/

{
    DBG_FUNC("CardInitialize")

    NDIS_STATUS Status;

    USHORT      SelfTestStatus;

    UINT        TimeOut;

    DBG_ENTER(Adapter);

    /*
    // First we make sure the adapter is where we think it is.
    */
    Status = CardIdentify(Adapter);
    if (Status != NDIS_STATUS_SUCCESS)
    {
        return (Status);
    }

    /*
    // Reset the hardware to make sure we're in a known state.
    */
    Status = CardDoCommand(Adapter, 0, HTDSU_CMD_RESET);
    
    if (PerformSelfTest)
    {
        /*
        // Wait for the reset to complete before starting the self-test.
        // Then issue the self-test command to see if the adapter firmware
        // is happy with the situation.
        */
        Status = CardDoCommand(Adapter, 0, HTDSU_CMD_SELFTEST);
        if (Status != NDIS_STATUS_SUCCESS)
        {
            DBG_ERROR(Adapter,("Failed HTDSU_CMD_RESET\n"));
            /*
            // Log error message and return.
            */
            NdisWriteErrorLogEntry(
                    Adapter->MiniportAdapterHandle,
                    NDIS_ERROR_CODE_HARDWARE_FAILURE,
                    3,
                    Status,
                    __FILEID__,
                    __LINE__
                    );
            return (Status);
        }
        
        /*
        // Wait for the self test to complete, but don't wait forever.
        */
        TimeOut = 0;
        while (Status == NDIS_STATUS_SUCCESS &&
               READ_REGISTER_USHORT(&Adapter->AdapterRam->Command) !=
                        HTDSU_CMD_NOP)
        {
            if (TimeOut++ > HTDSU_SELFTEST_TIMEOUT)
            {
                DBG_ERROR(Adapter,("Timeout waiting for SELFTEST to complete\n"));
                Status = NDIS_STATUS_HARD_ERRORS;
            }
            else
            {
                NdisStallExecution(_100_MICROSECONDS);
            }
        }
        if (Status != NDIS_STATUS_SUCCESS)
        {
            DBG_ERROR(Adapter,("Failed HTDSU_CMD_SELFTEST\n"));
            /*
            // Log error message and return.
            */
            NdisWriteErrorLogEntry(
                    Adapter->MiniportAdapterHandle,
                    NDIS_ERROR_CODE_HARDWARE_FAILURE,
                    3,
                    Status,
                    __FILEID__,
                    __LINE__
                    );
            return (Status);

⌨️ 快捷键说明

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