首页 > 代码库 > 改ucosii的中断禁止和恢复代码 【 mrs msr】

改ucosii的中断禁止和恢复代码 【 mrs msr】

ucosii原来的禁止中断以及恢复中断的代码是最简的,但是使用之前,必须声明一个固定名为 OS_CPU_SR   cpu_sr 的变量,吊在那里感觉很怪。

;*************************************************; Note(s)    : These functions are used in general like this:;                 void Task (void *p_arg);                 {;                 #if OS_CRITICAL_METHOD == 3          /* Allocate storage for CPU status register */;                     OS_CPU_SR  cpu_sr;;                 #endif;                          :;                     OS_ENTER_CRITICAL();             /* cpu_sr = OSCPUSaveSR();                */;                          :;                     OS_EXIT_CRITICAL();              /* OSCPURestoreSR(cpu_sr);                */;                          :;                 };*************************************************OSCPUSaveSR    MRS     R0, CPSR                ; Set IRQ and FIQ bits in CPSR to disable all interrupts    ORR     R1, R0, #0xC0                   MSR     CPSR_c, R1                  ;cpsr = cpsr_0 | 0xc0    MRS     R1, CPSR                ; Confirm that CPSR contains the proper interrupt disable flags    AND     R1, R1, #0xC0                   CMP     R1, #0xC0                   ;if( (cpsr_1 &0xc0) = 0xc0){ return }else { redo OSCPUSaveSR() }    BNE     OSCPUSaveSR                ; Not properly disabled (try again)    MOV     PC, LR                    ; Disabled, return the original CPSR contents in R0OSCPURestoreSR    MSR     CPSR_c, R0    MOV     PC, LR
;***************************************************
#if OS_CRITICAL_METHOD == 3#define OS_ENTER_CRITICAL() (cpu_sr = OSCPUSaveSR()) /* Disable interrupts */#define OS_EXIT_CRITICAL() (OSCPURestoreSR(cpu_sr)) /* Restore interrupts */#endif

改了下,这样可以如下使用这个功能:

;***********************************************;My OSEnterCritical && OSExitCritical oucaijun;void OSEnterCritical (unsigned int *pSave);;void OSExitCritical (unsigned int *pSave);; Useage:; OS_CPU_SR sr_save;; OSEnterCritical(&sr_save);; your_function_not_allow_interrupted; OSExitCritical(&sr_save);;***********************************************;NOINT EQU 0xc0OSEnterCritical    ;write and save    mrs r1, cpsr    str r1,[r0]    orr r1, r1, #NOINT    msr cpsr_c, r1    ;read and compare,judge if set_i_f successfully    mrs r1,cpsr    and r1,r1,#NOINT    cmp r1,#NOINT    bne OSEnterCritical    mov pc, lr    OSExitCritical    ldr r1,[r0]    msr cpsr_c, r1    mov pc, lr;***********************************************

仍要配对使用。

 

msr /msr的名称, 符合向左移动数据的习惯。

msr :  r to cpsr

msr cpsr_c, r1

mrs :   cpsr to r

mrs r1, cpsr_c  

改ucosii的中断禁止和恢复代码 【 mrs msr】