UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Visitor dohoonh
Visitor
512 Views
Registered: ‎07-24-2018

microblaze and axi timer with interrupt

Hi, I am making a timer with microblaze and interrupt in ISE 14.7 version.

 

The target is a PWM that generates an interrupt.

 

The PWM is working successfully.

 

However, there is a problem creating the interrupt.

 

I created an interrupt by referring to the code in the address below.

 

https://forums.xilinx.com/t5/Embedded-Development-Tools/MicroBlaze-Timer-Interrupt/td-p/345981

 

However, it does not work.

 

I tried debugging to see the difference between the code above and my code.

 

If you look at the specific parts of my code below

 

// Initialize the interrupt controller
status = XIntc_Initialize( gpIntc, INTC_DEVICE_ID );
if ( status == XST_SUCCESS) XGpio_WriteReg((GPIO_REG_BASEADDR), 0, 0xF);

 

In this section, the value of status is XST_STARTED instead of XST_SUCCESS.

 

I do not know what the cause is.

 

In the code below, I'm not sure if my code has a problem or it's a problem with XST_STARTED mentioned above.

 

Note that the values in #define TCSR0_up 0x6D6, #define TCSR1_up 0x6D6 mean up counter, PWM mode, and interrupt enable.

 

#include <stdio.h>
#include "platform.h"
#include "xparameters.h"
#include "xtmrctr.h"
#include "xintc.h"
#include "mb_interface.h"
#include "xtmrctr_l.h"
#include "xgpio_l.h"


#define TMRCTR_DEVICE_ID XPAR_AXI_TIMER_0_DEVICE_ID
#define TMRCTR TMRCTR_DEVICE_ID
#define TMRCTR_INTERRUPT_ID XPAR_MICROBLAZE_0_INTC_AXI_TIMER_0_INTERRUPT_INTR
#define INTC_DEVICE_ID XPAR_MICROBLAZE_0_INTC_DEVICE_ID

#define GPIO_REG_BASEADDR XPAR_AXI_GPIO_0_BASEADDR


XTmrCtr* gpTmrCtr; // Pointer to Timer Counter, used for general timing
XIntc* gpIntc; // Pointer to Interrupt Controller

void TimerCounterHandler(void* CallBackRef, u8 TmrCtrNumber);

#define XTC_TCSR_OFFSET 0 /**< Control/Status register */
#define XTC_TLR_OFFSET 4 /**< Load register */
#define XTC_TCR_OFFSET 8 /**< Timer counter register */

#define TLR0_up 0xB63
#define TLR1_up 0x16A
#define TCSR0_up 0x6D6
#define TCSR1_up 0x6D6

 

int main()
{


init_platform();

int status = XST_FAILURE;
XIntc intc;
gpIntc = &intc;

XTmrCtr tmrctr;
gpTmrCtr = &tmrctr;

// Initialize the interrupt controller
status = XIntc_Initialize( gpIntc, INTC_DEVICE_ID );
if ( status == XST_SUCCESS) XGpio_WriteReg((GPIO_REG_BASEADDR), 0, 0xF);

// Connect a device driver handler to call when an interrupt triggers for a device
XIntc_Connect( gpIntc, TMRCTR_INTERRUPT_ID,
(XInterruptHandler)XTmrCtr_InterruptHandler,
(void*)gpTmrCtr );

// Enable interrupt for the timer counter
XIntc_Enable( gpIntc, TMRCTR_INTERRUPT_ID );
// Start the interrupt controller
XIntc_Start( gpIntc, XIN_REAL_MODE );
// Set handler
XTmrCtr_SetHandler( gpTmrCtr, TimerCounterHandler, gpTmrCtr );

// Initialize the counter
XTmrCtr_Initialize( gpTmrCtr, 0 );
XTmrCtr_WriteReg(gpTmrCtr->BaseAddress, 0, XTC_TCSR_OFFSET, TCSR0_up);
XTmrCtr_WriteReg(gpTmrCtr->BaseAddress, 1, XTC_TCSR_OFFSET, TCSR1_up);
XTmrCtr_WriteReg(gpTmrCtr->BaseAddress, 0, XTC_TLR_OFFSET, TLR0_up);
XTmrCtr_WriteReg(gpTmrCtr->BaseAddress, 1, XTC_TLR_OFFSET, TLR1_up);
microblaze_enable_interrupts();

while(1){}

return 0;

}

void TimerCounterHandler(void* CallBackRef, u8 TmrCtrNumber)
{
XGpio_WriteReg((GPIO_REG_BASEADDR), 0, 0xF);
}

0 Kudos