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

📄 main.c

📁 基于usb 芯片net2272的一个loopback的程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*********************************************************************************

Copyright(c) 2005 Analog Devices, Inc. All Rights Reserved.

This software is proprietary and confidential.  By using this software you agree
to the terms of the associated Analog Devices License Agreement.

*********************************************************************************/


/*********************************************************************

Include files

*********************************************************************/

#include <services/services.h>		// system service includes
#include <drivers/adi_dev.h>		// device manager includes
#include <adi_net2272.h>			// NET2272 device driver includes

#include "ezkitutilities.h"			// EZ-Kit includes
#include "plx/NcCommon.h"			// Netchip common includes
#include "usbcmd.h"					// USB commands

// firmware version string info
#pragma align 4
char FwVersionInfo[NUM_VERSION_STRINGS][MAX_VERSION_STRING_LEN] = {
																	__DATE__,		// build date
																	__TIME__,		// build time
																	"02.00.00",		// version number
#ifdef __ADSPBF533__
																	"ADSP-BF533",	// target processor
#elif defined(__ADSPBF537__)
																	"ADSP-BF537",	// target processor
#elif defined(__ADSPBF561__)
																	"ADSP-BF561",	// target processor
#else
#error *** Processor not supported ***
#endif
																	"loopback"};	// application name


volatile bool g_bRxFlag = FALSE;			// rx flag
volatile bool g_bTxFlag = FALSE;			// tx flag
volatile bool g_bUsbConfigured = FALSE;		// USB device configured flag

/*********************************************************************

Prototypes

*********************************************************************/

u32 usb_Read(	ADI_DEV_DEVICE_HANDLE DeviceHandle, ADI_DEV_BUFFER_TYPE BufferType,
				ADI_DEV_BUFFER *pBuffer, bool bWaitForCompletion);
u32 usb_Write(	ADI_DEV_DEVICE_HANDLE DeviceHandle, ADI_DEV_BUFFER_TYPE BufferType,
				ADI_DEV_BUFFER *pBuffer, bool bWaitForCompletion);
unsigned int QuerySupport( ADI_DEV_DEVICE_HANDLE devhandle, u32 u32Command );
unsigned int Loopback(ADI_DEV_DEVICE_HANDLE devhandle, u32 u32Count);
unsigned int ReadMemory( ADI_DEV_DEVICE_HANDLE devhandle, u8 *p8Address, u32 u32Count );
unsigned int WriteMemory( ADI_DEV_DEVICE_HANDLE devhandle, u8 *p8Address, u32 u32Count );

/*********************************************************************

Static data

*********************************************************************/

static ADI_DEV_DEVICE_HANDLE DevHandle;										// device handle
static ADI_DEV_1D_BUFFER UsbcbBuffer;										// one-dimensional buffer for processing usbcb
static u8 IntMgrData[                      (ADI_INT_SECONDARY_MEMORY * 0)];	// storage for interrupt manager
static u8 DMAMgrData[ADI_DMA_BASE_MEMORY + (ADI_DMA_CHANNEL_MEMORY * 2)];	// storage for DMA manager
static u8 DevMgrData[ADI_DEV_BASE_MEMORY + (ADI_DEV_DEVICE_MEMORY * 1)];	// storage for device manager
static ADI_INT_CRITICAL_REGION_DATA	CriticalRegionData;						// storage for critical region


/*********************************************************************

	Function:		failure

	Description:	In case of failure we toggle LEDs.

*********************************************************************/

void failure(void)
{
	volatile unsigned int v = 0;	// counter

	while (1)
	{
		ezTurnOnAllLEDs();

		// delay...leave LEDs on
    	for ( v = 0; v < 0x01ffffff; v++)
			;

		ezTurnOffAllLEDs();

		// delay...leave LEDs off
    	for ( v = 0; v < 0x01ffffff; v++)
			;
	}
}


/*********************************************************************

	Function:		ExceptionHandler
					HWErrorHandler

	Description:	We should never get an exception or hardware error,
					but just in case we'll catch them should one ever occur.

*********************************************************************/

static ADI_INT_HANDLER(ExceptionHandler)	// exception handler
{
	failure();
	return(ADI_INT_RESULT_PROCESSED);
}

static ADI_INT_HANDLER(HWErrorHandler)		// hardware error handler
{
	failure();
	return(ADI_INT_RESULT_PROCESSED);
}

/*********************************************************************

	Function:		ClientCallback

	Description:	Each type of callback event has it's own unique ID
					so we can use a single callback function for all
					callback events.  The switch statement tells us
					which event has occurred.

					In the example, we'll get a callback when the NET2272
					has completed processing of the buffer or when an
					important event has occured that the application
					should know about.

					Note that in the device driver model, in order to
					generate a callback for buffer completion, the
					CallbackParameter of the buffer must be set to a non-NULL
					value.  That non-NULL value is then passed to the
					callback function as the pArg parameter.

*********************************************************************/

static void ClientCallback( void *AppHandle, u32  Event, void *pArg)
{
	static unsigned int TxCtr = 0;				// number of buffers processed
	static unsigned int RxCtr = 0;				// number of buffers processed
	static unsigned int SetConfigCtr = 0;		// number of SET_CONFIGs
	static unsigned int RootPortResetCtr = 0;	// number of root port resets
	static unsigned int VbusFalseCtr = 0;		// number of VBUS false detections

	// note, AppHandle will be 0x2272 which was passed into the adi_dev_open() call
	// to indicate the NET2272 driver is making the callback

	switch (Event)
	{
		case ADI_NET2272_EVENT_DATA_TX:			// data was transmitted

			// pArg holds the address of the data buffer processed

			// set flag and increment counter
			g_bTxFlag = TRUE;
			TxCtr++;
			break;

		case ADI_NET2272_EVENT_DATA_RX:			// data was received

			// pArg holds the address of the data buffer processed

			// set flag and increment counter
			g_bRxFlag = TRUE;
			RxCtr++;
			break;

		case ADI_NET2272_EVENT_SET_CONFIG:		// host called set configuration

			// pArg holds the configuration number

			// set flag and increment counter
			if (0x1 == (u32)pArg)
				g_bUsbConfigured = TRUE;
			else
				g_bUsbConfigured = FALSE;

			SetConfigCtr++;

			break;

		case ADI_NET2272_EVENT_ROOT_PORT_RESET: // reset signaling detected

			// pArg is NULL for this event

			// set flag and increment counter
			g_bUsbConfigured = FALSE;
			RootPortResetCtr++;

			break;

		case ADI_NET2272_EVENT_VBUS_FALSE: 		// cable unplugged

			// pArg is NULL for this event

			// set flag and increment counter
			g_bUsbConfigured = FALSE;
			VbusFalseCtr++;

			break;

		case ADI_NET2272_EVENT_RESUME: 			// device resumed

			// pArg is NULL for this event
			break;

		case ADI_NET2272_EVENT_SUSPEND: 		// device suspended

			// pArg is NULL for this event
			break;
	}

	// return
}


/*********************************************************************
*
*	Function:	main
*
*********************************************************************/

#include <stdio.h>

#include "comm_command.h"

char my_buf[1024];


void main(void)
{
	unsigned int Result;							// result
	unsigned int i;									// index
	u32	ResponseCount;								// response count
	u32 SecondaryCount;								// secondary count
	ADI_DEV_MANAGER_HANDLE DeviceManagerHandle;		// DevMgr handle
	ADI_DMA_MANAGER_HANDLE DMAHandle;				// DMAMgr handle
	bool bKeepRunning = TRUE;						// keep running flag
	USBCB usbcb;									// USB command block
	USBCB *pusbcb = &usbcb;							// pointer to USBCB
	
	USB_COMM_COMMAND refCmd, cmd;
	
	printf("The address is: %x\n", my_buf);

⌨️ 快捷键说明

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