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

📄 intmgrsetivgexample.c

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

Copyright(c) 2004 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.  

***********************************************************************************

Please refer to the 'readme.txt' file for a description of the Interrupt Manager Examples.

*********************************************************************

Include files

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

#include <services/services.h>
#include "ezkitutilities.h"

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

Enumerations and defines

*********************************************************************/
#define HOOK  1
#define UNHOOK  0


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

Data Structures 

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



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

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


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

Static functions

*********************************************************************/
// flag service memory for 1 callback
static u8 FlagServiceData[ADI_FLAG_CALLBACK_MEMORY * 1];
/********************************************************************/

volatile unsigned int HookFlag, ChangeState;

/*********************************************************************
 Timer0_Handle

 Handler for Timer 0.

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

static ADI_INT_HANDLER(Timer0_Handle) {
	
	// clear timer 0 interupt
	adi_tmr_GPControl(ADI_TMR_GP_TIMER_0, ADI_TMR_GP_CMD_CLEAR_INTERRUPT, NULL);

	// toggle the specified LED
	ezToggleLED(EZ_FIRST_LED);

	// This return value tells the interrupt manager not to process 
	// anymore ISR's for this IVG, because we already serviced the 
	// peripheral that had interrupted this time.
	// For this example, however, there is only one ISR per IVG.
	return (ADI_INT_RESULT_PROCESSED);
	
}
 

/*********************************************************************
 Timer1_Handle
 
 Handler for Timer 1

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

static ADI_INT_HANDLER(Timer1_Handle) {
	
	// clear timer 1 interupt
	adi_tmr_GPControl(ADI_TMR_GP_TIMER_1, ADI_TMR_GP_CMD_CLEAR_INTERRUPT, NULL);
		
	// toggle the specified LED

	ezToggleLED(EZ_FIRST_LED+1);
	
	
	// This return value tells the interrupt manager not to process 
	// anymore ISR's for this IVG, because we already serviced the 
	// peripheral that had interrupted this time.
	// For this example, however, there is only one ISR per IVG.
	return (ADI_INT_RESULT_PROCESSED);

}
 

/*********************************************************************
 Timer2_Handle

 Handler for Timer 2

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

static ADI_INT_HANDLER(Timer2_Handle) {
 	
	// clear timer 2 interupt
	adi_tmr_GPControl(ADI_TMR_GP_TIMER_2, ADI_TMR_GP_CMD_CLEAR_INTERRUPT, NULL);
		
	// toggle the specified LED
	ezToggleLED(EZ_FIRST_LED+2);
	
	
	// This return value tells the interrupt manager not to process 
	// anymore ISR's for this IVG, because we already serviced the 
	// peripheral that had interrupted this time.
	// For this example, however, there is only one ISR per IVG.
	return (ADI_INT_RESULT_PROCESSED);
}
  

/*********************************************************************
 Flag Callback					

 This Callback occurs every time a button 1 is pressed
		
*********************************************************************/

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

	// Clear flag for Button 0
	adi_flag_Clear(ezButtonToFlag[0]);
	ChangeState = TRUE;
	
	if( HookFlag == UNHOOK)
	// Tells the App whether to hook or unhook the Timer ISR's
		HookFlag = HOOK;	
	else
		HookFlag = UNHOOK;	
	
}

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

 InitFlags
																		
 This function configures PF8 as input for edge sensitive interrupt 
 generation. The switch connected to PF8 (SW7) can be used to send a 
 signal to the application.

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

void InitFlags(void)
{
    u32 i; //loop variable

	// initialize LEDS being used
    for (i = EZ_FIRST_LED; i < EZ_NUM_LEDS; i++){
        ezInitLED(i);
    }

	//open flag for button 1
	adi_flag_Open(ezButtonToFlag[0]);
	
	//set the direction of the flag as an input
	adi_flag_SetDirection(ezButtonToFlag[0], ADI_FLAG_DIRECTION_INPUT);
	
	//set the trigger event to rising edge
	adi_flag_SetTrigger(ezButtonToFlag[0],ADI_FLAG_TRIGGER_LEVEL_LOW);

}


/****************************************************************************
  InitTimers	
				
  Set up timers for PWM mode and enables them.
******************************************************************************/

void InitTimers(void)
{
	//Setting up command table for Timer 0
	ADI_TMR_GP_CMD_VALUE_PAIR Timer0ConfigurationTable [] = {
		{ ADI_TMR_GP_CMD_SET_TIMER_MODE,			(void *)0x01			},
		{ ADI_TMR_GP_CMD_SET_COUNT_METHOD,			(void *)TRUE			},
		{ ADI_TMR_GP_CMD_SET_INTERRUPT_ENABLE,		(void *)TRUE			},
		{ ADI_TMR_GP_CMD_SET_OUTPUT_PAD_DISABLE,	(void *)TRUE			},
		{ ADI_TMR_GP_CMD_SET_PERIOD,				(void *)0x08000000		},
		{ ADI_TMR_GP_CMD_SET_WIDTH, 				(void *)0x00400000		},
		{ ADI_TMR_GP_CMD_END,						NULL					}, 
	};
	
	//Setting up command table for Timer 1
	ADI_TMR_GP_CMD_VALUE_PAIR Timer1ConfigurationTable [] = {
		{ ADI_TMR_GP_CMD_SET_TIMER_MODE,			(void *)0x01			},
		{ ADI_TMR_GP_CMD_SET_COUNT_METHOD,			(void *)TRUE			},
		{ ADI_TMR_GP_CMD_SET_INTERRUPT_ENABLE,		(void *)TRUE			},
		{ ADI_TMR_GP_CMD_SET_OUTPUT_PAD_DISABLE,	(void *)TRUE			},
		{ ADI_TMR_GP_CMD_SET_PERIOD,				(void *)0x04000000		},
		{ ADI_TMR_GP_CMD_SET_WIDTH, 				(void *)0x00400000		},
		{ ADI_TMR_GP_CMD_END,						NULL					}, 
	};
		
	//Setting up command table for Timer 2
	ADI_TMR_GP_CMD_VALUE_PAIR Timer2ConfigurationTable [] = {
		{ ADI_TMR_GP_CMD_SET_TIMER_MODE,			(void *)0x01			},
		{ ADI_TMR_GP_CMD_SET_COUNT_METHOD,			(void *)TRUE			},
		{ ADI_TMR_GP_CMD_SET_INTERRUPT_ENABLE,		(void *)TRUE			},
		{ ADI_TMR_GP_CMD_SET_OUTPUT_PAD_DISABLE,	(void *)TRUE			},
		{ ADI_TMR_GP_CMD_SET_PERIOD,				(void *)0x02000000		},
		{ ADI_TMR_GP_CMD_SET_WIDTH, 				(void *)0x00400000 		},
		{ ADI_TMR_GP_CMD_END,						NULL					}, 
	};
	
	//Open Timer 0 for access
	adi_tmr_Open(ADI_TMR_GP_TIMER_0);
	
	//Program timer 0 with Timer 0 table
	adi_tmr_GPControl(ADI_TMR_GP_TIMER_0, ADI_TMR_GP_CMD_TABLE, Timer0ConfigurationTable);
	
	//Open Timer 1 for access
	adi_tmr_Open(ADI_TMR_GP_TIMER_1);
	
	//Program timer 1 with Timer 1 table
	adi_tmr_GPControl(ADI_TMR_GP_TIMER_1, ADI_TMR_GP_CMD_TABLE, Timer1ConfigurationTable);
	
	//Open Timer 2 for access
	adi_tmr_Open(ADI_TMR_GP_TIMER_2);
	
	//Program timer 2 with Timer 2 table
	adi_tmr_GPControl(ADI_TMR_GP_TIMER_2, ADI_TMR_GP_CMD_TABLE, Timer2ConfigurationTable);

	// enable timers 0, 1, 2		
	adi_tmr_GPGroupEnable(ADI_TMR_GP_TIMER_0 | ADI_TMR_GP_TIMER_1 | ADI_TMR_GP_TIMER_2,TRUE);
	
}


/*********************************************************************
*
*	Function:	main
*
*********************************************************************/

void main(void) {

	u32 ResponseCount;
	u32 change = 0;
	void *pExitCriticalArg;
	
	// initialize the EZ-Kit
	ezInit(1);
	
	// start out by hooking the ISR's
	HookFlag = HOOK;
	ChangeState = TRUE;
	
	
	// initialize interrupt manager, no secondary handlers.
	ezErrorCheck(adi_int_Init(NULL, 0, &ResponseCount, NULL));	
	

	// initialize the flag manager because the LEDs and buttons connect via flags
	ezErrorCheck(adi_flag_Init(FlagServiceData, sizeof(FlagServiceData), &ResponseCount, NULL));
	
	// initialize the Timer manager
	ezErrorCheck(adi_tmr_Init(NULL));
	
	InitFlags();
	
	//Enable callbacks on flag with enough memory for 1 callback
 	ezErrorCheck(adi_flag_InstallCallback(ezButtonToFlag[0], FLAG_PERIPHERAL_ID , ADI_FLAG_TRIGGER_FALLING_EDGE, FALSE, (void*)(0x12345678), NULL, Callback)); 
	
	// change the timer ISRs so they map to separate IVG levels	
	adi_int_SICSetIVG(ADI_INT_TIMER0,11);
	adi_int_SICSetIVG(ADI_INT_TIMER1,10);				
 	adi_int_SICSetIVG(ADI_INT_TIMER2,9);
 	
	while (1) {
			
		if( ChangeState && (HookFlag == UNHOOK )) {	
			
			ChangeState = FALSE;
			
			// Disable the timers before unhooking the timer interrupts	
			adi_tmr_GPGroupEnable(ADI_TMR_GP_TIMER_0 | ADI_TMR_GP_TIMER_1 | ADI_TMR_GP_TIMER_2,FALSE);
				
			// unhook timer ISRs
			ezErrorCheck(adi_int_SICDisable(ADI_INT_TIMER0));
			ezErrorCheck(adi_int_SICDisable(ADI_INT_TIMER1));
			ezErrorCheck(adi_int_SICDisable(ADI_INT_TIMER2));
			
			ezErrorCheck(adi_int_CECUnhook(11, Timer0_Handle, (void*)0x12345678));
			ezErrorCheck(adi_int_CECUnhook(10, Timer1_Handle, (void*)0x87654321));
			ezErrorCheck(adi_int_CECUnhook(9, Timer2_Handle, (void*)0x12348765));
		}
		
		// If we are going from the unhooked to the hooked state
		if( ChangeState && (HookFlag == HOOK )) {	
	
			ChangeState = FALSE;
			
			// hook the handlers for timers 0, 1, 2
			ezErrorCheck(adi_int_CECHook(11, Timer0_Handle, (void*)0x12345678, FALSE));
			ezErrorCheck(adi_int_CECHook(10, Timer1_Handle, (void*)0x87654321, FALSE));
			ezErrorCheck(adi_int_CECHook(9,  Timer2_Handle, (void*)0x12348765, FALSE));	

			ezErrorCheck(adi_int_SICEnable(ADI_INT_TIMER0));
			ezErrorCheck(adi_int_SICEnable(ADI_INT_TIMER1));
			ezErrorCheck(adi_int_SICEnable(ADI_INT_TIMER2));

			InitTimers();
		}
	}	
// return
}

⌨️ 快捷键说明

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