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_TIMER_Type;
typedef struct _flexio_timer_handle flexio_timer_handle_t;
typedef void (*flexio_timer_callback_t)(FLEXIO_TIMER_Type *base,
flexio_timer_handle_t *handle,
status_t status);
struct _flexio_timer_handle
{
flexio_timer_callback_t callback;
};
void FLEXIO_TimerUserCallback(FLEXIO_TIMER_Type *base,
flexio_timer_handle_t *handle,
status_t status)
{
if ((status & 0x2) == 0x2)
{
togglePin = 1;
}
}
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;
memset(handle, 0, sizeof(*handle));
handle->callback = callback;
EnableIRQ(flexio_irqs[FLEXIO_GetInstance(base->flexioBase)]);
return FLEXIO_RegisterHandleIRQ(base, handle, FLEXIO_TimerHandleIRQ);
}
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