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

📄 main.c

📁 ADI Blackfin BF51X 範例程式
💻 C
📖 第 1 页 / 共 2 页
字号:

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

    /* initialize pieces required to start POST */
	Init_PLL();
    Init_SDRAM();
	Init_LEDs();
	Init_PushButtons();
	Init_Timers();
	Init_Timer_Interrupts();

	/* check pushbuttons right away */
	porth = g_nPORTHIO;

	/* if PB1 is pressed we want to enter the standard loop */
	if ( PH0 == (porth & PH0) )
	{
		g_nInitialTest = TID_STANDARD_LOOP;
		g_bIsTestChosen = true;
		g_nPostState = STATE_SELECTED;
	}

    /* check to see if the LCD EZ-EXTENDER is connected */
	if( IsLcdPresentAndConfigured() )
	{
		/* if so, display some pictures; note, this may blink LED0
			randomly while running */
		LCD_DISPLAY_PICS();
	}

	/* else blink the LEDs while waiting for user to enter test via pushbuttons */
	ClearSet_LED_Bank( (-1), 0x0000);
	while (!g_bIsTestChosen)
	{
		for(i = 0x100; i > 0; i--)
		{
			ClearSet_LED(LED1, 1);
			ClearSet_LED(LED2, 0);
			Delay(i);				/* delay decreasing */

			ClearSet_LED(LED1, 0);
			ClearSet_LED(LED2, 1);

			Delay(0x100 - i);		/* delay increasing */
		}

		if (g_bIsTestChosen)
			break;

		for(i = 0; i < 0x100; i++)
		{
			ClearSet_LED(LED1, 1);
			ClearSet_LED(LED2, 0);
			Delay(i);				/* delay increasing */

			ClearSet_LED(LED1, 0);
			ClearSet_LED(LED2, 1);
			Delay(0x100 - i);		/* delay decreasing */
		}
	}

	ClearSet_LED_Bank( (-1), 0x0000);

    /* standard loop */
    if( TID_STANDARD_LOOP == g_nInitialTest )
	{
        /* do the one-time tests first */
		PerformTest( TID_VERSION, IGNORE_FAILURES );
		PerformTest( TID_PBLED, DO_NOT_IGNORE_FAILURES );
		PerformTest( TID_ROTARY, DO_NOT_IGNORE_FAILURES );
		PerformTest( TID_EMMC, DO_NOT_IGNORE_FAILURES );

		/* loop on these tests forever */
		while ( 1 )
		{
			for( nTestIndex = TID_SPI_FLASH; nTestIndex <= TID_LAST_STD_LOOP_TEST; nTestIndex++ )
			{
				PerformTest( nTestIndex, DO_NOT_IGNORE_FAILURES );
				Delay(BLINK_FAST * 20);
			}

			g_loops++;

			/* indicate everything passed */
			ClearSet_LED_Bank( (-1), 0x0000);
			LED_Bar( BLINK_SLOW);
		}
	}

	/* some tests we don't want to loop on */
	else if( (TID_PROG_DIGIPOT == g_nInitialTest) ||
			 (TID_PROG_PUB_KEY == g_nInitialTest) ||
			 (TID_LCD_CONFIG_FLASH == g_nInitialTest) )
	{
		/* run test */
		PerformTest( g_nInitialTest, DO_NOT_IGNORE_FAILURES );

		/* wait, then reset the LEDs */
		Delay(BLINK_SLOW * 25);

		/* indicate everything passed */
		ClearSet_LED_Bank( (-1), 0x0000);

		while ( 1 )
		{
			/* do a slower blink to indicate we are done */
			LED_Bar( BLINK_SLOW );
		}
	}

	/* the rest of the tests we can loop on */
	else if( (g_nInitialTest < NUM_TESTS ) )	/* catch the rest */
	{
		/* if LCD_TOUCH, wait for user to configure switches and press PB2 */
		if ( g_nInitialTest == TID_LCD_TOUCH )
		{
			/* we'll blink LED2 to indicate the tester is able to configure
	  			for this test */
			ClearSet_LED( LED1, 0x0);
			ClearSet_LED( LED2, 0x0);
			ClearSet_LED( LED3, 0x0);
			do
			{
				ClearSet_LED( LED3, 0x2);	/* toggle */
				Delay(BLINK_SLOW*2);		/* blink a little faster than setup */
			}while( (g_nPORTHIO & PH1) != PH1 );

			/* clear global mirror register */
			g_nPORTHIO &= ~PH1;
		}

		/* loop on this test */
		while ( 1 )
		{
	   		/* run test */
			PerformTest( g_nInitialTest, DO_NOT_IGNORE_FAILURES );

			/* wait, then reset the LEDs */
			Delay(BLINK_SLOW * 25);

			/* indicate everything passed */
			ClearSet_LED_Bank( (-1), 0x0000);

			for ( i = 0; i < 4; i++)
			{
				/* blink a few times to indicate the test is complete before looping */
				LED_Bar( BLINK_SLOW );
			}
		}
	}

	/* else it's an unsupported test */
	else
	{
		/* let PerformTest display failure */
		PerformTest( g_nInitialTest, DO_NOT_IGNORE_FAILURES );
	}
}


/*******************************************************************
*   Function:    BLINK_FW_VERSION
*   Description: displays firmware version via LEDs
*******************************************************************/
int BLINK_FW_VERSION( void )
{
	bool breakout = false;	/* flag in case you want to break out */
	int n = 0;				/* index */


	while (!breakout)
	{
		/* blink the MAJOR rev on LED0 */
		for ( n = 0; n < FIRMWARE_MAJOR_REV; n++ )
		{
			ClearSet_LED_Bank( (-1), 0x0000);
			Delay(BLINK_SLOW * 3);
			ClearSet_LED_Bank( TEST_1, TEST_1_SET);
			Delay(BLINK_SLOW * 3);
		}

		/* delay */
		ClearSet_LED_Bank( (-1), 0x0000);
		Delay(BLINK_SLOW * 5);

		/* blink the MINOR rev on LED1 */
		for ( n = 0; n < FIRMWARE_MINOR_REV; n++ )
		{
			ClearSet_LED_Bank( (-1), 0x0000);
			Delay(BLINK_SLOW * 3);
			ClearSet_LED_Bank( TEST_2, TEST_2_SET);
			Delay(BLINK_SLOW * 3);
		}

		/* blink a bar to indicate we're done showing both versions */
		ClearSet_LED_Bank( (-1), 0x0000);
		Delay(BLINK_SLOW * 5);
		LED_Bar( BLINK_SLOW );
	}

	return 1;
}


/*******************************************************************
*   Function:    CHECK_CONFIGURATION_DATA
*   Description: performs a check on the configuration data stored in parallel flash
*******************************************************************/
int CHECK_CONFIGURATION_DATA(void)
{
	unsigned char *cfgdata = (unsigned char*) 0x203f0000;	/* start of configuration data */
	unsigned char EzProj[6] = {'A', 'A', '0', '2', '1', '7'}; /* project number for this board */
	int nResult = 1;					/* status flag */
	int i = 0;							/* index */
	int project_offset = 48;			/* project number offset */

	/* make sure it's programmed as the correct board */
	for( i = 0; i < 6; i++ )
	{
		if( cfgdata[project_offset + i] != EzProj[i] )
		{
			nResult = 0;
			break;
		}
	}

	return nResult;
}


/****************************************************************************
*   Function:    IsLcdPresentAndConfigured
*   Description: checks to see if an LCD Ez Extender is connected
*				 and the configuration flash is configured
******************************************************************************/
bool IsLcdPresentAndConfigured(void)
{
	unsigned char dataOut[6];			/* storage for configuration data */
	unsigned char LcdProj[6] = {'A', 'A', '0', '2', '1', '6'}; /* project number for
																  the LCD extender */
	bool bLcdPresent = true;			/* status flag */
	int i = 0;							/* index */

	/* Read the configuration flash back so we can verify.
	   Location 48 is the beginning of a unique number
	   that identifies the extender that is connected */
	ReadM24C02(48, dataOut, 6);

	/* make sure it is the LCD extender */
	for( i = 0; i < 6; i++ )
	{
		if( dataOut[i] != LcdProj[i] )
		{
			bLcdPresent = false;
			break;
		}
	}

	return bLcdPresent;
}


⌨️ 快捷键说明

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