I am trying to initiate a Timer (Timer 0) interrupt on the rising edge of a pulse.
The timer is in the Timer mode so as to count the clocks between the rising edges.
Following is my initialization code
// Init board hardware.
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
// Init FSL debug console.
BOARD_InitDebugConsole();
CLOCK_AttachClk(kFRO_HF_to_CTIMER0);
PRINTF("Configuring Timer 0...\n");
const uint32_t port1_pin26_config = ( //Configure as CT_INP3
IOCON_FUNC3 |
// No addition pin function
IOCON_MODE_PULLDOWN |
// Standard mode, output slew rate control is enabled
IOCON_PIO_SLEW_STANDARD |
// Input function is not inverted
IOCON_PIO_INV_DI |
// Enables digital function
IOCON_PIO_DIGITAL_EN |
// Open drain is disabled
IOCON_PIO_OPENDRAIN_DI);
// PORT1 PIN26
IOCON_PinMuxSet(IOCON, 1, 26, port1_pin26_config);
INPUTMUX_Init(INPUTMUX);
INPUTMUX_AttachSignal(INPUTMUX, 1, kINPUTMUX_CtimerInp3ToTimer0Captsel);
INPUTMUX_Deinit(INPUTMUX);
CTIMER_GetDefaultConfig(&g_ctimer_config);
CTIMER_Init(CTIMER0, &g_ctimer_config);
CTIMER0->CTCR &= 0x0000000F;
CTIMER0->CTCR |= ((0x2 << 5) | (1 << 4));
CTIMER_RegisterCallBack(CTIMER0, &g_ctimer_callback[0], kCTIMER_SingleCallback);
CTIMER_SetupCapture(CTIMER0, kCTIMER_Capture_1, kCTIMER_Capture_RiseEdge, true);
CTIMER_EnableInterrupts(CTIMER0, kCTIMER_Capture1InterruptEnable);
CTIMER_StartTimer(CTIMER0);
However, The callback function for the capture is never called.
The callback code looks like this
void ctimer_capture_callback(uint32_t arg_flags);
void ctimer_match_callback(uint32_t arg_flags);
/******************************************************************************
* Global Variables
*****************************************************************************/
ctimer_config_t g_ctimer_config;
ctimer_callback_t g_ctimer_callback[] = {NULL, NULL, NULL, NULL, NULL, ctimer_capture_callback, NULL, NULL};
uint32_t g_timer_val = 0;
uint8_t g_valid_lock = 0;
/******************************************************************************
* Function Definition
*****************************************************************************/
void ctimer_capture_callback(uint32_t arg_flags)
{
if (CTIMER_GetStatusFlags(CTIMER0) & kCTIMER_Capture1InterruptEnable){ //Breakpoint here
//...
}
}
The code never reaches the breakpoint ( if (CTIMER_GetStatusFlags(CTIMER0) & kCTIMER_Capture1InterruptEnable){ line) However the timer does get reset on capture so I believe the reset on capture functionality is working.
What am I doing wrong?