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

📄 smsc911x_platform.c

📁 由smsc公司改进的lwip2.1.1基于嵌入式系统的TCP/ip协议栈
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************
 *
 * Copyright (C) 2008  SMSC
 *
 * All rights reserved.
 *
 ***************************************************************************
 * File: new_smsc911x_platform.c
 */

#include "smsc_environment.h"
#include "smsc911x_platform.h"

#if !SMSC911X_ENABLED
#error Platform functions not implemented
#endif


/* Debug bits */
#define DEBUG_TRACE_BIT		(0x10)
#define DEBUG_NOTICE_BIT	(0x20)
#define DEBUG_WARNING_BIT	(0x40)

#ifndef SMSC_TRACE_ENABLED
#define SMSC_TRACE_ENABLED	(1)
#endif
#ifndef SMSC_NOTICE_ENABLED
#define SMSC_NOTICE_ENABLED	(1)
#endif
#ifndef SMSC_WARNING_ENABLED
#define SMSC_WARNING_ENABLED	(1)
#endif
#ifndef SMSC_ERROR_ENABLED
#define SMSC_ERROR_ENABLED	(1)
#endif

/* Debug Utilities */
/* SMSC_TRACE is used for informational purposes only,
	it may be useful during debugging but is usually too
	noisy to keep it enabled all the time.
	'condition' is usually filled in with an individual module 
	debug enable switch, but it could also be used to specify a runtime
	condition that activates the message. */
#if (SMSC_TRACE_ENABLED)
#define SMSC_TRACE(condition,message) 				\
	do {											\
		if((condition)&(1|DEBUG_TRACE_BIT)) {		\
			SMSC_PLATFORM_MESSAGE(("  TRACE: "));	\
			SMSC_PLATFORM_MESSAGE(message); 		\
			SMSC_PLATFORM_MESSAGE(("\n"));			\
		}											\
	} while(0)
#define SMSC_PRINT(condition,message)			\
	do {										\
		if((condition)&(1|DEBUG_TRACE_BIT)) {	\
			SMSC_PLATFORM_MESSAGE(message);		\
		}										\
	} while(0)
#else
#define SMSC_TRACE(condition,message)
#define SMSC_PRINT(condition,message)
#endif

/* SMSC_NOTICE is intended to be used only when an error is detected
   and fully handled and recoverable. (example is dropping packets) 
	'condition' is usually filled in with an individual module 
	debug enable switch, but it could also be used to specify a runtime
	condition that activates the message. */
#if (SMSC_NOTICE_ENABLED)
#define SMSC_NOTICE(condition,message) 				\
	do {											\
		if((condition)&(1|DEBUG_NOTICE_BIT)) {		\
			SMSC_PLATFORM_MESSAGE((" NOTICE: "));	\
			SMSC_PLATFORM_MESSAGE(message);			\
			SMSC_PLATFORM_MESSAGE(("\n"));			\
		}											\
	} while(0)
#else
#define SMSC_NOTICE(condition,message)
#endif

/* SMSC_WARNING is intended to be used only when an error is detected
   and but may not be handled or recoverable. (example is how to handle unknown codes) 
	'condition' is usually filled in with an individual module 
	debug enable switch, but it could also be used to specify a runtime
	condition that activates the message. */
#if (SMSC_WARNING_ENABLED)
#define SMSC_WARNING(condition,message) 			\
	do {											\
		if((condition)&(1|DEBUG_WARNING_BIT)) {		\
			SMSC_PLATFORM_MESSAGE(("WARNING: "));	\
			SMSC_PLATFORM_MESSAGE(message);			\
			SMSC_PLATFORM_MESSAGE(("\n"));			\
		}											\
	} while(0)
#else
#define SMSC_WARNING(condition,message)
#endif

/* SMSC_ERROR is to be used only when a fatal unrecoverable error has 
   accured. It contains a halt command to prevent further corruption.
   SMSC_ASSERT is similar to SMSC_ERROR in that both can be used to notify
   of a fatal error. SMSC_ASSERT allow the user to provide a condition
   which if false will trigger the error. If the error is triggered an 
   halt command will prevent further execution.
   Neither SMSC_ERROR or SMSC_ASSERT can be enabled on a per module based.
   If they are enabled they are enabled for all modules.
   */
#if (SMSC_ERROR_ENABLED)
#define SMSC_ERROR(message) 								\
	do { 													\
		SMSC_PLATFORM_MESSAGE(("!ERROR!: "));				\
		SMSC_PLATFORM_MESSAGE(message);						\
		SMSC_PLATFORM_HALT_MESSAGE(							\
			("\n!ERROR!: file=%s, line=%d\n",				\
				__FILE__,__LINE__));						\
	} while(0)

#define SMSC_ASSERT(condition) 								\
	do { 													\
		if(!(condition)) {									\
			SMSC_PLATFORM_HALT_MESSAGE(						\
				("ASSERTION FAILURE: file=%s, line=%d\n", 	\
                	__FILE__, __LINE__));					\
        }													\
   	} while(0)
            
/*
* The following macros help by verifying you have a valid structure pointer
*   This is especially useful when void pointers are used to pass structures
*   around. These macros can be used to make sure a structure has been 
*   initialized and make sure it is the correct structure.
*/
#define DECLARE_SIGNATURE	u32_t mSignature;
#define ASSIGN_SIGNATURE(structure_pointer,signature) 				\
	do {															\
		(structure_pointer)->mSignature=((u32_t)signature);			\
	}while(0)
#define CHECK_SIGNATURE(structure_pointer,signature) 				\
	do {															\
		if((structure_pointer)->mSignature!=((u32_t)signature)) {		\
			SMSC_PLATFORM_HALT_MESSAGE(								\
				("SIGNATURE_FAILURE: file=%s, line=%d\n",			\
					__FILE__, __LINE__));							\
		}															\
	} while(0)
#define CLEAR_SIGNATURE(structure_pointer)			\
	do {											\
		(structure_pointer)->mSignature=(u32_t)0);	\
	} while(0)
#else /* SMSC_ERROR_ENABLED */
#define SMSC_ERROR(message)
#define SMSC_ASSERT(condition)  
#define DECLARE_SIGNATURE
#define ASSIGN_SIGNATURE(structure_pointer,signature)
#define CHECK_SIGNATURE(structure_pointer,signature)
#define CLEAR_SIGNATURE(structure_pointer)
#endif /* SMSC_ERROR_ENABLED */

#define SMSC_INTERRUPT_STACK_SIZE	(2048)

#if SMSC_ERROR_ENABLED
#define SMSC911X_PLATFORM_DATA_SIGNATURE (0xB8973454)
#endif

typedef struct SMSC911X_PLATFORM_DATA_
{
	DECLARE_SIGNATURE
	mem_ptr_t io_address;	/* Base address */
	int irq_number;			/* interrupt number */
	
	SMSC911X_ISR isr;
	void * isr_argument;
	
	/* platform specific data structure: io address, irq, isr
	handler and other platform specific data need to be part of
	this structure.
	*/
} SMSC911X_PLATFORM_DATA;

static SMSC911X_PLATFORM_DATA Smsc911xPlatformData[SMSC911X_INTERFACE_COUNT];

/*****************************************************************************
* The following functions are to be implemented according to the 
*   platform independent interface defined in 
*
* Network_Stack\Source\interfaces\smsc911x.h
* 
* Please see that file for full documentation on the expected behavior 
*   of these functions.
*****************************************************************************/

#if SMSC_TRACE_ENABLED
void Smsc911xPlatform_DisplayResources(int debugMode,int interfaceIndex)
{
	/* Prints the platform specific data such as io address, irq
	number, level and other platform specific information if any.
	*/
	SMSC911X_PLATFORM_DATA * platformData=NULL;
	SMSC_ASSERT((interfaceIndex>=0)&&(interfaceIndex<SMSC911X_INTERFACE_COUNT));
	platformData=&(Smsc911xPlatformData[interfaceIndex]);
	SMSC_TRACE(debugMode,("RESOURCES:"));
	SMSC_TRACE(debugMode,("  io_address=0x%p",(void *)(platformData->io_address)));
	SMSC_TRACE(debugMode,("  irq_number=%d",platformData->irq_number));
	/* Print any other platform specific resources here */
}
#endif

int Smsc911xPlatform_Initialize(int interfaceIndex)
{
	/* Initialize platform specific things necessary to make the register space
	accessible by the driver.
	*/
	

⌨️ 快捷键说明

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