How to add a FlexIO timer Interrupt Service Routine?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to add a FlexIO timer Interrupt Service Routine?

Jump to solution
1,539 Views
imxrtuser
Senior Contributor I

Hello!

I am using two FlexIO Timers in a chain on the RT1020. Timer 0 is used as trigger for Timer 1 and Timer 1 generates an interrupt.

I followed the flexio spi driver and added two functions and some typedefs/structs. The first function is a TimerHandleIRQ (->analogous to FLEXIO_SPI_SlaveTransferHandleIRQ) and the second one creates a timer handle (->FLEXIO_SPI_MasterTransferCreateHandle). The IRQ function and the handle get registered with FLEXIO_RegisterHandleIRQ() of fsl_flexio.c.

typedef struct _flexio_timer_type
{
    FLEXIO_Type *flexioBase; /*!< FlexIO base pointer. */
} FLEXIO_TIMER_Type;

/*! @brief  typedef for flexio_timer_handle_t in advance. */
typedef struct _flexio_timer_handle flexio_timer_handle_t;

/*! @brief Define FlexIO timer handle structure. */
/*! @brief FlexIO timer callback if timer interrupt is pending*/
typedef void (*flexio_timer_callback_t)(FLEXIO_TIMER_Type *base,
                                        flexio_timer_handle_t *handle,
                                        status_t status);
// flexio timer handle
struct _flexio_timer_handle
{
    flexio_timer_callback_t callback; /*!< FlexIO timer callback. */
};

// user call back function, if togglePin == 1 the user led gets toggled in main
void FLEXIO_TimerUserCallback(FLEXIO_TIMER_Type *base,
                                   flexio_timer_handle_t *handle,
                                   status_t status)
{
    if ((status & 0x2) == 0x2) // Timer 1 interrupt
    {
      togglePin = 1;
    }
}


// create the flexio timer handle and register it
status_t FLEXIO_TimerCreateHandle(FLEXIO_TIMER_Type *base,
                                               flexio_timer_handle_t *handle,
                                               flexio_timer_callback_t callback)
{
    assert(handle);

    IRQn_Type flexio_irqs[] = FLEXIO_IRQS;

    /* Zero the handle. */
    memset(handle, 0, sizeof(*handle));

    /* Register callback. */
    handle->callback = callback;

    /* Enable interrupt in NVIC. */
    EnableIRQ(flexio_irqs[FLEXIO_GetInstance(base->flexioBase)]);

    /* Save the context in global variables to support the double weak mechanism. */
    return FLEXIO_RegisterHandleIRQ(base, handle, FLEXIO_TimerHandleIRQ);
}

// the interrupt service routine which gets called if there is a FlexIO interrupt
void FLEXIO_TimerHandleIRQ(void *timerType, void *timerHandle)
{
    assert(timerHandle);

    flexio_timer_handle_t *handle = (flexio_timer_handle_t *)timerHandle;
    FLEXIO_TIMER_Type *base;
    uint32_t status;
 
        if (handle->callback)
        {
             base   = (FLEXIO_TIMER_Type *)timerType;
             status = FLEXIO_GetTimerStatusFlags(base->flexioBase);
             FLEXIO_ClearTimerStatusFlags(base->flexioBase, status);
            (handle->callback)(base, handle, status);
        }
}

I would like to know if this is the correct way to add a custom FlexIO timer ISR or if there is an easier way to register a custom FlexIO timer ISR. Unfortunately I can't find a FlexIO timer driver or application note.

Kind regards,

Stefan

0 Kudos
Reply
1 Solution
1,445 Views
FelipeGarcia
NXP Employee
NXP Employee

Hello Stefan,

 

Unfortunately, we do not have any FlexIO timer driver. However, your application seems correct to from my perspective.

 

In addition, I recommend you to check the following community document that can give you more hints regarding FlexIO functionality and implementation.

 

https://community.nxp.com/docs/DOC-105640 

 

Best regards,

Felipe

View solution in original post

0 Kudos
Reply
2 Replies
1,446 Views
FelipeGarcia
NXP Employee
NXP Employee

Hello Stefan,

 

Unfortunately, we do not have any FlexIO timer driver. However, your application seems correct to from my perspective.

 

In addition, I recommend you to check the following community document that can give you more hints regarding FlexIO functionality and implementation.

 

https://community.nxp.com/docs/DOC-105640 

 

Best regards,

Felipe

0 Kudos
Reply
1,445 Views
imxrtuser
Senior Contributor I

Hello Felipe,

thank you for your answer!

The code is working but I think that are quite a lot of structures and functions just to be able to respond to the interrupt. I think it is easier to just override  FLEXIO1_IRQHandler (defined as PUBWEAK FLEXIO1_IRQHandler in startup_MIMXRT1021.s), if there are no other drivers which need to respond to a FlexIO interrupt.

So now I'm just doing the following:

// Prototype definition
void FLEXIO1_IRQHandler(void);

// The ISR function
void FLEXIO1_IRQHandler(void)
{
  uint32_t status = FLEXIO_GetTimerStatusFlags(FLEXIO1);
  FLEXIO_ClearTimerStatusFlags(FLEXIO1, status);
  if ((status & 0x2) == 0x2) // Timer 1 interrupt
    {
      togglePin = 1;
    }  
}

//and in main I just enable the FlexIO IRQ after initializing the FlexIO timers
IRQn_Type flexio_irqs[] = FLEXIO_IRQS;
EnableIRQ(flexio_irqs[FLEXIO_GetInstance(FLEXIO1)]);

Kind regards,

Stefan

0 Kudos
Reply