前言# @" O$ g9 d- J! e- q6 E ~! z4 h
本篇文章带大家了解FreeRTOS里面的FreeRTOSConfig.h文件,此文基于正点原子FreeRTOS手册讲解。; D9 v* N7 F* Z: v
( g( p! L% `2 {一、文件讲解
' K+ N7 j3 m* q; c/ e" B# i9 a W源码:
: \) c) J# y1 A) E7 N0 T" r$ v6 H. Y& W4 r# D
- /* USER CODE BEGIN Header */
' U6 S1 j. B- @( K6 h4 o! q - /*! K" P+ M1 p, J1 t: O7 u
- * FreeRTOS Kernel V10.0.1+ ?/ K% |; O* v: j- { t& A' w
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
; W* L Z, o$ N$ j& ~) `% p - *3 R9 r+ L0 U( u M
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
2 i( O& b! t% T$ Z" m2 c - * this software and associated documentation files (the "Software"), to deal in$ Z" v3 d- {2 F+ u6 |& Y2 _. L6 M
- * the Software without restriction, including without limitation the rights to* Q) B; n4 |) G& A
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
5 \/ @6 J4 ]# T' z - * the Software, and to permit persons to whom the Software is furnished to do so,
' @9 w1 y p _6 z - * subject to the following conditions:' L/ o4 g; f: ?7 @9 ~. ?) O
- *. ?. r8 m+ v- r* {' [
- * The above copyright notice and this permission notice shall be included in all
, c {9 z8 X) O1 R - * copies or substantial portions of the Software.. y+ V$ F9 q: m
- *
0 d6 \! m6 V0 _7 E( g/ d - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR9 h+ T, X' n9 U; I4 n: O4 k4 `" `. Q
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
4 G w% z# A7 P5 Q0 C3 _& I& [ - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR0 ^2 }5 S6 g; L/ ?+ n5 I
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
7 H' L: W, s y% G; a5 k - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
' P x7 H/ _0 }% e - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.+ y0 T2 u2 [) q+ M# X- y
- *9 U! K. A, g- J1 i8 a& L5 ^5 W% G
- % R) z" }8 ?5 M; G' `5 j7 ]8 p
- *
/ S8 l+ g4 r7 b' J4 f5 T - * 1 tab == 4 spaces!
+ Q% g* b* g0 u5 I5 o - */ [* q% E* X0 E! U7 H8 f% o
- /* USER CODE END Header */; G3 p! B( a& z1 r' X
1 ] b0 I/ C2 \$ k# s/ m' }/ h- #ifndef FREERTOS_CONFIG_H
4 U- w. V" x* E' m - #define FREERTOS_CONFIG_H* m! v, B) G7 k
- ; _- E1 s& @) Y X6 F
- /*-----------------------------------------------------------$ e( w, Y J9 C
- * Application specific definitions.
; X% w* }6 n `+ l; H ^* c - *
% n3 K \: C0 l5 S3 b, X4 L7 k, y - * These definitions should be adjusted for your particular hardware and. c& ?3 x7 C* S
- * application requirements./ d( a( |9 X8 F
- *! y+ R9 r1 p4 f) p/ q4 B
- * These parameters and more are described within the 'configuration' section of the
% o9 v3 j& _/ x( |# @: p1 l - * FreeRTOS API documentation available on the FreeRTOS.org web site.( w ~9 |5 `! A, `7 C. ~
- *
; h6 L; y, s! Z' e4 ]0 d+ l
/ O) Q# E' D, ^6 `- *----------------------------------------------------------*/& n& J7 F0 F4 N; G0 `& Z7 g0 {
- ; x* m p3 n" M
- /* USER CODE BEGIN Includes */
; @5 ?; S5 W! I - /* Section where include file can be added */
& h& M9 G. d5 d B - /* USER CODE END Includes */
& o2 v; I, J9 E/ G6 y - % A5 H$ u6 q5 k7 E" ^* d/ o5 R
- /* Ensure definitions are only used by the compiler, and not by the assembler. */
3 [ f& K' U3 ^! a - #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)8 {; `- M2 G8 g; k
- #include <stdint.h>
' b* R8 ?# h& H1 ?& j( W) B - extern uint32_t SystemCoreClock;
. ]" V6 y( l+ j4 o) J7 } - #endif
; P( Y1 X3 E& o# s" @# [ - #define configUSE_PREEMPTION 1
P7 h/ J3 N2 E5 K1 u - #define configSUPPORT_STATIC_ALLOCATION 16 u2 d; h8 U: S+ n# U4 T
- #define configSUPPORT_DYNAMIC_ALLOCATION 1
# D( J: C0 \9 s - #define configUSE_IDLE_HOOK 06 L3 _. Z# u0 ~) L" `9 l
- #define configUSE_TICK_HOOK 0
2 T( A) M( h0 ~% B( `- m% M - #define configCPU_CLOCK_HZ ( SystemCoreClock )
, j+ R# Q1 V7 o* a7 f2 G: r - #define configTICK_RATE_HZ ((TickType_t)1000)
4 |+ P2 C" Q1 t9 Y' a0 O - #define configMAX_PRIORITIES ( 7 )
2 H1 B# \0 S5 ]- d4 W! q - #define configMINIMAL_STACK_SIZE ((uint16_t)128)4 ?4 }: [6 x8 t: Z* D% C
- #define configTOTAL_HEAP_SIZE ((size_t)3072)
0 j% v1 @0 |: F8 k9 @, C Y6 C - #define configMAX_TASK_NAME_LEN ( 16 )7 e5 C! ?- q9 } B
- #define configUSE_16_BIT_TICKS 0
n3 p, e- ?+ j! [% }# w0 h - #define configUSE_MUTEXES 1
/ U, J# z! Z/ s E - #define configQUEUE_REGISTRY_SIZE 8) B' X X0 R5 q) A
- #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
; ]/ x3 z. Y, _4 @3 M9 h - ' L9 E8 O# M' o
- /* Co-routine definitions. */
+ a+ f6 d* u2 Z' f* t# ]' H) h: D - #define configUSE_CO_ROUTINES 0
$ e% Z! R) ^( h - #define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
" z( E; U3 F+ Q: G6 l
- A5 z- e$ O6 E8 R& ^( w- /* Set the following definitions to 1 to include the API function, or zero, g; z* Y+ J6 l6 p7 w' q
- to exclude the API function. */
- b) `2 b. a, P' x7 E, ~6 M& x - #define INCLUDE_vTaskPrioritySet 1. z7 r, F. j& V+ @$ X9 Y3 W4 m0 Q
- #define INCLUDE_uxTaskPriorityGet 1
, d; Q7 n2 q: o$ X - #define INCLUDE_vTaskDelete 1
. n% w$ w* [" C& ?0 g y. S$ e - #define INCLUDE_vTaskCleanUpResources 0
/ T( z3 H( w( G' K h. u - #define INCLUDE_vTaskSuspend 1
( T1 E" K0 q/ D& {' Z" Q7 b - #define INCLUDE_vTaskDelayUntil 0; V+ C: J. n( }2 w$ P* Q3 K
- #define INCLUDE_vTaskDelay 1
5 {1 s% ?+ U- X- }- c$ @ - #define INCLUDE_xTaskGetSchedulerState 1+ V/ k. L3 {% r4 n' Y
- , G9 C$ e2 o$ d1 o
- . ^9 _, K6 z8 G
- //Tickless
* n5 e" Q% r, u& ] - #define configUSE_TICKLESS_IDLE 1//启用tickless低功耗/ I1 J$ @$ Q: R5 P( f1 I' h" j: e9 C0 ~
- #define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 35 _/ S. @! G6 L- t$ f* i
- : C7 F9 M9 w* b" F( B4 j
- /* Cortex-M specific definitions. */
$ K( s6 L. [4 Z/ R - #ifdef __NVIC_PRIO_BITS
% w8 j6 Y4 g8 p: m6 [. ~ - /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */0 l2 }2 v2 _, B2 i$ n T
- #define configPRIO_BITS __NVIC_PRIO_BITS
& g+ o! z2 G1 e+ b, R' c - #else; p L& _3 T6 }: J
- #define configPRIO_BITS 4
% m; |+ D* q& Z% E - #endif8 y. P' a; v, p, ^
" p8 x& M! h/ I; v- /* The lowest interrupt priority that can be used in a call to a "set priority"' p: I @2 n+ b0 I0 J
- function. */
b2 X s- Y4 @9 D. r$ D - #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15
5 z) L. O5 G. v - 7 K/ A S! X. Q! M
- /* The highest interrupt priority that can be used by any interrupt service
) G z4 B. e' j; y8 N0 { - routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
9 T: I8 w( ]7 _% y - INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
0 I8 }- _" y7 i) b) e' J p - PRIORITY THAN THIS! (higher priorities are lower numeric values. */+ b( \ U3 @0 y$ w1 s. h+ B5 O
- #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
/ Q7 N9 e- `. v# u+ E1 v: N0 E! R3 g
0 \3 b( w0 M J4 `8 k& y6 R- O4 o7 b- /* Interrupt priorities used by the kernel port layer itself. These are generic* R) B4 u5 q4 R4 e9 Z. `1 l- T, F9 ?
- to all Cortex-M ports, and do not rely on any particular library functions. */
5 P4 W4 K; o$ P: s - #define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )% F6 q% l. n' Z# d5 _" I
- /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
( n# d8 p% W% G4 R" s# p2 Z1 _ - See <a href="http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html." target="_blank">http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html.</a> */% R2 Y! c. U2 r6 p
- #define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
' o) `' f4 q6 k( m" e6 D - " M5 k. \. ^& `8 ?9 z" J' [
- /* Normal assert() semantics without relying on the provision of an assert.h+ T- g4 p/ V5 ]0 b1 W% `
- header file. */% U ^! P0 D+ D2 B
- /* USER CODE BEGIN 1 */" ^5 N: Z2 l( D2 H& s
- #define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}
/ {. N# z# h. W$ d( y* U' z/ o% @ - /* USER CODE END 1 */1 `0 y4 R" t3 B! Q
- 0 ?0 k* i2 w* V! @+ \5 m2 A
- /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS4 ^: }" C6 y5 S% N" D; A
- standard names. */. C) Q+ K# Q5 P( M* d- \: L
- #define vPortSVCHandler SVC_Handler
6 E% _8 e: G* d - #define xPortPendSVHandler PendSV_Handler0 a5 m* R, C. z j: h+ X% i
- 2 t0 K7 B2 X E# s' i2 Q" v- e8 w6 G$ }
- /* IMPORTANT: This define is commented when used with STM32Cube firmware, when the timebase source is SysTick,2 c) b/ \0 K4 E. P$ q& e
- to prevent overwriting SysTick_Handler defined within STM32Cube HAL */3 M+ V: b* s7 z- K4 R3 o
8 Y! E7 A5 J# s6 d" E% Y& }/ R$ X- #define xPortSysTickHandler SysTick_Handler
" c1 {; E) B, x- ]6 S4 Z - * ]6 V. I; U% O( B" q
- /* USER CODE BEGIN Defines */
9 u/ _1 \+ m9 i; P' ` - /* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */
. m2 R, z. j, q/ ~- y/ h. g - /* USER CODE END Defines */
x+ B) l. `+ ]
$ C% r5 `; T6 H- #endif /* FREERTOS_CONFIG_H */
$ j, _* [; k- i I0 W
复制代码
3 i1 F+ B: q) C( I. M% B1 l; wFreeRTOS 的配置基本是通过在 FreeRTOSConfig.h 中使用“#define”这样的语句来定义宏定义实现的。: L1 N3 F6 ^0 P4 u7 E; e' U
这些宏定义都有特殊的含义,我们就调其中一个讲解。- #define configGENERATE_RUN_TIME_STATS 1
' M" ]: t! X, k) r7 n' Z1 H3 e
复制代码
0 j+ S$ _1 i% n7 F$ T$ y将此宏设置为1开启时间统计功能,相应的 API 函数会被编译,为 0 时关闭时间统计功能。
4 r h6 x) X3 l, L其他的宏作用也和这个差不多,当设置为1时就可以使能某些函数,设置为0函数就不可用。
|5 m" Y6 @0 x5 W* N其他宏大家可以自己看看,一般cubeMX生成代码后都会自动配置一些宏。6 l) l$ F$ z4 k
( \: o6 h( j* X5 G. C' T+ |7 E
总结; X9 j) z4 u: [' H, I
FreeRTOSConfig.h文件简单解析就到这里。: g0 P4 X( ~( l" o
' C3 W& P7 b* K: D
) `) ]1 I ^/ f# z: i& x0 Y
|