Working with Interrupts

This page discusses some of the things you may want to do with relation to interrupts.

Enabling and Disabling Interrupts

In some cases, you may want to ensure a section of code is not interrupted. For example, you might be talking to a peripheral where the whole transaction must happen in one go, and an interrupt could cause the operation to fail.

The simplest way to avoid this is to disable interrupts for the critical section of your code:

__disable_irq(); 	// Disable Interrupts

// do something that can't be interrupted

__enable_irq(); 	// Enable Interrupts



4 comments:

08 Apr 2011

The interrupts that are received during the "do something..." block are processed after __enable_irq() ?

I'll see if I can dig up the details in the datasheet.

In case someone was wondering and didn't want to have to go research I thought I'd ask.

Many thanks!

10 Apr 2011

Michael

Who cares what the data sheet say? The mbed is designed for easy experimenting. So, why not write & run a simple test program who's result reveals whether/when interrupts are fired in the above situation, and post the results for us all. That sort of thing also helps reveal bugs between what the 'experts' think should/will happen from the library functions, and what really happens :-)!

29 Sep 2011

Simon:

Your posted method has solved one of my stucking server issues forever!! I appreciate you saved lots of my time.

_disable_irq(); Disable Interrupts

do something that can't be interrupted

enable_irq(); Enable Interrupts

29 Sep 2011

So do they stack up or not......??

Posting comments for this page has been disabled