Interrupts outside of MQX Lite

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Interrupts outside of MQX Lite

Jump to solution
788 Views
marks
Contributor IV

Hello, I want to have a few interrupts run outside of MQX Lite because of latency. I'm working with PEx Microcontroller Driver Suit Version 10.4.2 and IAR  Ver 7.30 on a Kinetis KV31. Reading the documentation, I found _int_install_kernel_isr in the reference manual.

Question 1: Is _int_install_kernel_isr the correct function to use? If so it says "A kernel ISR must save the registers that it needs and must service the hardware interrupt. When the kernel ISR is finished, it must restore the registers and perform a return-from-interrupt instruction."

Question 2: Is there an example of how to do this?

I found a some information on interrupts with MQX but not much with MQX Lite. Any additional educational materials (labs, demos, app notes, etc.)  that you could site would be greatly appreciated!

Also, I see there are the following functions available in cortex.c as part of the psp.

_cortex_int_init(num, prior, enable)

_cortex_int_enable(irq)

Question 3: Should I use these functions to set priority and enable the interrupts outside of MQX Lite?

Question 4:  Are these functions documented anywhere?

Thank you for your help!

Mark

0 Kudos
1 Solution
430 Views
DavidS
NXP Employee
NXP Employee

Hi Mark,

Will try to answer questions as best I can.

A1) if using the _int_install_kernel_isr you need to have the vector table in RAM rather than the default flash location.  The reason it that function only operates on RAM location and cannot modify the flash vector table.  Alternative to this approach would be for you to simply add your vector to the vector table.  Then you own it and MQX does not.  In either approach you need to be careful not to use MQX function calls but only use a global variable if you need to notify MQX application that the ISR did something.  Having a ISR outside MQX is sometimes called a Gorilla ISR as fyi.

A2) Generically the MQX examples apply to the MQXLite.  The _cortex_int_X functions are handy and would work well for your custom Gorilla ISR.

A3) Yes.

A4) Not that I'm aware of.  I usually head to the source code and read the Function description.

Simple example attached (sorry in CW10.6 but code should provide insight).  Look for "//DES" to see comments.

Regards,

David

View solution in original post

0 Kudos
3 Replies
431 Views
DavidS
NXP Employee
NXP Employee

Hi Mark,

Will try to answer questions as best I can.

A1) if using the _int_install_kernel_isr you need to have the vector table in RAM rather than the default flash location.  The reason it that function only operates on RAM location and cannot modify the flash vector table.  Alternative to this approach would be for you to simply add your vector to the vector table.  Then you own it and MQX does not.  In either approach you need to be careful not to use MQX function calls but only use a global variable if you need to notify MQX application that the ISR did something.  Having a ISR outside MQX is sometimes called a Gorilla ISR as fyi.

A2) Generically the MQX examples apply to the MQXLite.  The _cortex_int_X functions are handy and would work well for your custom Gorilla ISR.

A3) Yes.

A4) Not that I'm aware of.  I usually head to the source code and read the Function description.

Simple example attached (sorry in CW10.6 but code should provide insight).  Look for "//DES" to see comments.

Regards,

David

0 Kudos
430 Views
marks
Contributor IV

Hi David, Thank you for the detailed reply and example code. I like the idea of keeping the vectors in flash. Just seems simpler. I added my ISRs to the Vector.c by adding a few lines of code at the bottom of Vectors_config.h. For example, to add my own comparator interrupt I added the following.

#undef VECTOR_57        

#define VECTOR_57         (tIsrFunc)&CMP1_isr 

and then to set the priority and enable the ISR:

_cortex_int_init(INT_CMP1,8, TRUE);

_cortex_int_enable(INT_CMP1);

Seems to work great! All that business about the need to "save" and "restore" used registers and perform a "return-from-interrupt instruction" does not apply here because the compiler takes care of all that I guess.

Since I am using the stand-alone PEx, the files Vectors.c and Vectors_config.h.get written over each time I "Generate Processor Expert Code" and I lose my edits. Is there a better way to modify the vector table than editing Vectors_config.h. after each PEx compile?

Thanks,

Mark

0 Kudos
430 Views
marek_neuzil
NXP Employee
NXP Employee

Hello Mark,

There is one workaround to avoid changes of a generated file by Processor Expert. When you set the read-only attribute of the file that you have modified manually, the file is not modified by Processor Expert. There is reported a warning during generation of code by Processor Expert (for example:

Generator: Warning: Error during writing to file: C:\Freescale\KDS_3.0.0\workspace\Test RAM config on MK22FN512\Generated_Code\Vectors_Config.h) that can be ignored.

You can set the read-only attribute in the Properties of the file (in the Project Explorer window click on the file by right button of the mouse and select Properties).

pastedImage_1.png

Best Regards,

Marek Neuzil

0 Kudos