前言
" X% Q Q) P3 [, k- O- i- F8 D本篇文章带大家了解FreeRTOS里面的FreeRTOSConfig.h文件,此文基于正点原子FreeRTOS手册讲解。* t" }; \/ H+ \" J
, A0 ~- n# l5 k9 M# @一、文件讲解
* Y2 {7 n8 j: L源码:
7 @) M$ {# Z6 O% s7 _. I
- m8 I8 k3 C/ d0 U8 ?) ^- /* USER CODE BEGIN Header */. K* K2 X; f2 ]2 D; Y9 p: U; B
- /*
! k2 |4 G* @# `8 n' ~% a; e - * FreeRTOS Kernel V10.0.1
, o& d* J% T) H! I6 l! z4 E/ r x - * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.1 B( T7 w; p( R1 \; K" g
- *
: ]; i# Z- x! W! u4 O4 R4 p1 h$ N - * Permission is hereby granted, free of charge, to any person obtaining a copy of
7 s+ v; O% V2 f3 ?9 _. a( L - * this software and associated documentation files (the "Software"), to deal in
5 T2 Z3 q6 h" t: y8 [. ~ - * the Software without restriction, including without limitation the rights to, I& c5 X9 e2 e/ N
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
4 I" G! t K/ b! B& w1 R' _ - * the Software, and to permit persons to whom the Software is furnished to do so,8 a! j* q4 U3 i' x1 O1 Q, n
- * subject to the following conditions:
. ~7 C$ L c0 n8 h) G P - *
" j5 B" E3 M* V5 z2 ]% x8 R- K( C - * The above copyright notice and this permission notice shall be included in all7 i1 N; V0 {& O4 T
- * copies or substantial portions of the Software.6 T/ ^: o4 U7 U
- *
1 S0 s& O4 l M1 s6 L - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR$ d, I- v$ C# w. G" Z; a
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# o8 S* z" @. f; i) V( T - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR7 t0 g6 c0 h7 E: s1 `
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER- M! k& K1 R; Y# H$ }" V/ o
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
9 B( ~% c, `4 E& ^ - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.! W" `0 U1 `6 |0 R: w @
- *2 F: F: O9 ?1 o! ^) K2 U* f! D
- p! i: [' s+ \4 K3 g
- *
1 [1 O. t! Z& R - * 1 tab == 4 spaces!. |1 B `! z3 u2 H
- */
0 x) r9 t- [$ K4 Q. `; F - /* USER CODE END Header */
( ?& T6 c, ~: }& k - 9 H+ m2 P x% b6 g
- #ifndef FREERTOS_CONFIG_H
5 F( Q" r. r6 Y - #define FREERTOS_CONFIG_H( f5 c: o6 F7 {
- " e! U- a3 F, K B% e) v5 c
- /*-----------------------------------------------------------, c" d# |# G% U& @
- * Application specific definitions.* y V: s8 G- p/ C# V
- *. L. S' a1 r* l5 b
- * These definitions should be adjusted for your particular hardware and
, Z/ O: C. {; T# M3 E2 u- N% l - * application requirements.
6 e) V' u' o/ x) G3 Z% F - *
% X# t2 F, v2 _ - * These parameters and more are described within the 'configuration' section of the
6 s; T" }& P' {2 N$ }6 K - * FreeRTOS API documentation available on the FreeRTOS.org web site.
9 y+ s) k$ }0 G - *& h' v- n& R$ t+ J' w
- , e. A2 `) d, g q) c: v
- *----------------------------------------------------------*/5 _4 [) C* ^3 _$ u# C/ S% G; G
# y1 e2 @6 |$ j. \1 O2 l0 ], b, T: u# u- /* USER CODE BEGIN Includes */
f8 q/ w$ J% v$ u, t - /* Section where include file can be added */
3 ~( D* q; V7 f4 a R, h - /* USER CODE END Includes */5 Q+ A* |9 M% B; c, ?5 b
- # W8 A' ~ l$ b
- /* Ensure definitions are only used by the compiler, and not by the assembler. */$ U- N% U8 v: a* j$ T
- #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__): G U% y7 G2 B' L& W& {
- #include <stdint.h>7 i$ u, D) d4 U. {& F2 Z) b
- extern uint32_t SystemCoreClock;
" w5 v! E( I7 f( b - #endif; V8 r( N/ V1 ]% A) m2 q
- #define configUSE_PREEMPTION 17 G8 H( i) s& T7 D9 l1 G6 x: L
- #define configSUPPORT_STATIC_ALLOCATION 1
5 d7 V; @+ F$ L! j% k, s; ] - #define configSUPPORT_DYNAMIC_ALLOCATION 13 e+ d7 d9 a4 T. l9 S
- #define configUSE_IDLE_HOOK 0
4 I0 Y. j) G. Q3 x. x - #define configUSE_TICK_HOOK 09 ^4 H4 z0 @$ Y$ ^( z9 y8 J* S& r
- #define configCPU_CLOCK_HZ ( SystemCoreClock )
7 q5 R: D- w1 ~8 m - #define configTICK_RATE_HZ ((TickType_t)1000)
3 a. H+ _' q. V# T6 o+ e3 Q - #define configMAX_PRIORITIES ( 7 )
" P5 h* }7 D+ {2 J5 x! R# g$ k - #define configMINIMAL_STACK_SIZE ((uint16_t)128): K9 J" @/ V- T# Z
- #define configTOTAL_HEAP_SIZE ((size_t)3072)! _+ d1 {& F' z2 u- f( R
- #define configMAX_TASK_NAME_LEN ( 16 )5 I6 a& r) K# g c% g$ s( G
- #define configUSE_16_BIT_TICKS 05 `& K# H+ H3 m
- #define configUSE_MUTEXES 1
/ K! r+ U1 h- L/ ~, \ E - #define configQUEUE_REGISTRY_SIZE 8* x: u" F& A) M& b: Y- f# n5 H$ }
- #define configUSE_PORT_OPTIMISED_TASK_SELECTION 14 ]- u2 S7 Q7 L+ o6 }: Y
* C' E. b d( @8 l x$ s3 V/ f$ z- /* Co-routine definitions. */
7 N' {) U6 z( c% K6 {% n" |( z4 D s - #define configUSE_CO_ROUTINES 0% P% X' x8 `+ i2 p' ]! K( ?9 I9 q2 }
- #define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
; i- ~% l7 g4 q( z9 `8 {' X% l; S: S - + L; j8 _+ ?" X
- /* Set the following definitions to 1 to include the API function, or zero1 ] K H1 O& O0 S
- to exclude the API function. */
; X$ I- ^( b0 }- Q" |; Y - #define INCLUDE_vTaskPrioritySet 1
# Q- |$ v' A, V1 I/ D - #define INCLUDE_uxTaskPriorityGet 1
" f( q; b2 A. {( L' f- S; h! a6 Q - #define INCLUDE_vTaskDelete 1
3 V+ i; `/ P6 z - #define INCLUDE_vTaskCleanUpResources 0
. [" I, w7 D' }9 c4 u7 G - #define INCLUDE_vTaskSuspend 13 b `* r& e+ g/ D7 Q# |' O( K
- #define INCLUDE_vTaskDelayUntil 0' J/ W% F W# \; F0 Z2 M
- #define INCLUDE_vTaskDelay 1
7 d5 t6 V7 n; X7 r4 [; I; R: R - #define INCLUDE_xTaskGetSchedulerState 1* T0 ], M. `2 B
5 m: \- l$ Z8 s( m) V; d% u
5 z( T. j) w" y3 {- //Tickless; H8 {$ Q0 A* \) d8 o
- #define configUSE_TICKLESS_IDLE 1//启用tickless低功耗& ~, j E; r! Q1 _8 j9 a
- #define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 39 p7 i2 [7 N0 \+ ]6 W
" C* i( d! m1 S: k- /* Cortex-M specific definitions. */9 _) u, z9 h: g: Y6 P
- #ifdef __NVIC_PRIO_BITS4 ~0 f* z8 \! D9 d
- /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
) z X+ |" P; Y7 ^0 X - #define configPRIO_BITS __NVIC_PRIO_BITS
& q' z! P0 v2 n- ? - #else
; o: u; D) @) K- t3 K( S - #define configPRIO_BITS 4
/ W3 [2 d! e N1 Q - #endif2 ]- e1 u, W7 m1 R& n: p
- 5 Z3 t8 y& Q7 {: o: ^8 p
- /* The lowest interrupt priority that can be used in a call to a "set priority"
1 F2 K& G/ b& c, O. N$ q# U - function. */+ Q0 A: [# V# R) G- h2 p
- #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15
K7 D7 e4 ]2 J1 p
* Y$ c' k% k) E% P- /* The highest interrupt priority that can be used by any interrupt service2 {" ?& ?& v' ?" C7 m3 T8 j# S
- routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
- y( ^; b$ v+ d$ S: ~) U6 V - INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
. y: v3 m j( W3 U1 z - PRIORITY THAN THIS! (higher priorities are lower numeric values. */4 j) H, A W* Z1 \ m
- #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 54 u) U8 f% ^7 c0 h+ _5 K
- $ N5 @; |. v+ |* h
- /* Interrupt priorities used by the kernel port layer itself. These are generic' R5 R; i) ~5 _4 O
- to all Cortex-M ports, and do not rely on any particular library functions. */
# L+ k5 b% E; M% G0 J6 {- R" I9 W - #define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )* P) M c) o" v7 V" ~
- /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
- d& u- h/ o% G3 j; 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> */9 n) ?. l' B6 F. Z4 Y. v* t1 [
- #define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )" m9 y$ ~* L* d& L; v8 e; O
8 B% H/ p6 m! v" W; l6 }- /* Normal assert() semantics without relying on the provision of an assert.h
' P- s% { ?& `" F& z; V" I - header file. */
+ l' ^+ P% c" A# J+ u0 R& g - /* USER CODE BEGIN 1 */
- f" F* f) N# E: } - #define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}1 j# W0 w: i9 i- X! b
- /* USER CODE END 1 */2 t, S; x' k$ u0 @( V; _8 C
z" f7 M3 l+ e- /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS& ?8 t4 [1 d* w- i
- standard names. */
6 O( m; _- m( P( W2 ] - #define vPortSVCHandler SVC_Handler5 d# n; b0 V7 g, R5 U- M
- #define xPortPendSVHandler PendSV_Handler
( O- v, B7 A: ]( ]3 m o) \
1 Y1 F7 D1 i* X- /* IMPORTANT: This define is commented when used with STM32Cube firmware, when the timebase source is SysTick,
' }, o3 N0 v. T: a( `4 O { - to prevent overwriting SysTick_Handler defined within STM32Cube HAL */) L, [" U% t( N. L+ w, U) i1 \9 a
- 0 }" h% I4 q" X, |8 O1 a$ N
- #define xPortSysTickHandler SysTick_Handler0 |9 k* e5 a j; b% W/ ~9 d) y
9 [! V6 E/ V! F+ ^- /* USER CODE BEGIN Defines */; Z7 k" E: d" s( l6 x
- /* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */- s; n0 Y& m5 j" U# t' k
- /* USER CODE END Defines */1 {3 U" L1 K. i; n4 z3 r- f$ G
- , ?% d, Q* Y; F2 y
- #endif /* FREERTOS_CONFIG_H */& _% B4 f% M9 c! N2 k, @! R
复制代码 / g+ |- D+ G% m9 g+ U
FreeRTOS 的配置基本是通过在 FreeRTOSConfig.h 中使用“#define”这样的语句来定义宏定义实现的。- u# D1 d9 R# z/ E" k0 s& b
这些宏定义都有特殊的含义,我们就调其中一个讲解。- #define configGENERATE_RUN_TIME_STATS 1- `! w$ ^" I1 T6 w; v# k# E5 `# x
复制代码
: a$ N; U& x: Z' M4 A$ A将此宏设置为1开启时间统计功能,相应的 API 函数会被编译,为 0 时关闭时间统计功能。9 l7 K5 f8 K+ F+ I" J* k$ G; c
其他的宏作用也和这个差不多,当设置为1时就可以使能某些函数,设置为0函数就不可用。
4 g' m# f/ ]$ h+ v其他宏大家可以自己看看,一般cubeMX生成代码后都会自动配置一些宏。
r5 G. X6 |) D* m- v7 P L) V8 Z! p2 [$ ?7 i
总结
% H" q, Q# T" t, |0 x3 OFreeRTOSConfig.h文件简单解析就到这里。; X* Q \# g4 {7 Y# }- m: a8 [& X
% ?: l7 X& o: N, J/ W
4 v! U! Y% s! x; r* \1 Y9 p) F |