硬汉嵌入式论坛

 找回密码
 立即注册
查看: 2980|回复: 4
收起左侧

[μCOS-II] OS_ENTER_CRITICAL()嵌套

[复制链接]

6

主题

18

回帖

36

积分

新手上路

积分
36
发表于 2021-8-6 15:28:31 | 显示全部楼层 |阅读模式
硬汉哥,我一直有个疑问,OS_ENTER_CRITICAL() 和OS_EXIT_CRITICAL()是成双成对的。
但是比如我有个函数已经开了enter了,又调用别的函数,也开enter,会有什么影响吗

void func1()
{
   OS_ENTER_CRITICAL()
    func2();
   OS_EXIT_CRITICAL()
}


void func2()
{
   OS_ENTER_CRITICAL()
   do somethings....

   OS_EXIT_CRITICAL()

}


回复

使用道具 举报

19

主题

371

回帖

428

积分

高级会员

积分
428
发表于 2021-8-6 22:07:09 | 显示全部楼层
用method = 3,没问题
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106660
QQ
发表于 2021-8-7 10:35:23 | 显示全部楼层
按照楼上群友说的方式即可。
详细说明如下:

/*
*********************************************************************************************************
*                                              Cortex-M
*                                      Critical Section Management
*
* 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.
*             NOT IMPLEMENTED
*
* 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.
*             NOT IMPLEMENTED
*
* 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.
*********************************************************************************************************
*/

#define  OS_CRITICAL_METHOD   3u

#if OS_CRITICAL_METHOD == 3u
                                                 /* Save current BASEPRI priority lvl for exception... */
                                                 /* .. and set BASEPRI to CPU_CFG_KA_IPL_BOUNDARY      */
#define  OS_ENTER_CRITICAL()  do { cpu_sr = OS_CPU_SR_Save(CPU_CFG_KA_IPL_BOUNDARY << (8u - CPU_CFG_NVIC_PRIO_BITS));} while (0)
                                                 /* Restore CPU BASEPRI priority level.                */
#define  OS_EXIT_CRITICAL()   do { OS_CPU_SR_Restore(cpu_sr);} while (0)
#endif




回复

使用道具 举报

6

主题

18

回帖

36

积分

新手上路

积分
36
 楼主| 发表于 2021-8-10 13:56:50 | 显示全部楼层
h_007 发表于 2021-8-6 22:07
用method = 3,没问题

感谢大神~~~~~~~~~~~~~~~
回复

使用道具 举报

6

主题

18

回帖

36

积分

新手上路

积分
36
 楼主| 发表于 2021-8-10 13:57:19 | 显示全部楼层
eric2013 发表于 2021-8-7 10:35
按照楼上群友说的方式即可。
详细说明如下:

明白了。感谢硬汉,永远支持你
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-4-28 15:11 , Processed in 0.197773 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表