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

📄 halether.c

📁 WINDOWS CE BSP用于SBC2440开发板
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
 *
 * System On Chip(SOC)
 *
 * Copyright (c) 2002 Software Center, Samsung Electronics, Inc.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of Samsung 
 * Electronics, Inc("Confidential Information"). You Shall not disclose such 
 * Confidential Information and shall use it only in accordance with the terms 
 * of the license agreement you entered into Samsung.
 *
 *-----------------------------------------------------------------------------
 *
 *	S3C2440 BSP
 *
 * halether.c :
 *
 *	Platform specific code for debug ethernet services (debug messages,          
 *	kernel debugger, text shell (CESH)).  These functions are all called         	
 *	from ethdbg.lib.  They are non-preemptible, and cannot make any system calls.
 *
 *
 * @author	zartoven@samsung.com (SOC, SWC, SAMSUNG Electronics)
 *
 * @date	2002/04/04
 * 
 * Log:
 *	2002/04/04  Start(From ODO's BSP)
 *      
 ******************************************************************************
 */


#include <windows.h>
#include <nkintr.h>
#include <ethdbg.h>
#include <halether.h>
#include <kitl.h>
#include "s2440.h"
#include "drv_glob.h"
#include "oalintr.h"

#define pDriverGlobals			((PDRIVER_GLOBALS) DRIVER_GLOBALS_PHYSICAL_MEMORY_START)

BOOL   CS8900DBG_Init(BYTE *iobase, DWORD membase, USHORT MacAddr[3]);
BOOL   CS8900DBG_IsReceivedPacket(void);
UINT16 CS8900DBG_GetFrame(BYTE *pbData, UINT16 *pwLength);
UINT16 CS8900DBG_SendFrame( BYTE *pbData, DWORD dwLength );
BOOL   CS8900DBG_ReInit(DWORD iobase, DWORD membase);
BOOL   CS8900DBG_MulticastList(PUCHAR pucMulticastAddresses, DWORD dwNumAddresses);
void   CS8900DBG_CurrentPacketFilter(DWORD dwFilter);
void   CS8900DBG_EnableInts(void);
void   CS8900DBG_DisableInts(void);
DWORD  CS8900DBG_GetPendingInts(void);

PVOID PCMCIA_Init(void);


//
// Function pointers to the support library functions of the currently installed debug ethernet controller.
//
PFN_EDBG_INIT             pfnEDbgInit;
PFN_EDBG_ENABLE_INTS      pfnEDbgEnableInts;
PFN_EDBG_DISABLE_INTS     pfnEDbgDisableInts;
PFN_EDBG_GET_PENDING_INTS pfnEDbgGetPendingInts;
PFN_EDBG_GET_FRAME        pfnEDbgGetFrame;
PFN_EDBG_SEND_FRAME       pfnEDbgSendFrame;
PFN_EDBG_READ_EEPROM      pfnEDbgReadEEPROM;
PFN_EDBG_WRITE_EEPROM     pfnEDbgWriteEEPROM;
PFN_EDBG_SET_OPTIONS      pfnEDbgSetOptions;

#ifdef IMGSHAREETH
PFN_EDBG_CURRENT_PACKET_FILTER  pfnCurrentPacketFilter;
PFN_EDBG_MULTICAST_LIST			pfnMulticastList;

BOOL OEMEthCurrentPacketFilter(PDWORD pdwRequestedFilter);

// Multicast list - Vmini assumes a maximum of 8 entries.
//
#define MAX_MULTICAST_LIST      8
BOOL	ucMultiAddr[MAX_MULTICAST_LIST][6];

BOOL	bNewFilter = FALSE;		//	User mode --> Kernel mode to set new filter.
DWORD	dwFilter;				//	The filter..
BOOL	bNewMulticast = FALSE;	//	User mode --> Kernel mode for new list
DWORD	dwNoOfEntry;

/* ProcessVMiniSend()
 *
 *		This routine drains the pending VMINI TX.
 * 
 */
void ProcessVMiniSend(void)
{
	PBYTE   pVMiniData;
    DWORD   dwVMiniDataLength;

	////////////////////////////////////////////////////////////////////////////
	//	Handle the filter if we need to..
	//
	if (bNewFilter && pfnCurrentPacketFilter)
	{
		bNewFilter = FALSE;		
		pfnCurrentPacketFilter(dwFilter);
	}		

	//
    //  Handle new multicast list..
    //
    if (bNewMulticast && pfnMulticastList)
    {
        bNewMulticast = FALSE;
        pfnMulticastList((PUCHAR)ucMultiAddr, dwNoOfEntry);
    }

    ////////////////////////////////////////////////////////////////////////////
    //  Consume all the client packets.
    //
    while (VBridgeKGetOneTxBuffer(&pVMiniData, &dwVMiniDataLength) == TRUE)
    {
        pfnEDbgSendFrame (pVMiniData, dwVMiniDataLength);
        VBridgeKGetOneTxBufferComplete(pVMiniData);
    } 

}	//	ProcessVMiniSend()

#endif //IMGSHAREETH



/* OEMEthInit
 *
 *  Initialization routine
 *
 *  Return Value:
 *    Return TRUE if init is successful, FALSE if error.
 */
BOOL
OEMEthInit(EDBG_ADAPTER *pAdapter) 
{
	PBYTE pBaseIOAddress;

	// Driver globals from the bootloader.
	//
	if (pDriverGlobals->eth.EbootMagicNum == EBOOT_MAGIC_NUM)
	{
		memcpy(pAdapter, &pDriverGlobals->eth.TargetAddr, sizeof(EDBG_ADAPTER));

		switch(pDriverGlobals->misc.EbootDevice)
		{
		case(DOWNLOAD_DEVICE_PCMCIA):	// NE2000 CF card.
			pBaseIOAddress  = (PBYTE)PCMCIA_Init();
			if (pBaseIOAddress)
			{
				// Initialize the built-in Ethenet controller.
				//
				if (!NE2000Init((PBYTE)pBaseIOAddress, 1, pAdapter->Addr.wMAC))
				{
					EdbgOutputDebugString("ERROR: OEMEthInit: Failed to initialize Ethernet controller.\r\n");
					return(FALSE);
				}
			}
			pfnEDbgInit           	= NE2000Init;
			pfnEDbgEnableInts     	= NE2000EnableInts;
			pfnEDbgDisableInts    	= NE2000DisableInts;
			pfnEDbgGetPendingInts 	= NE2000GetPendingInts;
			pfnEDbgGetFrame       	= NE2000GetFrame;
			pfnEDbgSendFrame      	= NE2000SendFrame;
			pfnEDbgReadEEPROM     	= NE2000ReadEEPROM;
			pfnEDbgWriteEEPROM    	= NE2000WriteEEPROM;
			pfnEDbgSetOptions     	= NE2000SetOptions;
		#ifdef IMGSHAREETH
			pfnCurrentPacketFilter	= Ne2000CurrentPacketFilter;
			pfnMulticastList		= NE2000MulticastList;
		#endif	// IMGSHAREETH.
			break;
		case(DOWNLOAD_DEVICE_CS8900):	// CS8900A.
			// Initialize the CS8900.
			//
			if (!CS8900DBG_Init((PBYTE)CS8900DBG_IOBASE, CS8900DBG_MEMBASE, pAdapter->Addr.wMAC))
			{
				EdbgOutputDebugString("ERROR: OEMEthInit: CS8900 initialization failed.\r\n");
				return(FALSE);
			}

			pfnEDbgInit				= CS8900DBG_Init;
			pfnEDbgEnableInts     	= CS8900DBG_EnableInts;
			pfnEDbgDisableInts    	= CS8900DBG_DisableInts;
			pfnEDbgGetFrame			= CS8900DBG_GetFrame;
			pfnEDbgSendFrame		= CS8900DBG_SendFrame;
			pfnEDbgGetPendingInts 	= CS8900DBG_GetPendingInts;
		#ifdef IMGSHAREETH
			pfnCurrentPacketFilter	= CS8900DBG_CurrentPacketFilter;
			pfnMulticastList		= CS8900DBG_MulticastList;
		#endif	// IMGSHAREETH.
			break;
		default:
			EdbgOutputDebugString("ERROR: OEMInit: Unknown download NIC (0x%x).\r\n", pDriverGlobals->misc.EbootDevice);
			return(FALSE);
		}
	}
	else
	{
		// TODO - retrieve CS8900 MAC address from flash...
		// TODO - intialize the CS8900 from scratch...
	}

	EdbgOutputDebugString("::: OEMEthInit() IP Address : %s\r\n", inet_ntoa(pAdapter->Addr.dwIP));
	EdbgOutputDebugString("::: OEMEthInit() Netmask    : %s\r\n", inet_ntoa(pDriverGlobals->eth.SubnetMask));

	// Setup SYSINTR used for KITL NIC.
	//
	if (pDriverGlobals->misc.EbootDevice == DOWNLOAD_DEVICE_PCMCIA)
		pAdapter->SysIntrVal    = SYSINTR_PCMCIA_LEVEL;
	else
		pAdapter->SysIntrVal    = SYSINTR_ETHER;

	pAdapter->DHCPLeaseTime = DEFAULT_DHCP_LEASE;
    pAdapter->EdbgFlags     = pDriverGlobals->eth.EdbgFlags;
		
#ifdef IMGSHAREETH
    VBridgeInit();
    VBridgeKSetLocalMacAddress((char *)pAdapter->Addr.wMAC);
#endif	// IMGSHAREETH.

	return(TRUE);
}


/* OEMEthEnableInts
 *
 *  Turn on HW interrupts.  
 */
void
OEMEthEnableInts()
{
	if (pfnEDbgEnableInts)
	{
		pfnEDbgEnableInts();
	}
}


/* OEMEthDisableInts
 *
 *  Disable HW interrupts.
 */
void
OEMEthDisableInts()
{
	if (pfnEDbgDisableInts)
	{
		pfnEDbgDisableInts();
	}
}

/* OEMEthISR
 *
 *    ISR routine, called by EDBG IST when Ethernet controller interrupts. Also
 *    called in polling mode, to check for received data.
 *
 * Return Value:
 *    Return bitmask indicating which interrupts are pending.  Currently, the ones
 *    that EDBG cares about are the following (others should be handled internally):
 *       INTR_TYPE_RX   -- Receive interrupt. IST will call into GetFrame to read data.
 */
DWORD
OEMEthISR()
{
#ifdef IMGSHAREETH
    ProcessVMiniSend();
#endif	// IMGSHAREETH.

    return (pfnEDbgGetPendingInts());
}

/* OEMEthGetFrame
 *
 *   Check to see if a frame has been received, and if so copy to buffer. An optimization
 *   which may be performed in the Ethernet driver is to filter out all received broadcast
 *   packets except for ARPs.  This is done in the SMC9000 driver.
 *
 * Return Value:
 *    Return TRUE if frame has been received, FALSE if not.
 */
BOOL
OEMEthGetFrame(
    BYTE *pData,       // OUT - Receives frame data
    UINT16 *pwLength)  // IN  - Length of Rx buffer
                       // OUT - Number of bytes received
{
#ifdef IMGSHAREETH
	BOOL	bStatus;
	BOOL	bTaken;		
	UINT16	wOriginalLength = *pwLength;
	
	ProcessVMiniSend();

	while (1)
	{		
		*pwLength = wOriginalLength;

		bStatus	 = pfnEDbgGetFrame(pData, pwLength);
			
		if (bStatus)
		{
			////////////////////////////////////////////////////////////////////
			VBridgeKIndicateOneRxBuffer(pData, *pwLength, FALSE, &bTaken);
			if (!bTaken)				
				return bStatus;
		}
		else
			break;
	}

⌨️ 快捷键说明

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