AnsweredAssumed Answered

How to add a FlexIO timer Interrupt Service Routine?

Question asked by Stefan Mitterhauser on Jan 21, 2020
Latest reply on Jan 23, 2020 by Stefan Mitterhauser

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

Outcomes