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

📄 pbled_test.c

📁 ADSP 地层驱动
💻 C
字号:
/*****************************************************************************
**																			**
**	 Name: 	PB_LED_test.c											**	
**																			**
******************************************************************************

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

Pjoject Name:	BF533 ATE

Date Modified:	12/10/04				Ver 0.0

Software:		VisualDSP++ 4.5

Hardware:		ADSP-BF533 EZ-KIT Lite

Connections:	

Purpose:		Perform a POST push button test on the BF533 EZ-Kit Lite

*****************************************************************************/
#include <stdlib.h>
#include <sysreg.h>
#include <ccblkfn.h>
#include "PBLED_test.h"


#define pFlashA_PortB_Dir	(volatile unsigned char *)0x20270007
#define pFlashA_PortB_Data	(volatile unsigned char *)0x20270005


//--------------------------------------------------------------------------//
// Function:	void Delay(const unsigned long ulMs)						//
//																			//
// Description: Just a simple delay, don't be fooled by the ulMs, it's NOT
//				in miliseconds! 
//--------------------------------------------------------------------------//
void Delay(const unsigned long ulMs)
{
	unsigned long ulTMs = ulMs * 500;
	
	do{
		asm("nop;");
	}while( ulTMs--);
}


//--------------------------------------------------------------------------//
// Function:	Init_LEDs													//
//																			//
// Parameters:	None														//
//																			//
// Return:		None														//
//																			//
// Description:	This function configures PORTF2 as output for LEDs
//--------------------------------------------------------------------------//
void Init_LEDs(void)
{
	// enable all AMS banks
	*pEBIU_AMGCTL |= 0xE;
	
	// set all flags as outputs
	*pFlashA_PortB_Dir = 0xFF;
}

//--------------------------------------------------------------------------//
// Function:	void Init_PushButtons(void)
//																			//
// Description: Configure push button operation
//				
//--------------------------------------------------------------------------//
void Init_PushButtons(void)
{
	// set PF dir reg
    *pFIO_DIR = 0x0000;
    ssync();
    
    // set PF polarity reg
    *pFIO_POLAR = 0x0000;
    ssync();
    
    // enable PF inputs    
    *pFIO_INEN |= 0x0f00;
    ssync();
}


//////////////////////////////////////////////////////////////////////////////
// void LED_Bar(const int iSpeed)
// 
// PURPOSE:		Display a blinking LED bar
// 
// INPUT:		iSpeed - the speed of the blink
//////////////////////////////////////////////////////////////////////////////
void LED_Bar(const int iSpeed)
{
	enLED n;
	int j;
	
	for( n = LED4; n < LAST_LED; (n <<= 1) )
	{
		ClearSet_LED(n, 3);
		Delay(iSpeed);
	}
}



//////////////////////////////////////////////////////////////////////////////
// void Blink_LED(const int enleds, const int iSpeed)
// 
// PURPOSE:		Blink various LED's
// 
// INPUT:		iSpeed - the speed of the blink
//				enleds - the LED to actually blink
//////////////////////////////////////////////////////////////////////////////
void Blink_LED(const int enleds, const int iSpeed)
{
	int j;
	enLED n;
	
	while( 1 )
	{
		for( n = LED4; n < LAST_LED; (n <<= 1) )
		{
			if( n & enleds )
			{
				ClearSet_LED(n, 3);
			}
		}
		
		Delay(iSpeed);
	}
}



//////////////////////////////////////////////////////////////////////////////
// void ClearSet_LED_Bank(const int enleds, const int iState)
// 
// PURPOSE:		Clear or set a particular LED or group of LED's
// 
// INPUT:		iState - the state ON, OFF, TGL
//				enleds - the LED(s) to actually blink
//////////////////////////////////////////////////////////////////////////////
void ClearSet_LED_Bank(const int enleds, const int iState)
{
	enLED n;
	int nTempState = iState;
	
	
	for( n = LED4; n < LAST_LED; (n <<= 1) )
	{
		if( n & enleds )
		{
			ClearSet_LED(n, (nTempState & 0x3) );
		}
		
		nTempState >>= 2;
	}
}


//////////////////////////////////////////////////////////////////////////////
// void ClearSet_LED(const enLED led, const int bState)
// 
// PURPOSE:		Clear or set a particular LED (NOT A GROUP)
// 
// INPUT:		iState - the state ON, OFF, TGL
//				enleds - the LED(s) to actually blink
//////////////////////////////////////////////////////////////////////////////
void ClearSet_LED(const enLED led, const int bState)
{
	if( 0 == bState ) // clear
	{
		*pFlashA_PortB_Data &= (~led);
	}
	else if( 1 == bState ) // set
	{
		*pFlashA_PortB_Data |= led;
	}
	else // toggle the bits
	{
		*pFlashA_PortB_Data ^= led;
	}

}

//--------------------------------------------------------------------------//
// Function:	int GetPushButtons(void)
//																			//
// Description: Read the flags register
//				
//--------------------------------------------------------------------------//
int GetPushButtons(void)
{
	return (*pFIO_FLAG_D);	
}


//--------------------------------------------------------------------------//
// Function:	int TEST_PBLED(void)
//																			//
// Description: Test each push button
//				
// 0x04 == PB1
// 0x08 == PB2
// 0x10 == PB3
// 0x20 == PB4
//--------------------------------------------------------------------------//
int TEST_PBLED(void)
{
	Init_LEDs();
	Init_PushButtons();
	
	// clear all the LED's
	ClearSet_LED_Bank( (-1), 0x0000);
	
    
	int nPushed = 0;
	int iTemp = 0;	
	unsigned int nTimer = 1;//SetTimeout(0x400000);
	if( ((unsigned int)-1) != nTimer )
	{
		do{
			int iTemp = GetPushButtons();
			
			if( SW4_PF8 == (iTemp & SW4_PF8) )// PF8/SW4
			{	// PB1 was pressed.
				nPushed |= 0x04;
				ClearSet_LED_Bank( (LED4|LED5|LED6|LED7|LED8|LED9), 0x15 );
			}
			else if( SW5_PF9 == (iTemp & SW5_PF9) )// PF9/SW5
			{	// PB2 was pressed.
				nPushed |= 0x08;
				ClearSet_LED_Bank( (LED4|LED5|LED6|LED7|LED8|LED9), 0x540);
			}
			else if( SW6_PF10 == (iTemp & SW6_PF10) )// PF10/SW6
			{	// PB2 was pressed.
				nPushed |= 0x10;
				ClearSet_LED_Bank( (LED4|LED5|LED6|LED7|LED8|LED9), 0x111);
			}
			else if( SW7_PF11 == (iTemp & SW7_PF11) )// PF11/SW7
			{	// PB2 was pressed.
				nPushed |= 0x20;
				ClearSet_LED_Bank( (LED4|LED5|LED6|LED7|LED8|LED9), 0x444);
			}
		}while( 0x3C != nPushed); //while( (0x3C != nPushed) && (!IsTimedout(nTimer))  );
	}
	//ClearTimeout(nTimer);
	
	// either a timeout occured, or all the push buttons were not depressed.
	
	// disable  push button PB1, PB2, PB3, PB4
    *pFIO_INEN = 0x0000;

	return (0x3C == nPushed);
}



#ifdef _STANDALONE_
void main(void)
{
	sysreg_write(reg_SYSCFG, 0x32);		//Initialize System Configuration Register
	
	do{
		if( 0 == TEST_PBLED() )
		{
			asm("emuexcpt;");
		}
		
	}while(1);
	

}
#endif //_STANDALONE_



⌨️ 快捷键说明

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