Hi everyone,
I am trying to come up with some macros to enable and disable all interrupts in my LPC2364 while using the Keil RTX and programming in uVision4. After searching through much of the knowledge base, I came across the macros IENABLE and IDISABLE.
unsigned char interrupts_enabled = 0; #define IENABLE __asm{ MRS LR , SPSR }; \ __asm{ STMFD SP! , {LR} }; \ __asm{ MSR CPSR_c , #0x1F }; \ __asm{ STMFD SP! , {LR} }; \ interrupts_enabled = 1; #define IDISABLE __asm{ LDMFD SP! , {LR} }; \ __asm{ MSR CPSR_c , #0x92 }; \ __asm{ LDMFD SP! , {LR} }; \ __asm{ MSR SPSR_cxsf , LR }; \ interrupts_enabled = 0;
Most of that code is a mix of what is suggested in the following links:
http://www.keil.com/support/docs/2910.htm http://www.keil.com/support/man/docs/armcc/armcc_cihccdja.htm http://www.keil.com/support/man/docs/armcc/armcc_Chdgbbia.htm
However, I think I am having a problem due to Virtual Registers. As per the third reference above, we are not allowed to access the LR, SP and PC registers directly. That is the reason why, obviously, I get errors such as the following:
..\RF\mrfi\radios\common\mrfi_f1f2.c(242): error: #20: identifier "LR" is undefined
These instructions that access the LR and SP registers are quite significant in what I am trying to achieve though. How can I express this behavior in terms of what inline assembly can do for me? Has anyone done anything like this before, for enabling/disabling interrupts in a LPC microcontroller?
Per,
Thank you for trying to answer and be as informative as you can.
I do realize all of the things you have said, but there is a reason why I need to know whether I have enabled/disabled interrupts -- simply to be compliant with the protocol stack I am trying to port to my platform.
Describing the application is really out of scope in this forum, but what I am doing is porting the SimpliciTI protocol stack from Texas Instruments to the Keil environment with LPC23xx.
To do that, I have to change some macros that are right now specific to TI microcontrollers, and adapt them to the ARM LPC23xx reality, which means that if they have macros such as "BSP_INTERRUPTS_ARE_ENABLED()" or "BSP_DISABLE_INTERRUPTS()", I should be able to provide proper output so the software will function as expected.
For now I am keeping a variable whose value I change whenever I disable or enable interrupts in my SWI, but if there is a better way to do that I would very much like to know about it.