2007-09-04 11:02 AM
Enable/Disable Global Interrupts
2011-05-17 12:44 AM
I'm designing some code that has data that will be written to by an ISR and read by a non-ISR function. My main program needs to perform a few quick operations using this stored data and thus I need to ensure that the data is not overwritten by an ISR midstream. Thus I'd like a quick and easy way to globally disable and enable interrupts.
Should I declare all members that will be accessed in this way ''volatile'' or can I use:Code:
// Begin critical section SCU_AHBPeriphClockConfig(__VIC,DISABLE); // Disable all interrupts //Do stuff SCU_AHBPeriphClockConfig(__VIC,ENABLE); // Enable all interrupts Thanks!2011-05-17 12:44 AM
You could disable at core level
vPortEnableInterrupts: STMDB SP!, {R0} MRS R0, CPSR BIC R0, R0, #0xC0 MSR CPSR, R0 LDMIA SP!, {R0} BX lr vPortDisableInterrupts: STMDB SP!, {R0} MRS R0, CPSR ORR R0, R0, #0xC0 MSR CPSR, R0 LDMIA SP!, {R0} BX lr you can also put this in inline asm if you wish. What compiler are you using? Most have inbuilt functions to do this, eg. __disable_interrupt(); __enable_interrupt(); Regards sjo2011-05-17 12:44 AM
Just to add to thread. I am also looking for a way to easily enable then disable interrupts.
I am using: ARM/Thumb C/C++ Compiler, RVCT3.1 [Build 903] for uVision [Standard] From the documentation (Italics and bold are mine): The __disable_irq intrinsic can only be executed in privileged modes, that is, in non user modes. In User mode this intrinsic does not change the interrupt flags in the CPSR.So, I too need an alternate method to enable/disable interrupts.2011-05-17 12:44 AM
Um, the inability to enable/disable interrupts in USER mode is a feature of the ARM. There is no way around it, unless you switch to something like System or Supervisor modes.
Why are you using USER mode for an embedded application? This would only apply if you were doing something like Linux, and the default on power up is SYSTEM anyways.2011-05-17 12:44 AM
In user mode the only way for enabling/disabling interrupts
is to use software interupts (SWI). start from here: http://www.keil.com/support/docs/3229.htm2011-05-17 12:44 AM
question @lakata:
- the application run in system mode - i use no SWI for enabling/disabling interrupts how can i sure that enabling/disabling interrupts is an atomic operation ?2011-05-17 12:44 AM
Hey lakata,
Anything from within main( ) would be in User Mode. Hence, my concern with the ability to disable interrupts. My application does a fair amount of processing from within main (I'm not using any OS). Interrupts get generated and move data around. main executes a state machine, processing data as needed to move the state along. My goal is to not ever disable interrupts, but while debugging it sometimes helps.2011-05-17 12:44 AM
Your choices are above, they are good enough techniques for freertos, uclinux and ecos.
Spen2011-05-17 12:44 AM
sjo's recommendations are atomic, as far as I know, although I would be hesitant to put any critical instructions immediately after writing to CPSR in case there is something funky with the ARM instruction pipeline.