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

📄 xscale_test.c

📁 基于ecos的redboot
💻 C
📖 第 1 页 / 共 4 页
字号:

	if (GpioOutputPort==0x55)
		printf("\nGPIO Output Data Register first write/read test PASSED.");
	else
		printf("\nGPIO Output Data Register first write/read test FAILED.");

/*
	printf("\n\nStrike Enter to continue" );
	printf("\n0x55" );
	while(xgetchar()!=0x0d);
*/
	
	/* write output data pattern to GPIO Output Data Register at address 00001724h */
	*( unsigned char * ) 0x00001724 = 0xaa;
	
	/* read output data pattern from GPIO Output Data Register at address 00001724h */
	GpioOutputPort = *( unsigned char * ) 0x00001724;

	if (GpioOutputPort==0xaa)
		printf("\nGPIO Output Data Register second write/read test PASSED.");
	else
		printf("\nGPIO Output Data Register second write/read test FAILED.");
	
	
	printf("\n\nRemove output test socket from header J16, strike 'Enter' to continue" );
	while(xgetchar()!=0x0d);



	/* GPIO input port test */
/*
	printf("\n\nPlug input test socket into header J16, strike 'Enter' to continue" );
	while(xgetchar()!=0x0d);
*/

	/* GPIO Input Data Register address is 00001720h */	/* read port */
/*
	GpioInputPort = *( unsigned char * ) 0x00001720;
	if ( GpioInputPort==0x55 )
		printf("\nGPIO Input Data Register first read test PASSED");
	else
		printf("\nGPIO Input Data Register first read test FAILED");
*/

	
	/* GPIO Input Data Register address is 00001720h */	/* read port */
/*
	GpioInputPort = *( unsigned char * ) 0x00001720;

	if ( GpioInputPort==0xaa )
		printf("\nGPIO Input Data Register second read test PASSED");
	else
		printf("\nGPIO Input Data Register second read test FAILED");
*/	
/*
	printf("\n\nRemove input test socket from header J16, strike 'Enter' to continue" );
	while(xgetchar()!=0x0d);
*/

} /* end gpio_test() */



/*************************************************************************
* Device_Seek - look for a PCI device
*
* During initialization, a device driver must call this function
* (or a similar one) with the specific PCI Vendor Id and Device Id
* of the device to be supported to determine its location (or lack
* thereof) on the PCI bus.  If multiple devices are to be supported,
* this function must be called repeatedly with an increasing dev_index
* until the function returns ERROR.  Each instance (if any) of the device
* will then have been identified.
*
* Once the device is located, the device driver can then call the 
* appropriate PCI BIOS function to read device information from PCI
* Configuration Space (i.e. Runtime Register PCI Base address, Local
* Memory PCI Base address, etc.)
*
*/
STATUS Device_Seek(
		int verbose,
		unsigned long adapter_vendor,
		unsigned long adapter_device_id,
		unsigned long dev_index,
    	PCI_DEVICE_LOCATION *dev_info
		)
{
	if (verbose)
	{
		printf("Looking for Adapter on PCI Bus with:\n");
		printf("Vendor Id = 0x%04x\n",adapter_vendor);
		printf("Device Id = 0x%04x\n",adapter_device_id);
		printf("Index     = %x\n",dev_index);
	}

    if (sys_find_pci_device (adapter_vendor,
			     adapter_device_id,
			     dev_index, dev_info) != OK)
    {
		if (verbose) printf("Failed to Find Adapter\n");
		return (ERROR);
    }
    else
    {
		if (verbose)
		{
			printf("Adapter found at :\n");
			printf("  PCI Bus Number : %d\n", dev_info->bus_number);
			printf("  Device Number  : %d\n", dev_info->device_number);
		}
		return (OK);
    }
}


/* i82559 Ethernet test */
void ether_test (void)
{

    PCI_DEVICE_LOCATION dev_loc[6];  /* 6 is the max Enet for now */
	int	unit = 0;
	int i, num_enet;

	
	for (i = 0, num_enet = 0; i < 6; i++, num_enet++)
	{
		if (Device_Seek (FALSE, VENDOR_INTEL,
			     I82557,
				 i,
				 &(dev_loc[num_enet])) != OK)
		{
			break;
		}

	}

	for (i = 0; i < 6; i++, num_enet++)
	{
		if (Device_Seek (FALSE, VENDOR_INTEL,
			     I82559ER,
				 i,
				 &(dev_loc[num_enet])) != OK)
		{
			break;
		}

	}
	
	if (num_enet == 0)
	{
		printf ("No supported Ethernet devices found\n");
		return;
	}
	
	printf ("Supported Ethernet Devices:\n\n");

	printf (" Unit#  Bus#  Device#\n");
	printf (" -----  ----  -------\n");
	for (i = 0; i < num_enet; i++)
	{
		printf ("   %d     %d       %d\n", i, dev_loc[i].bus_number, dev_loc[i].device_number); 
	}

	printf ("\nEnter the unit number to test : ");
	unit = decIn();
	printf ("\n");

	pci_ether_test (dev_loc[unit].bus_number,
					dev_loc[unit].device_number,
					dev_loc[unit].function_number);

}




/* Setup Serial EEPROM for Ethernet Configuration */
static void enet_setup (void)
{
	UINT32 adapter_ptr;   /* Ptr to PCI Ethernet adapter */

	PCI_DEVICE_LOCATION dev_loc;
	UINT16 eepromData[3] = 
	{
		0x4801,		/* Valid EEPROM, No Expansion ROM, Rev = ?, PHY Addr = 1 */
		0x0700,		/* Subsystem Id			- PCI700 */
		0x113c		/* Subsystem Vendor Id	- Cyclone Microsystems */
	};
	int config_data_offset = 0x0a;	/* offset into EEPROM for config. data storage */
	int ia_offset = 0x00;			/* offset into EEPROM for IA storage */
	UINT8  buffer[6];				/* temporary storage for IA */
    UINT16 temp_node_addr[3] = {0,0,0};
    UINT16 serial_no;
    UINT8  revision_id = 0, port_id = 0;
	char rev_string[8];

    /* Cyclone identifier */
    buffer[0] = 0x00;
    buffer[1] = 0x80;
    buffer[2] = 0x4D;
	buffer[3] = 0x46;    /* board identifier - PCI700 = 70 = 0x46 */

	serial_no = 10000;
	while (serial_no >= 10000)
	{
		printf ("\nEnter the board serial number (1 - 9999): ");
		serial_no = decIn();
		printf ("\n");
	}
	revision_id = 8;
	while ((revision_id < 1) || (revision_id > 7))
	{
		printf ("\nEnter the board revison (A - G)      : ");
		sgets (rev_string);
		rev_string[0] = (rev_string[0] & 0xdf);		/* convert to upper case */
		revision_id = (rev_string[0] - 'A') + 1;	/* convert to a number 1 - 7 */
		printf ("\n");
	}
	revision_id &= 0x7;
	eepromData[0] |= (revision_id << 8);	/* add the rev. id to data */
	
	/* we only want to set up on-board 559 */
	dev_loc.bus_number = 2;
	dev_loc.device_number = 0;
	dev_loc.function_number = 0;
	
	/* Get the PCI Base Address for mem. runtime registers */
	if (sys_read_config_dword (dev_loc.bus_number,
						    dev_loc.device_number,
	   					    dev_loc.function_number,
							0x10, &adapter_ptr) == ERROR)
	{
		printf("Unable to read i82559 PCI Base Address\n");
		return;
	}

	/* strip off indicator bits */
	adapter_ptr = adapter_ptr & 0xfffffff0;

	printf ("Writing the Configuration Data to the Serial EEPROM... ");
	if (eeprom_write (adapter_ptr,config_data_offset,eepromData,3) != OK)
	{
		printf ("Error writing the Configuration Data to Serial EEPROM\n");
		return;
	}
	printf ("Done\n");

	/* setup node's Ethernet address */
	port_id = ((0 << 6) & 0xc0);	/* two bits of port number ID */
	buffer[4] = (UINT8) (((serial_no & 0x3FFF) >> 8) | port_id);
	buffer[5] = (UINT8) (serial_no & 0x00FF); 
		
	temp_node_addr[0] = (UINT16) ((buffer[1] << 8) + buffer[0]);
	temp_node_addr[1] = (UINT16) ((buffer[3] << 8) + buffer[2]);
	temp_node_addr[2] = (UINT16) ((buffer[5] << 8) + buffer[4]);

	printf ("Writing the Individual Address to the Serial EEPROM... ");
	if (eeprom_write (adapter_ptr,ia_offset,temp_node_addr,3) != OK)
	{
		printf ("\nError writing the IA address to Serial EEPROM.\n");
		return;
	}
	printf ("Done\n"); 
	

	/* now that we have finished writing the configuration data, we must ask the
	   operator to reset the PCI916 to have the configuration changes take effect.
	   After the reset, the standard Enet. port diagnostics can be run on the 916
	   under test */

	printf ("\n\n******** Reset the IQ80310 Now to Have Changes Take Effect ********\n\n");

	/* wait forever as a reset will bring us back */
	while ((volatile int)TRUE)
		;
}



/* use the clock in the Performance Monitoring Unit to do delays */
void polled_delay (int usec)
{
volatile int i;
	
	_enable_timer();

	for (i = 0; i < usec; i++)
		_usec_delay();

	_disable_timer();
}



void internal_timer()
{
	int j, i;

	printf ("\n");

	_enable_timer();

	printf ("Timer enabled...\n");

	for (j = 0; j < 20; j++)
	{		
		printf (".");
		for (i = 0; i < 1000; i++)
			_msec_delay();
	}

	_disable_timer();

	printf ("\nTimer disabled...\n");
}






#define I80960RP_BRIDGE		0x0960
#define I80960RP_NAME0		"80960RP PCI-PCI Bridge"

#define I80960RP_ATU		0x1960
#define I80960RP_NAME1		"80960RP Address Translation Unit"

#define I80960RM_BRIDGE		0x0962
#define I80960RM_NAME0		"80960RM PCI-PCI Bridge"

#define I80960RM_ATU		0x1962
#define I80960RM_NAME1		"80960RM Address Translation Unit"

#define I80960RN_BRIDGE		0x0964
#define I80960RN_NAME0		"80960RN PCI-PCI Bridge"

#define I80960RN_ATU		0x1964
#define I80960RN_NAME1		"80960RN Address Translation Unit"

#define I80303_BRIDGE		0x0309
#define I80303_NAME0		"80303 PCI-PCI Bridge"

#define I80303_ATU			0x5309
#define I80303_NAME1		"80303 Address Translation Unit"



/******************************************************************/
/* The following functions are all part of the PCI Interrupt Test */
/******************************************************************/
/* definitions pertaining to PCI interrupt test */
#define MAX_I960RX 31
typedef struct 
{
	UINT32 device_id;
	UINT32 busno;
	UINT32 devno;
	UINT32 funcno;
} I960RX_DEVICES;
I960RX_DEVICES i960Rx_devices[MAX_I960RX];
UINT32 num_rx_devices = 0; 
UINT32	messagingUnitBase = (UINT32)NULL;

/* Outbound Interrupt Status Register bits */
#define OB_STAT_INTA	(1 << 4)
#define OB_STAT_INTB	(1 << 5)
#define OB_STAT_INTC	(1 << 6)
#define OB_STAT_INTD	(1 << 7)

/* Outbound Doorbell Register bits */
#define OB_DBELL_INTA	(1 << 28)
#define OB_DBELL_INTB	(1 << 29)
#define OB_DBELL_INTC	(1 << 30)
#define OB_DBELL_INTD	(1 << 31)

/***********************************************************************
*
* line_to_string - Returns name as string of particular XINT number
*
*/
static char *line_to_string (int intline)
{
	switch (intline)
	{
		case XINT0: return("XINT0");
		case XINT1: return("XINT1");
		case XINT2: return("XINT2");
		case XINT3: return("XINT3");
		default:	return("ERROR");
	}
}


/***************************************************************************
*
* PCI_IntHandler - Interrupt handler for PCI interrupt test
*
* Used to verify that an interrupt was recieved during the PCI interrupt 
* test by the IQ80310 from the add-in i960Rx board.  This handler prints out
* which interrupt was recieved, and then clears the interrupt by clearing 
* the doorbell register on the i960Rx card.
*
*/
int PCI_IntHandler (int IntPin)
{
	UINT32 *OutboundDbReg	 = (UINT32 *)(messagingUnitBase + 0x2c);
	UINT32 *OutboundIstatReg = (UINT32 *)(messagingUnitBase + 0x30);

	switch (IntPin)
	{
	case INTA:

		/* check to see if we are looking at the correct interrupt */
		if (!(*OutboundIstatReg & OB_STAT_INTA))
		{		
		#if 0
			printf ("OISR Mismatch!\n");
			printf ("OISR = 0x%X\n", *OutboundIstatReg);
			printf ("**** PCI INTA Error ****\n\n");

			/* try to clear all sources */
			*OutboundDbReg = (OB_DBELL_INTA|OB_DBELL_INTB|OB_DBELL_INTC|OB_DBELL_INTD);
		#endif
			return (0);
		}
		else
		{			
			printf ("PCI INTA generated/received\n\n");
			printf ("OISR OK!\n");
			printf ("OISR = 0x%X\n", *OutboundIstatReg);
			printf ("**** PCI INTA Success ****\n\n");
			*OutboundDbReg |= OB_DBELL_INTA;		/* try to clear specific source */
			return (1);
		}

		break;

	case INTB:

		/* check to see if we are looking at the correct interrupt */
		if (!(*OutboundIstatReg & OB_STAT_INTB))
		{
		#if 0
			printf ("OISR Mismatch!\n");
			printf ("OISR = 0x%X\n", *OutboundIstatReg);
			printf ("**** PCI INTB Error ****\n\n");

			/* try to clear all sources */
			*OutboundDbReg = (OB_DBELL_INTA|OB_DBELL_INTB|OB_DBELL_INTC|OB_DBELL_INTD);
		#endif
			return (0);
		}
		else
		{
			printf ("PCI INTB generated/received\n\n");
			printf ("OISR OK!\n");
			printf ("OISR = 0x%X\n", *OutboundIstatReg);
			printf ("**** PCI INTB Success ****\n\n");
			*OutboundDbReg |= OB_DBELL_INTB;		/* try to clear specific source */
			return (1);
		}

		break;

	case INTC:

		/* check to see if we are looking at the correct interrupt */
		if (!(*OutboundIstatReg & OB_STAT_INTC))
		{
		#if 0	
			printf ("OISR Mismatch!\n");
			printf ("OISR = 0x%X\n", *OutboundIstatReg);
			printf ("**** PCI INTC Error ****\n\n");
	
			/* try to clear all sources */
			*OutboundDbReg = (OB_DBELL_INTA|OB_DBELL_INTB|OB_DBELL_INTC|OB_DBELL_INTD);
		#endif
			return (0);
		}
		else
		{
			printf ("PCI INTC generated/received\n\n");
			printf ("OISR OK!\n");

⌨️ 快捷键说明

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