Hi Kas
Below is a reference of how the IRQ is used in the uTasker project (the KEA-64 has this as port interrupt possibility but limited to a single pin - PTA5 - see further details at the end).
Here is the user interrupt callback (could do anything so it is just an example)
static void irq_handler(void)
{
fnInterruptMessage(OWN_TASK, IRQ_FIRED);
}
This is the user interface code to set up an IRQ interrupt (on KE and KEA parts)
INTERRUPT_SETUP interrupt_setup; // interrupt configuration parameters
interrupt_setup.int_type = PORT_INTERRUPT; // identifier to configure port interrupt
interrupt_setup.int_handler = irq_handler; // handling function
interrupt_setup.int_priority = PRIORITY_PORT_IRQ_INT; // interrupt priority level
interrupt_setup.int_port = KE_PORTI; // the port that the interrupt input is on
interrupt_setup.int_port_bits = KE_PORTI_BIT6; // the IRQ input connected
interrupt_setup.int_port_sense = (IRQ_FALLING_EDGE | PULLUP_ON); // interrupt is to be falling edge sensitive
fnConfigureInterrupt((void *)&interrupt_setup); // configure interrupt
fnConfigureInterrupt() does the following in the case of these settings:
static void (*IRQ_handler)(void) = 0; // handler for IRQ
unsigned char ucPortPin = SIM_PINSEL_IRQPS_PTI6;
POWER_UP(0, SIM_SCGC_IRQ); // enable clocks to the external interrupt module
SIM_PINSEL0 = ((SIM_PINSEL0 & ~(SIM_PINSEL_IRQPS_PTI6)) | ucPortPin); // select the IRQ pin to use
IRQ_SC = IRQ_SC_IRQPE; // enable IRQ pin function with pull-up
IRQ_handler = port_interrupt->int_handler; // enter the application handler
fnEnterInterrupt(irq_IRQ_ID, port_interrupt->int_priority, _IRQ_isr); // ensure that the handler is entered
IRQ_SC |= (IRQ_SC_IRQIE | IRQ_SC_IRQACK); // enable interrupt and reset pending interrupt
fnEnterInterrupt() enters the IRQ vector into the vector table (in SRAM in this case but can also be fixed in Flash).
To enable the interrupt source in the NVIC it does (in the case of the IRQ):
IRQ4_7_PRIORITY_REGISTER |= 0xc0000000;
IRQ0_32_SER = 0x00000080;
Of course the main Cortex interrupt must also be enabled.
When the IRQ triggers the IRQ handler is called, which resets the IRQ interrupt flag and calls the user's handler
static __interrupt void _IRQ_isr(void)
{
IRQ_SC |= (IRQ_SC_IRQACK); // reset the interrupt flag
if (IRQ_handler != 0) {
IRQ_handler(); // call the interrupt handler
}
}
The KEA-64 (as some smaller KE parts) has however only one IRQ input which can only be on PTA5. PTA5 defaults to RESET_b input and to use it the following differences are valid:
- the reset function must be disabled in SIM_SOPT0 [SIM_SOPT0 &= ~(SIM_SOPT_RSTPE);] - this is however a write-once field so it has to be used carefully. It is best to do it immediately after reset (where all such bits are defined together) so that it is guarantied to work.
- The SIM_PINSEL0 operations are redundant since the other sources don't exist
Regards
Mark
http://www.utasker.com/kinetis.html