OS_CRITICAL_METHOD的意思

 

      在UCOS2的源代码及相关应用程序中,总会出现OS_CRITICAL_METHOD ==3的判断,为此在网上找到该语句的解释,

Method #1: Disable/Enable interrupts using simple instructions. After critical section, interrupts will be enabled even if they were disabled before entering the critical section.

Method #2: Disable/Enable interrupts by preserving the state of interrupts. In other words, if interrupts were disabled before entering the critical section, they will be disabled when leaving the critical section.

Method #3: Disable/Enable interrupts by preserving the state of interrupts. Generally speaking you would store the state of the interrupt disable flag in the local variable 'cpu_sr' and then disable interrupts. 'cpu_sr' is allocated in all of uC/OS-II's functions that need to disable interrupts. You would restore the interrupt disable state by copying back 'cpu_sr' into the CPU's status register.

宏OS_ENTER_CRITICAL ( ) 和 OS_EXIT_CRITICAL ( ) 的实现方法:

用户通过定义移植文件OS_CPU.H中的常数OS_CRITICAL_METHOD来选择3中实现方法:

  • OS_CRITICAL_METHOD = 1 :

             直接使用处理器的开关中断指令来实现宏

  • OS_CRITICAL_METHOD = 2 :

             利用堆栈保存和恢复CPU的状态

  • OS_CRITICAL_METHOD = 3 :

             利用编译器扩展功能获得程序状态字,保存在局部变量cpu_sr

    更详细的解释和比较见下面的链接:

http://blog.csdn.net/qb_2008/article/details/7201340

你可能感兴趣的:(OS,扩展,编译器)