硬汉嵌入式论坛

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

[μCOS-III] 特别注意,现在的新版uCOS-II和III的开关中断也开始采用BASEPRI寄存器设置

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106959
QQ
发表于 2019-5-5 11:12:42 | 显示全部楼层 |阅读模式
通过BASEPRI寄存器可以设置关闭受到uCOS-III管理的中断。
而其它不受控制的中断可以像裸机一样使用,让这些中断可以得到及时响应,降低中断延迟时间。

  1. /*
  2. *********************************************************************************************************
  3. *                                      KERNEL AWARE IPL BOUNDARY
  4. *
  5. * Note(s) : (1) Determines the IPL level that establishes the boundary for ISRs that are kernel-aware and
  6. *               those that are not.  All ISRs at this level or lower are kernel-aware.
  7. *
  8. *           (2) ARMv7-M: Since the port is using BASEPRI to separate kernel vs non-kernel aware ISR, please
  9. *               make sure your external interrupt priorities are set accordingly. For example, if
  10. *               CPU_CFG_KA_IPL_BOUNDARY is set to 4 then external interrupt priorities 4-15 will be kernel
  11. *               aware while priorities 0-3 will be use as non-kernel aware.
  12. *********************************************************************************************************
  13. */

  14. #define  CPU_CFG_KA_IPL_BOUNDARY                           4u
复制代码


现在的开关中断实现:

  1. #define  CPU_INT_DIS()         do { cpu_sr = CPU_SR_Save(CPU_CFG_KA_IPL_BOUNDARY << (8u - CPU_CFG_NVIC_PRIO_BITS));} while (0)
  2. #define  CPU_INT_EN()          do { CPU_SR_Restore(cpu_sr); } while (0) /* Restore CPU BASEPRI priority level.          */


  3. #ifdef   CPU_CFG_INT_DIS_MEAS_EN
  4.                                                                         /* Disable interrupts, ...                      */
  5.                                                                         /* & start interrupts disabled time measurement.*/
  6. #define  CPU_CRITICAL_ENTER()  do { CPU_INT_DIS();         \
  7.                                     CPU_IntDisMeasStart(); }  while (0)
  8.                                                                         /* Stop & measure   interrupts disabled time,   */
  9.                                                                         /* ...  & re-enable interrupts.                 */
  10. #define  CPU_CRITICAL_EXIT()   do { CPU_IntDisMeasStop();  \
  11.                                     CPU_INT_EN();          }  while (0)

  12. #else

  13. #define  CPU_CRITICAL_ENTER()  do { CPU_INT_DIS(); } while (0)          /* Disable   interrupts.                        */
  14. #define  CPU_CRITICAL_EXIT()   do { CPU_INT_EN();  } while (0)          /* Re-enable interrupts.                        */

  15. #endif
复制代码


具体实现:
  1. ;********************************************************************************************************
  2. ;                                      CRITICAL SECTION FUNCTIONS
  3. ;
  4. ; Description : Disable/Enable Kernel aware interrupts by preserving the state of BASEPRI.  Generally speaking,
  5. ;               the state of the BASEPRI interrupt exception processing is stored in the local variable
  6. ;               'cpu_sr' & Kernel Aware interrupts are then disabled ('cpu_sr' is allocated in all functions
  7. ;               that need to disable Kernel aware interrupts). The previous BASEPRI interrupt state is restored
  8. ;               by copying 'cpu_sr' into the BASEPRI register.
  9. ;
  10. ; Prototypes  : CPU_SR  CPU_SR_Save   (CPU_SR  new_basepri);
  11. ;               void    CPU_SR_Restore(CPU_SR  cpu_sr);
  12. ;
  13. ; Note(s)     : (1) These functions are used in general like this :
  14. ;
  15. ;                       void  Task (void  *p_arg)
  16. ;                       {
  17. ;                           CPU_SR_ALLOC();                     /* Allocate storage for CPU status register */
  18. ;                               :
  19. ;                               :
  20. ;                           CPU_CRITICAL_ENTER();               /* cpu_sr = CPU_SR_Save();                  */
  21. ;                               :
  22. ;                               :
  23. ;                           CPU_CRITICAL_EXIT();                /* CPU_SR_Restore(cpu_sr);                  */
  24. ;                               :
  25. ;                       }
  26. ;
  27. ;               (2) Increasing priority using a write to BASEPRI does not take effect immediately.
  28. ;                   (a) IMPLICATION  This erratum means that the instruction after an MSR to boost BASEPRI
  29. ;                       might incorrectly be preempted by an insufficient high priority exception.
  30. ;
  31. ;                   (b) WORKAROUND  The MSR to boost BASEPRI can be replaced by the following code sequence:
  32. ;
  33. ;                       CPSID i
  34. ;                       MSR to BASEPRI
  35. ;                       DSB
  36. ;                       ISB
  37. ;                       CPSIE i
  38. ;********************************************************************************************************

  39. CPU_SR_Save
  40.         CPSID   I                               ; Cortex-M7 errata notice. See Note #2
  41.         PUSH   {R1}
  42.         MRS     R1, BASEPRI
  43.         MSR     BASEPRI, R0
  44.         DSB
  45.         ISB
  46.         MOV     R0, R1
  47.         POP    {R1}
  48.         CPSIE   I
  49.         BX      LR


  50. CPU_SR_Restore
  51.         CPSID   I                               ; Cortex-M7 errata notice. See Note #2
  52.         MSR     BASEPRI, R0
  53.         DSB
  54.         ISB
  55.         CPSIE   I
  56.         BX      LR
复制代码



回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106959
QQ
 楼主| 发表于 2019-5-5 11:15:07 | 显示全部楼层
针对这个问题,在FreeRTOS教程的第12章有详细讲解,uCOS这里的处理也是一样的。
QQ截图20190505111408.jpg
回复

使用道具 举报

1

主题

7

回帖

10

积分

新手上路

积分
10
发表于 2020-5-11 23:40:06 | 显示全部楼层
eric2013 发表于 2019-5-5 11:15
针对这个问题,在FreeRTOS教程的第12章有详细讲解,uCOS这里的处理也是一样的。

请问下怎么能看懂uCOS的这些cpu文件啊,有哪些参考资料啊,不知道从哪儿开始
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106959
QQ
 楼主| 发表于 2020-5-12 08:20:29 | 显示全部楼层
glass 发表于 2020-5-11 23:40
请问下怎么能看懂uCOS的这些cpu文件啊,有哪些参考资料啊,不知道从哪儿开始

最新版的只有这个:

基于V5,V6和V7的最新版uCOS-III V3.08.00程序模板,含MDK和IAR两个版本,支持uC/Probe(2020-03-19)
http://www.armbbs.cn/forum.php?m ... 6918&fromuid=58
(出处: 硬汉嵌入式论坛)

老版的看这个:
http://www.armbbs.cn/forum.php?mod=viewthread&tid=1788
回复

使用道具 举报

1

主题

7

回帖

10

积分

新手上路

积分
10
发表于 2020-5-12 15:49:31 | 显示全部楼层
eric2013 发表于 2020-5-12 08:20
最新版的只有这个:

基于V5,V6和V7的最新版uCOS-III V3.08.00程序模板,含MDK和IAR两个版本,支持uC/ ...

谢谢 xd
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-12 04:33 , Processed in 0.250920 second(s), 36 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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