Hi,
there are two possibilities for an ISR.
MQX has an ISR handler, but it is more like a "micro thread", you register your behavioural code with MQX, and can pass parameters in and out. It is s-l-o-w.
However, if you have moved your vector table into RAM (a good idea) you can install a kernel interrupt, which is the traditional void-void.
If you want to do anything faster than about 100 Hz, I would do it that way.
There are examples in the MQX directory, but you still have to learn stuff.
So in the spirit of generosity, here you are, some sample code for a Kinetis.
#define PIT_TIMER (2)
#define PIT_TMR_INTVEC (INT_PIT0 + PIT_TIMER)
//some utilities
/*******************************************************************************/
/* void SetPit(uint_16 rate) */
/* Description:- */
/* Calculate Hardware timer count on Kinetis for appropriate f (in Hz) */
/* And jam into PIT register = which resets the PIT counter */
/* In general, the Peripheral bus clock which is used to drive PIT module */
/* runs at half the main clock speed. (i.e. around 48MHz) */
/*******************************************************************************/
void SetPIT(uint_16 rate)
{
PITTimerCounts = BSP_BUS_CLOCK/rate;
PIT_LDVAL(PIT_TIMER) = PITTimerCounts;
}
/*******************************************************************************/
/* void ResetPIT(void) */
/* Description:- */
/* jam precalculated count into PIT register = which resets the PIT counter */
/*******************************************************************************/
void ResetPIT(void)
{
PIT_LDVAL(PIT_TIMER) = PITTimerCounts;
}
/*******************************************************************************/
/* void StartPIT(void) */
/* Description:- */
/* jam precalculated count into PIT register = which resets the PIT counter */
/* Turn ON PIT in Kinetis and clear state flag */
/*******************************************************************************/
void StartPIT(void)
{
PIT_LDVAL(PIT_TIMER) = PITTimerCounts;
PIT_TCTRL(PIT_TIMER) |= PIT_TCTRL_TEN_MASK;//turn on timer
PIT_Stopped = FALSE;
}
/*******************************************************************************/
/* void StopPRF(void) */
/* Description:- */
/* Turn off PIT in Kinetis and set state flag */
/*******************************************************************************/
void StopPIT(void)
{
PIT_TCTRL(PIT_TIMER) &= ~PIT_TCTRL_TEN_MASK;//turn off timer
PIT_Stopped = TRUE;
}
//here is the interrupt handler
#if MQX_ROM_VECTORS
//MQX_ISR takes a parameter
void PRF_tick_isr( pointer user_isr_ptr )
#else
//kernel ISR is void void
void PIT_tick_isr( void )
#endif
{
volatile uint_32 tmp;
tick++;//do stuff here
PIT_TFLG(PRF_TIMER) = PIT_TFLG_TIF_MASK; //finally, write a 1 to clear the interrupt
tmp = PIT_CVAL(PRF_TIMER);//see errata
}
/*
Kinetis e2682: PIT: Does not generate a subsequent interrupt after clearing the interrupt flag
Errata type: Errata
Description: The PIT does not generate a subsequent interrupt after clearing the interrupt flag in the ISR
upon receiving the first interrupt. Thus, the second interrupt will never be triggered.
Workaround: In order to enable the use of subsequent interrupts from the PIT, the user must access any PIT
register after clearing the interrupt flag in the ISR.
*/
//here the routine to install the interrupt
void InstallTimerInterrupt(void)
{
StopTimer();//for safety, make sure the timer is disabled.
#if MQX_ROM_VECTORS
_int_install_isr(PIT_TMR_INTVEC, PIT_tick_isr, NULL);
#else
_int_install_kernel_isr(PIT_TMR_INTVEC, PIT_tick_isr);
#endif
PIT_MCR = PIT_MCR_FRZ_MASK;//enable timers but stop when in debug mode
PIT_TCTRL(PRF_TIMER) = PIT_TCTRL_TIE_MASK;//turn on interrupt, but do not enable timer
_bsp_int_init(PRF_TMR_INTVEC,3,0,TRUE);//also need to enable the interrupt controller
//this bit is hidden deep in the guts of the ARM cortex documentation.
}
NB there may be typos in the above - I take no responsibility for any errors in this code. Offered in good faith.
If you choose to use it, the risk is yours. If anyone wants to criticise it, at least say how it can be improved.
Hope that helps