Disabling Interrupts - Need a more General Approach

15 Nov 2010

I  am writing a program  that  uses a lot  of  interrupts,  but I need  to be able to sequence then  depending  upon  what the processor  is  currently doing.  I've  looked on the  forum  and  it s not  clear  to me how  to do this.  In  an 8  bit  controller like the 89LPC922,  there  is an IRQ register  and  you simply mask  out the  IRQ's  you want to ignore,  and then re-enable them when required.

For control  applications that are entiely  IRQ  driven, can  someone  point  me in the right  direction? An RTOS  is not an option in my case.

Would  make a great API,  or  extension to  the existing IRQ  API BTW

 

15 Nov 2010

You could disable the interrupt by:

Interrupt.rise/fall(NULL);

That should disable the interrupt.

Lerche

 

15 Nov 2010

 

user Christian Lerche wrote:

You could disable the interrupt by:

Interrupt.rise/fall(NULL);

That should disable the interrupt.

Lerche

 

I don't think that actually disables the interrupt, it just stops calling your handler. If you really need to disable interrupts, use __disable_irq()/__enable_irq() intrinsics. To disable a specific interrupt, use NVIC_DisableIRQ() (e.g. NVIC_DisableIRQ(UART0_IRQn)). You can find the interrupt numbers in LPC17xx.h.

 

15 Nov 2010

I really think the cookbook or the handbook should have a section on this topic. I had to figure it out also to do serial interrupts. Only info around was in the forums.

 

15 Nov 2010

user jim hamblen wrote:

I really think the cookbook or the handbook should have a section on this topic.

Go for it :) It's editable by anyone.

15 Nov 2010 . Edited: 15 Nov 2010

As pointed out, you can mask/unmask interrupts as required in the NVIC. You can also (to some extent) play with interrupt priorities, which in general provides better behavior.

15 Nov 2010

Has anyone found some good reference materials on interrupts from ARM or Keil and the C functions to control it that would help new mbed users and students?  I tried a quick search, but did not find much.

 

 

16 Nov 2010

The application is  for a device  that has  miultiple interrupt  sources  and basically  does  nothing  until an interrupt  comes along.  Howver,  in some states (like standby,  for example),  it  should  only respond  to the power  ON  interrupt  and  no  others.

I  will take a look at the proposal from Igor - I am a novice at this so  there may well be a few  more questions from my side  in the next week or so.

 

Thanks

 

 

 

16 Nov 2010

In that case, you probably don't want to mask interrupts, but to effectively disable interrupt sources other than the one you're interested at. That's because masking only postpone handling, and it'll probably be useless for your device to handle old interrupts at exit of standby mode, right?

17 Nov 2010

Correct.  I  need to be able to

1. disable interrupts  while executing some tasks  (most of them in fact) and then re-enable them.  What  is  enbabled/disabled  depends  upon the state  of the system

2.  mask  some  interrupts - e.g.  if  something if a serial port is being serviced  and a button gets pushed, the  button  routine  needs  to wait  etc.

17 Nov 2010

Correct.  I  need to be able to

1. disable interrupts  while executing some tasks  (most of them in fact) and then re-enable them.  What  is  enbabled/disabled  depends  upon the state  of the system

2.  mask  some  interrupts - e.g.  if  something if a serial port is being serviced  and a button gets pushed, the  button  routine  needs  to wait  etc.