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

📄 flushcallback.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.  

$RCSfile: FlushCallback.c,v $
$Revision: 1.1 $
$Date: 2007/03/28 17:55:34 $
***********************************************************************************

Please refer to the 'readme.txt' file for a description of the example.


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

Include files

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

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

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

Enumerations and defines

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

#define QUEUE_SIZE		10

// Interrupt to use for deferred callbacks (separate from the timer interrupts)
#define INTERRUPT_FOR_CALLBACK	12

#define INTERRUPT_FOR_TIMER		11


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

Data Structures 

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

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

Static data

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

// no need for interrupt manager storage because we aren't using 2ndary interrupts

// storage for callback manager (only used for deferred callbacks)
static ADI_DCB_HANDLE	Callback_Handle;
static u8				Callback_Manager_Storage[ADI_DCB_QUEUE_SIZE];
static u8				Callback_Queue[ADI_DCB_ENTRY_SIZE * QUEUE_SIZE];


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

 Callback functions

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

//
// This is called by the DCB service based on the posted callback in the
// interrupt handler above.
//
static void CallbackRoutine(
	void *ClientHandle,
	u32  Event,
	void *pArg)
{
	ezCycleLEDs();
}


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

Static functions

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

static ADI_INT_HANDLER(TimerInterruptHandler) {
	u32	i;
		
	// Check if this has our client argument
	i = (u32) ClientArg;
	if( i != 1234 ) {
		return (ADI_INT_RESULT_NOT_PROCESSED);
	}

	// signal that we got the interrupt
	ezErrorCheck( adi_tmr_GPControl(ADI_TMR_GP_TIMER_0, ADI_TMR_GP_CMD_CLEAR_INTERRUPT, 0));
	
	// Post a deferred callback
	adi_dcb_Post(
		Callback_Handle,	// The handle of the required queue server
		1,					// The software priority of the entry
		CallbackRoutine,	// The address of the callback function
		(void *) 0,			// Unused client argument
		0,					// Unused client argument
		(void *) 0);		// Unused client argument

		
	// When the user presses the first button, flush all items out of the callback queue
	if( ezIsButtonPushed(EZ_FIRST_BUTTON)) {
		adi_dcb_Control(Callback_Handle, ADI_DCB_CMD_FLUSH_QUEUE, 0);
		ezClearButton(EZ_FIRST_BUTTON);
	}
		
	return (ADI_INT_RESULT_PROCESSED);
}


/****************************************************************************
  Function:	Init
				
  Do all initialization
******************************************************************************/

void Init(void)
{
    u32 i; //loop variable
    u32 ResponseCount;
	
	//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 *)0x04000000		},
		{ ADI_TMR_GP_CMD_SET_WIDTH, 				(void *)0x00200000		},
		{ ADI_TMR_GP_CMD_ENABLE_TIMER,				(void *)0x01			},
		{ ADI_TMR_GP_CMD_END,						NULL					}, 
	};
	
	// initialize the EZ-Kit
	ezInit(1);	
	
	// initialize interrupt manager, no memory is needed since we don't use 2ndary interrupts
	ezErrorCheck(adi_int_Init( (void *)NULL, 0, &ResponseCount, NULL));
	
	// initialize callback manager and give it the storage area
	ezErrorCheck( adi_dcb_Init(Callback_Manager_Storage, sizeof(Callback_Manager_Storage), &ResponseCount, NULL));
	
	//Initialize the flag service, memory is not passed because callbacks are not being used
	ezErrorCheck(adi_flag_Init(NULL, 0, &ResponseCount, NULL));
	
	// initialize the Timer manager
	ezErrorCheck(adi_tmr_Init(NULL));
	
	// hook an interrupt to use with the timer with 1234 as the client argument.
	ezErrorCheck( adi_int_CECHook(INTERRUPT_FOR_TIMER, TimerInterruptHandler, (void *)1234, FALSE));
	
	// set the GP timer to use that interrupt
	ezErrorCheck( adi_int_SICSetIVG(ADI_INT_TIMER0, INTERRUPT_FOR_TIMER));
	
	// enable the GP timer interrupt
	ezErrorCheck( adi_int_SICEnable(ADI_INT_TIMER0));

	//Create a deferred callback queue, give it the storage for the queue, and receive the Handle for the queue
	ezErrorCheck( adi_dcb_Open(INTERRUPT_FOR_CALLBACK, Callback_Queue, sizeof(Callback_Queue), &ResponseCount, &Callback_Handle));	
	
	//Initialize all LEDS and Buttons
	for (i = EZ_FIRST_BUTTON; i < EZ_NUM_BUTTONS; i++){
        ezInitButton(i);
	}
	
	for (i = EZ_FIRST_LED; i < EZ_NUM_LEDS; i++){
        ezInitLED(i);
	}
	
	//Open Timer 0 for access
	ezErrorCheck( adi_tmr_Open(ADI_TMR_GP_TIMER_0));
	
	//Program timer 0 with Timer 0 table, this enables the timer
	ezErrorCheck( adi_tmr_GPControl(ADI_TMR_GP_TIMER_0, ADI_TMR_GP_CMD_TABLE, Timer0ConfigurationTable));
			
}
 
	
/*********************************************************************
*
*	Function:	main
*
*********************************************************************/

void main(void) {
	
	Init();
	
	//Run forever
	while (1) {
		
	}
		
// return
}

⌨️ 快捷键说明

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