├── .gitignore ├── .gitmodules ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── docs ├── tutorial_1 │ └── README.md ├── tutorial_10 │ └── README.md ├── tutorial_11 │ └── README.md ├── tutorial_12 │ └── README.md ├── tutorial_13 │ └── README.md ├── tutorial_14 │ └── README.md ├── tutorial_15 │ └── README.md ├── tutorial_16 │ └── README.md ├── tutorial_17 │ └── README.md ├── tutorial_18 │ └── README.md ├── tutorial_19 │ └── README.md ├── tutorial_2 │ └── README.md ├── tutorial_20 │ └── README.md ├── tutorial_21 │ └── README.md ├── tutorial_3 │ └── README.md ├── tutorial_4 │ └── README.md ├── tutorial_5 │ └── README.md ├── tutorial_6 │ └── README.md ├── tutorial_7 │ └── README.md ├── tutorial_8 │ └── README.md └── tutorial_9 │ └── README.md └── source ├── CMakeLists.txt └── tutorials ├── tutorial_1 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_1.c ├── tutorial_10 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_10.c ├── tutorial_11 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_11.c ├── tutorial_12 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_12.c ├── tutorial_13 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_13.c ├── tutorial_14 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_14.c ├── tutorial_15 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_15.c ├── tutorial_16 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_16.c ├── tutorial_17 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_17.c ├── tutorial_18 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_18.c ├── tutorial_19 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_19.c ├── tutorial_2 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_2.c ├── tutorial_20 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_20.c ├── tutorial_21 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_21.c ├── tutorial_3 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_3.c ├── tutorial_4 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_4.c ├── tutorial_5 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_5.c ├── tutorial_6 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_6.c ├── tutorial_7 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_7.c ├── tutorial_8 ├── include │ └── FreeRTOSConfig.h └── source │ └── tutorial_8.c └── tutorial_9 ├── include └── FreeRTOSConfig.h └── source └── tutorial_9.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | Debug/ 45 | build/ 46 | 47 | # Kernel Module Compile Results 48 | *.mod* 49 | *.cmd 50 | .tmp_versions/ 51 | modules.order 52 | Module.symvers 53 | Mkfile.old 54 | dkms.conf 55 | 56 | # IDE Files 57 | .vscode/ 58 | .settings/ 59 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "source/FreeRTOS-Kernel"] 2 | path = source/FreeRTOS-Kernel 3 | url = https://github.com/FreeRTOS/FreeRTOS-Kernel.git 4 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | 10 | ## Reporting Bugs/Feature Requests 11 | 12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 13 | 14 | When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already 15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 16 | 17 | * A reproducible test case or series of steps 18 | * The version of our code being used 19 | * Any modifications you've made relevant to the bug 20 | * Anything unusual about your environment or deployment 21 | 22 | 23 | ## Contributing via Pull Requests 24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 25 | 26 | 1. You are working against the latest source on the *main* branch. 27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 29 | 30 | To send us a pull request, please: 31 | 32 | 1. Fork the repository. 33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 34 | 3. Ensure local tests pass. 35 | 4. Commit to your fork using clear commit messages. 36 | 5. Send us a pull request, answering any default questions in the pull request interface. 37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 38 | 39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 41 | 42 | 43 | ## Finding contributions to work on 44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start. 45 | 46 | 47 | ## Code of Conduct 48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 50 | opensource-codeofconduct@amazon.com with any additional questions or comments. 51 | 52 | 53 | ## Security issue notifications 54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 55 | 56 | 57 | ## Licensing 58 | 59 | See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 60 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT No Attribution 2 | 3 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 13 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 15 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 16 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 17 | 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting-Started-With-FreeRTOS 2 | This repository contains a collection of tutorials designed to help users to get 3 | started with the FreeRTOS Kernel. 4 | 5 | # Prerequisites 6 | * GCC compiler. 7 | * CMake 3.15.0 or later. 8 | * Clone this repository along with the submodules: 9 | ``` 10 | git clone --recurse-submodules https://github.com/FreeRTOS/Lab-Project-FreeRTOS-Tutorials.git 11 | ``` 12 | Or 13 | ``` 14 | git clone https://github.com/FreeRTOS/Lab-Project-FreeRTOS-Tutorials.git 15 | cd Lab-Project-FreeRTOS-Tutorials 16 | git submodule update --init --recursive 17 | ``` 18 | 19 | # Tutorials 20 | ## Add FreeRTOS to a Bare Metal Project 21 | * [Add FreeRTOS to a Bare Metal Project](docs/tutorial_1/README.md) 22 | 23 | ## Tasks and Scheduling 24 | * [Task Creation](docs/tutorial_2/README.md) 25 | * [Static Allocation](docs/tutorial_3/README.md) 26 | * [Task Priorities](docs/tutorial_4/README.md) 27 | * [Task Parameters](docs/tutorial_5/README.md) 28 | * [Scheduling Algorithm - Prioritized Preemptive Scheduling with Time Slicing](docs/tutorial_6/README.md) 29 | * [Scheduling Algorithm - Prioritized Preemptive Scheduling without Time Slicing](docs/tutorial_7/README.md) 30 | * [Scheduling Algorithm - Co-operative Scheduling](docs/tutorial_8/README.md) 31 | 32 | ## Queue 33 | * [Using Queues for Inter-Task Communication](docs/tutorial_9/README.md) 34 | * [Using Queues for Communication between Interrupts and Tasks](docs/tutorial_10/README.md) 35 | 36 | ## Software Timer 37 | * [Software Timers](docs/tutorial_11/README.md) 38 | 39 | ## Semaphore and Mutex 40 | * [Semaphore](docs/tutorial_12/README.md) 41 | * [Mutex](docs/tutorial_13/README.md) 42 | * [Priority Inversion and Priority Inheritance](docs/tutorial_14/README.md) 43 | 44 | ## Event Group 45 | * [Event Management using Event Groups](docs/tutorial_15/README.md) 46 | * [Task Synchronization using Event Groups](docs/tutorial_16/README.md) 47 | 48 | ## Task Notification 49 | * [Using Task Notifications as a Light Weight Binary Semaphore](docs/tutorial_17/README.md) 50 | * [Using Task Notifications as a Light Weight Event Group](docs/tutorial_18/README.md) 51 | 52 | ## Stream Buffer 53 | * [Stream Buffer](docs/tutorial_19/README.md) 54 | 55 | ## Message Buffer 56 | * [Message Buffer](docs/tutorial_20/README.md) 57 | 58 | ## Resource Management 59 | * [Resource Management](docs/tutorial_21/README.md) 60 | -------------------------------------------------------------------------------- /docs/tutorial_1/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Add FreeRTOS to a bare metal project. 3 | * Build and execute. 4 | 5 | # Concepts 6 | FreeRTOS code is organized into 2 parts: 7 | 1. **Common Code** - This is the code written in C and is applicable to all the 8 | platforms. This includes - 9 | * `FreeRTOS-Kernel/list.c` 10 | * `FreeRTOS-Kernel/tasks.c` 11 | * `FreeRTOS-Kernel/timers.c` 12 | * `FreeRTOS-Kernel/queue.c` 13 | * `FreeRTOS-Kernel/event_groups.c` 14 | * `FreeRTOS-Kernel/stream_buffer.c` 15 | * `FreeRTOS-Kernel/portable/MemMang/heap_x.c` where x is 1,2,3,4 or 5. 16 | 17 | 1. **Port Layer** - The code is written in Assembly and C and specific to the 18 | compiler (e.g. GCC) and the microcontroller architecture (e.g. Cortex-M4). 19 | We will use `FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix` port in our 20 | tutorials. 21 | 22 | 1. **Config File** - The application writer needs to provide a 23 | `FreeRTOSConfig.h` file to customize the FreeRTOS-Kernel behavior. 24 | 25 | # Steps 26 | 1. Execute the following commands from the root of the repository to build: 27 | ```shell 28 | rm -rf build 29 | mkdir build 30 | cd build 31 | cmake -B . -S ../source/ -DTUTORIAL=1 32 | make 33 | ``` 34 | 35 | 1. Execute the following command to run the binary: 36 | ```shell 37 | ./freertos_example 38 | ``` 39 | -------------------------------------------------------------------------------- /docs/tutorial_10/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Creating and using FreeRTOS queues to send messages between interrupts and 3 | tasks. 4 | 5 | # Concepts 6 | Queues are the primary mechanism for inter-task communications. They can be used 7 | to send messages between tasks, and between interrupts and tasks. 8 | 9 | # Steps 10 | 1. Complete all the TODOs in the `source/tutorials/tutorial_10/source/tutorial_10.c` 11 | file. 12 | 13 | 1. Execute the following commands from the root of the repository to build: 14 | ```shell 15 | rm -rf build 16 | mkdir build 17 | cd build 18 | cmake -B . -S ../source/ -DTUTORIAL=10 19 | make 20 | ``` 21 | 22 | 1. Execute the following command to run the binary: 23 | ```shell 24 | ./freertos_example 25 | ``` 26 | 27 | 1. Understand the output. 28 | -------------------------------------------------------------------------------- /docs/tutorial_11/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Software Timers. 3 | 4 | # Concepts 5 | Software timers are used to schedule the execution of a function at a set time 6 | in the future, or periodically with a fixed frequency. The function executed by 7 | the software timer is called the software timer's callback function. 8 | 9 | Software timer callback functions are implemented as C functions and must have 10 | the following prototype: 11 | 12 | ```c 13 | void TimerCallback( TimerHandle_t xTimer ); 14 | ``` 15 | A software timer’s period is the time between the software timer being started, 16 | and the software timer’s callback function executing. There are two types of 17 | software timer: 18 | 19 | 1. One-shot timers - Once started, a one-shot timer will execute its callback 20 | function once only. A one-shot timer can be restarted manually, but will not 21 | restart itself. 22 | 23 | 2. Auto-reload timers - Once started, an auto-reload timer will re-start itself 24 | each time it expires, resulting in periodic execution of its callback function. 25 | 26 | 27 | # Steps 28 | 1. Complete all the TODOs in the `source/tutorials/tutorial_11/source/tutorial_11.c` 29 | file. 30 | 31 | 1. Execute the following commands from the root of the repository to build: 32 | ```shell 33 | rm -rf build 34 | mkdir build 35 | cd build 36 | cmake -B . -S ../source/ -DTUTORIAL=11 37 | make 38 | ``` 39 | 40 | 1. Execute the following command to run the binary: 41 | ```shell 42 | ./freertos_example 43 | ``` 44 | 45 | 1. Understand the output. 46 | -------------------------------------------------------------------------------- /docs/tutorial_12/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Semaphore. 3 | 4 | # Concepts 5 | Semaphores are synchronization primitives to enable synchronization between 6 | tasks, and between interrupts and tasks. 7 | 8 | 9 | # Steps 10 | 1. Complete all the TODOs in the `source/tutorials/tutorial_12/source/tutorial_12.c` 11 | file. 12 | 13 | 1. Execute the following commands from the root of the repository to build: 14 | ```shell 15 | rm -rf build 16 | mkdir build 17 | cd build 18 | cmake -B . -S ../source/ -DTUTORIAL=12 19 | make 20 | ``` 21 | 22 | 1. Execute the following command to run the binary: 23 | ```shell 24 | ./freertos_example 25 | ``` 26 | 27 | 1. Understand the output. 28 | -------------------------------------------------------------------------------- /docs/tutorial_13/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Mutex. 3 | 4 | # Concepts 5 | Mutex, short for Mutual Exclusion, is a synchronization primitive used to 6 | synchronize access to a shared resource. 7 | 8 | # Steps 9 | 1. Complete all the TODOs in the `source/tutorials/tutorial_13/source/tutorial_13.c` 10 | file. 11 | 12 | 1. Execute the following commands from the root of the repository to build: 13 | ```shell 14 | rm -rf build 15 | mkdir build 16 | cd build 17 | cmake -B . -S ../source/ -DTUTORIAL=13 18 | make 19 | ``` 20 | 21 | 1. Execute the following command to run the binary: 22 | ```shell 23 | ./freertos_example 24 | ``` 25 | 26 | 1. Understand the output. 27 | -------------------------------------------------------------------------------- /docs/tutorial_14/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Priority Inversion and Priority Inheritance. 3 | 4 | # Concepts 5 | ## Priority Inversion 6 | Priority Inversion is a scenario in which a high priority task is indefinitely 7 | delayed while waiting for a resource held by a low priority task that cannot 8 | proceed due to the presence of an unrelated medium priority task. As a result, 9 | the high priority task is prevented from running by lower medium priority task, 10 | effectively inverting the assigned priorities of the tasks. This violates the 11 | priority model that high priority tasks can only be prevented from running by 12 | higher priority tasks. 13 | 14 | ## Priority Inheritance 15 | Priority Inheritance is a method for eliminating unbounded Priority Inversion. 16 | If a high priority task blocks while attempting to obtain a resource that is 17 | currently held by a lower priority task, then the priority of the task holding 18 | the resource is temporarily raised to that of the blocking task. This mechanism 19 | ensures that the higher priority task is kept in the blocked state for the 20 | shortest time possible, and in so doing minimize the 'priority inversion' that 21 | has already occurred. 22 | 23 | # Steps 24 | 1. Execute the following commands from the root of the repository to build: 25 | ```shell 26 | rm -rf build 27 | mkdir build 28 | cd build 29 | cmake -B . -S ../source/ -DTUTORIAL=14 30 | make 31 | ``` 32 | 33 | 1. Execute the following command to run the binary: 34 | ```shell 35 | ./freertos_example 36 | ``` 37 | 38 | 1. Understand the output. 39 | -------------------------------------------------------------------------------- /docs/tutorial_15/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Event Management using Event Groups. 3 | 4 | # Concepts 5 | Event groups are another synchronization primitives of FreeRTOS that allow 6 | events to be communicated to tasks. Unlike queues and semaphores: 7 | 8 | * Event groups allow a task to wait in the Blocked state for a combination of 9 | one of more events to occur. 10 | * Event groups unblock all the tasks that were waiting for the same event, or 11 | combination of events, when the event occurs. 12 | 13 | These unique properties of event groups make them useful for synchronizing 14 | multiple tasks, broadcasting events to more than one task, allowing a task to 15 | wait in the Blocked state for any one of a set of events to occur, and allowing 16 | a task to wait in the Blocked state for multiple actions to complete. 17 | 18 | # Steps 19 | 1. Complete all the TODOs in the `source/tutorials/tutorial_15/source/tutorial_15.c` 20 | file. 21 | 22 | 1. Execute the following commands from the root of the repository to build: 23 | ```shell 24 | rm -rf build 25 | mkdir build 26 | cd build 27 | cmake -B . -S ../source/ -DTUTORIAL=15 28 | make 29 | ``` 30 | 31 | 1. Execute the following command to run the binary: 32 | ```shell 33 | ./freertos_example 34 | ``` 35 | 36 | 1. Understand the output. 37 | -------------------------------------------------------------------------------- /docs/tutorial_16/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Task Synchronization using Event Groups. 3 | 4 | # Concepts 5 | An event group can be used to create a synchronization point: 6 | 7 | * Each task that must participate in the synchronization is assigned a unique 8 | event bit within the event group. 9 | * Each task sets its own event bit when it reaches the synchronization point. 10 | * Having set its own event bit, each task blocks on the event group to wait for 11 | the event bits that represent all the other synchronizing tasks to also become 12 | set. 13 | 14 | # Steps 15 | 1. Complete all the TODOs in the `source/tutorials/tutorial_16/source/tutorial_16.c` 16 | file. 17 | 18 | 1. Execute the following commands from the root of the repository to build: 19 | ```shell 20 | rm -rf build 21 | mkdir build 22 | cd build 23 | cmake -B . -S ../source/ -DTUTORIAL=16 24 | make 25 | ``` 26 | 27 | 1. Execute the following command to run the binary: 28 | ```shell 29 | ./freertos_example 30 | ``` 31 | 32 | 1. Understand the output. 33 | -------------------------------------------------------------------------------- /docs/tutorial_17/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Task notifications. 3 | * Using task notifications as a light weight binary semaphore. 4 | 5 | # Concepts 6 | Task notifications are an efficient mechanism to allow tasks to interact with 7 | other tasks, and to synchronize with ISRs, without the need for a separate 8 | communication object. Using a task notification to send an event or data to a 9 | task is significantly faster than using a queue, semaphore or event group to 10 | perform an equivalent operation. These performance benefits come with some use 11 | case limitations: 12 | 13 | 1. Task notifications can only be used when there is only one task that 14 | can be the recipient of the event. 15 | 1. While a receiving task can wait for a notification in the Blocked state 16 | (so not consuming any CPU time), a sending task cannot wait in the Blocked 17 | state for a send to complete if the send cannot complete immediately. 18 | 19 | ## Using task notifications as a light weight binary semaphore 20 | When a task notification is used in place of a binary semaphore the receiving 21 | task's notification value is used in place of the binary semaphore's count 22 | value, and the ulTaskNotifyTake() (or ulTaskNotifyTakeIndexed()) API function is 23 | used in place of the semaphore's xSemaphoreTake() API function. The 24 | ulTaskNotifyTake() function's xClearOnExit parameter is set to pdTRUE so the 25 | count value is returned to zero each time the notification is taken - emulating 26 | a binary semaphore. Likewise the xTaskNotifyGive() (or xTaskNotifyGiveIndexed()) 27 | is used in place of the semaphore's xSemaphoreGive() function. 28 | 29 | # Steps 30 | 1. Complete all the TODOs in the `source/tutorials/tutorial_17/source/tutorial_17.c` 31 | file. 32 | 33 | 1. Execute the following commands from the root of the repository to build: 34 | ```shell 35 | rm -rf build 36 | mkdir build 37 | cd build 38 | cmake -B . -S ../source/ -DTUTORIAL=17 39 | make 40 | ``` 41 | 42 | 1. Execute the following command to run the binary: 43 | ```shell 44 | ./freertos_example 45 | ``` 46 | 47 | 1. Understand the output. 48 | -------------------------------------------------------------------------------- /docs/tutorial_18/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Task notifications. 3 | * Using task notifications as a light weight event group. 4 | 5 | # Concepts 6 | Task notifications are an efficient mechanism to allow tasks to interact with 7 | other tasks, and to synchronize with ISRs, without the need for a separate 8 | communication object. Using a task notification to send an event or data to a 9 | task is significantly faster than using a queue, semaphore or event group to 10 | perform an equivalent operation. These performance benefits come with some use 11 | case limitations: 12 | 13 | 1. Task notifications can only be used when there is only one task that 14 | can be the recipient of the event. 15 | 1. While a receiving task can wait for a notification in the Blocked state 16 | (so not consuming any CPU time), a sending task cannot wait in the Blocked 17 | state for a send to complete if the send cannot complete immediately. 18 | 19 | ## Using task notifications as a light weight event group 20 | When a task notification is used in place of an event group the receiving 21 | task's notification value is used in place of the event group, bits within 22 | the receiving task's notification value are used as event flags, and the 23 | xTaskNotifyWait() API function is used in place of the event group's 24 | xEventGroupWaitBits() API function. Likewise, bits are set using the 25 | xTaskNotify() API function (with their eAction parameter set to eSetBits) in 26 | place of the xEventGroupSetBits() functions. 27 | 28 | # Steps 29 | 1. Complete all the TODOs in the `source/tutorials/tutorial_18/source/tutorial_18.c` 30 | file. 31 | 32 | 1. Execute the following commands from the root of the repository to build: 33 | ```shell 34 | rm -rf build 35 | mkdir build 36 | cd build 37 | cmake -B . -S ../source/ -DTUTORIAL=18 38 | make 39 | ``` 40 | 41 | 1. Execute the following command to run the binary: 42 | ```shell 43 | ./freertos_example 44 | ``` 45 | 46 | 1. Understand the output. 47 | -------------------------------------------------------------------------------- /docs/tutorial_19/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Stream Buffer. 3 | 4 | # Concepts 5 | Stream buffers are inter-task communication primitives to allow a stream of 6 | bytes to be passed from an interrupt service routine to a task, or from one task 7 | to another task. A byte stream can be of arbitrary length and does not 8 | necessarily have a beginning or end. 9 | 10 | **IMPORTANT NOTE:** The stream buffer implementation assumes there is only one 11 | task or interrupt that will write to the buffer (the writer), and only one task 12 | or interrupt that will read from the buffer (the reader). 13 | 14 | The amount of data that must be in the stream buffer before a task that is 15 | waiting for data, is removed from the blocked state is called the stream 16 | buffer's Trigger Level. For example: 17 | * If a task is blocked on a read of an empty stream buffer that has a trigger 18 | level of 1 then the task will be unblocked when a single byte is written to 19 | the buffer or the task's block time expires. 20 | * If a task is blocked on a read of an empty stream buffer that has a trigger 21 | level of 10 then the task will not be unblocked until the stream buffer 22 | contains at least 10 bytes or the task's block time expires. 23 | 24 | If a reading task's block time expires before the trigger level is reached then 25 | the task will still receive however many bytes are actually available. 26 | 27 | # Steps 28 | 1. Complete all the TODOs in the `source/tutorials/tutorial_19/source/tutorial_19.c` 29 | file. 30 | 31 | 1. Execute the following commands from the root of the repository to build: 32 | ```shell 33 | rm -rf build 34 | mkdir build 35 | cd build 36 | cmake -B . -S ../source/ -DTUTORIAL=19 37 | make 38 | ``` 39 | 40 | 1. Execute the following command to run the binary: 41 | ```shell 42 | ./freertos_example 43 | ``` 44 | 45 | 1. Understand the output. 46 | -------------------------------------------------------------------------------- /docs/tutorial_2/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Use FreeRTOS APIs to create a task. 3 | 4 | # Concepts 5 | 6 | ## Task Functions 7 | FreeRTOS Tasks are implemented as C functions which must have the following 8 | prototype: 9 | 10 | ```c 11 | void TaskFunction( void *pvParameters ); 12 | ``` 13 | 14 | Each task normally runs forever within an infinite loop, and does not exit. The 15 | structure of a typical task is shown below: 16 | 17 | ```c 18 | void TaskFunction( void *pvParameters ) 19 | { 20 | /* A task is normally implemented as an infinite loop. */ 21 | for( ;; ) 22 | { 23 | /* The code to implement the task functionality goes here. */ 24 | } 25 | } 26 | ``` 27 | 28 | # Steps 29 | 1. Complete all the TODOs in the `source/tutorials/tutorial_2/source/tutorial_2.c` 30 | file. 31 | 32 | 1. Execute the following commands from the root of the repository to build: 33 | ```shell 34 | rm -rf build 35 | mkdir build 36 | cd build 37 | cmake -B . -S ../source/ -DTUTORIAL=2 38 | make 39 | ``` 40 | 41 | 1. Execute the following command to run the binary: 42 | ```shell 43 | ./freertos_example 44 | ``` 45 | -------------------------------------------------------------------------------- /docs/tutorial_20/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Message Buffer. 3 | 4 | # Concepts 5 | Message buffers are inter-task communication primitives to allow variable length 6 | discrete messages to be passed from an interrupt service routine to a task, or 7 | from one task to another task. A message can only be read out in it entirety, 8 | not as individual bytes. 9 | 10 | **IMPORTANT NOTE:** The message buffer implementation assumes there is only one 11 | task or interrupt that will write to the buffer (the writer), and only one task 12 | or interrupt that will read from the buffer (the reader). 13 | 14 | # Steps 15 | 1. Complete all the TODOs in the `source/tutorials/tutorial_20/source/tutorial_20.c` 16 | file. 17 | 18 | 1. Execute the following commands from the root of the repository to build: 19 | ```shell 20 | rm -rf build 21 | mkdir build 22 | cd build 23 | cmake -B . -S ../source/ -DTUTORIAL=20 24 | make 25 | ``` 26 | 27 | 1. Execute the following command to run the binary: 28 | ```shell 29 | ./freertos_example 30 | ``` 31 | 32 | 1. Understand the output. 33 | -------------------------------------------------------------------------------- /docs/tutorial_21/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Resource Management. 3 | 4 | # Concepts 5 | In a multitasking system there is potential for error if one task starts to 6 | access a shared resource, but does not complete its access before being 7 | preempted. If the task leaves the resource in an inconsistent state, then access 8 | to the same resource by any other task or interrupt could result in data 9 | corruption, or other similar issue. 10 | 11 | To ensure data consistency is maintained at all times, access to a shared 12 | resource, must be managed using a 'mutual exclusion' technique. The goal is to 13 | ensure that, once a task starts to access a shared resource, the same task has 14 | exclusive access to the resource until the resource has been returned to a 15 | consistent state. 16 | 17 | FreeRTOS provides several features that can be used to implement mutual 18 | exclusion, but the best mutual exclusion method is to (whenever possible, as it 19 | is often not practical) design the application in such a way that resources are 20 | not shared, and each resource is accessed only from a single task. 21 | 22 | ## Critical Sections 23 | Critical sections are regions of code that are surrounded by calls to the macros 24 | `taskENTER_CRITICAL()` and `taskEXIT_CRITICAL()`, respectively. Critical 25 | sections work by disabling interrupts and therefore, must be kept very short, 26 | otherwise they will adversely affect interrupt response times. 27 | 28 | ## Suspending (or Locking) the Scheduler 29 | If a shared resource is only accessed from multiple tasks and not from any 30 | interrupt, the access to it can be synchronized by suspending (or locking) the 31 | scheduler. Suspending the scheduler prevents a context switch from occurring, 32 | but leaves interrupts enabled. If an interrupt requests a context switch while 33 | the scheduler is suspended, then the request is held pending, and is performed 34 | only when the scheduler is resumed (un-suspended). 35 | 36 | The scheduler is suspended by calling `vTaskSuspendAll()` and is resumed 37 | (un-suspended) by calling `xTaskResumeAll()`. 38 | 39 | ## Mutex 40 | Mutex, short for Mutual Exclusion, is a synchronization primitive used to 41 | synchronize access to a shared resource that is shared between two or more 42 | tasks. 43 | 44 | # Steps 45 | 1. Execute the following commands from the root of the repository to build: 46 | ```shell 47 | rm -rf build 48 | mkdir build 49 | cd build 50 | cmake -B . -S ../source/ -DTUTORIAL=21 51 | make 52 | ``` 53 | 54 | 1. Execute the following command to run the binary: 55 | ```shell 56 | ./freertos_example 57 | ``` 58 | 59 | 1. Understand the output. 60 | -------------------------------------------------------------------------------- /docs/tutorial_3/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Static allocation. 3 | 4 | # Concepts 5 | Each FreeRTOS task requires 2 blocks of memory - 6 | * Task Control Block (TCB) - FreeRTOS-Kernel uses it to store the control 7 | information of a task. 8 | * Stack - Each task maintains its own stack. 9 | 10 | If a task is created using `xTaskCreate` API, then the memory needed for TCB and 11 | Stack is allocated from the FreeRTOS heap by calling `pvPortMalloc`. If a task 12 | is created using `xTaskCreateStatic` API, then the memory needed for TCB and 13 | Stack is provided by the application writer. 14 | 15 | # Steps 16 | 1. Complete all the TODOs in the `source/tutorials/tutorial_3/source/tutorial_3.c` 17 | file. 18 | 19 | 1. Execute the following commands from the root of the repository to build: 20 | ```shell 21 | rm -rf build 22 | mkdir build 23 | cd build 24 | cmake -B . -S ../source/ -DTUTORIAL=3 25 | make 26 | ``` 27 | 28 | 1. Execute the following command to run the binary: 29 | ```shell 30 | ./freertos_example 31 | ``` 32 | -------------------------------------------------------------------------------- /docs/tutorial_4/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Task Priorities. 3 | 4 | # Concepts 5 | The FreeRTOS scheduler always runs the highest priority ready task (i.e. the 6 | task that is able to run). 7 | 8 | # Steps 9 | 1. Complete all the TODOs in the `source/tutorials/tutorial_4/source/tutorial_4.c` 10 | file. 11 | 12 | 1. Execute the following commands from the root of the repository to build: 13 | ```shell 14 | rm -rf build 15 | mkdir build 16 | cd build 17 | cmake -B . -S ../source/ -DTUTORIAL=4 18 | make 19 | ``` 20 | 21 | 1. Execute the following command to run the binary: 22 | ```shell 23 | ./freertos_example 24 | ``` 25 | -------------------------------------------------------------------------------- /docs/tutorial_5/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Task Parameters. 3 | 4 | # Concepts 5 | A task can be passed a value at the time of creation using the `pvParameters` 6 | parameter of the `xTaskCreate` API. The value is passed as the parameter to the 7 | created task. 8 | 9 | # Steps 10 | 1. Complete all the TODOs in the `source/tutorials/tutorial_5/source/tutorial_5.c` 11 | file. 12 | 13 | 1. Execute the following commands from the root of the repository to build: 14 | ```shell 15 | rm -rf build 16 | mkdir build 17 | cd build 18 | cmake -B . -S ../source/ -DTUTORIAL=5 19 | make 20 | ``` 21 | 22 | 1. Execute the following command to run the binary: 23 | ```shell 24 | ./freertos_example 25 | ``` 26 | -------------------------------------------------------------------------------- /docs/tutorial_6/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Scheduling Algorithms. 3 | 4 | # Concepts 5 | FreeRTOS-Kernel supports the following 3 scheduling algorithms: 6 | 1. Prioritized Preemptive Scheduling with Time Slicing 7 | 2. Prioritized Preemptive Scheduling without Time Slicing 8 | 3. Co-operative Scheduling 9 | 10 | ## Prioritized Preemptive Scheduling with Time Slicing 11 | The required FreeRTOSConfig.h settings are: 12 | 13 | ```c 14 | #define configUSE_PREEMPTION 1 15 | #define configUSE_TIME_SLICING 1 16 | ``` 17 | 18 | Prioritized Preemptive Scheduling with Time Slicing algorithm uses both 19 | Preemption and Time Slicing. 20 | 21 | **Preemption** - Preemptive scheduling algorithm immediately preempts the 22 | Running task if a task that has a priority higher than the Running task 23 | enters the Ready state. Being preempted means being involuntarily 24 | (without explicitly yielding or blocking) moved out of the Running state and 25 | into the Ready state to allow a different task to run. 26 | 27 | **Time Slicing** - Time slicing is used to share processing time between tasks 28 | of equal priority, even when the tasks do not explicitly yield or enter the 29 | Blocked state. Time Slicing selects a new task to run at the end of each 30 | time slice if there are other Ready state tasks that have the same priority 31 | as the Running task. A time slice is equal to the time between two RTOS tick 32 | interrupts. 33 | 34 | # Steps 35 | 36 | 1. Execute the following commands from the root of the repository to build: 37 | ```shell 38 | rm -rf build 39 | mkdir build 40 | cd build 41 | cmake -B . -S ../source/ -DTUTORIAL=6 42 | make 43 | ``` 44 | 45 | 1. Execute the following command to run the binary: 46 | ```shell 47 | ./freertos_example 48 | ``` 49 | 50 | 1. Understand the output. 51 | -------------------------------------------------------------------------------- /docs/tutorial_7/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Scheduling Algorithms. 3 | 4 | # Concepts 5 | FreeRTOS-Kernel supports the following 3 scheduling algorithms: 6 | 1. Prioritized Preemptive Scheduling with Time Slicing 7 | 2. Prioritized Preemptive Scheduling without Time Slicing 8 | 3. Co-operative Scheduling 9 | 10 | ## Prioritized Preemptive Scheduling without Time Slicing 11 | The required FreeRTOSConfig.h settings are: 12 | 13 | ```c 14 | #define configUSE_PREEMPTION 1 15 | #define configUSE_TIME_SLICING 0 16 | ``` 17 | 18 | Prioritized Preemptive Scheduling with without Slicing algorithm uses 19 | Preemption but does not use Time Slicing. 20 | 21 | **Preemption** - Preemptive scheduling algorithm immediately preempts the 22 | Running task if a task that has a priority higher than the Running task 23 | enters the Ready state. Being preempted means being involuntarily 24 | (without explicitly yielding or blocking) moved out of the Running state and 25 | into the Ready state to allow a different task to run. 26 | 27 | **Time Slicing** - Time slicing is used to share processing time between tasks 28 | of equal priority, even when the tasks do not explicitly yield or enter the 29 | Blocked state. Time Slicing selects a new task to run at the end of each 30 | time slice if there are other Ready state tasks that have the same priority 31 | as the Running task. A time slice is equal to the time between two RTOS tick 32 | interrupts. 33 | 34 | # Steps 35 | 36 | 1. Execute the following commands from the root of the repository to build: 37 | ```shell 38 | rm -rf build 39 | mkdir build 40 | cd build 41 | cmake -B . -S ../source/ -DTUTORIAL=7 42 | make 43 | ``` 44 | 45 | 1. Execute the following command to run the binary: 46 | ```shell 47 | ./freertos_example 48 | ``` 49 | 50 | 1. Understand the output. 51 | -------------------------------------------------------------------------------- /docs/tutorial_8/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Scheduling Algorithms. 3 | 4 | # Concepts 5 | FreeRTOS-Kernel supports the following 3 scheduling algorithms: 6 | 1. Prioritized Preemptive Scheduling with Time Slicing 7 | 2. Prioritized Preemptive Scheduling without Time Slicing 8 | 3. Co-operative Scheduling 9 | 10 | ## Co-operative Scheduling 11 | The required FreeRTOSConfig.h settings are: 12 | 13 | ```c 14 | #define configUSE_PREEMPTION 0 15 | ``` 16 | 17 | When the co-operative scheduling is used, a context switch will only occur 18 | when the Running task enters the Blocked state, or the Running task 19 | explicitly yields (manually requests a re-schedule) by calling 20 | taskYIELD(). Tasks are never preempted, so time slicing cannot be used. 21 | 22 | # Steps 23 | 24 | 1. Execute the following commands from the root of the repository to build: 25 | ```shell 26 | rm -rf build 27 | mkdir build 28 | cd build 29 | cmake -B . -S ../source/ -DTUTORIAL=8 30 | make 31 | ``` 32 | 33 | 1. Execute the following command to run the binary: 34 | ```shell 35 | ./freertos_example 36 | ``` 37 | 38 | 1. Understand the output. 39 | -------------------------------------------------------------------------------- /docs/tutorial_9/README.md: -------------------------------------------------------------------------------- 1 | # Learning Objectives 2 | * Creating and using FreeRTOS queues to send messages between tasks. 3 | 4 | # Concepts 5 | Queues are the primary mechanism for inter-task communications. They can be used 6 | to send messages between tasks, and between interrupts and tasks. 7 | 8 | # Steps 9 | 1. Complete all the TODOs in the `source/tutorials/tutorial_9/source/tutorial_9.c` 10 | file. 11 | 12 | 1. Execute the following commands from the root of the repository to build: 13 | ```shell 14 | rm -rf build 15 | mkdir build 16 | cd build 17 | cmake -B . -S ../source/ -DTUTORIAL=9 18 | make 19 | ``` 20 | 21 | 1. Execute the following command to run the binary: 22 | ```shell 23 | ./freertos_example 24 | ``` 25 | 26 | 1. Understand the output. 27 | -------------------------------------------------------------------------------- /source/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.15 ) 2 | project( freertos_example ) 3 | 4 | # Compiler flags. 5 | add_compile_options( -Wall -Wextra -Wpedantic ) 6 | set( CMAKE_CXX_FLAGS_RELEASE "-O3" ) 7 | set( CMAKE_CXX_FLAGS_DEBUG "-O0 -g3" ) 8 | 9 | # Default to 1st tutorial. 10 | if( NOT DEFINED TUTORIAL ) 11 | set( TUTORIAL 1 ) 12 | endif() 13 | 14 | set( FREERTOS_KERNEL_PATH "FreeRTOS-Kernel" ) 15 | set( FREERTOS_TUTORIAL_INCLUDE_SEARCH_PATH "tutorials/tutorial_${TUTORIAL}/include" ) 16 | file( GLOB FREERTOS_TUTORIAL_SOURCES "tutorials/tutorial_${TUTORIAL}/source/*.c" ) 17 | 18 | # Add the freertos_config for FreeRTOS-Kernel. 19 | add_library( freertos_config INTERFACE ) 20 | target_include_directories( freertos_config 21 | INTERFACE 22 | ${FREERTOS_TUTORIAL_INCLUDE_SEARCH_PATH} ) 23 | 24 | # Select heap 3. 25 | set( FREERTOS_HEAP "3" CACHE STRING "" FORCE ) 26 | 27 | # Select the Posix port. 28 | set( FREERTOS_PORT "GCC_POSIX" CACHE STRING "" FORCE ) 29 | 30 | # Add the FreeRTOS-Kernel subdirectory. 31 | add_subdirectory( ${FREERTOS_KERNEL_PATH} ${CMAKE_CURRENT_BINARY_DIR}/FreeRTOS-Kernel ) 32 | 33 | add_executable( freertos_example 34 | ${FREERTOS_TUTORIAL_SOURCES} ) 35 | 36 | target_link_libraries( freertos_example freertos_kernel freertos_config ) 37 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_1/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 30 | #define configUSE_IDLE_HOOK 0 31 | #define configUSE_TICK_HOOK 0 32 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 33 | #define configTICK_RATE_HZ ( 1000 ) 34 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 35 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 36 | #define configMAX_TASK_NAME_LEN ( 12 ) 37 | #define configUSE_TRACE_FACILITY 1 38 | #define configUSE_16_BIT_TICKS 0 39 | #define configIDLE_SHOULD_YIELD 1 40 | #define configUSE_MUTEXES 1 41 | #define configCHECK_FOR_STACK_OVERFLOW 0 42 | #define configUSE_RECURSIVE_MUTEXES 1 43 | #define configQUEUE_REGISTRY_SIZE 20 44 | #define configUSE_APPLICATION_TASK_TAG 1 45 | #define configUSE_COUNTING_SEMAPHORES 1 46 | #define configUSE_ALTERNATIVE_API 0 47 | #define configUSE_QUEUE_SETS 1 48 | #define configUSE_TASK_NOTIFICATIONS 1 49 | #define configSUPPORT_STATIC_ALLOCATION 0 50 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 51 | #define configRECORD_STACK_HIGH_ADDRESS 1 52 | 53 | /* Software timer related configuration options. The maximum possible task 54 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 55 | * deliberately set higher to ensure it is correctly capped back to 56 | * configMAX_PRIORITIES - 1. */ 57 | #define configUSE_TIMERS 1 58 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 59 | #define configTIMER_QUEUE_LENGTH 20 60 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 61 | 62 | #define configMAX_PRIORITIES ( 7 ) 63 | 64 | /* Co-routine related configuration options. */ 65 | #define configUSE_CO_ROUTINES 0 66 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 67 | 68 | /* Set the following definitions to 1 to include the API function, or zero 69 | * to exclude the API function. In most cases the linker will remove unused 70 | * functions anyway. */ 71 | #define INCLUDE_vTaskPrioritySet 1 72 | #define INCLUDE_uxTaskPriorityGet 1 73 | #define INCLUDE_vTaskDelete 1 74 | #define INCLUDE_vTaskCleanUpResources 0 75 | #define INCLUDE_vTaskSuspend 1 76 | #define INCLUDE_vTaskDelayUntil 1 77 | #define INCLUDE_vTaskDelay 1 78 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 79 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 80 | #define INCLUDE_xTaskGetSchedulerState 1 81 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 82 | #define INCLUDE_xTaskGetIdleTaskHandle 1 83 | #define INCLUDE_xTaskGetHandle 1 84 | #define INCLUDE_eTaskGetState 1 85 | #define INCLUDE_xSemaphoreGetMutexHolder 1 86 | #define INCLUDE_xTimerPendFunctionCall 1 87 | #define INCLUDE_xTaskAbortDelay 1 88 | 89 | /* It is a good idea to define configASSERT() while developing. configASSERT() 90 | * uses the same semantics as the standard C assert() macro. Don't define 91 | * configASSERT() when performing code coverage tests though, as it is not 92 | * intended to asserts() to fail, some code is intended not to run if no 93 | * errors are present. */ 94 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 95 | 96 | #endif /* FREERTOS_CONFIG_H */ 97 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_1/source/tutorial_1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | /* Standard includes. */ 26 | #include 27 | #include 28 | 29 | /** 30 | * @brief Tutorial entry point. 31 | */ 32 | int main( void ) 33 | { 34 | for( ; ; ) 35 | { 36 | fprintf( stderr, "Tutorial 1 running...\r\n" ); 37 | 38 | /* Sleep for a second. */ 39 | sleep( 1 ); 40 | } 41 | 42 | return 0; 43 | } 44 | /*-----------------------------------------------------------*/ 45 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_10/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_TIME_SLICING 1 30 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 31 | #define configUSE_IDLE_HOOK 0 32 | #define configUSE_TICK_HOOK 1 33 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 34 | #define configTICK_RATE_HZ ( 1000 ) 35 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 36 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 37 | #define configMAX_TASK_NAME_LEN ( 12 ) 38 | #define configUSE_TRACE_FACILITY 1 39 | #define configUSE_16_BIT_TICKS 0 40 | #define configIDLE_SHOULD_YIELD 1 41 | #define configUSE_MUTEXES 1 42 | #define configCHECK_FOR_STACK_OVERFLOW 0 43 | #define configUSE_RECURSIVE_MUTEXES 1 44 | #define configQUEUE_REGISTRY_SIZE 20 45 | #define configUSE_APPLICATION_TASK_TAG 1 46 | #define configUSE_COUNTING_SEMAPHORES 1 47 | #define configUSE_ALTERNATIVE_API 0 48 | #define configUSE_QUEUE_SETS 1 49 | #define configUSE_TASK_NOTIFICATIONS 1 50 | #define configSUPPORT_STATIC_ALLOCATION 1 51 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 52 | #define configRECORD_STACK_HIGH_ADDRESS 1 53 | #define configKERNEL_PROVIDED_STATIC_MEMORY 1 54 | 55 | /* Software timer related configuration options. The maximum possible task 56 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 57 | * deliberately set higher to ensure it is correctly capped back to 58 | * configMAX_PRIORITIES - 1. */ 59 | #define configUSE_TIMERS 1 60 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 61 | #define configTIMER_QUEUE_LENGTH 20 62 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 63 | 64 | #define configMAX_PRIORITIES ( 7 ) 65 | 66 | /* Co-routine related configuration options. */ 67 | #define configUSE_CO_ROUTINES 0 68 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 69 | 70 | /* Set the following definitions to 1 to include the API function, or zero 71 | * to exclude the API function. In most cases the linker will remove unused 72 | * functions anyway. */ 73 | #define INCLUDE_vTaskPrioritySet 1 74 | #define INCLUDE_uxTaskPriorityGet 1 75 | #define INCLUDE_vTaskDelete 1 76 | #define INCLUDE_vTaskCleanUpResources 0 77 | #define INCLUDE_vTaskSuspend 1 78 | #define INCLUDE_vTaskDelayUntil 1 79 | #define INCLUDE_vTaskDelay 1 80 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 81 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 82 | #define INCLUDE_xTaskGetSchedulerState 1 83 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 84 | #define INCLUDE_xTaskGetIdleTaskHandle 1 85 | #define INCLUDE_xTaskGetHandle 1 86 | #define INCLUDE_eTaskGetState 1 87 | #define INCLUDE_xSemaphoreGetMutexHolder 1 88 | #define INCLUDE_xTimerPendFunctionCall 1 89 | #define INCLUDE_xTaskAbortDelay 1 90 | 91 | /* It is a good idea to define configASSERT() while developing. configASSERT() 92 | * uses the same semantics as the standard C assert() macro. Don't define 93 | * configASSERT() when performing code coverage tests though, as it is not 94 | * intended to asserts() to fail, some code is intended not to run if no 95 | * errors are present. */ 96 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 97 | 98 | #endif /* FREERTOS_CONFIG_H */ 99 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_10/source/tutorial_10.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | /* Standard includes. */ 26 | #include 27 | #include 28 | 29 | /* FreeRTOS includes. */ 30 | #include "FreeRTOS.h" 31 | #include "task.h" 32 | #include "queue.h" 33 | 34 | /** 35 | * @brief Function that implement FreeRTOS task. 36 | */ 37 | static void prvReceiverTask( void * pvParams ); 38 | /*-----------------------------------------------------------*/ 39 | 40 | /** 41 | * @brief Queue used in the program. 42 | */ 43 | static QueueHandle_t xQueue; 44 | 45 | /** 46 | * @brief Counter used in the program. 47 | */ 48 | static UBaseType_t uxCounter = 0; 49 | /*-----------------------------------------------------------*/ 50 | 51 | /** 52 | * @brief Tutorial entry point. 53 | */ 54 | int main( void ) 55 | { 56 | BaseType_t xTaskCreationResult = pdFAIL; 57 | 58 | xTaskCreationResult = xTaskCreate( prvReceiverTask, 59 | "Receiver", 60 | configMINIMAL_STACK_SIZE, 61 | NULL, 62 | tskIDLE_PRIORITY, 63 | NULL ); 64 | configASSERT( xTaskCreationResult == pdPASS ); 65 | 66 | /* TODO 1 - Create a queue capable of holding 5 UBaseType_t using 67 | * xQueueCreate API. 68 | * 69 | * Use the following values for xQueueCreate parameters: 70 | * uxQueueLength 5 71 | * uxItemSize sizeof( UBaseType_t ) 72 | * 73 | * Assign the return value to xQueue. 74 | */ 75 | 76 | configASSERT( xQueue != NULL ); 77 | 78 | /* Start the scheduler. */ 79 | vTaskStartScheduler(); 80 | 81 | /* Should not reach here. */ 82 | for( ;; ) 83 | { 84 | 85 | } 86 | 87 | /* Just to make the compiler happy. */ 88 | return 0; 89 | } 90 | /*-----------------------------------------------------------*/ 91 | 92 | static void prvReceiverTask( void * pvParams ) 93 | { 94 | UBaseType_t uxReceivedValue; 95 | 96 | /* Silence warning about unused parameters. */ 97 | ( void ) pvParams; 98 | 99 | for( ;; ) 100 | { 101 | /* TODO 2 - Receive from the queue using xQueueReceive API. 102 | * 103 | * Use the following values for xQueueReceive parameters: 104 | * xQueue xQueue 105 | * pvBuffer &( uxReceivedValue ) 106 | * xTicksToWait portMAX_DELAY 107 | */ 108 | 109 | 110 | fprintf( stderr, "Value received from the queue: %lu\r\n", uxReceivedValue ); 111 | fprintf( stderr, "Number of items in the queue: %lu.\r\n", uxQueueMessagesWaiting( xQueue ) ); 112 | } 113 | } 114 | /*-----------------------------------------------------------*/ 115 | 116 | void vApplicationTickHook( void ) 117 | { 118 | BaseType_t xQueueSendResult = pdFAIL; 119 | BaseType_t xHighPriorityTaskWoken = pdFALSE; 120 | 121 | uxCounter++; 122 | 123 | if( ( uxCounter % 1000 ) == 0 ) 124 | { 125 | /* TODO 3 - Send uxCounter to the queue using xQueueSendFromISR API. 126 | * 127 | * Use the following values for xQueueSend parameters: 128 | * xQueue xQueue 129 | * pvItemToQueue &( uxCounter ) 130 | * pxHigherPriorityTaskWoken &( xHighPriorityTaskWoken ) 131 | * 132 | * Assign the return value to xQueueSendResult. 133 | */ 134 | 135 | configASSERT( xQueueSendResult == pdPASS ); 136 | } 137 | 138 | portYIELD_FROM_ISR( xHighPriorityTaskWoken ); 139 | } 140 | /*-----------------------------------------------------------*/ 141 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_11/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_TIME_SLICING 1 30 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 31 | #define configUSE_IDLE_HOOK 0 32 | #define configUSE_TICK_HOOK 0 33 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 34 | #define configTICK_RATE_HZ ( 1000 ) 35 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 36 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 37 | #define configMAX_TASK_NAME_LEN ( 12 ) 38 | #define configUSE_TRACE_FACILITY 1 39 | #define configUSE_16_BIT_TICKS 0 40 | #define configIDLE_SHOULD_YIELD 1 41 | #define configUSE_MUTEXES 1 42 | #define configCHECK_FOR_STACK_OVERFLOW 0 43 | #define configUSE_RECURSIVE_MUTEXES 1 44 | #define configQUEUE_REGISTRY_SIZE 20 45 | #define configUSE_APPLICATION_TASK_TAG 1 46 | #define configUSE_COUNTING_SEMAPHORES 1 47 | #define configUSE_ALTERNATIVE_API 0 48 | #define configUSE_QUEUE_SETS 1 49 | #define configUSE_TASK_NOTIFICATIONS 1 50 | #define configSUPPORT_STATIC_ALLOCATION 1 51 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 52 | #define configRECORD_STACK_HIGH_ADDRESS 1 53 | #define configKERNEL_PROVIDED_STATIC_MEMORY 1 54 | 55 | /* Software timer related configuration options. The maximum possible task 56 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 57 | * deliberately set higher to ensure it is correctly capped back to 58 | * configMAX_PRIORITIES - 1. */ 59 | #define configUSE_TIMERS 1 60 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 61 | #define configTIMER_QUEUE_LENGTH 20 62 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 63 | 64 | #define configMAX_PRIORITIES ( 7 ) 65 | 66 | /* Co-routine related configuration options. */ 67 | #define configUSE_CO_ROUTINES 0 68 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 69 | 70 | /* Set the following definitions to 1 to include the API function, or zero 71 | * to exclude the API function. In most cases the linker will remove unused 72 | * functions anyway. */ 73 | #define INCLUDE_vTaskPrioritySet 1 74 | #define INCLUDE_uxTaskPriorityGet 1 75 | #define INCLUDE_vTaskDelete 1 76 | #define INCLUDE_vTaskCleanUpResources 0 77 | #define INCLUDE_vTaskSuspend 1 78 | #define INCLUDE_vTaskDelayUntil 1 79 | #define INCLUDE_vTaskDelay 1 80 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 81 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 82 | #define INCLUDE_xTaskGetSchedulerState 1 83 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 84 | #define INCLUDE_xTaskGetIdleTaskHandle 1 85 | #define INCLUDE_xTaskGetHandle 1 86 | #define INCLUDE_eTaskGetState 1 87 | #define INCLUDE_xSemaphoreGetMutexHolder 1 88 | #define INCLUDE_xTimerPendFunctionCall 1 89 | #define INCLUDE_xTaskAbortDelay 1 90 | 91 | /* It is a good idea to define configASSERT() while developing. configASSERT() 92 | * uses the same semantics as the standard C assert() macro. Don't define 93 | * configASSERT() when performing code coverage tests though, as it is not 94 | * intended to asserts() to fail, some code is intended not to run if no 95 | * errors are present. */ 96 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 97 | 98 | #endif /* FREERTOS_CONFIG_H */ 99 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_11/source/tutorial_11.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | /* Standard includes. */ 26 | #include 27 | #include 28 | 29 | /* FreeRTOS includes. */ 30 | #include "FreeRTOS.h" 31 | #include "task.h" 32 | #include "timers.h" 33 | 34 | /** 35 | * @brief Timer callback function. 36 | */ 37 | static void prvTimerCallback( TimerHandle_t xTimer ); 38 | /*-----------------------------------------------------------*/ 39 | 40 | /** 41 | * @brief Tutorial entry point. 42 | */ 43 | int main( void ) 44 | { 45 | BaseType_t xTimerStartResult = pdFAIL; 46 | TimerHandle_t xAutoReloadTimer, xOneShotTimer; 47 | 48 | /* 49 | * TODO 1 - Create an auto-reload timer with 1000 ms period using 50 | * xTimerCreate API. 51 | * 52 | * Use the following values for xTimerCreate parameters: 53 | * pcTimerName "AutoTimer" 54 | * xTimerPeriodInTicks pdMS_TO_TICKS( 1000 ) 55 | * xAutoReload pdTRUE 56 | * pvTimerID ( void * ) 1 57 | * pxCallbackFunction prvTimerCallback 58 | * 59 | * Assign the return value to xAutoReloadTimer. 60 | */ 61 | 62 | configASSERT( xAutoReloadTimer != NULL ); 63 | 64 | /* 65 | * TODO 2 - Create a one-shot timer with 100 ms period using xTimerCreate 66 | * API. 67 | * 68 | * Use the following values for xTimerCreate parameters: 69 | * pcTimerName "OneTimer" 70 | * xTimerPeriodInTicks pdMS_TO_TICKS( 100 ) 71 | * xAutoReload pdFALSE 72 | * pvTimerID ( void * ) 2 73 | * pxCallbackFunction prvTimerCallback 74 | * 75 | * Assign the return value to xOneShotTimer. 76 | */ 77 | 78 | configASSERT( xOneShotTimer != NULL ); 79 | 80 | /* 81 | * TODO 3 - Start the auto-reload timer using xTimerStart API. 82 | * 83 | * Use the following values for xTimerStart parameters: 84 | * xTimer xAutoReloadTimer 85 | * xTicksToWait 0 86 | * 87 | * Assign the return value to xTimerStartResult. 88 | */ 89 | 90 | configASSERT( xTimerStartResult == pdPASS ); 91 | 92 | /* 93 | * TODO 4 - Start the one-shot timer using xTimerStart API. 94 | * 95 | * Use the following values for xTimerStart parameters: 96 | * xTimer xOneShotTimer 97 | * xTicksToWait 0 98 | * 99 | * Assign the return value to xTimerStartResult. 100 | */ 101 | 102 | configASSERT( xTimerStartResult == pdPASS ); 103 | 104 | /* Start the scheduler. */ 105 | vTaskStartScheduler(); 106 | 107 | /* Should not reach here. */ 108 | for( ;; ) 109 | { 110 | 111 | } 112 | 113 | /* Just to make the compiler happy. */ 114 | return 0; 115 | } 116 | /*-----------------------------------------------------------*/ 117 | 118 | static void prvTimerCallback( TimerHandle_t xTimer ) 119 | { 120 | fprintf( stderr, "Callback for Timer ID %p running...\r\n", pvTimerGetTimerID( xTimer ) ); 121 | } 122 | /*-----------------------------------------------------------*/ 123 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_12/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_TIME_SLICING 1 30 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 31 | #define configUSE_IDLE_HOOK 0 32 | #define configUSE_TICK_HOOK 0 33 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 34 | #define configTICK_RATE_HZ ( 1000 ) 35 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 36 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 37 | #define configMAX_TASK_NAME_LEN ( 12 ) 38 | #define configUSE_TRACE_FACILITY 1 39 | #define configUSE_16_BIT_TICKS 0 40 | #define configIDLE_SHOULD_YIELD 1 41 | #define configUSE_MUTEXES 1 42 | #define configCHECK_FOR_STACK_OVERFLOW 0 43 | #define configUSE_RECURSIVE_MUTEXES 1 44 | #define configQUEUE_REGISTRY_SIZE 20 45 | #define configUSE_APPLICATION_TASK_TAG 1 46 | #define configUSE_COUNTING_SEMAPHORES 1 47 | #define configUSE_ALTERNATIVE_API 0 48 | #define configUSE_QUEUE_SETS 1 49 | #define configUSE_TASK_NOTIFICATIONS 1 50 | #define configSUPPORT_STATIC_ALLOCATION 1 51 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 52 | #define configRECORD_STACK_HIGH_ADDRESS 1 53 | #define configKERNEL_PROVIDED_STATIC_MEMORY 1 54 | 55 | /* Software timer related configuration options. The maximum possible task 56 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 57 | * deliberately set higher to ensure it is correctly capped back to 58 | * configMAX_PRIORITIES - 1. */ 59 | #define configUSE_TIMERS 1 60 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 61 | #define configTIMER_QUEUE_LENGTH 20 62 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 63 | 64 | #define configMAX_PRIORITIES ( 7 ) 65 | 66 | /* Co-routine related configuration options. */ 67 | #define configUSE_CO_ROUTINES 0 68 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 69 | 70 | /* Set the following definitions to 1 to include the API function, or zero 71 | * to exclude the API function. In most cases the linker will remove unused 72 | * functions anyway. */ 73 | #define INCLUDE_vTaskPrioritySet 1 74 | #define INCLUDE_uxTaskPriorityGet 1 75 | #define INCLUDE_vTaskDelete 1 76 | #define INCLUDE_vTaskCleanUpResources 0 77 | #define INCLUDE_vTaskSuspend 1 78 | #define INCLUDE_vTaskDelayUntil 1 79 | #define INCLUDE_vTaskDelay 1 80 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 81 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 82 | #define INCLUDE_xTaskGetSchedulerState 1 83 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 84 | #define INCLUDE_xTaskGetIdleTaskHandle 1 85 | #define INCLUDE_xTaskGetHandle 1 86 | #define INCLUDE_eTaskGetState 1 87 | #define INCLUDE_xSemaphoreGetMutexHolder 1 88 | #define INCLUDE_xTimerPendFunctionCall 1 89 | #define INCLUDE_xTaskAbortDelay 1 90 | 91 | /* It is a good idea to define configASSERT() while developing. configASSERT() 92 | * uses the same semantics as the standard C assert() macro. Don't define 93 | * configASSERT() when performing code coverage tests though, as it is not 94 | * intended to asserts() to fail, some code is intended not to run if no 95 | * errors are present. */ 96 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 97 | 98 | #endif /* FREERTOS_CONFIG_H */ 99 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_12/source/tutorial_12.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | /* Standard includes. */ 26 | #include 27 | #include 28 | 29 | /* FreeRTOS includes. */ 30 | #include "FreeRTOS.h" 31 | #include "task.h" 32 | #include "semphr.h" 33 | 34 | /** 35 | * @brief Functions that implement FreeRTOS tasks. 36 | */ 37 | static void prvTask1( void * pvParams ); 38 | static void prvTask2( void * pvParams ); 39 | /*-----------------------------------------------------------*/ 40 | 41 | /** 42 | * @brief Semaphore used in this program. 43 | */ 44 | static SemaphoreHandle_t xSemaphore = NULL; 45 | /*-----------------------------------------------------------*/ 46 | 47 | /** 48 | * @brief Tutorial entry point. 49 | */ 50 | int main( void ) 51 | { 52 | BaseType_t xTaskCreationResult = pdFAIL; 53 | 54 | xTaskCreationResult = xTaskCreate( prvTask1, 55 | "Task1", 56 | configMINIMAL_STACK_SIZE, 57 | NULL, 58 | tskIDLE_PRIORITY + 1, 59 | NULL ); 60 | configASSERT( xTaskCreationResult == pdPASS ); 61 | 62 | xTaskCreationResult = xTaskCreate( prvTask2, 63 | "Task2", 64 | configMINIMAL_STACK_SIZE, 65 | NULL, 66 | tskIDLE_PRIORITY, 67 | NULL ); 68 | configASSERT( xTaskCreationResult == pdPASS ); 69 | 70 | /* 71 | * TODO 1 - Create a binary semaphore using xSemaphoreCreateBinary API. 72 | * 73 | * Assign the return value to xSemaphore. 74 | */ 75 | 76 | configASSERT( xSemaphore != NULL ); 77 | 78 | /* Start the scheduler. */ 79 | vTaskStartScheduler(); 80 | 81 | /* Should not reach here. */ 82 | for( ;; ) 83 | { 84 | 85 | } 86 | 87 | /* Just to make the compiler happy. */ 88 | return 0; 89 | } 90 | /*-----------------------------------------------------------*/ 91 | 92 | static void prvTask1( void * pvParams ) 93 | { 94 | /* Silence warning about unused parameters. */ 95 | ( void ) pvParams; 96 | 97 | for( ;; ) 98 | { 99 | /* 100 | * TODO 2 - Take the semaphore using the xSemaphoreTake API. 101 | * 102 | * Use the following values for xSemaphoreTake parameters: 103 | * xSemaphore xSemaphore 104 | * xBlockTime portMAX_DELAY 105 | */ 106 | 107 | fprintf( stderr, "Task 1 is running...\r\n" ); 108 | } 109 | 110 | } 111 | /*-----------------------------------------------------------*/ 112 | 113 | static void prvTask2( void * pvParams ) 114 | { 115 | BaseType_t xSemaphoreGiveResult = pdFAIL; 116 | 117 | /* Silence warning about unused parameters. */ 118 | ( void ) pvParams; 119 | 120 | for( ;; ) 121 | { 122 | fprintf( stderr, "Task 2 - signalling Task 1...\r\n" ); 123 | 124 | /* 125 | * TODO 3 - Give the semaphore using the xSemaphoreGive API. 126 | * 127 | * Use the following values for xSemaphoreGive parameters: 128 | * xSemaphore xSemaphore 129 | * 130 | * Assign the return value to xSemaphoreGiveResult. 131 | */ 132 | 133 | configASSERT( xSemaphoreGiveResult == pdPASS ); 134 | 135 | fprintf( stderr, "Task 2 is running...\r\n" ); 136 | 137 | vTaskDelay( pdMS_TO_TICKS( 1000 ) ); 138 | } 139 | } 140 | /*-----------------------------------------------------------*/ 141 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_13/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_TIME_SLICING 1 30 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 31 | #define configUSE_IDLE_HOOK 0 32 | #define configUSE_TICK_HOOK 0 33 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 34 | #define configTICK_RATE_HZ ( 1000 ) 35 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 36 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 37 | #define configMAX_TASK_NAME_LEN ( 12 ) 38 | #define configUSE_TRACE_FACILITY 1 39 | #define configUSE_16_BIT_TICKS 0 40 | #define configIDLE_SHOULD_YIELD 1 41 | #define configUSE_MUTEXES 1 42 | #define configCHECK_FOR_STACK_OVERFLOW 0 43 | #define configUSE_RECURSIVE_MUTEXES 1 44 | #define configQUEUE_REGISTRY_SIZE 20 45 | #define configUSE_APPLICATION_TASK_TAG 1 46 | #define configUSE_COUNTING_SEMAPHORES 1 47 | #define configUSE_ALTERNATIVE_API 0 48 | #define configUSE_QUEUE_SETS 1 49 | #define configUSE_TASK_NOTIFICATIONS 1 50 | #define configSUPPORT_STATIC_ALLOCATION 1 51 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 52 | #define configRECORD_STACK_HIGH_ADDRESS 1 53 | #define configKERNEL_PROVIDED_STATIC_MEMORY 1 54 | 55 | /* Software timer related configuration options. The maximum possible task 56 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 57 | * deliberately set higher to ensure it is correctly capped back to 58 | * configMAX_PRIORITIES - 1. */ 59 | #define configUSE_TIMERS 1 60 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 61 | #define configTIMER_QUEUE_LENGTH 20 62 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 63 | 64 | #define configMAX_PRIORITIES ( 7 ) 65 | 66 | /* Co-routine related configuration options. */ 67 | #define configUSE_CO_ROUTINES 0 68 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 69 | 70 | /* Set the following definitions to 1 to include the API function, or zero 71 | * to exclude the API function. In most cases the linker will remove unused 72 | * functions anyway. */ 73 | #define INCLUDE_vTaskPrioritySet 1 74 | #define INCLUDE_uxTaskPriorityGet 1 75 | #define INCLUDE_vTaskDelete 1 76 | #define INCLUDE_vTaskCleanUpResources 0 77 | #define INCLUDE_vTaskSuspend 1 78 | #define INCLUDE_vTaskDelayUntil 1 79 | #define INCLUDE_vTaskDelay 1 80 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 81 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 82 | #define INCLUDE_xTaskGetSchedulerState 1 83 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 84 | #define INCLUDE_xTaskGetIdleTaskHandle 1 85 | #define INCLUDE_xTaskGetHandle 1 86 | #define INCLUDE_eTaskGetState 1 87 | #define INCLUDE_xSemaphoreGetMutexHolder 1 88 | #define INCLUDE_xTimerPendFunctionCall 1 89 | #define INCLUDE_xTaskAbortDelay 1 90 | 91 | /* It is a good idea to define configASSERT() while developing. configASSERT() 92 | * uses the same semantics as the standard C assert() macro. Don't define 93 | * configASSERT() when performing code coverage tests though, as it is not 94 | * intended to asserts() to fail, some code is intended not to run if no 95 | * errors are present. */ 96 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 97 | 98 | #endif /* FREERTOS_CONFIG_H */ 99 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_13/source/tutorial_13.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | /* Standard includes. */ 26 | #include 27 | #include 28 | 29 | /* FreeRTOS includes. */ 30 | #include "FreeRTOS.h" 31 | #include "task.h" 32 | #include "semphr.h" 33 | 34 | /** 35 | * @brief Functions that implement FreeRTOS tasks. 36 | */ 37 | static void prvTask1( void * pvParams ); 38 | static void prvTask2( void * pvParams ); 39 | /*-----------------------------------------------------------*/ 40 | 41 | /** 42 | * @brief Mutex used in this program. 43 | */ 44 | static SemaphoreHandle_t xMutex = NULL; 45 | /*-----------------------------------------------------------*/ 46 | 47 | /** 48 | * @brief Tutorial entry point. 49 | */ 50 | int main( void ) 51 | { 52 | BaseType_t xTaskCreationResult = pdFAIL; 53 | 54 | xTaskCreationResult = xTaskCreate( prvTask1, 55 | "Task1", 56 | configMINIMAL_STACK_SIZE, 57 | NULL, 58 | tskIDLE_PRIORITY, 59 | NULL ); 60 | configASSERT( xTaskCreationResult == pdPASS ); 61 | 62 | xTaskCreationResult = xTaskCreate( prvTask2, 63 | "Task2", 64 | configMINIMAL_STACK_SIZE, 65 | NULL, 66 | tskIDLE_PRIORITY, 67 | NULL ); 68 | configASSERT( xTaskCreationResult == pdPASS ); 69 | 70 | /* 71 | * TODO 1 - Create a mutex using xSemaphoreCreateMutex API. 72 | * 73 | * Assign the return value to xMutex. 74 | */ 75 | 76 | configASSERT( xMutex != NULL ); 77 | 78 | /* Start the scheduler. */ 79 | vTaskStartScheduler(); 80 | 81 | /* Should not reach here. */ 82 | for( ;; ) 83 | { 84 | 85 | } 86 | 87 | /* Just to make the compiler happy. */ 88 | return 0; 89 | } 90 | /*-----------------------------------------------------------*/ 91 | 92 | static void prvTask1( void * pvParams ) 93 | { 94 | BaseType_t xSemaphoreGiveResult = pdFAIL; 95 | 96 | /* Silence warning about unused parameters. */ 97 | ( void ) pvParams; 98 | 99 | for( ;; ) 100 | { 101 | /* 102 | * TODO 2 - Take the mutex using xSemaphoreTake API. 103 | * 104 | * Use the following values for xSemaphoreTake parameters: 105 | * xSemaphore xMutex 106 | * xBlockTime portMAX_DELAY 107 | */ 108 | 109 | { 110 | fprintf( stderr, "Task 1 is running...\r\n" ); 111 | } 112 | /* 113 | * TODO 3 - Give the mutex using xSemaphoreGive API. 114 | * 115 | * Use the following values for xSemaphoreGive parameters: 116 | * xSemaphore xMutex 117 | * 118 | * Assign the return value to xSemaphoreGiveResult. 119 | */ 120 | 121 | configASSERT( xSemaphoreGiveResult == pdPASS ); 122 | 123 | vTaskDelay( pdMS_TO_TICKS( 1000 ) ); 124 | } 125 | 126 | } 127 | /*-----------------------------------------------------------*/ 128 | 129 | static void prvTask2( void * pvParams ) 130 | { 131 | BaseType_t xSemaphoreGiveResult = pdFAIL; 132 | 133 | /* Silence warning about unused parameters. */ 134 | ( void ) pvParams; 135 | 136 | for( ;; ) 137 | { 138 | /* 139 | * TODO 4 - Take the mutex using xSemaphoreTake API. 140 | * 141 | * Use the following values for xSemaphoreTake parameters: 142 | * xSemaphore xMutex 143 | * xBlockTime portMAX_DELAY 144 | */ 145 | 146 | { 147 | fprintf( stderr, "Task 2 is running...\r\n" ); 148 | } 149 | /* 150 | * TODO 5 - Give the mutex using xSemaphoreGive API. 151 | * 152 | * Use the following values for xSemaphoreGive parameters: 153 | * xSemaphore xMutex 154 | * 155 | * Assign the return value to xSemaphoreGiveResult. 156 | */ 157 | 158 | configASSERT( xSemaphoreGiveResult == pdPASS ); 159 | 160 | vTaskDelay( pdMS_TO_TICKS( 1000 ) ); 161 | } 162 | } 163 | /*-----------------------------------------------------------*/ 164 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_14/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_TIME_SLICING 1 30 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 31 | #define configUSE_IDLE_HOOK 0 32 | #define configUSE_TICK_HOOK 0 33 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 34 | #define configTICK_RATE_HZ ( 1000 ) 35 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 36 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 37 | #define configMAX_TASK_NAME_LEN ( 12 ) 38 | #define configUSE_TRACE_FACILITY 1 39 | #define configUSE_16_BIT_TICKS 0 40 | #define configIDLE_SHOULD_YIELD 1 41 | #define configUSE_MUTEXES 1 42 | #define configCHECK_FOR_STACK_OVERFLOW 0 43 | #define configUSE_RECURSIVE_MUTEXES 1 44 | #define configQUEUE_REGISTRY_SIZE 20 45 | #define configUSE_APPLICATION_TASK_TAG 1 46 | #define configUSE_COUNTING_SEMAPHORES 1 47 | #define configUSE_ALTERNATIVE_API 0 48 | #define configUSE_QUEUE_SETS 1 49 | #define configUSE_TASK_NOTIFICATIONS 1 50 | #define configSUPPORT_STATIC_ALLOCATION 1 51 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 52 | #define configRECORD_STACK_HIGH_ADDRESS 1 53 | #define configKERNEL_PROVIDED_STATIC_MEMORY 1 54 | 55 | /* Software timer related configuration options. The maximum possible task 56 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 57 | * deliberately set higher to ensure it is correctly capped back to 58 | * configMAX_PRIORITIES - 1. */ 59 | #define configUSE_TIMERS 1 60 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 61 | #define configTIMER_QUEUE_LENGTH 20 62 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 63 | 64 | #define configMAX_PRIORITIES ( 7 ) 65 | 66 | /* Co-routine related configuration options. */ 67 | #define configUSE_CO_ROUTINES 0 68 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 69 | 70 | /* Set the following definitions to 1 to include the API function, or zero 71 | * to exclude the API function. In most cases the linker will remove unused 72 | * functions anyway. */ 73 | #define INCLUDE_vTaskPrioritySet 1 74 | #define INCLUDE_uxTaskPriorityGet 1 75 | #define INCLUDE_vTaskDelete 1 76 | #define INCLUDE_vTaskCleanUpResources 0 77 | #define INCLUDE_vTaskSuspend 1 78 | #define INCLUDE_vTaskDelayUntil 1 79 | #define INCLUDE_vTaskDelay 1 80 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 81 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 82 | #define INCLUDE_xTaskGetSchedulerState 1 83 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 84 | #define INCLUDE_xTaskGetIdleTaskHandle 1 85 | #define INCLUDE_xTaskGetHandle 1 86 | #define INCLUDE_eTaskGetState 1 87 | #define INCLUDE_xSemaphoreGetMutexHolder 1 88 | #define INCLUDE_xTimerPendFunctionCall 1 89 | #define INCLUDE_xTaskAbortDelay 1 90 | 91 | /* It is a good idea to define configASSERT() while developing. configASSERT() 92 | * uses the same semantics as the standard C assert() macro. Don't define 93 | * configASSERT() when performing code coverage tests though, as it is not 94 | * intended to asserts() to fail, some code is intended not to run if no 95 | * errors are present. */ 96 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 97 | 98 | #endif /* FREERTOS_CONFIG_H */ 99 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_14/source/tutorial_14.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | /* Standard includes. */ 26 | #include 27 | #include 28 | 29 | /* FreeRTOS includes. */ 30 | #include "FreeRTOS.h" 31 | #include "task.h" 32 | #include "semphr.h" 33 | 34 | /** 35 | * @brief Functions that implement FreeRTOS tasks. 36 | */ 37 | static void prvHighPriorityTask( void * pvParams ); 38 | static void prvLowPriorityTask( void * pvParams ); 39 | /*-----------------------------------------------------------*/ 40 | 41 | /** 42 | * @brief Mutex used in this program. 43 | */ 44 | static SemaphoreHandle_t xMutex = NULL; 45 | /*-----------------------------------------------------------*/ 46 | 47 | /** 48 | * @brief Tutorial entry point. 49 | */ 50 | int main( void ) 51 | { 52 | BaseType_t xTaskCreationResult = pdFAIL; 53 | 54 | xTaskCreationResult = xTaskCreate( prvHighPriorityTask, 55 | "High", 56 | configMINIMAL_STACK_SIZE, 57 | NULL, 58 | tskIDLE_PRIORITY + 1, 59 | NULL ); 60 | configASSERT( xTaskCreationResult == pdPASS ); 61 | 62 | xTaskCreationResult = xTaskCreate( prvLowPriorityTask, 63 | "Low", 64 | configMINIMAL_STACK_SIZE, 65 | NULL, 66 | tskIDLE_PRIORITY, 67 | NULL ); 68 | configASSERT( xTaskCreationResult == pdPASS ); 69 | 70 | xMutex = xSemaphoreCreateMutex(); 71 | configASSERT( xMutex != NULL ); 72 | 73 | /* Start the scheduler. */ 74 | vTaskStartScheduler(); 75 | 76 | /* Should not reach here. */ 77 | for( ;; ) 78 | { 79 | 80 | } 81 | 82 | /* Just to make the compiler happy. */ 83 | return 0; 84 | } 85 | /*-----------------------------------------------------------*/ 86 | 87 | static void prvHighPriorityTask( void * pvParams ) 88 | { 89 | /* Silence warning about unused parameters. */ 90 | ( void ) pvParams; 91 | 92 | for( ;; ) 93 | { 94 | vTaskDelay( pdMS_TO_TICKS( 1000 ) ); 95 | 96 | xSemaphoreTake( xMutex, portMAX_DELAY ); 97 | } 98 | } 99 | /*-----------------------------------------------------------*/ 100 | 101 | static void prvLowPriorityTask( void * pvParams ) 102 | { 103 | /* Silence warning about unused parameters. */ 104 | ( void ) pvParams; 105 | 106 | xSemaphoreTake( xMutex, portMAX_DELAY ); 107 | 108 | for( ;; ) 109 | { 110 | fprintf( stderr, "Task priority is %lu\r\n", uxTaskPriorityGet( NULL ) ); 111 | 112 | vTaskDelay( pdMS_TO_TICKS( 1000 ) ); 113 | } 114 | } 115 | /*-----------------------------------------------------------*/ 116 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_15/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_TIME_SLICING 1 30 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 31 | #define configUSE_IDLE_HOOK 0 32 | #define configUSE_TICK_HOOK 0 33 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 34 | #define configTICK_RATE_HZ ( 1000 ) 35 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 36 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 37 | #define configMAX_TASK_NAME_LEN ( 12 ) 38 | #define configUSE_TRACE_FACILITY 1 39 | #define configUSE_16_BIT_TICKS 0 40 | #define configIDLE_SHOULD_YIELD 1 41 | #define configUSE_MUTEXES 1 42 | #define configCHECK_FOR_STACK_OVERFLOW 0 43 | #define configUSE_RECURSIVE_MUTEXES 1 44 | #define configQUEUE_REGISTRY_SIZE 20 45 | #define configUSE_APPLICATION_TASK_TAG 1 46 | #define configUSE_COUNTING_SEMAPHORES 1 47 | #define configUSE_ALTERNATIVE_API 0 48 | #define configUSE_QUEUE_SETS 1 49 | #define configUSE_TASK_NOTIFICATIONS 1 50 | #define configSUPPORT_STATIC_ALLOCATION 1 51 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 52 | #define configRECORD_STACK_HIGH_ADDRESS 1 53 | #define configKERNEL_PROVIDED_STATIC_MEMORY 1 54 | 55 | /* Software timer related configuration options. The maximum possible task 56 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 57 | * deliberately set higher to ensure it is correctly capped back to 58 | * configMAX_PRIORITIES - 1. */ 59 | #define configUSE_TIMERS 1 60 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 61 | #define configTIMER_QUEUE_LENGTH 20 62 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 63 | 64 | #define configMAX_PRIORITIES ( 7 ) 65 | 66 | /* Co-routine related configuration options. */ 67 | #define configUSE_CO_ROUTINES 0 68 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 69 | 70 | /* Set the following definitions to 1 to include the API function, or zero 71 | * to exclude the API function. In most cases the linker will remove unused 72 | * functions anyway. */ 73 | #define INCLUDE_vTaskPrioritySet 1 74 | #define INCLUDE_uxTaskPriorityGet 1 75 | #define INCLUDE_vTaskDelete 1 76 | #define INCLUDE_vTaskCleanUpResources 0 77 | #define INCLUDE_vTaskSuspend 1 78 | #define INCLUDE_vTaskDelayUntil 1 79 | #define INCLUDE_vTaskDelay 1 80 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 81 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 82 | #define INCLUDE_xTaskGetSchedulerState 1 83 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 84 | #define INCLUDE_xTaskGetIdleTaskHandle 1 85 | #define INCLUDE_xTaskGetHandle 1 86 | #define INCLUDE_eTaskGetState 1 87 | #define INCLUDE_xSemaphoreGetMutexHolder 1 88 | #define INCLUDE_xTimerPendFunctionCall 1 89 | #define INCLUDE_xTaskAbortDelay 1 90 | 91 | /* It is a good idea to define configASSERT() while developing. configASSERT() 92 | * uses the same semantics as the standard C assert() macro. Don't define 93 | * configASSERT() when performing code coverage tests though, as it is not 94 | * intended to asserts() to fail, some code is intended not to run if no 95 | * errors are present. */ 96 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 97 | 98 | #endif /* FREERTOS_CONFIG_H */ 99 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_16/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_TIME_SLICING 1 30 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 31 | #define configUSE_IDLE_HOOK 0 32 | #define configUSE_TICK_HOOK 0 33 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 34 | #define configTICK_RATE_HZ ( 1000 ) 35 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 36 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 37 | #define configMAX_TASK_NAME_LEN ( 12 ) 38 | #define configUSE_TRACE_FACILITY 1 39 | #define configUSE_16_BIT_TICKS 0 40 | #define configIDLE_SHOULD_YIELD 1 41 | #define configUSE_MUTEXES 1 42 | #define configCHECK_FOR_STACK_OVERFLOW 0 43 | #define configUSE_RECURSIVE_MUTEXES 1 44 | #define configQUEUE_REGISTRY_SIZE 20 45 | #define configUSE_APPLICATION_TASK_TAG 1 46 | #define configUSE_COUNTING_SEMAPHORES 1 47 | #define configUSE_ALTERNATIVE_API 0 48 | #define configUSE_QUEUE_SETS 1 49 | #define configUSE_TASK_NOTIFICATIONS 1 50 | #define configSUPPORT_STATIC_ALLOCATION 1 51 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 52 | #define configRECORD_STACK_HIGH_ADDRESS 1 53 | #define configKERNEL_PROVIDED_STATIC_MEMORY 1 54 | 55 | /* Software timer related configuration options. The maximum possible task 56 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 57 | * deliberately set higher to ensure it is correctly capped back to 58 | * configMAX_PRIORITIES - 1. */ 59 | #define configUSE_TIMERS 1 60 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 61 | #define configTIMER_QUEUE_LENGTH 20 62 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 63 | 64 | #define configMAX_PRIORITIES ( 7 ) 65 | 66 | /* Co-routine related configuration options. */ 67 | #define configUSE_CO_ROUTINES 0 68 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 69 | 70 | /* Set the following definitions to 1 to include the API function, or zero 71 | * to exclude the API function. In most cases the linker will remove unused 72 | * functions anyway. */ 73 | #define INCLUDE_vTaskPrioritySet 1 74 | #define INCLUDE_uxTaskPriorityGet 1 75 | #define INCLUDE_vTaskDelete 1 76 | #define INCLUDE_vTaskCleanUpResources 0 77 | #define INCLUDE_vTaskSuspend 1 78 | #define INCLUDE_vTaskDelayUntil 1 79 | #define INCLUDE_vTaskDelay 1 80 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 81 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 82 | #define INCLUDE_xTaskGetSchedulerState 1 83 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 84 | #define INCLUDE_xTaskGetIdleTaskHandle 1 85 | #define INCLUDE_xTaskGetHandle 1 86 | #define INCLUDE_eTaskGetState 1 87 | #define INCLUDE_xSemaphoreGetMutexHolder 1 88 | #define INCLUDE_xTimerPendFunctionCall 1 89 | #define INCLUDE_xTaskAbortDelay 1 90 | 91 | /* It is a good idea to define configASSERT() while developing. configASSERT() 92 | * uses the same semantics as the standard C assert() macro. Don't define 93 | * configASSERT() when performing code coverage tests though, as it is not 94 | * intended to asserts() to fail, some code is intended not to run if no 95 | * errors are present. */ 96 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 97 | 98 | #endif /* FREERTOS_CONFIG_H */ 99 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_17/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_TIME_SLICING 1 30 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 31 | #define configUSE_IDLE_HOOK 0 32 | #define configUSE_TICK_HOOK 0 33 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 34 | #define configTICK_RATE_HZ ( 1000 ) 35 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 36 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 37 | #define configMAX_TASK_NAME_LEN ( 12 ) 38 | #define configUSE_TRACE_FACILITY 1 39 | #define configUSE_16_BIT_TICKS 0 40 | #define configIDLE_SHOULD_YIELD 1 41 | #define configUSE_MUTEXES 1 42 | #define configCHECK_FOR_STACK_OVERFLOW 0 43 | #define configUSE_RECURSIVE_MUTEXES 1 44 | #define configQUEUE_REGISTRY_SIZE 20 45 | #define configUSE_APPLICATION_TASK_TAG 1 46 | #define configUSE_COUNTING_SEMAPHORES 1 47 | #define configUSE_ALTERNATIVE_API 0 48 | #define configUSE_QUEUE_SETS 1 49 | #define configUSE_TASK_NOTIFICATIONS 1 50 | #define configSUPPORT_STATIC_ALLOCATION 1 51 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 52 | #define configRECORD_STACK_HIGH_ADDRESS 1 53 | #define configKERNEL_PROVIDED_STATIC_MEMORY 1 54 | 55 | /* Software timer related configuration options. The maximum possible task 56 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 57 | * deliberately set higher to ensure it is correctly capped back to 58 | * configMAX_PRIORITIES - 1. */ 59 | #define configUSE_TIMERS 1 60 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 61 | #define configTIMER_QUEUE_LENGTH 20 62 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 63 | 64 | #define configMAX_PRIORITIES ( 7 ) 65 | 66 | /* Co-routine related configuration options. */ 67 | #define configUSE_CO_ROUTINES 0 68 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 69 | 70 | /* Set the following definitions to 1 to include the API function, or zero 71 | * to exclude the API function. In most cases the linker will remove unused 72 | * functions anyway. */ 73 | #define INCLUDE_vTaskPrioritySet 1 74 | #define INCLUDE_uxTaskPriorityGet 1 75 | #define INCLUDE_vTaskDelete 1 76 | #define INCLUDE_vTaskCleanUpResources 0 77 | #define INCLUDE_vTaskSuspend 1 78 | #define INCLUDE_vTaskDelayUntil 1 79 | #define INCLUDE_vTaskDelay 1 80 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 81 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 82 | #define INCLUDE_xTaskGetSchedulerState 1 83 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 84 | #define INCLUDE_xTaskGetIdleTaskHandle 1 85 | #define INCLUDE_xTaskGetHandle 1 86 | #define INCLUDE_eTaskGetState 1 87 | #define INCLUDE_xSemaphoreGetMutexHolder 1 88 | #define INCLUDE_xTimerPendFunctionCall 1 89 | #define INCLUDE_xTaskAbortDelay 1 90 | 91 | /* It is a good idea to define configASSERT() while developing. configASSERT() 92 | * uses the same semantics as the standard C assert() macro. Don't define 93 | * configASSERT() when performing code coverage tests though, as it is not 94 | * intended to asserts() to fail, some code is intended not to run if no 95 | * errors are present. */ 96 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 97 | 98 | #endif /* FREERTOS_CONFIG_H */ 99 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_17/source/tutorial_17.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | /* Standard includes. */ 26 | #include 27 | #include 28 | 29 | /* FreeRTOS includes. */ 30 | #include "FreeRTOS.h" 31 | #include "task.h" 32 | 33 | /** 34 | * @brief Functions that implement FreeRTOS tasks. 35 | */ 36 | static void prvTask1( void * pvParams ); 37 | static void prvTask2( void * pvParams ); 38 | /*-----------------------------------------------------------*/ 39 | 40 | /** 41 | * @brief Handle of task 1. 42 | */ 43 | static TaskHandle_t xTask1Handle = NULL; 44 | /*-----------------------------------------------------------*/ 45 | 46 | /** 47 | * @brief Tutorial entry point. 48 | */ 49 | int main( void ) 50 | { 51 | BaseType_t xTaskCreationResult = pdFAIL; 52 | 53 | xTaskCreationResult = xTaskCreate( prvTask1, 54 | "Task1", 55 | configMINIMAL_STACK_SIZE, 56 | NULL, 57 | tskIDLE_PRIORITY + 1, 58 | &( xTask1Handle ) ); 59 | configASSERT( xTaskCreationResult == pdPASS ); 60 | 61 | xTaskCreationResult = xTaskCreate( prvTask2, 62 | "Task2", 63 | configMINIMAL_STACK_SIZE, 64 | NULL, 65 | tskIDLE_PRIORITY, 66 | NULL ); 67 | configASSERT( xTaskCreationResult == pdPASS ); 68 | 69 | /* Start the scheduler. */ 70 | vTaskStartScheduler(); 71 | 72 | /* Should not reach here. */ 73 | for( ;; ) 74 | { 75 | 76 | } 77 | 78 | /* Just to make the compiler happy. */ 79 | return 0; 80 | } 81 | /*-----------------------------------------------------------*/ 82 | 83 | static void prvTask1( void * pvParams ) 84 | { 85 | /* Silence warning about unused parameters. */ 86 | ( void ) pvParams; 87 | 88 | for( ;; ) 89 | { 90 | fprintf( stderr, "Task 1: Waiting for notification...\r\n" ); 91 | 92 | /* 93 | * TODO 1 - Wait for a task notification using ulTaskNotifyTake API. 94 | * 95 | * Use the following values for ulTaskNotifyTake parameters: 96 | * xClearCountOnExit pdTRUE 97 | * xTicksToWait portMAX_DELAY 98 | */ 99 | 100 | 101 | fprintf( stderr, "Task 1: Received notification...\r\n" ); 102 | } 103 | } 104 | /*-----------------------------------------------------------*/ 105 | 106 | static void prvTask2( void * pvParams ) 107 | { 108 | /* Silence warning about unused parameters. */ 109 | ( void ) pvParams; 110 | 111 | for( ;; ) 112 | { 113 | fprintf( stderr, "Task 2: Notifying task 1...\r\n" ); 114 | 115 | /* 116 | * TODO 2 - Notify task 1 using xTaskNotifyGive API. 117 | * 118 | * Use the following values for xTaskNotifyGive parameters: 119 | * xTaskToNotify xTask1Handle 120 | */ 121 | 122 | 123 | fprintf( stderr, "Task 2: Notified task 1...\r\n" ); 124 | 125 | vTaskDelay( pdMS_TO_TICKS( 1000 ) ); 126 | } 127 | } 128 | /*-----------------------------------------------------------*/ 129 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_18/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_TIME_SLICING 1 30 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 31 | #define configUSE_IDLE_HOOK 0 32 | #define configUSE_TICK_HOOK 0 33 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 34 | #define configTICK_RATE_HZ ( 1000 ) 35 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 36 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 37 | #define configMAX_TASK_NAME_LEN ( 12 ) 38 | #define configUSE_TRACE_FACILITY 1 39 | #define configUSE_16_BIT_TICKS 0 40 | #define configIDLE_SHOULD_YIELD 1 41 | #define configUSE_MUTEXES 1 42 | #define configCHECK_FOR_STACK_OVERFLOW 0 43 | #define configUSE_RECURSIVE_MUTEXES 1 44 | #define configQUEUE_REGISTRY_SIZE 20 45 | #define configUSE_APPLICATION_TASK_TAG 1 46 | #define configUSE_COUNTING_SEMAPHORES 1 47 | #define configUSE_ALTERNATIVE_API 0 48 | #define configUSE_QUEUE_SETS 1 49 | #define configUSE_TASK_NOTIFICATIONS 1 50 | #define configSUPPORT_STATIC_ALLOCATION 1 51 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 52 | #define configRECORD_STACK_HIGH_ADDRESS 1 53 | #define configKERNEL_PROVIDED_STATIC_MEMORY 1 54 | 55 | /* Software timer related configuration options. The maximum possible task 56 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 57 | * deliberately set higher to ensure it is correctly capped back to 58 | * configMAX_PRIORITIES - 1. */ 59 | #define configUSE_TIMERS 1 60 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 61 | #define configTIMER_QUEUE_LENGTH 20 62 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 63 | 64 | #define configMAX_PRIORITIES ( 7 ) 65 | 66 | /* Co-routine related configuration options. */ 67 | #define configUSE_CO_ROUTINES 0 68 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 69 | 70 | /* Set the following definitions to 1 to include the API function, or zero 71 | * to exclude the API function. In most cases the linker will remove unused 72 | * functions anyway. */ 73 | #define INCLUDE_vTaskPrioritySet 1 74 | #define INCLUDE_uxTaskPriorityGet 1 75 | #define INCLUDE_vTaskDelete 1 76 | #define INCLUDE_vTaskCleanUpResources 0 77 | #define INCLUDE_vTaskSuspend 1 78 | #define INCLUDE_vTaskDelayUntil 1 79 | #define INCLUDE_vTaskDelay 1 80 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 81 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 82 | #define INCLUDE_xTaskGetSchedulerState 1 83 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 84 | #define INCLUDE_xTaskGetIdleTaskHandle 1 85 | #define INCLUDE_xTaskGetHandle 1 86 | #define INCLUDE_eTaskGetState 1 87 | #define INCLUDE_xSemaphoreGetMutexHolder 1 88 | #define INCLUDE_xTimerPendFunctionCall 1 89 | #define INCLUDE_xTaskAbortDelay 1 90 | 91 | /* It is a good idea to define configASSERT() while developing. configASSERT() 92 | * uses the same semantics as the standard C assert() macro. Don't define 93 | * configASSERT() when performing code coverage tests though, as it is not 94 | * intended to asserts() to fail, some code is intended not to run if no 95 | * errors are present. */ 96 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 97 | 98 | #endif /* FREERTOS_CONFIG_H */ 99 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_18/source/tutorial_18.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | /* Standard includes. */ 26 | #include 27 | #include 28 | 29 | /* FreeRTOS includes. */ 30 | #include "FreeRTOS.h" 31 | #include "task.h" 32 | 33 | /** 34 | * @brief Definitions of event bits. 35 | */ 36 | #define EVENT_1_BIT ( 1UL << 0UL ) 37 | #define EVENT_2_BIT ( 1UL << 1UL ) 38 | /*-----------------------------------------------------------*/ 39 | 40 | /** 41 | * @brief Functions that implement FreeRTOS tasks. 42 | */ 43 | static void prvEventGeneratorTask( void * pvParams ); 44 | static void prvEventHandlerTask( void * pvParams ); 45 | /*-----------------------------------------------------------*/ 46 | 47 | /** 48 | * @brief Handle of the event handler task. 49 | */ 50 | static TaskHandle_t xEventHandlerTaskHandle = NULL; 51 | /*-----------------------------------------------------------*/ 52 | 53 | /** 54 | * @brief Tutorial entry point. 55 | */ 56 | int main( void ) 57 | { 58 | BaseType_t xTaskCreationResult = pdFAIL; 59 | 60 | xTaskCreationResult = xTaskCreate( prvEventGeneratorTask, 61 | "Generator", 62 | configMINIMAL_STACK_SIZE, 63 | NULL, 64 | tskIDLE_PRIORITY, 65 | NULL ); 66 | configASSERT( xTaskCreationResult == pdPASS ); 67 | 68 | xTaskCreationResult = xTaskCreate( prvEventHandlerTask, 69 | "Handler", 70 | configMINIMAL_STACK_SIZE, 71 | NULL, 72 | tskIDLE_PRIORITY + 1, 73 | &( xEventHandlerTaskHandle ) ); 74 | configASSERT( xTaskCreationResult == pdPASS ); 75 | 76 | /* Start the scheduler. */ 77 | vTaskStartScheduler(); 78 | 79 | /* Should not reach here. */ 80 | for( ;; ) 81 | { 82 | 83 | } 84 | 85 | /* Just to make the compiler happy. */ 86 | return 0; 87 | } 88 | /*-----------------------------------------------------------*/ 89 | 90 | static void prvEventGeneratorTask( void * pvParams ) 91 | { 92 | /* Silence warning about unused parameters. */ 93 | ( void ) pvParams; 94 | 95 | for( ;; ) 96 | { 97 | fprintf( stderr, "Generating event 1...\r\n" ); 98 | 99 | /* 100 | * TODO 1 - Notify the event handler task about event 1 using 101 | * xTaskNotify API. 102 | * 103 | * Use the following values for xTaskNotify parameters: 104 | * xTaskToNotify xEventHandlerTaskHandle 105 | * ulValue EVENT_1_BIT 106 | * eAction eSetBits 107 | */ 108 | 109 | 110 | vTaskDelay( pdMS_TO_TICKS( 500 ) ); 111 | 112 | fprintf( stderr, "Generating event 2...\r\n" ); 113 | 114 | /* 115 | * TODO 2 - Notify the event handler task about event 2 using 116 | * xTaskNotify API. 117 | * 118 | * Use the following values for xTaskNotify parameters: 119 | * xTaskToNotify xEventHandlerTaskHandle 120 | * ulValue EVENT_2_BIT 121 | * eAction eSetBits 122 | */ 123 | 124 | 125 | vTaskDelay( pdMS_TO_TICKS( 500 ) ); 126 | 127 | fprintf( stderr, "Generated both events...\r\n" ); 128 | } 129 | } 130 | /*-----------------------------------------------------------*/ 131 | 132 | static void prvEventHandlerTask( void * pvParams ) 133 | { 134 | uint32_t ulNotifiedValue; 135 | 136 | /* Silence warning about unused parameters. */ 137 | ( void ) pvParams; 138 | 139 | for( ;; ) 140 | { 141 | /* 142 | * TODO 3 - Wait for a task notification using xTaskNotifyWait API. 143 | * 144 | * Use the following values for xTaskNotifyWait parameters: 145 | * ulBitsToClearOnEntry 0 146 | * ulBitsToClearOnExit ~0 147 | * pulNotificationValue &( ulNotifiedValue ) 148 | * xTicksToWait portMAX_DELAY 149 | */ 150 | 151 | 152 | if( ( ulNotifiedValue & EVENT_1_BIT ) != 0 ) 153 | { 154 | fprintf( stderr, "Handling event 1...\r\n" ); 155 | } 156 | 157 | if( ( ulNotifiedValue & EVENT_2_BIT ) != 0 ) 158 | { 159 | fprintf( stderr, "Handling event 2...\r\n" ); 160 | } 161 | } 162 | } 163 | /*-----------------------------------------------------------*/ 164 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_19/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_TIME_SLICING 1 30 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 31 | #define configUSE_IDLE_HOOK 0 32 | #define configUSE_TICK_HOOK 0 33 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 34 | #define configTICK_RATE_HZ ( 1000 ) 35 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 36 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 37 | #define configMAX_TASK_NAME_LEN ( 12 ) 38 | #define configUSE_TRACE_FACILITY 1 39 | #define configUSE_16_BIT_TICKS 0 40 | #define configIDLE_SHOULD_YIELD 1 41 | #define configUSE_MUTEXES 1 42 | #define configCHECK_FOR_STACK_OVERFLOW 0 43 | #define configUSE_RECURSIVE_MUTEXES 1 44 | #define configQUEUE_REGISTRY_SIZE 20 45 | #define configUSE_APPLICATION_TASK_TAG 1 46 | #define configUSE_COUNTING_SEMAPHORES 1 47 | #define configUSE_ALTERNATIVE_API 0 48 | #define configUSE_QUEUE_SETS 1 49 | #define configUSE_TASK_NOTIFICATIONS 1 50 | #define configSUPPORT_STATIC_ALLOCATION 1 51 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 52 | #define configRECORD_STACK_HIGH_ADDRESS 1 53 | #define configKERNEL_PROVIDED_STATIC_MEMORY 1 54 | 55 | /* Software timer related configuration options. The maximum possible task 56 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 57 | * deliberately set higher to ensure it is correctly capped back to 58 | * configMAX_PRIORITIES - 1. */ 59 | #define configUSE_TIMERS 1 60 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 61 | #define configTIMER_QUEUE_LENGTH 20 62 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 63 | 64 | #define configMAX_PRIORITIES ( 7 ) 65 | 66 | /* Co-routine related configuration options. */ 67 | #define configUSE_CO_ROUTINES 0 68 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 69 | 70 | /* Set the following definitions to 1 to include the API function, or zero 71 | * to exclude the API function. In most cases the linker will remove unused 72 | * functions anyway. */ 73 | #define INCLUDE_vTaskPrioritySet 1 74 | #define INCLUDE_uxTaskPriorityGet 1 75 | #define INCLUDE_vTaskDelete 1 76 | #define INCLUDE_vTaskCleanUpResources 0 77 | #define INCLUDE_vTaskSuspend 1 78 | #define INCLUDE_vTaskDelayUntil 1 79 | #define INCLUDE_vTaskDelay 1 80 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 81 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 82 | #define INCLUDE_xTaskGetSchedulerState 1 83 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 84 | #define INCLUDE_xTaskGetIdleTaskHandle 1 85 | #define INCLUDE_xTaskGetHandle 1 86 | #define INCLUDE_eTaskGetState 1 87 | #define INCLUDE_xSemaphoreGetMutexHolder 1 88 | #define INCLUDE_xTimerPendFunctionCall 1 89 | #define INCLUDE_xTaskAbortDelay 1 90 | 91 | /* It is a good idea to define configASSERT() while developing. configASSERT() 92 | * uses the same semantics as the standard C assert() macro. Don't define 93 | * configASSERT() when performing code coverage tests though, as it is not 94 | * intended to asserts() to fail, some code is intended not to run if no 95 | * errors are present. */ 96 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 97 | 98 | #endif /* FREERTOS_CONFIG_H */ 99 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_19/source/tutorial_19.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | /* Standard includes. */ 26 | #include 27 | #include 28 | 29 | /* FreeRTOS includes. */ 30 | #include "FreeRTOS.h" 31 | #include "task.h" 32 | #include "stream_buffer.h" 33 | 34 | /** 35 | * @brief Functions that implement FreeRTOS tasks. 36 | */ 37 | static void prvReaderTask( void * pvParams ); 38 | static void prvWriterTask( void * pvParams ); 39 | /*-----------------------------------------------------------*/ 40 | 41 | /** 42 | * @brief Stream buffer used in this program. 43 | */ 44 | static StreamBufferHandle_t xStreamBuffer = NULL; 45 | /*-----------------------------------------------------------*/ 46 | 47 | /** 48 | * @brief Tutorial entry point. 49 | */ 50 | int main( void ) 51 | { 52 | BaseType_t xTaskCreationResult = pdFAIL; 53 | 54 | xTaskCreationResult = xTaskCreate( prvReaderTask, 55 | "Reader", 56 | configMINIMAL_STACK_SIZE, 57 | NULL, 58 | tskIDLE_PRIORITY + 1, 59 | NULL ); 60 | configASSERT( xTaskCreationResult == pdPASS ); 61 | 62 | xTaskCreationResult = xTaskCreate( prvWriterTask, 63 | "Writer", 64 | configMINIMAL_STACK_SIZE, 65 | NULL, 66 | tskIDLE_PRIORITY, 67 | NULL ); 68 | configASSERT( xTaskCreationResult == pdPASS ); 69 | 70 | /* 71 | * TODO 1 - Create a stream buffer of size 10 using xStreamBufferCreate API. 72 | * 73 | * Use the following values for xStreamBufferCreate parameters: 74 | * xBufferSizeBytes 10 75 | * xTriggerLevelBytes 5 76 | * 77 | * Assign the return value to xStreamBuffer. 78 | */ 79 | 80 | configASSERT( xStreamBuffer != NULL ); 81 | 82 | /* Start the scheduler. */ 83 | vTaskStartScheduler(); 84 | 85 | /* Should not reach here. */ 86 | for( ;; ) 87 | { 88 | 89 | } 90 | 91 | /* Just to make the compiler happy. */ 92 | return 0; 93 | } 94 | /*-----------------------------------------------------------*/ 95 | 96 | static void prvReaderTask( void * pvParams ) 97 | { 98 | uint8_t ucRxData[ 5 ]; 99 | size_t i, uxReceivedBytes; 100 | 101 | /* Silence warning about unused parameters. */ 102 | ( void ) pvParams; 103 | 104 | for( ;; ) 105 | { 106 | /* 107 | * TODO 2 - Read data from the steam buffer using xStreamBufferReceive 108 | * API. 109 | * 110 | * Use the following values for xStreamBufferReceive parameters: 111 | * xStreamBuffer xStreamBuffer 112 | * pvRxData &( ucRxData[ 0 ] ) 113 | * xBufferLengthBytes 5 114 | * xTicksToWait portMAX_DELAY 115 | * 116 | * Assign the return value to uxReceivedBytes. 117 | */ 118 | 119 | 120 | fprintf( stderr, "Received %lu byte(s)...\r\n", uxReceivedBytes ); 121 | 122 | for( i = 0; i < uxReceivedBytes; i++ ) 123 | { 124 | fprintf( stderr, "0x%0X ", ucRxData[ i ] ); 125 | } 126 | 127 | fprintf( stderr, "\r\n" ); 128 | } 129 | } 130 | /*-----------------------------------------------------------*/ 131 | 132 | static void prvWriterTask( void * pvParams ) 133 | { 134 | uint8_t ucTxData[ 6 ] = { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6 }; 135 | size_t uxSentBytes; 136 | 137 | /* Silence warning about unused parameters. */ 138 | ( void ) pvParams; 139 | 140 | for( ;; ) 141 | { 142 | fprintf( stderr, "Sending 1 byte...\r\n" ); 143 | 144 | /* 145 | * TODO 3 - Send 1 byte to the stream buffer using xStreamBufferSend 146 | * API. 147 | * 148 | * Use the following values for xStreamBufferSend parameters: 149 | * xStreamBuffer xStreamBuffer 150 | * pvTxData &( ucTxData[ 0 ] ) 151 | * xDataLengthBytes 1 152 | * xTicksToWait portMAX_DELAY 153 | * 154 | * Assign the return value to uxSentBytes. 155 | */ 156 | 157 | configASSERT( uxSentBytes == 1 ); 158 | 159 | fprintf( stderr, "Sending 5 bytes...\r\n" ); 160 | 161 | /* 162 | * TODO 4 - Send 5 bytes to the stream buffer using xStreamBufferSend 163 | * API. 164 | * 165 | * Use the following values for xStreamBufferSend parameters: 166 | * xStreamBuffer xStreamBuffer 167 | * pvTxData &( ucTxData[ 1 ] ) 168 | * xDataLengthBytes 5 169 | * xTicksToWait portMAX_DELAY 170 | * 171 | * Assign the return value to uxSentBytes. 172 | */ 173 | 174 | configASSERT( uxSentBytes == 5 ); 175 | 176 | fprintf( stderr, "Finished sending data.\r\n" ); 177 | 178 | vTaskDelay( pdMS_TO_TICKS( 1000 ) ); 179 | } 180 | } 181 | /*-----------------------------------------------------------*/ 182 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_2/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 30 | #define configUSE_IDLE_HOOK 0 31 | #define configUSE_TICK_HOOK 0 32 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 33 | #define configTICK_RATE_HZ ( 1000 ) 34 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 35 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 36 | #define configMAX_TASK_NAME_LEN ( 12 ) 37 | #define configUSE_TRACE_FACILITY 1 38 | #define configUSE_16_BIT_TICKS 0 39 | #define configIDLE_SHOULD_YIELD 1 40 | #define configUSE_MUTEXES 1 41 | #define configCHECK_FOR_STACK_OVERFLOW 0 42 | #define configUSE_RECURSIVE_MUTEXES 1 43 | #define configQUEUE_REGISTRY_SIZE 20 44 | #define configUSE_APPLICATION_TASK_TAG 1 45 | #define configUSE_COUNTING_SEMAPHORES 1 46 | #define configUSE_ALTERNATIVE_API 0 47 | #define configUSE_QUEUE_SETS 1 48 | #define configUSE_TASK_NOTIFICATIONS 1 49 | #define configSUPPORT_STATIC_ALLOCATION 0 50 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 51 | #define configRECORD_STACK_HIGH_ADDRESS 1 52 | 53 | /* Software timer related configuration options. The maximum possible task 54 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 55 | * deliberately set higher to ensure it is correctly capped back to 56 | * configMAX_PRIORITIES - 1. */ 57 | #define configUSE_TIMERS 1 58 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 59 | #define configTIMER_QUEUE_LENGTH 20 60 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 61 | 62 | #define configMAX_PRIORITIES ( 7 ) 63 | 64 | /* Co-routine related configuration options. */ 65 | #define configUSE_CO_ROUTINES 0 66 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 67 | 68 | /* Set the following definitions to 1 to include the API function, or zero 69 | * to exclude the API function. In most cases the linker will remove unused 70 | * functions anyway. */ 71 | #define INCLUDE_vTaskPrioritySet 1 72 | #define INCLUDE_uxTaskPriorityGet 1 73 | #define INCLUDE_vTaskDelete 1 74 | #define INCLUDE_vTaskCleanUpResources 0 75 | #define INCLUDE_vTaskSuspend 1 76 | #define INCLUDE_vTaskDelayUntil 1 77 | #define INCLUDE_vTaskDelay 1 78 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 79 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 80 | #define INCLUDE_xTaskGetSchedulerState 1 81 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 82 | #define INCLUDE_xTaskGetIdleTaskHandle 1 83 | #define INCLUDE_xTaskGetHandle 1 84 | #define INCLUDE_eTaskGetState 1 85 | #define INCLUDE_xSemaphoreGetMutexHolder 1 86 | #define INCLUDE_xTimerPendFunctionCall 1 87 | #define INCLUDE_xTaskAbortDelay 1 88 | 89 | /* It is a good idea to define configASSERT() while developing. configASSERT() 90 | * uses the same semantics as the standard C assert() macro. Don't define 91 | * configASSERT() when performing code coverage tests though, as it is not 92 | * intended to asserts() to fail, some code is intended not to run if no 93 | * errors are present. */ 94 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 95 | 96 | #endif /* FREERTOS_CONFIG_H */ 97 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_2/source/tutorial_2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | /* Standard includes. */ 26 | #include 27 | #include 28 | 29 | /* FreeRTOS includes. */ 30 | #include "FreeRTOS.h" 31 | #include "task.h" 32 | 33 | /** 34 | * @brief Function that implement FreeRTOS task. 35 | */ 36 | static void prvTaskFunction( void * pvParams ); 37 | /*-----------------------------------------------------------*/ 38 | 39 | /** 40 | * @brief Tutorial entry point. 41 | */ 42 | int main( void ) 43 | { 44 | BaseType_t xTaskCreationResult = pdFAIL; 45 | 46 | /* TODO 1 - Create a FreeRTOS task using xTaskCreate API which 47 | * uses prvTaskFunction as the task function. 48 | * 49 | * Use the following values for xTaskCreate parameters: 50 | * pxTaskCode prvTaskFunction 51 | * pcName "Task" 52 | * usStackDepth configMINIMAL_STACK_SIZE 53 | * pvParameters NULL 54 | * uxPriority tskIDLE_PRIORITY 55 | * pxCreatedTask NULL 56 | * 57 | * Assign the return value to xTaskCreationResult. 58 | */ 59 | 60 | configASSERT( xTaskCreationResult == pdPASS ); 61 | 62 | /* TODO 2 - Call vTaskStartScheduler to start the scheduler. */ 63 | 64 | /* Should not reach here. */ 65 | for( ;; ) 66 | { 67 | 68 | } 69 | 70 | /* Just to make the compiler happy. */ 71 | return 0; 72 | } 73 | /*-----------------------------------------------------------*/ 74 | 75 | static void prvTaskFunction( void * pvParams ) 76 | { 77 | /* Silence warning about unused parameters. */ 78 | ( void ) pvParams; 79 | 80 | for( ;; ) 81 | { 82 | fprintf( stderr, "Tutorial 2 running...\r\n" ); 83 | 84 | /* Pause for a second. */ 85 | vTaskDelay( pdMS_TO_TICKS( 1000 ) ); 86 | } 87 | } 88 | /*-----------------------------------------------------------*/ 89 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_20/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_TIME_SLICING 1 30 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 31 | #define configUSE_IDLE_HOOK 0 32 | #define configUSE_TICK_HOOK 0 33 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 34 | #define configTICK_RATE_HZ ( 1000 ) 35 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 36 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 37 | #define configMAX_TASK_NAME_LEN ( 12 ) 38 | #define configUSE_TRACE_FACILITY 1 39 | #define configUSE_16_BIT_TICKS 0 40 | #define configIDLE_SHOULD_YIELD 1 41 | #define configUSE_MUTEXES 1 42 | #define configCHECK_FOR_STACK_OVERFLOW 0 43 | #define configUSE_RECURSIVE_MUTEXES 1 44 | #define configQUEUE_REGISTRY_SIZE 20 45 | #define configUSE_APPLICATION_TASK_TAG 1 46 | #define configUSE_COUNTING_SEMAPHORES 1 47 | #define configUSE_ALTERNATIVE_API 0 48 | #define configUSE_QUEUE_SETS 1 49 | #define configUSE_TASK_NOTIFICATIONS 1 50 | #define configSUPPORT_STATIC_ALLOCATION 1 51 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 52 | #define configRECORD_STACK_HIGH_ADDRESS 1 53 | #define configKERNEL_PROVIDED_STATIC_MEMORY 1 54 | 55 | /* Software timer related configuration options. The maximum possible task 56 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 57 | * deliberately set higher to ensure it is correctly capped back to 58 | * configMAX_PRIORITIES - 1. */ 59 | #define configUSE_TIMERS 1 60 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 61 | #define configTIMER_QUEUE_LENGTH 20 62 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 63 | 64 | #define configMAX_PRIORITIES ( 7 ) 65 | 66 | /* Co-routine related configuration options. */ 67 | #define configUSE_CO_ROUTINES 0 68 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 69 | 70 | /* Set the following definitions to 1 to include the API function, or zero 71 | * to exclude the API function. In most cases the linker will remove unused 72 | * functions anyway. */ 73 | #define INCLUDE_vTaskPrioritySet 1 74 | #define INCLUDE_uxTaskPriorityGet 1 75 | #define INCLUDE_vTaskDelete 1 76 | #define INCLUDE_vTaskCleanUpResources 0 77 | #define INCLUDE_vTaskSuspend 1 78 | #define INCLUDE_vTaskDelayUntil 1 79 | #define INCLUDE_vTaskDelay 1 80 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 81 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 82 | #define INCLUDE_xTaskGetSchedulerState 1 83 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 84 | #define INCLUDE_xTaskGetIdleTaskHandle 1 85 | #define INCLUDE_xTaskGetHandle 1 86 | #define INCLUDE_eTaskGetState 1 87 | #define INCLUDE_xSemaphoreGetMutexHolder 1 88 | #define INCLUDE_xTimerPendFunctionCall 1 89 | #define INCLUDE_xTaskAbortDelay 1 90 | 91 | /* It is a good idea to define configASSERT() while developing. configASSERT() 92 | * uses the same semantics as the standard C assert() macro. Don't define 93 | * configASSERT() when performing code coverage tests though, as it is not 94 | * intended to asserts() to fail, some code is intended not to run if no 95 | * errors are present. */ 96 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 97 | 98 | #endif /* FREERTOS_CONFIG_H */ 99 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_21/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_TIME_SLICING 1 30 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 31 | #define configUSE_IDLE_HOOK 0 32 | #define configUSE_TICK_HOOK 1 33 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 34 | #define configTICK_RATE_HZ ( 1000 ) 35 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 36 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 37 | #define configMAX_TASK_NAME_LEN ( 12 ) 38 | #define configUSE_TRACE_FACILITY 1 39 | #define configUSE_16_BIT_TICKS 0 40 | #define configIDLE_SHOULD_YIELD 1 41 | #define configUSE_MUTEXES 1 42 | #define configCHECK_FOR_STACK_OVERFLOW 0 43 | #define configUSE_RECURSIVE_MUTEXES 1 44 | #define configQUEUE_REGISTRY_SIZE 20 45 | #define configUSE_APPLICATION_TASK_TAG 1 46 | #define configUSE_COUNTING_SEMAPHORES 1 47 | #define configUSE_ALTERNATIVE_API 0 48 | #define configUSE_QUEUE_SETS 1 49 | #define configUSE_TASK_NOTIFICATIONS 1 50 | #define configSUPPORT_STATIC_ALLOCATION 1 51 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 52 | #define configRECORD_STACK_HIGH_ADDRESS 1 53 | #define configKERNEL_PROVIDED_STATIC_MEMORY 1 54 | 55 | /* Software timer related configuration options. The maximum possible task 56 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 57 | * deliberately set higher to ensure it is correctly capped back to 58 | * configMAX_PRIORITIES - 1. */ 59 | #define configUSE_TIMERS 1 60 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 61 | #define configTIMER_QUEUE_LENGTH 20 62 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 63 | 64 | #define configMAX_PRIORITIES ( 7 ) 65 | 66 | /* Co-routine related configuration options. */ 67 | #define configUSE_CO_ROUTINES 0 68 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 69 | 70 | /* Set the following definitions to 1 to include the API function, or zero 71 | * to exclude the API function. In most cases the linker will remove unused 72 | * functions anyway. */ 73 | #define INCLUDE_vTaskPrioritySet 1 74 | #define INCLUDE_uxTaskPriorityGet 1 75 | #define INCLUDE_vTaskDelete 1 76 | #define INCLUDE_vTaskCleanUpResources 0 77 | #define INCLUDE_vTaskSuspend 1 78 | #define INCLUDE_vTaskDelayUntil 1 79 | #define INCLUDE_vTaskDelay 1 80 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 81 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 82 | #define INCLUDE_xTaskGetSchedulerState 1 83 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 84 | #define INCLUDE_xTaskGetIdleTaskHandle 1 85 | #define INCLUDE_xTaskGetHandle 1 86 | #define INCLUDE_eTaskGetState 1 87 | #define INCLUDE_xSemaphoreGetMutexHolder 1 88 | #define INCLUDE_xTimerPendFunctionCall 1 89 | #define INCLUDE_xTaskAbortDelay 1 90 | 91 | /* It is a good idea to define configASSERT() while developing. configASSERT() 92 | * uses the same semantics as the standard C assert() macro. Don't define 93 | * configASSERT() when performing code coverage tests though, as it is not 94 | * intended to asserts() to fail, some code is intended not to run if no 95 | * errors are present. */ 96 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 97 | 98 | #endif /* FREERTOS_CONFIG_H */ 99 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_21/source/tutorial_21.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | /* Standard includes. */ 26 | #include 27 | #include 28 | 29 | /* FreeRTOS includes. */ 30 | #include "FreeRTOS.h" 31 | #include "task.h" 32 | #include "semphr.h" 33 | 34 | /** 35 | * @brief Functions that implement FreeRTOS tasks. 36 | */ 37 | static void prvTask1( void * pvParams ); 38 | static void prvTask2( void * pvParams ); 39 | /*-----------------------------------------------------------*/ 40 | 41 | /** 42 | * @brief Mutex used in this program. 43 | */ 44 | static SemaphoreHandle_t xMutex = NULL; 45 | 46 | /** 47 | * @brief Shared counters used in this program. 48 | */ 49 | static uint32_t ulSharedCounter1BetweenTasks = 0; 50 | static uint32_t ulSharedCounter2BetweenTasks = 0; 51 | static uint32_t ulSharedCounterBetweenTasksAndInterrupts = 0; 52 | /*-----------------------------------------------------------*/ 53 | 54 | /** 55 | * @brief Tutorial entry point. 56 | */ 57 | int main( void ) 58 | { 59 | BaseType_t xTaskCreationResult = pdFAIL; 60 | 61 | xTaskCreationResult = xTaskCreate( prvTask1, 62 | "Task1", 63 | configMINIMAL_STACK_SIZE, 64 | NULL, 65 | tskIDLE_PRIORITY, 66 | NULL ); 67 | configASSERT( xTaskCreationResult == pdPASS ); 68 | 69 | xTaskCreationResult = xTaskCreate( prvTask2, 70 | "Task2", 71 | configMINIMAL_STACK_SIZE, 72 | NULL, 73 | tskIDLE_PRIORITY, 74 | NULL ); 75 | configASSERT( xTaskCreationResult == pdPASS ); 76 | 77 | xMutex = xSemaphoreCreateMutex(); 78 | configASSERT( xMutex != NULL ); 79 | 80 | /* Start the scheduler. */ 81 | vTaskStartScheduler(); 82 | 83 | /* Should not reach here. */ 84 | for( ;; ) 85 | { 86 | 87 | } 88 | 89 | /* Just to make the compiler happy. */ 90 | return 0; 91 | } 92 | /*-----------------------------------------------------------*/ 93 | 94 | static void prvTask1( void * pvParams ) 95 | { 96 | uint32_t ulLocalCounter1, ulLocalCounter2, ulLocalCounter3; 97 | 98 | /* Silence warning about unused parameters. */ 99 | ( void ) pvParams; 100 | 101 | for( ;; ) 102 | { 103 | vTaskSuspendAll(); 104 | { 105 | ulSharedCounter1BetweenTasks++; 106 | ulLocalCounter1 = ulSharedCounter1BetweenTasks; 107 | } 108 | xTaskResumeAll(); 109 | 110 | xSemaphoreTake( xMutex, portMAX_DELAY ); 111 | { 112 | ulSharedCounter2BetweenTasks++; 113 | ulLocalCounter2 = ulSharedCounter2BetweenTasks; 114 | 115 | } 116 | xSemaphoreGive( xMutex ); 117 | 118 | taskENTER_CRITICAL(); 119 | { 120 | ulSharedCounterBetweenTasksAndInterrupts++; 121 | ulLocalCounter3 = ulSharedCounterBetweenTasksAndInterrupts; 122 | } 123 | taskEXIT_CRITICAL(); 124 | 125 | fprintf( stderr, "Task 1 ulSharedCounter1BetweenTasks: %u.\r\n", ulLocalCounter1 ); 126 | fprintf( stderr, "Task 1 ulSharedCounter2BetweenTasks: %u.\r\n", ulLocalCounter2 ); 127 | fprintf( stderr, "Task 1 ulSharedCounterBetweenTasksAndInterrupts: %u.\r\n", ulLocalCounter3 ); 128 | 129 | vTaskDelay( pdMS_TO_TICKS( 1000 ) ); 130 | } 131 | } 132 | /*-----------------------------------------------------------*/ 133 | 134 | static void prvTask2( void * pvParams ) 135 | { 136 | uint32_t ulLocalCounter1, ulLocalCounter2, ulLocalCounter3; 137 | 138 | /* Silence warning about unused parameters. */ 139 | ( void ) pvParams; 140 | 141 | for( ;; ) 142 | { 143 | vTaskSuspendAll(); 144 | { 145 | ulSharedCounter1BetweenTasks++; 146 | ulLocalCounter1 = ulSharedCounter1BetweenTasks; 147 | } 148 | xTaskResumeAll(); 149 | 150 | xSemaphoreTake( xMutex, portMAX_DELAY ); 151 | { 152 | ulSharedCounter2BetweenTasks++; 153 | ulLocalCounter2 = ulSharedCounter2BetweenTasks; 154 | 155 | } 156 | xSemaphoreGive( xMutex ); 157 | 158 | taskENTER_CRITICAL(); 159 | { 160 | ulSharedCounterBetweenTasksAndInterrupts++; 161 | ulLocalCounter3 = ulSharedCounterBetweenTasksAndInterrupts; 162 | } 163 | taskEXIT_CRITICAL(); 164 | 165 | fprintf( stderr, "Task 2 ulSharedCounter1BetweenTasks: %u.\r\n", ulLocalCounter1 ); 166 | fprintf( stderr, "Task 2 ulSharedCounter2BetweenTasks: %u.\r\n", ulLocalCounter2 ); 167 | fprintf( stderr, "Task 2 ulSharedCounterBetweenTasksAndInterrupts: %u.\r\n", ulLocalCounter3 ); 168 | 169 | vTaskDelay( pdMS_TO_TICKS( 1000 ) ); 170 | } 171 | } 172 | /*-----------------------------------------------------------*/ 173 | 174 | void vApplicationTickHook( void ) 175 | { 176 | ulSharedCounterBetweenTasksAndInterrupts++; 177 | } 178 | /*-----------------------------------------------------------*/ 179 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_3/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 30 | #define configUSE_IDLE_HOOK 0 31 | #define configUSE_TICK_HOOK 0 32 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 33 | #define configTICK_RATE_HZ ( 1000 ) 34 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 35 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 36 | #define configMAX_TASK_NAME_LEN ( 12 ) 37 | #define configUSE_TRACE_FACILITY 1 38 | #define configUSE_16_BIT_TICKS 0 39 | #define configIDLE_SHOULD_YIELD 1 40 | #define configUSE_MUTEXES 1 41 | #define configCHECK_FOR_STACK_OVERFLOW 0 42 | #define configUSE_RECURSIVE_MUTEXES 1 43 | #define configQUEUE_REGISTRY_SIZE 20 44 | #define configUSE_APPLICATION_TASK_TAG 1 45 | #define configUSE_COUNTING_SEMAPHORES 1 46 | #define configUSE_ALTERNATIVE_API 0 47 | #define configUSE_QUEUE_SETS 1 48 | #define configUSE_TASK_NOTIFICATIONS 1 49 | #define configSUPPORT_STATIC_ALLOCATION 1 50 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 51 | #define configRECORD_STACK_HIGH_ADDRESS 1 52 | #define configKERNEL_PROVIDED_STATIC_MEMORY 1 53 | 54 | /* Software timer related configuration options. The maximum possible task 55 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 56 | * deliberately set higher to ensure it is correctly capped back to 57 | * configMAX_PRIORITIES - 1. */ 58 | #define configUSE_TIMERS 1 59 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 60 | #define configTIMER_QUEUE_LENGTH 20 61 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 62 | 63 | #define configMAX_PRIORITIES ( 7 ) 64 | 65 | /* Co-routine related configuration options. */ 66 | #define configUSE_CO_ROUTINES 0 67 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 68 | 69 | /* Set the following definitions to 1 to include the API function, or zero 70 | * to exclude the API function. In most cases the linker will remove unused 71 | * functions anyway. */ 72 | #define INCLUDE_vTaskPrioritySet 1 73 | #define INCLUDE_uxTaskPriorityGet 1 74 | #define INCLUDE_vTaskDelete 1 75 | #define INCLUDE_vTaskCleanUpResources 0 76 | #define INCLUDE_vTaskSuspend 1 77 | #define INCLUDE_vTaskDelayUntil 1 78 | #define INCLUDE_vTaskDelay 1 79 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 80 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 81 | #define INCLUDE_xTaskGetSchedulerState 1 82 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 83 | #define INCLUDE_xTaskGetIdleTaskHandle 1 84 | #define INCLUDE_xTaskGetHandle 1 85 | #define INCLUDE_eTaskGetState 1 86 | #define INCLUDE_xSemaphoreGetMutexHolder 1 87 | #define INCLUDE_xTimerPendFunctionCall 1 88 | #define INCLUDE_xTaskAbortDelay 1 89 | 90 | /* It is a good idea to define configASSERT() while developing. configASSERT() 91 | * uses the same semantics as the standard C assert() macro. Don't define 92 | * configASSERT() when performing code coverage tests though, as it is not 93 | * intended to asserts() to fail, some code is intended not to run if no 94 | * errors are present. */ 95 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 96 | 97 | #endif /* FREERTOS_CONFIG_H */ 98 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_3/source/tutorial_3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | /* Standard includes. */ 26 | #include 27 | #include 28 | 29 | /* FreeRTOS includes. */ 30 | #include "FreeRTOS.h" 31 | #include "task.h" 32 | 33 | /** 34 | * @brief Function that implement FreeRTOS task. 35 | */ 36 | static void prvTaskFunction( void * pvParams ); 37 | /*-----------------------------------------------------------*/ 38 | 39 | /** 40 | * @brief TCB and stack buffers for the task. 41 | */ 42 | static StaticTask_t xTaskTcbBuffer; 43 | static StackType_t xTaskStackBuffer[ configMINIMAL_STACK_SIZE ]; 44 | /*-----------------------------------------------------------*/ 45 | 46 | /** 47 | * @brief Tutorial entry point. 48 | */ 49 | int main( void ) 50 | { 51 | TaskHandle_t xCreatedTaskHandle = NULL; 52 | 53 | /* TODO 1 - Create a FreeRTOS task using xTaskCreateStatic API which 54 | * uses prvTaskFunction as the task function. 55 | * 56 | * Use the following values for xTaskCreateStatic parameters: 57 | * pxTaskCode prvTaskFunction 58 | * pcName "Task1" 59 | * ulStackDepth configMINIMAL_STACK_SIZE 60 | * pvParameters NULL 61 | * uxPriority tskIDLE_PRIORITY 62 | * puxStackBuffer &( xTaskStackBuffer[ 0 ] ) 63 | * pxTaskBuffer &( xTaskTcbBuffer ) 64 | * 65 | * Assign the return value to xCreatedTaskHandle. 66 | */ 67 | configASSERT( xCreatedTaskHandle != NULL ); 68 | 69 | /* TODO 2 - Call vTaskStartScheduler to start the scheduler. */ 70 | 71 | /* Should not reach here. */ 72 | for( ;; ) 73 | { 74 | 75 | } 76 | 77 | /* Just to make the compiler happy. */ 78 | return 0; 79 | } 80 | /*-----------------------------------------------------------*/ 81 | 82 | static void prvTaskFunction( void * pvParams ) 83 | { 84 | /* Silence warning about unused parameters. */ 85 | ( void ) pvParams; 86 | 87 | for( ;; ) 88 | { 89 | fprintf( stderr, "Tutorial 3 running...\r\n" ); 90 | 91 | /* Pause for a second. */ 92 | vTaskDelay( pdMS_TO_TICKS( 1000 ) ); 93 | } 94 | } 95 | /*-----------------------------------------------------------*/ 96 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_4/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 30 | #define configUSE_IDLE_HOOK 0 31 | #define configUSE_TICK_HOOK 0 32 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 33 | #define configTICK_RATE_HZ ( 1000 ) 34 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 35 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 36 | #define configMAX_TASK_NAME_LEN ( 12 ) 37 | #define configUSE_TRACE_FACILITY 1 38 | #define configUSE_16_BIT_TICKS 0 39 | #define configIDLE_SHOULD_YIELD 1 40 | #define configUSE_MUTEXES 1 41 | #define configCHECK_FOR_STACK_OVERFLOW 0 42 | #define configUSE_RECURSIVE_MUTEXES 1 43 | #define configQUEUE_REGISTRY_SIZE 20 44 | #define configUSE_APPLICATION_TASK_TAG 1 45 | #define configUSE_COUNTING_SEMAPHORES 1 46 | #define configUSE_ALTERNATIVE_API 0 47 | #define configUSE_QUEUE_SETS 1 48 | #define configUSE_TASK_NOTIFICATIONS 1 49 | #define configSUPPORT_STATIC_ALLOCATION 1 50 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 51 | #define configRECORD_STACK_HIGH_ADDRESS 1 52 | #define configKERNEL_PROVIDED_STATIC_MEMORY 1 53 | 54 | /* Software timer related configuration options. The maximum possible task 55 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 56 | * deliberately set higher to ensure it is correctly capped back to 57 | * configMAX_PRIORITIES - 1. */ 58 | #define configUSE_TIMERS 1 59 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 60 | #define configTIMER_QUEUE_LENGTH 20 61 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 62 | 63 | #define configMAX_PRIORITIES ( 7 ) 64 | 65 | /* Co-routine related configuration options. */ 66 | #define configUSE_CO_ROUTINES 0 67 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 68 | 69 | /* Set the following definitions to 1 to include the API function, or zero 70 | * to exclude the API function. In most cases the linker will remove unused 71 | * functions anyway. */ 72 | #define INCLUDE_vTaskPrioritySet 1 73 | #define INCLUDE_uxTaskPriorityGet 1 74 | #define INCLUDE_vTaskDelete 1 75 | #define INCLUDE_vTaskCleanUpResources 0 76 | #define INCLUDE_vTaskSuspend 1 77 | #define INCLUDE_vTaskDelayUntil 1 78 | #define INCLUDE_vTaskDelay 1 79 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 80 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 81 | #define INCLUDE_xTaskGetSchedulerState 1 82 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 83 | #define INCLUDE_xTaskGetIdleTaskHandle 1 84 | #define INCLUDE_xTaskGetHandle 1 85 | #define INCLUDE_eTaskGetState 1 86 | #define INCLUDE_xSemaphoreGetMutexHolder 1 87 | #define INCLUDE_xTimerPendFunctionCall 1 88 | #define INCLUDE_xTaskAbortDelay 1 89 | 90 | /* It is a good idea to define configASSERT() while developing. configASSERT() 91 | * uses the same semantics as the standard C assert() macro. Don't define 92 | * configASSERT() when performing code coverage tests though, as it is not 93 | * intended to asserts() to fail, some code is intended not to run if no 94 | * errors are present. */ 95 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 96 | 97 | #endif /* FREERTOS_CONFIG_H */ 98 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_4/source/tutorial_4.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | /* Standard includes. */ 26 | #include 27 | #include 28 | 29 | /* FreeRTOS includes. */ 30 | #include "FreeRTOS.h" 31 | #include "task.h" 32 | 33 | /** 34 | * @brief Functions that implement FreeRTOS tasks. 35 | */ 36 | static void prvHighPriorityTaskFunction( void * pvParams ); 37 | static void prvLowPriorityTaskFunction( void * pvParams ); 38 | /*-----------------------------------------------------------*/ 39 | 40 | /** 41 | * @brief Tutorial entry point. 42 | */ 43 | int main( void ) 44 | { 45 | BaseType_t xTaskCreationResult = pdFAIL; 46 | 47 | /* TODO 1 - Create a FreeRTOS task using xTaskCreate API which 48 | * uses prvHighPriorityTaskFunction as the task function. 49 | * 50 | * Use the following values for xTaskCreate parameters: 51 | * pxTaskCode prvHighPriorityTaskFunction 52 | * pcName "High" 53 | * usStackDepth configMINIMAL_STACK_SIZE 54 | * pvParameters NULL 55 | * uxPriority 1 56 | * pxCreatedTask NULL 57 | * 58 | * Assign the return value to xTaskCreationResult. 59 | */ 60 | configASSERT( xTaskCreationResult == pdPASS ); 61 | 62 | /* TODO 2 - Create a FreeRTOS task using xTaskCreate API which 63 | * uses prvLowPriorityTaskFunction as the task function. 64 | * 65 | * Use the following values for xTaskCreate parameters: 66 | * pxTaskCode prvLowPriorityTaskFunction 67 | * pcName "Low" 68 | * usStackDepth configMINIMAL_STACK_SIZE 69 | * pvParameters NULL 70 | * uxPriority 0 71 | * pxCreatedTask NULL 72 | * 73 | * Assign the return value to xTaskCreationResult. 74 | */ 75 | configASSERT( xTaskCreationResult == pdPASS ); 76 | 77 | /* Start the scheduler. */ 78 | vTaskStartScheduler(); 79 | 80 | /* Should not reach here. */ 81 | for( ;; ) 82 | { 83 | 84 | } 85 | 86 | /* Just to make the compiler happy. */ 87 | return 0; 88 | } 89 | /*-----------------------------------------------------------*/ 90 | 91 | static void prvHighPriorityTaskFunction( void * pvParams ) 92 | { 93 | uint64_t i; 94 | 95 | /* Silence warning about unused parameters. */ 96 | ( void ) pvParams; 97 | 98 | for( ;; ) 99 | { 100 | fprintf( stderr, "Tutorial 4 high priority task running...\r\n" ); 101 | 102 | for( i = 0; i < 1000000000; i++ ) 103 | { 104 | /* This loop is just a very crude delay implementation. */ 105 | } 106 | } 107 | } 108 | /*-----------------------------------------------------------*/ 109 | 110 | static void prvLowPriorityTaskFunction( void * pvParams ) 111 | { 112 | uint64_t i; 113 | 114 | /* Silence warning about unused parameters. */ 115 | ( void ) pvParams; 116 | 117 | for( ;; ) 118 | { 119 | fprintf( stderr, "Tutorial 4 low priority task running...\r\n" ); 120 | 121 | for( i = 0; i < 1000000000; i++ ) 122 | { 123 | /* This loop is just a very crude delay implementation. */ 124 | } 125 | } 126 | } 127 | /*-----------------------------------------------------------*/ 128 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_5/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 30 | #define configUSE_IDLE_HOOK 0 31 | #define configUSE_TICK_HOOK 0 32 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 33 | #define configTICK_RATE_HZ ( 1000 ) 34 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 35 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 36 | #define configMAX_TASK_NAME_LEN ( 12 ) 37 | #define configUSE_TRACE_FACILITY 1 38 | #define configUSE_16_BIT_TICKS 0 39 | #define configIDLE_SHOULD_YIELD 1 40 | #define configUSE_MUTEXES 1 41 | #define configCHECK_FOR_STACK_OVERFLOW 0 42 | #define configUSE_RECURSIVE_MUTEXES 1 43 | #define configQUEUE_REGISTRY_SIZE 20 44 | #define configUSE_APPLICATION_TASK_TAG 1 45 | #define configUSE_COUNTING_SEMAPHORES 1 46 | #define configUSE_ALTERNATIVE_API 0 47 | #define configUSE_QUEUE_SETS 1 48 | #define configUSE_TASK_NOTIFICATIONS 1 49 | #define configSUPPORT_STATIC_ALLOCATION 1 50 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 51 | #define configRECORD_STACK_HIGH_ADDRESS 1 52 | #define configKERNEL_PROVIDED_STATIC_MEMORY 1 53 | 54 | /* Software timer related configuration options. The maximum possible task 55 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 56 | * deliberately set higher to ensure it is correctly capped back to 57 | * configMAX_PRIORITIES - 1. */ 58 | #define configUSE_TIMERS 1 59 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 60 | #define configTIMER_QUEUE_LENGTH 20 61 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 62 | 63 | #define configMAX_PRIORITIES ( 7 ) 64 | 65 | /* Co-routine related configuration options. */ 66 | #define configUSE_CO_ROUTINES 0 67 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 68 | 69 | /* Set the following definitions to 1 to include the API function, or zero 70 | * to exclude the API function. In most cases the linker will remove unused 71 | * functions anyway. */ 72 | #define INCLUDE_vTaskPrioritySet 1 73 | #define INCLUDE_uxTaskPriorityGet 1 74 | #define INCLUDE_vTaskDelete 1 75 | #define INCLUDE_vTaskCleanUpResources 0 76 | #define INCLUDE_vTaskSuspend 1 77 | #define INCLUDE_vTaskDelayUntil 1 78 | #define INCLUDE_vTaskDelay 1 79 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 80 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 81 | #define INCLUDE_xTaskGetSchedulerState 1 82 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 83 | #define INCLUDE_xTaskGetIdleTaskHandle 1 84 | #define INCLUDE_xTaskGetHandle 1 85 | #define INCLUDE_eTaskGetState 1 86 | #define INCLUDE_xSemaphoreGetMutexHolder 1 87 | #define INCLUDE_xTimerPendFunctionCall 1 88 | #define INCLUDE_xTaskAbortDelay 1 89 | 90 | /* It is a good idea to define configASSERT() while developing. configASSERT() 91 | * uses the same semantics as the standard C assert() macro. Don't define 92 | * configASSERT() when performing code coverage tests though, as it is not 93 | * intended to asserts() to fail, some code is intended not to run if no 94 | * errors are present. */ 95 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 96 | 97 | #endif /* FREERTOS_CONFIG_H */ 98 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_5/source/tutorial_5.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | /* Standard includes. */ 26 | #include 27 | #include 28 | 29 | /* FreeRTOS includes. */ 30 | #include "FreeRTOS.h" 31 | #include "task.h" 32 | 33 | /** 34 | * @brief Function that implement FreeRTOS tasks. 35 | */ 36 | static void prvTaskFunction( void * pvParams ); 37 | /*-----------------------------------------------------------*/ 38 | 39 | /** 40 | * @brief Tutorial entry point. 41 | */ 42 | int main( void ) 43 | { 44 | BaseType_t xTaskCreationResult = pdFAIL; 45 | 46 | /* TODO 1 - Create a FreeRTOS task using xTaskCreate API which 47 | * uses prvTaskFunction as the task function. 48 | * 49 | * Use the following values for xTaskCreate parameters: 50 | * pxTaskCode prvTaskFunction 51 | * pcName "Task1" 52 | * usStackDepth configMINIMAL_STACK_SIZE 53 | * pvParameters ( void * ) 1 54 | * uxPriority tskIDLE_PRIORITY 55 | * pxCreatedTask NULL 56 | * 57 | * Assign the return value to xTaskCreationResult. 58 | */ 59 | configASSERT( xTaskCreationResult == pdPASS ); 60 | 61 | /* TODO 2 - Create a FreeRTOS task using xTaskCreate API which 62 | * uses prvTaskFunction as the task function. 63 | * 64 | * Use the following values for xTaskCreate parameters: 65 | * pxTaskCode prvTaskFunction 66 | * pcName "Task2" 67 | * usStackDepth configMINIMAL_STACK_SIZE 68 | * pvParameters ( void * ) 2 69 | * uxPriority tskIDLE_PRIORITY 70 | * pxCreatedTask NULL 71 | * 72 | * Assign the return value to xTaskCreationResult. 73 | */ 74 | configASSERT( xTaskCreationResult == pdPASS ); 75 | 76 | /* Start the scheduler. */ 77 | vTaskStartScheduler(); 78 | 79 | /* Should not reach here. */ 80 | for( ;; ) 81 | { 82 | 83 | } 84 | 85 | /* Just to make the compiler happy. */ 86 | return 0; 87 | } 88 | /*-----------------------------------------------------------*/ 89 | 90 | static void prvTaskFunction( void * pvParams ) 91 | { 92 | for( ;; ) 93 | { 94 | fprintf( stderr, "Tutorial 5 task %p running...\r\n", pvParams ); 95 | 96 | vTaskDelay( pdMS_TO_TICKS( 1000 ) ); 97 | } 98 | } 99 | /*-----------------------------------------------------------*/ 100 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_6/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_TIME_SLICING 1 30 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 31 | #define configUSE_IDLE_HOOK 0 32 | #define configUSE_TICK_HOOK 0 33 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 34 | #define configTICK_RATE_HZ ( 1000 ) 35 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 36 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 37 | #define configMAX_TASK_NAME_LEN ( 12 ) 38 | #define configUSE_TRACE_FACILITY 1 39 | #define configUSE_16_BIT_TICKS 0 40 | #define configIDLE_SHOULD_YIELD 1 41 | #define configUSE_MUTEXES 1 42 | #define configCHECK_FOR_STACK_OVERFLOW 0 43 | #define configUSE_RECURSIVE_MUTEXES 1 44 | #define configQUEUE_REGISTRY_SIZE 20 45 | #define configUSE_APPLICATION_TASK_TAG 1 46 | #define configUSE_COUNTING_SEMAPHORES 1 47 | #define configUSE_ALTERNATIVE_API 0 48 | #define configUSE_QUEUE_SETS 1 49 | #define configUSE_TASK_NOTIFICATIONS 1 50 | #define configSUPPORT_STATIC_ALLOCATION 1 51 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 52 | #define configRECORD_STACK_HIGH_ADDRESS 1 53 | #define configKERNEL_PROVIDED_STATIC_MEMORY 1 54 | 55 | /* Software timer related configuration options. The maximum possible task 56 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 57 | * deliberately set higher to ensure it is correctly capped back to 58 | * configMAX_PRIORITIES - 1. */ 59 | #define configUSE_TIMERS 1 60 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 61 | #define configTIMER_QUEUE_LENGTH 20 62 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 63 | 64 | #define configMAX_PRIORITIES ( 7 ) 65 | 66 | /* Co-routine related configuration options. */ 67 | #define configUSE_CO_ROUTINES 0 68 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 69 | 70 | /* Set the following definitions to 1 to include the API function, or zero 71 | * to exclude the API function. In most cases the linker will remove unused 72 | * functions anyway. */ 73 | #define INCLUDE_vTaskPrioritySet 1 74 | #define INCLUDE_uxTaskPriorityGet 1 75 | #define INCLUDE_vTaskDelete 1 76 | #define INCLUDE_vTaskCleanUpResources 0 77 | #define INCLUDE_vTaskSuspend 1 78 | #define INCLUDE_vTaskDelayUntil 1 79 | #define INCLUDE_vTaskDelay 1 80 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 81 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 82 | #define INCLUDE_xTaskGetSchedulerState 1 83 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 84 | #define INCLUDE_xTaskGetIdleTaskHandle 1 85 | #define INCLUDE_xTaskGetHandle 1 86 | #define INCLUDE_eTaskGetState 1 87 | #define INCLUDE_xSemaphoreGetMutexHolder 1 88 | #define INCLUDE_xTimerPendFunctionCall 1 89 | #define INCLUDE_xTaskAbortDelay 1 90 | 91 | /* It is a good idea to define configASSERT() while developing. configASSERT() 92 | * uses the same semantics as the standard C assert() macro. Don't define 93 | * configASSERT() when performing code coverage tests though, as it is not 94 | * intended to asserts() to fail, some code is intended not to run if no 95 | * errors are present. */ 96 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 97 | 98 | #endif /* FREERTOS_CONFIG_H */ 99 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_6/source/tutorial_6.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | /* Standard includes. */ 26 | #include 27 | #include 28 | 29 | /* FreeRTOS includes. */ 30 | #include "FreeRTOS.h" 31 | #include "task.h" 32 | 33 | /** 34 | * @brief Functions that implement FreeRTOS tasks. 35 | */ 36 | static void prvTask1Function( void * pvParams ); 37 | static void prvTask2Function( void * pvParams ); 38 | /*-----------------------------------------------------------*/ 39 | 40 | /** 41 | * @brief Tutorial entry point. 42 | */ 43 | int main( void ) 44 | { 45 | BaseType_t xTaskCreationResult = pdFAIL; 46 | 47 | xTaskCreationResult = xTaskCreate( prvTask1Function, 48 | "Task1", 49 | configMINIMAL_STACK_SIZE, 50 | NULL, 51 | tskIDLE_PRIORITY, 52 | NULL ); 53 | configASSERT( xTaskCreationResult == pdPASS ); 54 | 55 | xTaskCreationResult = xTaskCreate( prvTask2Function, 56 | "Task2", 57 | configMINIMAL_STACK_SIZE, 58 | NULL, 59 | tskIDLE_PRIORITY, 60 | NULL ); 61 | configASSERT( xTaskCreationResult == pdPASS ); 62 | 63 | /* Start the scheduler. */ 64 | vTaskStartScheduler(); 65 | 66 | /* Should not reach here. */ 67 | for( ;; ) 68 | { 69 | 70 | } 71 | 72 | /* Just to make the compiler happy. */ 73 | return 0; 74 | } 75 | /*-----------------------------------------------------------*/ 76 | 77 | static void prvTask1Function( void * pvParams ) 78 | { 79 | uint64_t i; 80 | 81 | /* Silence warning about unused parameters. */ 82 | ( void ) pvParams; 83 | 84 | for( ;; ) 85 | { 86 | fprintf( stderr, "Tutorial 6 task 1 running...\r\n" ); 87 | 88 | for( i = 0; i < 100000000; i++ ) 89 | { 90 | /* This loop is just a very crude delay implementation. */ 91 | } 92 | } 93 | } 94 | /*-----------------------------------------------------------*/ 95 | 96 | static void prvTask2Function( void * pvParams ) 97 | { 98 | uint64_t i; 99 | 100 | /* Silence warning about unused parameters. */ 101 | ( void ) pvParams; 102 | 103 | for( ;; ) 104 | { 105 | fprintf( stderr, "Tutorial 6 task 2 running...\r\n" ); 106 | 107 | for( i = 0; i < 100000000; i++ ) 108 | { 109 | /* This loop is just a very crude delay implementation. */ 110 | } 111 | } 112 | } 113 | /*-----------------------------------------------------------*/ 114 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_7/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_TIME_SLICING 0 30 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 31 | #define configUSE_IDLE_HOOK 0 32 | #define configUSE_TICK_HOOK 0 33 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 34 | #define configTICK_RATE_HZ ( 1000 ) 35 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 36 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 37 | #define configMAX_TASK_NAME_LEN ( 12 ) 38 | #define configUSE_TRACE_FACILITY 1 39 | #define configUSE_16_BIT_TICKS 0 40 | #define configIDLE_SHOULD_YIELD 1 41 | #define configUSE_MUTEXES 1 42 | #define configCHECK_FOR_STACK_OVERFLOW 0 43 | #define configUSE_RECURSIVE_MUTEXES 1 44 | #define configQUEUE_REGISTRY_SIZE 20 45 | #define configUSE_APPLICATION_TASK_TAG 1 46 | #define configUSE_COUNTING_SEMAPHORES 1 47 | #define configUSE_ALTERNATIVE_API 0 48 | #define configUSE_QUEUE_SETS 1 49 | #define configUSE_TASK_NOTIFICATIONS 1 50 | #define configSUPPORT_STATIC_ALLOCATION 1 51 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 52 | #define configRECORD_STACK_HIGH_ADDRESS 1 53 | #define configKERNEL_PROVIDED_STATIC_MEMORY 1 54 | 55 | /* Software timer related configuration options. The maximum possible task 56 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 57 | * deliberately set higher to ensure it is correctly capped back to 58 | * configMAX_PRIORITIES - 1. */ 59 | #define configUSE_TIMERS 1 60 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 61 | #define configTIMER_QUEUE_LENGTH 20 62 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 63 | 64 | #define configMAX_PRIORITIES ( 7 ) 65 | 66 | /* Co-routine related configuration options. */ 67 | #define configUSE_CO_ROUTINES 0 68 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 69 | 70 | /* Set the following definitions to 1 to include the API function, or zero 71 | * to exclude the API function. In most cases the linker will remove unused 72 | * functions anyway. */ 73 | #define INCLUDE_vTaskPrioritySet 1 74 | #define INCLUDE_uxTaskPriorityGet 1 75 | #define INCLUDE_vTaskDelete 1 76 | #define INCLUDE_vTaskCleanUpResources 0 77 | #define INCLUDE_vTaskSuspend 1 78 | #define INCLUDE_vTaskDelayUntil 1 79 | #define INCLUDE_vTaskDelay 1 80 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 81 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 82 | #define INCLUDE_xTaskGetSchedulerState 1 83 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 84 | #define INCLUDE_xTaskGetIdleTaskHandle 1 85 | #define INCLUDE_xTaskGetHandle 1 86 | #define INCLUDE_eTaskGetState 1 87 | #define INCLUDE_xSemaphoreGetMutexHolder 1 88 | #define INCLUDE_xTimerPendFunctionCall 1 89 | #define INCLUDE_xTaskAbortDelay 1 90 | 91 | /* It is a good idea to define configASSERT() while developing. configASSERT() 92 | * uses the same semantics as the standard C assert() macro. Don't define 93 | * configASSERT() when performing code coverage tests though, as it is not 94 | * intended to asserts() to fail, some code is intended not to run if no 95 | * errors are present. */ 96 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 97 | 98 | #endif /* FREERTOS_CONFIG_H */ 99 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_7/source/tutorial_7.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | /* Standard includes. */ 26 | #include 27 | #include 28 | 29 | /* FreeRTOS includes. */ 30 | #include "FreeRTOS.h" 31 | #include "task.h" 32 | 33 | /** 34 | * @brief Functions that implement FreeRTOS tasks. 35 | */ 36 | static void prvTask1Function( void * pvParams ); 37 | static void prvTask2Function( void * pvParams ); 38 | /*-----------------------------------------------------------*/ 39 | 40 | /** 41 | * @brief Tutorial entry point. 42 | */ 43 | int main( void ) 44 | { 45 | BaseType_t xTaskCreationResult = pdFAIL; 46 | 47 | xTaskCreationResult = xTaskCreate( prvTask1Function, 48 | "Task1", 49 | configMINIMAL_STACK_SIZE, 50 | NULL, 51 | tskIDLE_PRIORITY, 52 | NULL ); 53 | configASSERT( xTaskCreationResult == pdPASS ); 54 | 55 | /* Start the scheduler. */ 56 | vTaskStartScheduler(); 57 | 58 | /* Should not reach here. */ 59 | for( ;; ) 60 | { 61 | 62 | } 63 | 64 | /* Just to make the compiler happy. */ 65 | return 0; 66 | } 67 | /*-----------------------------------------------------------*/ 68 | 69 | static void prvTask1Function( void * pvParams ) 70 | { 71 | uint64_t i; 72 | BaseType_t xTaskCreationResult = pdFAIL; 73 | 74 | /* Silence warning about unused parameters. */ 75 | ( void ) pvParams; 76 | 77 | xTaskCreationResult = xTaskCreate( prvTask2Function, 78 | "Task2", 79 | configMINIMAL_STACK_SIZE, 80 | NULL, 81 | tskIDLE_PRIORITY, 82 | NULL ); 83 | configASSERT( xTaskCreationResult == pdPASS ); 84 | 85 | for( ;; ) 86 | { 87 | fprintf( stderr, "Tutorial 7 task 1 running...\r\n" ); 88 | 89 | for( i = 0; i < 100000000; i++ ) 90 | { 91 | /* This loop is just a very crude delay implementation. */ 92 | } 93 | } 94 | } 95 | /*-----------------------------------------------------------*/ 96 | 97 | static void prvTask2Function( void * pvParams ) 98 | { 99 | uint64_t i; 100 | 101 | /* Silence warning about unused parameters. */ 102 | ( void ) pvParams; 103 | 104 | for( ;; ) 105 | { 106 | fprintf( stderr, "Tutorial 7 task 2 running...\r\n" ); 107 | 108 | for( i = 0; i < 100000000; i++ ) 109 | { 110 | /* This loop is just a very crude delay implementation. */ 111 | } 112 | } 113 | } 114 | /*-----------------------------------------------------------*/ 115 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_8/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 0 29 | #define configUSE_TIME_SLICING 0 30 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 31 | #define configUSE_IDLE_HOOK 0 32 | #define configUSE_TICK_HOOK 0 33 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 34 | #define configTICK_RATE_HZ ( 1000 ) 35 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 36 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 37 | #define configMAX_TASK_NAME_LEN ( 12 ) 38 | #define configUSE_TRACE_FACILITY 1 39 | #define configUSE_16_BIT_TICKS 0 40 | #define configIDLE_SHOULD_YIELD 1 41 | #define configUSE_MUTEXES 1 42 | #define configCHECK_FOR_STACK_OVERFLOW 0 43 | #define configUSE_RECURSIVE_MUTEXES 1 44 | #define configQUEUE_REGISTRY_SIZE 20 45 | #define configUSE_APPLICATION_TASK_TAG 1 46 | #define configUSE_COUNTING_SEMAPHORES 1 47 | #define configUSE_ALTERNATIVE_API 0 48 | #define configUSE_QUEUE_SETS 1 49 | #define configUSE_TASK_NOTIFICATIONS 1 50 | #define configSUPPORT_STATIC_ALLOCATION 1 51 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 52 | #define configRECORD_STACK_HIGH_ADDRESS 1 53 | #define configKERNEL_PROVIDED_STATIC_MEMORY 1 54 | 55 | /* Software timer related configuration options. The maximum possible task 56 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 57 | * deliberately set higher to ensure it is correctly capped back to 58 | * configMAX_PRIORITIES - 1. */ 59 | #define configUSE_TIMERS 1 60 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 61 | #define configTIMER_QUEUE_LENGTH 20 62 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 63 | 64 | #define configMAX_PRIORITIES ( 7 ) 65 | 66 | /* Co-routine related configuration options. */ 67 | #define configUSE_CO_ROUTINES 0 68 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 69 | 70 | /* Set the following definitions to 1 to include the API function, or zero 71 | * to exclude the API function. In most cases the linker will remove unused 72 | * functions anyway. */ 73 | #define INCLUDE_vTaskPrioritySet 1 74 | #define INCLUDE_uxTaskPriorityGet 1 75 | #define INCLUDE_vTaskDelete 1 76 | #define INCLUDE_vTaskCleanUpResources 0 77 | #define INCLUDE_vTaskSuspend 1 78 | #define INCLUDE_vTaskDelayUntil 1 79 | #define INCLUDE_vTaskDelay 1 80 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 81 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 82 | #define INCLUDE_xTaskGetSchedulerState 1 83 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 84 | #define INCLUDE_xTaskGetIdleTaskHandle 1 85 | #define INCLUDE_xTaskGetHandle 1 86 | #define INCLUDE_eTaskGetState 1 87 | #define INCLUDE_xSemaphoreGetMutexHolder 1 88 | #define INCLUDE_xTimerPendFunctionCall 1 89 | #define INCLUDE_xTaskAbortDelay 1 90 | 91 | /* It is a good idea to define configASSERT() while developing. configASSERT() 92 | * uses the same semantics as the standard C assert() macro. Don't define 93 | * configASSERT() when performing code coverage tests though, as it is not 94 | * intended to asserts() to fail, some code is intended not to run if no 95 | * errors are present. */ 96 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 97 | 98 | #endif /* FREERTOS_CONFIG_H */ 99 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_8/source/tutorial_8.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | /* Standard includes. */ 26 | #include 27 | #include 28 | 29 | /* FreeRTOS includes. */ 30 | #include "FreeRTOS.h" 31 | #include "task.h" 32 | 33 | /** 34 | * @brief Functions that implement FreeRTOS tasks. 35 | */ 36 | static void prvTask1Function( void * pvParams ); 37 | static void prvTask2Function( void * pvParams ); 38 | /*-----------------------------------------------------------*/ 39 | 40 | /** 41 | * @brief Tutorial entry point. 42 | */ 43 | int main( void ) 44 | { 45 | BaseType_t xTaskCreationResult = pdFAIL; 46 | 47 | xTaskCreationResult = xTaskCreate( prvTask1Function, 48 | "Task1", 49 | configMINIMAL_STACK_SIZE, 50 | NULL, 51 | tskIDLE_PRIORITY, 52 | NULL ); 53 | configASSERT( xTaskCreationResult == pdPASS ); 54 | 55 | /* Start the scheduler. */ 56 | vTaskStartScheduler(); 57 | 58 | /* Should not reach here. */ 59 | for( ;; ) 60 | { 61 | 62 | } 63 | 64 | /* Just to make the compiler happy. */ 65 | return 0; 66 | } 67 | /*-----------------------------------------------------------*/ 68 | 69 | static void prvTask1Function( void * pvParams ) 70 | { 71 | uint64_t i; 72 | BaseType_t xTaskCreationResult = pdFAIL; 73 | 74 | /* Silence warning about unused parameters. */ 75 | ( void ) pvParams; 76 | 77 | xTaskCreationResult = xTaskCreate( prvTask2Function, 78 | "Task2", 79 | configMINIMAL_STACK_SIZE, 80 | NULL, 81 | tskIDLE_PRIORITY + 1, 82 | NULL ); 83 | configASSERT( xTaskCreationResult == pdPASS ); 84 | 85 | for( ;; ) 86 | { 87 | fprintf( stderr, "Tutorial 8 task 1 running...\r\n" ); 88 | 89 | for( i = 0; i < 100000000; i++ ) 90 | { 91 | /* This loop is just a very crude delay implementation. */ 92 | } 93 | } 94 | } 95 | /*-----------------------------------------------------------*/ 96 | 97 | static void prvTask2Function( void * pvParams ) 98 | { 99 | uint64_t i; 100 | 101 | /* Silence warning about unused parameters. */ 102 | ( void ) pvParams; 103 | 104 | for( ;; ) 105 | { 106 | fprintf( stderr, "Tutorial 8 task 2 running...\r\n" ); 107 | 108 | for( i = 0; i < 100000000; i++ ) 109 | { 110 | /* This loop is just a very crude delay implementation. */ 111 | } 112 | } 113 | } 114 | /*-----------------------------------------------------------*/ 115 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_9/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | #ifndef FREERTOS_CONFIG_H 26 | #define FREERTOS_CONFIG_H 27 | 28 | #define configUSE_PREEMPTION 1 29 | #define configUSE_TIME_SLICING 1 30 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 31 | #define configUSE_IDLE_HOOK 0 32 | #define configUSE_TICK_HOOK 0 33 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 34 | #define configTICK_RATE_HZ ( 1000 ) 35 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */ 36 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) 37 | #define configMAX_TASK_NAME_LEN ( 12 ) 38 | #define configUSE_TRACE_FACILITY 1 39 | #define configUSE_16_BIT_TICKS 0 40 | #define configIDLE_SHOULD_YIELD 1 41 | #define configUSE_MUTEXES 1 42 | #define configCHECK_FOR_STACK_OVERFLOW 0 43 | #define configUSE_RECURSIVE_MUTEXES 1 44 | #define configQUEUE_REGISTRY_SIZE 20 45 | #define configUSE_APPLICATION_TASK_TAG 1 46 | #define configUSE_COUNTING_SEMAPHORES 1 47 | #define configUSE_ALTERNATIVE_API 0 48 | #define configUSE_QUEUE_SETS 1 49 | #define configUSE_TASK_NOTIFICATIONS 1 50 | #define configSUPPORT_STATIC_ALLOCATION 1 51 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 52 | #define configRECORD_STACK_HIGH_ADDRESS 1 53 | #define configKERNEL_PROVIDED_STATIC_MEMORY 1 54 | 55 | /* Software timer related configuration options. The maximum possible task 56 | * priority is configMAX_PRIORITIES - 1. The priority of the timer task is 57 | * deliberately set higher to ensure it is correctly capped back to 58 | * configMAX_PRIORITIES - 1. */ 59 | #define configUSE_TIMERS 1 60 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 61 | #define configTIMER_QUEUE_LENGTH 20 62 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 63 | 64 | #define configMAX_PRIORITIES ( 7 ) 65 | 66 | /* Co-routine related configuration options. */ 67 | #define configUSE_CO_ROUTINES 0 68 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 69 | 70 | /* Set the following definitions to 1 to include the API function, or zero 71 | * to exclude the API function. In most cases the linker will remove unused 72 | * functions anyway. */ 73 | #define INCLUDE_vTaskPrioritySet 1 74 | #define INCLUDE_uxTaskPriorityGet 1 75 | #define INCLUDE_vTaskDelete 1 76 | #define INCLUDE_vTaskCleanUpResources 0 77 | #define INCLUDE_vTaskSuspend 1 78 | #define INCLUDE_vTaskDelayUntil 1 79 | #define INCLUDE_vTaskDelay 1 80 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 81 | #define INCLUDE_uxTaskGetStackHighWaterMark2 1 82 | #define INCLUDE_xTaskGetSchedulerState 1 83 | #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 84 | #define INCLUDE_xTaskGetIdleTaskHandle 1 85 | #define INCLUDE_xTaskGetHandle 1 86 | #define INCLUDE_eTaskGetState 1 87 | #define INCLUDE_xSemaphoreGetMutexHolder 1 88 | #define INCLUDE_xTimerPendFunctionCall 1 89 | #define INCLUDE_xTaskAbortDelay 1 90 | 91 | /* It is a good idea to define configASSERT() while developing. configASSERT() 92 | * uses the same semantics as the standard C assert() macro. Don't define 93 | * configASSERT() when performing code coverage tests though, as it is not 94 | * intended to asserts() to fail, some code is intended not to run if no 95 | * errors are present. */ 96 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 97 | 98 | #endif /* FREERTOS_CONFIG_H */ 99 | -------------------------------------------------------------------------------- /source/tutorials/tutorial_9/source/tutorial_9.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS-Tutorials 3 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT-0 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 8 | * software and associated documentation files (the "Software"), to deal in the Software 9 | * without restriction, including without limitation the rights to use, copy, modify, 10 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | * 20 | * https://www.FreeRTOS.org 21 | * https://github.com/FreeRTOS 22 | * 23 | */ 24 | 25 | /* Standard includes. */ 26 | #include 27 | #include 28 | 29 | /* FreeRTOS includes. */ 30 | #include "FreeRTOS.h" 31 | #include "task.h" 32 | #include "queue.h" 33 | 34 | /** 35 | * @brief Functions that implement FreeRTOS tasks. 36 | */ 37 | static void prvSenderTask( void * pvParams ); 38 | static void prvReceiverTask( void * pvParams ); 39 | /*-----------------------------------------------------------*/ 40 | 41 | /** 42 | * @brief Queue used in the program. 43 | */ 44 | static QueueHandle_t xQueue; 45 | /*-----------------------------------------------------------*/ 46 | 47 | /** 48 | * @brief Tutorial entry point. 49 | */ 50 | int main( void ) 51 | { 52 | BaseType_t xTaskCreationResult = pdFAIL; 53 | 54 | xTaskCreationResult = xTaskCreate( prvSenderTask, 55 | "Sender", 56 | configMINIMAL_STACK_SIZE, 57 | NULL, 58 | tskIDLE_PRIORITY + 1, 59 | NULL ); 60 | configASSERT( xTaskCreationResult == pdPASS ); 61 | 62 | xTaskCreationResult = xTaskCreate( prvReceiverTask, 63 | "Receiver", 64 | configMINIMAL_STACK_SIZE, 65 | NULL, 66 | tskIDLE_PRIORITY, 67 | NULL ); 68 | configASSERT( xTaskCreationResult == pdPASS ); 69 | 70 | /* TODO 1 - Create a queue capable of holding 5 UBaseType_t using 71 | * xQueueCreate API. 72 | * 73 | * Use the following values for xQueueCreate parameters: 74 | * uxQueueLength 5 75 | * uxItemSize sizeof( UBaseType_t ) 76 | * 77 | * Assign the return value to xQueue. 78 | */ 79 | 80 | configASSERT( xQueue != NULL ); 81 | 82 | /* Start the scheduler. */ 83 | vTaskStartScheduler(); 84 | 85 | /* Should not reach here. */ 86 | for( ;; ) 87 | { 88 | 89 | } 90 | 91 | /* Just to make the compiler happy. */ 92 | return 0; 93 | } 94 | /*-----------------------------------------------------------*/ 95 | 96 | static void prvSenderTask( void * pvParams ) 97 | { 98 | BaseType_t xQueueSendResult; 99 | UBaseType_t uxValueToSend = 0; 100 | 101 | /* Silence warning about unused parameters. */ 102 | ( void ) pvParams; 103 | 104 | for( ;; ) 105 | { 106 | uxValueToSend++; 107 | 108 | /* TODO 2 - Send uxValueToSend to the queue using xQueueSend API. 109 | * 110 | * Use the following values for xQueueSend parameters: 111 | * xQueue xQueue 112 | * pvItemToQueue &( uxValueToSend ) 113 | * xTicksToWait portMAX_DELAY 114 | * 115 | * Assign the return value to xQueueSendResult. 116 | */ 117 | 118 | configASSERT( xQueueSendResult == pdPASS ); 119 | 120 | vTaskDelay( pdMS_TO_TICKS( 1000 ) ); 121 | } 122 | } 123 | /*-----------------------------------------------------------*/ 124 | 125 | static void prvReceiverTask( void * pvParams ) 126 | { 127 | UBaseType_t uxReceivedValue; 128 | 129 | /* Silence warning about unused parameters. */ 130 | ( void ) pvParams; 131 | 132 | for( ;; ) 133 | { 134 | /* TODO 3 - Receive from the queue using xQueueReceive API. 135 | * 136 | * Use the following values for xQueueReceive parameters: 137 | * xQueue xQueue 138 | * pvBuffer &( uxReceivedValue ) 139 | * xTicksToWait portMAX_DELAY 140 | */ 141 | 142 | 143 | fprintf( stderr, "Value received from the queue: %lu\r\n", uxReceivedValue ); 144 | fprintf( stderr, "Number of items in the queue: %lu.\r\n", uxQueueMessagesWaiting( xQueue ) ); 145 | } 146 | } 147 | /*-----------------------------------------------------------*/ 148 | --------------------------------------------------------------------------------