Skip to content

Commit f28c698

Browse files
committed
Add FreeRTOS-Kernel source code
1 parent 48861ae commit f28c698

File tree

402 files changed

+212850
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

402 files changed

+212850
-8
lines changed

freertos-cargo-build/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use walkdir::WalkDir;
99
/// The Kernel can be found at Github: https://github.com/FreeRTOS/FreeRTOS-Kernel
1010
///
1111
/// When not set, you can use the Builder to specify the path
12-
const ENV_KEY_FREERTOS_SRC: &str = "FREERTOS_SRC";
12+
const ENV_KEY_FREERTOS_SRC: &str = "DEP_FREERTOS_KERNEL";
1313

1414
/// The FREERTOS_CONFIG variable must point to the directory
1515
/// where the FreeRTOSConfig.h file is located for the current project.

freertos-rust-examples/build.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ fn main() {
1313

1414
let mut b = freertos_build::Builder::new();
1515

16-
b.freertos("FreeRTOS-Kernel/");
17-
1816
// Windows example specific stuff.
1917
if target_family == "windows" {
2018
b.freertos_config("examples/win");

freertos-rust/FreeRTOS-Kernel/CMakeLists.txt

Lines changed: 272 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[{000214A0-0000-0000-C000-000000000046}]
2+
Prop3=19,2
3+
[InternetShortcut]
4+
URL=https://github.com/FreeRTOS/FreeRTOS-Kernel
5+
IconIndex=0
6+
IDList=
7+
HotKey=0

freertos-rust/FreeRTOS-Kernel/History.txt

Lines changed: 3494 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
MIT License
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# MISRA Compliance
2+
3+
FreeRTOS-Kernel conforms to [MISRA C:2012](https://www.misra.org.uk/misra-c)
4+
guidelines, with the deviations listed below. Compliance is checked with
5+
Coverity static analysis version 2023.6.1. Since the FreeRTOS kernel is
6+
designed for small-embedded devices, it needs to have a very small memory
7+
footprint and has to be efficient. To achieve that and to increase the
8+
performance, it deviates from some MISRA rules. The specific deviations,
9+
suppressed inline, are listed below.
10+
11+
Additionally, [MISRA configuration file](examples/coverity/coverity_misra.config)
12+
contains project wide deviations.
13+
14+
### Suppressed with Coverity Comments
15+
To find the violation references in the source files run grep on the source code
16+
with ( Assuming rule 8.4 violation; with justification in point 1 ):
17+
```
18+
grep 'MISRA Ref 8.4.1' . -rI
19+
```
20+
21+
#### Dir 4.7
22+
MISRA C:2012 Dir 4.7: If a function returns error information, then that error
23+
information shall be tested.
24+
25+
_Ref 4.7.1_
26+
- `taskENTER_CRITICAL_FROM_ISR` returns the interrupt mask and not any error
27+
information. Therefore, there is no need test the return value.
28+
29+
#### Rule 8.4
30+
31+
MISRA C:2012 Rule 8.4: A compatible declaration shall be visible when an
32+
object or function with external linkage is defined.
33+
34+
_Ref 8.4.1_
35+
- pxCurrentTCB(s) is defined with external linkage but it is only referenced
36+
from the assembly code in the port files. Therefore, adding a declaration in
37+
header file is not useful as the assembly code will still need to declare it
38+
separately.
39+
40+
_Ref 8.4.2_
41+
- xQueueRegistry is defined with external linkage because it is accessed by the
42+
kernel unit tests. It is not meant to be directly accessed by the application
43+
and therefore, not declared in a header file.
44+
45+
#### Rule 8.6
46+
47+
MISRA C:2012 Rule 8.6: An identifier with external linkage shall have exactly
48+
one external definition.
49+
50+
_Ref 8.6.1_
51+
- This rule prohibits an identifier with external linkage to have multiple
52+
definitions or no definition. FreeRTOS hook functions are implemented in
53+
the application and therefore, have no definition in the Kernel code.
54+
55+
#### Rule 11.1
56+
MISRA C:2012 Rule 11.1: Conversions shall not be performed between a pointer to
57+
function and any other type.
58+
59+
_Ref 11.1.1_
60+
- The pointer to function is casted into void to avoid unused parameter
61+
compiler warning when Stream Buffer's Tx and Rx Completed callback feature is
62+
not used.
63+
64+
#### Rule 11.3
65+
66+
MISRA C:2012 Rule 11.3: A cast shall not be performed between a pointer to
67+
object type and a pointer to a different object type.
68+
69+
_Ref 11.3.1_
70+
- This rule prohibits casting a pointer to object into a pointer to a
71+
different object because it may result in an incorrectly aligned pointer,
72+
leading to undefined behavior. Even if the casting produces a correctly
73+
aligned pointer, the behavior may be still undefined if the pointer is
74+
used to access an object. FreeRTOS deliberately creates external aliases
75+
for all the kernel object types (StaticEventGroup_t, StaticQueue_t,
76+
StaticStreamBuffer_t, StaticTimer_t and StaticTask_t) for data hiding
77+
purposes. The internal object types and the corresponding external
78+
aliases are guaranteed to have the same size and alignment which is
79+
checked using configASSERT.
80+
81+
82+
#### Rule 11.5
83+
84+
MISRA C:2012 Rule 11.5: A conversion should not be performed from pointer to
85+
void into pointer to object.
86+
This rule prohibits conversion of a pointer to void into a pointer to
87+
object because it may result in an incorrectly aligned pointer leading
88+
to undefined behavior.
89+
90+
_Ref 11.5.1_
91+
- The memory blocks returned by pvPortMalloc() are guaranteed to meet the
92+
architecture alignment requirements specified by portBYTE_ALIGNMENT.
93+
The casting of the pointer to void returned by pvPortMalloc() is,
94+
therefore, safe because it is guaranteed to be aligned.
95+
96+
_Ref 11.5.2_
97+
- The conversion from a pointer to void into a pointer to EventGroup_t is
98+
safe because it is a pointer to EventGroup_t, which is returned to the
99+
application at the time of event group creation for data hiding
100+
purposes.
101+
102+
_Ref 11.5.3_
103+
- The conversion from a pointer to void in list macros for list item owner
104+
is safe because the type of the pointer stored and retrieved is the
105+
same.
106+
107+
_Ref 11.5.4_
108+
- The conversion from a pointer to void into a pointer to EventGroup_t is
109+
safe because it is a pointer to EventGroup_t, which is passed as a
110+
parameter to the xTimerPendFunctionCallFromISR API when the callback is
111+
pended.
112+
113+
_Ref 11.5.5_
114+
- The conversion from a pointer to void into a pointer to uint8_t is safe
115+
because data storage buffers are implemented as uint8_t arrays for the
116+
ease of sizing, alignment and access.
117+
118+
#### Rule 14.3
119+
120+
MISRA C-2012 Rule 14.3: Controlling expressions shall not be invariant.
121+
122+
_Ref 14.3_
123+
- The `configMAX_TASK_NAME_LEN` , `taskRESERVED_TASK_NAME_LENGTH` and `SIZE_MAX`
124+
are evaluated to constants at compile time and may vary based on the build
125+
configuration.
126+
127+
#### Rule 18.1
128+
129+
MISRA C-2012 Rule 18.1: A pointer resulting from arithmetic on a pointer operand
130+
shall address an element of the same array as that pointer operand.
131+
132+
_Ref 18.1_
133+
- Array access remains within bounds since either the null terminator in
134+
the IDLE task name will break the loop, or the loop will break normally
135+
if the array size is smaller than the IDLE task name length.
136+
137+
#### Rule 21.6
138+
139+
MISRA C-2012 Rule 21.6: The Standard Library input/output functions shall not
140+
be used.
141+
142+
_Ref 21.6.1_
143+
- The Standard Library function snprintf is used in vTaskListTasks and
144+
vTaskGetRunTimeStatistics APIs, both of which are utility functions only and
145+
are not considered part of core kernel implementation.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[InternetShortcut]
2+
URL=https://www.FreeRTOS.org/FreeRTOS-quick-start-guide.html
3+
IDList=
4+
[{000214A0-0000-0000-C000-000000000046}]
5+
Prop3=19,2
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
[![CMock Unit Tests](https://github.com/FreeRTOS/FreeRTOS-Kernel/actions/workflows/unit-tests.yml/badge.svg?branch=main&event=push)](https://github.com/FreeRTOS/FreeRTOS-Kernel/actions/workflows/unit-tests.yml?query=branch%3Amain+event%3Apush+workflow%3A%22CMock+Unit+Tests%22++)
2+
[![codecov](https://codecov.io/gh/FreeRTOS/FreeRTOS-Kernel/badge.svg?branch=main)](https://codecov.io/gh/FreeRTOS/FreeRTOS-Kernel)
3+
4+
## Getting started
5+
6+
This repository contains FreeRTOS kernel source/header files and kernel
7+
ports only. This repository is referenced as a submodule in
8+
[FreeRTOS/FreeRTOS](https://github.com/FreeRTOS/FreeRTOS)
9+
repository, which contains pre-configured demo application projects under
10+
```FreeRTOS/Demo``` directory.
11+
12+
The easiest way to use FreeRTOS is to start with one of the pre-configured demo
13+
application projects. That way you will have the correct FreeRTOS source files
14+
included, and the correct include paths configured. Once a demo application is
15+
building and executing you can remove the demo application files, and start to
16+
add in your own application source files. See the
17+
[FreeRTOS Kernel Quick Start Guide](https://www.freertos.org/Documentation/01-FreeRTOS-quick-start/01-Beginners-guide/02-Quick-start-guide)
18+
for detailed instructions and other useful links.
19+
20+
Additionally, for FreeRTOS kernel feature information refer to the
21+
[Developer Documentation](https://www.freertos.org/Documentation/02-Kernel/02-Kernel-features/00-Developer-docs),
22+
and [API Reference](https://www.freertos.org/Documentation/02-Kernel/04-API-references/01-Task-creation/00-TaskHandle).
23+
24+
Also for contributing and creating a Pull Request please refer to
25+
[the instructions here](.github/CONTRIBUTING.md#contributing-via-pull-request).
26+
27+
**FreeRTOS-Kernel V11.1.0
28+
[source code](https://github.com/FreeRTOS/FreeRTOS-Kernel/tree/V11.1.0) is part
29+
of the
30+
[FreeRTOS 202406.00 LTS](https://github.com/FreeRTOS/FreeRTOS-LTS/tree/202406-LTS)
31+
release.**
32+
33+
### Getting help
34+
35+
If you have any questions or need assistance troubleshooting your FreeRTOS project,
36+
we have an active community that can help on the
37+
[FreeRTOS Community Support Forum](https://forums.freertos.org).
38+
39+
## To consume FreeRTOS-Kernel
40+
41+
### Consume with CMake
42+
43+
If using CMake, it is recommended to use this repository using FetchContent.
44+
Add the following into your project's main or a subdirectory's `CMakeLists.txt`:
45+
46+
- Define the source and version/tag you want to use:
47+
48+
```cmake
49+
FetchContent_Declare( freertos_kernel
50+
GIT_REPOSITORY https://github.com/FreeRTOS/FreeRTOS-Kernel.git
51+
GIT_TAG main #Note: Best practice to use specific git-hash or tagged version
52+
)
53+
```
54+
55+
In case you prefer to add it as a git submodule, do:
56+
57+
```bash
58+
git submodule add https://github.com/FreeRTOS/FreeRTOS-Kernel.git <path of the submodule>
59+
git submodule update --init
60+
```
61+
62+
- Add a freertos_config library (typically an INTERFACE library) The following assumes the directory structure:
63+
- `include/FreeRTOSConfig.h`
64+
65+
```cmake
66+
add_library(freertos_config INTERFACE)
67+
68+
target_include_directories(freertos_config SYSTEM
69+
INTERFACE
70+
include
71+
)
72+
73+
target_compile_definitions(freertos_config
74+
INTERFACE
75+
projCOVERAGE_TEST=0
76+
)
77+
```
78+
79+
In case you installed FreeRTOS-Kernel as a submodule, you will have to add it as a subdirectory:
80+
81+
```cmake
82+
add_subdirectory(${FREERTOS_PATH})
83+
```
84+
85+
- Configure the FreeRTOS-Kernel and make it available
86+
- this particular example supports a native and cross-compiled build option.
87+
88+
```cmake
89+
set( FREERTOS_HEAP "4" CACHE STRING "" FORCE)
90+
# Select the native compile PORT
91+
set( FREERTOS_PORT "GCC_POSIX" CACHE STRING "" FORCE)
92+
# Select the cross-compile PORT
93+
if (CMAKE_CROSSCOMPILING)
94+
set(FREERTOS_PORT "GCC_ARM_CA9" CACHE STRING "" FORCE)
95+
endif()
96+
97+
FetchContent_MakeAvailable(freertos_kernel)
98+
```
99+
100+
- In case of cross compilation, you should also add the following to `freertos_config`:
101+
102+
```cmake
103+
target_compile_definitions(freertos_config INTERFACE ${definitions})
104+
target_compile_options(freertos_config INTERFACE ${options})
105+
```
106+
107+
### Consuming stand-alone - Cloning this repository
108+
109+
To clone using HTTPS:
110+
111+
```
112+
git clone https://github.com/FreeRTOS/FreeRTOS-Kernel.git
113+
```
114+
115+
Using SSH:
116+
117+
```
118+
git clone [email protected]:FreeRTOS/FreeRTOS-Kernel.git
119+
```
120+
121+
## Repository structure
122+
123+
- The root of this repository contains the three files that are common to
124+
every port - list.c, queue.c and tasks.c. The kernel is contained within these
125+
three files. croutine.c implements the optional co-routine functionality - which
126+
is normally only used on very memory limited systems.
127+
128+
- The ```./portable``` directory contains the files that are specific to a particular microcontroller and/or compiler.
129+
See the readme file in the ```./portable``` directory for more information.
130+
131+
- The ```./include``` directory contains the real time kernel header files.
132+
133+
- The ```./template_configuration``` directory contains a sample `FreeRTOSConfig.h` to help jumpstart a new project.
134+
See the [FreeRTOSConfig.h](examples/template_configuration/FreeRTOSConfig.h) file for instructions.
135+
136+
### Code Formatting
137+
138+
FreeRTOS files are formatted using the
139+
"[uncrustify](https://github.com/uncrustify/uncrustify)" tool.
140+
The configuration file used by uncrustify can be found in the
141+
[FreeRTOS/CI-CD-GitHub-Actions's](https://github.com/FreeRTOS/CI-CD-Github-Actions)
142+
[uncrustify.cfg](https://github.com/FreeRTOS/CI-CD-Github-Actions/tree/main/formatting)
143+
file.
144+
145+
### Line Endings
146+
147+
File checked into the FreeRTOS-Kernel repository use unix-style LF line endings
148+
for the best compatibility with git.
149+
150+
For optimal compatibility with Microsoft Windows tools, it is best to enable
151+
the git autocrlf feature. You can enable this setting for the current
152+
repository using the following command:
153+
154+
```
155+
git config core.autocrlf true
156+
```
157+
158+
### Git History Optimizations
159+
160+
Some commits in this repository perform large refactors which touch many lines
161+
and lead to unwanted behavior when using the `git blame` command. You can
162+
configure git to ignore the list of large refactor commits in this repository
163+
with the following command:
164+
165+
```
166+
git config blame.ignoreRevsFile .git-blame-ignore-revs
167+
```
168+
169+
### Spelling and Formatting
170+
171+
We recommend using [Visual Studio Code](https://code.visualstudio.com),
172+
commonly referred to as VSCode, when working on the FreeRTOS-Kernel.
173+
The FreeRTOS-Kernel also uses [cSpell](https://cspell.org/) as part of its
174+
spelling check. The config file for which can be found at [cspell.config.yaml](cspell.config.yaml)
175+
There is additionally a
176+
[cSpell plugin for VSCode](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker)
177+
that can be used as well.
178+
*[.cSpellWords.txt](.github/.cSpellWords.txt)* contains words that are not
179+
traditionally found in an English dictionary. It is used by the spellchecker
180+
to verify the various jargon, variable names, and other odd words used in the
181+
FreeRTOS code base are correct. If your pull request fails to pass the spelling
182+
and you believe this is a mistake, then add the word to
183+
*[.cSpellWords.txt](.github/.cSpellWords.txt)*. When adding a word please
184+
then sort the list, which can be done by running the bash command:
185+
`sort -u .cSpellWords.txt -o .cSpellWords.txt`
186+
Note that only the FreeRTOS-Kernel Source Files, [include](include),
187+
[portable/MemMang](portable/MemMang), and [portable/Common](portable/Common)
188+
files are checked for proper spelling, and formatting at this time.
189+
190+
## Third Party Tools
191+
Visit [this link](.github/third_party_tools.md) for detailed information about
192+
third-party tools with FreeRTOS support.

0 commit comments

Comments
 (0)