#if OS_CRITICAL_METHOD == 3 OS_CPU_SR cpu_sr; #endif 是啥意思

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了#if OS_CRITICAL_METHOD == 3 OS_CPU_SR cpu_sr; #endif 是啥意思相关的知识,希望对你有一定的参考价值。

OS_ENTER_CRITICAL() 和 OS_EXIT_CRITICAL()可用于临界代码的使用中。
注意:所有的PEND调用(OSTimeDly()之类)之前,不能关掉中断,否则,应用程序崩溃。
OS_ENTER_CRITICAL 和OS_EXIT_CRITICAL 的实现方法有3种,取决于处理器的类型以及C编译器的特性。

实现方法1 OS_CRITICAL_METHOD == 1
这是最简单的方法,直接使用处理器指令关中断;
这种方式的缺点是: 如果在禁止中断的情况下,调用UCOSII功能函数,从函数返回时,中断可能会变成允许的!

实现方法2 OS_CRITICAL_METHOD == 2
执行OS_ENTER_CRITICAL时,先将中断状态保存到堆栈,再关中断;执行OS_EXIT_CRITICAL时,从堆栈中恢复原来的中断状态。
缺点,当用户使用的处理器有堆栈指针相对寻址模式时,可能出现严重错误。

实现方法3 OS_CRITICAL_METHOD == 3
某些编译器提供了扩展功能,用户可以得到当前处理器状态字的值,并将其保存在C函数局部变量之中。
相关临界代码如下
OS_CPU_SR cpu_sr
cpu_sr = get_processor_psw();
disable_interrupts();
/*临界代码*/
set_processor_psw();

以上是摘自网上的一个ucosII的学习笔记。可以参考回答你的问题。
我说下我自己的理解,因为编译环境和硬件环境的差异,所以ucosII进入临界段的时候关闭中断和出临界段的时候开中断的方式不同。但是无非就是操作处理器的寄存器设置中断使能,失能或者保存当前中断状态寄存器的值到堆栈,或出栈。以上的三种方法是ucosii给出的三种方法。就是这么得来的。
参考技术A 预编译指令
#if 条件满足
指令 //否则这条指令不编译
#endif

html 基本IF,IF - ELSE和IF - ELSE IF - ELSE语句。

<!-- Basic IF statement will have an IF statement (what to do if the test is true), and an ELSE statement (what to do if the test is not true). You can have multiple logical tests by using an IF statement, any number of ELSE IF statements, and an ELSE statment in case none of the IF or ELSE IF statements are true. -->

<script language="javascript" type="text/javascript">
        
  var age = 18;           
        
  if (age <= 10)            
  {
      document.write("You can't vote, you're not even a teenager<br/>"); 
  } 
  else if (age < 18)
  {
    document.write("You can't vote, but you're getting closer to being old enough<br/>"); 
  }
  else
  {
    document.write("You CAN vote, yay!<br/>"); 
  }
  
  /*
      Comparision Operators
            
      ==  Equivlency
      === Equivlent in value and type
          1 == "1"  true
          1 === "1" false
      >   Greater Than
      <   Less Than
      >=  GT or =
      <=  LT or =
      !=  Not Equal To
         
      &&  And  (used to combine two logical operators)
      ||  Or   (used to create an OR statment between two logical operators
            
            
  */

</script>

<!-- DETAIL!!! -->

<script language="javascript" type="text/javascript">
        
  var age = 18;   // Creates variable age, sets it to a value of 18          
        
  if (age <= 10)  // First logical test, IF statement, if age variable is less than or equal to 10,        
  {
      document.write("You can't vote, you're not even a teenager<br/>");   // Then write 'You can't vote, you're not even a teenager' 
  } 
  else if (age < 18)   // Second logical test, ELSE IF statement (you can have as many of these as you want), they are tested in order, if age viarable is less than 18 (but over 10 due to the fact that 10 and under was already tested in the first IF statement),
  {
    document.write("You can't vote, but you're getting closer to being old enough<br/>");   // Then write 'You can't vote, but you're getting closer to being old enough'  
  }
  else   // ELSE, what to do if none of the previous logical tests are true,
  {
    document.write("You CAN vote, yay!<br/>");   // Then write, 'You CAN vote, yay!' 
  }


</script>

以上是关于#if OS_CRITICAL_METHOD == 3 OS_CPU_SR cpu_sr; #endif 是啥意思的主要内容,如果未能解决你的问题,请参考以下文章

php 如果是if if if if block

错题记录

if--else 嵌套 怎么理解?

对于互斥条件,多个“if”语句和“if-else-if”语句是不是相同?

if-if 和 if-elif 是不是定义为链式条件?

html 基本IF,IF - ELSE和IF - ELSE IF - ELSE语句。