MCUxpresso intrinsic functions for interrupts?

cancel
Showing results for 
Search instead for 
Did you mean: 

MCUxpresso intrinsic functions for interrupts?

Jump to solution
1,316 Views
joseph_jean-jac
Contributor III

Hello Everyone,

 

I am in a situation where I need to replace the IAR intrinsic functions for retrieving an interrupt state and restoring an interrupt state. For the IAR compiler, the process is usually something like this:

 

void function(void) { 
__istate_t  s = __get_interrupt_state();
__disable_interrupt();
/* Do something here. */
__set_interrupt_state(s);

}

 

Browsing through the forums here, I found that to enable and disable interrupts for MCUxpresso, the following API was used:

__enable_irq()

__disable_irq()

 

My question is what are the MCUxpresso equivalent for IAR's __get_interrupt_state() and

__set_interrupt_state()? I tried searching through the web and I couldn't find what I was exactly looking for in the MCUxpresso user guide and getting started manuals.

 

Any help is greatly appreciated, thanks!

1 Solution
726 Views
BlackNight
NXP Employee
NXP Employee

Hi Joseph,

Let the IDE create the SDK project for you (don't try to set things up by hand unless you know what you do), as this will setup all the needed defines and include paths. The __enable_irq() is present in the cmsis_gcc.h as shown below:

pastedImage_1.png

Erich

View solution in original post

10 Replies
726 Views
joseph_jean-jac
Contributor III

Does anyone know how to get __enable_irq() and __disable_irq() working on the K65? 

Or better yet where to download the library for the functions in the “core_cm4.h” file? Of course this is assuming __enable_irq() and __disable_irq() are located in that header file. 

Thanks!

0 Kudos
726 Views
BlackNight
NXP Employee
NXP Employee

They are in the SDK you can get from Welcome | MCUXpresso SDK Builder 

I hope this helps,

Erich

0 Kudos
726 Views
joseph_jean-jac
Contributor III

Hi Erich,

I created a SDK and used it to create a new project. I included all of the CMSIS drivers in the new project and I went to the "Installed SDK's" window, selected the SDK I had built for the K65, and selected the "Recreate and reload part support info" button to double make sure the SDK was installed. I then went on to include the "core_cm4.h" file so I could use  __enable_irq() and __disable_irq(). I compiled and still received 26 errors ( "declaration not in scope", etc). 

I'm not sure what is going on, I feel like I am missing something super basic...something that should be a normal routine. I tried recreating a new project with the SDK, to make sure I did the process right, and still no avail. When I commented out the interrupt enable/disable() function calls and the core_cm4.h file, I received no compilation errors and I was able to run my program (of course it was not working properly according to expected behavior, since I commented out the interrupt function calls). 

This is rather frustrating considering I am not even trying to use the NVIC functions which are more complex. I appreciate your help thus far.

0 Kudos
727 Views
BlackNight
NXP Employee
NXP Employee

Hi Joseph,

Let the IDE create the SDK project for you (don't try to set things up by hand unless you know what you do), as this will setup all the needed defines and include paths. The __enable_irq() is present in the cmsis_gcc.h as shown below:

pastedImage_1.png

Erich

View solution in original post

726 Views
joseph_jean-jac
Contributor III

Thank you Erich!!

"cmsis_gcc.h" was indeed the file I needed. All the errors went away and I was able to run my program properly. 

Thanks once again!!!

Looking back I probably should looked more into the manuals for the ARM Cortex M4 rather than the manuals for NXP/MCUXpresso IDE. 

0 Kudos
726 Views
BlackNight
NXP Employee
NXP Employee

Hi Joseph,

great to hear that it is working now!

If it is about interrupts and ARM Cortex-M: that multi-part tutorial might be of interest for you (even if not using FreeRTOS): ARM Cortex-M, Interrupts and FreeRTOS: Part 1

I hope this helps,

Erich

726 Views
converse
Senior Contributor V

In Cortex-M parts, there is no interrupt state to save, so you can just use the intrinsics as provided. If you need some finer-grain control over interrupts, look at the NVIC* functions. 

726 Views
joseph_jean-jac
Contributor III

Thanks, so saving/restoring interrupts state are inherently handled by __disable_irq() and __enable_irq()?

I thought intrinsic functions were compiler based rather than processor based? I say this because I see you mentioned there are no interrupt states to save on Cortex-M processors. Or is my understanding of intrinsic functions completely upside down?

Also, when I tried to include the "core_cm4.h"  file (I'm using the K65) to call __disable_irq() and __enable_irq(), I got almost 30 errors in "core_cm4.h" basically stating that most of the functions(__NVIC_PRIO_BITS, IRQn_Type, __NVIC_DisableIRQ, etc)  are either not declared in scope or are declared void.

Once again, any help is greatly appreciated! 

0 Kudos
726 Views
converse
Senior Contributor V

An intrinsic function is one that is hard-coded into the compiler. The compiler recognises the intrinsic and replaces the function call with automatically generated instructions. The problem with an intrinsic is if you need to generate a different set of instructions (for a different MCU, for example), then you need to release a new version of the compiler. The stated advantage was that the compiler knew what was happening with the code either side of the intrinsics and could produce more optimal code, but modern compilers can do this for any code without the need for special code hard-coded into the compiler.

MCUXpresso instead provides 'intrinsics' through macros in header files. This means you can easily support a wide range of different processors (using the same 'instrinsic' function name, but with different output) by just supplying a different header file. As you have seen, with Cortex-M4, this involves calling functions on the NVIC to emulate the behaviour. To resolve the NVIC functions, you will need to download and build the appropriate library from the SDK for your part (sorry, I am not familiar with the K65, so can't point you at it directly).

Note that with the NVIC, which has prioritised interrupts, the use of enable/disable_irq is a rather blunt tool, and you can often just disable low(er) priority interrupts while allowing high(er) priroty interrupts to continue - depending, of course, on the nature of your code.

726 Views
joseph_jean-jac
Contributor III

Thanks for the explanation, that was of great help!!

Because of the nature of my code, enable/disable_irq() actually works for my situation. NVIC functions requires an interrupt number to be passed as an argument....which sets a different direction for my code. 

As far as downloading and building the appropriate library from the SDK to get the NVIC functions working correctly, shouldn't that library be included by default when you create an SDK for a particular platform (such as K65) using MCUXpresso SDK builder?? I'm asking on behalf of enable/disable_irq() which should be defined in "core_cm4.h" as well (even though I couldn't find in that header file). 

Once again, thanks for all the help that you have given so far!

0 Kudos