当前位置:网站首页>FreeRTOS overview and experience

FreeRTOS overview and experience

2022-06-24 11:34:00 ~Old

1.1 FreeRTOS Directory structure

With Keil Under the tools STM32F103 Chip as an example , its FreeRTOS Directory as follows :

 Insert picture description here

Mainly involves 2 A catalog :

  • Demo
    • Demo Under the directory is the project file , With “ Chips and compilers are combined into one name ”
    • such as :CORTEX_STM32F103_Keil 
  • Source
    • The root directory is the core file , These documents are FreeRTOS Source code , These files are generic
    • portable Directories are files that need to be implemented during migration , Hardware interface layer ,FreeRTOS And the chip .
      • The directory name is :[complier]/[architecture]
      • such as :RVDS/ARM_CM3, This means cortexM3 Architecture in RVDS Migration files on tools

1.2 Core documents

FreeRTOS Strictly speaking, the most core document of is 2 individual :

  • FreeRTOS/Source/task.c 
  • FreeRTOS/Source/list.c

Broad sense of queue.c It is often used , But it's not necessary , Some places also put queue.c This document is also considered necessary .

The functions of other documents are also listed as follows :

FreeRTOS/Source The files under the effect
tasks.c It's necessary , Task operation
list.c It's necessary , The list of operations
queue.c Basically , Provides queue operations , Semaphore (semaphore) operation
timer.c Optional ,software timer
event_groups.c Optional , Provide event group function
croutine.c Optional , coroutines ,FreeRTOS No more updates , Out of date

1.3 Files involved in migration

transplant FreeRTOS The documents involved are placed in FreeRTOS/Source/portable/[complier]/[architecture] Under the table of contents ,

such as :RVDS/ARM_CM3, This means cortexM3 Architecture in RVDS or Keil Migration files on tools

There are 2 File :

  • port.c
  • portmacro.h

1.4 Header file related

1.4.1 Header Directory

FreeRTOS Three header directories are required :

  • FreeRTOS Own header file :FreeRTOS/Source/include
  • Header files used in migration ,FreeRTOS/Source/portable/[complier]/[architecture]
  • With configuration file FreeRTOSConfig.h The catalog of

1.4.2 The header file

The header file effect
FreeRTO\quSConfig.hFreeRTOS Configuration file for , For example, select a scheduling algorithm :configUSE_PREEMPTION Every demo Must contain FreeRTOSConfig.h It is suggested to modify demo Medium FreeRTOSConfig.h, Instead of writing from scratch , In fact, this file is provided for users to tailor FreeRTOS System , Defined as needed
FreeRTOS.h Use FreeRTOS API Function time , This file must be included , stay FreeRTOS.h after , Then include other header files , such as :task.h、queue.h、semphr.h、event_group.h

1.5 memory management

The file in FreeRTOS/Source/portable/MemMang Next , It is also placed in portable Under the table of contents , Means that you can provide your own functions .

The source code provides... By default 5 File , Corresponding to memory management 5 Methods .

file advantage shortcoming
heap_1.c Assignment Brief , Time is set Allocate only, do not recycle
heap_2.c Dynamic allocation , Best match debris , Time is uncertain
heap_3.c Call standard library functions Slow speed , Time is uncertain
heap_4.c Adjacent free memory can be merged It can solve the problem of fragmentation , Time is uncertain
heap_5.c stay heap_4 Support separate memory blocks based on It can solve the problem of fragmentation , Time is uncertain

1.6 Demo

Demo The directory is pre configured , No compilation errors in the project , The purpose is that you can modify based on it , To fit your board .

these Demo You can also continue to streamline , So that FreeRTOS It looks clean and refreshing .

1.7 Data types and programming specifications

Each migrated version contains its own portmacro.h The header file , It's defined in it 2 Data types :

  • TickType_t: 
    • FreeRTOS A periodic clock interrupt is configured :Tick Interrupt
    • Every time an interrupt occurs , The number of interrupts is accumulated , This is known as tick count
    • tick count The type of this variable is Tick Type_t
    • Tick Type_t It can be 16 Bit , It can also be 32 Bit
    • FreeRTOSConfig.h In the definition of configUSE_16_BIT_TICKS when ,TickType_t Namely uint16_t
    • otherwise TickType_t Namely uint32_t
    • about 32 An architecture , Make a proposal to TickType_t Configure to uint32_t
  • BaseType_t:
    • This is the most efficient data type of the architecture
    • 32 Bit architecture , It is uin32_t
    • 16 Bit architecture , It is uint16_t
    • 8 Bit architecture , It is uint8_t
    • BaseType_t Usually used as a simple return value type , And logical values , such as pdTRUE/pdFALSE

1.7.2 Variable name

Variable names are prefixed

Variable name prefix c meaning
cchar
sint16_t .short
lint32_t,long
xBaseType_t, Other non-standard types : Structure ,task handle、queue handle etc.
uunsigned
p The pointer
ucuint8_t , unsigned char
pcchar The pointer

1.7.3 Function name

The prefix of the function name is 2 part : return type , In which file do you define .

Function name prefix meaning
vTaskPrioritySet return type :void
stay task.c In the definition of
xQueueReceive        

return type :BaseType_t

stay queue.c In the definition of

pvTimerGetTimerID

return type :pointer to void

stay timer.c In the definition of

1.7.4 Macro name

The name of the macro is capitalized , You can add a lowercase prefix . Prefixes are used to denote : In which file are macros defined .

Prefix of macro meaning : Define... In that file
port( such as portMAX_DELAY)portable.h or portmacro.h
task( such as taskENTER_CRITICAL())task.h
pd( such as pdTRUE)projdefs.h
config( such as configUSE_PREEMPTION)FreeRTOSConfig.h
err( such as errQUEUE_FULL)projdefs.h

The general macro definition is as follows :

macro value
pdTRUE1
pdFALSE0
pdPASS1
pdFAIL1

原网站

版权声明
本文为[~Old]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241022339859.html