硬汉嵌入式论坛

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

[QQ群问题解答] 我在任务里面OSSchedlock(),,后发现任务是不再被调度了,但是我在中断里面调用OSSc

[复制链接]

92

主题

76

回帖

92

积分

初级会员

积分
92
发表于 2014-4-28 18:29:54 | 显示全部楼层 |阅读模式
我在任务里面OSSchedlock(),,后发现任务是不再被调度了,但是我在中断里面调用OSSchedUnlock()后为什么调度还是没有运行起来?
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106721
QQ
发表于 2014-5-21 20:01:21 | 显示全部楼层
这两个函数是成对使用的,不能够在中断里面调用,特别注意这句话:
if (OSIntNesting == 0u) {                /* Can't call from an ISR                             */
  1. /*$PAGE*/
  2. /*
  3. *********************************************************************************************************
  4. *                                         PREVENT SCHEDULING
  5. *
  6. * Description: This function is used to prevent rescheduling to take place.  This allows your application
  7. *              to prevent context switches until you are ready to permit context switching.
  8. *
  9. * Arguments  : none
  10. *
  11. * Returns    : none
  12. *
  13. * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every
  14. *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
  15. *********************************************************************************************************
  16. */
  17. #if OS_SCHED_LOCK_EN > 0u
  18. void  OSSchedLock (void)
  19. {
  20. #if OS_CRITICAL_METHOD == 3u                     /* Allocate storage for CPU status register           */
  21.     OS_CPU_SR  cpu_sr = 0u;
  22. #endif
  23.     if (OSRunning == OS_TRUE) {                  /* Make sure multitasking is running                  */
  24.         OS_ENTER_CRITICAL();
  25.         if (OSIntNesting == 0u) {                /* Can't call from an ISR                             */
  26.             if (OSLockNesting < 255u) {          /* Prevent OSLockNesting from wrapping back to 0      */
  27.                 OSLockNesting++;                 /* Increment lock nesting level                       */
  28.             }
  29.         }
  30.         OS_EXIT_CRITICAL();
  31.     }
  32. }
  33. #endif
  34. /*$PAGE*/
  35. /*
  36. *********************************************************************************************************
  37. *                                          ENABLE SCHEDULING
  38. *
  39. * Description: This function is used to re-allow rescheduling.
  40. *
  41. * Arguments  : none
  42. *
  43. * Returns    : none
  44. *
  45. * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every
  46. *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
  47. *********************************************************************************************************
  48. */
  49. #if OS_SCHED_LOCK_EN > 0u
  50. void  OSSchedUnlock (void)
  51. {
  52. #if OS_CRITICAL_METHOD == 3u                               /* Allocate storage for CPU status register */
  53.     OS_CPU_SR  cpu_sr = 0u;
  54. #endif
  55.     if (OSRunning == OS_TRUE) {                            /* Make sure multitasking is running        */
  56.         OS_ENTER_CRITICAL();
  57.         if (OSIntNesting == 0u) {                          /* Can't call from an ISR                   */
  58.             if (OSLockNesting > 0u) {                      /* Do not decrement if already 0            */
  59.                 OSLockNesting--;                           /* Decrement lock nesting level             */
  60.                 if (OSLockNesting == 0u) {                 /* See if scheduler is enabled              */
  61.                     OS_EXIT_CRITICAL();
  62.                     OS_Sched();                            /* See if a HPT is ready                    */
  63.                 } else {
  64.                     OS_EXIT_CRITICAL();
  65.                 }
  66.             } else {
  67.                 OS_EXIT_CRITICAL();
  68.             }
  69.         } else {
  70.             OS_EXIT_CRITICAL();
  71.         }
  72.     }
  73. }
  74. #endif
复制代码
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-1 04:17 , Processed in 0.219257 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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