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

📄 ledbutton_callback.c

📁 ADI公司blackfin DSP开发板BF533 EZ-KIT LITE附带的全部原代码
💻 C
字号:
/*********************************************************************************

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.  

$RCSfile: LEDButton_Callback.c,v $
$Revision: 1.1 $
$Date: 2007/03/28 17:55:36 $

Description:
			This is a little demo to show how to use the flag service for the 
			LEDs and push buttons.  
			
			On the ADSP-BF533 EZ-Kit, the push buttons on the EZ-Kit must be 
			enabled by having switches 1 through 4 turned on on the SW9 DIP switch
			on the board.  

			On the ADSP-BF537 EZ-Kit, the push buttons on the EZ-Kit must be 
			enabled by having switches 1 through 4 turned on on the SW5 DIP switch
			on the board.  

			On the ADSP-BF561 EZ-Kit, the push buttons on the EZ-Kit must be 
			enabled by having switches 1 through 4 turned on on the SW4 DIP switch
			on the board.  

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


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

Include files

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

#include "services\services.h"		// system services
#include "ezkitutilities.h"			// ezkit utilities

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

Globals

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

u32 timedelay = 250; //value in ms

u32 direction;			// direction of the LEDs 1 = Forward, 2 = Reverse

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

Static data

The LEDs and pushbuttons interface with the processor via the programmable
flags.  The EZ-Kit utilities utilize the flag service to control the 
LEDs and pushbuttons.  Because the demo uses interrupts for the 
pushbuttons, we need to give the flag service memory to control the 
interrupts, and the interrupt manager memory for secondary handlers.  Note
that if the flags were using separate IVG levels, we wouldn't need to 
provide the interrupt service with memory.  But because all the flag 
interrupts are ganged up on a single IVG, we need to supply memory for
the secondary handlers (note that one handler is installed as the primary
and the rest are secondary so we need 1 less secondary handler).  

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

// flag service
static u8 FlagServiceData[ADI_FLAG_CALLBACK_MEMORY * (EZ_NUM_BUTTONS + 1)];

// interrupt service
static u8 IntMgrData[ADI_INT_SECONDARY_MEMORY * (EZ_NUM_BUTTONS)];

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

Peripheral ID Macros

This program works on the EZ-Kits.  The macros
below are used to identify which EZ-Kit we're targeting.  Specifically, 
the FLAG_PERIPHERAL_ID macro is set to the peripheral ID to which the 
interrupt driven push buttons are mapped.  See the adi_int.h file
within the system services library (blackfin/include/services) for
more information on peripheral IDs.  

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

#if defined(__ADSP_EDINBURGH__)
#define FLAG_PERIPHERAL_ID	(ADI_INT_PFA)
#endif

#if defined(__ADSP_BRAEMAR__)
#define FLAG_PERIPHERAL_ID	(ADI_INT_PORTFG_A)
#endif

#if defined(__ADSP_TETON__)
#define FLAG_PERIPHERAL_ID	(ADI_INT_PF0_15_A)
#endif


/*********************************************************************
	Callback - Function that is called when callback is set

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

void static Callback(void *ClientHandle,u32  Event,void *pArg){

	u32 ButtonNum = (u32)pArg; 		// button that was pushed
	
	// Check to see what button is pressed and set the direction
	if (ButtonNum == ezButtonToFlag[EZ_FIRST_BUTTON])
		direction = 1;
			
	else if (ButtonNum == ezButtonToFlag[EZ_FIRST_BUTTON+1])
		direction = 2;

	//error case
	else
		ezTurnOnAllLEDs;
}

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

	Function:		main

	Description:	This function is main function of the demo.  Everything 
					is done in main to show exactly how to use the flag
					service.
					
					In the unlikely event we get an error somewhere, 
					this demo uses the ezErrorCheck function to light
					all the LEDs and spin in a loop.   

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

void main(void) {
	
	u32 ResponseCount;  		// number of things a service can control
	u32 ReturnValue;			// the return value from calling flag functions
	u32 currentLED;				// Current LED that is on
	u32 i;						// Loop Variable
								
	// configure ezkit
	ezInit(1);

	// initialize the Interrupt Manager
	ezErrorCheck(adi_int_Init(IntMgrData, sizeof(IntMgrData), &ResponseCount, NULL));
	
	// initialize the flag manager because the LEDs and buttons connect via flags
	ezErrorCheck(adi_flag_Init(FlagServiceData, sizeof(FlagServiceData), &ResponseCount, NULL));
	
	// configure push buttons as inputs for button 1
	adi_flag_Open(ezButtonToFlag[0]);
	adi_flag_SetDirection(ezButtonToFlag[0], ADI_FLAG_DIRECTION_INPUT);
	adi_flag_InstallCallback(ezButtonToFlag[0], FLAG_PERIPHERAL_ID, ADI_FLAG_TRIGGER_RISING_EDGE, TRUE, (void*)EZ_FIRST_BUTTON, NULL, Callback);
	
	// configure push buttons as inputs for button 2
	adi_flag_Open(ezButtonToFlag[1]);
	adi_flag_SetDirection(ezButtonToFlag[1], ADI_FLAG_DIRECTION_INPUT);
	adi_flag_InstallCallback(ezButtonToFlag[1], FLAG_PERIPHERAL_ID, ADI_FLAG_TRIGGER_RISING_EDGE, TRUE, (void*)(EZ_FIRST_BUTTON+1), NULL, Callback);
	
	// configure push buttons as inputs for button 3
	adi_flag_Open(ezButtonToFlag[2]);
	adi_flag_SetDirection(ezButtonToFlag[2], ADI_FLAG_DIRECTION_INPUT);
	
	// ADSP-BF533 specific info
	// initialize LEDS being used
#if defined(__ADSP_EDINBURGH__)
    for (i = EZ_FIRST_LED; i < EZ_NUM_LEDS; i++){
        ezInitLED(i);
    }
#endif
	
	// ADSP-BF537 & BF561 EZ-Kit specific info
	// configure all the LEDS on the ADSP-BF537 & BF561 EZ-Kit
#if defined(__ADSP_BRAEMAR__) || defined (__ADSP_TETON__)
 
	//open each flag and set the direction to an ouput
	for (i=EZ_FIRST_LED; i < EZ_LAST_LED +1; i++){
		adi_flag_Open(ezLEDToFlag[i]);
		adi_flag_SetDirection(ezLEDToFlag[i], ADI_FLAG_DIRECTION_OUTPUT);
	}
#endif
	
	//MAIN LOOP
	
	//intitalize current position
	currentLED = EZ_FIRST_LED;
	
	
	//setting direction to 0 causes nothing to happen until a push button is pressed
	direction = 0;
	while (1) {
		
		//once 1st push button is set the LEDS start moving to the right
		if (direction == 1){
			
			//Turn on the LED delay then turning it off and move on
			//
			//LEDS have to be turned on diffently for BF533EZKIT
#if defined(__ADSP_EDINBURGH__)
			ezToggleLED(currentLED);
			ezDelay(timedelay);
			ezToggleLED(currentLED);
#endif

#if defined(__ADSP_TETON__) || defined(__ADSP_BRAEMAR__)
			adi_flag_Toggle(ezLEDToFlag[currentLED]);
			ezDelay(timedelay);
			adi_flag_Toggle(ezLEDToFlag[currentLED]);
	
#endif

			//Once the LED reaches the last in the chain reset currentLED to the first LED
			if (currentLED == EZ_LAST_LED)
				currentLED = EZ_FIRST_LED;
			else{
				currentLED++;
			}
		}
		
		//once 1st push button is set the LEDS start moving to the left
		if (direction == 2){
			
			//Turn on the LED delay then turning it off and move on
			//
			//LEDS have to be turned on diffently for BF533EZKIT
#if defined(__ADSP_EDINBURGH__)
			ezToggleLED(currentLED);
			ezDelay(timedelay);
			ezToggleLED(currentLED);
#endif


#if defined(__ADSP_TETON__) || defined(__ADSP_BRAEMAR__)
			adi_flag_Toggle(ezLEDToFlag[currentLED]);
			ezDelay(timedelay);
			adi_flag_Toggle(ezLEDToFlag[currentLED]);
	
#endif
			//Once the LED reaches the first in the chain reset currentLED to the last LED
			if (currentLED == EZ_FIRST_LED){
				currentLED = EZ_LAST_LED;
			}
				else{
				currentLED--;
			}	
		}
		
		//check if button 3 is pressed and exit if it is pressed
		adi_flag_Sense(ezButtonToFlag[2],&ReturnValue);
		if (ReturnValue){
			break;	
		}
		
	// ENDLOOP
	}
	
	// remove callbacks for each push button
	adi_flag_RemoveCallback(ezButtonToFlag[0]);
	adi_flag_RemoveCallback(ezButtonToFlag[1]);
	
	
	// terminate the flag service
	adi_flag_Terminate();
	
	//terminate the interupt service
	adi_int_Terminate();
	
	// that's all folks!
}


⌨️ 快捷键说明

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