📄 multiqcallback.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: MultiQCallback.c,v $
$Revision: 1.1 $
$Date: 2007/03/28 17:55:34 $
*********************************************************************
Include files
*********************************************************************/
#include <services/services.h>
#include "ezkitutilities.h"
/*********************************************************************
Enumerations and defines
*********************************************************************/
#define QUEUE_SIZE 10
// Interrupts to use for deferred callbacks (separate from the timer interrupts)
#define INTERRUPT_FOR_CALLBACK0 11
#define INTERRUPT_FOR_CALLBACK1 10
#define INTERRUPT_FOR_TIMER0 9
#define INTERRUPT_FOR_TIMER1 8
/*********************************************************************
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_Handle0;
static ADI_DCB_HANDLE Callback_Handle1;
static u8 Callback_Manager_Storage[ADI_DCB_QUEUE_SIZE * 2];
static u8 Callback_Queue0[ADI_DCB_ENTRY_SIZE * QUEUE_SIZE];
static u8 Callback_Queue1[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 CallbackRoutine0(
void *ClientHandle,
u32 Event,
void *pArg)
{
ezToggleLED(EZ_FIRST_LED);
}
static void CallbackRoutine1(
void *ClientHandle,
u32 Event,
void *pArg)
{
ezToggleLED(EZ_FIRST_LED+2);
}
/*********************************************************************
Static functions
*********************************************************************/
static ADI_INT_HANDLER(TimerInterruptHandler0) {
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 the deferred callback
adi_dcb_Post(
Callback_Handle0, // The handle of the required queue server
1, // The software priority of the entry
CallbackRoutine0, // The address of the callback function
ClientArg, // just pass along our client argument for lack of anything better
1234, // The value of the second argument to the callback function
(void *) 1111); // The value of the third argument to the callback function
ezToggleLED(EZ_FIRST_LED+1);
return (ADI_INT_RESULT_PROCESSED);
}
static ADI_INT_HANDLER(TimerInterruptHandler1) {
u32 i;
// Check if this has our client argument
i = (u32) ClientArg;
if( i != 4321 ) {
return (ADI_INT_RESULT_NOT_PROCESSED);
}
// signal that we got the interrupt
ezErrorCheck( adi_tmr_GPControl(ADI_TMR_GP_TIMER_1, ADI_TMR_GP_CMD_CLEAR_INTERRUPT, 0));
// Post the deferred callback
adi_dcb_Post(
Callback_Handle1, // The handle of the required queue server
1, // The software priority of the entry
CallbackRoutine1, // The address of the callback function
ClientArg, // just pass along our client argument for lack of anything better
4321, // The value of the second argument to the callback function
(void *) 1111); // The value of the third argument to the callback function
ezToggleLED(EZ_FIRST_LED+3);
return (ADI_INT_RESULT_PROCESSED);
}
/****************************************************************************
Function: Init
Do all initialization
******************************************************************************/
void Init(void)
{
u32 i; //loop variable
//Setting up command table for Timer0
ADI_TMR_GP_CMD_VALUE_PAIR TimerConfigurationTable0 [] = {
{ 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 },
};
//Setting up command table for Timer1, use different time values
ADI_TMR_GP_CMD_VALUE_PAIR TimerConfigurationTable1 [] = {
{ 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 *)0x00200000 },
{ ADI_TMR_GP_CMD_ENABLE_TIMER, (void *)0x01 },
{ ADI_TMR_GP_CMD_END, NULL },
};
u32 ResponseCount;
// 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 interrupts to use with the timers with 1234 and 4321 as the client arguments.
ezErrorCheck( adi_int_CECHook(INTERRUPT_FOR_TIMER0, TimerInterruptHandler0, (void *)1234, FALSE));
ezErrorCheck( adi_int_CECHook(INTERRUPT_FOR_TIMER1, TimerInterruptHandler1, (void *)4321, FALSE));
// set the GP timers to use those interrupts
ezErrorCheck( adi_int_SICSetIVG(ADI_INT_TIMER0, INTERRUPT_FOR_TIMER0));
ezErrorCheck( adi_int_SICSetIVG(ADI_INT_TIMER1, INTERRUPT_FOR_TIMER1));
// enable the GP timer interrupts
ezErrorCheck( adi_int_SICEnable(ADI_INT_TIMER0));
ezErrorCheck( adi_int_SICEnable(ADI_INT_TIMER1));
//Create two deferred callback queues, give them the storage for the queue, and receive the Handle for each queue
ezErrorCheck( adi_dcb_Open(INTERRUPT_FOR_CALLBACK0, Callback_Queue0, sizeof(Callback_Queue0), &ResponseCount, &Callback_Handle0));
ezErrorCheck( adi_dcb_Open(INTERRUPT_FOR_CALLBACK1, Callback_Queue1, sizeof(Callback_Queue1), &ResponseCount, &Callback_Handle1));
//Open Timers for access
ezErrorCheck( adi_tmr_Open(ADI_TMR_GP_TIMER_0));
ezErrorCheck( adi_tmr_Open(ADI_TMR_GP_TIMER_1));
//Program timers with a table, this enables the timers
ezErrorCheck( adi_tmr_GPControl(ADI_TMR_GP_TIMER_0, ADI_TMR_GP_CMD_TABLE, TimerConfigurationTable0));
ezErrorCheck( adi_tmr_GPControl(ADI_TMR_GP_TIMER_1, ADI_TMR_GP_CMD_TABLE, TimerConfigurationTable1));
//Initialize all LEDS and Buttons
for (i = EZ_FIRST_LED; i < EZ_NUM_LEDS; i++){
ezInitLED(i);
}
}
/*********************************************************************
*
* Function: main
*
*********************************************************************/
void main(void) {
u32 ResponseCount;
void *pExitCriticalArg;
Init();
//Run forever
while (1) {
}
// return
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -