前言
/ A. I+ e5 m$ J3 k本篇文章带大家了解FreeRTOS里面的FreeRTOSConfig.h文件,此文基于正点原子FreeRTOS手册讲解。; ~8 v: G- z! H, K. s. {
7 |5 v- n& V, ~
一、文件讲解 n& E7 s' ?$ ^* H/ [3 Q
源码:
: Q O0 |" Y; N r& u H7 V# B! X# ?& v/ j
- /* USER CODE BEGIN Header */
: B" T7 w8 _2 b* V, n' E - /*
, b, ]" @ M) N) ^5 K - * FreeRTOS Kernel V10.0.14 B( ^) Z" R6 [. g* S0 n* Z- E4 l
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.' U. [/ m/ b6 P5 F; H
- *
! e: Y: k1 b3 a8 N ]. f8 i, Q - * Permission is hereby granted, free of charge, to any person obtaining a copy of2 P; t' F; Z& B- s: H3 y2 V
- * this software and associated documentation files (the "Software"), to deal in( |1 U4 h% u4 T' Y( B8 m( ?
- * the Software without restriction, including without limitation the rights to! U8 _' X0 Y3 J/ R
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
B9 q8 \# b8 g3 E# ~ - * the Software, and to permit persons to whom the Software is furnished to do so,/ [$ `- U0 R( g& k, f6 r
- * subject to the following conditions:6 D& N3 l2 H+ q/ `, W
- *+ w4 S$ E8 A& w) [0 L1 Z' B
- * The above copyright notice and this permission notice shall be included in all
" U) O3 V! \( W$ j- N - * copies or substantial portions of the Software.
+ e8 T& u- O* ~( X/ n5 g2 e - *
: @/ I) f' f: C4 ^ - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR$ U8 c8 C9 V0 M- e {3 E7 N
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS" {! }; ^" j% x* R9 D1 I* u0 |
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR# N. ^; i$ g& O9 i
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
" I+ @6 S, l; p0 S0 _, ~# a - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN! K9 a* y- W% P' r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.6 F" ~- J6 P( m2 {
- *) v$ }7 O. C2 A1 d/ w
! ?* p1 f! W# e* c1 m; a- O- *
! P( z# s, l4 o - * 1 tab == 4 spaces!5 Q) Q5 m0 k+ f5 T* L" Z) f
- */; `& |4 r) b- w G* q
- /* USER CODE END Header */
( g: W" H! c; a/ k, T8 m - 5 d% Z# a* Y4 {, c1 w5 @ p
- #ifndef FREERTOS_CONFIG_H
+ j6 ^: }0 m" i" ^; V8 N% } - #define FREERTOS_CONFIG_H8 R8 G" l& l5 z3 c P/ j3 ?
- 0 H5 Z- D# R+ o9 S4 k6 r: k7 [3 V
- /*-----------------------------------------------------------( L* k8 q* l: q+ h2 c4 v
- * Application specific definitions./ e, n# h2 E$ f& S
- *$ i- H" I+ B" E/ a y
- * These definitions should be adjusted for your particular hardware and' v i( E: [7 P: B' @
- * application requirements.
6 H5 `' N# E9 A" A" S - *( y& y/ C7 ~+ N
- * These parameters and more are described within the 'configuration' section of the; {0 M! H, U! h* d+ d u& v, b
- * FreeRTOS API documentation available on the FreeRTOS.org web site.2 K+ h; d7 C; h! l% a' K
- *
# p: J+ \# l6 v9 C
3 b; V: D* y. R6 F! q5 W4 B- *----------------------------------------------------------*/
: s% A( a% O; m- o8 \$ H - 5 x; U$ D4 _! g) N9 R
- /* USER CODE BEGIN Includes */$ S: r' d* W3 { f/ v
- /* Section where include file can be added */0 Z b$ H( W. K2 Z9 U9 H4 h
- /* USER CODE END Includes */
0 [2 h3 e( t$ F' q - 6 z! d- M* m1 E; o" ~0 `# v1 ]8 o8 q
- /* Ensure definitions are only used by the compiler, and not by the assembler. */
/ d; k) Z$ [% |6 S* F: { f2 M - #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)6 @( c& F$ Q J! {1 M) ?+ W
- #include <stdint.h>9 j3 @! \/ e9 J
- extern uint32_t SystemCoreClock;
- U2 m) T! x" r. ]6 u2 h - #endif1 {7 F- Z7 y1 Q) Q8 j
- #define configUSE_PREEMPTION 1
_& I( P) @* x0 ? - #define configSUPPORT_STATIC_ALLOCATION 1% v/ P. K% p+ }! ?& ~
- #define configSUPPORT_DYNAMIC_ALLOCATION 16 Q9 q" `0 Q5 T# Z, G+ a* P
- #define configUSE_IDLE_HOOK 0
: S- ~& F% t1 G: m3 ^ - #define configUSE_TICK_HOOK 0
! ] G6 u+ u/ \: [ a/ Q; l - #define configCPU_CLOCK_HZ ( SystemCoreClock )3 l* X! Q/ X) a9 l$ \9 l$ d
- #define configTICK_RATE_HZ ((TickType_t)1000)
+ O. B% E8 O& p3 Z - #define configMAX_PRIORITIES ( 7 )
5 r$ w) |+ [: Z+ T4 [) F$ | - #define configMINIMAL_STACK_SIZE ((uint16_t)128)6 u& ~1 c7 ?, T4 [1 ~0 ^( M3 s
- #define configTOTAL_HEAP_SIZE ((size_t)3072)
2 v! O$ K) g9 L0 b) }. ?6 ` - #define configMAX_TASK_NAME_LEN ( 16 )
+ l( g0 I) P! w, T - #define configUSE_16_BIT_TICKS 0
( h, K* G H% y" c# ?( b5 l - #define configUSE_MUTEXES 1( _* R }' N/ D+ s2 u6 |8 A; {
- #define configQUEUE_REGISTRY_SIZE 8
3 e3 c8 \; x/ Y2 V% W. a - #define configUSE_PORT_OPTIMISED_TASK_SELECTION 18 S! Z& V. d. g
- 6 i$ J% x+ u& x4 ]/ ^
- /* Co-routine definitions. */4 l3 M6 h+ _0 M; ?/ n" G/ a- Z
- #define configUSE_CO_ROUTINES 0, D1 K( h7 r$ L. L/ D$ w" {3 F/ g3 o3 P$ v
- #define configMAX_CO_ROUTINE_PRIORITIES ( 2 )% h% A. P: v7 z, G* W& n( z- ^
- ! j: }) H1 u6 F. @5 k/ G& T$ P; W7 H
- /* Set the following definitions to 1 to include the API function, or zero
- f, O3 {0 G1 g; x" F/ J! {9 E - to exclude the API function. */7 f4 Y2 s% O2 k2 \. ~9 i
- #define INCLUDE_vTaskPrioritySet 1; @1 S% A. L- ]# Q4 P
- #define INCLUDE_uxTaskPriorityGet 1
9 w$ l2 J6 g( X3 i. \. t5 s7 B - #define INCLUDE_vTaskDelete 13 {, f2 ?$ B/ I/ @$ @2 ]9 d% q
- #define INCLUDE_vTaskCleanUpResources 0% J5 a$ a* {: [; l% Z7 o$ B- H
- #define INCLUDE_vTaskSuspend 1# P# ]# q8 r4 `; E% K2 L! M
- #define INCLUDE_vTaskDelayUntil 0
6 K1 i; K! m- @" c& r. N - #define INCLUDE_vTaskDelay 1
7 I# Q* \$ g0 _6 V9 o+ v. {4 J - #define INCLUDE_xTaskGetSchedulerState 1: j2 @1 x! B v- s9 I8 I8 N
/ P* B( x& h$ ?- 3 W( [+ \" j q1 q$ `2 a
- //Tickless5 _% r2 I K* [/ m5 n0 K5 N- g
- #define configUSE_TICKLESS_IDLE 1//启用tickless低功耗' Y, y; t2 F# m3 D9 a& K
- #define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 3- \1 j+ g* C/ I( _' {
- 0 B% v! E+ N0 Y! n; }2 @ W
- /* Cortex-M specific definitions. */
2 ?, n. j6 P: _9 \7 ~" I5 W - #ifdef __NVIC_PRIO_BITS) s# T) G" ^% o7 q* B7 O/ O
- /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
+ y; v8 Y0 z- L - #define configPRIO_BITS __NVIC_PRIO_BITS( z4 _* F& [) E' @) M' i! A- l
- #else
/ `, {$ ^5 O% h' T4 b+ O - #define configPRIO_BITS 4
* K$ G, y# Q' B9 M" @9 p - #endif( f# v I) p9 d x9 D- Z5 `
, g- j+ ~" z+ M: |: }: z C I- /* The lowest interrupt priority that can be used in a call to a "set priority"; ?1 F/ M& u0 Z5 j8 A
- function. */
) B* p. m/ u# h& D - #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 155 A, R2 v/ v; I0 J- ^2 Z
- 7 r1 K4 X9 G6 t: |) z' ]
- /* The highest interrupt priority that can be used by any interrupt service
7 R- F- y, A; {4 P+ C - routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL" |0 p/ ^' a& x8 ?: p! j* D
- INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER' D l" a3 |: a1 Q: j; g' Q
- PRIORITY THAN THIS! (higher priorities are lower numeric values. */
' y( U: c5 e9 P3 Y8 [) q. r - #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
7 {! z& \+ {0 P# b A/ u& j
3 f: B$ u7 d8 u- c f' Y- /* Interrupt priorities used by the kernel port layer itself. These are generic- l# _" ?' t- J- ~( K
- to all Cortex-M ports, and do not rely on any particular library functions. */$ g% P. C$ Y4 d7 R6 n# y
- #define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )/ e! [; X# \. G" t. h) N# \
- /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
0 P/ n2 J+ o5 d3 m - See <a href="http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html." target="_blank">http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html.</a> */
' R1 a# T9 i! {% G& x+ O0 f - #define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )0 O9 [7 b1 F/ u) v- R3 J( ^3 K: C
- + j' \0 S# N. c
- /* Normal assert() semantics without relying on the provision of an assert.h! S. d9 m# D0 D5 z4 c
- header file. */" {( I" _# t }! s5 t
- /* USER CODE BEGIN 1 */
. R$ D1 @3 ]+ C, q4 ]0 i! ? | - #define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}3 K9 E% X5 j. x6 ^+ d$ G' G2 q
- /* USER CODE END 1 */# q6 e3 K, L' v( o5 Y- a( s6 C- ^
' a0 ^4 x1 b) J" ~+ U- @- /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS9 L" [+ l1 `' ]/ N
- standard names. */
" x7 h9 w$ w+ F1 Q( n( b: B - #define vPortSVCHandler SVC_Handler# F( k% l+ Q) C" U$ M
- #define xPortPendSVHandler PendSV_Handler; ?( G: Y8 F1 n0 n
7 f& Y5 v( a& `) b+ p. }/ S- /* IMPORTANT: This define is commented when used with STM32Cube firmware, when the timebase source is SysTick,( p& C$ q7 a- G0 S
- to prevent overwriting SysTick_Handler defined within STM32Cube HAL */; b7 i! X( v! B) r& K- ]' T
' `" S$ {/ L! i) D, t% G- #define xPortSysTickHandler SysTick_Handler9 A2 ]! F, a! H
9 L5 S$ }( H1 i( [- k6 U2 @% K9 o- /* USER CODE BEGIN Defines */; j5 b/ [2 M( d$ G( w- z
- /* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */9 m% S0 c6 v0 Z
- /* USER CODE END Defines */
9 v ~' [2 H. m; j1 A) Q) R1 | - ( H5 e- m2 t3 K- _+ e
- #endif /* FREERTOS_CONFIG_H */
8 @: O# J# i$ M$ ^
复制代码 5 f, ?8 |2 d/ Z/ K
FreeRTOS 的配置基本是通过在 FreeRTOSConfig.h 中使用“#define”这样的语句来定义宏定义实现的。
" v* q5 ?9 f2 V; Q4 M) k2 }这些宏定义都有特殊的含义,我们就调其中一个讲解。- #define configGENERATE_RUN_TIME_STATS 1
5 d" `) F# O( P r* r. O5 e
复制代码
2 ]) s% \6 V' b3 Q7 m; g: e+ b将此宏设置为1开启时间统计功能,相应的 API 函数会被编译,为 0 时关闭时间统计功能。
) ~' @* {' k" y! Z其他的宏作用也和这个差不多,当设置为1时就可以使能某些函数,设置为0函数就不可用。6 C# J1 i$ h- ~. W+ M% a4 Y& |6 p. n
其他宏大家可以自己看看,一般cubeMX生成代码后都会自动配置一些宏。
, L5 D" c |# N/ L8 Z& }; Z+ n) s/ J" W. u' n- }7 r$ j
总结, _' `5 _- b+ a$ y
FreeRTOSConfig.h文件简单解析就到这里。
! T# j' c% A4 b
4 ?0 S, u3 @6 d) Y! [8 O @4 E% X B( c. A5 L$ W2 J
|