硬汉嵌入式论坛

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

[FreeRTOS] FreeRTOS的配置选项configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY说明

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106746
QQ
发表于 2015-8-18 17:23:34 | 显示全部楼层 |阅读模式
这个选项使用的时候要注意如下问题,不注意会导致系统死机:
=======================================================================

/* The highest interrupt priority that can be used by any interrupt service
routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY    5
=======================================================================
官方说明看这个帖子:
http://www.freertos.org/RTOS-Cortex-M3-M4.html
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106746
QQ
 楼主| 发表于 2015-8-18 17:26:54 | 显示全部楼层
这个配置选项使用的是寄存器basepri。FreeRTOS中开关中断使用的是这个寄存器,而uCOS使用的PRIMASK。
2.png
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106746
QQ
 楼主| 发表于 2015-8-18 17:30:32 | 显示全部楼层
为了防止客户配置错这个选项,官方的demo里面一般都有一个如下的配置断言:

#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106746
QQ
 楼主| 发表于 2015-8-21 11:59:30 | 显示全部楼层
/* RTOS ports that support interrupt nesting have the concept of a
        maximum    system call (or maximum API call) interrupt priority.
        Interrupts that are    above the maximum system call priority are keep
        permanently enabled, even when the RTOS kernel is in a critical section,
        but cannot make any calls to FreeRTOS API functions.  If configASSERT()
        is defined in FreeRTOSConfig.h then
        portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
        failure if a FreeRTOS API function is called from an interrupt that has
        been assigned a priority above the configured maximum system call
        priority.  Only FreeRTOS functions that end in FromISR can be called
        from interrupts    that have been assigned a priority at or (logically)
        below the maximum system call interrupt priority.  FreeRTOS maintains a
        separate interrupt safe API to ensure interrupt entry is as fast and as
        simple as possible.  More information (albeit Cortex-M specific) is
        provided on the following link:
        http://www.freertos.org/RTOS-Cortex-M3-M4.html */
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106746
QQ
 楼主| 发表于 2015-8-21 12:05:29 | 显示全部楼层
#if( configASSERT_DEFINED == 1 )


    void vPortValidateInterruptPriority( void )
    {
    uint32_t ulCurrentInterrupt;
    uint8_t ucCurrentPriority;


        /* Obtain the number of the currently executing interrupt. */
        ulCurrentInterrupt = vPortGetIPSR();


        /* Is the interrupt number a user defined interrupt? */
        if( ulCurrentInterrupt >= portFIRST_USER_INTERRUPT_NUMBER )
        {
            /* Look up the interrupt's priority. */
            ucCurrentPriority = pcInterruptPriorityRegisters[ ulCurrentInterrupt ];


            /* The following assertion will fail if a service routine (ISR) for
            an interrupt that has been assigned a priority above
            configMAX_SYSCALL_INTERRUPT_PRIORITY calls an ISR safe FreeRTOS API
            function.  ISR safe FreeRTOS API functions must *only* be called
            from interrupts that have been assigned a priority at or below
            configMAX_SYSCALL_INTERRUPT_PRIORITY.


            Numerically low interrupt priority numbers represent logically high
            interrupt priorities, therefore the priority of the interrupt must
            be set to a value equal to or numerically *higher* than
            configMAX_SYSCALL_INTERRUPT_PRIORITY.


            Interrupts that    use the FreeRTOS API must not be left at their
            default priority of    zero as that is the highest possible priority,
            which is guaranteed to be above configMAX_SYSCALL_INTERRUPT_PRIORITY,
            and    therefore also guaranteed to be invalid.


            FreeRTOS maintains separate thread and ISR API functions to ensure
            interrupt entry is as fast and simple as possible.


            The following links provide detailed information:
            http://www.freertos.org/RTOS-Cortex-M3-M4.html
            http://www.freertos.org/FAQHelp.html */
            configASSERT( ucCurrentPriority >= ucMaxSysCallPriority );
        }


        /* Priority grouping:  The interrupt controller (NVIC) allows the bits
        that define each interrupt's priority to be split between bits that
        define the interrupt's pre-emption priority bits and bits that define
        the interrupt's sub-priority.  For simplicity all bits must be defined
        to be pre-emption priority bits.  The following assertion will fail if
        this is not the case (if some bits represent a sub-priority).


        If the application only uses CMSIS libraries for interrupt
        configuration then the correct setting can be achieved on all Cortex-M
        devices by calling NVIC_SetPriorityGrouping( 0 ); before starting the
        scheduler.  Note however that some vendor specific peripheral libraries
        assume a non-zero priority group setting, in which cases using a value
        of zero will result in unpredicable behaviour. */
        configASSERT( ( portAIRCR_REG & portPRIORITY_GROUP_MASK ) <= ulMaxPRIGROUPValue );
    }


#endif /* configASSERT_DEFINED */
回复

使用道具 举报

334

主题

2032

回帖

3039

积分

版主

Rank: 7Rank: 7Rank: 7

积分
3039
发表于 2015-8-21 14:04:04 | 显示全部楼层
这个说明的英语好难懂。。。。

貌似都说了一个意思,RTOS自己有个中断级别,比它级别更高的中断会一直打开,关闭不了。

如果中断级别比RTOS的高,在这个中断函数中不能调用RTOS的函数。自己写的函数就没问题。
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106746
QQ
 楼主| 发表于 2015-8-21 16:52:18 | 显示全部楼层

回 caicaptain2 的帖子

caicaptain2:这个说明的英语好难懂。。。。

貌似都说了一个意思,RTOS自己有个中断级别,比它级别更高的中断会一直打开,关闭不了。

如果中断级别比RTOS的高,在这个中断函数中不能调用RTOS的函数。自己写的函数就没问题。
....... (2015-08-21 14:04) 
[s:151]
理解很到位。
另外我发现注释代码的人喜欢用英语从句,读起来比较绕。
回复

使用道具 举报

0

主题

13

回帖

13

积分

新手上路

积分
13
发表于 2015-10-26 16:12:30 | 显示全部楼层
请问怎么理解“FreeRTOS maintains separate thread and ISR API functions to ensure interrupt entry is as fast and simple as possible”呢?
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106746
QQ
 楼主| 发表于 2015-10-26 19:32:01 | 显示全部楼层

回 文刀言身寸 的帖子

文刀言身寸:请问怎么理解“FreeRTOS maintains separate thread and ISR API functions to ensure interrupt entry is as fast and simple as possible”呢? (2015-10-26 16:12) 
这里主要是指中断里面调用的API函数和任务里面调用的API进行了分开操作,中断里面调用的函数都是以xxxFromISR结尾的。
回复

使用道具 举报

0

主题

13

回帖

13

积分

新手上路

积分
13
发表于 2015-10-27 09:21:19 | 显示全部楼层

回 eric2013 的帖子

eric2013:这里主要是指中断里面调用的API函数和任务里面调用的API进行了分开操作,中断里面调用的函数都是以xxxFromISR结尾的。 (2015-10-26 19:32) 
thanks
回复

使用道具 举报

0

主题

3

回帖

0

积分

新手上路

积分
0
发表于 2015-10-29 17:00:05 | 显示全部楼层
为什么前面说中断里面不能调用API函数,而这里又说“中断里面调用的函数都是以xxxFromISR结尾的”??????好像有点矛盾
回复

使用道具 举报

0

主题

3

回帖

0

积分

新手上路

积分
0
发表于 2015-10-29 17:22:38 | 显示全部楼层

回 eric2013 的帖子

eric2013:这里主要是指中断里面调用的API函数和任务里面调用的API进行了分开操作,中断里面调用的函数都是以xxxFromISR结尾的。(2015-10-26 19:32)嬀/color]
什么情况可以调用,,,什么情况不可以调用???并且自己设置中断优先级比configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY高以及低,中断处理函数都会执行,,,,,,是不是哪里没定义正确???????
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106746
QQ
 楼主| 发表于 2015-10-29 17:48:49 | 显示全部楼层

回 wuyuwei 的帖子

wuyuwei:什么情况可以调用,,,什么情况不可以调用???并且自己设置中断优先级比configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY高以及低,中断处理函数都会执行,,,,,,是不是哪里没定义正确???????
 (2015-10-29 17:22) 
看我在这个帖子里面的回复,有什么问题话,可以交流下
http://www.armbbs.cn/forum.php?mod=viewthread&tid=15063
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-3 22:11 , Processed in 0.215938 second(s), 34 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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