Skip to content

Commit 5a9d7c8

Browse files
n9wxuactions-user
andauthored
Sample FreeRTOSConfig.h and template port (#812)
* config file experiments * adding a config file for an example * Added a template port and updated the CMakeLists * template and default configuration build * finalising the sample FreeRTOSConfig.h header file * removed .config hidden file * further reductions in the template port * Uncrustify: triggered by comment. * Uncrustify: triggered by comment. * minor readme updates * fixed spelling error in HTTP * fixed a type and added a link to the sample readme * uncrustified FreeRTOSConfig.h * Uncrustify: triggered by comment. * Revert "Uncrustify: triggered by comment." This reverts commit e534f46. * Revert "Revert "Uncrustify: triggered by comment."" This reverts commit c9058dd. * excluding the FreeRTOSConfig.h from copyright+license check because this file is intended to be incorporated into user code * Removed the copyright and license from the template files * put license copy in the template and sample files * Uncrustify: triggered by comment. --------- Co-authored-by: GitHub Action <[email protected]>
1 parent 9d2571d commit 5a9d7c8

File tree

8 files changed

+650
-5
lines changed

8 files changed

+650
-5
lines changed

.github/scripts/kernel_checker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
'Makefile',
3939
'.DS_Store',
4040
'cspell.config.yaml'
41+
'FreeRTOSConfig.h'
4142
]
4243

4344
KERNEL_IGNORED_EXTENSIONS = [
@@ -92,7 +93,8 @@
9293
r'.*portable/ThirdParty/xClang/XCOREAI/*',
9394
r'.*IAR/ARM_C*',
9495
r'.*IAR/78K0R/*',
95-
r'.*CCS/MSP430X/*'
96+
r'.*CCS/MSP430X/*',
97+
r'.*portable/template/*'
9698
]
9799

98100
KERNEL_THIRD_PARTY_PATTERNS = [

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ if(NOT FREERTOS_PORT)
196196
" SOFTUNE_MB91460 - Compiler: Softune Target: MB91460\n"
197197
" SOFTUNE_MB96340 - Compiler: Softune Target: MB96340\n"
198198
" TASKING_ARM_CM4F - Compiler: Tasking Target: ARM Cortex-M4 with FPU\n"
199+
" TEMPLATE - Compiler: HOST Target: None\n"
199200
" CDK_THEAD_CK802 - Compiler: CDK Target: T-head CK802\n"
200201
" XCC_XTENSA - Compiler: XCC Target: Xtensa\n"
201202
" WIZC_PIC18 - Compiler: WizC Target: PIC18")

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[![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++)
22
[![codecov](https://codecov.io/gh/FreeRTOS/FreeRTOS-Kernel/badge.svg?branch=main)](https://codecov.io/gh/FreeRTOS/FreeRTOS-Kernel)
3+
34
## Getting started
5+
46
This repository contains FreeRTOS kernel source/header files and kernel
57
ports only. This repository is referenced as a submodule in
68
[FreeRTOS/FreeRTOS](https://github.com/FreeRTOS/FreeRTOS)
@@ -20,13 +22,15 @@ Additionally, for FreeRTOS kernel feature information refer to the
2022
and [API Reference](https://www.FreeRTOS.org/a00106.html).
2123

2224
### Getting help
25+
2326
If you have any questions or need assistance troubleshooting your FreeRTOS project,
2427
we have an active community that can help on the
2528
[FreeRTOS Community Support Forum](https://forums.freertos.org).
2629

2730
## To consume FreeRTOS-Kernel
2831

2932
### Consume with CMake
33+
3034
If using CMake, it is recommended to use this repository using FetchContent.
3135
Add the following into your project's main or a subdirectory's `CMakeLists.txt`:
3236

@@ -42,12 +46,13 @@ FetchContent_Declare( freertos_kernel
4246
In case you prefer to add it as a git submodule, do:
4347

4448
```bash
45-
$ git submodule add https://github.com/FreeRTOS/FreeRTOS-Kernel.git <path of the submodule>
46-
$ git submodule update --init
49+
git submodule add https://github.com/FreeRTOS/FreeRTOS-Kernel.git <path of the submodule>
50+
git submodule update --init
4751
```
4852

4953
- Add a freertos_config library (typically an INTERFACE library) The following assumes the directory structure:
5054
- `include/FreeRTOSConfig.h`
55+
5156
```cmake
5257
add_library(freertos_config INTERFACE)
5358
@@ -93,15 +98,19 @@ target_compile_options(freertos_config INTERFACE ${options})
9398
### Consuming stand-alone - Cloning this repository
9499

95100
To clone using HTTPS:
101+
96102
```
97103
git clone https://github.com/FreeRTOS/FreeRTOS-Kernel.git
98104
```
105+
99106
Using SSH:
107+
100108
```
101109
git clone [email protected]:FreeRTOS/FreeRTOS-Kernel.git
102110
```
103111

104112
## Repository structure
113+
105114
- The root of this repository contains the three files that are common to
106115
every port - list.c, queue.c and tasks.c. The kernel is contained within these
107116
three files. croutine.c implements the optional co-routine functionality - which
@@ -112,7 +121,11 @@ See the readme file in the ```./portable``` directory for more information.
112121

113122
- The ```./include``` directory contains the real time kernel header files.
114123

124+
- The ```./sample_configuration``` directory contains a sample `FreeRTOSConfig.h` to help jumpstart a new project.
125+
See the [FreeRTOSConfig.h](sample_configuration/FreeRTOSConfig.h) file for instructions.
126+
115127
### Code Formatting
128+
116129
FreeRTOS files are formatted using the
117130
"[uncrustify](https://github.com/uncrustify/uncrustify)" tool.
118131
The configuration file used by uncrustify can be found in the
@@ -121,26 +134,31 @@ The configuration file used by uncrustify can be found in the
121134
file.
122135

123136
### Line Endings
137+
124138
File checked into the FreeRTOS-Kernel repository use unix-style LF line endings
125139
for the best compatibility with git.
126140

127141
For optimal compatibility with Microsoft Windows tools, it is best to enable
128142
the git autocrlf feature. You can enable this setting for the current
129143
repository using the following command:
144+
130145
```
131146
git config core.autocrlf true
132147
```
133148

134149
### Git History Optimizations
150+
135151
Some commits in this repository perform large refactors which touch many lines
136152
and lead to unwanted behavior when using the `git blame` command. You can
137153
configure git to ignore the list of large refactor commits in this repository
138154
with the following command:
155+
139156
```
140157
git config blame.ignoreRevsFile .git-blame-ignore-revs
141158
```
142159

143160
### Spelling and Formatting
161+
144162
We recommend using [Visual Studio Code](https://code.visualstudio.com),
145163
commonly referred to as VSCode, when working on the FreeRTOS-Kernel.
146164
The FreeRTOS-Kernel also uses [cSpell](https://cspell.org/) as part of its

portable/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ endif()
88
# FreeRTOS internal cmake file. Do not use it in user top-level project
99

1010
add_library(freertos_kernel_port STATIC
11-
# 16-Bit DOS ports for BCC
11+
# TEMPLATE Port
12+
$<$<STREQUAL:${FREERTOS_PORT},TEMPLATE>:
13+
template/port.c>
14+
15+
# 16-Bit DOS ports for BCC
1216
$<$<STREQUAL:${FREERTOS_PORT},BCC_16BIT_DOS_FLSH186>:
1317
BCC/16BitDOS/common/portcomn.c
1418
BCC/16BitDOS/Flsh186/port.c>
@@ -708,7 +712,10 @@ if( FREERTOS_PORT MATCHES "GCC_ARM_CM(3|4)_MPU" OR
708712
endif()
709713

710714
target_include_directories(freertos_kernel_port PUBLIC
711-
# 16-Bit DOS ports for BCC
715+
# TEMPLATE Port
716+
$<$<STREQUAL:${FREERTOS_PORT},TEMPLATE>:${CMAKE_CURRENT_LIST_DIR}/template>
717+
718+
# 16-Bit DOS ports for BCC
712719
$<$<STREQUAL:${FREERTOS_PORT},BCC_16BIT_DOS_FLSH186>:
713720
${CMAKE_CURRENT_LIST_DIR}/BCC/16BitDOS/common
714721
${CMAKE_CURRENT_LIST_DIR}/BCC/16BitDOS/Flsh186>

portable/template/port.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
3+
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* SPDX-License-Identifier: MIT
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
8+
* this software and associated documentation files (the "Software"), to deal in
9+
* the Software without restriction, including without limitation the rights to
10+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11+
* the Software, and to permit persons to whom the Software is furnished to do so,
12+
* subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
*
24+
* https://www.FreeRTOS.org
25+
* https://github.com/FreeRTOS
26+
*
27+
*/
28+
29+
#include "FreeRTOS.h"
30+
#include "task.h"
31+
32+
BaseType_t xPortStartScheduler( void )
33+
{
34+
return pdTRUE;
35+
}
36+
37+
void vPortEndScheduler( void )
38+
{
39+
}
40+
41+
StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
42+
TaskFunction_t pxCode,
43+
void * pvParameters )
44+
{
45+
return NULL;
46+
}
47+
48+
void vPortYield( void )
49+
{
50+
/* Save the current Context */
51+
/* Switch to the highest priority task that is ready to run. */
52+
vTaskSwitchContext();
53+
/* Start executing the task we have just switched to. */
54+
}
55+
56+
static void prvTickISR( void )
57+
{
58+
/* Interrupts must have been enabled for the ISR to fire, so we have to
59+
* save the context with interrupts enabled. */
60+
61+
/* Maintain the tick count. */
62+
if( xTaskIncrementTick() != pdFALSE )
63+
{
64+
/* Switch to the highest priority task that is ready to run. */
65+
vTaskSwitchContext();
66+
}
67+
68+
/* start executing the new task */
69+
}

portable/template/portmacro.h

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
3+
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* SPDX-License-Identifier: MIT
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
8+
* this software and associated documentation files (the "Software"), to deal in
9+
* the Software without restriction, including without limitation the rights to
10+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11+
* the Software, and to permit persons to whom the Software is furnished to do so,
12+
* subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
*
24+
* https://www.FreeRTOS.org
25+
* https://github.com/FreeRTOS
26+
*
27+
*/
28+
#ifndef PORTMACRO_H
29+
#define PORTMACRO_H
30+
31+
/*-----------------------------------------------------------
32+
* Port specific definitions.
33+
*
34+
* The settings in this file configure FreeRTOS correctly for the
35+
* given hardware and compiler.
36+
*
37+
* These settings should not be altered.
38+
*-----------------------------------------------------------
39+
*/
40+
41+
/* Type definitions. */
42+
#define portCHAR char
43+
#define portFLOAT float
44+
#define portDOUBLE double
45+
#define portLONG long
46+
#define portSHORT int
47+
#define portSTACK_TYPE uint8_t
48+
#define portBASE_TYPE char
49+
50+
#define portSTACK_GROWTH ( -1 )
51+
#define portBYTE_ALIGNMENT 4
52+
#define portPOINTER_SIZE_TYPE size_t
53+
typedef portSTACK_TYPE StackType_t;
54+
typedef signed char BaseType_t;
55+
typedef unsigned char UBaseType_t;
56+
57+
#if ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_16_BITS )
58+
typedef uint16_t TickType_t;
59+
#define portMAX_DELAY ( TickType_t ) 0xffff
60+
#elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_32_BITS )
61+
typedef uint32_t TickType_t;
62+
#define portMAX_DELAY ( TickType_t ) 0xffffffffUL
63+
#else
64+
#error configTICK_TYPE_WIDTH_IN_BITS set to unsupported tick type width.
65+
#endif
66+
67+
/* Architecture specific optimisations. */
68+
#ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
69+
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
70+
#endif
71+
72+
#if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
73+
74+
/* Check the configuration. */
75+
#if ( configMAX_PRIORITIES > 32 )
76+
#error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice.
77+
#endif
78+
79+
/* Store/clear the ready priorities in a bit map. */
80+
#define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
81+
#define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
82+
83+
/*-----------------------------------------------------------*/
84+
85+
#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) \
86+
{ \
87+
uxTopPriority = 0; \
88+
} \
89+
while( 0 )
90+
91+
#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
92+
93+
#define portDISABLE_INTERRUPTS() \
94+
{ /* Disable the interrupts */ \
95+
}
96+
#define portENABLE_INTERRUPTS() \
97+
{ /* Enable the interrupts */ \
98+
}
99+
100+
#define portENTER_CRITICAL() \
101+
{ /* preserve current interrupt state and then disable interrupts */ \
102+
}
103+
#define portEXIT_CRITICAL() \
104+
{ /* restore previously preserved interrupt state */ \
105+
}
106+
107+
extern void vPortYield( void );
108+
#define portYIELD() vPortYield()
109+
110+
/* Task function macros as described on the FreeRTOS.org WEB site. */
111+
#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters )
112+
#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters )
113+
114+
#endif /* PORTMACRO_H */

0 commit comments

Comments
 (0)