📄 intmgrtimerexample.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
*********************************************************************/
/*********************************************************************
Data Structures
*********************************************************************/
/*********************************************************************
Static data
*********************************************************************/
// storage for interrupt manager data
static u8 IntMgrData[(ADI_INT_SECONDARY_MEMORY * 2)];
/*********************************************************************
Static functions
*********************************************************************/
/*********************************************************************
Interrupt Service Routin for Timer 0.
*********************************************************************/
static ADI_INT_HANDLER(Timer0_ISR) {
// See if this is a timer 0 event, by calling a function to
// read corresponding bit (16) in the the SIC_ISR register
if (adi_int_SICInterruptAsserted(ADI_INT_TIMER0) == ADI_INT_RESULT_NOT_ASSERTED)
// This return value tells the interrupt manager to process the next
// ISR in the chain for this IVG, because we haven't yet serviced the
// peripheral that interrupted this time
return (ADI_INT_RESULT_NOT_PROCESSED);
// 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.
return (ADI_INT_RESULT_PROCESSED);
}
/*********************************************************************
Interrupt Service Routin for Timer 1.
*********************************************************************/
static ADI_INT_HANDLER(Timer1_ISR) {
// See if this is a timer 0 event, by calling a function to
// read corresponding bit (17) in the the SIC_ISR register
if (adi_int_SICInterruptAsserted(ADI_INT_TIMER1) == ADI_INT_RESULT_NOT_ASSERTED)
// This return value tells the interrupt manager to process the next
// ISR in the chain for this IVG, because we haven't yet serviced the
// peripheral that interrupted this time
return (ADI_INT_RESULT_NOT_PROCESSED);
// 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.
return (ADI_INT_RESULT_PROCESSED);
}
/*********************************************************************
Interrupt Service Routin for Timer 2.
*********************************************************************/
static ADI_INT_HANDLER(Timer2_ISR) {
// See if this is a timer 0 event, by calling a function to
// read corresponding bit (18) in the the SIC_ISR register
if (adi_int_SICInterruptAsserted(ADI_INT_TIMER2) == ADI_INT_RESULT_NOT_ASSERTED)
// This return value tells the interrupt manager to process the next
// ISR in the chain for this IVG, because we haven't yet serviced the
// peripheral that interrupted this time
return (ADI_INT_RESULT_NOT_PROCESSED);
// 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.
return (ADI_INT_RESULT_PROCESSED);
}
/****************************************************************************
Function: Init_Timers
Set up timers for PWM mode and enale 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;
void *pExitCriticalArg;
u32 i; //loop variable
// initialize the EZ-Kit
ezInit(1);
// initialize interrupt manager
ezErrorCheck(adi_int_Init(IntMgrData, sizeof(IntMgrData), &ResponseCount, NULL));
// initialize the Timer manager
ezErrorCheck(adi_tmr_Init(NULL));
// initialize the flag manager because the LEDs and buttons connect via flags
// Since callbacks are not being used memory does not to be given to the service
ezErrorCheck(adi_flag_Init(NULL, 0, &ResponseCount, NULL));
// initialize LEDS being used
for (i = EZ_FIRST_LED; i < EZ_NUM_LEDS; i++){
ezInitLED(i);
}
// By default,the three GP timers share IVG11
// hook the primary handler, timer 0
ezErrorCheck(adi_int_CECHook(11, Timer0_ISR, &Timer0_ISR, FALSE));
// the nesting flag is ignored after the first call to adi_int_CECHook
ezErrorCheck(adi_int_CECHook(11, Timer1_ISR, &Timer1_ISR, TRUE));
ezErrorCheck(adi_int_CECHook(11, Timer2_ISR, &Timer2_ISR, TRUE));
ezErrorCheck(adi_int_SICEnable(ADI_INT_TIMER0));
ezErrorCheck(adi_int_SICEnable(ADI_INT_TIMER1));
ezErrorCheck(adi_int_SICEnable(ADI_INT_TIMER2));
InitTimers();
while (1) {
}
// return
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -