diff --git a/.clang-format b/.clang-format index f2dd0de..cbb22eb 100644 --- a/.clang-format +++ b/.clang-format @@ -3,110 +3,183 @@ Language: Cpp # BasedOnStyle: Google AccessModifierOffset: -1 AlignAfterOpenBracket: Align -AlignConsecutiveMacros: false -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseColons: false AlignEscapedNewlines: Left -AlignOperands: true -AlignTrailingComments: true +AlignOperands: Align +AlignTrailingComments: + Kind: Always + OverEmptyLines: 0 AllowAllArgumentsOnNextLine: true -AllowAllConstructorInitializersOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true +AllowBreakBeforeNoexceptSpecifier: Never AllowShortBlocksOnASingleLine: Never AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: All -AllowShortLambdasOnASingleLine: All +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: Empty AllowShortIfStatementsOnASingleLine: WithoutElse +AllowShortLambdasOnASingleLine: All AllowShortLoopsOnASingleLine: true AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: true AlwaysBreakTemplateDeclarations: Yes +AttributeMacros: + - __capability BinPackArguments: true BinPackParameters: true +BitFieldColonSpacing: Both BraceWrapping: AfterCaseLabel: false AfterClass: false - AfterControlStatement: false + AfterControlStatement: Never AfterEnum: false + AfterExternBlock: false AfterFunction: false AfterNamespace: false AfterObjCDeclaration: false AfterStruct: false AfterUnion: false - AfterExternBlock: false BeforeCatch: false BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false IndentBraces: false SplitEmptyFunction: true SplitEmptyRecord: true SplitEmptyNamespace: true +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakArrays: true BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: Always BreakBeforeBraces: Attach -BreakBeforeInheritanceComma: false -BreakInheritanceList: BeforeColon +BreakBeforeInlineASMColon: OnlyMultiline BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: BeforeColon -BreakAfterJavaFieldAnnotations: false +BreakInheritanceList: BeforeColon BreakStringLiterals: true ColumnLimit: 80 CommentPragmas: '^ IWYU pragma:' CompactNamespaces: false -ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true -DeriveLineEnding: true DerivePointerAlignment: true DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock ExperimentalAutoDetectBinPacking: false FixNamespaceComments: true ForEachMacros: - foreach - Q_FOREACH - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE IncludeBlocks: Regroup IncludeCategories: - Regex: '^' Priority: 2 SortPriority: 0 + CaseSensitive: false - Regex: '^<.*\.h>' Priority: 1 SortPriority: 0 + CaseSensitive: false - Regex: '^<.*' Priority: 2 SortPriority: 0 + CaseSensitive: false - Regex: '.*' Priority: 3 SortPriority: 0 + CaseSensitive: false IncludeIsMainRegex: '([-_](test|unittest))?$' IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseBlocks: false IndentCaseLabels: true +IndentExternBlock: AfterExternBlock IndentGotoLabels: true IndentPPDirectives: None +IndentRequiresClause: true IndentWidth: 2 IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: false +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 JavaScriptQuotes: Leave JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: false +KeepEmptyLinesAtEOF: false +LambdaBodyIndentation: Signature +LineEnding: DeriveLF MacroBlockBegin: '' MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 NamespaceIndentation: None ObjCBinPackProtocolList: Never ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: NextLine PenaltyBreakAssignment: 2 PenaltyBreakBeforeFirstCallParameter: 1 PenaltyBreakComment: 300 PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 PenaltyBreakString: 1000 PenaltyBreakTemplateDeclaration: 10 PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 PenaltyReturnTypeOnItsOwnLine: 200 PointerAlignment: Left +PPIndentWidth: -1 +QualifierAlignment: Leave RawStringFormats: - Language: Cpp Delimiters: @@ -133,36 +206,75 @@ RawStringFormats: - PARSE_TEXT_PROTO - ParseTextOrDie - ParseTextProtoOrDie - CanonicalDelimiter: '' + - ParseTestProto + - ParsePartialTestProto + CanonicalDelimiter: pb BasedOnStyle: google +ReferenceAlignment: Pointer ReflowComments: true -SortIncludes: true -SortUsingDeclarations: true +RemoveBracesLLVM: false +RemoveParentheses: Leave +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric SpaceAfterCStyleCast: false SpaceAfterLogicalNot: false SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false SpaceBeforeCpp11BracedList: false SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false SpaceInEmptyBlock: false -SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 2 -SpacesInAngles: false -SpacesInConditionalStatement: false +SpacesInAngles: Never SpacesInContainerLiterals: true -SpacesInCStyleCastParentheses: false -SpacesInParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false SpacesInSquareBrackets: false -SpaceBeforeSquareBrackets: false Standard: Auto +StatementAttributeLikeMacros: + - Q_EMIT StatementMacros: - Q_UNUSED - QT_REQUIRE_VERSION TabWidth: 8 -UseCRLF: false UseTab: Never +VerilogBreakBetweenInstancePorts: true +WhitespaceSensitiveMacros: + - BOOST_PP_STRINGIZE + - CF_SWIFT_NAME + - NS_SWIFT_NAME + - PP_STRINGIZE + - STRINGIZE ... diff --git a/.clang-tidy b/.clang-tidy index b6d771a..763a884 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -24,11 +24,13 @@ Checks: 'cert-*, -hicpp-named-parameter, -hicpp-no-array-decay, -hicpp-no-assembler, + -misc-include-cleaner, + -performance-enum-size, -readability-named-parameter, + -readability-redundant-inline-specifier, ' WarningsAsErrors: '*' HeaderFilterRegex: '' -AnalyzeTemporaryDtors: false FormatStyle: google CheckOptions: - key: abseil-string-find-startswith.AbseilStringsMatchHeader diff --git a/.github/actions/submodules/action.yml b/.github/actions/submodules/action.yml deleted file mode 100644 index bb8cf76..0000000 --- a/.github/actions/submodules/action.yml +++ /dev/null @@ -1,10 +0,0 @@ -runs: - using: "composite" - steps: - - name: Clone Submodules - shell: bash - run: | - git config --global url."https://github.com/".insteadOf "git@github.com:" - auth_header="$(git config --local --get http.https://github.com/.extraheader)" - git submodule sync --recursive - git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive diff --git a/.github/workflows/ContinuousIntegration.yml b/.github/workflows/ContinuousIntegration.yml index 4040535..dd18dcb 100644 --- a/.github/workflows/ContinuousIntegration.yml +++ b/.github/workflows/ContinuousIntegration.yml @@ -15,47 +15,53 @@ env: jobs: Check-Formatting: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v2 - - uses: ./.github/actions/submodules + - name: Checkout Repository and Submodules + uses: actions/checkout@v2 + with: + submodules: recursive - - name: Install Dependencies - run: sudo apt install clang-format + - name: Install Dependencies + run: sudo apt install clang-format - - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + - name: Configure CMake + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - - name: Run Clang Format - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -t clang-format-dry-run + - name: Run Clang Format + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -t clang-format-dry-run Check-Linter: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v2 - - uses: ./.github/actions/submodules + - name: Checkout Repository and Submodules + uses: actions/checkout@v2 + with: + submodules: recursive - - name: Install Dependencies - run: sudo apt install clang-tidy + - name: Install Dependencies + run: sudo apt install clang-tidy - - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + - name: Configure CMake + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - - name: Run Clang Tidy - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -t clang-tidy + - name: Run Clang Tidy + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -t clang-tidy Compile-Examples: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v2 - - uses: ./.github/actions/submodules + - name: Checkout Repository and Submodules + uses: actions/checkout@v2 + with: + submodules: recursive - - name: Install Dependencies - run: sudo apt install gcc-arm-none-eabi + - name: Install Dependencies + run: sudo apt install gcc-arm-none-eabi - - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER=arm-none-eabi-gcc -DCMAKE_CXX_COMPILER=arm-none-eabi-g++ -DCMAKE_C_FLAGS="-Werror" -DCMAKE_CXX_FLAGS="-Werror" + - name: Configure CMake + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER=arm-none-eabi-gcc -DCMAKE_CXX_COMPILER=arm-none-eabi-g++ -DCMAKE_C_FLAGS="-Werror" -DCMAKE_CXX_FLAGS="-Werror" - - name: Compile Examples - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -t example-all + - name: Compile Examples + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -t example-all diff --git a/.github/workflows/Doxygen.yml b/.github/workflows/Doxygen.yml index ec27675..d70625a 100644 --- a/.github/workflows/Doxygen.yml +++ b/.github/workflows/Doxygen.yml @@ -10,29 +10,31 @@ env: jobs: Doxygen: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v2 - - uses: ./.github/actions/submodules - - - name: Install Dependencies - run: sudo apt install doxygen graphviz - - - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - - - name: Run Doxygen - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -t doxygen - - - name: Archive HTML Output - uses: actions/upload-artifact@v2 - with: - name: Doxygen - path: ${{github.workspace}}/build/doxygen/html - - - name: Deploy HTML Output - uses: peaceiris/actions-gh-pages@v3 - if: ${{ github.ref == 'refs/heads/main' }} - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ${{github.workspace}}/build/doxygen/html + - name: Checkout Repository and Submodules + uses: actions/checkout@v2 + with: + submodules: recursive + + - name: Install Dependencies + run: sudo apt install doxygen graphviz + + - name: Configure CMake + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + + - name: Run Doxygen + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -t doxygen + + - name: Archive HTML Output + uses: actions/upload-artifact@v2 + with: + name: Doxygen + path: ${{github.workspace}}/build/doxygen/html + + - name: Deploy HTML Output + uses: peaceiris/actions-gh-pages@v3 + if: ${{ github.ref == 'refs/heads/main' }} + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ${{github.workspace}}/build/doxygen/html diff --git a/CMakeLists.txt b/CMakeLists.txt index 561e6c4..3316547 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,9 +2,6 @@ cmake_minimum_required(VERSION 3.16) set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") -# CMake Modules Path -set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake") - # C++ Standard set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) @@ -18,17 +15,17 @@ add_subdirectory(${FREERTOS_CPP_PATH}) ## FreeRTOS Kernel Config ## # Include the FreeRTOS kernel and configure it for the ARM M0 port so the examples will compile. -set(FREERTOS_KERNEL_PATH ${CMAKE_CURRENT_LIST_DIR}/FreeRTOS-Kernel) -set(FREERTOS_KERNEL_PORT ARM_CM0) -set(FREERTOS_KERNEL_CONFIG ${CMAKE_CURRENT_LIST_DIR}/examples/config) -set(FREERTOS_KERNEL_HEAP_FILE heap_4) -include(FreeRTOS-Kernel) - -target_compile_options(FreeRTOS-Kernel PUBLIC +set(FREERTOS_PORT GCC_ARM_CM0 CACHE STRING \"\") +set(FREERTOS_HEAP 4) +add_library(freertos_config INTERFACE) +target_include_directories(freertos_config INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/examples/config +) +target_compile_options(freertos_config INTERFACE "-mcpu=cortex-m0" "-fno-exceptions" ) - +add_subdirectory(FreeRTOS-Kernel) ## Examples' Configuration ## add_custom_target(example-all) diff --git a/FreeRTOS-Cpp/CMakeLists.txt b/FreeRTOS-Cpp/CMakeLists.txt index 5128037..3322d8f 100644 --- a/FreeRTOS-Cpp/CMakeLists.txt +++ b/FreeRTOS-Cpp/CMakeLists.txt @@ -11,7 +11,7 @@ add_library(FreeRTOS-Cpp INTERFACE) ## Dependencies ## target_link_libraries(FreeRTOS-Cpp INTERFACE - FreeRTOS-Kernel + freertos_kernel ) ## Headers ## diff --git a/FreeRTOS-Cpp/include/FreeRTOS/EventGroups.hpp b/FreeRTOS-Cpp/include/FreeRTOS/EventGroups.hpp index 6aa7a1b..ea283de 100644 --- a/FreeRTOS-Cpp/include/FreeRTOS/EventGroups.hpp +++ b/FreeRTOS-Cpp/include/FreeRTOS/EventGroups.hpp @@ -33,6 +33,8 @@ #include "FreeRTOS.h" #include "event_groups.h" +#if (configUSE_EVENT_GROUPS == 1) + namespace FreeRTOS { /** @@ -52,13 +54,24 @@ class EventGroupBase { EventGroupBase(const EventGroupBase&) = delete; EventGroupBase& operator=(const EventGroupBase&) = delete; - static void* operator new(size_t, void* ptr) { return ptr; } - static void* operator new[](size_t, void* ptr) { return ptr; } static void* operator new(size_t) = delete; static void* operator new[](size_t) = delete; - // NOLINTNEXTLINE - using EventBits = std::bitset<((configUSE_16_BIT_TICKS == 1) ? 8 : 24)>; + static void* operator new(size_t, void* ptr) { + return ptr; + } + + static void* operator new[](size_t, void* ptr) { + return ptr; + } + +#if (configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_16_BITS) + using EventBits = std::bitset<8>; // NOLINT +#elif (configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_32_BITS) + using EventBits = std::bitset<24>; // NOLINT +#elif (configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_64_BITS) + using EventBits = std::bitset<56>; // NOLINT +#endif /** * EventGroups.hpp @@ -70,7 +83,9 @@ class EventGroupBase { * @retval true the handle is not NULL. * @retval false the handle is NULL. */ - inline bool isValid() const { return (handle != NULL); } + inline bool isValid() const { + return (handle != NULL); + } /** * EventGroups.hpp @@ -216,8 +231,8 @@ class EventGroupBase { inline bool setFromISR(bool& higherPriorityTaskWoken, const EventBits& bitsToSet) const { BaseType_t taskWoken = pdFALSE; - bool result = (xEventGroupSetBitsFromISR(handle, bitsToSet.to_ulong(), - &taskWoken) == pdPASS); + const bool result = (xEventGroupSetBitsFromISR(handle, bitsToSet.to_ulong(), + &taskWoken) == pdPASS); if (taskWoken == pdTRUE) { higherPriorityTaskWoken = true; } @@ -306,7 +321,9 @@ class EventGroupBase { * @return EventBits The value of the event bits in the event group at the * time get() was called. */ - inline EventBits get() const { return EventBits(xEventGroupGetBits(handle)); } + inline EventBits get() const { + return EventBits(xEventGroupGetBits(handle)); + } /** * EventGroups.hpp @@ -392,7 +409,9 @@ class EventGroupBase { * Tasks that are blocked on the event group being deleted will be unblocked, * and report an event group value of 0. */ - ~EventGroupBase() { vEventGroupDelete(this->handle); }; + ~EventGroupBase() { + vEventGroupDelete(this->handle); + }; EventGroupBase(EventGroupBase&&) noexcept = default; EventGroupBase& operator=(EventGroupBase&&) noexcept = default; @@ -436,7 +455,9 @@ class EventGroup : public EventGroupBase { * Example Usage * @include EventGroups/eventGroup.cpp */ - EventGroup() { this->handle = xEventGroupCreate(); } + EventGroup() { + this->handle = xEventGroupCreate(); + } ~EventGroup() = default; EventGroup(const EventGroup&) = delete; @@ -500,4 +521,6 @@ class StaticEventGroup : public EventGroupBase { } // namespace FreeRTOS +#endif /* configUSE_EVENT_GROUPS */ + #endif // FREERTOS_EVENTGROUPS_HPP diff --git a/FreeRTOS-Cpp/include/FreeRTOS/Kernel.hpp b/FreeRTOS-Cpp/include/FreeRTOS/Kernel.hpp index 49eaa0c..67db8db 100644 --- a/FreeRTOS-Cpp/include/FreeRTOS/Kernel.hpp +++ b/FreeRTOS-Cpp/include/FreeRTOS/Kernel.hpp @@ -81,7 +81,9 @@ inline SchedulerState getSchedulerState() { * task that has been deleted but not yet freed by the idle task will also be * included in the count. */ -inline UBaseType_t getNumberOfTasks() { return uxTaskGetNumberOfTasks(); } +inline UBaseType_t getNumberOfTasks() { + return uxTaskGetNumberOfTasks(); +} #if (INCLUDE_xTaskGetIdleTaskHandle == 1 && configGENERATE_RUN_TIME_STATS == 1) /** @@ -119,7 +121,9 @@ inline TickType_t getIdleRunTimeCounter() { * @retval TickType_t The count of ticks since * FreeRTOS::Kernel::startScheduler() was called. */ -inline TickType_t getTickCount() { return xTaskGetTickCount(); } +inline TickType_t getTickCount() { + return xTaskGetTickCount(); +} /** * Kernel.hpp @@ -136,7 +140,9 @@ inline TickType_t getTickCount() { return xTaskGetTickCount(); } * microcontroller being used or interrupt nesting is either not supported or * not being used. */ -inline TickType_t getTickCountFromISR() { return xTaskGetTickCountFromISR(); } +inline TickType_t getTickCountFromISR() { + return xTaskGetTickCountFromISR(); +} /** *Kernel.hpp @@ -150,7 +156,9 @@ inline TickType_t getTickCountFromISR() { return xTaskGetTickCountFromISR(); } *the task that calls FreeRTOS::Kernel::yield() then the RTOS scheduler will *simply select the task that called FreeRTOS::Kernel::yield() to run again. */ -inline void yield() { taskYIELD(); } +inline void yield() { + taskYIELD(); +} /** * Kernel.hpp @@ -168,7 +176,9 @@ inline void yield() { taskYIELD(); } * Example Usage * @include Kernel/enterExitCritical.cpp */ -inline void enterCritical() { taskENTER_CRITICAL(); } +inline void enterCritical() { + taskENTER_CRITICAL(); +} /** * Kernel.hpp @@ -192,7 +202,9 @@ inline void enterCritical() { taskENTER_CRITICAL(); } * Example Usage * @include Kernel/enterExitCriticalFromISR.cpp */ -inline uint32_t enterCriticalFromISR() { return taskENTER_CRITICAL_FROM_ISR(); } +inline uint32_t enterCriticalFromISR() { + return taskENTER_CRITICAL_FROM_ISR(); +} /** * Kernel.hpp @@ -210,7 +222,9 @@ inline uint32_t enterCriticalFromISR() { return taskENTER_CRITICAL_FROM_ISR(); } * Example Usage * @include Kernel/enterExitCritical.cpp */ -inline void exitCritical() { taskEXIT_CRITICAL(); } +inline void exitCritical() { + taskEXIT_CRITICAL(); +} /** * Kernel.hpp @@ -246,7 +260,9 @@ inline void exitCriticalFromISR(const uint32_t interruptStatus) { * * Function to disable all maskable interrupts. */ -inline void disableInterrupts() { taskDISABLE_INTERRUPTS(); } +inline void disableInterrupts() { + taskDISABLE_INTERRUPTS(); +} /** * Kernel.hpp @@ -257,7 +273,9 @@ inline void disableInterrupts() { taskDISABLE_INTERRUPTS(); } * * Function to enable microcontroller interrupts. */ -inline void enableInterrupts() { taskENABLE_INTERRUPTS(); } +inline void enableInterrupts() { + taskENABLE_INTERRUPTS(); +} /** * Kernel.hpp @@ -272,7 +290,9 @@ inline void enableInterrupts() { taskENABLE_INTERRUPTS(); } * Example Usage * @include Kernel/startScheduler.cpp */ -inline void startScheduler() { vTaskStartScheduler(); } +inline void startScheduler() { + vTaskStartScheduler(); +} /** * Kernel.hpp @@ -305,7 +325,9 @@ inline void startScheduler() { vTaskStartScheduler(); } * Example Usage * @include Kernel/endScheduler.cpp */ -inline void endScheduler() { vTaskEndScheduler(); } +inline void endScheduler() { + vTaskEndScheduler(); +} /** * Kernel.hpp @@ -328,7 +350,9 @@ inline void endScheduler() { vTaskEndScheduler(); } * Example Usage * @include Kernel/suspendAll.cpp */ -inline void suspendAll() { vTaskSuspendAll(); } +inline void suspendAll() { + vTaskSuspendAll(); +} /** * Kernel.hpp @@ -350,7 +374,9 @@ inline void suspendAll() { vTaskSuspendAll(); } * Example Usage * @include Kernel/resumeAll.cpp */ -inline bool resumeAll() { return (xTaskResumeAll() == pdTRUE); } +inline bool resumeAll() { + return (xTaskResumeAll() == pdTRUE); +} #if (configUSE_TICKLESS_IDLE != 0) /** diff --git a/FreeRTOS-Cpp/include/FreeRTOS/MessageBuffer.hpp b/FreeRTOS-Cpp/include/FreeRTOS/MessageBuffer.hpp index 0e9fdad..ff6a8ba 100644 --- a/FreeRTOS-Cpp/include/FreeRTOS/MessageBuffer.hpp +++ b/FreeRTOS-Cpp/include/FreeRTOS/MessageBuffer.hpp @@ -65,11 +65,17 @@ class MessageBufferBase { MessageBufferBase(const MessageBufferBase&) = delete; MessageBufferBase& operator=(const MessageBufferBase&) = delete; - static void* operator new(size_t, void* ptr) { return ptr; } - static void* operator new[](size_t, void* ptr) { return ptr; } static void* operator new(size_t) = delete; static void* operator new[](size_t) = delete; + static void* operator new(size_t, void* ptr) { + return ptr; + } + + static void* operator new[](size_t, void* ptr) { + return ptr; + } + /** * MessageBuffer.hpp * @@ -80,7 +86,9 @@ class MessageBufferBase { * @retval true If the handle is not NULL. * @retval false If the handle is NULL. */ - inline bool isValid() const { return (handle != NULL); } + inline bool isValid() const { + return (handle != NULL); + } /** * MessageBuffer.hpp @@ -178,7 +186,8 @@ class MessageBufferBase { inline size_t sendFromISR(bool& higherPriorityTaskWoken, const void* data, const size_t length) const { BaseType_t taskWoken = pdFALSE; - size_t result = xMessageBufferSendFromISR(handle, data, length, &taskWoken); + const size_t result = + xMessageBufferSendFromISR(handle, data, length, &taskWoken); if (taskWoken == pdTRUE) { higherPriorityTaskWoken = true; } @@ -284,7 +293,7 @@ class MessageBufferBase { inline size_t receiveFromISR(bool& higherPriorityTaskWoken, void* buffer, const size_t bufferLength) const { BaseType_t taskWoken = pdFALSE; - size_t result = + const size_t result = xMessageBufferReceiveFromISR(handle, buffer, bufferLength, &taskWoken); if (taskWoken == pdTRUE) { higherPriorityTaskWoken = true; @@ -348,7 +357,9 @@ class MessageBufferBase { * @retval false If there was a task blocked waiting to send to or read from * the message buffer then the message buffer will not be reset. */ - inline bool reset() const { return (xMessageBufferReset(handle) == pdPASS); } + inline bool reset() const { + return (xMessageBufferReset(handle) == pdPASS); + } /** * MessageBuffer.hpp @@ -401,7 +412,9 @@ class MessageBufferBase { * Delete a queue - freeing all the memory allocated for storing of items * placed on the queue. */ - ~MessageBufferBase() { vMessageBufferDelete(this->handle); } + ~MessageBufferBase() { + vMessageBufferDelete(this->handle); + } MessageBufferBase(MessageBufferBase&&) noexcept = default; MessageBufferBase& operator=(MessageBufferBase&&) noexcept = default; diff --git a/FreeRTOS-Cpp/include/FreeRTOS/Mutex.hpp b/FreeRTOS-Cpp/include/FreeRTOS/Mutex.hpp index e045324..17f4c8c 100644 --- a/FreeRTOS-Cpp/include/FreeRTOS/Mutex.hpp +++ b/FreeRTOS-Cpp/include/FreeRTOS/Mutex.hpp @@ -55,11 +55,17 @@ class MutexBase { MutexBase(const MutexBase&) = delete; MutexBase& operator=(const MutexBase&) = delete; - static void* operator new(size_t, void* ptr) { return ptr; } - static void* operator new[](size_t, void* ptr) { return ptr; } static void* operator new(size_t) = delete; static void* operator new[](size_t) = delete; + static void* operator new(size_t, void* ptr) { + return ptr; + } + + static void* operator new[](size_t, void* ptr) { + return ptr; + } + /** * Mutex.hpp * @@ -69,7 +75,9 @@ class MutexBase { * @retval true the handle is not NULL. * @retval false the handle is NULL. */ - inline bool isValid() const { return (handle != NULL); } + inline bool isValid() const { + return (handle != NULL); + } /** * Mutex.hpp @@ -114,7 +122,7 @@ class MutexBase { */ inline bool lockFromISR(bool& higherPriorityTaskWoken) const { BaseType_t taskWoken = pdFALSE; - bool result = (xSemaphoreTakeFromISR(handle, &taskWoken) == pdTRUE); + const bool result = (xSemaphoreTakeFromISR(handle, &taskWoken) == pdTRUE); if (taskWoken == pdTRUE) { higherPriorityTaskWoken = true; } @@ -153,7 +161,9 @@ class MutexBase { * Example Usage * @include Mutex/unlock.cpp */ - inline bool unlock() const { return (xSemaphoreGive(handle) == pdTRUE); } + inline bool unlock() const { + return (xSemaphoreGive(handle) == pdTRUE); + } private: MutexBase() = default; @@ -169,7 +179,9 @@ class MutexBase { * @note Do not delete a mutex that has tasks blocked on it (tasks that are in * the Blocked state waiting for the mutex to become available). */ - ~MutexBase() { vSemaphoreDelete(this->handle); } + ~MutexBase() { + vSemaphoreDelete(this->handle); + } MutexBase(MutexBase&&) noexcept = default; MutexBase& operator=(MutexBase&&) noexcept = default; @@ -305,7 +317,9 @@ class Mutex : public MutexBase { * Example Usage * @include Mutex/mutex.cpp */ - Mutex() { this->handle = xSemaphoreCreateMutex(); } + Mutex() { + this->handle = xSemaphoreCreateMutex(); + } ~Mutex() = default; Mutex(const Mutex&) = delete; @@ -358,7 +372,9 @@ class RecursiveMutex : public RecursiveMutexBase { * Example Usage * @include Mutex/recursiveMutex.cpp */ - RecursiveMutex() { this->handle = xSemaphoreCreateRecursiveMutex(); } + RecursiveMutex() { + this->handle = xSemaphoreCreateRecursiveMutex(); + } ~RecursiveMutex() = default; RecursiveMutex(const RecursiveMutex&) = delete; @@ -416,7 +432,9 @@ class StaticMutex : public MutexBase { * Example Usage * @include Mutex/staticMutex.cpp */ - StaticMutex() { this->handle = xSemaphoreCreateMutexStatic(&staticMutex); } + StaticMutex() { + this->handle = xSemaphoreCreateMutexStatic(&staticMutex); + } ~StaticMutex() = default; StaticMutex(const StaticMutex&) = delete; diff --git a/FreeRTOS-Cpp/include/FreeRTOS/Queue.hpp b/FreeRTOS-Cpp/include/FreeRTOS/Queue.hpp index fe6cc31..4244732 100644 --- a/FreeRTOS-Cpp/include/FreeRTOS/Queue.hpp +++ b/FreeRTOS-Cpp/include/FreeRTOS/Queue.hpp @@ -58,11 +58,17 @@ class QueueBase { QueueBase(const QueueBase&) = delete; QueueBase& operator=(const QueueBase&) = delete; - static void* operator new(size_t, void* ptr) { return ptr; } - static void* operator new[](size_t, void* ptr) { return ptr; } static void* operator new(size_t) = delete; static void* operator new[](size_t) = delete; + static void* operator new(size_t, void* ptr) { + return ptr; + } + + static void* operator new[](size_t, void* ptr) { + return ptr; + } + /** * Queue.hpp * @@ -72,7 +78,9 @@ class QueueBase { * @retval true the handle is not NULL. * @retval false the handle is NULL. */ - inline bool isValid() const { return (handle != NULL); } + inline bool isValid() const { + return (handle != NULL); + } /** * Queue.hpp @@ -355,7 +363,9 @@ class QueueBase { * * Resets a queue to its original empty state. */ - inline void reset() const { xQueueReset(handle); } + inline void reset() const { + xQueueReset(handle); + } /** * Queue.hpp @@ -379,7 +389,9 @@ class QueueBase { * Example Usage * @include Queue/overwrite.cpp */ - inline void overwrite(const T& item) const { xQueueOverwrite(handle, &item); } + inline void overwrite(const T& item) const { + xQueueOverwrite(handle, &item); + } /** * Queue.hpp @@ -542,7 +554,9 @@ class QueueBase { * semaphore or mutex from the register. If you are not using a kernel aware * debugger then this function can be ignored. */ - inline void unregister() const { vQueueUnregisterQueue(handle); } + inline void unregister() const { + vQueueUnregisterQueue(handle); + } /** * Queue.hpp @@ -559,7 +573,9 @@ class QueueBase { * @return If the queue referenced by the queue is in the queue registry, then * the text name of the queue is returned, otherwise NULL is returned. */ - inline const char* getName() const { return pcQueueGetName(handle); } + inline const char* getName() const { + return pcQueueGetName(handle); + } /** * Queue.hpp @@ -620,7 +636,9 @@ class QueueBase { * Delete a queue - freeing all the memory allocated for storing of items * placed on the queue. */ - ~QueueBase() { vQueueDelete(this->handle); } + ~QueueBase() { + vQueueDelete(this->handle); + } QueueBase(QueueBase&&) noexcept = default; QueueBase& operator=(QueueBase&&) noexcept = default; diff --git a/FreeRTOS-Cpp/include/FreeRTOS/Semaphore.hpp b/FreeRTOS-Cpp/include/FreeRTOS/Semaphore.hpp index 63d7bfa..bfcd429 100644 --- a/FreeRTOS-Cpp/include/FreeRTOS/Semaphore.hpp +++ b/FreeRTOS-Cpp/include/FreeRTOS/Semaphore.hpp @@ -54,11 +54,17 @@ class SemaphoreBase { SemaphoreBase(const SemaphoreBase&) = delete; SemaphoreBase& operator=(const SemaphoreBase&) = delete; - static void* operator new(size_t, void* ptr) { return ptr; } - static void* operator new[](size_t, void* ptr) { return ptr; } static void* operator new(size_t) = delete; static void* operator new[](size_t) = delete; + static void* operator new(size_t, void* ptr) { + return ptr; + } + + static void* operator new[](size_t, void* ptr) { + return ptr; + } + /** * Semaphore.hpp * @@ -68,7 +74,9 @@ class SemaphoreBase { * @retval true the handle is not NULL. * @retval false the handle is NULL. */ - inline bool isValid() const { return (handle != NULL); } + inline bool isValid() const { + return (handle != NULL); + } /** * Semaphore.hpp @@ -85,7 +93,9 @@ class SemaphoreBase { * semaphore then 1 is returned if the semaphore is available, and 0 is * returned if the semaphore is not available. */ - inline UBaseType_t getCount() const { return uxSemaphoreGetCount(handle); } + inline UBaseType_t getCount() const { + return uxSemaphoreGetCount(handle); + } /** * Semaphore.hpp @@ -147,7 +157,7 @@ class SemaphoreBase { */ inline bool takeFromISR(bool& higherPriorityTaskWoken) const { BaseType_t taskWoken = pdFALSE; - bool result = (xSemaphoreTakeFromISR(handle, &taskWoken) == pdTRUE); + const bool result = (xSemaphoreTakeFromISR(handle, &taskWoken) == pdTRUE); if (taskWoken == pdTRUE) { higherPriorityTaskWoken = true; } @@ -189,7 +199,9 @@ class SemaphoreBase { * Example Usage * @include Semaphore/give.cpp */ - inline bool give() const { return (xSemaphoreGive(handle) == pdTRUE); } + inline bool give() const { + return (xSemaphoreGive(handle) == pdTRUE); + } /** * Semaphore.hpp @@ -216,7 +228,7 @@ class SemaphoreBase { */ inline bool giveFromISR(bool& higherPriorityTaskWoken) const { BaseType_t taskWoken = pdFALSE; - bool result = (xSemaphoreGiveFromISR(handle, &taskWoken) == pdTRUE); + const bool result = (xSemaphoreGiveFromISR(handle, &taskWoken) == pdTRUE); if (taskWoken == pdTRUE) { higherPriorityTaskWoken = true; } @@ -251,7 +263,9 @@ class SemaphoreBase { * @note Do not delete a semaphore that has tasks blocked on it (tasks that * are in the Blocked state waiting for the semaphore to become available). */ - ~SemaphoreBase() { vSemaphoreDelete(this->handle); } + ~SemaphoreBase() { + vSemaphoreDelete(this->handle); + } SemaphoreBase(SemaphoreBase&&) noexcept = default; SemaphoreBase& operator=(SemaphoreBase&&) noexcept = default; @@ -323,7 +337,9 @@ class BinarySemaphore : public SemaphoreBase { * Example Usage * @include Semaphore/binarySemaphore.cpp */ - BinarySemaphore() { this->handle = xSemaphoreCreateBinary(); } + BinarySemaphore() { + this->handle = xSemaphoreCreateBinary(); + } ~BinarySemaphore() = default; BinarySemaphore(const BinarySemaphore&) = delete; diff --git a/FreeRTOS-Cpp/include/FreeRTOS/StreamBuffer.hpp b/FreeRTOS-Cpp/include/FreeRTOS/StreamBuffer.hpp index c87a734..ebae9b9 100644 --- a/FreeRTOS-Cpp/include/FreeRTOS/StreamBuffer.hpp +++ b/FreeRTOS-Cpp/include/FreeRTOS/StreamBuffer.hpp @@ -31,6 +31,8 @@ #include "FreeRTOS.h" #include "stream_buffer.h" +#if (configUSE_STREAM_BUFFERS == 1) + namespace FreeRTOS { /** @@ -65,11 +67,17 @@ class StreamBufferBase { StreamBufferBase(const StreamBufferBase&) = delete; StreamBufferBase& operator=(const StreamBufferBase&) = delete; - static void* operator new(size_t, void* ptr) { return ptr; } - static void* operator new[](size_t, void* ptr) { return ptr; } static void* operator new(size_t) = delete; static void* operator new[](size_t) = delete; + static void* operator new(size_t, void* ptr) { + return ptr; + } + + static void* operator new[](size_t, void* ptr) { + return ptr; + } + /** * StreamBuffer.hpp * @@ -80,7 +88,9 @@ class StreamBufferBase { * @retval true If the handle is not NULL. * @retval false If the handle is NULL. */ - inline bool isValid() const { return (handle != NULL); } + inline bool isValid() const { + return (handle != NULL); + } /** * StreamBuffer.hpp @@ -166,7 +176,8 @@ class StreamBufferBase { inline size_t sendFromISR(bool& higherPriorityTaskWoken, const void* data, const size_t length) const { BaseType_t taskWoken = pdFALSE; - size_t result = xStreamBufferSendFromISR(handle, data, length, &taskWoken); + const size_t result = + xStreamBufferSendFromISR(handle, data, length, &taskWoken); if (taskWoken == pdTRUE) { higherPriorityTaskWoken = true; } @@ -273,7 +284,7 @@ class StreamBufferBase { inline size_t receiveFromISR(bool& higherPriorityTaskWoken, void* buffer, const size_t bufferLength) const { BaseType_t taskWoken = pdFALSE; - size_t result = + const size_t result = xStreamBufferReceiveFromISR(handle, buffer, bufferLength, &taskWoken); if (taskWoken == pdTRUE) { higherPriorityTaskWoken = true; @@ -382,7 +393,9 @@ class StreamBufferBase { * @return false If there was a task blocked waiting to send to or read from * the stream buffer then the stream buffer was not reset. */ - inline bool reset() const { return (xStreamBufferReset(handle) == pdPASS); } + inline bool reset() const { + return (xStreamBufferReset(handle) == pdPASS); + } /** * StreamBuffer.hpp @@ -416,7 +429,9 @@ class StreamBufferBase { * @return true If the stream buffer is full. * @return false Otherwise. */ - inline bool isFull() const { return (xStreamBufferIsFull(handle) == pdTRUE); } + inline bool isFull() const { + return (xStreamBufferIsFull(handle) == pdTRUE); + } private: StreamBufferBase() = default; @@ -431,7 +446,9 @@ class StreamBufferBase { * * Deletes a stream buffer and free the allocated memory. */ - ~StreamBufferBase() { vStreamBufferDelete(this->handle); } + ~StreamBufferBase() { + vStreamBufferDelete(this->handle); + } StreamBufferBase(StreamBufferBase&&) noexcept = default; StreamBufferBase& operator=(StreamBufferBase&&) noexcept = default; @@ -563,4 +580,6 @@ class StaticStreamBuffer : public StreamBufferBase { } // namespace FreeRTOS +#endif /* configUSE_STREAM_BUFFERS */ + #endif // FREERTOS_STREAMBUFFER_HPP \ No newline at end of file diff --git a/FreeRTOS-Cpp/include/FreeRTOS/Task.hpp b/FreeRTOS-Cpp/include/FreeRTOS/Task.hpp index ee6a887..d74fc3d 100644 --- a/FreeRTOS-Cpp/include/FreeRTOS/Task.hpp +++ b/FreeRTOS-Cpp/include/FreeRTOS/Task.hpp @@ -66,11 +66,17 @@ class TaskBase { TaskBase(const TaskBase&) = delete; TaskBase& operator=(const TaskBase&) = delete; - static void* operator new(size_t, void* ptr) { return ptr; } - static void* operator new[](size_t, void* ptr) { return ptr; } static void* operator new(size_t) = delete; static void* operator new[](size_t) = delete; + static void* operator new(size_t, void* ptr) { + return ptr; + } + + static void* operator new[](size_t, void* ptr) { + return ptr; + } + enum class State { Running = eRunning, Ready = eReady, @@ -88,8 +94,7 @@ class TaskBase { SetValueWithoutOverwrite = eSetValueWithoutOverwrite, }; - // NOLINTNEXTLINE - using NotificationBits = std::bitset<32>; + using NotificationBits = std::bitset<32>; // NOLINT /** * Task.hpp @@ -126,7 +131,9 @@ class TaskBase { * Example Usage * @include Task/getPriority.cpp */ - inline UBaseType_t getPriority() const { return uxTaskPriorityGet(handle); } + inline UBaseType_t getPriority() const { + return uxTaskPriorityGet(handle); + } #endif /* INCLUDE_uxTaskPriorityGet */ #if (INCLUDE_vTaskPrioritySet == 1) @@ -156,6 +163,45 @@ class TaskBase { } #endif /* INCLUDE_vTaskPrioritySet */ +#if ((INCLUDE_uxTaskPriorityGet == 1) && (configUSE_MUTEXES == 1)) + /** + * Task.hpp + * + * @brief Function that calls UBaseType_t uxTaskBasePriorityGet( const + * TaskHandle_t xTask ) + * + * @see + * + * + * INCLUDE_uxTaskPriorityGet and configUSE_MUTEXES must be defined as 1 for + * this function to be available. See the configuration section for more + * information. + * + * Obtain the base priority of any task. + * + * @return UBaseType_t The base priority of the task. + */ + inline UBaseType_t getBasePriority() const { + return uxTaskBasePriorityGet(handle); + } + + /** + * @brief Function that calls UBaseType_t uxTaskBasePriorityGetFromISR( + * const TaskHandle_t xTask ) + * + * INCLUDE_uxTaskPriorityGet and configUSE_MUTEXES must be defined as 1 for + * this function to be available. See the configuration section for more + * information. + * + * Obtain the base priority of any task. + * + * @return UBaseType_t The base priority of the task. + */ + inline UBaseType_t getBasePriorityFromISR() const { + return uxTaskBasePriorityGetFromISR(handle); + } +#endif /* (INCLUDE_uxTaskPriorityGet == 1) && (configUSE_MUTEXES == 1) */ + #if (INCLUDE_vTaskSuspend == 1) /** * Task.hpp @@ -178,7 +224,9 @@ class TaskBase { * Example Usage * @include Task/suspend.cpp */ - inline void suspend() const { vTaskSuspend(handle); } + inline void suspend() const { + vTaskSuspend(handle); + } /** * Task.hpp @@ -199,7 +247,9 @@ class TaskBase { * Example Usage * @include Task/resume.cpp */ - inline void resume() const { vTaskResume(handle); } + inline void resume() const { + vTaskResume(handle); + } #if (INCLUDE_xTaskResumeFromISR == 1) /** @@ -265,7 +315,9 @@ class TaskBase { * @retval true Otherwise. * @retval false If the task was not in the Blocked state. */ - inline bool abortDelay() const { return (xTaskAbortDelay(handle) == pdPASS); } + inline bool abortDelay() const { + return (xTaskAbortDelay(handle) == pdPASS); + } #endif /* INCLUDE_xTaskAbortDelay */ #if (INCLUDE_xTaskGetIdleTaskHandle == 1) @@ -391,7 +443,9 @@ class TaskBase { * @return const char* The text (human readable) name of the task. A pointer * to the subject task's name, which is a standard NULL terminated C string. */ - inline const char* getName() const { return pcTaskGetName(handle); } + inline const char* getName() const { + return pcTaskGetName(handle); + } #if (INCLUDE_xTaskGetHandle == 1) /** @@ -666,7 +720,7 @@ class TaskBase { const NotifyAction action, const NotificationBits value = 0, const UBaseType_t index = 0) const { uint32_t pulNotificationValue; - bool result = + const bool result = (xTaskNotifyAndQueryIndexed(handle, index, value.to_ulong(), static_cast(action), &pulNotificationValue) == pdPASS); @@ -752,10 +806,10 @@ class TaskBase { const NotificationBits value = 0, const UBaseType_t index = 0) const { BaseType_t taskWoken = pdFALSE; uint32_t pulNotificationValue; - bool result = (xTaskNotifyAndQueryIndexedFromISR( - handle, index, value.to_ulong(), - static_cast(action), - &pulNotificationValue, &taskWoken) == pdPASS); + const bool result = (xTaskNotifyAndQueryIndexedFromISR( + handle, index, value.to_ulong(), + static_cast(action), + &pulNotificationValue, &taskWoken) == pdPASS); if (taskWoken == pdTRUE) { higherPriorityTaskWoken = true; @@ -781,10 +835,10 @@ class TaskBase { const NotifyAction action, const NotificationBits value = 0, const UBaseType_t index = 0) const { uint32_t pulNotificationValue; - bool result = (xTaskNotifyAndQueryIndexedFromISR( - handle, index, value.to_ulong(), - static_cast(action), - &pulNotificationValue, NULL) == pdPASS); + const bool result = (xTaskNotifyAndQueryIndexedFromISR( + handle, index, value.to_ulong(), + static_cast(action), + &pulNotificationValue, NULL) == pdPASS); return std::make_pair(result, NotificationBits(pulNotificationValue)); } @@ -856,9 +910,10 @@ class TaskBase { const NotificationBits value = 0, const UBaseType_t index = 0) const { BaseType_t taskWoken = pdFALSE; - bool result = (xTaskNotifyIndexedFromISR(handle, index, value.to_ulong(), - static_cast(action), - &taskWoken) == pdPASS); + const bool result = + (xTaskNotifyIndexedFromISR(handle, index, value.to_ulong(), + static_cast(action), + &taskWoken) == pdPASS); if (taskWoken == pdTRUE) { higherPriorityTaskWoken = true; } @@ -972,7 +1027,7 @@ class TaskBase { const NotificationBits bitsToClearOnExit = 0, const UBaseType_t index = 0) { uint32_t pulNotificationValue; - bool result = + const bool result = (xTaskNotifyWaitIndexed(index, bitsToClearOnEntry.to_ulong(), bitsToClearOnExit.to_ulong(), &pulNotificationValue, ticksToWait) == pdTRUE); @@ -1336,7 +1391,9 @@ class Task : public TaskBase { * @return false If the task was not created successfully due to insufficient * memory. */ - bool isValid() const { return taskCreatedSuccessfully; } + bool isValid() const { + return taskCreatedSuccessfully; + } protected: /** diff --git a/FreeRTOS-Cpp/include/FreeRTOS/Timer.hpp b/FreeRTOS-Cpp/include/FreeRTOS/Timer.hpp index 6bc67fe..606def9 100644 --- a/FreeRTOS-Cpp/include/FreeRTOS/Timer.hpp +++ b/FreeRTOS-Cpp/include/FreeRTOS/Timer.hpp @@ -61,11 +61,17 @@ class TimerBase { TimerBase(const TimerBase&) = delete; TimerBase& operator=(const TimerBase&) = delete; - static void* operator new(size_t, void* ptr) { return ptr; } - static void* operator new[](size_t, void* ptr) { return ptr; } static void* operator new(size_t) = delete; static void* operator new[](size_t) = delete; + static void* operator new(size_t, void* ptr) { + return ptr; + } + + static void* operator new[](size_t, void* ptr) { + return ptr; + } + /** * Timer.hpp * @@ -75,7 +81,9 @@ class TimerBase { * interface function callTimerFunction() and should not be called or * referenced by the user. */ - virtual inline void timerEntry() final { timerFunction(); } + virtual inline void timerEntry() final { + timerFunction(); + } /** * Timer.hpp @@ -87,7 +95,9 @@ class TimerBase { * @return false If the timer was not created successfully due to insufficient * memory. */ - inline bool isValid() const { return (handle != NULL); } + inline bool isValid() const { + return (handle != NULL); + } /** * Timer.hpp @@ -195,7 +205,7 @@ class TimerBase { */ inline bool startFromISR(bool& higherPriorityTaskWoken) const { BaseType_t taskWoken = pdFALSE; - bool result = (xTimerStartFromISR(handle, &taskWoken) == pdPASS); + const bool result = (xTimerStartFromISR(handle, &taskWoken) == pdPASS); if (taskWoken == pdTRUE) { higherPriorityTaskWoken = true; } @@ -284,7 +294,7 @@ class TimerBase { */ inline bool stopFromISR(bool& higherPriorityTaskWoken) const { BaseType_t taskWoken = pdFALSE; - bool result = (xTimerStopFromISR(handle, &taskWoken) == pdPASS); + const bool result = (xTimerStopFromISR(handle, &taskWoken) == pdPASS); if (taskWoken == pdTRUE) { higherPriorityTaskWoken = true; } @@ -392,7 +402,7 @@ class TimerBase { inline bool changePeriodFromISR(bool& higherPriorityTaskWoken, const TickType_t newPeriod) const { BaseType_t taskWoken = pdFALSE; - bool result = + const bool result = (xTimerChangePeriodFromISR(handle, newPeriod, &taskWoken) == pdPASS); if (taskWoken == pdTRUE) { higherPriorityTaskWoken = true; @@ -536,7 +546,7 @@ class TimerBase { */ inline bool resetFromISR(bool& higherPriorityTaskWoken) const { BaseType_t taskWoken = pdFALSE; - bool result = (xTimerResetFromISR(handle, &taskWoken) == pdPASS); + const bool result = (xTimerResetFromISR(handle, &taskWoken) == pdPASS); if (taskWoken == pdTRUE) { higherPriorityTaskWoken = true; } @@ -561,7 +571,7 @@ class TimerBase { * Timer.hpp * * @brief Function that calls void vTimerSetReloadMode( TimerHandle_t - * xTimer, const UBaseType_t uxAutoReload ) + * xTimer, const UBaseType_t xAutoReload ) * * @see * @@ -599,7 +609,9 @@ class TimerBase { * Example Usage * @include Timer/getName.cpp */ - inline const char* getName() const { return pcTimerGetName(handle); } + inline const char* getName() const { + return pcTimerGetName(handle); + } /** * Timer.hpp @@ -620,7 +632,9 @@ class TimerBase { * Example Usage * @include Timer/getPeriod.cpp */ - inline TickType_t getPeriod() const { return xTimerGetPeriod(handle); } + inline TickType_t getPeriod() const { + return xTimerGetPeriod(handle); + } /** * Timer.hpp @@ -692,7 +706,9 @@ class TimerBase { * * @return TickType_t Delete block time in ticks. */ - inline TickType_t getDeleteBlockTime() const { return deleteBlockTime; } + inline TickType_t getDeleteBlockTime() const { + return deleteBlockTime; + } protected: /** @@ -770,7 +786,7 @@ class Timer : public TimerBase { * * @brief Construct a new Timer object by calling TimerHandle_t * xTimerCreate( const char * const pcTimerName, const TickType_t - * xTimerPeriod, const UBaseType_t uxAutoReload, void * const pvTimerID, + * xTimerPeriod, const UBaseType_t xAutoReload, void * const pvTimerID, * TimerCallbackFunction_t pxCallbackFunction ) * * @see @@ -860,7 +876,7 @@ class StaticTimer : public TimerBase { * * @brief Construct a new StaticTimer object by calling TimerHandle_t * xTimerCreateStatic( const char * const pcTimerName, const TickType_t - * xTimerPeriod, const UBaseType_t uxAutoReload, void * const pvTimerID, + * xTimerPeriod, const UBaseType_t xAutoReload, void * const pvTimerID, * TimerCallbackFunction_t pxCallbackFunction StaticTimer_t *pxTimerBuffer * ) * diff --git a/cmake/FreeRTOS-Kernel.cmake b/cmake/FreeRTOS-Kernel.cmake deleted file mode 100644 index 0377101..0000000 --- a/cmake/FreeRTOS-Kernel.cmake +++ /dev/null @@ -1,183 +0,0 @@ -list(APPEND CMAKE_MESSAGE_CONTEXT "FreeRTOS-Kernel") - -add_library(FreeRTOS-Kernel OBJECT) - -# Optional parameters. -option(FREERTOS_KERNEL_USE_CUSTOM_PORT "Enable the use of a custom port implementation from a different project. When enabling this option set to the path that contains port files." OFF) -option(FREERTOS_KERNEL_USE_CUSTOM_HEAP "Enable the use of a custom heap implementation from a different project. When enabling this option set to the file that implements the memory management." OFF) - -## FreeRTOS Kernel Config ## -# Check that contains FreeRTOSConfig.h -if(NOT DEFINED FREERTOS_KERNEL_CONFIG) - message(FATAL_ERROR " is undefined. Set to the path that contains FreeRTOSConfig.h.") -else() - if(NOT EXISTS "${FREERTOS_KERNEL_CONFIG}/FreeRTOSConfig.h") - message(FATAL_ERROR "FreeRTOSConfig.h not found in ${FREERTOS_KERNEL_CONFIG}. Set to the path that contains FreeRTOSConfig.h.") - endif() -endif () - - -## FreeRTOS Kernel Port ## -if(FREERTOS_KERNEL_USE_CUSTOM_PORT) - # If a custom port is being used then check that contains a valid directory. - if(NOT DEFINED FREERTOS_KERNEL_PORT) - message(FATAL_ERROR " is undefined. When using a custom port set to the path that contains the port source files.") - else() - if(NOT EXISTS ${FREERTOS_KERNEL_PORT}) - message(FATAL_ERROR "Custom port folder: ${FREERTOS_KERNEL_PORT} does not exist.") - endif() - endif() -else() - set(FREERTOS_KERNEL_PORTABLE_DIRECTORY ${FREERTOS_KERNEL_PATH}/portable) - - # Port macro header files. Most ports use portmacro.h as their header file, but some special ports use other header files. - set(FREERTOS_KERNEL_PORT_HEADER_FILES - "portmacro.h" - "secure_port_macros.h" - ) - - # Create a list of expressions to search for possible ports by prepending the portable directory. - set(FREERTOS_KERNEL_PORT_HEADER_FILES_EXPRESSION ${FREERTOS_KERNEL_PORT_HEADER_FILES}) - list(TRANSFORM FREERTOS_KERNEL_PORT_HEADER_FILES_EXPRESSION PREPEND ${FREERTOS_KERNEL_PORTABLE_DIRECTORY}/*/) - - # Get a list of all possible ports by searching for port header files the portable folder. - file(GLOB_RECURSE PORT_FILES RELATIVE ${FREERTOS_KERNEL_PORTABLE_DIRECTORY} CONFIGURE_DEPENDS ${FREERTOS_KERNEL_PORT_HEADER_FILES_EXPRESSION}) - - foreach(PORT_FILE ${PORT_FILES}) - # Get the highest level directory of the file patha and add it to the list of possible compiler ports. - string(REGEX REPLACE "(\/.*)" "" COMPILER_PORT ${PORT_FILE}) - list(APPEND COMPILER_PORTS ${COMPILER_PORT}) - list(REMOVE_DUPLICATES COMPILER_PORTS) - endforeach() - - message(VERBOSE "Available compiler ports in ${FREERTOS_KERNEL_PORTABLE_DIRECTORY} are:\r${COMPILER_PORTS}") - - if(NOT DEFINED FREERTOS_KERNEL_COMPILER_PORT) - # If the user did not specify a specific compiler port then use the compiler ID identified by CMake and set the port folder accordingly. - if(${CMAKE_C_COMPILER_ID} STREQUAL "ARMClang") - set(FREERTOS_KERNEL_COMPILER_PORT "ARMClang") - elseif(${CMAKE_C_COMPILER_ID} STREQUAL "Bruce") - set(FREERTOS_KERNEL_COMPILER_PORT "BCC") - elseif(${CMAKE_C_COMPILER_ID} STREQUAL "GNU") - set(FREERTOS_KERNEL_COMPILER_PORT "GCC") - elseif(${CMAKE_C_COMPILER_ID} STREQUAL "IAR") - set(FREERTOS_KERNEL_COMPILER_PORT "IAR") - elseif(${CMAKE_C_COMPILER_ID} STREQUAL "MSVC") - set(FREERTOS_KERNEL_COMPILER_PORT "MSVC-MingW") - elseif(${CMAKE_C_COMPILER_ID} STREQUAL "OpenWatcom") - set(FREERTOS_KERNEL_COMPILER_PORT "oWatcom") - elseif(${CMAKE_C_COMPILER_ID} STREQUAL "SDCC") - set(FREERTOS_KERNEL_COMPILER_PORT "SDCC") - else() - message(FATAL_ERROR "The C compiler identification is ${CMAKE_C_COMPILER_ID}. A port can't be identified for this compiler. Check your toolchain configuration.\n" - "Set to explicitly specify a compiler port in FreeRTOS-Kernel/portable. This may be required if CMake cannot natively identify your compiler or you would like to override the detected one.\n" - ) - endif() - message(VERBOSE "The C compiler identification is: ${CMAKE_C_COMPILER_ID}. The compiler port has been assigned to: ${FREERTOS_KERNEL_COMPILER_PORT}") - endif() - - # Check that contains a valid compiler port in the portable directory. - if(NOT FREERTOS_KERNEL_COMPILER_PORT IN_LIST COMPILER_PORTS) - message(FATAL_ERROR "${FREERTOS_KERNEL_COMPILER_PORT} is not an available compiler port. Available ports are:\r${COMPILER_PORTS}") - else() - set(FREERTOS_KERNEL_COMPILER_PORT ${FREERTOS_KERNEL_PATH}/portable/${FREERTOS_KERNEL_COMPILER_PORT}) - endif() - - # Create a list of expressions to search for possible ports by prepending the portable directory. - set(FREERTOS_KERNEL_PORT_HEADER_FILES_EXPRESSION ${FREERTOS_KERNEL_PORT_HEADER_FILES}) - list(TRANSFORM FREERTOS_KERNEL_PORT_HEADER_FILES_EXPRESSION PREPEND ${FREERTOS_KERNEL_COMPILER_PORT}/*/) - - # Get a list of all possible ports by searching for port header files the compiler port folder. - file(GLOB_RECURSE PORT_FILES RELATIVE ${FREERTOS_KERNEL_COMPILER_PORT} CONFIGURE_DEPENDS ${FREERTOS_KERNEL_PORT_HEADER_FILES_EXPRESSION}) - - foreach(PORT_FILE ${PORT_FILES}) - # Add the directory that contains portmacro.h to the list of possible ports. - get_filename_component(PORT_DIRECTORY ${PORT_FILE} DIRECTORY) - list(APPEND PORTS ${PORT_DIRECTORY}) - endforeach() - - message(VERBOSE "Available ports in ${FREERTOS_KERNEL_COMPILER_PORT} are:\r${PORTS}") - - # Check that contains a valid port in the identified compiler port directory. - if (NOT DEFINED FREERTOS_KERNEL_PORT) - message(FATAL_ERROR " is undefined. Set to the desired port. Available ports in ${FREERTOS_KERNEL_COMPILER_PORT} are:\r${PORTS}") - else() - if(NOT FREERTOS_KERNEL_PORT IN_LIST PORTS) - message(FATAL_ERROR "${FREERTOS_KERNEL_PORT} is not an available port. Available ports in ${FREERTOS_KERNEL_COMPILER_PORT} are:\r${PORTS}") - else() - set(FREERTOS_KERNEL_PORT ${FREERTOS_KERNEL_COMPILER_PORT}/${FREERTOS_KERNEL_PORT}) - endif() - endif() -endif() -message(VERBOSE "Directory for port implementation is: ${FREERTOS_KERNEL_PORT}") - -# Search the port directory for source files. -file(GLOB FREERTOS_KERNEL_PORT_SOURCES - ${FREERTOS_KERNEL_PORT}/*.asm - ${FREERTOS_KERNEL_PORT}/*.c - ${FREERTOS_KERNEL_PORT}/*.s* - ${FREERTOS_KERNEL_PORT}/*.S -) -message(VERBOSE "Source files identified for port implementation are: ${FREERTOS_KERNEL_PORT_SOURCES}") - - -## FreeRTOS Kernel Heap ## -if(FREERTOS_KERNEL_USE_CUSTOM_HEAP) - # If a custom heap is being used then check that contains a valid file. - if(NOT DEFINED FREERTOS_KERNEL_HEAP_FILE) - message(FATAL_ERROR " is undefined. Set to the file that contains the heap implementation.") - else() - if(NOT EXISTS ${FREERTOS_KERNEL_HEAP_FILE}) - message(FATAL_ERROR "Custom heap implementation file: ${FREERTOS_KERNEL_HEAP_FILE} does not exist.") - endif() - endif() -else() - # Search the memory management directory for available heap implementations. - set(FREERTOS_MEMORY_MANAGEMENT_DIRECTORY "${FREERTOS_KERNEL_PATH}/portable/MemMang") - file(GLOB HEAP_FILES RELATIVE "${FREERTOS_MEMORY_MANAGEMENT_DIRECTORY}" CONFIGURE_DEPENDS "${FREERTOS_MEMORY_MANAGEMENT_DIRECTORY}/*.c") - message(VERBOSE "Available heap files in ${FREERTOS_MEMORY_MANAGEMENT_DIRECTORY} are: ${HEAP_FILES}") - - # Check that contains a valid heap file in the memory management directory. - if(NOT DEFINED FREERTOS_KERNEL_HEAP_FILE) - message(FATAL_ERROR " is undefined. Set to the desired heap implementation. Available implementations are: ${HEAPS}") - else () - if(${FREERTOS_KERNEL_HEAP_FILE} IN_LIST HEAP_FILES) - set(FREERTOS_KERNEL_HEAP_FILE ${FREERTOS_MEMORY_MANAGEMENT_DIRECTORY}/${FREERTOS_KERNEL_HEAP_FILE}) - elseif(${FREERTOS_KERNEL_HEAP_FILE}.c IN_LIST HEAP_FILES) - set(FREERTOS_KERNEL_HEAP_FILE ${FREERTOS_MEMORY_MANAGEMENT_DIRECTORY}/${FREERTOS_KERNEL_HEAP_FILE}.c) - else() - message(FATAL_ERROR "${FREERTOS_KERNEL_HEAP_FILE} is not an available heap. Available heap files are: ${HEAP_FILES}") - endif() - endif() -endif() -message(VERBOSE "Heap implementation file is: ${FREERTOS_KERNEL_HEAP_FILE}") - - -## FreeRTOS Kernel Headers ## -target_include_directories(FreeRTOS-Kernel PUBLIC - "${FREERTOS_KERNEL_PATH}/include" - ${FREERTOS_KERNEL_CONFIG} - ${FREERTOS_KERNEL_PORT} -) - - -## FreeRTOS Kernel Sources ## -# Add core kernel source files. -target_sources(FreeRTOS-Kernel PRIVATE - "${FREERTOS_KERNEL_PATH}/croutine.c" - "${FREERTOS_KERNEL_PATH}/event_groups.c" - "${FREERTOS_KERNEL_PATH}/list.c" - "${FREERTOS_KERNEL_PATH}/queue.c" - "${FREERTOS_KERNEL_PATH}/stream_buffer.c" - "${FREERTOS_KERNEL_PATH}/tasks.c" - "${FREERTOS_KERNEL_PATH}/timers.c" -) - -# Add heap implemntation source file. -target_sources(FreeRTOS-Kernel PRIVATE ${FREERTOS_KERNEL_HEAP_FILE}) - -# Add kernel port source file(s). -target_sources(FreeRTOS-Kernel PRIVATE ${FREERTOS_KERNEL_PORT_SOURCES}) - - -list(POP_BACK CMAKE_MESSAGE_CONTEXT) diff --git a/examples/Queue/sendToBackFromISR.cpp b/examples/Queue/sendToBackFromISR.cpp index 73b4bae..2e6736c 100644 --- a/examples/Queue/sendToBackFromISR.cpp +++ b/examples/Queue/sendToBackFromISR.cpp @@ -2,8 +2,12 @@ #include // Fake interface to get data from. -char getByte() { return 'A'; } -size_t getBytesRemaining() { return 0; } +char getByte() { + return 'A'; +} +size_t getBytesRemaining() { + return 0; +} // Queue that holds 10 characters. FreeRTOS::StaticQueue rxQueue; diff --git a/examples/Queue/sendToFrontFromISR.cpp b/examples/Queue/sendToFrontFromISR.cpp index 9a19df0..10f913d 100644 --- a/examples/Queue/sendToFrontFromISR.cpp +++ b/examples/Queue/sendToFrontFromISR.cpp @@ -4,8 +4,12 @@ constexpr char emergencyMessage = 'E'; // Fake interface to get data from. -char getByte() { return 'A'; } -size_t getBytesRemaining() { return 0; } +char getByte() { + return 'A'; +} +size_t getBytesRemaining() { + return 0; +} // Queue that holds 10 characters. FreeRTOS::StaticQueue rxQueue; diff --git a/examples/Task/notifyFromISR.cpp b/examples/Task/notifyFromISR.cpp index 37ba812..9b6a23f 100644 --- a/examples/Task/notifyFromISR.cpp +++ b/examples/Task/notifyFromISR.cpp @@ -12,7 +12,9 @@ class MyTask : public FreeRTOS::Task { }; // Fake peripherial interface functions. -uint32_t ulReadPeripheralInterruptStatus() { return 0; } +uint32_t ulReadPeripheralInterruptStatus() { + return 0; +} void vClearPeripheralInterruptStatus(uint32_t ulStatusRegister) {} MyTask myTask; diff --git a/examples/Task/notifyTake.cpp b/examples/Task/notifyTake.cpp index d376d66..e27d241 100644 --- a/examples/Task/notifyTake.cpp +++ b/examples/Task/notifyTake.cpp @@ -7,7 +7,9 @@ class MyTask : public FreeRTOS::Task { }; // Fake peripherial interface functions -BaseType_t xQueryPeripheral() { return 0; } +BaseType_t xQueryPeripheral() { + return 0; +} void vProcessPeripheralEvent(BaseType_t xEvent) {} constexpr BaseType_t NO_MORE_EVENTS = 0; diff --git a/examples/config/FreeRTOSConfig.h b/examples/config/FreeRTOSConfig.h index 14f36f8..7298ede 100644 --- a/examples/config/FreeRTOSConfig.h +++ b/examples/config/FreeRTOSConfig.h @@ -92,6 +92,8 @@ #define configUSE_16_BIT_TICKS 0 #define configIDLE_SHOULD_YIELD 1 #define configUSE_TASK_NOTIFICATIONS 1 +#define configUSE_EVENT_GROUPS 1 +#define configUSE_STREAM_BUFFERS 1 #define configUSE_MUTEXES 1 #define configUSE_RECURSIVE_MUTEXES 1 #define configUSE_COUNTING_SEMAPHORES 1 @@ -160,12 +162,13 @@ #define INCLUDE_xTaskGetSchedulerState 1 #define INCLUDE_xTaskGetCurrentTaskHandle 1 #define INCLUDE_uxTaskGetStackHighWaterMark 1 -#define INCLUDE_xTaskGetIdleTaskHandle 0 -#define INCLUDE_eTaskGetState 0 +#define INCLUDE_uxTaskGetStackHighWaterMark2 1 +#define INCLUDE_xTaskGetIdleTaskHandle 1 +#define INCLUDE_eTaskGetState 1 #define INCLUDE_xEventGroupSetBitFromISR 1 #define INCLUDE_xTimerPendFunctionCall 1 -#define INCLUDE_xTaskAbortDelay 0 -#define INCLUDE_xTaskGetHandle 0 +#define INCLUDE_xTaskAbortDelay 1 +#define INCLUDE_xTaskGetHandle 1 #define INCLUDE_xTaskResumeFromISR 1 #define INCLUDE_xQueueGetMutexHolder 1