?? prioritycallback.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: PriorityCallback.c,v $
$Revision: 1.1 $
$Date: 2007/03/28 17:55:35 $
*********************************************************************
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)
{
switch( (int)ClientHandle ) {
// The high priority callback should happen first, then the medium priority callback,
// then the low priority callback. This means lower priority callbacks can turn off
// the LED turned on by the higher priority callback. So only the third LED should
// remain on.
case 5:
// This is the low priority callback
ezTurnOffLED(EZ_FIRST_LED+1); // turn off medium priority LED
ezTurnOnLED(EZ_FIRST_LED+2); // turn on an LED
ezToggleLED(EZ_FIRST_LED+5); // toggle an LED
break;
case 6:
// This is the high priority callback
ezTurnOnLED(EZ_FIRST_LED); // turn on an LED
ezToggleLED(EZ_FIRST_LED+3); // toggle an LED
break;
case 7:
// This is the medium priority callback
ezTurnOffLED(EZ_FIRST_LED); // turn off high priority LED
ezTurnOnLED(EZ_FIRST_LED+1); // turn on an LED
ezToggleLED(EZ_FIRST_LED+4); // toggle an LED
break;
default:
ezErrorCheck(1); // we should never be here
break;
}
}
/*********************************************************************
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 low priority deferred callback with ClientArg=100
adi_dcb_Post(
Callback_Handle, // The handle of the required queue server
100, // The software priority of the entry (low number == high priority)
CallbackRoutine, // The address of the callback function
(void *)5, // A number for the callback routine to know which one this is
0, // The value of the second argument to the callback function
(void *) 0); // The value of the third argument to the callback function
// Post a high priority deferred callback
adi_dcb_Post(
Callback_Handle, // The handle of the required queue server
1, // The software priority of the entry (low number == high priority)
CallbackRoutine, // The address of the callback function
(void *)6, // A number for the callback routine to know which one this is
0, // The value of the second argument to the callback function
(void *) 0); // The value of the third argument to the callback function
// Post a medium priority deferred callback
adi_dcb_Post(
Callback_Handle, // The handle of the required queue server
2, // The software priority of the entry (low number == high priority)
CallbackRoutine, // The address of the callback function
(void *)7, // A number for the callback routine to know which one this is
0, // The value of the second argument to the callback function
(void *) 0); // The value of the third argument to the callback function
return (ADI_INT_RESULT_PROCESSED);
}
/****************************************************************************
Function: Init
Do all initialization
******************************************************************************/
void Init(void)
{
u32 i; //loop variable
//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_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 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_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) {
u32 ResponseCount;
void *pExitCriticalArg;
Init();
//Run forever
while (1) {
}
// return
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -