硬汉嵌入式论坛

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

[μCOS-II] 分析源码 uc/os 2.93.00 OSIntEnter()函数遇到些问题

[复制链接]

1

主题

14

回帖

17

积分

新手上路

积分
17
发表于 2020-3-29 10:53:04 | 显示全部楼层 |阅读模式
发现有两个函数
1.
void  OSIntEnter (void)
{
    if (OSRunning == OS_TRUE) {
        if (OSIntNesting < 255u) {
            OSIntNesting++;                      /* Increment ISR nesting level                        */
        }
        OS_TRACE_ISR_ENTER();
    }
}


2.
void  OSIntExit (void)
{
#if OS_CRITICAL_METHOD == 3u                               /* Allocate storage for CPU status register */
    OS_CPU_SR  cpu_sr = 0u;
#endif



    if (OSRunning == OS_TRUE) {
        OS_ENTER_CRITICAL();
        if (OSIntNesting > 0u) {                           /* Prevent OSIntNesting from wrapping       */
            OSIntNesting--;
        }
        if (OSIntNesting == 0u) {                          /* Reschedule only if all ISRs complete ... */
            if (OSLockNesting == 0u) {                     /* ... and not locked.                      */
                OS_SchedNew();
                OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
                if (OSPrioHighRdy != OSPrioCur) {          /* No Ctx Sw if current task is highest rdy */
#if OS_TASK_PROFILE_EN > 0u
                    OSTCBHighRdy->OSTCBCtxSwCtr++;         /* Inc. # of context switches to this task  */
#endif
                    OSCtxSwCtr++;                          /* Keep track of the number of ctx switches */

#if OS_TASK_CREATE_EXT_EN > 0u
#if defined(OS_TLS_TBL_SIZE) && (OS_TLS_TBL_SIZE > 0u)
                    OS_TLS_TaskSw();
#endif
#endif
                    OS_TRACE_ISR_EXIT_TO_SCHEDULER();

                    OSIntCtxSw();                          /* Perform interrupt level ctx switch       */
                } else {
                    OS_TRACE_ISR_EXIT();
                }
            } else {
                OS_TRACE_ISR_EXIT();
            }
        } else {
            OS_TRACE_ISR_EXIT();
        }

        OS_EXIT_CRITICAL();
    }
}


OSIntExit()使用临界段保护了OSIntNesting以确保修改时的正确性, 为什么OSIntEnter()中不用使用临界段保护OSIntNesting 这个全局的系统变量呢,求教各位
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106913
QQ
发表于 2020-3-29 10:59:57 | 显示全部楼层
这个是需要用户手动加的,标准的中断写法

  1. void  My_Handler (void)
  2. {
  3. #if OS_CRITICAL_METHOD == 3u                                    /* Allocate storage for CPU status register             */
  4.     OS_CPU_SR  cpu_sr;
  5. #endif


  6.     OS_ENTER_CRITICAL();
  7.     OSIntEnter();                                               /* Tell uC/OS-II that we are starting an ISR            */
  8.     OS_EXIT_CRITICAL();

  9.     xxxxxxxxxxxxxxxxxxxx

  10.     OSIntExit();                                                /* Tell uC/OS-II that we are leaving the ISR            */
  11. }
复制代码

回复

使用道具 举报

1

主题

14

回帖

17

积分

新手上路

积分
17
 楼主| 发表于 2020-3-29 11:06:07 | 显示全部楼层
eric2013 发表于 2020-3-29 10:59
这个是需要用户手动加的,标准的中断写法

void  OSIntEnter (void)
{
#if OS_CRITICAL_METHOD == 3u                                    /* Allocate storage for CPU status register             */
    OS_CPU_SR  cpu_sr;
#endif
OS_ENTER_CRITICAL();
    if (OSRunning == OS_TRUE) {
        if (OSIntNesting < 255u) {
            OSIntNesting++;                      /* Increment ISR nesting level                        */
        }
        OS_TRACE_ISR_ENTER();
    }
OS_EXIT_CRITICAL();
}


把函数改成这样可以吗,会对源码编写有什么不好的影响吗
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106913
QQ
发表于 2020-3-29 11:07:29 | 显示全部楼层
lulua 发表于 2020-3-29 11:06
void  OSIntEnter (void)
{
#if OS_CRITICAL_METHOD == 3u                                    /* All ...

随便改,遇到问题了再解决。
回复

使用道具 举报

1

主题

14

回帖

17

积分

新手上路

积分
17
 楼主| 发表于 2020-3-29 11:09:38 | 显示全部楼层
eric2013 发表于 2020-3-29 11:07
随便改,遇到问题了再解决。

好的,谢谢eric2013
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-10 04:10 , Processed in 0.159123 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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