cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Adventurer
Adventurer
410 Views
Registered: ‎09-30-2017

Interrupts from TimerCounter

Hello,

In my design, the interrupt line from the timer is connected to interrupt controller.

The timer is set for a RESET value + Down count + Auto reload

When it reaches 0, it should create an interrupt. 

I ran the attached code.

For some reason, I'm getting an interrupt upon timer start (which should not happen).

And then endless interrupts. 

My quesions:

1. If the timer is connected to interrupt handler, should I use: XTmrCtr_SetHandler ?  Why ?

2. Currently I'm connecting a handler to the interrupt controller with:

XIntc_Connect(&InterruptController, TMRCTR_INTERRUPT_ID, TmrCtr_FastHandler,(void *)0);

3. In the handler I'm calling to XIntc_Acknowledge(&InterruptController, TMRCTR_INTERRUPT_ID);

Should I do any further operations to clear the interrupt ?

Thank you in advance,

Zvika 

#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "xparameters.h"
#include "xil_exception.h"
#include "xtmrctr.h"
#include "xintc.h"

/************************** Constant Definitions *****************************/
#define TMRCTR_DEVICE_ID   XPAR_TMRCTR_0_DEVICE_ID
#define INTC_DEVICE_ID            XPAR_INTC_0_DEVICE_ID
#define TMRCTR_INTERRUPT_ID XPAR_INTC_0_TMRCTR_0_VEC_ID

#define TIMER_COUNTER_0    0

#define RESET_VALUE    0xF0000000
int IntCounter=0;
/************************** Function Prototypes ******************************/

int TmrCtrPolledExample(u16 DeviceId, u8 TmrCtrNumber);

static int TmrCtrSetupIntrSystem(XIntc* IntcInstancePtr,
                           XTmrCtr* InstancePtr,
                           u16 DeviceId,
                           u16 IntrId,
                           u8 TmrCtrNumber);

void TimerCounterHandler(void *CallBackRef, u8 TmrCtrNumber);

void TmrCtrDisableIntr(XIntc* IntcInstancePtr, u16 IntrId);

/************************** Variable Definitions *****************************/

XTmrCtr TimerCounter; /* The instance of the Tmrctr Device */
XIntc InterruptController;  /* The instance of the Interrupt Controller */

/****************************************************************************/
void TmrCtr_FastHandler(void *CallbackRef)
{

       XIntc_Acknowledge(&InterruptController, TMRCTR_INTERRUPT_ID);

       IntCounter++;


}
/*************************************************************************/



int main()
{
//   init_platform();
    int Status;

  //  u32 Value1;
    u32 Value2;
    XTmrCtr TmrCtrInstancePtr ;


    Status = XTmrCtr_Initialize(&TmrCtrInstancePtr, TIMER_COUNTER_0);
       if (Status != XST_SUCCESS) {
              return XST_FAILURE;
       }
    /*interupt*/
    Status = XIntc_Initialize(&InterruptController, INTC_DEVICE_ID);
       if (Status != XST_SUCCESS) {
              return XST_FAILURE;
       }

       Status = XIntc_Connect(&InterruptController, TMRCTR_INTERRUPT_ID, TmrCtr_FastHandler,(void *)0);
       if (Status != XST_SUCCESS) {
              return XST_FAILURE;
       }

    Status = XIntc_Start(&InterruptController, XIN_REAL_MODE);
       if (Status != XST_SUCCESS) {
              return XST_FAILURE;
       }

    XIntc_Enable(&InterruptController, TMRCTR_INTERRUPT_ID);

    Xil_ExceptionInit();

      Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler)XIntc_InterruptHandler,&InterruptController);

       Xil_ExceptionEnable();

    /*interupt*/

    XTmrCtr_SetHandler(&TmrCtrInstancePtr, TimerCounterHandler,NULL);

    XTmrCtr_SetOptions(&TmrCtrInstancePtr, TIMER_COUNTER_0,
              XTC_INT_MODE_OPTION | XTC_DOWN_COUNT_OPTION | XTC_AUTO_RELOAD_OPTION);

    XTmrCtr_SetResetValue(&TmrCtrInstancePtr,TIMER_COUNTER_0, RESET_VALUE);

    //XTmrCtr_Start(&TmrCtrInstancePtr, TIMER_COUNTER_0);

       while (1) {
              Value2 = XTmrCtr_GetValue(&TmrCtrInstancePtr, TIMER_COUNTER_0);

       }

       XTmrCtr_SetOptions(&TmrCtrInstancePtr, TIMER_COUNTER_0, 0);
    //cleanup_platform();
    //return 0;
}

/******************************************************************************/
void TimerCounterHandler(void *CallBackRef, u8 TmrCtrNumber)
{
       XTmrCtr *InstancePtr = (XTmrCtr *)CallBackRef;
}

 

 

0 Kudos
0 Replies