Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.
unsigned int timer_count = 10000000; /* initial timer period in OPBcycles ~= 0.3 sec */
unsigned int led_data = 0;
void timer_int_handler(void *baseaddr_p)
{
unsigned int csr;
/* Read timer 0 CSR to see if it requested the interrupt */
csr = XTmrCtr_mGetControlStatusReg(XPAR_OPB_TIMER_1_BASEADDR, 0);
if (csr & XTC_CSR_INT_OCCURED_MASK)
{
/* Increment led_count in a johnson-counter pattern */
led_data = led_data +1;
if(led_data > 16)
led_data = 0;
XGpio_mSetDataReg(XPAR_LEDS_BASEADDR, 1, led_data);
}
/* Clear the timer interrupt */
XTmrCtr_mSetControlStatusReg(XPAR_OPB_TIMER_1_BASEADDR, 0, csr);
}
/* Interrupt test routine */
void InterruptTest(void)
{
/* Enable MicroBlaze interrupts */
microblaze_enable_interrupts();
/* Start the interrupt controller */
XIntc_mMasterEnable(XPAR_OPB_INTC_0_BASEADDR);
/* Set the gpio for LEDs as output */
XGpio_mSetDataDirection(XPAR_LEDS_BASEADDR, 1, 0x00000000);
/* Set the number of cycles the timer counts before interrupting */
XTmrCtr_mSetLoadReg(XPAR_OPB_TIMER_1_BASEADDR, 0, timer_count);
/* Reset the timers, and clear interrupts */
XTmrCtr_mSetControlStatusReg(XPAR_OPB_TIMER_1_BASEADDR, 0,XTC_CSR_INT_OCCURED_MASK | XTC_CSR_LOAD_MASK );
/* Enable timer and UART interrupt requests in the interrupt
controller */
XIntc_mEnableIntr(XPAR_OPB_INTC_0_BASEADDR,XPAR_OPB_TIMER_1_INTERRUPT_MASK);
I attach the code needed to adjust interrupt routine in my own code(it's not timer but not important).
I add some comments for you, I hope it could help.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.