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

📄 main.c

📁 基于visual dsp++开发环境
💻 C
字号:
/*****************************************************************************
**																			**
**	 Name: 	main.c															**
**																			**
******************************************************************************

(C) Copyright 2006 - Analog Devices, Inc.  All rights reserved.

Project Name:	BF538F POST ATE

Date Modified:	01 Sept 2005

Software:		VisualDSP++ 4.5

Hardware:		ADSP-BF538F EZ-KIT Lite


Purpose:		Perform a POST ATE on the BF538F EZ-Kit Lite


BF538F EZ-KIT test indicators 	(version 1.00.0 1 Sept 2006)


Enter BF538F EZ-KIT POST by pressing PB1.

			LED4	LED3	LED2	LED1
VERSION		0   	0   	0   	1
PBLED		0		0		1		0
SDRAM		0		0		1		1
UART		0		1		0		0	needs jumper
FLASH		0		1		0		1
AUDIO		0		1		1		0	not used on stamp
FLASH_INT	0		1		1		1   test using PB1 & PB3
CAN_TX		1		0		0		0	test using PB1 & PB2
CAN_RX		1		0		0		1	test using PB2
ETHERNET	1		0		1		0	needs loopback connector,test using PB4


The switch settings for the built in self test differ slightly from the default settings shipped.
See the users manual for default switch settings.
"Switch settings:
	- SW2 CAN Enable, 		1 = OFF, 2 = OFF, 3 = ON,  4 = ON.
	- SW4 UART,				1 = OFF, 2 = ON,  3 = OFF, 4 = ON.
	- SW5 Push Buttons,		1 = ON,  2 = ON,  3 = ON,  4 = ON.
	- SW6 Flash enable,		1 = ON,  2 = ON,  3 = ON,  4 = ON.
	- SW14 FCE		,		1 = OFF, 2 = OFF, 3 = OFF, 4 = OFF.
	- SW7 Audio enable,		1 = ON,  2 = ON,  3 = ON,  4 = ON, 5 = 0N, 6 = ON, 7 = ON, 8 = ON.
	- SW3 Boot mode sel,	1 = OFF, 2 = ON
	- JP9 UART loop,		ON

*****************************************************************************/
#include <string.h>
#include <services/services.h>		// system service includes
#include <drivers/adi_dev.h>		// device manager includes

#include "Timer_ISR.h"
#include "post_common.h"
#include "PBLED_test.h"
#include "Pll.h"
#include <drivers\flash\adi_m29w320.h>
#include <drivers\flash\adi_S29AL004D_8D.h>	// flash-S29AL004D_8D includes


static u8 DevMgrData[ADI_DEV_BASE_MEMORY + (ADI_DEV_DEVICE_MEMORY * 2)];
static ADI_INT_CRITICAL_REGION_DATA	CriticalRegionData;						// storage for critical region


ADI_DEV_DEVICE_HANDLE DevHandleM29W320;
ADI_DEV_DEVICE_HANDLE DevHandleS29AL004D_8D;

//////////////////////////////////////////////////////////////////////////////
//
// variables
//
//////////////////////////////////////////////////////////////////////////////
static int g_loops = 0;
char g_szVersion[64] = "1.00.0";
char g_szBuildDate[64];
char g_szBuildTime[64];


//////////////////////////////////////////////////////////////////////////////
//
// function prototypes
//
//////////////////////////////////////////////////////////////////////////////
int TEST_VERSION(void);
int TEST_PBLED(void);
int TEST_SDRAM(void);
int TEST_UART(void);
int TEST_CAN_TX(void);
int TEST_CAN_RX(void);
int TEST_AUDIO(void);
int TEST_FLASH(void);
int TEST_FLASH_INTERNAL(void);
int TEST_ETHERNET(void);
int TEST_DUMMY(void) {return 1;}// a dummy test for targets which do not have a specific piece of hardware

// this controls the number of test run using g_pTestFunctions
typedef enum TEST_INDEX_tag{
	VERSION,			// 0001
	PBLED,				// 0010
	SDRAM,				// 0011
	UART,				// 0100
	FLASH,				// 0101
	AUDIO,				// 0110
	NUM_TESTS_IMPLEMENTED,	// this is the end of repeating tests
// these are one time tests they must be manually configured using push buttons
	FLASH_INT = NUM_TESTS_IMPLEMENTED,// 0111
	CAN_TX,						 	// 1000
	CAN_RX,							// 1001
	ETHERNET,						// 1010

	LAST_POST_TEST,

	NUM_TESTS = LAST_POST_TEST

}enTEST_INDEX;


typedef int (*pfnTests)(void);

typedef struct stTestParams_TAG
{
	enTESTS m_nTest;
	enTEST_STATES m_nTestState;
	pfnTests m_pTestFunctions;

}stTestParamaters;


stTestParamaters g_Tests[NUM_TESTS] = {
	{TEST_1, TEST_1_SET, TEST_VERSION},
 	{TEST_2, TEST_2_SET, TEST_PBLED},
 	{TEST_3, TEST_3_SET, TEST_SDRAM},
 	{TEST_4, TEST_4_SET, TEST_UART},
 	{TEST_5, TEST_5_SET, TEST_FLASH},
 	{TEST_6, TEST_6_SET, TEST_AUDIO},
 	{TEST_7, TEST_7_SET, TEST_FLASH_INTERNAL},
 	{TEST_8, TEST_8_SET, TEST_CAN_TX},
 	{TEST_9, TEST_9_SET,TEST_CAN_RX},
 	{TEST_10, TEST_10_SET,TEST_ETHERNET},
 	};


//////////////////////////////////////////////////////////////////////////////
// void PerformTest( const stTestParamaters Test, const int nIgnoreResult  )
//
// Purpose:  Wrap up the test paramaters and perform the test
//////////////////////////////////////////////////////////////////////////////
int PerformTest( const stTestParamaters Test, const int nIgnoreResult )
{
	int nResult = 0;

	Delay(BLINK_SLOW * 25);
	ClearSet_LED_Bank( (-1), 0x0000);
	ClearSet_LED_Bank( Test.m_nTest, Test.m_nTestState); // change the state of the led

	nResult = Test.m_pTestFunctions();
	if( 0 == nResult )
	{	// test failed
		if( 0 == nIgnoreResult )
		{
			Blink_LED( Test.m_nTest, BLINK_FAST );
		}
	}

	return nResult;
}


//--------------------------------------------------------------------------//
// Function:	main														//
//--------------------------------------------------------------------------//
void main(void)
{
	int bPassed;
	int nDelay;
	volatile int bTrue = 1;

	unsigned int Result;							// result
	u32	ResponseCount;								// response count
	u32 SecondaryCount;								// secondary count
	ADI_DEV_MANAGER_HANDLE DeviceManagerHandle;		// DevMgr handle

  	strcpy(g_szBuildDate, __DATE__);
	strcpy(g_szBuildTime, __TIME__);

	// Set CCLK = 500 MHz, SCLK = 125 MHz
	Init_PLL();

	// initialize device manager
	Result = adi_dev_Init(	DevMgrData,				// ptr to memory for use by DevMgr
							sizeof(DevMgrData),		// size of memory for use by DevMgr
							&ResponseCount,			// returns number of devices DevMgr can support
							&DeviceManagerHandle,	// ptr to DevMgr handle
							&CriticalRegionData);	// ptr to critical region info

	Init_LEDs();
	Init_PushButtons();

	Init_Timers();
	Init_Timer_Interrupts();

	int temp = *pFIO_FLAG_D;

	asm("nop;");
	asm("nop;");
	asm("nop;");
	asm("nop;");

	// If PB1 was pressed we will test the BF538F EZ-KIT Lite
	if( PF0 == (temp & PF0) )
	{

		// open the M29W320
		Result = adi_dev_Open(	DeviceManagerHandle,			// DevMgr handle
								&ADIM29W320EntryPoint,			// pdd entry point
								0,								// device instance
								NULL,							// client handle callback identifier
								&DevHandleM29W320,				// DevMgr handle for this device
								ADI_DEV_DIRECTION_BIDIRECTIONAL,// data direction for this device
								NULL,							// handle to DmaMgr for this device
								NULL,							// handle to deferred callback service
								NULL);							// client's callback function

		// POST test has been entered, do the one time tests

		// SILICON VERSION TEST //
		PerformTest( g_Tests[VERSION], 0 );


		// PUSH BUTTON & LED TEST //
		PerformTest( g_Tests[PBLED], 0 );

		// this is the CAN TX test, but it is only done once
		// and only if both push buttons have been pressed at the
		// same time
		if( PF1 == (temp & PF1) )
		{  	// CAN TEST //
			PerformTest( g_Tests[CAN_TX], 0 );
		}

		int nTestStartIndex = 2;

		while(1) // do the POST tests forever
		{
			int nTestIndex;


			for( nTestIndex = nTestStartIndex; nTestIndex < NUM_TESTS_IMPLEMENTED; nTestIndex++ )
			{
					PerformTest( g_Tests[nTestIndex], 0 );
			}

			// done with all tests
			g_loops++;

			// WAIT A BIT, THEN RESET THE LED's
			Delay(BLINK_SLOW * 25);

			// indicate everything passed
			ClearSet_LED_Bank( (-1), 0x0000);
			//for( nDelay = 0; nDelay < g_loops; nDelay++)
			{
				LED_Bar( BLINK_SLOW );
			}
		}// end while(1)

		// close the device, good programming practice would be to close the device
		// here but since the POST test runs in an infinite loop the device never needs
		// to be closed
		//Result = adi_dev_Close(DevHandleM29W320);
	}
	// Since the CAN test requires a receiver and a transmitter, this
	// puts the ezkit into a CAN receiver for the CAN test
	// and only if both push buttons have been pressed at the
	// same time
	else if( PF1 == (temp & PF1) )
	{  	// CAN RX TEST //
		while( 1 )
		{
			PerformTest( g_Tests[CAN_RX], 1 );

			ClearSet_LED_Bank( (-1), 0x0000);
			for( nDelay = 0; nDelay < 8; nDelay++)
			{
				LED_Bar( BLINK_SLOW );
			}
		}
	}
	// Test internal flash
	else if( PF2 == (temp & PF2) )
	{
	   	// open the S29AL004D_8D
		Result = adi_dev_Open(	DeviceManagerHandle,			// DevMgr handle
								&ADIS29AL004D_8DEntryPoint,		// pdd entry point
								0,								// device instance
								NULL,							// client handle callback identifier
								&DevHandleS29AL004D_8D,			// DevMgr handle for this device
								ADI_DEV_DIRECTION_BIDIRECTIONAL,// data direction for this device
								NULL,							// handle to DmaMgr for this device
								NULL,							// handle to deferred callback service
								NULL);							// client's callback function

		while( 1 )
		{
			PerformTest( g_Tests[FLASH_INT], 0 );

			// WAIT A BIT, THEN RESET THE LED's
			Delay(BLINK_SLOW * 25);

			ClearSet_LED_Bank( (-1), 0x0000);
			for( nDelay = 0; nDelay < 4; nDelay++)
			{
				LED_Bar( BLINK_SLOW );
			}
		}
	}
	// Test ethernet
	if( PF3 == (temp & PF3) )
	{

		while( 1 )
		{
			PerformTest( g_Tests[ETHERNET], 0 );

			// WAIT A BIT, THEN RESET THE LED's
			Delay(BLINK_SLOW * 25);

			ClearSet_LED_Bank( (-1), 0x0000);
			for( nDelay = 0; nDelay < 4; nDelay++)
			{
				LED_Bar( BLINK_SLOW );
			}
		}
	}
	else
	{
		// this is just normal blink mode.
		ClearSet_LED_Bank( (-1), 0x0000);
		while(1)
		{
			LED_Bar(BLINK_SLOW);
		}
	}
}

⌨️ 快捷键说明

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