What's Best Way to Globally Disable Interrupts
2005-05-02 by kaiandxiulpc2000
Yahoo Groups archive
Index last updated: 2026-04-28 23:31 UTC
Thread
2005-05-02 by kaiandxiulpc2000
If my user application is running with interrupts occurring, then I need to disable all interrupts for a bit of time: 1) Should I use the C command "VICIntEnable=0x00000000"? OR 2) Set the IRQ and FIQ bits in the cpsr? Also, then do I have to be in non-user mode (i.e. privileged mode) to enable/disable the IRQ/FIQ bits in the cpsr?
2005-05-02 by Robert Adsett
At 07:30 PM 5/2/05 +0000, kaiandxiulpc2000 wrote: >If my user application is running with interrupts occurring, then I >need to disable all interrupts for a bit of time: > >1) Should I use the C command "VICIntEnable=0x00000000"? >OR >2) Set the IRQ and FIQ bits in the cpsr? Also, then do I have to be >in >non-user mode (i.e. privileged mode) to enable/disable the IRQ/FIQ >bits >in the cpsr? In my opinion number 2 will cause you the least problems. In fact I would disable interrupts before modifying VICIntEnable. And yes you have to be in a mode other than user mode. On the other hand there is no reason to be in user mode anyway. The only thing that distinguishes user mode from system mode is that in user mode is that in user mode you cannot set and clear the interrupt enable bits. Personally I prefer a disable/restore interrupt pair rather than a disable/enable interrupt pair. There is an implementation of the former in the newlib-lpc library that should be easily separable from that library if desired. Robert " 'Freedom' has no meaning of itself. There are always restrictions, be they legal, genetic, or physical. If you don't believe me, try to chew a radio signal. " -- Kelvin Throop, III http://www.aeolusdevelopment.com/
2005-05-02 by embeddedjanitor
--- In lpc2000@yahoogroups.com, Robert Adsett <subscriptions@a...>
wrote:
> At 07:30 PM 5/2/05 +0000, kaiandxiulpc2000 wrote:
> >If my user application is running with interrupts occurring, then I
> >need to disable all interrupts for a bit of time:
> >
> >1) Should I use the C command "VICIntEnable=0x00000000"?
> >OR
> >2) Set the IRQ and FIQ bits in the cpsr? Also, then do I have to
be
> >in
> >non-user mode (i.e. privileged mode) to enable/disable the IRQ/FIQ
> >bits
> >in the cpsr?
>
> In my opinion number 2 will cause you the least problems. In fact I
would
> disable interrupts before modifying VICIntEnable. And yes you have
to be in
> a mode other than user mode. On the other hand there is no reason
to be in
> user mode anyway. The only thing that distinguishes user mode from
system
> mode is that in user mode is that in user mode you cannot set and
clear the
> interrupt enable bits.
Agree. Look back for postings on spurious interrupts. Fiddling with
the VIC is not enough.
>
> Personally I prefer a disable/restore interrupt pair rather than a
> disable/enable interrupt pair. There is an implementation of the
former in
> the newlib-lpc library that should be easily separable from that
library if
> desired.
Agree again.
restoring allows you to restore the previous state (ie. you should not
always blindly turn interrupts on). Restoring allows you to use the
same code in an interrupt or normal context etc.
I use two funtions intGetDisable() and intEnable()
int intval; // previous interrupt value
intval = intGetDisable(); // Is the interrupt enabled? Disable if it
is enabled;
// protected code
if(intval)
intEnable();