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

📄 card.c

📁 这是一个56K MODEM的驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
        }

        /*
        // Verify that self test was successful.
        */
        SelfTestStatus = READ_REGISTER_USHORT(&Adapter->AdapterRam->SelfTestStatus);
        if (SelfTestStatus != 0 && SelfTestStatus != HTDSU_SELFTEST_OK)
        {
            DBG_ERROR(Adapter,("Failed HTDSU_CMD_SELFTEST (Status=%X)\n",
                      SelfTestStatus));
            /*
            // Log error message and return.
            */
            NdisWriteErrorLogEntry(
                    Adapter->MiniportAdapterHandle,
                    NDIS_ERROR_CODE_HARDWARE_FAILURE,
                    3,
                    SelfTestStatus,
                    __FILEID__,
                    __LINE__
                    );
            return (NDIS_STATUS_HARD_ERRORS);
        }
    }

    DBG_LEAVE(Adapter);

    return (NDIS_STATUS_SUCCESS);
}


VOID
CardLineConfig(
    IN PHTDSU_ADAPTER       Adapter,
    IN USHORT               CardLine    /* HTDSU_CMD_LINE1 or HTDSU_CMD_LINE2 */
    )

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

Functional Description:

    This routine will ready the controller to send and receive packets.

Parameters:

    Adapter _ A pointer ot our adapter information structure.

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

Return Values:

    None

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

{
    DBG_FUNC("CardLineConfig")

    DBG_ENTER(Adapter);

    ASSERT((CardLine==HTDSU_CMD_LINE1) || (CardLine==HTDSU_CMD_LINE2));

    /*
    // Configure the line for HDLC framing and for leased or dialup mode.
    */
    CardDoCommand(Adapter, CardLine, HTDSU_CMD_HDLC_PROTOCOL);
    if (Adapter->LineType == HTDSU_LINEMODE_LEASED)
    {
        CardDoCommand(Adapter, CardLine, HTDSU_CMD_DDS_TX_CLOCK);
        CardDoCommand(Adapter, CardLine, HTDSU_CMD_LEASED_LINE);
    }
    else
    {
        CardDoCommand(Adapter, CardLine, HTDSU_CMD_DIALUP_LINE);
    }

    /*
    // Clear any pending interrupts.
    */
    CardDoCommand(Adapter, 0, HTDSU_CMD_CLEAR_INTERRUPT);
    CardClearInterrupt(Adapter);

    DBG_LEAVE(Adapter);
}


VOID
CardLineDisconnect(
    IN PHTDSU_ADAPTER       Adapter,
    IN USHORT               CardLine     /* HTDSU_CMD_LINE1 or HTDSU_CMD_LINE2 */
    )

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

Functional Description:

    This routine will disconnect any call currently on the line.

Parameters:

    Adapter _ A pointer ot our adapter information structure.

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

Return Values:

    None

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

{
    DBG_FUNC("CardLineDisconnect")

    DBG_ENTER(Adapter);

    ASSERT((CardLine==HTDSU_CMD_LINE1) || (CardLine==HTDSU_CMD_LINE2));

    /*
    // Disconnect the line and reconfigure the line for next time.
    */
    CardDoCommand(Adapter, CardLine, HTDSU_CMD_DISCONNECT);
    CardLineConfig(Adapter, CardLine);

    DBG_LEAVE(Adapter);
}


VOID
CardPrepareTransmit(
    IN PHTDSU_ADAPTER       Adapter,
    IN USHORT               CardLine,    /* HTDSU_CMD_LINE1 or HTDSU_CMD_LINE2 */
    IN USHORT               BytesToSend
    )

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

Functional Description:

    This routine will write the packet header information into the
    transmit buffer.  This assumes that the controller has notified the
    driver that the transmit buffer is empty.

Parameters:

    Adapter _ A pointer ot our adapter information structure.

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

    BytesToSend _ Number of bytes to transmit.

Return Values:

    None

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

{
    DBG_FUNC("CardPrepareTransmit")

    DBG_ENTER(Adapter);

    ASSERT((CardLine==HTDSU_CMD_LINE1) || (CardLine==HTDSU_CMD_LINE2));
    ASSERT(READ_REGISTER_USHORT(&Adapter->AdapterRam->TxDataEmpty));
    ASSERT(BytesToSend > 0);

    /*
    // Tell the adapter how many bytes are to be sent, and which line to use.
    */
    WRITE_REGISTER_USHORT(
            &Adapter->AdapterRam->TxBuffer.Address,
            (USHORT) (CardLine - HTDSU_CMD_LINE1)
            );
    WRITE_REGISTER_USHORT(
            &Adapter->AdapterRam->TxBuffer.Length,
            BytesToSend
            );

    /*
    // Mark the end of packet and end of packet list.
    */
    WRITE_REGISTER_USHORT(
            &Adapter->AdapterRam->TxBuffer.Data[(BytesToSend+1)/sizeof(USHORT)],
            HTDSU_DATA_TERMINATOR
            );
    WRITE_REGISTER_USHORT(
            &Adapter->AdapterRam->TxBuffer.Data[(BytesToSend+3)/sizeof(USHORT)],
            HTDSU_DATA_TERMINATOR
            );

    DBG_LEAVE(Adapter);
}


VOID
CardGetReceiveInfo(
    IN PHTDSU_ADAPTER       Adapter,
    OUT PUSHORT             CardLine,    /* HTDSU_CMD_LINE1 or HTDSU_CMD_LINE2 */
    OUT PUSHORT             BytesReceived,
    OUT PUSHORT             RxErrors
    )

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

Functional Description:

    This routine will retrieve the packet header information from the
    receive buffer.  This assumes that the controller has notified the
    driver that a packet has been received.

Parameters:

    Adapter _ A pointer ot our adapter information structure.

    CardLine _ Specifies which line the packet was received on (HTDSU_LINEx_ID).

    BytesReceived _ Number of bytes received.

    RxErrors _ Receive error flags non-zero if packet has errors.

Return Values:

    None

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

    USHORT Length;

    DBG_ENTER(Adapter);

    ASSERT(READ_REGISTER_USHORT(&Adapter->AdapterRam->RxDataAvailable));

    /*
    // The length field tells us how many bytes are in the packet, and
    // the most significant bit tells us whether the packet has a CRC error.
    */
    Length = READ_REGISTER_USHORT(&Adapter->AdapterRam->RxBuffer.Length);
    *BytesReceived = Length & ~HTDSU_CRC_ERROR;
    *RxErrors = Length & HTDSU_CRC_ERROR;
    
    /*
    // The least significant nibble of the address tells us what line the
    // packet was received on -- at least it better...
    */
    *CardLine = (READ_REGISTER_USHORT(&Adapter->AdapterRam->RxBuffer.Address) &
                        0x000F) + HTDSU_CMD_LINE1;

    if ((*CardLine != HTDSU_CMD_LINE1) && (*CardLine != HTDSU_CMD_LINE2))
    {
        *RxErrors |= HTDSU_RX_ERROR;
        *CardLine = HTDSU_CMD_LINE1;    // Don't return a bad line #
    }
    else if (*BytesReceived > HTDSU_MAX_PACKET_SIZE)
    {
        *RxErrors |= HTDSU_RX_ERROR;
    }

    DBG_LEAVE(Adapter);
}


VOID
CardDialNumber(
    IN PHTDSU_ADAPTER       Adapter,
    IN USHORT               CardLine,    /* HTDSU_CMD_LINE1 or HTDSU_CMD_LINE2 */
    IN PUCHAR               DialString,
    IN ULONG                DialStringLength
    )

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

Functional Description:

    Place a dial string on the adapter and start the dialing sequence.

Parameters:

    Adapter _ A pointer ot our adapter information structure.

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

    DialString _ A pointer to an ASCII null-terminated string of digits.

    DialStringLength _ Number of bytes in dial string.

Return Values:

    None

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

{
    DBG_FUNC("CardDialNumber")

    UINT    Index;

    PUSHORT DialRam;

    DBG_ENTER(Adapter);

    ASSERT(READ_REGISTER_USHORT(&Adapter->AdapterRam->TxDataEmpty));
    ASSERT(READ_REGISTER_USHORT(&Adapter->AdapterRam->Command) == HTDSU_CMD_NOP);

    /*
    // Make sure dial string is within the limit of the adapter.
    */
    if (DialStringLength > HTDSU_MAX_DIALING_DIGITS)
    {
        ASSERT(DialStringLength <= HTDSU_MAX_DIALING_DIGITS);
        DialStringLength = HTDSU_MAX_DIALING_DIGITS;
    }

    /*
    // Copy the digits to be dialed onto the adapter.
    // The adapter interprets phone numbers as high byte is valid digit,
    // low byte is ignored, the last digit gets bit 15 set.
    */
    DialRam = (PUSHORT) &Adapter->AdapterRam->TxBuffer;

    for (Index = 0; Index < DialStringLength && *DialString; Index++)
    {
        if ((*DialString >= '0') && (*DialString <= '9'))
        {
            WRITE_REGISTER_USHORT(
                    DialRam,
                    (USHORT) ((*DialString - '0') << 8)
                    );
        }
        DialRam++;
        DialString++;
    }

    /*
    // Set the MSB in the last digit.
    */
    DialRam--;
    WRITE_REGISTER_USHORT(
            DialRam,
            (USHORT) (READ_REGISTER_USHORT(DialRam) | 0x8000)
            );

    /*
    // Initiate the dial sequence.
    */
    CardDoCommand(Adapter, CardLine, HTDSU_CMD_DIAL);

    DBG_LEAVE(Adapter);
}

⌨️ 快捷键说明

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