cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
bahec06
Observer
Observer
237 Views
Registered: ‎07-20-2015

Microblaze timer interrupt not working

Hi all. I have a simple processor system on KC-705 board with Microblaze, AXI Timer, AXI GPIO and AXI Interrupt Controler. Here is a block diagram of my system:

block_diagram.PNG

Here is a memory map for the system:

memory_map.PNG

Now i want to create a simple project with LED blinking at timer interrupt events. Here is my source code for Microblaze:

#include "xparameters.h"
#include "xenv_standalone.h"
#include "xil_exception.h"
#include "mb_interface.h"
#include "xtmrctr_l.h"
#include "xgpio.h"
#include "xtmrctr.h"
#include "xintc.h"

#define TMR_FIRST_CHANNEL 	0
#define TMR_SECOND_CHANNEL 	1

#define GP_TMR_RESET_VALUE 0x00FFFFFF

/////////////////////////////////////////////////////////////
////////////////////////Instances////////////////////////////
XGpio gpio_led;
XTmrCtr gp_tmr;
XIntc intc;
/////////////////////////////////////////////////////////////

static void GP_TimerCounterHandler(void *CallBackRef, u8 TmrCtrNumber);
static void TmrCtr_FastHandler(void);
static int gp_tmr_init(XTmrCtr * InstancePtr, u32 gp_tmr_id);
/////////////////////////////////////////////////////////////


void GP_TimerCounterHandler(void *CallBackRef, u8 TmrCtrNumber)
{
	static u32 led_state = (u32)(0x00000000);

	if(led_state == 0) {
		led_state = (u32)(0x00000001);
	}
	else {
		led_state = (u32)(0x00000000);
	}

	XGpio_DiscreteWrite(&gpio_led, 1, led_state);

	//xil_printf("led_state is %d\n\r", led_state);
}

void TmrCtr_FastHandler(void)
{
	/* Call the TmrCtr Interrupt handler */
	XTmrCtr_InterruptHandler(&gp_tmr);
	XIntc_Acknowledge(&intc, 0);
}

int gp_tmr_init(XTmrCtr * InstancePtr, u32 gp_tmr_id) {
	int status = XST_SUCCESS;

	status = XTmrCtr_Initialize(InstancePtr, gp_tmr_id);
	if (status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	//Self-test of the GP Timer
	status = XTmrCtr_SelfTest(InstancePtr, TMR_FIRST_CHANNEL);
	if (status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	return status;
}

int main() {
	int Status = XST_SUCCESS;
	//xil_printf("FCsim start\r\n");

	//xil_printf("**Periphery initialization start\n\r");
	//TODO : Make init fuctions for all instances

	//////////////////////GPIO Led Initialization
	Status = XGpio_Initialize(&gpio_led, XPAR_AXI_GPIO_0_DEVICE_ID);
	if (Status != XST_SUCCESS) {
		//xil_printf("--   gpio_led_init() FAIL\n\r");
		return 1;
	}

	//////////////////////GPIO Timer Initialization
	Status = gp_tmr_init(&gp_tmr, XPAR_AXI_TIMER_0_DEVICE_ID);
	if (Status != XST_SUCCESS) {
		//xil_printf("--   gp_tmr_init() FAIL\n\r");
		return 1;
	}

	//////////////////////Initialize interrupt controller
	Status = XIntc_Initialize(&intc, XPAR_INTC_0_DEVICE_ID);
	if (Status != XST_SUCCESS) {
		//xil_printf("--   intc_init() FAIL\n\r");
		return 1;
	}

	//Perform a self-test to ensure that the hardware was built correctly
	Status = XIntc_SelfTest(&intc);
	if (Status != XST_SUCCESS) {
		//xil_printf("--   intc_self_test() FAIL\n\r");
		return 1;
	}

	//xil_printf("**Periphery initialization done\n\r");

	///////////////////////Connect Fast Interrupt Handler for GP Timer
	//xil_printf("**Connect fast interrupt handler for GP Timer\n\r");
	Status = XIntc_ConnectFastHandler(&intc, XPAR_INTC_0_TMRCTR_0_VEC_ID, (XFastInterruptHandler)TmrCtr_FastHandler);
	if (Status != XST_SUCCESS) {
		//xil_printf("--   connect gp_tmr Fast Interrupt Handler FAIL\n\r");
		return 1;
	}

	//////////////Start Interrupt Controller
	//xil_printf("**Start Interrupt Controller\n\r");
	Status = XIntc_Start(&intc, XIN_REAL_MODE);
	if (Status != XST_SUCCESS) {
		//xil_printf("--   start interrupt controller FAIL\n\r");
		return 1;
	}

	//Enable interrupt from GP timer
	//xil_printf("**Enable interrupt from GP timer\n\r");
	XIntc_Enable(&intc, XPAR_INTC_0_TMRCTR_0_VEC_ID);

	//xil_printf("**Initialize the exception table\n\r");
	//Initialize the exception table
	Xil_ExceptionInit();
	//Register the interrupt controller handler with the exception table
	Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler) XIntc_InterruptHandler, &intc);

	//Setup GP Timer and Start it
	//xil_printf("**Setup GP Timer and Start it\n\r");
	XTmrCtr_SetHandler(&gp_tmr, GP_TimerCounterHandler, &gp_tmr);
	XTmrCtr_SetOptions(&gp_tmr, TMR_FIRST_CHANNEL, XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION | XTC_DOWN_COUNT_OPTION);
	XTmrCtr_SetResetValue(&gp_tmr, TMR_FIRST_CHANNEL, GP_TMR_RESET_VALUE);
	XTmrCtr_Start(&gp_tmr, TMR_FIRST_CHANNEL);

	//Microblaze enable exceptions and interrupts
	//xil_printf("**Microblaze enable exceptions and interrupts\n\r");
	Xil_ExceptionEnable();

	//xil_printf("**Start infinite loop\n\r");
	while(1) {

	}

	return 0;
}

I see that the function GP_TimerCounterHandler executes only once, so the LED is always on. In the debug mode i see that AXI Timer TCR0 register decrements and all bits of TCSR0 are valid. But ISR and IPR registers of AXI Interrupt Controllers are always at 1 after first interrupt. Fast interrupt is enabled in hardware, so this is not the reason. Can anyone help me please? What is the problem? Version of Vivado and SDK are 2016.4

Tags (2)
0 Kudos
Reply
1 Reply
bahec06
Observer
Observer
126 Views
Registered: ‎07-20-2015

No ideas? Help, please.

0 Kudos
Reply