firda.h

来自「S3C24A0的完整BSP包,对开发此芯片的开发者很有用.」· C头文件 代码 · 共 419 行

H
419
字号
//
// 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.
//
/*
 ************************************************************************
 *
 *  firda.h
 *
 *
 *      (C) Copyright Samsung Electronics
 *
 *
 *      (ep)
 *
 *************************************************************************
 */



#ifndef FIRDA_H_	
#define FIRDA_H_

    #include <ndis.h>
    #include <ntddndis.h>  // defines OID's

	
    #include "settings.h"
    #include "comm.h"
    #include "sync.h"

    #define pnpid_str "*pnp0511,*pnp0510,*pnp0501,*pnp0500"

    #define NDIS_MAJOR_VERSION 5
    #define NDIS_MINOR_VERSION 0



    #define DBGIRDA 0
//
// Registry Keywords.
//
#ifdef UNDER_CE
    // WinCE has specific regsitry value names. Only support one dongle type.
    #define CARDTYPE            NDIS_STRING_CONST("BoardType")
    #define CONFIGIOADDRESS     NDIS_STRING_CONST("ConfigBase")
    #define UARTIOADDRESS       NDIS_STRING_CONST("IoBase")
    #define INTERRUPT           NDIS_STRING_CONST("Irq")
    #define DMACHANNEL          NDIS_STRING_CONST("Dma")
    #define DONGLETYPE          NDIS_STRING_CONST("DongleType")
#else // UNDER_CE
    #define CARDTYPE            NDIS_STRING_CONST("BoardType")
    #define CONFIGIOADDRESS     NDIS_STRING_CONST("ConfigIoBaseAddress")
    #define UARTIOADDRESS       NDIS_STRING_CONST("IoBaseAddress")
    #define INTERRUPT           NDIS_STRING_CONST("InterruptNumber")
    #define DMACHANNEL          NDIS_STRING_CONST("DmaChannel")
    #define DONGLE_A_TYPE       NDIS_STRING_CONST("Dongle_A_Type")
    #define DONGLE_B_TYPE       NDIS_STRING_CONST("Dongle_B_Type")
#endif // !UNDER_CE

//
// Valid value ranges for the DMA Channels.
//
    #define VALID_DMACHANNELS {0xFF,0x0,0x1,0x3}

    #define FIR_INT_MASK 0x14




typedef struct DebugCounters {
    ULONG TxPacketsStarted;
    ULONG TxPacketsCompleted;
    ULONG ReceivedPackets;
    ULONG WindowSize;
    ULONG StatusFIFOOverflows;
    ULONG TxUnderruns;
    ULONG ReceiveFIFOOverflows;
    ULONG MissedPackets;
    ULONG ReceiveCRCErrors;
    ULONG ReturnPacketHandlerCalled;
    ULONG RxWindow;
    ULONG RxWindowMax;
    ULONG RxDPC_Window;
    ULONG RxDPC_WindowMax;
    ULONG RxDPC_G1_Count;
} DebugCounters;

/*
 *  A receive buffer is either FREE (not holding anything) FULL
 * (holding undelivered data) or PENDING (holding data delivered
 * asynchronously)
 */
typedef enum rcvbufferStates { 
    STATE_FREE, 
    STATE_FULL,
    STATE_PENDING
} rcvBufferState;

typedef enum {
    ADAPTER_NONE=0,
    ADAPTER_TX,
    ADAPTER_RX
} adapterState;


typedef struct {
    LIST_ENTRY listEntry;
    rcvBufferState state;
    PNDIS_PACKET packet;
    UINT dataLen;
    PUCHAR dataBuf;
    BOOLEAN isDmaBuf;
} rcvBuffer;

typedef struct {
    UINT Length;            // Length of buffer.
    UCHAR NotUsed;          // Spare byte, not filled in.
    UCHAR StsCmd;           // For the sts cmd info.
    ULONG physAddress;      // Physical address of buffer
} DescTableEntry;



#define S24A0_IRDA_MODEFIR 			0x4
#define S24A0_IRDA_MODEMIR 			0x2

#define S24A0_IRDA_MIRFULLSPEED 	0x0
#define S24A0_IRDA_MIRHALFSPEED 	(0x1 << 4)
 
#define S24A0_IRDA_TEMICAUTO	 	0x0
#define S24A0_IRDA_TEMICHP	 		0x1
#define S24A0_IRDA_TEMICIBM	 		0x2

#define S24A0_IRDA_TXMODEINT 		0x1
#define S24A0_IRDA_TXMODEDMA 		0x2

#define S24A0_IRDA_RXMODEINT 		0x1
#define S24A0_IRDA_RXMODEDMA 		0x2

#define S24A0_IRDA_FIRPREAMLEN16	0x00
#define S24A0_IRDA_FIRPREAMLEN4		0x01
#define S24A0_IRDA_FIRPREAMLEN8		0x02
#define S24A0_IRDA_FIRPREAMLEN32	0x03

#define S24A0_IRDA_FIFOSIZE16		0x00
#define S24A0_IRDA_FIFOSIZE64		0x01

#define S24A0_IRDA_TXFIFO64_TRIG48		0x01
#define S24A0_IRDA_TXFIFO64_TRIG32		0x02
#define S24A0_IRDA_TXFIFO64_TRIG08		0x03

#define S24A0_IRDA_TXFIFO16_TRIG12		0x01
#define S24A0_IRDA_TXFIFO16_TRIG08		0x02
#define S24A0_IRDA_TXFIFO16_TRIG02		0x03

#define S24A0_IRDA_RXFIFO64_TRIG01		0x00
#define S24A0_IRDA_RXFIFO64_TRIG16		0x01
#define S24A0_IRDA_RXFIFO64_TRIG32		0x02
#define S24A0_IRDA_RXFIFO64_TRIG56		0x03

#define S24A0_IRDA_RXFIFO16_TRIG4		0x01
#define S24A0_IRDA_RXFIFO16_TRIG8		0x02
#define S24A0_IRDA_RXFIFO16_TRIG14		0x03

typedef struct FirConf_s{
	UINT		IrMode;
	UINT		MirMode;
	BOOLEAN		bSendIRPulse;
	UINT		Temic;
	UINT		PreampleLen;
	UINT		StartFlagCnt;
	UINT		TxMode;
	UINT		RxMode;
	UINT		FifoSize;
	UINT		TxFifoTrigger;
	UINT		RxFifoTrigger;
}FirConf;


typedef struct IrDevice {
    /*
     * This is the handle that the NDIS wrapper associates with a
     * connection.  The handle that the miniport driver associates with
     * the connection is just an index into the devStates array).
     */
    NDIS_HANDLE ndisAdapterHandle;

        // The supportedspeed mask... At the moment we r only conc on Irda.
    UINT supportedSpeedsMask;
    
	// The turn around time needed TATs 
    UINT turnAroundTime_usec;


//    int CardType;


    /*
     *  Current speed setting, in bits/sec.
     *  (Note: this is updated when we ACTUALLY change the speed,
     *         not when we get the request to change speed via
     *         MiniportSetInformation).
     */
    UINT currentSpeed;

    
    NDIS_SPIN_LOCK Lock;

    /*
     *  This structure holds information about our ISR.
     *  It is used to synchronize with the ISR.
     */
    NDIS_MINIPORT_INTERRUPT interruptObj;

    //
    // Interrupt Mask.
    //
    UCHAR IntMask;


	// This variable has been introduced  so that we r able to find that the DMA 
	// is being used or the interrupts are being used for transmission.
	//
	UCHAR DmaInUse;		// Tx=1, Rx=2, NotInUse=0x0
	UCHAR IntInUse;		// Tx=1, Rx=2, NotInuse=0x0

	UINT32 DMAChannel;

    /*   
     *  Memory-mapped port range
     */
    UCHAR mappedPortRange[8];

    /*
     *  Circular queue of pending receive buffers
     */
#define NUM_RCV_BUFS 16
    #define NEXT_RCV_BUF_INDEX(i) (((i)==NO_BUF_INDEX) ? 0 : (((i)+1)%NUM_RCV_BUFS))
    LIST_ENTRY rcvBufBuf;       // Protected by SyncWithInterrupt
    LIST_ENTRY rcvBufFree;      // Protected by SyncWithInterrupt
    LIST_ENTRY rcvBufFull;      // Protected by SyncWithInterrupt
    LIST_ENTRY rcvBufPend;      // Protected by QueueLock
#if 0
    rcvBuffer rcvBufs[NUM_RCV_BUFS];    
#endif
    ULONG LastReadDMACount;
#if 0
    /*
     *  These indices into rcvBufs[] indicate the first and last
     *  non-FREE (FULL or PENDING) buffers in the circular list.
     */
    #define NO_BUF_INDEX -1
    int firstRcvBufIndex, lastRcvBufIndex;
#endif

    #if 0
    /*
     *  Send packet queue pointers.
     */
    PNDIS_PACKET firstSendPacket, lastSendPacket;


    PPNDIS_PACKET TxPacketArray;
    UINT TxPacketCount;
    UINT TxPacketIndex;
    #endif

    LIST_ENTRY SendQueue;

    /* Define a buffer of packet lengths that are Tx'ed. Assuming max of 8 */

    DescTableEntry *DescTableArray;
    PNDIS_PHYSICAL_ADDRESS DescTablePhyAddr;

    //
    // Physical Address used by SG_DMA for start of contiguous buffer
    // for Tx and Rx
    //
    PUCHAR SGDMA_Buff;
    PNDIS_PHYSICAL_ADDRESS SGDMA_BuffPhyAddr;

    /*
     *  Handle to NDIS packet pool, from which packets are
     *  allocated.
     */
    NDIS_HANDLE packetPoolHandle;
    NDIS_HANDLE bufferPoolHandle;


    /*
     * mediaBusy is set TRUE any time that this miniport driver moves a
     * data frame.  It can be reset by the protocol via
     * MiniportSetInformation and later checked via
     * MiniportQueryInformation to detect interleaving activity.
     */
    BOOLEAN mediaBusy;
    BOOLEAN haveIndicatedMediaBusy;

    /*
     * nowReceiving is set while we are receiving a frame.
     * It (not mediaBusy) is returned to the protocol when the protocol
     * queries OID_MEDIA_BUSY
     */
    BOOLEAN nowReceiving;
    adapterState AdapterState;

    volatile UCHAR FrameStatus;
    UCHAR InterruptMask;
    UCHAR InterruptStatus;
    UCHAR AuxStatus;

    /*
     *  Current link speed information.  
     */
    baudRateInfo *linkSpeedInfo;

    /*
     *  When speed is changed, we have to clear the send queue before
     *  setting the new speed on the hardware.  
     *  These vars let us remember to do it.
     */
    PNDIS_PACKET lastPacketAtOldSpeed;      
    BOOLEAN setSpeedAfterCurrentSendPacket;
    BOOLEAN setSpeedNow;

    /*
     *  Information on the COM port and send/receive FSM's.
     */
    comPortInfo portInfo;

    FirConf     firConf;

    UINT sgIO_Base;

    /*
     *  HW resources may be temporarily released via an OID from
     *  the protocol.
     */
    BOOLEAN resourcesReleased;

    /*
     *  UIR Module ID.
     */
    int UIR_Mid;

    BOOLEAN intEnabled;
    UCHAR intMask;

    /*
     *  Maintain statistical debug info.
     */
    UINT packetsRcvd;
    UINT packetsDropped;
    UINT packetsSent;
    UINT interruptCount;


    /* 
     *  DMA handles
     */
    NDIS_HANDLE DmaHandle;
    NDIS_HANDLE dmaBufferPoolHandle;
    PNDIS_BUFFER xmitDmaBuffer, rcvDmaBuffer;

    UINT rcvDmaOffset;
    UINT rcvDmaSize;
    UINT rcvPktOffset;
    UINT rcvdFrameStart;
    UINT rcvdFrameLen;
	BOOLEAN bRcvdFullFrame;

    UINT nextFrameStat;
    UINT nextFrameSize;

#ifdef UNDER_CE
    NDIS_MINIPORT_TIMER TurnaroundTimer;
#else
    NDIS_TIMER TurnaroundTimer;
#endif 

    ULONG HangChk;
    BOOLEAN DiscardNextPacketSet;
    /*
     *  Pointer to next device in global list.
     */
    struct IrDevice *next;

} IrDevice;

#define HEAD_SEND_PACKET(dev)                                   \
    (PNDIS_PACKET) (IsListEmpty(&(dev)->SendQueue) ? NULL :     \
        CONTAINING_RECORD((dev)->SendQueue.Flink,               \
                          NDIS_PACKET,                          \
                          MiniportReserved))                    

/*
 *  We use a pointer to the IrDevice structure as the miniport's device context.
 */
    #define CONTEXT_TO_DEV(__deviceContext) ((IrDevice *)(__deviceContext))
    #define DEV_TO_CONTEXT(__irdev) ((NDIS_HANDLE)(__irdev))

    #define ON  TRUE
    #define OFF FALSE

    #include "externs.h"





#endif FIRDA_H_

⌨️ 快捷键说明

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