From 2dec8984fdbe29b81cbb1525136581ecaf12ff76 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sun, 19 Dec 2021 14:34:24 +0100 Subject: [PATCH 01/73] Fix library.json syntax --- library.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index 972dba8..01bf6ca 100644 --- a/library.json +++ b/library.json @@ -24,11 +24,11 @@ "export": { "exclude": [ ".github", - "dev" + "dev", "docs", "**/.vs", "**/Debug", - "build", + "build" ] } } \ No newline at end of file From 1fd1b3e8a1bbb97e69c94e21fb02b7dccbce1baa Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Thu, 23 Dec 2021 20:46:21 +0100 Subject: [PATCH 02/73] Add system ThreadX support --- lwmem/src/system/lwmem_sys_threadx.c | 69 ++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 lwmem/src/system/lwmem_sys_threadx.c diff --git a/lwmem/src/system/lwmem_sys_threadx.c b/lwmem/src/system/lwmem_sys_threadx.c new file mode 100644 index 0000000..0aa2cd0 --- /dev/null +++ b/lwmem/src/system/lwmem_sys_threadx.c @@ -0,0 +1,69 @@ +/** + * \file lwmem_sys_cmsis_os.c + * \brief System functions for CMSIS-OS based operating system + */ + +/* + * Copyright (c) 2020 Tilen MAJERLE + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * This file is part of LwMEM - Lightweight dynamic memory manager library. + * + * Author: Tilen MAJERLE + * Version: v2.0.0 + */ +#include "system/lwmem_sys.h" + +#if LWMEM_CFG_OS && !__DOXYGEN__ + +/* + * To use this module, options must be defined as + * + * #define LWMEM_CFG_OS_MUTEX_HANDLE TX_MUTEX + */ + +/* Include ThreadX API module */ +#include "tx_api.h" +#include "tx_mutex.h" + +uint8_t +lwmem_sys_mutex_create(LWMEM_CFG_OS_MUTEX_HANDLE* m) { + static char name[] = "lwmem_mutex"; + return tx_mutex_create(m, name, TX_INHERIT) == TX_SUCCESS; +} + +uint8_t +lwmem_sys_mutex_isvalid(LWMEM_CFG_OS_MUTEX_HANDLE* m) { + return m->tx_mutex_id == TX_MUTEX_ID; +} + +uint8_t +lwmem_sys_mutex_wait(LWMEM_CFG_OS_MUTEX_HANDLE* m) { + return tx_mutex_get(m, TX_WAIT_FOREVER) == TX_SUCCESS; +} + +uint8_t +lwmem_sys_mutex_release(LWMEM_CFG_OS_MUTEX_HANDLE* m) { + return tx_mutex_put(m) == TX_SUCCESS; +} + +#endif /* LWMEM_CFG_OS && !__DOXYGEN__ */ From 459c588ddef1e9c5e823576e032144da6eaa0f77 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Thu, 23 Dec 2021 22:23:39 +0100 Subject: [PATCH 03/73] Add test sub-cmake --- CMakeLists.txt | 23 +++++++++++------------ lwmem/CMakeLists.txt | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 lwmem/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ed7aec..f56aa93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,19 +1,19 @@ cmake_minimum_required(VERSION 3.0.0) + +# Setup project project(LwLibPROJECT VERSION 0.1.0) -include(CTest) -enable_testing() +# Add executable and library +add_executable(${PROJECT_NAME}) -add_executable(${PROJECT_NAME} - lwmem/src/lwmem/lwmem.c - lwmem/src/system/lwmem_sys_win32.c - tests/lwmem_test.c - dev/VisualStudio/main.c +# Add key executable block +target_sources(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c + ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio/main.c ) target_include_directories(${PROJECT_NAME} PRIVATE - dev/VisualStudio - lwmem/src/include + ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio ) target_compile_definitions(${PROJECT_NAME} PRIVATE @@ -23,6 +23,5 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE LWMEM_DEV ) -set(CPACK_PROJECT_NAME ${PROJECT_NAME}) -set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) -include(CPack) +# Go to sub directory +add_subdirectory(lwmem) diff --git a/lwmem/CMakeLists.txt b/lwmem/CMakeLists.txt new file mode 100644 index 0000000..17df494 --- /dev/null +++ b/lwmem/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.0.0) + +# Check definitions of some key things +if(NOT DEFINED LWMEM_SYS_ARCH) + message("Warning: LWMEM_SYS_ARCH not defined. Using default one as \"win32\"") + set(LWMEM_SYS_ARCH "win32") +endif() + +# Add source files +target_sources(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.c + ${CMAKE_CURRENT_LIST_DIR}/src/system/lwmem_sys_${LWMEM_SYS_ARCH}.c + ) + +# Add include files +target_include_directories(${PROJECT_NAME} PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/src/include + ) From 62d0c40f015e6afd165cc7adadde794d71b90750 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 24 Dec 2021 11:36:53 +0100 Subject: [PATCH 04/73] Allow cmakelists to be invoked as demo project or used by 3rd party as a library --- CMakeLists.txt | 45 +++++++++++++++++++++++++------------------- lwmem/CMakeLists.txt | 23 +++++++++++++++------- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f56aa93..fdc1cc2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,27 +1,34 @@ cmake_minimum_required(VERSION 3.0.0) # Setup project -project(LwLibPROJECT VERSION 0.1.0) +project(LwMEM VERSION 2.0.1) +set(LWMEM_LIB_NAME lwmem) -# Add executable and library -add_executable(${PROJECT_NAME}) +# ------------------------ +# Configuration used if this is used as +# top-level project CMakeLists.txt file +# This is normally used for development purpose only +if (PROJECT_IS_TOP_LEVEL) + add_executable(${PROJECT_NAME}) -# Add key executable block -target_sources(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c - ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio/main.c - ) + # Add key executable block + target_sources(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio/main.c + ${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c + ) -target_include_directories(${PROJECT_NAME} PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio - ) + target_include_directories(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio + ) -target_compile_definitions(${PROJECT_NAME} PRIVATE - WIN32 - _DEBUG - CONSOLE - LWMEM_DEV - ) + target_compile_definitions(${PROJECT_NAME} PUBLIC + WIN32 + _DEBUG + CONSOLE + LWMEM_DEV + ) +endif() -# Go to sub directory -add_subdirectory(lwmem) +# Add subdir with lwmem and link to the project +add_subdirectory("lwmem") +target_link_libraries(${PROJECT_NAME} lwmem) \ No newline at end of file diff --git a/lwmem/CMakeLists.txt b/lwmem/CMakeLists.txt index 17df494..c879856 100644 --- a/lwmem/CMakeLists.txt +++ b/lwmem/CMakeLists.txt @@ -1,18 +1,27 @@ -cmake_minimum_required(VERSION 3.0.0) +cmake_minimum_required(VERSION 3.13) + +# Debug message +message("LWMEM: Entering lib source CMakeLists.txt") + +# Set library name +set(LWMEM_LIB_NAME "lwmem") # Check definitions of some key things if(NOT DEFINED LWMEM_SYS_ARCH) - message("Warning: LWMEM_SYS_ARCH not defined. Using default one as \"win32\"") + message("LWMEM: LWMEM_SYS_ARCH not defined. Using default one: \"win32\"") set(LWMEM_SYS_ARCH "win32") endif() -# Add source files -target_sources(${PROJECT_NAME} PUBLIC +# Register library to the system +add_library(${LWMEM_LIB_NAME} INTERFACE) + +# Setup generic source files +target_sources(${LWMEM_LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.c ${CMAKE_CURRENT_LIST_DIR}/src/system/lwmem_sys_${LWMEM_SYS_ARCH}.c ) -# Add include files -target_include_directories(${PROJECT_NAME} PRIVATE +# Setup include directories +target_include_directories(${LWMEM_LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/include - ) + ) \ No newline at end of file From cbc215be11c7eea657537a4b920448885ec02bda Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 24 Dec 2021 13:21:32 +0100 Subject: [PATCH 05/73] Update cmake to allow generation as lib or standalone --- CMakeLists.txt | 1 - lwmem/CMakeLists.txt | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fdc1cc2..4ed276e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.0.0) # Setup project project(LwMEM VERSION 2.0.1) -set(LWMEM_LIB_NAME lwmem) # ------------------------ # Configuration used if this is used as diff --git a/lwmem/CMakeLists.txt b/lwmem/CMakeLists.txt index c879856..0c87659 100644 --- a/lwmem/CMakeLists.txt +++ b/lwmem/CMakeLists.txt @@ -16,7 +16,7 @@ endif() add_library(${LWMEM_LIB_NAME} INTERFACE) # Setup generic source files -target_sources(${LWMEM_LIB_NAME} INTERFACE +target_sources(${LWMEM_LIB_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.c ${CMAKE_CURRENT_LIST_DIR}/src/system/lwmem_sys_${LWMEM_SYS_ARCH}.c ) @@ -24,4 +24,4 @@ target_sources(${LWMEM_LIB_NAME} INTERFACE # Setup include directories target_include_directories(${LWMEM_LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/include - ) \ No newline at end of file + ) From d9f91da6df19de7a6e7f9704954350590979a602 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 24 Dec 2021 14:01:17 +0100 Subject: [PATCH 06/73] Update cmake --- .vscode/launch.json | 2 +- .vscode/tasks.json | 2 +- CMakeLists.txt | 12 +++++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 8b95413..214334d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "name": "(Windows) Launch", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}\\build\\LwLibPROJECT.exe", + "program": "${workspaceFolder}\\build\\LwMEM.exe", "miDebuggerPath": "c:\\msys64\\mingw64\\bin\\gdb.exe", "args": [], "stopAtEntry": false, diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 309d100..26e109d 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -46,7 +46,7 @@ { "type": "shell", "label": "Run application", - "command": "${workspaceFolder}\\build\\LwLibPROJECT.exe", + "command": "${workspaceFolder}\\build\\LwMEM.exe", "args": [], "problemMatcher": [], }, diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ed276e..3655abf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.0.0) project(LwMEM VERSION 2.0.1) # ------------------------ -# Configuration used if this is used as +# Configuration used if cmake uses this as # top-level project CMakeLists.txt file # This is normally used for development purpose only if (PROJECT_IS_TOP_LEVEL) @@ -26,8 +26,10 @@ if (PROJECT_IS_TOP_LEVEL) CONSOLE LWMEM_DEV ) -endif() -# Add subdir with lwmem and link to the project -add_subdirectory("lwmem") -target_link_libraries(${PROJECT_NAME} lwmem) \ No newline at end of file + # Add subdir with lwmem and link to the project + add_subdirectory("lwmem") + target_link_libraries(${PROJECT_NAME} lwmem) +else() + message("LWMEM: For library link, use CMakeLists.txt in /lwmem directory") +endif() \ No newline at end of file From 54c9c1c07cd17cc339d2a515db2ed6bf162ef21c Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 24 Dec 2021 15:19:24 +0100 Subject: [PATCH 07/73] Update cmake --- .vscode/launch.json | 2 +- .vscode/tasks.json | 2 +- CMakeLists.txt | 60 +++++++++++++++++++++++++-------------------- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 214334d..8b95413 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "name": "(Windows) Launch", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}\\build\\LwMEM.exe", + "program": "${workspaceFolder}\\build\\LwLibPROJECT.exe", "miDebuggerPath": "c:\\msys64\\mingw64\\bin\\gdb.exe", "args": [], "stopAtEntry": false, diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 26e109d..309d100 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -46,7 +46,7 @@ { "type": "shell", "label": "Run application", - "command": "${workspaceFolder}\\build\\LwMEM.exe", + "command": "${workspaceFolder}\\build\\LwLibPROJECT.exe", "args": [], "problemMatcher": [], }, diff --git a/CMakeLists.txt b/CMakeLists.txt index 3655abf..287367b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,35 +1,41 @@ cmake_minimum_required(VERSION 3.0.0) # Setup project -project(LwMEM VERSION 2.0.1) +project(LwLibPROJECT VERSION 2.0.1) -# ------------------------ -# Configuration used if cmake uses this as -# top-level project CMakeLists.txt file -# This is normally used for development purpose only -if (PROJECT_IS_TOP_LEVEL) - add_executable(${PROJECT_NAME}) +# ------------------------------------------------- +# This CMakeLists.txt is used only if it is a top-level file. +# Purpose of it is to be able to compile project in standalone way only +# +# When library sources are to be included in another project +# user shall use /lwmem/CMakeLists.txt instead +if (NOT PROJECT_IS_TOP_LEVEL) + message(FATAL_ERROR "This CMakeLists.txt can only be used as top-level. Use /lwmem/CMakeLists.txt for library include purpose") +endif() - # Add key executable block - target_sources(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio/main.c - ${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c - ) +# Set as executable +add_executable(${PROJECT_NAME}) - target_include_directories(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio - ) +# Add key executable block +target_sources(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio/main.c + ${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c + ) - target_compile_definitions(${PROJECT_NAME} PUBLIC - WIN32 - _DEBUG - CONSOLE - LWMEM_DEV - ) +# Add key include paths +target_include_directories(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR} + ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio + ) - # Add subdir with lwmem and link to the project - add_subdirectory("lwmem") - target_link_libraries(${PROJECT_NAME} lwmem) -else() - message("LWMEM: For library link, use CMakeLists.txt in /lwmem directory") -endif() \ No newline at end of file +# Compilation definition information +target_compile_definitions(${PROJECT_NAME} PUBLIC + WIN32 + _DEBUG + CONSOLE + LWMEM_DEV + ) + +# Add subdir with lwmem and link to the project +add_subdirectory("lwmem") +target_link_libraries(${PROJECT_NAME} lwmem) \ No newline at end of file From bf4c384854146f54ec9b5d11ce26d17fb7bbe4c3 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 24 Dec 2021 18:57:03 +0100 Subject: [PATCH 08/73] Update CMake and split development and library --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 287367b..87cf561 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.0.0) # Setup project -project(LwLibPROJECT VERSION 2.0.1) +project(LwLibPROJECT) # ------------------------------------------------- # This CMakeLists.txt is used only if it is a top-level file. From 4f5e3ae8ad3087dc2feea35395386aad981f540a Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 24 Dec 2021 19:44:26 +0100 Subject: [PATCH 09/73] Move dvp one folder up and update CMakeLists.txt --- CMakeLists.txt | 4 ++-- dev/{VisualStudio => }/lwmem_dev.sln | 0 dev/{VisualStudio => }/lwmem_dev.vcxproj | 8 ++++---- dev/{VisualStudio => }/lwmem_dev.vcxproj.filters | 6 +++--- dev/{VisualStudio => }/lwmem_opts.h | 0 dev/{VisualStudio => }/main.c | 0 6 files changed, 9 insertions(+), 9 deletions(-) rename dev/{VisualStudio => }/lwmem_dev.sln (100%) rename dev/{VisualStudio => }/lwmem_dev.vcxproj (96%) rename dev/{VisualStudio => }/lwmem_dev.vcxproj.filters (84%) rename dev/{VisualStudio => }/lwmem_opts.h (100%) rename dev/{VisualStudio => }/main.c (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 87cf561..949e29f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,14 +18,14 @@ add_executable(${PROJECT_NAME}) # Add key executable block target_sources(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio/main.c + ${CMAKE_CURRENT_LIST_DIR}/dev/main.c ${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c ) # Add key include paths target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR} - ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio + ${CMAKE_CURRENT_LIST_DIR}/dev ) # Compilation definition information diff --git a/dev/VisualStudio/lwmem_dev.sln b/dev/lwmem_dev.sln similarity index 100% rename from dev/VisualStudio/lwmem_dev.sln rename to dev/lwmem_dev.sln diff --git a/dev/VisualStudio/lwmem_dev.vcxproj b/dev/lwmem_dev.vcxproj similarity index 96% rename from dev/VisualStudio/lwmem_dev.vcxproj rename to dev/lwmem_dev.vcxproj index 694d66a..3567e76 100644 --- a/dev/VisualStudio/lwmem_dev.vcxproj +++ b/dev/lwmem_dev.vcxproj @@ -73,7 +73,7 @@ true - ..\..\lwmem\src\include;.;$(IncludePath) + ..\lwmem\src\include;.;$(IncludePath) true @@ -143,9 +143,9 @@ - - - + + + diff --git a/dev/VisualStudio/lwmem_dev.vcxproj.filters b/dev/lwmem_dev.vcxproj.filters similarity index 84% rename from dev/VisualStudio/lwmem_dev.vcxproj.filters rename to dev/lwmem_dev.vcxproj.filters index 46dbc3b..feefc4e 100644 --- a/dev/VisualStudio/lwmem_dev.vcxproj.filters +++ b/dev/lwmem_dev.vcxproj.filters @@ -16,13 +16,13 @@ Source Files - + Source Files\LWMEM - + Source Files\LWMEM - + Source Files\Tests diff --git a/dev/VisualStudio/lwmem_opts.h b/dev/lwmem_opts.h similarity index 100% rename from dev/VisualStudio/lwmem_opts.h rename to dev/lwmem_opts.h diff --git a/dev/VisualStudio/main.c b/dev/main.c similarity index 100% rename from dev/VisualStudio/main.c rename to dev/main.c From 1c06752745c494a986c4f72fa11303f478c58b45 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 24 Dec 2021 19:58:29 +0100 Subject: [PATCH 10/73] Update Changelog file for CMakeLists --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b34703f..20cbb12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Develop +- Split CMakeLists.txt files between library and executable + ## v2.0.0 - Remove `len` parameter for regions definition. Affected functions: `lwmem_assignmem` and `lwmem_assignmem_ex` From 8db9c43d5171d1b9a76d32fa9c9f8985d70ca0fb Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 24 Dec 2021 20:11:19 +0100 Subject: [PATCH 11/73] Update getting started --- docs/get-started/index.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/get-started/index.rst b/docs/get-started/index.rst index c7055a9..d66abc5 100644 --- a/docs/get-started/index.rst +++ b/docs/get-started/index.rst @@ -45,10 +45,10 @@ This is used when you do not have yet local copy on your machine. Update cloned to latest version """"""""""""""""""""""""""""""" -* Open console and navigate to path in the system where your resources repository is. Use command ``cd your_path`` -* Run ``git pull origin master --recurse-submodules`` command to pull latest changes and to fetch latest changes from submodules on ``master`` branch -* Run ``git pull origin develop --recurse-submodules`` command to pull latest changes and to fetch latest changes from submodules on ``develop`` branch -* Run ``git submodule foreach git pull origin master`` to update & merge all submodules +* Open console and navigate to path in the system where your repository is located. Use command ``cd your_path`` +* Run ``git pull origin master`` command to get latest changes on ``master`` branch +* Run ``git pull origin develop`` command to get latest changes on ``develop`` branch +* Run ``git submodule update --init --remote`` to update submodules to latest version .. note:: This is preferred option to use when you want to evaluate library and run prepared examples. From 5a3562386c4377149c0554c7e81c85a9e3b969c0 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 24 Dec 2021 23:43:36 +0100 Subject: [PATCH 12/73] Add ARM NONE EABI global toolchain file --- cmake/gcc-arm-none-eabi.cmake | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 cmake/gcc-arm-none-eabi.cmake diff --git a/cmake/gcc-arm-none-eabi.cmake b/cmake/gcc-arm-none-eabi.cmake new file mode 100644 index 0000000..1946556 --- /dev/null +++ b/cmake/gcc-arm-none-eabi.cmake @@ -0,0 +1,19 @@ +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR arm) + +# Some default GCC settings +set(TOOLCHAIN_PREFIX arm-none-eabi-) +set(FLAGS "-fdata-sections -ffunction-sections --specs=nano.specs -Wl,--gc-sections") +set(CPP_FLAGS "-fno-rtti -fno-exceptions -fno-threadsafe-statics") + +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc ${FLAGS}) +set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++ ${FLAGS} ${CPP_FLAGS}) +set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy) +set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size) + +set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf") +set(CMAKE_EXECUTABLE_SUFFIX_C ".elf") +set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf") + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) From 1729e74d455b84e7ed60035fe73d6c4b9a982b90 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 24 Dec 2021 23:43:51 +0100 Subject: [PATCH 13/73] Extend examples with cmake support + vscode --- cmake/gcc-arm-none-eabi.cmake | 21 +-- .../.vscode/c_cpp_properties.json | 30 ++++ .../.vscode/cmake-kits.json | 10 ++ .../.vscode/launch.json | 20 +++ .../.vscode/settings.json | 7 + .../.vscode/tasks.json | 47 ++++++ .../CMakeLists.txt | 141 ++++++++++++++++++ .../.vscode/c_cpp_properties.json | 27 ++++ .../.vscode/cmake-kits.json | 10 ++ .../.vscode/launch.json | 20 +++ .../.vscode/tasks.json | 47 ++++++ .../lwmem_stm32l496_discovery/CMakeLists.txt | 121 +++++++++++++++ 12 files changed, 491 insertions(+), 10 deletions(-) create mode 100644 examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json create mode 100644 examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/cmake-kits.json create mode 100644 examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json create mode 100644 examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/settings.json create mode 100644 examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json create mode 100644 examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt create mode 100644 examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json create mode 100644 examples/stm32/lwmem_stm32l496_discovery/.vscode/cmake-kits.json create mode 100644 examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json create mode 100644 examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json create mode 100644 examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt diff --git a/cmake/gcc-arm-none-eabi.cmake b/cmake/gcc-arm-none-eabi.cmake index 1946556..3577ff8 100644 --- a/cmake/gcc-arm-none-eabi.cmake +++ b/cmake/gcc-arm-none-eabi.cmake @@ -1,16 +1,17 @@ -set(CMAKE_SYSTEM_NAME Generic) -set(CMAKE_SYSTEM_PROCESSOR arm) +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR arm) # Some default GCC settings -set(TOOLCHAIN_PREFIX arm-none-eabi-) -set(FLAGS "-fdata-sections -ffunction-sections --specs=nano.specs -Wl,--gc-sections") -set(CPP_FLAGS "-fno-rtti -fno-exceptions -fno-threadsafe-statics") +# arm-none-eabi- must be part of path environment +set(TOOLCHAIN_PREFIX arm-none-eabi-) +set(FLAGS "-fdata-sections -ffunction-sections --specs=nano.specs -Wl,--gc-sections") +set(CPP_FLAGS "-fno-rtti -fno-exceptions -fno-threadsafe-statics") -set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc ${FLAGS}) -set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) -set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++ ${FLAGS} ${CPP_FLAGS}) -set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy) -set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size) +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc ${FLAGS}) +set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++ ${FLAGS} ${CPP_FLAGS}) +set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy) +set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size) set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf") set(CMAKE_EXECUTABLE_SUFFIX_C ".elf") diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..51c0af9 --- /dev/null +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json @@ -0,0 +1,30 @@ +{ + "version": 4, + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}", + "${workspaceFolder}\\inc", + "${workspaceFolder}\\..\\..\\lib\\st\\STM32L4xx_HAL_Driver\\Inc", + "${workspaceFolder}\\..\\..\\lib\\st\\CMSIS\\Device\\ST\\STM32L4xx\\Include", + "${workspaceFolder}\\..\\..\\lib\\st\\CMSIS\\include", + "${workspaceFolder}\\..\\..\\lib\\FreeRTOS\\include", + "${workspaceFolder}\\..\\..\\lib\\FreeRTOS\\CMSIS_RTOS_V2", + "${workspaceFolder}\\..\\..\\lib\\FreeRTOS\\portable\\GCC\\ARM_CM4F", + "${workspaceFolder}\\..\\..\\..\\lwmem\\src\\include" + ], + "defines": [ + "__weak=__attribute__((weak))", + "__packed=__attribute__((__packed__))", + "STM32L496xx", + "USE_FULL_LL_DRIVER" + ], + "compilerPath": "c:\\msys64\\mingw64\\bin\\gcc.exe", + "cStandard": "gnu17", + "cppStandard": "gnu++14", + "intelliSenseMode": "windows-gcc-x86", + "configurationProvider": "ms-vscode.cmake-tools" + } + ] +} \ No newline at end of file diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/cmake-kits.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/cmake-kits.json new file mode 100644 index 0000000..0450cc9 --- /dev/null +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/cmake-kits.json @@ -0,0 +1,10 @@ +[ + { + "name": "GCC 10.3.1 arm-none-eabi", + "compilers": { + "C": "arm-none-eabi-gcc", + "CXX": "arm-none-eabi-g++" + }, + "toolchainFile": "../../../cmake/gcc-arm-none-eabi.cmake" + } + ] \ No newline at end of file diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json new file mode 100644 index 0000000..7c4d17d --- /dev/null +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json @@ -0,0 +1,20 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(Windows) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}\\build\\lwmem_l496vg.elf", + "miDebuggerPath": "gdb.exe", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/settings.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/settings.json new file mode 100644 index 0000000..54c07eb --- /dev/null +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "files.associations": { + "cmsis_os.h": "c", + "freertos.h": "c", + "lwmem.h": "c" + } +} \ No newline at end of file diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json new file mode 100644 index 0000000..35a0995 --- /dev/null +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json @@ -0,0 +1,47 @@ +{ + "version": "2.0.0", + + /* For this builds, you need + * + * - Ninja build system + * - MSYS2 compiler with ninja support + * - C/C++ extension for VSCode + * - CMake-Tools extension for VSCode + */ + "tasks": [ + { + "type": "cppbuild", + "label": "Build project", + "command": "cmake", + "args": ["--build", "\"build\""], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": ["$gcc"], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "type": "shell", + "label": "Re-build project", + "command": "cmake", + "args": ["--build", "\"build\"", "--clean-first", "-v"], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": ["$gcc"], + }, + { + "type": "shell", + "label": "Clean project", + "command": "cmake", + "args": ["--build", "\"build\"", "--target", "clean"], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + }, + ] +} \ No newline at end of file diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt b/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt new file mode 100644 index 0000000..c01fa02 --- /dev/null +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt @@ -0,0 +1,141 @@ +cmake_minimum_required(VERSION 3.12) + +# ############################################################################## +# Edit your MCU information up to the next border +project(lwmem_l496vg) +set(PROJECT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + +set(MCU_FAMILY STM32L4xx) +set(MCU_MODEL STM32L496xx) +set(CPU_PARAMETERS + -mcpu=cortex-m4 + -mthumb + -mfpu=fpv4-sp-d16 + -mfloat-abi=hard + ) + +# Set startup and linker script +set(STARTUP_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/STM32CubeIDE/startup/startup_stm32l496xx.s) +set(MCU_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/STM32CubeIDE/Debug_STM32L496AG_FLASH.ld) + +# ############################################################################## +set(EXECUTABLE ${CMAKE_PROJECT_NAME}) +enable_language(C CXX ASM) +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS ON) +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS ON) + +# Include headers +set(CUBE_INCLUDE_DIRECTORIES + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/${MCU_FAMILY}_HAL_Driver/Inc + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/${MCU_FAMILY}_HAL_Driver/Inc/Legacy + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/CMSIS/Device/ST/${MCU_FAMILY}/Include + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/CMSIS/include + ) +set(PROJECT_INCLUDE_DIRECTORIES + ${CMAKE_CURRENT_SOURCE_DIR}/inc + + # FreeRTOS + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/include + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/CMSIS_RTOS_V2 + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/portable/GCC/ARM_CM4F + ) + +# Source files +set(CUBE_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_dma.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_exti.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_gpio.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_pwr.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_rcc.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_usart.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_utils.c + ) +set(PROJECT_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/stm32l4xx_it.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/syscalls.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/system_stm32l4xx.c + + # FreeRTOS operating system + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/CMSIS_RTOS_V2/cmsis_os2.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/croutine.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/event_groups.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/portable/MemMang/heap_4.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/list.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/portable/GCC/ARM_CM4F/port.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/queue.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/tasks.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/timers.c + ) + +# Executable files +add_executable(${EXECUTABLE} + ${CUBE_SOURCES} + ${PROJECT_SOURCES} + ${STARTUP_SCRIPT} + ) + +# Embedded macros(defines) +target_compile_definitions(${EXECUTABLE} PRIVATE + "__weak=__attribute__((weak))" + "__packed=__attribute__((__packed__))" + ${MCU_MODEL} + USE_FULL_LL_DRIVER + ) + +# Add header directories (AFTER add_executable !!) +target_include_directories(${EXECUTABLE} PRIVATE + ${CUBE_INCLUDE_DIRECTORIES} + ${PROJECT_INCLUDE_DIRECTORIES} + ) + +# Add lwmem to the project +set(LWMEM_SYS_ARCH "cmsis_os") +add_subdirectory("../../../lwmem" lwmem) +target_link_libraries(${EXECUTABLE} lwmem) + +# Compiler and linker options +target_compile_options(${EXECUTABLE} PRIVATE + ${CPU_PARAMETERS} + -Wall + -Wextra + -Wpedantic + -Wno-unused-parameter + $<$: + -Wno-volatile + -Wold-style-cast + -Wuseless-cast + -Wsuggest-override> + $<$:-Og -g3 -ggdb> + $<$:-Og -g0> + ) + +# Setup linker parameters +target_link_options(${EXECUTABLE} PRIVATE + -T${MCU_LINKER_SCRIPT} + ${CPU_PARAMETERS} + -Wl,-Map=${CMAKE_PROJECT_NAME}.map + --specs=nosys.specs + -Wl,--start-group + -lc + -lm + -lstdc++ + -lsupc++ + -Wl,--end-group + -Wl,--print-memory-usage) + +# Execute post-build to print size +add_custom_command(TARGET ${EXECUTABLE} POST_BUILD + COMMAND ${CMAKE_SIZE} $) + +# Convert output to hex and binary +add_custom_command(TARGET ${EXECUTABLE} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O ihex $ ${EXECUTABLE}.hex) + +# Conver to bin file -> add conditional check? +add_custom_command(TARGET ${EXECUTABLE} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O binary $ ${EXECUTABLE}.bin) \ No newline at end of file diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..d29a816 --- /dev/null +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json @@ -0,0 +1,27 @@ +{ + "version": 4, + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}", + "${workspaceFolder}\\inc", + "${workspaceFolder}\\..\\..\\lib\\st\\STM32L4xx_HAL_Driver\\Inc", + "${workspaceFolder}\\..\\..\\lib\\st\\CMSIS\\Device\\ST\\STM32L4xx\\Include", + "${workspaceFolder}\\..\\..\\lib\\st\\CMSIS\\include", + "${workspaceFolder}\\..\\..\\..\\lwmem\\src\\include", + ], + "defines": [ + "__weak=__attribute__((weak))", + "__packed=__attribute__((__packed__))", + "STM32L496xx", + "USE_FULL_LL_DRIVER" + ], + "compilerPath": "c:\\msys64\\mingw64\\bin\\gcc.exe", + "cStandard": "gnu17", + "cppStandard": "gnu++14", + "intelliSenseMode": "windows-gcc-x86", + "configurationProvider": "ms-vscode.cmake-tools" + } + ] +} \ No newline at end of file diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/cmake-kits.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/cmake-kits.json new file mode 100644 index 0000000..0450cc9 --- /dev/null +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/cmake-kits.json @@ -0,0 +1,10 @@ +[ + { + "name": "GCC 10.3.1 arm-none-eabi", + "compilers": { + "C": "arm-none-eabi-gcc", + "CXX": "arm-none-eabi-g++" + }, + "toolchainFile": "../../../cmake/gcc-arm-none-eabi.cmake" + } + ] \ No newline at end of file diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json new file mode 100644 index 0000000..7c4d17d --- /dev/null +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json @@ -0,0 +1,20 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(Windows) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}\\build\\lwmem_l496vg.elf", + "miDebuggerPath": "gdb.exe", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json new file mode 100644 index 0000000..35a0995 --- /dev/null +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json @@ -0,0 +1,47 @@ +{ + "version": "2.0.0", + + /* For this builds, you need + * + * - Ninja build system + * - MSYS2 compiler with ninja support + * - C/C++ extension for VSCode + * - CMake-Tools extension for VSCode + */ + "tasks": [ + { + "type": "cppbuild", + "label": "Build project", + "command": "cmake", + "args": ["--build", "\"build\""], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": ["$gcc"], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "type": "shell", + "label": "Re-build project", + "command": "cmake", + "args": ["--build", "\"build\"", "--clean-first", "-v"], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": ["$gcc"], + }, + { + "type": "shell", + "label": "Clean project", + "command": "cmake", + "args": ["--build", "\"build\"", "--target", "clean"], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + }, + ] +} \ No newline at end of file diff --git a/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt b/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt new file mode 100644 index 0000000..09fbf93 --- /dev/null +++ b/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt @@ -0,0 +1,121 @@ +cmake_minimum_required(VERSION 3.12) + +# ############################################################################## +# Edit your MCU information up to the next border +project(lwmem_l496vg) +set(PROJECT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + +set(MCU_FAMILY STM32L4xx) +set(MCU_MODEL STM32L496xx) +set(CPU_PARAMETERS + -mcpu=cortex-m4 + -mthumb + -mfpu=fpv4-sp-d16 + -mfloat-abi=hard + ) + +# Set startup and linker script +set(STARTUP_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/STM32CubeIDE/startup/startup_stm32l496xx.s) +set(MCU_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/STM32CubeIDE/Debug_STM32L496AG_FLASH.ld) + +# ############################################################################## +set(EXECUTABLE ${CMAKE_PROJECT_NAME}) +enable_language(C CXX ASM) +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS ON) +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS ON) + +# Include headers +set(CUBE_INCLUDE_DIRECTORIES + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/${MCU_FAMILY}_HAL_Driver/Inc + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/${MCU_FAMILY}_HAL_Driver/Inc/Legacy + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/CMSIS/Device/ST/${MCU_FAMILY}/Include + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/CMSIS/include + ) +set(PROJECT_INCLUDE_DIRECTORIES + ${CMAKE_CURRENT_SOURCE_DIR}/../../../lwmem/src/include + ${CMAKE_CURRENT_SOURCE_DIR}/inc) + +# Source files +set(CUBE_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/../../../lwmem/src/lwmem/lwmem.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_dma.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_exti.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_gpio.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_pwr.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_rcc.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_usart.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_utils.c + ) +set(PROJECT_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/stm32l4xx_it.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/syscalls.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/system_stm32l4xx.c + ) + +# Executable files +add_executable(${EXECUTABLE} + ${CUBE_SOURCES} + ${PROJECT_SOURCES} + ${STARTUP_SCRIPT} + ) + +# Embedded macros(defines) +target_compile_definitions(${EXECUTABLE} PRIVATE + "__weak=__attribute__((weak))" + "__packed=__attribute__((__packed__))" + ${MCU_MODEL} + USE_FULL_LL_DRIVER + ) + +# Add header directories (AFTER add_executable !!) +target_include_directories(${EXECUTABLE} PRIVATE + ${CUBE_INCLUDE_DIRECTORIES} + ${PROJECT_INCLUDE_DIRECTORIES} + ) + +# Compiler and linker options +target_compile_options(${EXECUTABLE} PRIVATE + ${CPU_PARAMETERS} + -Wall + -Wextra + -Wpedantic + -Wno-unused-parameter + $<$: + -Wno-volatile + -Wold-style-cast + -Wuseless-cast + -Wsuggest-override> + $<$:-Og -g3 -ggdb> + $<$:-Og -g0> + ) + +# Setup linker parameters +target_link_options(${EXECUTABLE} PRIVATE + -T${MCU_LINKER_SCRIPT} + ${CPU_PARAMETERS} + -Wl,-Map=${CMAKE_PROJECT_NAME}.map + --specs=nosys.specs + -Wl,--start-group + -lc + -lm + -lstdc++ + -lsupc++ + -Wl,--end-group + -Wl,--print-memory-usage) + +# Execute post-build to print size +add_custom_command(TARGET ${EXECUTABLE} POST_BUILD + COMMAND ${CMAKE_SIZE} $) + +# Convert output to hex and binary +add_custom_command(TARGET ${EXECUTABLE} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O ihex $ ${EXECUTABLE}.hex) + +# Conver to bin file -> add conditional check? +add_custom_command(TARGET ${EXECUTABLE} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O binary $ ${EXECUTABLE}.bin) \ No newline at end of file From 4eff6d0c40773429fa79df023cbb7f5e7a34d52f Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sat, 25 Dec 2021 00:09:20 +0100 Subject: [PATCH 14/73] Add launch for cortex-debug --- .../.vscode/launch.json | 22 +++++++++++-------- .../.vscode/launch.json | 22 +++++++++++-------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json index 7c4d17d..e418d0e 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json @@ -5,16 +5,20 @@ "version": "0.2.0", "configurations": [ { - "name": "(Windows) Launch", - "type": "cppdbg", + "cwd": "${workspaceFolder}", + "executable": "build/lwmem_l496vg.elf", + "name": "Debug Microcontroller", "request": "launch", - "program": "${workspaceFolder}\\build\\lwmem_l496vg.elf", - "miDebuggerPath": "gdb.exe", - "args": [], - "stopAtEntry": false, - "cwd": "${fileDirname}", - "environment": [], - "console": "integratedTerminal" + "type": "cortex-debug", + "servertype": "stlink", + "serverpath": "c:/ST/STM32CubeIDE_1.0.2/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.win32_2.0.100.202109301221/tools/bin/ST-LINK_gdbserver.exe", + "armToolchainPath": "d:/_WORK/gcc-arm-none-eabi/10.3-2021.10/bin", + "device": "STM32L496VG", + "interface": "swd", + "serialNumber": "", // add J-Link serial number if having multiple attached the same time. + "runToMain": true, + "svdFile": "", + "v1": false } ] } \ No newline at end of file diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json index 7c4d17d..e418d0e 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json @@ -5,16 +5,20 @@ "version": "0.2.0", "configurations": [ { - "name": "(Windows) Launch", - "type": "cppdbg", + "cwd": "${workspaceFolder}", + "executable": "build/lwmem_l496vg.elf", + "name": "Debug Microcontroller", "request": "launch", - "program": "${workspaceFolder}\\build\\lwmem_l496vg.elf", - "miDebuggerPath": "gdb.exe", - "args": [], - "stopAtEntry": false, - "cwd": "${fileDirname}", - "environment": [], - "console": "integratedTerminal" + "type": "cortex-debug", + "servertype": "stlink", + "serverpath": "c:/ST/STM32CubeIDE_1.0.2/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.win32_2.0.100.202109301221/tools/bin/ST-LINK_gdbserver.exe", + "armToolchainPath": "d:/_WORK/gcc-arm-none-eabi/10.3-2021.10/bin", + "device": "STM32L496VG", + "interface": "swd", + "serialNumber": "", // add J-Link serial number if having multiple attached the same time. + "runToMain": true, + "svdFile": "", + "v1": false } ] } \ No newline at end of file From 744ab655116b3eac5ce8e8e45fbbfb0a48e2bc3f Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Mon, 27 Dec 2021 09:50:43 +0100 Subject: [PATCH 15/73] Add CMake higher granularity and update examples --- CMakeLists.txt | 11 +++++++++++ .../CMakeLists.txt | 1 + .../lwmem_stm32l496_discovery/CMakeLists.txt | 6 +++++- lwmem/CMakeLists.txt | 19 ++++++++++++++++--- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 949e29f..2b1702d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,17 @@ target_compile_definitions(${PROJECT_NAME} PUBLIC LWMEM_DEV ) +# Compiler and linker options +target_compile_options(${PROJECT_NAME} PRIVATE + ${CPU_PARAMETERS} + -Wall + -Wextra + -Wpedantic + -Wno-unused-parameter + ) + # Add subdir with lwmem and link to the project +set(LWMEM_SYS_ADD_FILES ON) +set(LWMEM_SYS_ARCH "win32") add_subdirectory("lwmem") target_link_libraries(${PROJECT_NAME} lwmem) \ No newline at end of file diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt b/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt index c01fa02..960f496 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt @@ -94,6 +94,7 @@ target_include_directories(${EXECUTABLE} PRIVATE ) # Add lwmem to the project +set(LWMEM_SYS_ADD_FILES ON) set(LWMEM_SYS_ARCH "cmsis_os") add_subdirectory("../../../lwmem" lwmem) target_link_libraries(${EXECUTABLE} lwmem) diff --git a/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt b/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt index 09fbf93..90bdeb5 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt +++ b/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt @@ -41,7 +41,6 @@ set(PROJECT_INCLUDE_DIRECTORIES # Source files set(CUBE_SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/../../../lwmem/src/lwmem/lwmem.c ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_dma.c ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_exti.c ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_gpio.c @@ -78,6 +77,11 @@ target_include_directories(${EXECUTABLE} PRIVATE ${PROJECT_INCLUDE_DIRECTORIES} ) +# Add lwmem to the project +set(LWMEM_SYS_ADD_FILES OFF) +add_subdirectory("../../../lwmem" lwmem) +target_link_libraries(${EXECUTABLE} lwmem) + # Compiler and linker options target_compile_options(${EXECUTABLE} PRIVATE ${CPU_PARAMETERS} diff --git a/lwmem/CMakeLists.txt b/lwmem/CMakeLists.txt index 0c87659..522aead 100644 --- a/lwmem/CMakeLists.txt +++ b/lwmem/CMakeLists.txt @@ -7,9 +7,16 @@ message("LWMEM: Entering lib source CMakeLists.txt") set(LWMEM_LIB_NAME "lwmem") # Check definitions of some key things -if(NOT DEFINED LWMEM_SYS_ARCH) - message("LWMEM: LWMEM_SYS_ARCH not defined. Using default one: \"win32\"") - set(LWMEM_SYS_ARCH "win32") +option(LWMEM_SYS_ADD_FILES OFF) +if (LWMEM_SYS_ADD_FILES) + message("LWMEM: LWMEM_SYS_ADD_FILES is set to ON. Looking for LWMEM_SYS_ARCH definition") + if(NOT DEFINED LWMEM_SYS_ARCH) + message("LWMEM: LWMEM_SYS_ARCH not defined. Using default one: \"win32\"") + set(LWMEM_SYS_ARCH "win32") + endif() + message("LWMEM: LWPRINTF_SYS_ARCH set to: " ${LWMEM_SYS_ARCH}) +else() + message("LWMEM: LWMEM_SYS_ADD_FILES is set to OFF. User must manually implement system functions in case of operating system support") endif() # Register library to the system @@ -18,8 +25,14 @@ add_library(${LWMEM_LIB_NAME} INTERFACE) # Setup generic source files target_sources(${LWMEM_LIB_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.c + ) + +# Add optional sources +if (LWMEM_SYS_ADD_FILES) +target_sources(${LWMEM_LIB_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/system/lwmem_sys_${LWMEM_SYS_ARCH}.c ) +endif() # Setup include directories target_include_directories(${LWMEM_LIB_NAME} INTERFACE From f689488a40f6e0d45a18da3505bbc831912b1034 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Mon, 27 Dec 2021 17:50:21 +0100 Subject: [PATCH 16/73] Update CMakeLists.txt for each library and split core and optional modules --- .vscode/c_cpp_properties.json | 2 +- CMakeLists.txt | 7 ++-- .../.vscode/c_cpp_properties.json | 2 +- .../.vscode/settings.json | 4 +- .../CMakeLists.txt | 29 +++++++------ .../.vscode/settings.json | 6 +++ .../lwmem_stm32l496_discovery/CMakeLists.txt | 21 +++++----- lwmem/CMakeLists.txt | 42 ++++--------------- 8 files changed, 49 insertions(+), 64 deletions(-) create mode 100644 examples/stm32/lwmem_stm32l496_discovery/.vscode/settings.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 24189a2..0bd1c71 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -4,7 +4,7 @@ { "name": "Win32", "includePath": [ - "${workspaceFolder}\\dev\\VisualStudio\\", + "${workspaceFolder}\\dev\\", "${workspaceFolder}\\lwmem\\src\\include\\" ], "defines": [ diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b1702d..deb93f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,9 @@ add_executable(${PROJECT_NAME}) target_sources(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/dev/main.c ${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c + + # win32 port + ${CMAKE_CURRENT_LIST_DIR}/lwmem/src/system/lwmem_sys_win32.c ) # Add key include paths @@ -46,7 +49,5 @@ target_compile_options(${PROJECT_NAME} PRIVATE ) # Add subdir with lwmem and link to the project -set(LWMEM_SYS_ADD_FILES ON) -set(LWMEM_SYS_ARCH "win32") add_subdirectory("lwmem") -target_link_libraries(${PROJECT_NAME} lwmem) \ No newline at end of file +target_link_libraries(${PROJECT_NAME} lwmem) diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json index 51c0af9..59be0ab 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json @@ -5,7 +5,7 @@ "name": "Win32", "includePath": [ "${workspaceFolder}", - "${workspaceFolder}\\inc", + "${workspaceFolder}\\inc", "${workspaceFolder}\\..\\..\\lib\\st\\STM32L4xx_HAL_Driver\\Inc", "${workspaceFolder}\\..\\..\\lib\\st\\CMSIS\\Device\\ST\\STM32L4xx\\Include", "${workspaceFolder}\\..\\..\\lib\\st\\CMSIS\\include", diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/settings.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/settings.json index 54c07eb..316acef 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/settings.json +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/settings.json @@ -2,6 +2,8 @@ "files.associations": { "cmsis_os.h": "c", "freertos.h": "c", - "lwmem.h": "c" + "lwmem.h": "c", + "main.h": "c", + "lwmem_opts.h": "c" } } \ No newline at end of file diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt b/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt index 960f496..a8a0bf9 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt @@ -29,23 +29,23 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS ON) # Include headers -set(CUBE_INCLUDE_DIRECTORIES +set(st_cube_include_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/${MCU_FAMILY}_HAL_Driver/Inc ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/${MCU_FAMILY}_HAL_Driver/Inc/Legacy ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/CMSIS/Device/ST/${MCU_FAMILY}/Include ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/CMSIS/include ) -set(PROJECT_INCLUDE_DIRECTORIES +set(project_include_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/inc - - # FreeRTOS + ) +set(freertos_include_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/include ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/CMSIS_RTOS_V2 ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/portable/GCC/ARM_CM4F ) # Source files -set(CUBE_SOURCES +set(st_cube_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_dma.c ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_exti.c ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_gpio.c @@ -54,13 +54,16 @@ set(CUBE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_usart.c ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_utils.c ) -set(PROJECT_SOURCES +set(project_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/stm32l4xx_it.c ${CMAKE_CURRENT_SOURCE_DIR}/src/syscalls.c ${CMAKE_CURRENT_SOURCE_DIR}/src/system_stm32l4xx.c - # FreeRTOS operating system + # LwMEM system func + ${CMAKE_CURRENT_SOURCE_DIR}/../../../lwmem/src/system/lwmem_sys_cmsis_os.c + ) +set(freertos_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/CMSIS_RTOS_V2/cmsis_os2.c ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/croutine.c ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/event_groups.c @@ -74,8 +77,9 @@ set(PROJECT_SOURCES # Executable files add_executable(${EXECUTABLE} - ${CUBE_SOURCES} - ${PROJECT_SOURCES} + ${st_cube_SRCS} + ${project_SRCS} + ${freertos_SRCS} ${STARTUP_SCRIPT} ) @@ -89,13 +93,12 @@ target_compile_definitions(${EXECUTABLE} PRIVATE # Add header directories (AFTER add_executable !!) target_include_directories(${EXECUTABLE} PRIVATE - ${CUBE_INCLUDE_DIRECTORIES} - ${PROJECT_INCLUDE_DIRECTORIES} + ${st_cube_include_DIRS} + ${project_include_DIRS} + ${freertos_include_DIRS} ) # Add lwmem to the project -set(LWMEM_SYS_ADD_FILES ON) -set(LWMEM_SYS_ARCH "cmsis_os") add_subdirectory("../../../lwmem" lwmem) target_link_libraries(${EXECUTABLE} lwmem) diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/settings.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/settings.json new file mode 100644 index 0000000..b068dd8 --- /dev/null +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "main.h": "c", + "stm32l4xx_ll_usart.h": "c" + } +} \ No newline at end of file diff --git a/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt b/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt index 90bdeb5..e6415bb 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt +++ b/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt @@ -29,18 +29,18 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS ON) # Include headers -set(CUBE_INCLUDE_DIRECTORIES +set(st_cube_include_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/${MCU_FAMILY}_HAL_Driver/Inc ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/${MCU_FAMILY}_HAL_Driver/Inc/Legacy ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/CMSIS/Device/ST/${MCU_FAMILY}/Include ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/CMSIS/include ) -set(PROJECT_INCLUDE_DIRECTORIES - ${CMAKE_CURRENT_SOURCE_DIR}/../../../lwmem/src/include - ${CMAKE_CURRENT_SOURCE_DIR}/inc) +set(project_include_DIRS + ${CMAKE_CURRENT_SOURCE_DIR}/inc + ) # Source files -set(CUBE_SOURCES +set(st_cube_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_dma.c ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_exti.c ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_gpio.c @@ -49,7 +49,7 @@ set(CUBE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_usart.c ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_utils.c ) -set(PROJECT_SOURCES +set(project_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/stm32l4xx_it.c ${CMAKE_CURRENT_SOURCE_DIR}/src/syscalls.c @@ -58,8 +58,8 @@ set(PROJECT_SOURCES # Executable files add_executable(${EXECUTABLE} - ${CUBE_SOURCES} - ${PROJECT_SOURCES} + ${st_cube_SRCS} + ${project_SOURCES} ${STARTUP_SCRIPT} ) @@ -73,12 +73,11 @@ target_compile_definitions(${EXECUTABLE} PRIVATE # Add header directories (AFTER add_executable !!) target_include_directories(${EXECUTABLE} PRIVATE - ${CUBE_INCLUDE_DIRECTORIES} - ${PROJECT_INCLUDE_DIRECTORIES} + ${st_cube_include_DIRS} + ${project_include_DIRS} ) # Add lwmem to the project -set(LWMEM_SYS_ADD_FILES OFF) add_subdirectory("../../../lwmem" lwmem) target_link_libraries(${EXECUTABLE} lwmem) diff --git a/lwmem/CMakeLists.txt b/lwmem/CMakeLists.txt index 522aead..b934230 100644 --- a/lwmem/CMakeLists.txt +++ b/lwmem/CMakeLists.txt @@ -1,40 +1,14 @@ cmake_minimum_required(VERSION 3.13) # Debug message -message("LWMEM: Entering lib source CMakeLists.txt") +message("Entering ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt") -# Set library name -set(LWMEM_LIB_NAME "lwmem") +# Register core library +add_library(lwmem INTERFACE) +target_sources(lwmem PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.c) +target_include_directories(lwmem INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/include) -# Check definitions of some key things -option(LWMEM_SYS_ADD_FILES OFF) -if (LWMEM_SYS_ADD_FILES) - message("LWMEM: LWMEM_SYS_ADD_FILES is set to ON. Looking for LWMEM_SYS_ARCH definition") - if(NOT DEFINED LWMEM_SYS_ARCH) - message("LWMEM: LWMEM_SYS_ARCH not defined. Using default one: \"win32\"") - set(LWMEM_SYS_ARCH "win32") - endif() - message("LWMEM: LWPRINTF_SYS_ARCH set to: " ${LWMEM_SYS_ARCH}) -else() - message("LWMEM: LWMEM_SYS_ADD_FILES is set to OFF. User must manually implement system functions in case of operating system support") -endif() +# Register other modules -# Register library to the system -add_library(${LWMEM_LIB_NAME} INTERFACE) - -# Setup generic source files -target_sources(${LWMEM_LIB_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.c - ) - -# Add optional sources -if (LWMEM_SYS_ADD_FILES) -target_sources(${LWMEM_LIB_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/src/system/lwmem_sys_${LWMEM_SYS_ARCH}.c - ) -endif() - -# Setup include directories -target_include_directories(${LWMEM_LIB_NAME} INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/src/include - ) +# Debug message +message("Exiting ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt") From bcfe8a2d2e947b0da8030cdbac5d96eef198afcd Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Mon, 27 Dec 2021 22:17:29 +0100 Subject: [PATCH 17/73] Update CMakeLists.txt files for all -> final corrections --- .../.vscode/.cortex-debug.registers.state.json | 1 + 1 file changed, 1 insertion(+) create mode 100644 examples/stm32/lwmem_stm32l496_discovery/.vscode/.cortex-debug.registers.state.json diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/.cortex-debug.registers.state.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/.cortex-debug.registers.state.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/.cortex-debug.registers.state.json @@ -0,0 +1 @@ +[] \ No newline at end of file From 40ed6275ea22cc22ee3b426b7db5e3f013cd3a08 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 7 Jan 2022 23:55:09 +0100 Subject: [PATCH 18/73] Improve CMake and VSCode support --- .../.vscode/c_cpp_properties.json | 27 +- .../.vscode/cmake-kits.json | 6 +- .../.vscode/launch.json | 26 +- .../.vscode/settings.json | 9 - .../.vscode/tasks.json | 27 +- .../CMakeLists.txt | 292 ++++++++++++------ .../gcc-arm-none-eabi.cmake | 20 ++ .../.cortex-debug.registers.state.json | 1 - .../.vscode/c_cpp_properties.json | 24 +- .../.vscode/cmake-kits.json | 6 +- .../.vscode/launch.json | 26 +- .../.vscode/settings.json | 6 - .../.vscode/tasks.json | 27 +- .../lwmem_stm32l496_discovery/CMakeLists.txt | 248 ++++++++++----- .../gcc-arm-none-eabi.cmake | 20 ++ 15 files changed, 492 insertions(+), 273 deletions(-) delete mode 100644 examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/settings.json create mode 100644 examples/stm32/lwmem_rtos_stm32l496_discovery/gcc-arm-none-eabi.cmake delete mode 100644 examples/stm32/lwmem_stm32l496_discovery/.vscode/.cortex-debug.registers.state.json delete mode 100644 examples/stm32/lwmem_stm32l496_discovery/.vscode/settings.json create mode 100644 examples/stm32/lwmem_stm32l496_discovery/gcc-arm-none-eabi.cmake diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json index 59be0ab..954cb6b 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json @@ -2,28 +2,15 @@ "version": 4, "configurations": [ { - "name": "Win32", - "includePath": [ - "${workspaceFolder}", - "${workspaceFolder}\\inc", - "${workspaceFolder}\\..\\..\\lib\\st\\STM32L4xx_HAL_Driver\\Inc", - "${workspaceFolder}\\..\\..\\lib\\st\\CMSIS\\Device\\ST\\STM32L4xx\\Include", - "${workspaceFolder}\\..\\..\\lib\\st\\CMSIS\\include", - "${workspaceFolder}\\..\\..\\lib\\FreeRTOS\\include", - "${workspaceFolder}\\..\\..\\lib\\FreeRTOS\\CMSIS_RTOS_V2", - "${workspaceFolder}\\..\\..\\lib\\FreeRTOS\\portable\\GCC\\ARM_CM4F", - "${workspaceFolder}\\..\\..\\..\\lwmem\\src\\include" - ], - "defines": [ - "__weak=__attribute__((weak))", - "__packed=__attribute__((__packed__))", - "STM32L496xx", - "USE_FULL_LL_DRIVER" - ], - "compilerPath": "c:\\msys64\\mingw64\\bin\\gcc.exe", + "name": "STM32", + "includePath": [], + "defines": [], + "compilerPath": "", "cStandard": "gnu17", "cppStandard": "gnu++14", - "intelliSenseMode": "windows-gcc-x86", + "intelliSenseMode": "${default}", + + /* Use this and all the include paths will come from CMake configuration instead */ "configurationProvider": "ms-vscode.cmake-tools" } ] diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/cmake-kits.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/cmake-kits.json index 0450cc9..4bc2d1b 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/cmake-kits.json +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/cmake-kits.json @@ -1,10 +1,10 @@ [ { - "name": "GCC 10.3.1 arm-none-eabi", + "name": "GCC arm-none-eabi - custom toolchain setup", "compilers": { "C": "arm-none-eabi-gcc", "CXX": "arm-none-eabi-g++" }, - "toolchainFile": "../../../cmake/gcc-arm-none-eabi.cmake" + "toolchainFile": "gcc-arm-none-eabi.cmake" } - ] \ No newline at end of file +] \ No newline at end of file diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json index e418d0e..b2edf8e 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json @@ -5,20 +5,28 @@ "version": "0.2.0", "configurations": [ { + "name": "Debug Microcontroller - STLink-V3", "cwd": "${workspaceFolder}", - "executable": "build/lwmem_l496vg.elf", - "name": "Debug Microcontroller", - "request": "launch", "type": "cortex-debug", + "executable": "${command:cmake.launchTargetPath}", //or fixed file path: build/stm32h735g-dk-led.elf + "request": "launch", //Use "attach" to connect to target w/o elf download "servertype": "stlink", - "serverpath": "c:/ST/STM32CubeIDE_1.0.2/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.win32_2.0.100.202109301221/tools/bin/ST-LINK_gdbserver.exe", - "armToolchainPath": "d:/_WORK/gcc-arm-none-eabi/10.3-2021.10/bin", - "device": "STM32L496VG", + "device": "STM32H735IG", //MCU used "interface": "swd", - "serialNumber": "", // add J-Link serial number if having multiple attached the same time. + "serialNumber": "", //Set ST-Link ID if you use multiple at the same time "runToMain": true, - "svdFile": "", - "v1": false + "svdFile": "STM32H73x.svd", //SVD file to see reisters + "v1": false, + "showDevDebugOutput": true, + + /* Will get automatically detected if STM32CubeIDE is installed to default directory + or it can be manually provided if necessary.. */ + //"serverpath": "c:\\ST\\STM32CubeIDE_1.7.0\\STM32CubeIDE\\plugins\\com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.win32_2.0.100.202109301221\\tools\\bin\\ST-LINK_gdbserver.exe", + //"armToolchainPath": "c:\\ST\\STM32CubeIDE_1.7.0\\STM32CubeIDE\\plugins\\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\\tools\\bin", + //"stm32cubeprogrammer": "c:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeProgrammer\\bin", + + /* If you use external loader, add additional arguments */ + //"serverArgs": ["--extload", "path/to/ext/loader.stldr"], } ] } \ No newline at end of file diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/settings.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/settings.json deleted file mode 100644 index 316acef..0000000 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/settings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "files.associations": { - "cmsis_os.h": "c", - "freertos.h": "c", - "lwmem.h": "c", - "main.h": "c", - "lwmem_opts.h": "c" - } -} \ No newline at end of file diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json index 35a0995..1c61742 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json @@ -1,13 +1,5 @@ { "version": "2.0.0", - - /* For this builds, you need - * - * - Ninja build system - * - MSYS2 compiler with ninja support - * - C/C++ extension for VSCode - * - CMake-Tools extension for VSCode - */ "tasks": [ { "type": "cppbuild", @@ -43,5 +35,22 @@ }, "problemMatcher": [] }, + { + "type": "shell", + "label": "Run CMake configuration", + "command": "cmake", + "args": [ + "--no-warn-unused-cli", + "-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE", + "-DCMAKE_BUILD_TYPE:STRING=Debug", + "-DCMAKE_TOOLCHAIN_FILE:FILEPATH=gcc-arm-none-eabi.cmake", + "-Bbuild", + "-G", "Ninja" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + } ] -} \ No newline at end of file +} diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt b/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt index a8a0bf9..6456d53 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt @@ -1,106 +1,179 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.22) -# ############################################################################## -# Edit your MCU information up to the next border -project(lwmem_l496vg) -set(PROJECT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +message("Entering ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt") -set(MCU_FAMILY STM32L4xx) -set(MCU_MODEL STM32L496xx) +# +# Core project settings +# +set(PROJ_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +project(lwmem_stm32l496g_discovery_rtos) +enable_language(C CXX ASM) +message("Build type: " ${CMAKE_BUILD_TYPE}) + +# Setup compiler settings +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS ON) +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS ON) + +# +# Core MCU flags, CPU, instruction set and FPU setup +# set(CPU_PARAMETERS - -mcpu=cortex-m4 -mthumb + -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard - ) +) -# Set startup and linker script -set(STARTUP_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/STM32CubeIDE/startup/startup_stm32l496xx.s) -set(MCU_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/STM32CubeIDE/Debug_STM32L496AG_FLASH.ld) - -# ############################################################################## -set(EXECUTABLE ${CMAKE_PROJECT_NAME}) -enable_language(C CXX ASM) -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS ON) - -# Include headers -set(st_cube_include_DIRS - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/${MCU_FAMILY}_HAL_Driver/Inc - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/${MCU_FAMILY}_HAL_Driver/Inc/Legacy - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/CMSIS/Device/ST/${MCU_FAMILY}/Include - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/CMSIS/include - ) -set(project_include_DIRS - ${CMAKE_CURRENT_SOURCE_DIR}/inc - ) -set(freertos_include_DIRS - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/CMSIS_RTOS_V2 - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/portable/GCC/ARM_CM4F - ) +# Set linker script +set(linker_script_SRC ${PROJ_PATH}/STM32CubeIDE/Debug_STM32L496AG_FLASH.ld) +set(EXECUTABLE ${CMAKE_PROJECT_NAME}) +# # Source files -set(st_cube_SRCS - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_dma.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_exti.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_gpio.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_pwr.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_rcc.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_usart.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_utils.c - ) -set(project_SRCS - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/stm32l4xx_it.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/syscalls.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/system_stm32l4xx.c - - # LwMEM system func - ${CMAKE_CURRENT_SOURCE_DIR}/../../../lwmem/src/system/lwmem_sys_cmsis_os.c - ) -set(freertos_SRCS - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/CMSIS_RTOS_V2/cmsis_os2.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/croutine.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/event_groups.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/portable/MemMang/heap_4.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/list.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/portable/GCC/ARM_CM4F/port.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/queue.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/tasks.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/FreeRTOS/timers.c - ) - +# +set(linked_SRCS + ${PROJ_PATH}/../../lib/FreeRTOS/CMSIS_RTOS_V2/cmsis_os2.c + ${PROJ_PATH}/../../lib/FreeRTOS/croutine.c + ${PROJ_PATH}/../../lib/FreeRTOS/event_groups.c + ${PROJ_PATH}/../../lib/FreeRTOS/portable/MemMang/heap_4.c + ${PROJ_PATH}/../../lib/FreeRTOS/list.c + ${PROJ_PATH}/../../lib/FreeRTOS/portable/GCC/ARM_CM4F/port.c + ${PROJ_PATH}/../../lib/FreeRTOS/queue.c + ${PROJ_PATH}/../../lib/FreeRTOS/tasks.c + ${PROJ_PATH}/../../lib/FreeRTOS/timers.c + ${PROJ_PATH}/../../../lwmem/src/lwmem/lwmem.c + ${PROJ_PATH}/../../../lwmem/src/system/lwmem_sys_cmsis_os.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_dma.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_exti.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_gpio.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_pwr.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_rcc.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_usart.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_utils.c + ${PROJ_PATH}/src/main.c + ${PROJ_PATH}/src/stm32l4xx_it.c + ${PROJ_PATH}/src/syscalls.c + ${PROJ_PATH}/src/system_stm32l4xx.c +) +set(source_folder_FreeRTOS_SRCS + ) + +set(source_folder_LwMEM_SRCS + ) + +set(source_folder_STM32L4xx_HAL_Drivers_SRCS + ) + +set(source_folder_User_SRCS + ) + +set(source_folder_startup_SRCS + ${PROJ_PATH}/STM32CubeIDE/startup/startup_stm32l496xx.s) + +# Source files in the same path as ".cproject/.project" but nowhere included in file descriptions +set(all_project_dir_SRCS + +) + +# +# Include directories +# +set(include_c_DIRS + ${PROJ_PATH}/inc + ${PROJ_PATH}/../../../lwmem/src/include + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Inc + ${PROJ_PATH}/../../lib/st/CMSIS/Device/ST/STM32L4xx/Include + ${PROJ_PATH}/../../lib/st/CMSIS/Include + ${PROJ_PATH}/../../lib/FreeRTOS/include + ${PROJ_PATH}/../../lib/FreeRTOS/CMSIS_RTOS_V2 + ${PROJ_PATH}/../../lib/FreeRTOS/portable/GCC/ARM_CM4F +) +set(include_cxx_DIRS + +) +set(include_asm_DIRS + +) + +# +# Symbols definition +# +set(symbols_c_SYMB + "__weak=__attribute__((weak))" + "__packed=__attribute__((__packed__))" + "USE_FULL_LL_DRIVER" + "STM32L496xx" +) +set(symbols_cxx_SYMB + "STM32F10X_MD" + "USE_STDPERIPH_DRIVER" +) +set(symbols_asm_SYMB + +) + +# +# Link directories setup +# Must be before executable is added +# +set(link_DIRS + +) +link_directories(${EXECUTABLE} ${link_DIRS}) + +# # Executable files +# add_executable(${EXECUTABLE} - ${st_cube_SRCS} - ${project_SRCS} - ${freertos_SRCS} - ${STARTUP_SCRIPT} - ) - -# Embedded macros(defines) + ${linked_SRCS} + ${all_project_dir_SRCS} + ${source_folder_FreeRTOS_SRCS} + ${source_folder_LwMEM_SRCS} + ${source_folder_STM32L4xx_HAL_Drivers_SRCS} + ${source_folder_User_SRCS} + ${source_folder_startup_SRCS}) + +# +# Add linked libraries for linker +# +set(link_LIBS + +) +target_link_libraries(${EXECUTABLE} ${link_LIBS}) + +# +# Project symbols +# target_compile_definitions(${EXECUTABLE} PRIVATE - "__weak=__attribute__((weak))" - "__packed=__attribute__((__packed__))" - ${MCU_MODEL} - USE_FULL_LL_DRIVER - ) - -# Add header directories (AFTER add_executable !!) + # Language specific only + $<$: ${symbols_c_SYMB}> + $<$: ${symbols_cxx_SYMB}> + $<$: ${symbols_asm_SYMB}> + + # Configuration specific + $<$: + DEBUG + > + $<$: > +) + +# +# Add include paths for each of the compiler +# target_include_directories(${EXECUTABLE} PRIVATE - ${st_cube_include_DIRS} - ${project_include_DIRS} - ${freertos_include_DIRS} - ) + # Language specific only + $<$: ${include_c_DIRS}> + $<$: ${include_cxx_DIRS}> + $<$: ${include_asm_DIRS}> -# Add lwmem to the project -add_subdirectory("../../../lwmem" lwmem) -target_link_libraries(${EXECUTABLE} lwmem) + # Configuration specific + $<$: > + $<$: > +) # Compiler and linker options target_compile_options(${EXECUTABLE} PRIVATE @@ -109,18 +182,29 @@ target_compile_options(${EXECUTABLE} PRIVATE -Wextra -Wpedantic -Wno-unused-parameter + $<$: + + > $<$: - -Wno-volatile - -Wold-style-cast - -Wuseless-cast - -Wsuggest-override> - $<$:-Og -g3 -ggdb> - $<$:-Og -g0> - ) + #-Wno-volatile + #-Wold-style-cast + #-Wuseless-cast + #-Wsuggest-override + > + $<$: + + > + $<$: + -Og -g3 -ggdb + > + $<$: + -Og -g0 + > +) # Setup linker parameters target_link_options(${EXECUTABLE} PRIVATE - -T${MCU_LINKER_SCRIPT} + -T${MCU_LINKER_SCRIPT}${linker_script_SRC} ${CPU_PARAMETERS} -Wl,-Map=${CMAKE_PROJECT_NAME}.map --specs=nosys.specs @@ -130,16 +214,22 @@ target_link_options(${EXECUTABLE} PRIVATE -lstdc++ -lsupc++ -Wl,--end-group - -Wl,--print-memory-usage) + -Wl,--print-memory-usage +) # Execute post-build to print size add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND ${CMAKE_SIZE} $) + COMMAND ${CMAKE_SIZE} $ +) # Convert output to hex and binary add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} -O ihex $ ${EXECUTABLE}.hex) + COMMAND ${CMAKE_OBJCOPY} -O ihex $ ${EXECUTABLE}.hex +) # Conver to bin file -> add conditional check? add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} -O binary $ ${EXECUTABLE}.bin) \ No newline at end of file + COMMAND ${CMAKE_OBJCOPY} -O binary $ ${EXECUTABLE}.bin +) + +message("Exiting ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt") \ No newline at end of file diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/gcc-arm-none-eabi.cmake b/examples/stm32/lwmem_rtos_stm32l496_discovery/gcc-arm-none-eabi.cmake new file mode 100644 index 0000000..3577ff8 --- /dev/null +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/gcc-arm-none-eabi.cmake @@ -0,0 +1,20 @@ +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR arm) + +# Some default GCC settings +# arm-none-eabi- must be part of path environment +set(TOOLCHAIN_PREFIX arm-none-eabi-) +set(FLAGS "-fdata-sections -ffunction-sections --specs=nano.specs -Wl,--gc-sections") +set(CPP_FLAGS "-fno-rtti -fno-exceptions -fno-threadsafe-statics") + +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc ${FLAGS}) +set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++ ${FLAGS} ${CPP_FLAGS}) +set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy) +set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size) + +set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf") +set(CMAKE_EXECUTABLE_SUFFIX_C ".elf") +set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf") + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/.cortex-debug.registers.state.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/.cortex-debug.registers.state.json deleted file mode 100644 index 0637a08..0000000 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/.cortex-debug.registers.state.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json index d29a816..954cb6b 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json @@ -2,25 +2,15 @@ "version": 4, "configurations": [ { - "name": "Win32", - "includePath": [ - "${workspaceFolder}", - "${workspaceFolder}\\inc", - "${workspaceFolder}\\..\\..\\lib\\st\\STM32L4xx_HAL_Driver\\Inc", - "${workspaceFolder}\\..\\..\\lib\\st\\CMSIS\\Device\\ST\\STM32L4xx\\Include", - "${workspaceFolder}\\..\\..\\lib\\st\\CMSIS\\include", - "${workspaceFolder}\\..\\..\\..\\lwmem\\src\\include", - ], - "defines": [ - "__weak=__attribute__((weak))", - "__packed=__attribute__((__packed__))", - "STM32L496xx", - "USE_FULL_LL_DRIVER" - ], - "compilerPath": "c:\\msys64\\mingw64\\bin\\gcc.exe", + "name": "STM32", + "includePath": [], + "defines": [], + "compilerPath": "", "cStandard": "gnu17", "cppStandard": "gnu++14", - "intelliSenseMode": "windows-gcc-x86", + "intelliSenseMode": "${default}", + + /* Use this and all the include paths will come from CMake configuration instead */ "configurationProvider": "ms-vscode.cmake-tools" } ] diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/cmake-kits.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/cmake-kits.json index 0450cc9..4bc2d1b 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/cmake-kits.json +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/cmake-kits.json @@ -1,10 +1,10 @@ [ { - "name": "GCC 10.3.1 arm-none-eabi", + "name": "GCC arm-none-eabi - custom toolchain setup", "compilers": { "C": "arm-none-eabi-gcc", "CXX": "arm-none-eabi-g++" }, - "toolchainFile": "../../../cmake/gcc-arm-none-eabi.cmake" + "toolchainFile": "gcc-arm-none-eabi.cmake" } - ] \ No newline at end of file +] \ No newline at end of file diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json index e418d0e..b2edf8e 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json @@ -5,20 +5,28 @@ "version": "0.2.0", "configurations": [ { + "name": "Debug Microcontroller - STLink-V3", "cwd": "${workspaceFolder}", - "executable": "build/lwmem_l496vg.elf", - "name": "Debug Microcontroller", - "request": "launch", "type": "cortex-debug", + "executable": "${command:cmake.launchTargetPath}", //or fixed file path: build/stm32h735g-dk-led.elf + "request": "launch", //Use "attach" to connect to target w/o elf download "servertype": "stlink", - "serverpath": "c:/ST/STM32CubeIDE_1.0.2/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.win32_2.0.100.202109301221/tools/bin/ST-LINK_gdbserver.exe", - "armToolchainPath": "d:/_WORK/gcc-arm-none-eabi/10.3-2021.10/bin", - "device": "STM32L496VG", + "device": "STM32H735IG", //MCU used "interface": "swd", - "serialNumber": "", // add J-Link serial number if having multiple attached the same time. + "serialNumber": "", //Set ST-Link ID if you use multiple at the same time "runToMain": true, - "svdFile": "", - "v1": false + "svdFile": "STM32H73x.svd", //SVD file to see reisters + "v1": false, + "showDevDebugOutput": true, + + /* Will get automatically detected if STM32CubeIDE is installed to default directory + or it can be manually provided if necessary.. */ + //"serverpath": "c:\\ST\\STM32CubeIDE_1.7.0\\STM32CubeIDE\\plugins\\com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.win32_2.0.100.202109301221\\tools\\bin\\ST-LINK_gdbserver.exe", + //"armToolchainPath": "c:\\ST\\STM32CubeIDE_1.7.0\\STM32CubeIDE\\plugins\\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\\tools\\bin", + //"stm32cubeprogrammer": "c:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeProgrammer\\bin", + + /* If you use external loader, add additional arguments */ + //"serverArgs": ["--extload", "path/to/ext/loader.stldr"], } ] } \ No newline at end of file diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/settings.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/settings.json deleted file mode 100644 index b068dd8..0000000 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "files.associations": { - "main.h": "c", - "stm32l4xx_ll_usart.h": "c" - } -} \ No newline at end of file diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json index 35a0995..1c61742 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json @@ -1,13 +1,5 @@ { "version": "2.0.0", - - /* For this builds, you need - * - * - Ninja build system - * - MSYS2 compiler with ninja support - * - C/C++ extension for VSCode - * - CMake-Tools extension for VSCode - */ "tasks": [ { "type": "cppbuild", @@ -43,5 +35,22 @@ }, "problemMatcher": [] }, + { + "type": "shell", + "label": "Run CMake configuration", + "command": "cmake", + "args": [ + "--no-warn-unused-cli", + "-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE", + "-DCMAKE_BUILD_TYPE:STRING=Debug", + "-DCMAKE_TOOLCHAIN_FILE:FILEPATH=gcc-arm-none-eabi.cmake", + "-Bbuild", + "-G", "Ninja" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + } ] -} \ No newline at end of file +} diff --git a/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt b/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt index e6415bb..4746748 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt +++ b/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt @@ -1,85 +1,162 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.22) -# ############################################################################## -# Edit your MCU information up to the next border -project(lwmem_l496vg) -set(PROJECT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +message("Entering ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt") -set(MCU_FAMILY STM32L4xx) -set(MCU_MODEL STM32L496xx) +# +# Core project settings +# +set(PROJ_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +project(lwmem_stm32l496g_discovery) +enable_language(C CXX ASM) +message("Build type: " ${CMAKE_BUILD_TYPE}) + +# Setup compiler settings +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS ON) +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS ON) + +# +# Core MCU flags, CPU, instruction set and FPU setup +# set(CPU_PARAMETERS - -mcpu=cortex-m4 -mthumb + -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard - ) +) -# Set startup and linker script -set(STARTUP_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/STM32CubeIDE/startup/startup_stm32l496xx.s) -set(MCU_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/STM32CubeIDE/Debug_STM32L496AG_FLASH.ld) - -# ############################################################################## -set(EXECUTABLE ${CMAKE_PROJECT_NAME}) -enable_language(C CXX ASM) -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS ON) - -# Include headers -set(st_cube_include_DIRS - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/${MCU_FAMILY}_HAL_Driver/Inc - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/${MCU_FAMILY}_HAL_Driver/Inc/Legacy - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/CMSIS/Device/ST/${MCU_FAMILY}/Include - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/CMSIS/include - ) -set(project_include_DIRS - ${CMAKE_CURRENT_SOURCE_DIR}/inc - ) +# Set linker script +set(linker_script_SRC ${PROJ_PATH}/STM32CubeIDE/Debug_STM32L496AG_FLASH.ld) +set(EXECUTABLE ${CMAKE_PROJECT_NAME}) +# # Source files -set(st_cube_SRCS - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_dma.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_exti.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_gpio.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_pwr.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_rcc.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_usart.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_utils.c - ) -set(project_SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/stm32l4xx_it.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/syscalls.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/system_stm32l4xx.c - ) +# +set(linked_SRCS + ${PROJ_PATH}/../../../lwmem/src/lwmem/lwmem.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_dma.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_exti.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_gpio.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_pwr.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_rcc.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_usart.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_utils.c + ${PROJ_PATH}/src/main.c + ${PROJ_PATH}/src/stm32l4xx_it.c + ${PROJ_PATH}/src/syscalls.c + ${PROJ_PATH}/src/system_stm32l4xx.c +) +set(source_folder_LwMEM_SRCS + ) + +set(source_folder_STM32L4xx_HAL_Drivers_SRCS + ) + +set(source_folder_User_SRCS + ) + +set(source_folder_startup_SRCS + ${PROJ_PATH}/STM32CubeIDE/startup/startup_stm32l496xx.s) + +# Source files in the same path as ".cproject/.project" but nowhere included in file descriptions +set(all_project_dir_SRCS + +) +# +# Include directories +# +set(include_c_DIRS + ${PROJ_PATH}/inc + ${PROJ_PATH}/../../../lwmem/src/include + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Inc + ${PROJ_PATH}/../../lib/st/CMSIS/Device/ST/STM32L4xx/Include + ${PROJ_PATH}/../../lib/st/CMSIS/Include +) +set(include_cxx_DIRS + +) +set(include_asm_DIRS + +) + +# +# Symbols definition +# +set(symbols_c_SYMB + "__weak=__attribute__((weak))" + "__packed=__attribute__((__packed__))" + "USE_FULL_LL_DRIVER" + "STM32L496xx" +) +set(symbols_cxx_SYMB + "STM32F10X_MD" + "USE_STDPERIPH_DRIVER" +) +set(symbols_asm_SYMB + +) + +# +# Link directories setup +# Must be before executable is added +# +set(link_DIRS + +) +link_directories(${EXECUTABLE} ${link_DIRS}) + +# # Executable files +# add_executable(${EXECUTABLE} - ${st_cube_SRCS} - ${project_SOURCES} - ${STARTUP_SCRIPT} - ) + ${linked_SRCS} + ${all_project_dir_SRCS} + ${source_folder_LwMEM_SRCS} + ${source_folder_STM32L4xx_HAL_Drivers_SRCS} + ${source_folder_User_SRCS} + ${source_folder_startup_SRCS}) + +# +# Add linked libraries for linker +# +set(link_LIBS + +) +target_link_libraries(${EXECUTABLE} ${link_LIBS}) -# Embedded macros(defines) +# +# Project symbols +# target_compile_definitions(${EXECUTABLE} PRIVATE - "__weak=__attribute__((weak))" - "__packed=__attribute__((__packed__))" - ${MCU_MODEL} - USE_FULL_LL_DRIVER - ) + # Language specific only + $<$: ${symbols_c_SYMB}> + $<$: ${symbols_cxx_SYMB}> + $<$: ${symbols_asm_SYMB}> + + # Configuration specific + $<$: + DEBUG + > + $<$: > +) -# Add header directories (AFTER add_executable !!) +# +# Add include paths for each of the compiler +# target_include_directories(${EXECUTABLE} PRIVATE - ${st_cube_include_DIRS} - ${project_include_DIRS} - ) + # Language specific only + $<$: ${include_c_DIRS}> + $<$: ${include_cxx_DIRS}> + $<$: ${include_asm_DIRS}> -# Add lwmem to the project -add_subdirectory("../../../lwmem" lwmem) -target_link_libraries(${EXECUTABLE} lwmem) + # Configuration specific + $<$: > + $<$: > +) # Compiler and linker options target_compile_options(${EXECUTABLE} PRIVATE @@ -88,18 +165,29 @@ target_compile_options(${EXECUTABLE} PRIVATE -Wextra -Wpedantic -Wno-unused-parameter + $<$: + + > $<$: - -Wno-volatile - -Wold-style-cast - -Wuseless-cast - -Wsuggest-override> - $<$:-Og -g3 -ggdb> - $<$:-Og -g0> - ) + #-Wno-volatile + #-Wold-style-cast + #-Wuseless-cast + #-Wsuggest-override + > + $<$: + + > + $<$: + -Og -g3 -ggdb + > + $<$: + -Og -g0 + > +) # Setup linker parameters target_link_options(${EXECUTABLE} PRIVATE - -T${MCU_LINKER_SCRIPT} + -T${MCU_LINKER_SCRIPT}${linker_script_SRC} ${CPU_PARAMETERS} -Wl,-Map=${CMAKE_PROJECT_NAME}.map --specs=nosys.specs @@ -109,16 +197,22 @@ target_link_options(${EXECUTABLE} PRIVATE -lstdc++ -lsupc++ -Wl,--end-group - -Wl,--print-memory-usage) + -Wl,--print-memory-usage +) # Execute post-build to print size add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND ${CMAKE_SIZE} $) + COMMAND ${CMAKE_SIZE} $ +) # Convert output to hex and binary add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} -O ihex $ ${EXECUTABLE}.hex) + COMMAND ${CMAKE_OBJCOPY} -O ihex $ ${EXECUTABLE}.hex +) # Conver to bin file -> add conditional check? add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} -O binary $ ${EXECUTABLE}.bin) \ No newline at end of file + COMMAND ${CMAKE_OBJCOPY} -O binary $ ${EXECUTABLE}.bin +) + +message("Exiting ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt") \ No newline at end of file diff --git a/examples/stm32/lwmem_stm32l496_discovery/gcc-arm-none-eabi.cmake b/examples/stm32/lwmem_stm32l496_discovery/gcc-arm-none-eabi.cmake new file mode 100644 index 0000000..3577ff8 --- /dev/null +++ b/examples/stm32/lwmem_stm32l496_discovery/gcc-arm-none-eabi.cmake @@ -0,0 +1,20 @@ +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR arm) + +# Some default GCC settings +# arm-none-eabi- must be part of path environment +set(TOOLCHAIN_PREFIX arm-none-eabi-) +set(FLAGS "-fdata-sections -ffunction-sections --specs=nano.specs -Wl,--gc-sections") +set(CPP_FLAGS "-fno-rtti -fno-exceptions -fno-threadsafe-statics") + +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc ${FLAGS}) +set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++ ${FLAGS} ${CPP_FLAGS}) +set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy) +set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size) + +set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf") +set(CMAKE_EXECUTABLE_SUFFIX_C ".elf") +set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf") + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) From 8f0e2f28fcc331397eb7be4ca9c526cbef7cce31 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sat, 8 Jan 2022 00:10:51 +0100 Subject: [PATCH 19/73] Update launch.json --- .../lwmem_rtos_stm32l496_discovery/.vscode/launch.json | 6 +++--- .../stm32/lwmem_stm32l496_discovery/.vscode/launch.json | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json index b2edf8e..381987f 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json @@ -8,14 +8,14 @@ "name": "Debug Microcontroller - STLink-V3", "cwd": "${workspaceFolder}", "type": "cortex-debug", - "executable": "${command:cmake.launchTargetPath}", //or fixed file path: build/stm32h735g-dk-led.elf + "executable": "${command:cmake.launchTargetPath}", //or fixed file path: build/project-name.elf "request": "launch", //Use "attach" to connect to target w/o elf download "servertype": "stlink", - "device": "STM32H735IG", //MCU used + "device": "STM32L496AG", //MCU used "interface": "swd", "serialNumber": "", //Set ST-Link ID if you use multiple at the same time "runToMain": true, - "svdFile": "STM32H73x.svd", //SVD file to see reisters + "svdFile": "", //SVD file to see registers "v1": false, "showDevDebugOutput": true, diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json index b2edf8e..381987f 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json @@ -8,14 +8,14 @@ "name": "Debug Microcontroller - STLink-V3", "cwd": "${workspaceFolder}", "type": "cortex-debug", - "executable": "${command:cmake.launchTargetPath}", //or fixed file path: build/stm32h735g-dk-led.elf + "executable": "${command:cmake.launchTargetPath}", //or fixed file path: build/project-name.elf "request": "launch", //Use "attach" to connect to target w/o elf download "servertype": "stlink", - "device": "STM32H735IG", //MCU used + "device": "STM32L496AG", //MCU used "interface": "swd", "serialNumber": "", //Set ST-Link ID if you use multiple at the same time "runToMain": true, - "svdFile": "STM32H73x.svd", //SVD file to see reisters + "svdFile": "", //SVD file to see registers "v1": false, "showDevDebugOutput": true, From 577732d3b0e197e8029ced241cf1a439ee89f77a Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sat, 8 Jan 2022 15:43:57 +0100 Subject: [PATCH 20/73] Add main.cpp --- dev/main.c | 14 ------- dev/main.cpp | 87 +++++++++++++++++++++++++++++++++++++++++ lwmem/src/lwmem/lwmem.c | 2 +- 3 files changed, 88 insertions(+), 15 deletions(-) delete mode 100644 dev/main.c create mode 100644 dev/main.cpp diff --git a/dev/main.c b/dev/main.c deleted file mode 100644 index bd363c5..0000000 --- a/dev/main.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "lwmem/lwmem.h" -#include -#include - -extern void lwmem_test_run(void); -extern void lwmem_test_memory_structure(void); - -int -main(void) { - lwmem_test_memory_structure(); - //lwmem_test_run(); - return 0; -} diff --git a/dev/main.cpp b/dev/main.cpp new file mode 100644 index 0000000..804acae --- /dev/null +++ b/dev/main.cpp @@ -0,0 +1,87 @@ +#include +#include "lwmem/lwmem.h" +#include +#include + +extern "C" void lwmem_test_run(void); +extern "C" void lwmem_test_memory_structure(void); + +namespace Lwmem { + +class Lwmem { +public: + Lwmem(const lwmem_region_t* regions = nullptr) { + if (regions != nullptr + && lwmem_assignmem_ex(&m_lw, m_regions)) { + m_regions = regions; + } + } + + uint8_t + set_regions(const lwmem_region_t* regions) { + if (m_regions == nullptr && regions != nullptr + && lwmem_assignmem_ex(&m_lw, m_regions)) { + m_regions = regions; + return 1; + } + return 0; + } + + void* + malloc_ex(const lwmem_region_t* region, size_t size) { + return lwmem_malloc_ex(&m_lw, region, size); + } + void* + malloc(size_t size) { + return malloc_ex(NULL, size); + } + void* + calloc_ex(const lwmem_region_t* region, size_t nitems, size_t size) { + return lwmem_calloc_ex(&m_lw, region, nitems, size); + } + void* + calloc(size_t nitems, size_t size) { + return calloc_ex(NULL, nitems, size); + } + void* + realloc_ex(const lwmem_region_t* region, void* ptr, size_t size) { + return lwmem_realloc_ex(&m_lw, region, ptr, size); + } + void* + realloc(void* ptr, size_t size) { + return realloc_ex(NULL, ptr, size); + } + + void + free(void* ptr) { + lwmem_free_ex(&m_lw, ptr); + } + +private: + /* Delete unused constructors */ + Lwmem() = delete; + Lwmem(const Lwmem& other) = delete; + /* Delete copy assignment operators */ + Lwmem& operator=(const Lwmem& other) = delete; + Lwmem* operator=(const Lwmem* other) = delete; + + lwmem_t m_lw; + const lwmem_region_t* m_regions = nullptr; +}; + +}; + +int +main(void) { + lwmem_test_memory_structure(); + //lwmem_test_run(); + + Lwmem::Lwmem manager(nullptr); + void* ret = manager.malloc(123); + + /* blablablabla */ + + manager.free(ret); + + return 0; +} diff --git a/lwmem/src/lwmem/lwmem.c b/lwmem/src/lwmem/lwmem.c index 67f369e..a3b798d 100644 --- a/lwmem/src/lwmem/lwmem.c +++ b/lwmem/src/lwmem/lwmem.c @@ -1037,7 +1037,7 @@ print_block(size_t i, lwmem_block_t* block) { printf("| %5d | %16p | %6d | %4d | %16d |", (int)i, - block, + (void *)block, (int)is_free, (int)block_size, (int)(is_free ? (block_size - LWMEM_BLOCK_META_SIZE) : 0)); From bb9afc207de5f91ffb045f3196668b71802647c7 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sat, 8 Jan 2022 15:44:18 +0100 Subject: [PATCH 21/73] Update cmakelists --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index deb93f2..6f240af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ add_executable(${PROJECT_NAME}) # Add key executable block target_sources(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/dev/main.c + ${CMAKE_CURRENT_LIST_DIR}/dev/main.cpp ${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c # win32 port From 261c7edbaaf41c469f0440d3bf158ac213766717 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sat, 8 Jan 2022 16:12:49 +0100 Subject: [PATCH 22/73] Add C++ wrapper --- CHANGELOG.md | 1 + CMakeLists.txt | 1 + README.md | 1 + dev/main.cpp | 73 ++-------------- docs/index.rst | 1 + lwmem/CMakeLists.txt | 5 ++ lwmem/src/include/lwmem/lwmem.hpp | 139 ++++++++++++++++++++++++++++++ lwmem/src/lwmem/lwmem.cpp | 33 +++++++ 8 files changed, 187 insertions(+), 67 deletions(-) create mode 100644 lwmem/src/include/lwmem/lwmem.hpp create mode 100644 lwmem/src/lwmem/lwmem.cpp diff --git a/CHANGELOG.md b/CHANGELOG.md index 20cbb12..96a8256 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Develop - Split CMakeLists.txt files between library and executable +- Add C++ wrapper functions ## v2.0.0 diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f240af..393a30b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,3 +51,4 @@ target_compile_options(${PROJECT_NAME} PRIVATE # Add subdir with lwmem and link to the project add_subdirectory("lwmem") target_link_libraries(${PROJECT_NAME} lwmem) +target_link_libraries(${PROJECT_NAME} lwmem_cpp) diff --git a/README.md b/README.md index 3feb20a..4b81873 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ * Supports automotive applications * Supports advanced free/realloc algorithms to optimize memory usage * Operating system ready, thread-safe API +* C++ wrapper functions * User friendly MIT license ## Contribute diff --git a/dev/main.cpp b/dev/main.cpp index 804acae..bddf070 100644 --- a/dev/main.cpp +++ b/dev/main.cpp @@ -1,84 +1,23 @@ -#include #include "lwmem/lwmem.h" +#include "lwmem/lwmem.hpp" #include #include +#include extern "C" void lwmem_test_run(void); extern "C" void lwmem_test_memory_structure(void); -namespace Lwmem { - -class Lwmem { -public: - Lwmem(const lwmem_region_t* regions = nullptr) { - if (regions != nullptr - && lwmem_assignmem_ex(&m_lw, m_regions)) { - m_regions = regions; - } - } - - uint8_t - set_regions(const lwmem_region_t* regions) { - if (m_regions == nullptr && regions != nullptr - && lwmem_assignmem_ex(&m_lw, m_regions)) { - m_regions = regions; - return 1; - } - return 0; - } - - void* - malloc_ex(const lwmem_region_t* region, size_t size) { - return lwmem_malloc_ex(&m_lw, region, size); - } - void* - malloc(size_t size) { - return malloc_ex(NULL, size); - } - void* - calloc_ex(const lwmem_region_t* region, size_t nitems, size_t size) { - return lwmem_calloc_ex(&m_lw, region, nitems, size); - } - void* - calloc(size_t nitems, size_t size) { - return calloc_ex(NULL, nitems, size); - } - void* - realloc_ex(const lwmem_region_t* region, void* ptr, size_t size) { - return lwmem_realloc_ex(&m_lw, region, ptr, size); - } - void* - realloc(void* ptr, size_t size) { - return realloc_ex(NULL, ptr, size); - } - - void - free(void* ptr) { - lwmem_free_ex(&m_lw, ptr); - } - -private: - /* Delete unused constructors */ - Lwmem() = delete; - Lwmem(const Lwmem& other) = delete; - /* Delete copy assignment operators */ - Lwmem& operator=(const Lwmem& other) = delete; - Lwmem* operator=(const Lwmem* other) = delete; - - lwmem_t m_lw; - const lwmem_region_t* m_regions = nullptr; -}; - -}; +Lwmem::LwmemLight<1024> manager; int main(void) { - lwmem_test_memory_structure(); + //lwmem_test_memory_structure(); //lwmem_test_run(); - Lwmem::Lwmem manager(nullptr); void* ret = manager.malloc(123); + std::cout << ret << std::endl; + /* blablablabla */ manager.free(ret); diff --git a/docs/index.rst b/docs/index.rst index 6c78805..5849552 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -26,6 +26,7 @@ Features * Supports automotive applications * Supports advanced free/realloc algorithms to optimize memory usage * Operating system ready, thread-safe API +* C++ wrapper functions * User friendly MIT license Requirements diff --git a/lwmem/CMakeLists.txt b/lwmem/CMakeLists.txt index b934230..1e2f0ee 100644 --- a/lwmem/CMakeLists.txt +++ b/lwmem/CMakeLists.txt @@ -8,6 +8,11 @@ add_library(lwmem INTERFACE) target_sources(lwmem PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.c) target_include_directories(lwmem INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/include) +# Register core library with C++ extensions +add_library(lwmem_cpp INTERFACE) +target_sources(lwmem PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.c ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.cpp) +target_include_directories(lwmem INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/include) + # Register other modules # Debug message diff --git a/lwmem/src/include/lwmem/lwmem.hpp b/lwmem/src/include/lwmem/lwmem.hpp new file mode 100644 index 0000000..3ec2f2b --- /dev/null +++ b/lwmem/src/include/lwmem/lwmem.hpp @@ -0,0 +1,139 @@ +/** + * \file lwmem.hpp + * \brief Lightweight dynamic memory manager - C++ wrapper + */ + +/* + * Copyright (c) 2020 Tilen MAJERLE + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * This file is part of LwMEM - Lightweight dynamic memory manager library. + * + * Author: Tilen MAJERLE + * Version: v2.0.0 + */ +#ifndef LWMEM_HDR_HPP +#define LWMEM_HDR_HPP + +#include "lwmem/lwmem.h" + +/** + * \ingroup LWMEM + * \defgroup LWMEM_CPP C++ wrapper functions for LwMEM + * \brief C++ wrapper functions for LwMEM + * \{ + */ + + +namespace Lwmem { + +/** + * \brief LwMEM Light implementation with single memory region. + * \tparam LEN: Length of region in units of bytes + * + * This class provides C++ wrapper functions for LwMEM library. + * For detailed docs instructions, have a look at \ref lwmem.c file. + * + * Start lwmem with: + * \code{.c} +Lwmem::LwmemLight<1024> mngr; //Use 1024 bytes of data for memory operations +void* ptr = mngr.malloc(...); +... +... +mngr.free(ptr); +\endcode + */ +template +class LwmemLight { +public: + LwmemLight() { + /* Simple region descriptor with one region */ + const lwmem_region_t regions[] = { + {m_reg_data, sizeof(m_reg_data)}, + {NULL, 0} + }; + lwmem_assignmem_ex(&m_lw, regions); + } + + /** + * \brief Allocate block of memory with selected size + * \param size: Block size to allocate in units of bytes + * \return Allocated memory or `NULL` on failure + * \sa lwmem_malloc_ex + */ + void* + malloc(size_t size) { + return lwmem_malloc_ex(&m_lw, nullptr, size); + } + + /** + * \brief Allocate block of memory with selected size and cleaned to all zeros + * \param[in] nitems: Number of items to allocate + * \param size: Size of each item in units of bytes + * \return Allocated memory or `NULL` on failure + * \sa lwmem_calloc_ex + */ + void* + calloc(size_t nitems, size_t size) { + return lwmem_calloc_ex(&m_lw, nullptr, nitems, size); + } + + /** + * \brief Reallocate block of memory + * \param ptr: Pointer to previously allocated memory block + * \param size: Block size to allocate in units of bytes + * \return Allocated memory or `NULL` on failure + * \sa lwmem_realloc_ex + */ + void* + realloc(void* ptr, size_t size) { + return lwmem_realloc_ex(&m_lw, nullptr, ptr, size); + } + + /** + * \brief Free memory block + * \param ptr: Pointer to previously allocated memory block + * \sa lwmem_realloc_ex + */ + void + free(void* ptr) { + lwmem_free_ex(&m_lw, ptr); + } + +private: + /* Delete unused constructors */ + LwmemLight(const LwmemLight& other) = delete; + /* Delete copy assignment operators */ + LwmemLight& operator=(const LwmemLight& other) = delete; + LwmemLight* operator=(const LwmemLight* other) = delete; + + lwmem_t m_lw; + uint8_t m_reg_data[LEN]; +}; + +}; + +/** + * \} + */ + +#endif /* LWMEM_HDR_HPP */ diff --git a/lwmem/src/lwmem/lwmem.cpp b/lwmem/src/lwmem/lwmem.cpp new file mode 100644 index 0000000..56ed731 --- /dev/null +++ b/lwmem/src/lwmem/lwmem.cpp @@ -0,0 +1,33 @@ +/** + * \file lwmem.cpp + * \brief Lightweight dynamic memory manager - C++ wrapper + */ + +/* + * Copyright (c) 2020 Tilen MAJERLE + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * This file is part of LwMEM - Lightweight dynamic memory manager library. + * + * Author: Tilen MAJERLE + * Version: v2.0.0 + */ From cc400026c8253dd3530d56acff54a51dd24adb85 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Thu, 13 Jan 2022 20:56:29 +0100 Subject: [PATCH 23/73] Update library.json --- library.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library.json b/library.json index 01bf6ca..4e8d30c 100644 --- a/library.json +++ b/library.json @@ -28,7 +28,8 @@ "docs", "**/.vs", "**/Debug", - "build" + "build", + "**/build" ] } } \ No newline at end of file From 4e4b61912276de1bc8a60de55e51dd9f58593185 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 14 Jan 2022 23:07:44 +0100 Subject: [PATCH 24/73] Update license year to 2022 --- CHANGELOG.md | 1 + LICENSE | 2 +- dev/lwmem_opts.h | 2 +- dev/main.cpp | 8 +++----- .../stm32/lwmem_rtos_stm32l496_discovery/inc/lwmem_opts.h | 2 +- examples/stm32/lwmem_rtos_stm32l496_discovery/inc/main.h | 2 +- examples/stm32/lwmem_rtos_stm32l496_discovery/src/main.c | 2 +- examples/stm32/lwmem_stm32l496_discovery/inc/lwmem_opts.h | 2 +- examples/stm32/lwmem_stm32l496_discovery/inc/main.h | 2 +- examples/stm32/lwmem_stm32l496_discovery/src/main.c | 2 +- examples/win32/lwmem/lwmem_opts.h | 2 +- examples/win32/lwmem_multi_ins_multi_region/lwmem_opts.h | 2 +- examples/win32/lwmem_multi_region/lwmem_opts.h | 2 +- examples/win32/lwmem_os/lwmem_opts.h | 2 +- lwmem/src/include/lwmem/lwmem.h | 2 +- lwmem/src/include/lwmem/lwmem_opt.h | 2 +- lwmem/src/include/lwmem/lwmem_opts_template.h | 2 +- lwmem/src/include/system/lwmem_sys.h | 2 +- lwmem/src/lwmem/lwmem.c | 2 +- lwmem/src/system/lwmem_sys_cmsis_os.c | 2 +- lwmem/src/system/lwmem_sys_threadx.c | 2 +- lwmem/src/system/lwmem_sys_win32.c | 2 +- 22 files changed, 24 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96a8256..900b367 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Split CMakeLists.txt files between library and executable - Add C++ wrapper functions +- Change license year to 2022 ## v2.0.0 diff --git a/LICENSE b/LICENSE index aa60317..5625f63 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Tilen MAJERLE +Copyright (c) 2022 Tilen MAJERLE Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/dev/lwmem_opts.h b/dev/lwmem_opts.h index a03fa48..91db702 100644 --- a/dev/lwmem_opts.h +++ b/dev/lwmem_opts.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2020 Tilen MAJERLE + * Copyright (c) 2022 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/dev/main.cpp b/dev/main.cpp index bddf070..5356162 100644 --- a/dev/main.cpp +++ b/dev/main.cpp @@ -7,19 +7,17 @@ extern "C" void lwmem_test_run(void); extern "C" void lwmem_test_memory_structure(void); +/* Setup manager */ Lwmem::LwmemLight<1024> manager; int main(void) { - //lwmem_test_memory_structure(); + lwmem_test_memory_structure(); //lwmem_test_run(); + /* Test C++ code */ void* ret = manager.malloc(123); - std::cout << ret << std::endl; - - /* blablablabla */ - manager.free(ret); return 0; diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/inc/lwmem_opts.h b/examples/stm32/lwmem_rtos_stm32l496_discovery/inc/lwmem_opts.h index 0f929f3..c3c6151 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/inc/lwmem_opts.h +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/inc/lwmem_opts.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2020 Tilen MAJERLE + * Copyright (c) 2022 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/inc/main.h b/examples/stm32/lwmem_rtos_stm32l496_discovery/inc/main.h index 4bff3ec..a798edf 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/inc/main.h +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/inc/main.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2020 Tilen MAJERLE + * Copyright (c) 2022 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/src/main.c b/examples/stm32/lwmem_rtos_stm32l496_discovery/src/main.c index e36eb21..45f1412 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/src/main.c +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/src/main.c @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2020 Tilen MAJERLE + * Copyright (c) 2022 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/examples/stm32/lwmem_stm32l496_discovery/inc/lwmem_opts.h b/examples/stm32/lwmem_stm32l496_discovery/inc/lwmem_opts.h index 1f94312..1c9c2d1 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/inc/lwmem_opts.h +++ b/examples/stm32/lwmem_stm32l496_discovery/inc/lwmem_opts.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2020 Tilen MAJERLE + * Copyright (c) 2022 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/examples/stm32/lwmem_stm32l496_discovery/inc/main.h b/examples/stm32/lwmem_stm32l496_discovery/inc/main.h index 4bff3ec..a798edf 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/inc/main.h +++ b/examples/stm32/lwmem_stm32l496_discovery/inc/main.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2020 Tilen MAJERLE + * Copyright (c) 2022 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/examples/stm32/lwmem_stm32l496_discovery/src/main.c b/examples/stm32/lwmem_stm32l496_discovery/src/main.c index 0c47d50..8592189 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/src/main.c +++ b/examples/stm32/lwmem_stm32l496_discovery/src/main.c @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2020 Tilen MAJERLE + * Copyright (c) 2022 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/examples/win32/lwmem/lwmem_opts.h b/examples/win32/lwmem/lwmem_opts.h index 1f94312..1c9c2d1 100644 --- a/examples/win32/lwmem/lwmem_opts.h +++ b/examples/win32/lwmem/lwmem_opts.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2020 Tilen MAJERLE + * Copyright (c) 2022 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/examples/win32/lwmem_multi_ins_multi_region/lwmem_opts.h b/examples/win32/lwmem_multi_ins_multi_region/lwmem_opts.h index 1f94312..1c9c2d1 100644 --- a/examples/win32/lwmem_multi_ins_multi_region/lwmem_opts.h +++ b/examples/win32/lwmem_multi_ins_multi_region/lwmem_opts.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2020 Tilen MAJERLE + * Copyright (c) 2022 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/examples/win32/lwmem_multi_region/lwmem_opts.h b/examples/win32/lwmem_multi_region/lwmem_opts.h index 1f94312..1c9c2d1 100644 --- a/examples/win32/lwmem_multi_region/lwmem_opts.h +++ b/examples/win32/lwmem_multi_region/lwmem_opts.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2020 Tilen MAJERLE + * Copyright (c) 2022 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/examples/win32/lwmem_os/lwmem_opts.h b/examples/win32/lwmem_os/lwmem_opts.h index 8536f88..a5dcb36 100644 --- a/examples/win32/lwmem_os/lwmem_opts.h +++ b/examples/win32/lwmem_os/lwmem_opts.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2020 Tilen MAJERLE + * Copyright (c) 2022 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lwmem/src/include/lwmem/lwmem.h b/lwmem/src/include/lwmem/lwmem.h index 90c579a..8784a26 100644 --- a/lwmem/src/include/lwmem/lwmem.h +++ b/lwmem/src/include/lwmem/lwmem.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2020 Tilen MAJERLE + * Copyright (c) 2022 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lwmem/src/include/lwmem/lwmem_opt.h b/lwmem/src/include/lwmem/lwmem_opt.h index 8050d88..ae7864b 100644 --- a/lwmem/src/include/lwmem/lwmem_opt.h +++ b/lwmem/src/include/lwmem/lwmem_opt.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2020 Tilen MAJERLE + * Copyright (c) 2022 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lwmem/src/include/lwmem/lwmem_opts_template.h b/lwmem/src/include/lwmem/lwmem_opts_template.h index ccac00c..1b54393 100644 --- a/lwmem/src/include/lwmem/lwmem_opts_template.h +++ b/lwmem/src/include/lwmem/lwmem_opts_template.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2020 Tilen MAJERLE + * Copyright (c) 2022 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lwmem/src/include/system/lwmem_sys.h b/lwmem/src/include/system/lwmem_sys.h index 9afb1e0..44bdfb1 100644 --- a/lwmem/src/include/system/lwmem_sys.h +++ b/lwmem/src/include/system/lwmem_sys.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2020 Tilen MAJERLE + * Copyright (c) 2022 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lwmem/src/lwmem/lwmem.c b/lwmem/src/lwmem/lwmem.c index a3b798d..e0cce7a 100644 --- a/lwmem/src/lwmem/lwmem.c +++ b/lwmem/src/lwmem/lwmem.c @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2020 Tilen MAJERLE + * Copyright (c) 2022 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lwmem/src/system/lwmem_sys_cmsis_os.c b/lwmem/src/system/lwmem_sys_cmsis_os.c index 17bf646..c720cc2 100644 --- a/lwmem/src/system/lwmem_sys_cmsis_os.c +++ b/lwmem/src/system/lwmem_sys_cmsis_os.c @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2020 Tilen MAJERLE + * Copyright (c) 2022 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lwmem/src/system/lwmem_sys_threadx.c b/lwmem/src/system/lwmem_sys_threadx.c index 0aa2cd0..db8fa51 100644 --- a/lwmem/src/system/lwmem_sys_threadx.c +++ b/lwmem/src/system/lwmem_sys_threadx.c @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2020 Tilen MAJERLE + * Copyright (c) 2022 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lwmem/src/system/lwmem_sys_win32.c b/lwmem/src/system/lwmem_sys_win32.c index 5fdb647..449fecf 100644 --- a/lwmem/src/system/lwmem_sys_win32.c +++ b/lwmem/src/system/lwmem_sys_win32.c @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2020 Tilen MAJERLE + * Copyright (c) 2022 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation From 56a2fafa52be6283a614adec42262b38b67d3125 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sat, 15 Jan 2022 00:41:45 +0100 Subject: [PATCH 25/73] Update .vscode files --- .vscode/extensions.json | 7 +++++++ .vscode/tasks.json | 12 ++---------- .../.vscode/extensions.json | 10 ++++++++++ .../.vscode/launch.json | 2 +- .../.vscode/tasks.json | 4 ++-- .../.vscode/extensions.json | 10 ++++++++++ .../lwmem_stm32l496_discovery/.vscode/launch.json | 2 +- .../lwmem_stm32l496_discovery/.vscode/tasks.json | 4 ++-- 8 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 .vscode/extensions.json create mode 100644 examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/extensions.json create mode 100644 examples/stm32/lwmem_stm32l496_discovery/.vscode/extensions.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..6a07920 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "ms-vscode.cpptools", + "ms-vscode.cmake-tools", + "twxs.cmake", + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 309d100..a4527df 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,19 +1,11 @@ { "version": "2.0.0", - - /* For this builds, you need - * - * - Ninja build system - * - MSYS2 compiler with ninja support - * - C/C++ extension for VSCode - * - CMake-Tools extension for VSCode - */ "tasks": [ { "type": "cppbuild", "label": "Build project", "command": "cmake", - "args": ["--build", "\"build\""], + "args": ["--build", "\"build\"", "-j", "8"], "options": { "cwd": "${workspaceFolder}" }, @@ -27,7 +19,7 @@ "type": "shell", "label": "Re-build project", "command": "cmake", - "args": ["--build", "\"build\"", "--clean-first", "-v"], + "args": ["--build", "\"build\"", "--clean-first", "-v", "-j", "8"], "options": { "cwd": "${workspaceFolder}" }, diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/extensions.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/extensions.json new file mode 100644 index 0000000..6cb8e03 --- /dev/null +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + "recommendations": [ + "ms-vscode.cpptools", + "ms-vscode.cmake-tools", + "marus25.cortex-debug", + "twxs.cmake", + "dan-c-underwood.arm", + "zixuanwang.linkerscript" + ] +} \ No newline at end of file diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json index 381987f..4ab494e 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json @@ -5,7 +5,7 @@ "version": "0.2.0", "configurations": [ { - "name": "Debug Microcontroller - STLink-V3", + "name": "Debug Microcontroller - ST-Link", "cwd": "${workspaceFolder}", "type": "cortex-debug", "executable": "${command:cmake.launchTargetPath}", //or fixed file path: build/project-name.elf diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json index 1c61742..3044733 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json @@ -5,7 +5,7 @@ "type": "cppbuild", "label": "Build project", "command": "cmake", - "args": ["--build", "\"build\""], + "args": ["--build", "\"build\"", "-j", "8"], "options": { "cwd": "${workspaceFolder}" }, @@ -19,7 +19,7 @@ "type": "shell", "label": "Re-build project", "command": "cmake", - "args": ["--build", "\"build\"", "--clean-first", "-v"], + "args": ["--build", "\"build\"", "--clean-first", "-v", "-j", "8"], "options": { "cwd": "${workspaceFolder}" }, diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/extensions.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/extensions.json new file mode 100644 index 0000000..6cb8e03 --- /dev/null +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + "recommendations": [ + "ms-vscode.cpptools", + "ms-vscode.cmake-tools", + "marus25.cortex-debug", + "twxs.cmake", + "dan-c-underwood.arm", + "zixuanwang.linkerscript" + ] +} \ No newline at end of file diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json index 381987f..4ab494e 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json @@ -5,7 +5,7 @@ "version": "0.2.0", "configurations": [ { - "name": "Debug Microcontroller - STLink-V3", + "name": "Debug Microcontroller - ST-Link", "cwd": "${workspaceFolder}", "type": "cortex-debug", "executable": "${command:cmake.launchTargetPath}", //or fixed file path: build/project-name.elf diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json index 1c61742..3044733 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json @@ -5,7 +5,7 @@ "type": "cppbuild", "label": "Build project", "command": "cmake", - "args": ["--build", "\"build\""], + "args": ["--build", "\"build\"", "-j", "8"], "options": { "cwd": "${workspaceFolder}" }, @@ -19,7 +19,7 @@ "type": "shell", "label": "Re-build project", "command": "cmake", - "args": ["--build", "\"build\"", "--clean-first", "-v"], + "args": ["--build", "\"build\"", "--clean-first", "-v", "-j", "8"], "options": { "cwd": "${workspaceFolder}" }, From 1c998584cca798227d091b8cfa51670fca04d971 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sat, 15 Jan 2022 16:28:50 +0100 Subject: [PATCH 26/73] Update CMakeLists.txt with automatic converter from CubeIDE --- .../CMakeLists.txt | 61 ++++++++----------- .../lwmem_stm32l496_discovery/CMakeLists.txt | 50 +++++++-------- 2 files changed, 47 insertions(+), 64 deletions(-) diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt b/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt index 6456d53..c55a36f 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt @@ -23,9 +23,11 @@ set(CMAKE_CXX_EXTENSIONS ON) # set(CPU_PARAMETERS -mthumb + # Other parameters + # -mcpu, -mfloat, -mfloat-abi, ... -mcpu=cortex-m4 - -mfpu=fpv4-sp-d16 - -mfloat-abi=hard + -mfpu=fpv4-sp-d16 + -mfloat-abi=hard ) # Set linker script @@ -35,8 +37,8 @@ set(EXECUTABLE ${CMAKE_PROJECT_NAME}) # # Source files # -set(linked_SRCS - ${PROJ_PATH}/../../lib/FreeRTOS/CMSIS_RTOS_V2/cmsis_os2.c +set(src_freertos_SRCS + ${PROJ_PATH}/../../lib/FreeRTOS/CMSIS_RTOS_V2/cmsis_os2.c ${PROJ_PATH}/../../lib/FreeRTOS/croutine.c ${PROJ_PATH}/../../lib/FreeRTOS/event_groups.c ${PROJ_PATH}/../../lib/FreeRTOS/portable/MemMang/heap_4.c @@ -44,41 +46,30 @@ set(linked_SRCS ${PROJ_PATH}/../../lib/FreeRTOS/portable/GCC/ARM_CM4F/port.c ${PROJ_PATH}/../../lib/FreeRTOS/queue.c ${PROJ_PATH}/../../lib/FreeRTOS/tasks.c - ${PROJ_PATH}/../../lib/FreeRTOS/timers.c + ${PROJ_PATH}/../../lib/FreeRTOS/timers.c) + +set(src_lwmem_SRCS ${PROJ_PATH}/../../../lwmem/src/lwmem/lwmem.c - ${PROJ_PATH}/../../../lwmem/src/system/lwmem_sys_cmsis_os.c + ${PROJ_PATH}/../../../lwmem/src/system/lwmem_sys_cmsis_os.c) + +set(src_stm32l4xx_hal_drivers_SRCS ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_dma.c ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_exti.c ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_gpio.c ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_pwr.c ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_rcc.c ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_usart.c - ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_utils.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_utils.c) + +set(src_user_SRCS ${PROJ_PATH}/src/main.c ${PROJ_PATH}/src/stm32l4xx_it.c ${PROJ_PATH}/src/syscalls.c - ${PROJ_PATH}/src/system_stm32l4xx.c -) -set(source_folder_FreeRTOS_SRCS - ) - -set(source_folder_LwMEM_SRCS - ) - -set(source_folder_STM32L4xx_HAL_Drivers_SRCS - ) + ${PROJ_PATH}/src/system_stm32l4xx.c) -set(source_folder_User_SRCS - ) - -set(source_folder_startup_SRCS +set(src_startup_SRCS ${PROJ_PATH}/STM32CubeIDE/startup/startup_stm32l496xx.s) -# Source files in the same path as ".cproject/.project" but nowhere included in file descriptions -set(all_project_dir_SRCS - -) - # # Include directories # @@ -128,14 +119,12 @@ link_directories(${EXECUTABLE} ${link_DIRS}) # # Executable files # -add_executable(${EXECUTABLE} - ${linked_SRCS} - ${all_project_dir_SRCS} - ${source_folder_FreeRTOS_SRCS} - ${source_folder_LwMEM_SRCS} - ${source_folder_STM32L4xx_HAL_Drivers_SRCS} - ${source_folder_User_SRCS} - ${source_folder_startup_SRCS}) +add_executable(${EXECUTABLE} + ${src_freertos_SRCS} + ${src_lwmem_SRCS} + ${src_stm32l4xx_hal_drivers_SRCS} + ${src_user_SRCS} + ${src_startup_SRCS}) # # Add linked libraries for linker @@ -192,7 +181,9 @@ target_compile_options(${EXECUTABLE} PRIVATE #-Wsuggest-override > $<$: - + -x assembler-with-cpp + -MMD + -MP > $<$: -Og -g3 -ggdb diff --git a/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt b/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt index 4746748..239e817 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt +++ b/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt @@ -23,9 +23,11 @@ set(CMAKE_CXX_EXTENSIONS ON) # set(CPU_PARAMETERS -mthumb + # Other parameters + # -mcpu, -mfloat, -mfloat-abi, ... -mcpu=cortex-m4 - -mfpu=fpv4-sp-d16 - -mfloat-abi=hard + -mfpu=fpv4-sp-d16 + -mfloat-abi=hard ) # Set linker script @@ -35,37 +37,27 @@ set(EXECUTABLE ${CMAKE_PROJECT_NAME}) # # Source files # -set(linked_SRCS - ${PROJ_PATH}/../../../lwmem/src/lwmem/lwmem.c +set(src_lwmem_SRCS + ${PROJ_PATH}/../../../lwmem/src/lwmem/lwmem.c) + +set(src_stm32l4xx_hal_drivers_SRCS ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_dma.c ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_exti.c ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_gpio.c ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_pwr.c ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_rcc.c ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_usart.c - ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_utils.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_utils.c) + +set(src_user_SRCS ${PROJ_PATH}/src/main.c ${PROJ_PATH}/src/stm32l4xx_it.c ${PROJ_PATH}/src/syscalls.c - ${PROJ_PATH}/src/system_stm32l4xx.c -) -set(source_folder_LwMEM_SRCS - ) - -set(source_folder_STM32L4xx_HAL_Drivers_SRCS - ) - -set(source_folder_User_SRCS - ) + ${PROJ_PATH}/src/system_stm32l4xx.c) -set(source_folder_startup_SRCS +set(src_startup_SRCS ${PROJ_PATH}/STM32CubeIDE/startup/startup_stm32l496xx.s) -# Source files in the same path as ".cproject/.project" but nowhere included in file descriptions -set(all_project_dir_SRCS - -) - # # Include directories # @@ -112,13 +104,11 @@ link_directories(${EXECUTABLE} ${link_DIRS}) # # Executable files # -add_executable(${EXECUTABLE} - ${linked_SRCS} - ${all_project_dir_SRCS} - ${source_folder_LwMEM_SRCS} - ${source_folder_STM32L4xx_HAL_Drivers_SRCS} - ${source_folder_User_SRCS} - ${source_folder_startup_SRCS}) +add_executable(${EXECUTABLE} + ${src_lwmem_SRCS} + ${src_stm32l4xx_hal_drivers_SRCS} + ${src_user_SRCS} + ${src_startup_SRCS}) # # Add linked libraries for linker @@ -175,7 +165,9 @@ target_compile_options(${EXECUTABLE} PRIVATE #-Wsuggest-override > $<$: - + -x assembler-with-cpp + -MMD + -MP > $<$: -Og -g3 -ggdb From d0af3abbc1ae2ed900e6d2e7db832d565b138664 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Tue, 18 Jan 2022 22:35:33 +0100 Subject: [PATCH 27/73] Update CMakeLists.txt to v3.22 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 393a30b..dbd12b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0.0) +cmake_minimum_required(VERSION 3.22) # Setup project project(LwLibPROJECT) From 5049ebad1c21240fd89b56c9438f368184a2c735 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Tue, 18 Jan 2022 22:41:32 +0100 Subject: [PATCH 28/73] Update CMakeLists.txt to v3.22 --- lwmem/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lwmem/CMakeLists.txt b/lwmem/CMakeLists.txt index 1e2f0ee..66cb97c 100644 --- a/lwmem/CMakeLists.txt +++ b/lwmem/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.13) +cmake_minimum_required(VERSION 3.22) # Debug message message("Entering ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt") From de2917481ddcb02d4789b188f7c8209af6cdcc17 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sun, 30 Jan 2022 10:06:37 +0100 Subject: [PATCH 29/73] Update code with astyle --- CHANGELOG.md | 1 + lwmem/src/include/system/lwmem_sys.h | 2 +- lwmem/src/lwmem/lwmem.c | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 900b367..876a5a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Split CMakeLists.txt files between library and executable - Add C++ wrapper functions - Change license year to 2022 +- Update code style with astyle ## v2.0.0 diff --git a/lwmem/src/include/system/lwmem_sys.h b/lwmem/src/include/system/lwmem_sys.h index 44bdfb1..d5301e2 100644 --- a/lwmem/src/include/system/lwmem_sys.h +++ b/lwmem/src/include/system/lwmem_sys.h @@ -47,7 +47,7 @@ extern "C" { * \brief System functions when used with operating system * \{ */ - + /** * \brief Create a new mutex and assign value to handle * \param[out] m: Output variable to save mutex handle diff --git a/lwmem/src/lwmem/lwmem.c b/lwmem/src/lwmem/lwmem.c index e0cce7a..1168426 100644 --- a/lwmem/src/lwmem/lwmem.c +++ b/lwmem/src/lwmem/lwmem.c @@ -686,14 +686,14 @@ lwmem_assignmem_ex(lwmem_t* const lw, const lwmem_region_t* regions) { if (regions == NULL || LWMEM_GET_LW(lw)->end_block != NULL /* Init function may only be called once per lwmem instance */ || (((size_t)LWMEM_CFG_ALIGN_NUM) & (((size_t)LWMEM_CFG_ALIGN_NUM) - 1)) > 0) { /* Must be power of 2 */ - return 0; + return 0; } /* Check values entered by application */ mem_start_addr = (void*)0; mem_size = 0; for (size_t i = 0;; ++i) { - /* + /* * Check for valid entry or end of array descriptor * * Invalid entry is considered as "end-of-region" indicator @@ -1037,7 +1037,7 @@ print_block(size_t i, lwmem_block_t* block) { printf("| %5d | %16p | %6d | %4d | %16d |", (int)i, - (void *)block, + (void*)block, (int)is_free, (int)block_size, (int)(is_free ? (block_size - LWMEM_BLOCK_META_SIZE) : 0)); From 70f217078961c7b39626bf5923c60e958f4b3732 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sun, 6 Feb 2022 22:35:36 +0100 Subject: [PATCH 30/73] Update link to font-awesome and license to 2022 --- docs/conf.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 1ced558..c18ddf8 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -23,7 +23,7 @@ # -- Project information ----------------------------------------------------- project = 'LwMEM' -copyright = '2020, Tilen MAJERLE' +copyright = '2022, Tilen MAJERLE' author = 'Tilen MAJERLE' # Try to get branch at which this is running @@ -115,9 +115,10 @@ html_css_files = [ 'css/common.css', 'css/custom.css', + 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css', ] html_js_files = [ - 'https://kit.fontawesome.com/3102794088.js' + '' ] master_doc = 'index' From dc48190286758a9a103223cd5c8c1f94cd467e46 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Wed, 16 Feb 2022 20:19:28 +0100 Subject: [PATCH 31/73] Update master branch to main --- docs/get-started/index.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/get-started/index.rst b/docs/get-started/index.rst index d66abc5..ac1ea31 100644 --- a/docs/get-started/index.rst +++ b/docs/get-started/index.rst @@ -13,10 +13,10 @@ Download library Library is primarly hosted on `Github `_. -You can get it with: +You can get it by: * Downloading latest release from `releases area `_ on Github -* Cloning ``master`` branch for latest stable version +* Cloning ``main`` branch for latest stable version * Cloning ``develop`` branch for latest development Download from releases @@ -34,11 +34,11 @@ This is used when you do not have yet local copy on your machine. * Make sure ``git`` is installed. * Open console and navigate to path in the system to clone repository to. Use command ``cd your_path`` -* Clone repository with one of available ``3`` options +* Clone repository with one of available options below * Run ``git clone --recurse-submodules https://github.com/MaJerle/lwmem`` command to clone entire repository, including submodules * Run ``git clone --recurse-submodules --branch develop https://github.com/MaJerle/lwmem`` to clone `development` branch, including submodules - * Run ``git clone --recurse-submodules --branch master https://github.com/MaJerle/lwmem`` to clone `latest stable` branch, including submodules + * Run ``git clone --recurse-submodules --branch main https://github.com/MaJerle/lwmem`` to clone `latest stable` branch, including submodules * Navigate to ``examples`` directory and run favourite example @@ -46,7 +46,7 @@ Update cloned to latest version """"""""""""""""""""""""""""""" * Open console and navigate to path in the system where your repository is located. Use command ``cd your_path`` -* Run ``git pull origin master`` command to get latest changes on ``master`` branch +* Run ``git pull origin main`` command to get latest changes on ``main`` branch * Run ``git pull origin develop`` command to get latest changes on ``develop`` branch * Run ``git submodule update --init --remote`` to update submodules to latest version From 574b5aa856024c61f4072f011c99ec3a0c83424b Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sat, 19 Feb 2022 00:14:53 +0100 Subject: [PATCH 32/73] Update requirements file for latest rtd theme --- docs/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index eb5e0fd..834b1bb 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,7 +2,7 @@ breathe>=4.9.1 colorama docutils==0.16 sphinx>=3.5.1 -sphinx_rtd_theme +sphinx_rtd_theme>=1.0.0 sphinx-tabs sphinxcontrib-svg2pdfconverter sphinx-sitemap From a9bb668ebddce1c69428560f32dab15bf5509071 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sat, 19 Feb 2022 01:47:05 +0100 Subject: [PATCH 33/73] Update requirements file for latest rtd theme --- docs/conf.py | 10 +- docs/index.rst | 19 ++ docs/static/dark-light/checked.svg | 1 + docs/static/dark-light/common-dark-light.css | 143 ++++++++ docs/static/dark-light/dark-mode-toggle.mjs | 329 +++++++++++++++++++ docs/static/dark-light/dark.css | 36 ++ docs/static/dark-light/light.css | 24 ++ docs/static/dark-light/moon.png | Bin 0 -> 3511 bytes docs/static/dark-light/moon.svg | 7 + docs/static/dark-light/sun.png | Bin 0 -> 1897 bytes docs/static/dark-light/sun.svg | 5 + docs/static/dark-light/unchecked.svg | 1 + 12 files changed, 569 insertions(+), 6 deletions(-) create mode 100644 docs/static/dark-light/checked.svg create mode 100644 docs/static/dark-light/common-dark-light.css create mode 100644 docs/static/dark-light/dark-mode-toggle.mjs create mode 100644 docs/static/dark-light/dark.css create mode 100644 docs/static/dark-light/light.css create mode 100644 docs/static/dark-light/moon.png create mode 100644 docs/static/dark-light/moon.svg create mode 100644 docs/static/dark-light/sun.png create mode 100644 docs/static/dark-light/sun.svg create mode 100644 docs/static/dark-light/unchecked.svg diff --git a/docs/conf.py b/docs/conf.py index c18ddf8..d091cbe 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -121,15 +121,13 @@ '' ] +# Master index file master_doc = 'index' -# -# Breathe configuration -# -# -# +# --- Breathe configuration ----------------------------------------------------- breathe_projects = { "lwmem": "_build/xml/" } breathe_default_project = "lwmem" -breathe_default_members = ('members', 'undoc-members') \ No newline at end of file +breathe_default_members = ('members', 'undoc-members') +breathe_show_enumvalue_initializer = True \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst index 5849552..009bddc 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -59,9 +59,28 @@ Table of contents .. toctree:: :maxdepth: 2 + :caption: Contents self get-started/index user-manual/index api-reference/index examples/index + +.. toctree:: + :maxdepth: 2 + :caption: Other projects + :hidden: + + LwDTC - DateTimeCron + LwESP - ESP-AT library + LwGPS - GPS NMEA parser + LwGSM - GSM-AT library + LwJSON - JSON parser + LwMEM - Memory manager + LwOW - OneWire with UART + LwPKT - Packet protocol + LwPRINTF - Printf + LwRB - Ring buffer + LwSHELL - Shell + LwUTIL - Utility functions diff --git a/docs/static/dark-light/checked.svg b/docs/static/dark-light/checked.svg new file mode 100644 index 0000000..a78af82 --- /dev/null +++ b/docs/static/dark-light/checked.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/static/dark-light/common-dark-light.css b/docs/static/dark-light/common-dark-light.css new file mode 100644 index 0000000..9a2dc1d --- /dev/null +++ b/docs/static/dark-light/common-dark-light.css @@ -0,0 +1,143 @@ +/** + * @license + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +:root { + --heading-color: red; + --duration: 0.5s; + --timing: ease; +} + +*, +::before, +::after { + box-sizing: border-box; +} + +body { + margin: 0; + transition: + color var(--duration) var(--timing), + background-color var(--duration) var(--timing); + font-family: sans-serif; + font-size: 12pt; + background-color: var(--background-color); + color: var(--text-color); + display: flex; + justify-content: center; +} + +main { + margin: 1rem; + max-width: 30rem; + position: relative; +} + +h1 { + color: var(--heading-color); + text-shadow: 0.1rem 0.1rem 0.1rem var(--shadow-color); + transition: text-shadow var(--duration) var(--timing); +} + +img { + max-width: 100%; + height: auto; + transition: filter var(--duration) var(--timing); +} + +p { + line-height: 1.5; + word-wrap: break-word; + overflow-wrap: break-word; + hyphens: auto; +} + +fieldset { + border: solid 0.1rem; + box-shadow: 0.1rem 0.1rem 0.1rem var(--shadow-color); + transition: box-shadow var(--duration) var(--timing); +} + +div { + padding: 0.5rem; +} + +aside { + position: absolute; + right: 0; + padding: 0.5rem; +} + +aside:nth-of-type(1) { + top: 0; +} + +aside:nth-of-type(2) { + top: 3rem; +} + +aside:nth-of-type(3) { + top: 7rem; +} + +aside:nth-of-type(4) { + top: 12rem; +} + +#content select, +#content button, +#content input[type="text"], +#content input[type="search"] { + width: 15rem; +} + +dark-mode-toggle { + --dark-mode-toggle-remember-icon-checked: url("checked.svg"); + --dark-mode-toggle-remember-icon-unchecked: url("unchecked.svg"); + --dark-mode-toggle-remember-font: 0.75rem "Helvetica"; + --dark-mode-toggle-legend-font: bold 0.85rem "Helvetica"; + --dark-mode-toggle-label-font: 0.85rem "Helvetica"; + --dark-mode-toggle-color: var(--text-color); + --dark-mode-toggle-background-color: none; + + margin-bottom: 1.5rem; +} + +#dark-mode-toggle-1 { + --dark-mode-toggle-dark-icon: url("sun.png"); + --dark-mode-toggle-light-icon: url("moon.png"); +} + +#dark-mode-toggle-2 { + --dark-mode-toggle-dark-icon: url("sun.svg"); + --dark-mode-toggle-light-icon: url("moon.svg"); + --dark-mode-toggle-icon-size: 2rem; + --dark-mode-toggle-icon-filter: invert(100%); +} + +#dark-mode-toggle-3, +#dark-mode-toggle-4 { + --dark-mode-toggle-dark-icon: url("moon.png"); + --dark-mode-toggle-light-icon: url("sun.png"); +} + +#dark-mode-toggle-3 { + --dark-mode-toggle-remember-filter: invert(100%); +} + +#dark-mode-toggle-4 { + --dark-mode-toggle-active-mode-background-color: var(--accent-color); + --dark-mode-toggle-remember-filter: invert(100%); +} diff --git a/docs/static/dark-light/dark-mode-toggle.mjs b/docs/static/dark-light/dark-mode-toggle.mjs new file mode 100644 index 0000000..da22262 --- /dev/null +++ b/docs/static/dark-light/dark-mode-toggle.mjs @@ -0,0 +1,329 @@ +/** + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// @license © 2019 Google LLC. Licensed under the Apache License, Version 2.0. +const doc = document; +const store = localStorage; +const PREFERS_COLOR_SCHEME = 'prefers-color-scheme'; +const MEDIA = 'media'; +const LIGHT = 'light'; +const DARK = 'dark'; +const MQ_DARK = `(${PREFERS_COLOR_SCHEME}:${DARK})`; +const MQ_LIGHT = `(${PREFERS_COLOR_SCHEME}:${LIGHT})`; +const LINK_REL_STYLESHEET = 'link[rel=stylesheet]'; +const REMEMBER = 'remember'; +const LEGEND = 'legend'; +const TOGGLE = 'toggle'; +const SWITCH = 'switch'; +const APPEARANCE = 'appearance'; +const PERMANENT = 'permanent'; +const MODE = 'mode'; +const COLOR_SCHEME_CHANGE = 'colorschemechange'; +const PERMANENT_COLOR_SCHEME = 'permanentcolorscheme'; +const ALL = 'all'; +const NOT_ALL = 'not all'; +const NAME = 'dark-mode-toggle'; +const DEFAULT_URL = 'https://googlechromelabs.github.io/dark-mode-toggle/demo/'; + +// See https://html.spec.whatwg.org/multipage/common-dom-interfaces.html ↵ +// #reflecting-content-attributes-in-idl-attributes. +const installStringReflection = (obj, attrName, propName = attrName) => { + Object.defineProperty(obj, propName, { + enumerable: true, + get() { + const value = this.getAttribute(attrName); + return value === null ? '' : value; + }, + set(v) { + this.setAttribute(attrName, v); + }, + }); +}; + +const installBoolReflection = (obj, attrName, propName = attrName) => { + Object.defineProperty(obj, propName, { + enumerable: true, + get() { + return this.hasAttribute(attrName); + }, + set(v) { + if (v) { + this.setAttribute(attrName, ''); + } else { + this.removeAttribute(attrName); + } + }, + }); +}; + +const template = doc.createElement('template'); +// âš ï¸ Note: this is a minified version of `src/template-contents.tpl`. +// Compress the CSS with https://cssminifier.com/, then paste it here. +// eslint-disable-next-line max-len +template.innerHTML = `
`; + +export class DarkModeToggle extends HTMLElement { + static get observedAttributes() { + return [MODE, APPEARANCE, PERMANENT, LEGEND, LIGHT, DARK, REMEMBER]; + } + + constructor() { + super(); + + installStringReflection(this, MODE); + installStringReflection(this, APPEARANCE); + installStringReflection(this, LEGEND); + installStringReflection(this, LIGHT); + installStringReflection(this, DARK); + installStringReflection(this, REMEMBER); + + installBoolReflection(this, PERMANENT); + + this._darkCSS = null; + this._lightCSS = null; + + doc.addEventListener(COLOR_SCHEME_CHANGE, (event) => { + this.mode = event.detail.colorScheme; + this._updateRadios(); + this._updateCheckbox(); + }); + + doc.addEventListener(PERMANENT_COLOR_SCHEME, (event) => { + this.permanent = event.detail.permanent; + this._permanentCheckbox.checked = this.permanent; + }); + + this._initializeDOM(); + } + + _initializeDOM() { + const shadowRoot = this.attachShadow({mode: 'open'}); + shadowRoot.appendChild(template.content.cloneNode(true)); + + // We need to support `media="(prefers-color-scheme: dark)"` (with space) + // and `media="(prefers-color-scheme:dark)"` (without space) + this._darkCSS = doc.querySelectorAll(`${LINK_REL_STYLESHEET}[${MEDIA}*=${PREFERS_COLOR_SCHEME}][${MEDIA}*="${DARK}"]`); + this._lightCSS = doc.querySelectorAll(`${LINK_REL_STYLESHEET}[${MEDIA}*=${PREFERS_COLOR_SCHEME}][${MEDIA}*="${LIGHT}"]`); + + // Get DOM references. + this._lightRadio = shadowRoot.querySelector('[part=lightRadio]'); + this._lightLabel = shadowRoot.querySelector('[part=lightLabel]'); + this._darkRadio = shadowRoot.querySelector('[part=darkRadio]'); + this._darkLabel = shadowRoot.querySelector('[part=darkLabel]'); + this._darkCheckbox = shadowRoot.querySelector('[part=toggleCheckbox]'); + this._checkboxLabel = shadowRoot.querySelector('[part=toggleLabel]'); + this._legendLabel = shadowRoot.querySelector('legend'); + this._permanentAside = shadowRoot.querySelector('aside'); + this._permanentCheckbox = + shadowRoot.querySelector('[part=permanentCheckbox]'); + this._permanentLabel = shadowRoot.querySelector('[part=permanentLabel]'); + + // Does the browser support native `prefers-color-scheme`? + const hasNativePrefersColorScheme = + matchMedia(MQ_DARK).media !== NOT_ALL; + // Listen to `prefers-color-scheme` changes. + if (hasNativePrefersColorScheme) { + matchMedia(MQ_DARK).addListener(({matches}) => { + this.mode = matches ? DARK : LIGHT; + this._dispatchEvent(COLOR_SCHEME_CHANGE, {colorScheme: this.mode}); + }); + } + // Set initial state, giving preference to a remembered value, then the + // native value (if supported), and eventually defaulting to a light + // experience. + const rememberedValue = store.getItem(NAME); + if (rememberedValue && [DARK, LIGHT].includes(rememberedValue)) { + this.mode = rememberedValue; + this._permanentCheckbox.checked = true; + this.permanent = true; + } else if (hasNativePrefersColorScheme) { + this.mode = matchMedia(MQ_LIGHT).matches ? LIGHT : DARK; + } + if (!this.mode) { + this.mode = LIGHT; + } + if (this.permanent && !rememberedValue) { + store.setItem(NAME, this.mode); + } + + // Default to toggle appearance. + if (!this.appearance) { + this.appearance = TOGGLE; + } + + // Update the appearance to either of toggle or switch. + this._updateAppearance(); + + // Update the radios + this._updateRadios(); + + // Make the checkbox reflect the state of the radios + this._updateCheckbox(); + + // Synchronize the behavior of the radio and the checkbox. + [this._lightRadio, this._darkRadio].forEach((input) => { + input.addEventListener('change', () => { + this.mode = this._lightRadio.checked ? LIGHT : DARK; + this._updateCheckbox(); + this._dispatchEvent(COLOR_SCHEME_CHANGE, {colorScheme: this.mode}); + }); + }); + this._darkCheckbox.addEventListener('change', () => { + this.mode = this._darkCheckbox.checked ? DARK : LIGHT; + this._updateRadios(); + this._dispatchEvent(COLOR_SCHEME_CHANGE, {colorScheme: this.mode}); + }); + + // Make remembering the last mode optional + this._permanentCheckbox.addEventListener('change', () => { + this.permanent = this._permanentCheckbox.checked; + this._dispatchEvent(PERMANENT_COLOR_SCHEME, { + permanent: this.permanent, + }); + }); + + // Finally update the mode and let the world know what's going on + this._updateMode(); + this._dispatchEvent(COLOR_SCHEME_CHANGE, {colorScheme: this.mode}); + this._dispatchEvent(PERMANENT_COLOR_SCHEME, { + permanent: this.permanent, + }); + } + + attributeChangedCallback(name, oldValue, newValue) { + if (name === MODE) { + if (![LIGHT, DARK].includes(newValue)) { + throw new RangeError(`Allowed values: "${LIGHT}" and "${DARK}".`); + } + // Only show the dialog programmatically on devices not capable of hover + // and only if there is a label + if (matchMedia('(hover:none)').matches && this.remember) { + this._showPermanentAside(); + } + if (this.permanent) { + store.setItem(NAME, this.mode); + } + this._updateRadios(); + this._updateCheckbox(); + this._updateMode(); + } else if (name === APPEARANCE) { + if (![TOGGLE, SWITCH].includes(newValue)) { + throw new RangeError(`Allowed values: "${TOGGLE}" and "${SWITCH}".`); + } + this._updateAppearance(); + } else if (name === PERMANENT) { + if (this.permanent) { + store.setItem(NAME, this.mode); + } else { + store.removeItem(NAME); + } + this._permanentCheckbox.checked = this.permanent; + } else if (name === LEGEND) { + this._legendLabel.textContent = newValue; + } else if (name === REMEMBER) { + this._permanentLabel.textContent = newValue; + } else if (name === LIGHT) { + this._lightLabel.textContent = newValue; + if (this.mode === LIGHT) { + this._checkboxLabel.textContent = newValue; + } + } else if (name === DARK) { + this._darkLabel.textContent = newValue; + if (this.mode === DARK) { + this._checkboxLabel.textContent = newValue; + } + } + } + + _dispatchEvent(type, value) { + this.dispatchEvent(new CustomEvent(type, { + bubbles: true, + composed: true, + detail: value, + })); + } + + _updateAppearance() { + // Hide or show the light-related affordances dependent on the appearance, + // which can be "switch" or "toggle". + const appearAsToggle = this.appearance === TOGGLE; + this._lightRadio.hidden = appearAsToggle; + this._lightLabel.hidden = appearAsToggle; + this._darkRadio.hidden = appearAsToggle; + this._darkLabel.hidden = appearAsToggle; + this._darkCheckbox.hidden = !appearAsToggle; + this._checkboxLabel.hidden = !appearAsToggle; + } + + _updateRadios() { + if (this.mode === LIGHT) { + this._lightRadio.checked = true; + } else { + this._darkRadio.checked = true; + } + } + + _updateCheckbox() { + if (this.mode === LIGHT) { + this._checkboxLabel.style.setProperty(`--${NAME}-checkbox-icon`, + `var(--${NAME}-light-icon,url("${DEFAULT_URL}moon.png"))`); + this._checkboxLabel.textContent = this.light; + if (!this.light) { + this._checkboxLabel.ariaLabel = DARK; + } + this._darkCheckbox.checked = false; + } else { + this._checkboxLabel.style.setProperty(`--${NAME}-checkbox-icon`, + `var(--${NAME}-dark-icon,url("${DEFAULT_URL}sun.png"))`); + this._checkboxLabel.textContent = this.dark; + if (!this.dark) { + this._checkboxLabel.ariaLabel = LIGHT; + } + this._darkCheckbox.checked = true; + } + } + + _updateMode() { + if (this.mode === LIGHT) { + this._lightCSS.forEach((link) => { + link.media = ALL; + link.disabled = false; + }); + this._darkCSS.forEach((link) => { + link.media = NOT_ALL; + link.disabled = true; + }); + } else { + this._darkCSS.forEach((link) => { + link.media = ALL; + link.disabled = false; + }); + this._lightCSS.forEach((link) => { + link.media = NOT_ALL; + link.disabled = true; + }); + } + } + + _showPermanentAside() { + this._permanentAside.style.visibility = 'visible'; + setTimeout(() => { + this._permanentAside.style.visibility = 'hidden'; + }, 3000); + } +} + +customElements.define(NAME, DarkModeToggle); \ No newline at end of file diff --git a/docs/static/dark-light/dark.css b/docs/static/dark-light/dark.css new file mode 100644 index 0000000..6ed8cfb --- /dev/null +++ b/docs/static/dark-light/dark.css @@ -0,0 +1,36 @@ +/** + * @license + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +:root { + color-scheme: dark; /* stylelint-disable-line property-no-unknown */ + + --background-color: rgb(15 15 15); + --text-color: rgb(240 240 240); + --shadow-color: rgb(240 240 240 / 50%); + --accent-color: rgb(0 0 240 / 50%); +} + +img { + filter: grayscale(50%); +} + +.icon { + filter: invert(100%); +} + +a { + color: yellow; +} diff --git a/docs/static/dark-light/light.css b/docs/static/dark-light/light.css new file mode 100644 index 0000000..f73cf7b --- /dev/null +++ b/docs/static/dark-light/light.css @@ -0,0 +1,24 @@ +/** + * @license + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +:root { + color-scheme: light; /* stylelint-disable-line property-no-unknown */ + + --background-color: rgb(240 240 240); + --text-color: rgb(15 15 15); + --shadow-color: rgb(15 15 15 / 50%); + --accent-color: rgb(240 0 0 / 50%); +} diff --git a/docs/static/dark-light/moon.png b/docs/static/dark-light/moon.png new file mode 100644 index 0000000000000000000000000000000000000000..0ad57d90044ef1f66d56d9208e6a6b3db43c7c55 GIT binary patch literal 3511 zcmV;o4M_5dP)&$gC;R#7483 zCOQ(#aN&4eN@Z(kZ-$3`=JnGy{=i6EE z+C}x)H}upq;?zpr(pvJ*F6YlY+RjMs$t2UsTG_}!oMNS&QmdLjl#ytel2DS4T%3$O zqKhYog=&g~PJ@75i+nkId1`ufQE+f?a&TR2Y;0<3YIAEqXlQ6=W@cz+QeQ&B=sPftxvO;AiZN=iydNJvIT zMnptJLPA16KR-M?JU2Ht(U1jQ0000ebW%=J00j;qAu=~YM^jf{c6fS+ii?z^s;jHK zz{khc)!5nH;O*}4^Ys1xDKt-&000ZVNklUtM#Tq?2nq-dihzl!syx2>oOA9??Sh-)CC-{Pt9NKy|N5o6mjElpDG=J1l34x@yS6z9n{JvkDWvm$x}rFIcCp%TpG%3Zkw) z+t+WGRz9w;Z)|LCZ86N*-pLhg+p+uFPFLEZx?qjE#6G99U0EfUU{oe~dpB=8&M8ZW z)afSm*&=+pQuq1mx63OZDeJm2;O(8gf8gXP|r6bKi-4M~&KciE|x0 z&oaTKHtX;~W3dnnn$Y8&F%{M@AGJ-edm(tx0gDwi2K_F0s{wN~oOeql4BOaf4B9A6 z8x0qQ4}od5#LWqur^?0V+HgGv9dyg8vd4gT@&%hhu7Vw^+*cQ{S-6tS!oM4ZkGNOM zLpHg)Ie}@|*e|m%28~3G!W_6Yt|p4UZ_%$B=KbnDA5{4Ep@lJLa*vp_4%q^u@^K4e zrP*CJ-J@>Ra>N{)PuZ+|SmFD+u%H;U@c?4NC@huBX5~nCK;Z!tW)Xb@3*!L(UX=GiluV7@xW?z;u;QEExI`)aF3XDPF>Cgb_)){S3<^W zC8KDJ=t&EZj}Fn6wlYR>=g*tQ+B4?XuG%2OY715`Da@+BF7^NdsotCD>BX? zLvG+BCfJm{-FnZSn5+i57&ODisCfib`GW5%&d@h$rmSz&{C6xXRT!$_Qs7bmi|c5( z((KeM4YvGuB+WohU?8* zB83YKS1MO5-%=+B0sCZcsg;JZsB83<&4TO-%WmFQ@U?S*GYp$@6!69dOi@)`qb~|m z$ikaMF7Hsvm2xk`xSAx8O;}>G=qoVXTu!|!N($uK43{dE-a5P|X2znBK?7djL_`&K zi&@jvFv(0ya_kCBjn8{NcBYFzf<3^#_1_+dm;z0EjY z957tzD*v~|6}aq!sqtVGsRa{*V401+D2!(Y~mMJjiYN+CFAL`O=vs^9}Js4Y^B-W(m0Yu<6!n~KK zii^6zeTn511@?VRi`FHA?+mgm zrQ@me^z@@g)6>)G)Ob?EYowvBQpGjv!WCG{6t!EGHaz+eJWj62LnGuql8`)^ysr1ksAVwOXn-Dgy1QH)gdcTUQjg|>j&R3Zfc6qma5A;?$A2PA@1=yT5Oix8!T)zP>!?IhJ@0+$vmS!yhEOI(EiCHrT z6e{Y1h3hLUN8BhR4*6aTFwR&msOqdW!1@LdFHAtBEdRz=`-6SC(1t z?&+5wMcpI&%B1&wV{WzbtW{-oIXz;Q3y%)n@hb1YgKDs{&Zf&L>#G>4zrlMQ8zMW# zHxQ=D<-&u*Tv^T9R59dS6*gSJ74JO}v(9ES<1wO19wk}AH|wE6s$9LIb~VW_s6uM> zP#2R%E@m^?$ry*_iBy^+?%-g|S6L{aXd6(s#3{0C?zG-(sjTQ&d^9mJkw}cFQ}wQkCN|*wE>eF>EE->c?3gY_hJ)aM^2&!e-?xRR)dXbjsEJTH6!0 zSkh}#5EU$3fk|UHs4yzi(ei5_&PP6mVatzHycBJN)vm}`t_lj*tQ;pAGL{X)-eDJU zZBb2DWbbk+n}u=T%u+^3Mr|aXRGYoaF%6>JQOfX z?!-u(Ci>$B;+0 zoFF=#N=+nW_FCrBnzk8*>iSgrQttU$9AxR3b1FLeD;Va*J)!nWvD?`Q>Np zgeb<%FQ!eCRQWH(HuYxw*{hc?U%h-qJm)gTe8PlOX{O1*i#$=m3@d@FD9GG!;~*=PX#{vZFL)t@YdevSYD002ovPDHLkV1gN2&RhTh literal 0 HcmV?d00001 diff --git a/docs/static/dark-light/moon.svg b/docs/static/dark-light/moon.svg new file mode 100644 index 0000000..fad89a4 --- /dev/null +++ b/docs/static/dark-light/moon.svg @@ -0,0 +1,7 @@ + + + + moon + + + diff --git a/docs/static/dark-light/sun.png b/docs/static/dark-light/sun.png new file mode 100644 index 0000000000000000000000000000000000000000..40c9b362bd4efe10a77721de66ea94b12437db56 GIT binary patch literal 1897 zcmV-v2bTDWP)!ye&-ZTBt zRs7RL{nau3#6|zXE&seB|G6&zxe))dEB~|s|F0PTtpWe00{@`^LH*>T0000EbW%=J z00s~oFGyc_ny|y&@b)K_;4lCH2C7L!K~#9!?VF2k+d2$}>-$YP%bZ!JY1w)Iw>%WB zgvplJm0ToPv46#Y4Q)Ph=-R3Swh^8{TqUu9~k`lAeZFnad>@@<67%+9A6*g zRFS90Hv~Dio*v&2;ms>=!N0XZ8{*EdDqLK!Hl^`cYJXy;hcNsc~d90NnXIDiP=NMF#JJ93`a!>*bLYRFsu^$%@lx$?C@6 zX@f{aF}aLxg9`wJwdy@rmTakkxK@P5tG|&T52?)UvuxcYsYETWne>Krj;X1gtDMb-{62(6$%q&tE@D^tZ6vj=#;3M}Q^`FK__Nl{q_oyuHlun z+hk~4<}!Ah417}VR$;j(;ck*?KeNGmm1BDp?k1VTjOE9E72Q!By`g1ox5w@az;XRq zgT>@y`vtDf)$zy%3wM)zJnmmySwo%{gSW|xuiIUH-6+XQh0fE$-7uMbeZ(pah89($ z5W&M>2D{~jO_`^05ERe~S|5X*uTKOfsk+FL$On1=5^^acU>{$%ok0=+G!?-=2i00z ztT9{xbPQ%s`}n%EXCslV6nlLON`k&$YP>UpeL_rf;F;?IV|oBhQgxaC>2(KX5p*0~ zO}i9YKAx7exqxleH}t)>IdPM1U$K0r-Q31xmaAO-z*+?S}fp+!A^tzttk?xd3lZTuqVa>o}OBKxJ{>#tm?(^ zo#3{e1$+yAxUHikFKe}ItMCq!E|r};cbinpkW;EvtAEB7BK)S@U#jo1XLLYm2?_b`ZW8CuCQV+ z|9i{Zj}ih3`eHvfDp9UZpEVfsueeEsT-u8L;7p-GziVp8E$saU<9znKm?Nrm|Lqv@ z?A40srnA{&vb3gWZgP1wUl0%ZE^frFJ^yx-L8y~`D+_QYu-MFKmOvd=xM!Kogsv=W zu#gG8+ESEe<|HlDz=mQ!NfT9XHBqH~%dNeAE!1fiGPFl&8w=H8TR301Y_iINSC%G& z9ogN%)*9ttX5mf)Koy5R=5fOiH@*DKXkcbd+@aTjTPk+55GGGN3#p2{s1>nW)~RI? zw_C;}cQXl@vV}~4#))MBKvikPL*WJiz|DV7JpPfv5CWQsxib9;ns+gI08*Vta%|uw zmYgiGa+bx*m~9N3cgfJam)W9>?Pav+w6vyWYP_HWCVX;rU9eiqU{OxWyV2s^D7BW^ zqSh)4nX+Bx$JKA6>!d+3+2C*GM(k$RBRji_16G!snCJ0>7WVA)=jJ$k# zPp1)`HPoDZ87p`^QYGVXW00000NkvXXu0mjf*I}_| literal 0 HcmV?d00001 diff --git a/docs/static/dark-light/sun.svg b/docs/static/dark-light/sun.svg new file mode 100644 index 0000000..0b18941 --- /dev/null +++ b/docs/static/dark-light/sun.svg @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/docs/static/dark-light/unchecked.svg b/docs/static/dark-light/unchecked.svg new file mode 100644 index 0000000..6702330 --- /dev/null +++ b/docs/static/dark-light/unchecked.svg @@ -0,0 +1 @@ + \ No newline at end of file From 1e86d6a9a7282888e00ec8e8922a300077810f98 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Mon, 21 Feb 2022 19:14:12 +0100 Subject: [PATCH 34/73] docs: Mention VSCode support --- docs/conf.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index d091cbe..032fb7c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -28,10 +28,20 @@ # Try to get branch at which this is running # and try to determine which version to display in sphinx -# Version is using git tag if on master or "latest-develop" if on develop branch +# Version is using git tag if on master/main or "latest-develop" if on develop branch version = '' git_branch = '' +def cmd_exec_print(t): + print("cmd > ", t, "\n", os.popen(t).read().strip(), "\n") + +# Print demo data here +cmd_exec_print('git branch') +cmd_exec_print('git describe') +cmd_exec_print('git describe --tags') +cmd_exec_print('git describe --tags --abbrev=0') +cmd_exec_print('git describe --tags --abbrev=1') + # Get current branch res = os.popen('git branch').read().strip() for line in res.split("\n"): @@ -41,17 +51,18 @@ # Decision for display version git_branch = git_branch.replace('(HEAD detached at ', '').replace(')', '') if git_branch.find('master') >= 0 or git_branch.find('main') >= 0: - version = os.popen('git describe --tags --abbrev=0').read().strip() - if version == '': - version = 'v0.0.0' -elif git_branch.find('develop') != -1 and not (git_branch.find('develop-') >= 0 or git_branch.find('develop/') >= 0): + #version = os.popen('git describe --tags --abbrev=0').read().strip() + version = 'latest-stable' +elif git_branch.find('develop-') >= 0 or git_branch.find('develop/') >= 0: + version = 'branch-' + git_branch +elif git_branch == 'develop' or git_branch == 'origin/develop': version = 'latest-develop' else: - version = 'branch-' + git_branch + version = os.popen('git describe --tags --abbrev=0').read().strip() # For debugging purpose only print("GIT BRANCH: " + git_branch) -print("GIT VERSION: " + version) +print("PROJ VERSION: " + version) # -- General configuration --------------------------------------------------- From b318fa416ab04746d093fc00e750602645121cc4 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Tue, 22 Feb 2022 22:04:34 +0100 Subject: [PATCH 35/73] Update tasks.json to add docs commands --- .vscode/tasks.json | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index a4527df..4a5e5eb 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -42,5 +42,32 @@ "args": [], "problemMatcher": [], }, + { + "label": "Docs: Install python plugins from requirements.txt file", + "type": "shell", + "command": "python -m pip install -r requirements.txt", + "options": { + "cwd": "${workspaceFolder}/docs" + }, + "problemMatcher": [] + }, + { + "label": "Docs: Generate html", + "type": "shell", + "command": ".\\make html", + "options": { + "cwd": "${workspaceFolder}/docs" + }, + "problemMatcher": [] + }, + { + "label": "Docs: Clean build directory", + "type": "shell", + "command": ".\\make clean", + "options": { + "cwd": "${workspaceFolder}/docs" + }, + "problemMatcher": [] + }, ] } \ No newline at end of file From df5ca05d43f95cfdacab74534a04e9f881f2c5af Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 4 Mar 2022 11:46:40 +0100 Subject: [PATCH 36/73] Add inner directive for doxygengroup --- docs/api-reference/lwmem_opt.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/api-reference/lwmem_opt.rst b/docs/api-reference/lwmem_opt.rst index f789afb..3695cf7 100644 --- a/docs/api-reference/lwmem_opt.rst +++ b/docs/api-reference/lwmem_opt.rst @@ -9,4 +9,5 @@ When any of the settings shall be modified, it shall be done in dedicated applic .. note:: Check :ref:`getting_started` for guidelines on how to create and use configuration file. -.. doxygengroup:: LWMEM_OPT \ No newline at end of file +.. doxygengroup:: LWMEM_OPT + :inner: \ No newline at end of file From 2a81abf0f42db81b315f811c45e1218a416787e7 Mon Sep 17 00:00:00 2001 From: upbeat27 Date: Mon, 14 Mar 2022 09:32:33 -0700 Subject: [PATCH 37/73] Optimize checking for default instance LWMEM_GET_LW is used almost everywhere, when it really only needs to reassign the instance once in each higher level function. After the reassignment, the correct instance will be used in all subsequent lower level functions. --- lwmem/src/include/lwmem/lwmem.h | 16 +++--- lwmem/src/lwmem/lwmem.c | 89 ++++++++++++++++++--------------- 2 files changed, 56 insertions(+), 49 deletions(-) diff --git a/lwmem/src/include/lwmem/lwmem.h b/lwmem/src/include/lwmem/lwmem.h index 8784a26..bca9c4f 100644 --- a/lwmem/src/include/lwmem/lwmem.h +++ b/lwmem/src/include/lwmem/lwmem.h @@ -102,14 +102,14 @@ typedef struct { size_t size; /*!< Size of region in units of bytes */ } lwmem_region_t; -size_t lwmem_assignmem_ex(lwmem_t* const lw, const lwmem_region_t* regions); -void* lwmem_malloc_ex(lwmem_t* const lw, const lwmem_region_t* region, const size_t size); -void* lwmem_calloc_ex(lwmem_t* const lw, const lwmem_region_t* region, const size_t nitems, const size_t size); -void* lwmem_realloc_ex(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, const size_t size); -uint8_t lwmem_realloc_s_ex(lwmem_t* const lw, const lwmem_region_t* region, void** const ptr, const size_t size); -void lwmem_free_ex(lwmem_t* const lw, void* const ptr); -void lwmem_free_s_ex(lwmem_t* const lw, void** const ptr); -size_t lwmem_get_size_ex(lwmem_t* const lw, void* ptr); +size_t lwmem_assignmem_ex(lwmem_t* lw, const lwmem_region_t* regions); +void* lwmem_malloc_ex(lwmem_t* lw, const lwmem_region_t* region, const size_t size); +void* lwmem_calloc_ex(lwmem_t* lw, const lwmem_region_t* region, const size_t nitems, const size_t size); +void* lwmem_realloc_ex(lwmem_t* lw, const lwmem_region_t* region, void* const ptr, const size_t size); +uint8_t lwmem_realloc_s_ex(lwmem_t* lw, const lwmem_region_t* region, void** const ptr, const size_t size); +void lwmem_free_ex(lwmem_t* lw, void* const ptr); +void lwmem_free_s_ex(lwmem_t* lw, void** const ptr); +size_t lwmem_get_size_ex(lwmem_t* lw, void* ptr); /** * \note This is a wrapper for \ref lwmem_assignmem_ex function. diff --git a/lwmem/src/lwmem/lwmem.c b/lwmem/src/lwmem/lwmem.c index 1168426..c9a0f48 100644 --- a/lwmem/src/lwmem/lwmem.c +++ b/lwmem/src/lwmem/lwmem.c @@ -131,15 +131,15 @@ * \param[in] in_p: Previous of input block */ #define LWMEM_GET_PREV_CURR_OF_BLOCK(in_lw, in_b, in_pp, in_p) do { \ - for ((in_pp) = NULL, (in_p) = &(LWMEM_GET_LW(in_lw)->start_block); \ + for ((in_pp) = NULL, (in_p) = &(in_lw->start_block); \ (in_p) != NULL && (in_p)->next < (in_b); \ (in_pp) = (in_p), (in_p) = (in_p)->next \ ) {} \ } while (0) #if LWMEM_CFG_OS -#define LWMEM_PROTECT(lw) lwmem_sys_mutex_wait(&(LWMEM_GET_LW(lw)->mutex)) -#define LWMEM_UNPROTECT(lw) lwmem_sys_mutex_release(&(LWMEM_GET_LW(lw)->mutex)) +#define LWMEM_PROTECT(lw) lwmem_sys_mutex_wait(&(lw->mutex)) +#define LWMEM_UNPROTECT(lw) lwmem_sys_mutex_release(&(lw->mutex)) #else /* LWMEM_CFG_OS */ #define LWMEM_PROTECT(lw) #define LWMEM_UNPROTECT(lw) @@ -219,7 +219,7 @@ prv_insert_free_block(lwmem_t* const lw, lwmem_block_t* nb) { * Try to find position to put new block in-between * Search until all free block addresses are lower than entry block */ - for (prev = &(LWMEM_GET_LW(lw)->start_block); prev != NULL && prev->next < nb; prev = prev->next) {} + for (prev = &(lw->start_block); prev != NULL && prev->next < nb; prev = prev->next) {} /* This is hard error with wrong memory usage */ if (prev == NULL) { @@ -262,8 +262,8 @@ prv_insert_free_block(lwmem_t* const lw, lwmem_block_t* nb) { */ if (prev->next != NULL && prev->next->size > 0 /* Do not remove "end of region" indicator in each region */ && (LWMEM_TO_BYTE_PTR(nb) + nb->size) == LWMEM_TO_BYTE_PTR(prev->next)) { - if (prev->next == LWMEM_GET_LW(lw)->end_block) {/* Does it points to the end? */ - nb->next = LWMEM_GET_LW(lw)->end_block; /* Set end block pointer */ + if (prev->next == lw->end_block) {/* Does it points to the end? */ + nb->next = lw->end_block; /* Set end block pointer */ } else { nb->size += prev->next->size; /* Expand of current block for size of next free block which is right behind new block */ nb->next = prev->next->next; /* Next free is pointed to the next one of previous next */ @@ -307,7 +307,7 @@ prv_split_too_big_block(lwmem_t* const lw, lwmem_block_t* block, size_t new_bloc next->size = block_size - new_block_size; /* Modify block data */ block->size = new_block_size; /* Current size is now smaller */ - LWMEM_GET_LW(lw)->mem_available_bytes += next->size;/* Increase available bytes by new block size */ + lw->mem_available_bytes += next->size;/* Increase available bytes by new block size */ prv_insert_free_block(lw, next); /* Add new block to the free list */ success = 1; @@ -341,12 +341,12 @@ prv_alloc(lwmem_t* const lw, const lwmem_region_t* region, const size_t size) { const size_t final_size = LWMEM_ALIGN(size) + LWMEM_BLOCK_META_SIZE; /* Check if initialized and if size is in the limits */ - if (LWMEM_GET_LW(lw)->end_block == NULL || final_size == LWMEM_BLOCK_META_SIZE || (final_size & LWMEM_ALLOC_BIT) > 0) { + if (lw->end_block == NULL || final_size == LWMEM_BLOCK_META_SIZE || (final_size & LWMEM_ALLOC_BIT) > 0) { return NULL; } /* Set default values */ - prev = &(LWMEM_GET_LW(lw)->start_block); /* Use pointer from custom lwmem block */ + prev = &(lw->start_block); /* Use pointer from custom lwmem block */ curr = prev->next; /* Curr represents first actual free block */ /* @@ -371,7 +371,7 @@ prv_alloc(lwmem_t* const lw, const lwmem_region_t* region, const size_t size) { */ for (; curr != NULL; prev = curr, curr = curr->next) { /* Check bounds */ - if (curr->next == NULL || curr == LWMEM_GET_LW(lw)->end_block) { + if (curr->next == NULL || curr == lw->end_block) { return NULL; } if ((uint8_t*)curr < (uint8_t*)region_start_addr) { /* Check if we reached region */ @@ -390,7 +390,7 @@ prv_alloc(lwmem_t* const lw, const lwmem_region_t* region, const size_t size) { * Loop until size of current block is smaller than requested final size */ for (; curr != NULL && curr->size < final_size; prev = curr, curr = curr->next) { - if (curr->next == NULL || curr == LWMEM_GET_LW(lw)->end_block) {/* If no more blocks available */ + if (curr->next == NULL || curr == lw->end_block) {/* If no more blocks available */ return NULL; /* No sufficient memory available to allocate block of memory */ } } @@ -407,11 +407,11 @@ prv_alloc(lwmem_t* const lw, const lwmem_region_t* region, const size_t size) { /* curr block is now removed from linked list */ - LWMEM_GET_LW(lw)->mem_available_bytes -= curr->size;/* Decrease available bytes by allocated block size */ + lw->mem_available_bytes -= curr->size;/* Decrease available bytes by allocated block size */ prv_split_too_big_block(lw, curr, final_size); /* Split block if it is too big */ LWMEM_BLOCK_SET_ALLOC(curr); /* Set block as allocated */ - LWMEM_INC_STATS(LWMEM_GET_LW(lw)->stats.nr_alloc); + LWMEM_INC_STATS(lw->stats.nr_alloc); return retval; } @@ -427,10 +427,10 @@ prv_free(lwmem_t* const lw, void* const ptr) { if (LWMEM_BLOCK_IS_ALLOC(block)) { /* Check if block is valid */ block->size &= ~LWMEM_ALLOC_BIT; /* Clear allocated bit indication */ - LWMEM_GET_LW(lw)->mem_available_bytes += block->size; /* Increase available bytes */ + lw->mem_available_bytes += block->size; /* Increase available bytes */ prv_insert_free_block(lw, block); /* Put block back to list of free block */ - LWMEM_INC_STATS(LWMEM_GET_LW(lw)->stats.nr_free); + LWMEM_INC_STATS(lw->stats.nr_free); } } @@ -528,7 +528,7 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co prev->next = (void*)(LWMEM_TO_BYTE_PTR(prev->next) - (block_size - final_size)); prev->next->size = tmp_size + (block_size - final_size); prev->next->next = tmp_next; - LWMEM_GET_LW(lw)->mem_available_bytes += block_size - final_size; /* Increase available bytes by increase of free block */ + lw->mem_available_bytes += block_size - final_size; /* Increase available bytes by increase of free block */ block->size = final_size; /* Block size is requested size */ } @@ -559,7 +559,7 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co * Merge blocks together by increasing current block with size of next free one * and remove next free from list of free blocks */ - LWMEM_GET_LW(lw)->mem_available_bytes -= prev->next->size; /* For now decrease effective available bytes */ + lw->mem_available_bytes -= prev->next->size; /* For now decrease effective available bytes */ block->size = block_size + prev->next->size;/* Increase effective size of new block */ prev->next = prev->next->next; /* Set next to next's next, effectively remove expanded block from free list */ @@ -589,7 +589,7 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co */ LWMEM_MEMMOVE(new_data_ptr, old_data_ptr, block_size); - LWMEM_GET_LW(lw)->mem_available_bytes -= prev->size;/* For now decrease effective available bytes */ + lw->mem_available_bytes -= prev->size;/* For now decrease effective available bytes */ prev->size += block_size; /* Increase size of input block size */ prevprev->next = prev->next; /* Remove prev from free list as it is now being used for allocation together with existing block */ block = prev; /* Move block pointer to previous one */ @@ -625,7 +625,7 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co */ LWMEM_MEMMOVE(new_data_ptr, old_data_ptr, block_size); /* Copy old buffer size to new location */ - LWMEM_GET_LW(lw)->mem_available_bytes -= prev->size + prev->next->size; /* Decrease effective available bytes for free blocks before and after input block */ + lw->mem_available_bytes -= prev->size + prev->next->size; /* Decrease effective available bytes for free blocks before and after input block */ prev->size += block_size + prev->next->size;/* Increase size of new block by size of 2 free blocks */ prevprev->next = prev->next->next; /* Remove free block before current one and block after current one from linked list (remove 2) */ block = prev; /* Previous block is now current */ @@ -677,14 +677,15 @@ lwmem_region_t regions[] = { * It must be called only once to setup memory regions */ size_t -lwmem_assignmem_ex(lwmem_t* const lw, const lwmem_region_t* regions) { +lwmem_assignmem_ex(lwmem_t* lw, const lwmem_region_t* regions) { + lw = LWMEM_GET_LW(lw); uint8_t* mem_start_addr; size_t mem_size, len = 0; lwmem_block_t* first_block, *prev_end_block; /* Check first things first */ if (regions == NULL - || LWMEM_GET_LW(lw)->end_block != NULL /* Init function may only be called once per lwmem instance */ + || lw->end_block != NULL /* Init function may only be called once per lwmem instance */ || (((size_t)LWMEM_CFG_ALIGN_NUM) & (((size_t)LWMEM_CFG_ALIGN_NUM) - 1)) > 0) { /* Must be power of 2 */ return 0; } @@ -719,8 +720,8 @@ lwmem_assignmem_ex(lwmem_t* const lw, const lwmem_region_t* regions) { /* Process further checks of valid inputs */ if (regions == NULL || len == 0 #if LWMEM_CFG_OS - || lwmem_sys_mutex_isvalid(&(LWMEM_GET_LW(lw)->mutex)) /* Check if mutex valid already = must not be */ - || !lwmem_sys_mutex_create(&(LWMEM_GET_LW(lw)->mutex)) /* Final step = try to create mutex for new instance */ + || lwmem_sys_mutex_isvalid(&(lw->mutex)) /* Check if mutex valid already = must not be */ + || !lwmem_sys_mutex_create(&(lw->mutex)) /* Final step = try to create mutex for new instance */ #endif /* LWMEM_CFG_OS */ ) { return 0; @@ -737,23 +738,23 @@ lwmem_assignmem_ex(lwmem_t* const lw, const lwmem_region_t* regions) { * In first indication application shall set start_block and never again * end_block value holds */ - if (LWMEM_GET_LW(lw)->end_block == NULL) { + if (lw->end_block == NULL) { /* * Next entry of start block is first region * It points to beginning of region data * In the later step(s) first block is manually set on top of memory region */ - LWMEM_GET_LW(lw)->start_block.next = (void*)mem_start_addr; - LWMEM_GET_LW(lw)->start_block.size = 0; /* Size of dummy start block is zero */ + lw->start_block.next = (void*)mem_start_addr; + lw->start_block.size = 0; /* Size of dummy start block is zero */ } /* Save current end block status as it is used later for linked list insertion */ - prev_end_block = LWMEM_GET_LW(lw)->end_block; + prev_end_block = lw->end_block; /* Put end block to the end of the region with size = 0 */ - LWMEM_GET_LW(lw)->end_block = (void*)(mem_start_addr + mem_size - LWMEM_BLOCK_META_SIZE); - LWMEM_GET_LW(lw)->end_block->next = NULL; /* End block in region does not have next entry */ - LWMEM_GET_LW(lw)->end_block->size = 0; /* Size of end block is zero */ + lw->end_block = (void*)(mem_start_addr + mem_size - LWMEM_BLOCK_META_SIZE); + lw->end_block->next = NULL; /* End block in region does not have next entry */ + lw->end_block->size = 0; /* Size of end block is zero */ /* * Create memory region first block. @@ -764,7 +765,7 @@ lwmem_assignmem_ex(lwmem_t* const lw, const lwmem_region_t* regions) { * Actual maximal available size for application in the region is mem_size - 2 * MEM_BLOCK_META_SIZE */ first_block = (void*)mem_start_addr; - first_block->next = LWMEM_GET_LW(lw)->end_block;/* Next block of first is last block */ + first_block->next = lw->end_block;/* Next block of first is last block */ first_block->size = mem_size - LWMEM_BLOCK_META_SIZE; /* Check if previous regions exist by checking previous end block state */ @@ -772,8 +773,8 @@ lwmem_assignmem_ex(lwmem_t* const lw, const lwmem_region_t* regions) { prev_end_block->next = first_block; /* End block of previous region now points to start of current region */ } - LWMEM_GET_LW(lw)->mem_available_bytes += first_block->size; /* Increase number of available bytes */ - ++LWMEM_GET_LW(lw)->mem_regions_count; /* Increase number of used regions */ + lw->mem_available_bytes += first_block->size; /* Increase number of available bytes */ + ++lw->mem_regions_count; /* Increase number of used regions */ } #if defined(LWMEM_DEV) @@ -781,7 +782,7 @@ lwmem_assignmem_ex(lwmem_t* const lw, const lwmem_region_t* regions) { LWMEM_MEMCPY(&lwmem_default.start_block_first_use, &lwmem_default.start_block, sizeof(lwmem_default.start_block)); #endif /* defined(LWMEM_DEV) */ - return LWMEM_GET_LW(lw)->mem_regions_count; /* Return number of regions used by manager */ + return lw->mem_regions_count; /* Return number of regions used by manager */ } /** @@ -795,8 +796,9 @@ lwmem_assignmem_ex(lwmem_t* const lw, const lwmem_region_t* regions) { * \note This function is thread safe when \ref LWMEM_CFG_OS is enabled */ void* -lwmem_malloc_ex(lwmem_t* const lw, const lwmem_region_t* region, const size_t size) { +lwmem_malloc_ex(lwmem_t* lw, const lwmem_region_t* region, const size_t size) { void* ptr; + lw = LWMEM_GET_LW(lw); LWMEM_PROTECT(lw); ptr = prv_alloc(lw, region, size); LWMEM_UNPROTECT(lw); @@ -819,10 +821,11 @@ lwmem_malloc_ex(lwmem_t* const lw, const lwmem_region_t* region, const size_t si * \note This function is thread safe when \ref LWMEM_CFG_OS is enabled */ void* -lwmem_calloc_ex(lwmem_t* const lw, const lwmem_region_t* region, const size_t nitems, const size_t size) { +lwmem_calloc_ex(lwmem_t* lw, const lwmem_region_t* region, const size_t nitems, const size_t size) { void* ptr; const size_t s = size * nitems; + lw = LWMEM_GET_LW(lw); LWMEM_PROTECT(lw); if ((ptr = prv_alloc(lw, region, s)) != NULL) { LWMEM_MEMSET(ptr, 0x00, s); @@ -854,8 +857,9 @@ lwmem_calloc_ex(lwmem_t* const lw, const lwmem_region_t* region, const size_t ni * \note This function is thread safe when \ref LWMEM_CFG_OS is enabled */ void* -lwmem_realloc_ex(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, const size_t size) { +lwmem_realloc_ex(lwmem_t* lw, const lwmem_region_t* region, void* const ptr, const size_t size) { void* p; + lw = LWMEM_GET_LW(lw); LWMEM_PROTECT(lw); p = prv_realloc(lw, region, ptr, size); LWMEM_UNPROTECT(lw); @@ -891,7 +895,7 @@ lwmem_realloc_ex(lwmem_t* const lw, const lwmem_region_t* region, void* const pt * \note This function is thread safe when \ref LWMEM_CFG_OS is enabled */ uint8_t -lwmem_realloc_s_ex(lwmem_t* const lw, const lwmem_region_t* region, void** const ptr, const size_t size) { +lwmem_realloc_s_ex(lwmem_t* lw, const lwmem_region_t* region, void** const ptr, const size_t size) { void* new_ptr; /* @@ -923,7 +927,8 @@ lwmem_realloc_s_ex(lwmem_t* const lw, const lwmem_region_t* region, void** const * \note This function is thread safe when \ref LWMEM_CFG_OS is enabled */ void -lwmem_free_ex(lwmem_t* const lw, void* const ptr) { +lwmem_free_ex(lwmem_t* lw, void* const ptr) { + lw = LWMEM_GET_LW(lw); LWMEM_PROTECT(lw); prv_free(lw, ptr); LWMEM_UNPROTECT(lw); @@ -944,8 +949,9 @@ lwmem_free_ex(lwmem_t* const lw, void* const ptr) { * \note This function is thread safe when \ref LWMEM_CFG_OS is enabled */ void -lwmem_free_s_ex(lwmem_t* const lw, void** const ptr) { +lwmem_free_s_ex(lwmem_t* lw, void** const ptr) { if (ptr != NULL && *ptr != NULL) { + lw = LWMEM_GET_LW(lw); LWMEM_PROTECT(lw); prv_free(lw, *ptr); LWMEM_UNPROTECT(lw); @@ -961,11 +967,12 @@ lwmem_free_s_ex(lwmem_t* const lw, void** const ptr) { * \return Block size for user in units of bytes */ size_t -lwmem_get_size_ex(lwmem_t* const lw, void* ptr) { +lwmem_get_size_ex(lwmem_t* lw, void* ptr) { lwmem_block_t* block; uint32_t len = 0; if (ptr != NULL) { + lw = LWMEM_GET_LW(lw); LWMEM_PROTECT(lw); block = LWMEM_GET_BLOCK_FROM_PTR(ptr); if (LWMEM_BLOCK_IS_ALLOC(block)) { From 57f4d15718e7a78fb331a65834f364652570c2cb Mon Sep 17 00:00:00 2001 From: upbeat27 Date: Mon, 14 Mar 2022 09:34:45 -0700 Subject: [PATCH 38/73] Add more useful info to stats Add total size, available size, and minimum ever available size --- lwmem/src/include/lwmem/lwmem.h | 13 +++++++++++++ lwmem/src/lwmem/lwmem.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/lwmem/src/include/lwmem/lwmem.h b/lwmem/src/include/lwmem/lwmem.h index bca9c4f..d81d011 100644 --- a/lwmem/src/include/lwmem/lwmem.h +++ b/lwmem/src/include/lwmem/lwmem.h @@ -70,6 +70,9 @@ typedef struct lwmem_block { * \brief Statistics structure */ typedef struct { + uint32_t mem_size_bytes; /*!< Total memory size of all regions combined */ + uint32_t mem_available_bytes; /*!< Free memory available for allocation */ + uint32_t minimum_ever_mem_available_bytes; /*!< Minimum amount of total free memory there has been in the heap since the system booted. */ uint32_t nr_alloc; /*!< Number of all allocated blocks in single instance */ uint32_t nr_free; /*!< Number of frees in the LwMEM instance */ } lwmem_stats_t; @@ -110,6 +113,9 @@ uint8_t lwmem_realloc_s_ex(lwmem_t* lw, const lwmem_region_t* region, void** void lwmem_free_ex(lwmem_t* lw, void* const ptr); void lwmem_free_s_ex(lwmem_t* lw, void** const ptr); size_t lwmem_get_size_ex(lwmem_t* lw, void* ptr); +#if LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ +void lwmem_get_stats_ex(lwmem_t* lw, lwmem_stats_t* stats); +#endif /** * \note This is a wrapper for \ref lwmem_assignmem_ex function. @@ -197,6 +203,13 @@ lwmem_region_t regions[] = { */ #define lwmem_get_size(ptr) lwmem_get_size(NULL, (ptr)) +/** + * \note This is a wrapper for \ref lwmem_get_stats_ex function. + * It operates in default LwMEM instance + * \param[in] ptr: Pointer to lwmem_stats_t to store result + */ +#define lwmem_get_stats(stats) lwmem_get_stats_ex(NULL, (stats)) + #if defined(LWMEM_DEV) && !__DOXYGEN__ unsigned char lwmem_debug_create_regions(lwmem_region_t** regs_out, size_t count, size_t size); void lwmem_debug_save_state(void); diff --git a/lwmem/src/lwmem/lwmem.c b/lwmem/src/lwmem/lwmem.c index c9a0f48..6b53c51 100644 --- a/lwmem/src/lwmem/lwmem.c +++ b/lwmem/src/lwmem/lwmem.c @@ -148,8 +148,14 @@ /* Statistics part */ #if LWMEM_CFG_ENABLE_STATS #define LWMEM_INC_STATS(field) (++(field)) +#define LWMEM_UPDATE_MIN_FREE(lw) do { \ + if (lw->mem_available_bytes < lw->stats.minimum_ever_mem_available_bytes) { \ + lw->stats.minimum_ever_mem_available_bytes = lw->mem_available_bytes; \ + } \ + } while (0) #else #define LWMEM_INC_STATS(field) +#define LWMEM_UPDATE_MIN_FREE(lw, current_free) #endif /* LWMEM_CFG_ENABLE_STATS */ /** @@ -411,6 +417,7 @@ prv_alloc(lwmem_t* const lw, const lwmem_region_t* region, const size_t size) { prv_split_too_big_block(lw, curr, final_size); /* Split block if it is too big */ LWMEM_BLOCK_SET_ALLOC(curr); /* Set block as allocated */ + LWMEM_UPDATE_MIN_FREE(lw); LWMEM_INC_STATS(lw->stats.nr_alloc); return retval; @@ -560,6 +567,7 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co * and remove next free from list of free blocks */ lw->mem_available_bytes -= prev->next->size; /* For now decrease effective available bytes */ + LWMEM_UPDATE_MIN_FREE(lw); block->size = block_size + prev->next->size;/* Increase effective size of new block */ prev->next = prev->next->next; /* Set next to next's next, effectively remove expanded block from free list */ @@ -590,6 +598,7 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co LWMEM_MEMMOVE(new_data_ptr, old_data_ptr, block_size); lw->mem_available_bytes -= prev->size;/* For now decrease effective available bytes */ + LWMEM_UPDATE_MIN_FREE(lw); prev->size += block_size; /* Increase size of input block size */ prevprev->next = prev->next; /* Remove prev from free list as it is now being used for allocation together with existing block */ block = prev; /* Move block pointer to previous one */ @@ -626,6 +635,7 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co LWMEM_MEMMOVE(new_data_ptr, old_data_ptr, block_size); /* Copy old buffer size to new location */ lw->mem_available_bytes -= prev->size + prev->next->size; /* Decrease effective available bytes for free blocks before and after input block */ + LWMEM_UPDATE_MIN_FREE(lw); prev->size += block_size + prev->next->size;/* Increase size of new block by size of 2 free blocks */ prevprev->next = prev->next->next; /* Remove free block before current one and block after current one from linked list (remove 2) */ block = prev; /* Previous block is now current */ @@ -781,6 +791,10 @@ lwmem_assignmem_ex(lwmem_t* lw, const lwmem_region_t* regions) { /* Copy default state of start block */ LWMEM_MEMCPY(&lwmem_default.start_block_first_use, &lwmem_default.start_block, sizeof(lwmem_default.start_block)); #endif /* defined(LWMEM_DEV) */ +#if LWMEM_CFG_ENABLE_STATS + lw->stats.mem_size_bytes = lw->mem_available_bytes; + lw->stats.minimum_ever_mem_available_bytes = lw->mem_available_bytes; +#endif return lw->mem_regions_count; /* Return number of regions used by manager */ } @@ -983,6 +997,23 @@ lwmem_get_size_ex(lwmem_t* lw, void* ptr) { return len; } +/** + * \brief Get statistics of a LwMEM instance + * \param[in] lw: LwMEM instance. Set to `NULL` to use default instance. + * Instance must be the same as used during allocation procedure + * \param[in] stats: Pointer to lwmem_stats_t to store result + */ +void +lwmem_get_stats_ex(lwmem_t* lw, lwmem_stats_t* stats) { + if (stats != NULL) { + lw = LWMEM_GET_LW(lw); + LWMEM_PROTECT(lw); + *stats = lw->stats; + stats->mem_available_bytes = lw->mem_available_bytes; + LWMEM_UNPROTECT(lw); + } +} + /* Part of library used ONLY for LWMEM_DEV purposes */ /* To validate and test library */ From fac7bcd7df534ea70c9b1d657df65b3b6c7403f8 Mon Sep 17 00:00:00 2001 From: upbeat27 Date: Mon, 14 Mar 2022 11:05:17 -0700 Subject: [PATCH 39/73] Address requested changes Adhering to code style --- lwmem/src/include/lwmem/lwmem.h | 2 +- lwmem/src/lwmem/lwmem.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lwmem/src/include/lwmem/lwmem.h b/lwmem/src/include/lwmem/lwmem.h index d81d011..df9f561 100644 --- a/lwmem/src/include/lwmem/lwmem.h +++ b/lwmem/src/include/lwmem/lwmem.h @@ -115,7 +115,7 @@ void lwmem_free_s_ex(lwmem_t* lw, void** const ptr); size_t lwmem_get_size_ex(lwmem_t* lw, void* ptr); #if LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ void lwmem_get_stats_ex(lwmem_t* lw, lwmem_stats_t* stats); -#endif +#endif /* LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ */ /** * \note This is a wrapper for \ref lwmem_assignmem_ex function. diff --git a/lwmem/src/lwmem/lwmem.c b/lwmem/src/lwmem/lwmem.c index 6b53c51..5441ea3 100644 --- a/lwmem/src/lwmem/lwmem.c +++ b/lwmem/src/lwmem/lwmem.c @@ -131,15 +131,15 @@ * \param[in] in_p: Previous of input block */ #define LWMEM_GET_PREV_CURR_OF_BLOCK(in_lw, in_b, in_pp, in_p) do { \ - for ((in_pp) = NULL, (in_p) = &(in_lw->start_block); \ + for ((in_pp) = NULL, (in_p) = &((in_lw)->start_block); \ (in_p) != NULL && (in_p)->next < (in_b); \ (in_pp) = (in_p), (in_p) = (in_p)->next \ ) {} \ } while (0) #if LWMEM_CFG_OS -#define LWMEM_PROTECT(lw) lwmem_sys_mutex_wait(&(lw->mutex)) -#define LWMEM_UNPROTECT(lw) lwmem_sys_mutex_release(&(lw->mutex)) +#define LWMEM_PROTECT(lw) lwmem_sys_mutex_wait(&((lw)->mutex)) +#define LWMEM_UNPROTECT(lw) lwmem_sys_mutex_release(&((lw)->mutex)) #else /* LWMEM_CFG_OS */ #define LWMEM_PROTECT(lw) #define LWMEM_UNPROTECT(lw) @@ -149,8 +149,8 @@ #if LWMEM_CFG_ENABLE_STATS #define LWMEM_INC_STATS(field) (++(field)) #define LWMEM_UPDATE_MIN_FREE(lw) do { \ - if (lw->mem_available_bytes < lw->stats.minimum_ever_mem_available_bytes) { \ - lw->stats.minimum_ever_mem_available_bytes = lw->mem_available_bytes; \ + if ((lw)->mem_available_bytes < (lw)->stats.minimum_ever_mem_available_bytes) { \ + (lw)->stats.minimum_ever_mem_available_bytes = (lw)->mem_available_bytes; \ } \ } while (0) #else @@ -688,11 +688,11 @@ lwmem_region_t regions[] = { */ size_t lwmem_assignmem_ex(lwmem_t* lw, const lwmem_region_t* regions) { - lw = LWMEM_GET_LW(lw); uint8_t* mem_start_addr; size_t mem_size, len = 0; lwmem_block_t* first_block, *prev_end_block; + lw = LWMEM_GET_LW(lw); /* Check first things first */ if (regions == NULL || lw->end_block != NULL /* Init function may only be called once per lwmem instance */ From 1bdc254431ea65d4f2c54d74bc27bb328bb13424 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 18 Mar 2022 19:22:04 +0100 Subject: [PATCH 40/73] fix bug for status --- lwmem/src/lwmem/lwmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lwmem/src/lwmem/lwmem.c b/lwmem/src/lwmem/lwmem.c index 5441ea3..e096273 100644 --- a/lwmem/src/lwmem/lwmem.c +++ b/lwmem/src/lwmem/lwmem.c @@ -155,7 +155,7 @@ } while (0) #else #define LWMEM_INC_STATS(field) -#define LWMEM_UPDATE_MIN_FREE(lw, current_free) +#define LWMEM_UPDATE_MIN_FREE(lw) #endif /* LWMEM_CFG_ENABLE_STATS */ /** From 1965d93fd4ff6caa49d8dd5d21babccc6eb4557b Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 18 Mar 2022 19:28:26 +0100 Subject: [PATCH 41/73] Do not compile if not enabled --- lwmem/src/lwmem/lwmem.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lwmem/src/lwmem/lwmem.c b/lwmem/src/lwmem/lwmem.c index e096273..2577c87 100644 --- a/lwmem/src/lwmem/lwmem.c +++ b/lwmem/src/lwmem/lwmem.c @@ -997,11 +997,13 @@ lwmem_get_size_ex(lwmem_t* lw, void* ptr) { return len; } +#if LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ + /** * \brief Get statistics of a LwMEM instance * \param[in] lw: LwMEM instance. Set to `NULL` to use default instance. * Instance must be the same as used during allocation procedure - * \param[in] stats: Pointer to lwmem_stats_t to store result + * \param[in] stats: Pointer to \ref lwmem_stats_t to store result */ void lwmem_get_stats_ex(lwmem_t* lw, lwmem_stats_t* stats) { @@ -1014,6 +1016,8 @@ lwmem_get_stats_ex(lwmem_t* lw, lwmem_stats_t* stats) { } } +#endif /* LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ */ + /* Part of library used ONLY for LWMEM_DEV purposes */ /* To validate and test library */ From d5b82ddaea60a82e1ce535dea68f0572fc40bbcc Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sat, 9 Apr 2022 12:20:53 +0200 Subject: [PATCH 42/73] fix: Wrong macro function call --- lwmem/src/include/lwmem/lwmem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lwmem/src/include/lwmem/lwmem.h b/lwmem/src/include/lwmem/lwmem.h index df9f561..0c30969 100644 --- a/lwmem/src/include/lwmem/lwmem.h +++ b/lwmem/src/include/lwmem/lwmem.h @@ -201,7 +201,7 @@ lwmem_region_t regions[] = { * \param[in] ptr: Pointer to allocated memory * \return Block size for user in units of bytes */ -#define lwmem_get_size(ptr) lwmem_get_size(NULL, (ptr)) +#define lwmem_get_size(ptr) lwmem_get_size_ex(NULL, (ptr)) /** * \note This is a wrapper for \ref lwmem_get_stats_ex function. From 55aca586c2622c43700b6cac13c69fd549fc43f5 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Wed, 13 Apr 2022 14:58:31 +0200 Subject: [PATCH 43/73] Update vscode c_cpp_properties.json to use cmake as provider --- .vscode/c_cpp_properties.json | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 0bd1c71..9768bc2 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -3,17 +3,6 @@ "configurations": [ { "name": "Win32", - "includePath": [ - "${workspaceFolder}\\dev\\", - "${workspaceFolder}\\lwmem\\src\\include\\" - ], - "defines": [ - "WIN32", - "_DEBUG", - "UNICODE", - "_UNICODE", - "LWMEM_DEV" - ], "compilerPath": "c:\\msys64\\mingw64\\bin\\gcc.exe", "cStandard": "gnu17", "cppStandard": "gnu++14", From 0139b087c75de36e96b09038f92e1a46cf2b27af Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Tue, 10 May 2022 20:38:02 +0200 Subject: [PATCH 44/73] docs: Update index rst --- docs/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/index.rst b/docs/index.rst index 009bddc..0337389 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -74,6 +74,7 @@ Table of contents LwDTC - DateTimeCron LwESP - ESP-AT library + LwEVT - Event manager LwGPS - GPS NMEA parser LwGSM - GSM-AT library LwJSON - JSON parser From f5738aa725aa58936e80d9aebfc3697cb2c20546 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Tue, 17 May 2022 22:28:39 +0200 Subject: [PATCH 45/73] Move to CMakEPresets --- .../.vscode/c_cpp_properties.json | 1 + .../.vscode/cmake-kits.json | 10 ----- .../.vscode/launch.json | 6 +-- .../.vscode/tasks.json | 23 ++-------- .../CMakeLists.txt | 5 ++- .../CMakePresets.json | 43 +++++++++++++++++++ .../{ => cmake}/gcc-arm-none-eabi.cmake | 0 .../.vscode/c_cpp_properties.json | 1 + .../.vscode/cmake-kits.json | 10 ----- .../.vscode/launch.json | 6 +-- .../.vscode/tasks.json | 23 ++-------- .../lwmem_stm32l496_discovery/CMakeLists.txt | 5 ++- .../CMakePresets.json | 43 +++++++++++++++++++ .../{ => cmake}/gcc-arm-none-eabi.cmake | 0 14 files changed, 106 insertions(+), 70 deletions(-) delete mode 100644 examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/cmake-kits.json create mode 100644 examples/stm32/lwmem_rtos_stm32l496_discovery/CMakePresets.json rename examples/stm32/lwmem_rtos_stm32l496_discovery/{ => cmake}/gcc-arm-none-eabi.cmake (100%) delete mode 100644 examples/stm32/lwmem_stm32l496_discovery/.vscode/cmake-kits.json create mode 100644 examples/stm32/lwmem_stm32l496_discovery/CMakePresets.json rename examples/stm32/lwmem_stm32l496_discovery/{ => cmake}/gcc-arm-none-eabi.cmake (100%) diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json index 954cb6b..1ead9e6 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json @@ -2,6 +2,7 @@ "version": 4, "configurations": [ { + /* ms-vscode.cmake-tools plugin shall to be installed, which provides include paths and defines through CMake file */ "name": "STM32", "includePath": [], "defines": [], diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/cmake-kits.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/cmake-kits.json deleted file mode 100644 index 4bc2d1b..0000000 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/cmake-kits.json +++ /dev/null @@ -1,10 +0,0 @@ -[ - { - "name": "GCC arm-none-eabi - custom toolchain setup", - "compilers": { - "C": "arm-none-eabi-gcc", - "CXX": "arm-none-eabi-g++" - }, - "toolchainFile": "gcc-arm-none-eabi.cmake" - } -] \ No newline at end of file diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json index 4ab494e..76f6682 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json @@ -8,14 +8,14 @@ "name": "Debug Microcontroller - ST-Link", "cwd": "${workspaceFolder}", "type": "cortex-debug", - "executable": "${command:cmake.launchTargetPath}", //or fixed file path: build/project-name.elf + "executable": "${command:cmake.launchTargetPath}", //or fixed file path: build/stm32h735g-dk-led.elf "request": "launch", //Use "attach" to connect to target w/o elf download "servertype": "stlink", - "device": "STM32L496AG", //MCU used + "device": "", //MCU used, ex. "STM32H735IG" "interface": "swd", "serialNumber": "", //Set ST-Link ID if you use multiple at the same time "runToMain": true, - "svdFile": "", //SVD file to see registers + "svdFile": "path/to/file.svd", //Path to SVD file to see registers "v1": false, "showDevDebugOutput": true, diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json index 3044733..04fe040 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json @@ -5,7 +5,7 @@ "type": "cppbuild", "label": "Build project", "command": "cmake", - "args": ["--build", "\"build\"", "-j", "8"], + "args": ["--build", "${command:cmake.buildDirectory}", "-j", "8"], "options": { "cwd": "${workspaceFolder}" }, @@ -19,7 +19,7 @@ "type": "shell", "label": "Re-build project", "command": "cmake", - "args": ["--build", "\"build\"", "--clean-first", "-v", "-j", "8"], + "args": ["--build", "${command:cmake.buildDirectory}", "--clean-first", "-v", "-j", "8"], "options": { "cwd": "${workspaceFolder}" }, @@ -29,24 +29,7 @@ "type": "shell", "label": "Clean project", "command": "cmake", - "args": ["--build", "\"build\"", "--target", "clean"], - "options": { - "cwd": "${workspaceFolder}" - }, - "problemMatcher": [] - }, - { - "type": "shell", - "label": "Run CMake configuration", - "command": "cmake", - "args": [ - "--no-warn-unused-cli", - "-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE", - "-DCMAKE_BUILD_TYPE:STRING=Debug", - "-DCMAKE_TOOLCHAIN_FILE:FILEPATH=gcc-arm-none-eabi.cmake", - "-Bbuild", - "-G", "Ninja" - ], + "args": ["--build", "${command:cmake.buildDirectory}", "--target", "clean"], "options": { "cwd": "${workspaceFolder}" }, diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt b/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt index c55a36f..270553b 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt @@ -198,6 +198,7 @@ target_link_options(${EXECUTABLE} PRIVATE -T${MCU_LINKER_SCRIPT}${linker_script_SRC} ${CPU_PARAMETERS} -Wl,-Map=${CMAKE_PROJECT_NAME}.map + -u _printf_float # STDIO float formatting support (remove if not used) --specs=nosys.specs -Wl,--start-group -lc @@ -218,9 +219,9 @@ add_custom_command(TARGET ${EXECUTABLE} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -O ihex $ ${EXECUTABLE}.hex ) -# Conver to bin file -> add conditional check? +# Convert to bin file -> add conditional check? add_custom_command(TARGET ${EXECUTABLE} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -O binary $ ${EXECUTABLE}.bin ) -message("Exiting ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt") \ No newline at end of file +message("Exiting ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt") diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakePresets.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakePresets.json new file mode 100644 index 0000000..788b377 --- /dev/null +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakePresets.json @@ -0,0 +1,43 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "default", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", + "toolchainFile": "${sourceDir}/cmake/gcc-arm-none-eabi.cmake", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + }, + { + "name": "Debug", + "inherits": "default", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "RelWithDebInfo", + "inherits": "default", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo" + } + }, + { + "name": "Release", + "inherits": "default", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "MinSizeRel", + "inherits": "default", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "MinSizeRel" + } + } + ] +} \ No newline at end of file diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/gcc-arm-none-eabi.cmake b/examples/stm32/lwmem_rtos_stm32l496_discovery/cmake/gcc-arm-none-eabi.cmake similarity index 100% rename from examples/stm32/lwmem_rtos_stm32l496_discovery/gcc-arm-none-eabi.cmake rename to examples/stm32/lwmem_rtos_stm32l496_discovery/cmake/gcc-arm-none-eabi.cmake diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json index 954cb6b..1ead9e6 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json @@ -2,6 +2,7 @@ "version": 4, "configurations": [ { + /* ms-vscode.cmake-tools plugin shall to be installed, which provides include paths and defines through CMake file */ "name": "STM32", "includePath": [], "defines": [], diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/cmake-kits.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/cmake-kits.json deleted file mode 100644 index 4bc2d1b..0000000 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/cmake-kits.json +++ /dev/null @@ -1,10 +0,0 @@ -[ - { - "name": "GCC arm-none-eabi - custom toolchain setup", - "compilers": { - "C": "arm-none-eabi-gcc", - "CXX": "arm-none-eabi-g++" - }, - "toolchainFile": "gcc-arm-none-eabi.cmake" - } -] \ No newline at end of file diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json index 4ab494e..76f6682 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json @@ -8,14 +8,14 @@ "name": "Debug Microcontroller - ST-Link", "cwd": "${workspaceFolder}", "type": "cortex-debug", - "executable": "${command:cmake.launchTargetPath}", //or fixed file path: build/project-name.elf + "executable": "${command:cmake.launchTargetPath}", //or fixed file path: build/stm32h735g-dk-led.elf "request": "launch", //Use "attach" to connect to target w/o elf download "servertype": "stlink", - "device": "STM32L496AG", //MCU used + "device": "", //MCU used, ex. "STM32H735IG" "interface": "swd", "serialNumber": "", //Set ST-Link ID if you use multiple at the same time "runToMain": true, - "svdFile": "", //SVD file to see registers + "svdFile": "path/to/file.svd", //Path to SVD file to see registers "v1": false, "showDevDebugOutput": true, diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json index 3044733..04fe040 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json @@ -5,7 +5,7 @@ "type": "cppbuild", "label": "Build project", "command": "cmake", - "args": ["--build", "\"build\"", "-j", "8"], + "args": ["--build", "${command:cmake.buildDirectory}", "-j", "8"], "options": { "cwd": "${workspaceFolder}" }, @@ -19,7 +19,7 @@ "type": "shell", "label": "Re-build project", "command": "cmake", - "args": ["--build", "\"build\"", "--clean-first", "-v", "-j", "8"], + "args": ["--build", "${command:cmake.buildDirectory}", "--clean-first", "-v", "-j", "8"], "options": { "cwd": "${workspaceFolder}" }, @@ -29,24 +29,7 @@ "type": "shell", "label": "Clean project", "command": "cmake", - "args": ["--build", "\"build\"", "--target", "clean"], - "options": { - "cwd": "${workspaceFolder}" - }, - "problemMatcher": [] - }, - { - "type": "shell", - "label": "Run CMake configuration", - "command": "cmake", - "args": [ - "--no-warn-unused-cli", - "-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE", - "-DCMAKE_BUILD_TYPE:STRING=Debug", - "-DCMAKE_TOOLCHAIN_FILE:FILEPATH=gcc-arm-none-eabi.cmake", - "-Bbuild", - "-G", "Ninja" - ], + "args": ["--build", "${command:cmake.buildDirectory}", "--target", "clean"], "options": { "cwd": "${workspaceFolder}" }, diff --git a/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt b/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt index 239e817..af04a85 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt +++ b/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt @@ -182,6 +182,7 @@ target_link_options(${EXECUTABLE} PRIVATE -T${MCU_LINKER_SCRIPT}${linker_script_SRC} ${CPU_PARAMETERS} -Wl,-Map=${CMAKE_PROJECT_NAME}.map + -u _printf_float # STDIO float formatting support (remove if not used) --specs=nosys.specs -Wl,--start-group -lc @@ -202,9 +203,9 @@ add_custom_command(TARGET ${EXECUTABLE} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -O ihex $ ${EXECUTABLE}.hex ) -# Conver to bin file -> add conditional check? +# Convert to bin file -> add conditional check? add_custom_command(TARGET ${EXECUTABLE} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -O binary $ ${EXECUTABLE}.bin ) -message("Exiting ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt") \ No newline at end of file +message("Exiting ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt") diff --git a/examples/stm32/lwmem_stm32l496_discovery/CMakePresets.json b/examples/stm32/lwmem_stm32l496_discovery/CMakePresets.json new file mode 100644 index 0000000..788b377 --- /dev/null +++ b/examples/stm32/lwmem_stm32l496_discovery/CMakePresets.json @@ -0,0 +1,43 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "default", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", + "toolchainFile": "${sourceDir}/cmake/gcc-arm-none-eabi.cmake", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + }, + { + "name": "Debug", + "inherits": "default", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "RelWithDebInfo", + "inherits": "default", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo" + } + }, + { + "name": "Release", + "inherits": "default", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "MinSizeRel", + "inherits": "default", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "MinSizeRel" + } + } + ] +} \ No newline at end of file diff --git a/examples/stm32/lwmem_stm32l496_discovery/gcc-arm-none-eabi.cmake b/examples/stm32/lwmem_stm32l496_discovery/cmake/gcc-arm-none-eabi.cmake similarity index 100% rename from examples/stm32/lwmem_stm32l496_discovery/gcc-arm-none-eabi.cmake rename to examples/stm32/lwmem_stm32l496_discovery/cmake/gcc-arm-none-eabi.cmake From 67537be39fbd21db15a0ca5d445677dbdd8b6a7c Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Wed, 18 May 2022 20:11:07 +0200 Subject: [PATCH 46/73] Update vscode & CMake related points --- cmake/gcc-arm-none-eabi.cmake | 20 ----- .../.vscode/c_cpp_properties.json | 2 +- .../.vscode/launch.json | 2 +- .../.vscode/tasks.json | 45 +++++++++- .../CMakeLists.txt | 84 +++++++++---------- .../.vscode/c_cpp_properties.json | 2 +- .../.vscode/launch.json | 2 +- .../.vscode/tasks.json | 45 +++++++++- .../lwmem_stm32l496_discovery/CMakeLists.txt | 56 ++++++------- 9 files changed, 162 insertions(+), 96 deletions(-) delete mode 100644 cmake/gcc-arm-none-eabi.cmake diff --git a/cmake/gcc-arm-none-eabi.cmake b/cmake/gcc-arm-none-eabi.cmake deleted file mode 100644 index 3577ff8..0000000 --- a/cmake/gcc-arm-none-eabi.cmake +++ /dev/null @@ -1,20 +0,0 @@ -set(CMAKE_SYSTEM_NAME Generic) -set(CMAKE_SYSTEM_PROCESSOR arm) - -# Some default GCC settings -# arm-none-eabi- must be part of path environment -set(TOOLCHAIN_PREFIX arm-none-eabi-) -set(FLAGS "-fdata-sections -ffunction-sections --specs=nano.specs -Wl,--gc-sections") -set(CPP_FLAGS "-fno-rtti -fno-exceptions -fno-threadsafe-statics") - -set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc ${FLAGS}) -set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) -set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++ ${FLAGS} ${CPP_FLAGS}) -set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy) -set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size) - -set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf") -set(CMAKE_EXECUTABLE_SUFFIX_C ".elf") -set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf") - -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json index 1ead9e6..0bd1ee9 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json @@ -2,7 +2,7 @@ "version": 4, "configurations": [ { - /* ms-vscode.cmake-tools plugin shall to be installed, which provides include paths and defines through CMake file */ + /* ms-vscode.cmake-tools plugin should be installed; it provides include paths and defines through CMake file */ "name": "STM32", "includePath": [], "defines": [], diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json index 76f6682..9b3d92d 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json @@ -17,7 +17,7 @@ "runToMain": true, "svdFile": "path/to/file.svd", //Path to SVD file to see registers "v1": false, - "showDevDebugOutput": true, + "showDevDebugOutput": "both", /* Will get automatically detected if STM32CubeIDE is installed to default directory or it can be manually provided if necessary.. */ diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json index 04fe040..fe4c345 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json @@ -34,6 +34,49 @@ "cwd": "${workspaceFolder}" }, "problemMatcher": [] - } + }, + { + "type": "shell", + "label": "CubeProg: Flash project (SWD)", + "command": "STM32_Programmer_CLI", + "args": [ + "--connect", + "port=swd", + "--download", "${command:cmake.launchTargetPath}", + "-hardRst" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + }, + { + "type": "shell", + "label": "CubeProg: Flash project with defined serial number (SWD) - you must set serial number first", + "command": "STM32_Programmer_CLI", + "args": [ + "--connect", + "port=swd", + "sn=", + "--download", "${command:cmake.launchTargetPath}", + "-hardRst" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + }, + { + "type": "shell", + "label": "CubeProg: List all available communication interfaces", + "command": "STM32_Programmer_CLI", + "args": [ + "--list", + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + }, ] } diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt b/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt index 270553b..7859dc6 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/CMakeLists.txt @@ -26,8 +26,8 @@ set(CPU_PARAMETERS # Other parameters # -mcpu, -mfloat, -mfloat-abi, ... -mcpu=cortex-m4 - -mfpu=fpv4-sp-d16 - -mfloat-abi=hard + -mfpu=fpv4-sp-d16 + -mfloat-abi=hard ) # Set linker script @@ -38,50 +38,50 @@ set(EXECUTABLE ${CMAKE_PROJECT_NAME}) # Source files # set(src_freertos_SRCS - ${PROJ_PATH}/../../lib/FreeRTOS/CMSIS_RTOS_V2/cmsis_os2.c - ${PROJ_PATH}/../../lib/FreeRTOS/croutine.c - ${PROJ_PATH}/../../lib/FreeRTOS/event_groups.c - ${PROJ_PATH}/../../lib/FreeRTOS/portable/MemMang/heap_4.c - ${PROJ_PATH}/../../lib/FreeRTOS/list.c - ${PROJ_PATH}/../../lib/FreeRTOS/portable/GCC/ARM_CM4F/port.c - ${PROJ_PATH}/../../lib/FreeRTOS/queue.c - ${PROJ_PATH}/../../lib/FreeRTOS/tasks.c - ${PROJ_PATH}/../../lib/FreeRTOS/timers.c) + ${PROJ_PATH}/../../lib/FreeRTOS/CMSIS_RTOS_V2/cmsis_os2.c + ${PROJ_PATH}/../../lib/FreeRTOS/croutine.c + ${PROJ_PATH}/../../lib/FreeRTOS/event_groups.c + ${PROJ_PATH}/../../lib/FreeRTOS/portable/MemMang/heap_4.c + ${PROJ_PATH}/../../lib/FreeRTOS/list.c + ${PROJ_PATH}/../../lib/FreeRTOS/portable/GCC/ARM_CM4F/port.c + ${PROJ_PATH}/../../lib/FreeRTOS/queue.c + ${PROJ_PATH}/../../lib/FreeRTOS/tasks.c + ${PROJ_PATH}/../../lib/FreeRTOS/timers.c) set(src_lwmem_SRCS - ${PROJ_PATH}/../../../lwmem/src/lwmem/lwmem.c - ${PROJ_PATH}/../../../lwmem/src/system/lwmem_sys_cmsis_os.c) + ${PROJ_PATH}/../../../lwmem/src/lwmem/lwmem.c + ${PROJ_PATH}/../../../lwmem/src/system/lwmem_sys_cmsis_os.c) set(src_stm32l4xx_hal_drivers_SRCS - ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_dma.c - ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_exti.c - ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_gpio.c - ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_pwr.c - ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_rcc.c - ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_usart.c - ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_utils.c) + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_dma.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_exti.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_gpio.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_pwr.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_rcc.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_usart.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_utils.c) set(src_user_SRCS - ${PROJ_PATH}/src/main.c - ${PROJ_PATH}/src/stm32l4xx_it.c - ${PROJ_PATH}/src/syscalls.c - ${PROJ_PATH}/src/system_stm32l4xx.c) + ${PROJ_PATH}/src/main.c + ${PROJ_PATH}/src/stm32l4xx_it.c + ${PROJ_PATH}/src/syscalls.c + ${PROJ_PATH}/src/system_stm32l4xx.c) set(src_startup_SRCS - ${PROJ_PATH}/STM32CubeIDE/startup/startup_stm32l496xx.s) + ${PROJ_PATH}/STM32CubeIDE/startup/startup_stm32l496xx.s) # # Include directories # set(include_c_DIRS ${PROJ_PATH}/inc - ${PROJ_PATH}/../../../lwmem/src/include - ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Inc - ${PROJ_PATH}/../../lib/st/CMSIS/Device/ST/STM32L4xx/Include - ${PROJ_PATH}/../../lib/st/CMSIS/Include - ${PROJ_PATH}/../../lib/FreeRTOS/include - ${PROJ_PATH}/../../lib/FreeRTOS/CMSIS_RTOS_V2 - ${PROJ_PATH}/../../lib/FreeRTOS/portable/GCC/ARM_CM4F + ${PROJ_PATH}/../../../lwmem/src/include + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Inc + ${PROJ_PATH}/../../lib/st/CMSIS/Device/ST/STM32L4xx/Include + ${PROJ_PATH}/../../lib/st/CMSIS/Include + ${PROJ_PATH}/../../lib/FreeRTOS/include + ${PROJ_PATH}/../../lib/FreeRTOS/CMSIS_RTOS_V2 + ${PROJ_PATH}/../../lib/FreeRTOS/portable/GCC/ARM_CM4F ) set(include_cxx_DIRS @@ -95,13 +95,13 @@ set(include_asm_DIRS # set(symbols_c_SYMB "__weak=__attribute__((weak))" - "__packed=__attribute__((__packed__))" - "USE_FULL_LL_DRIVER" - "STM32L496xx" + "__packed=__attribute__((__packed__))" + "USE_FULL_LL_DRIVER" + "STM32L496xx" ) set(symbols_cxx_SYMB "STM32F10X_MD" - "USE_STDPERIPH_DRIVER" + "USE_STDPERIPH_DRIVER" ) set(symbols_asm_SYMB @@ -120,11 +120,11 @@ link_directories(${EXECUTABLE} ${link_DIRS}) # Executable files # add_executable(${EXECUTABLE} - ${src_freertos_SRCS} - ${src_lwmem_SRCS} - ${src_stm32l4xx_hal_drivers_SRCS} - ${src_user_SRCS} - ${src_startup_SRCS}) + ${src_freertos_SRCS} + ${src_lwmem_SRCS} + ${src_stm32l4xx_hal_drivers_SRCS} + ${src_user_SRCS} + ${src_startup_SRCS}) # # Add linked libraries for linker @@ -195,7 +195,7 @@ target_compile_options(${EXECUTABLE} PRIVATE # Setup linker parameters target_link_options(${EXECUTABLE} PRIVATE - -T${MCU_LINKER_SCRIPT}${linker_script_SRC} + -T${linker_script_SRC} ${CPU_PARAMETERS} -Wl,-Map=${CMAKE_PROJECT_NAME}.map -u _printf_float # STDIO float formatting support (remove if not used) diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json index 1ead9e6..0bd1ee9 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json @@ -2,7 +2,7 @@ "version": 4, "configurations": [ { - /* ms-vscode.cmake-tools plugin shall to be installed, which provides include paths and defines through CMake file */ + /* ms-vscode.cmake-tools plugin should be installed; it provides include paths and defines through CMake file */ "name": "STM32", "includePath": [], "defines": [], diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json index 76f6682..9b3d92d 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json @@ -17,7 +17,7 @@ "runToMain": true, "svdFile": "path/to/file.svd", //Path to SVD file to see registers "v1": false, - "showDevDebugOutput": true, + "showDevDebugOutput": "both", /* Will get automatically detected if STM32CubeIDE is installed to default directory or it can be manually provided if necessary.. */ diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json index 04fe040..fe4c345 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json @@ -34,6 +34,49 @@ "cwd": "${workspaceFolder}" }, "problemMatcher": [] - } + }, + { + "type": "shell", + "label": "CubeProg: Flash project (SWD)", + "command": "STM32_Programmer_CLI", + "args": [ + "--connect", + "port=swd", + "--download", "${command:cmake.launchTargetPath}", + "-hardRst" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + }, + { + "type": "shell", + "label": "CubeProg: Flash project with defined serial number (SWD) - you must set serial number first", + "command": "STM32_Programmer_CLI", + "args": [ + "--connect", + "port=swd", + "sn=", + "--download", "${command:cmake.launchTargetPath}", + "-hardRst" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + }, + { + "type": "shell", + "label": "CubeProg: List all available communication interfaces", + "command": "STM32_Programmer_CLI", + "args": [ + "--list", + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + }, ] } diff --git a/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt b/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt index af04a85..553edb4 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt +++ b/examples/stm32/lwmem_stm32l496_discovery/CMakeLists.txt @@ -26,8 +26,8 @@ set(CPU_PARAMETERS # Other parameters # -mcpu, -mfloat, -mfloat-abi, ... -mcpu=cortex-m4 - -mfpu=fpv4-sp-d16 - -mfloat-abi=hard + -mfpu=fpv4-sp-d16 + -mfloat-abi=hard ) # Set linker script @@ -38,35 +38,35 @@ set(EXECUTABLE ${CMAKE_PROJECT_NAME}) # Source files # set(src_lwmem_SRCS - ${PROJ_PATH}/../../../lwmem/src/lwmem/lwmem.c) + ${PROJ_PATH}/../../../lwmem/src/lwmem/lwmem.c) set(src_stm32l4xx_hal_drivers_SRCS - ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_dma.c - ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_exti.c - ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_gpio.c - ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_pwr.c - ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_rcc.c - ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_usart.c - ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_utils.c) + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_dma.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_exti.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_gpio.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_pwr.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_rcc.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_usart.c + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_utils.c) set(src_user_SRCS - ${PROJ_PATH}/src/main.c - ${PROJ_PATH}/src/stm32l4xx_it.c - ${PROJ_PATH}/src/syscalls.c - ${PROJ_PATH}/src/system_stm32l4xx.c) + ${PROJ_PATH}/src/main.c + ${PROJ_PATH}/src/stm32l4xx_it.c + ${PROJ_PATH}/src/syscalls.c + ${PROJ_PATH}/src/system_stm32l4xx.c) set(src_startup_SRCS - ${PROJ_PATH}/STM32CubeIDE/startup/startup_stm32l496xx.s) + ${PROJ_PATH}/STM32CubeIDE/startup/startup_stm32l496xx.s) # # Include directories # set(include_c_DIRS ${PROJ_PATH}/inc - ${PROJ_PATH}/../../../lwmem/src/include - ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Inc - ${PROJ_PATH}/../../lib/st/CMSIS/Device/ST/STM32L4xx/Include - ${PROJ_PATH}/../../lib/st/CMSIS/Include + ${PROJ_PATH}/../../../lwmem/src/include + ${PROJ_PATH}/../../lib/st/STM32L4xx_HAL_Driver/Inc + ${PROJ_PATH}/../../lib/st/CMSIS/Device/ST/STM32L4xx/Include + ${PROJ_PATH}/../../lib/st/CMSIS/Include ) set(include_cxx_DIRS @@ -80,13 +80,13 @@ set(include_asm_DIRS # set(symbols_c_SYMB "__weak=__attribute__((weak))" - "__packed=__attribute__((__packed__))" - "USE_FULL_LL_DRIVER" - "STM32L496xx" + "__packed=__attribute__((__packed__))" + "USE_FULL_LL_DRIVER" + "STM32L496xx" ) set(symbols_cxx_SYMB "STM32F10X_MD" - "USE_STDPERIPH_DRIVER" + "USE_STDPERIPH_DRIVER" ) set(symbols_asm_SYMB @@ -105,10 +105,10 @@ link_directories(${EXECUTABLE} ${link_DIRS}) # Executable files # add_executable(${EXECUTABLE} - ${src_lwmem_SRCS} - ${src_stm32l4xx_hal_drivers_SRCS} - ${src_user_SRCS} - ${src_startup_SRCS}) + ${src_lwmem_SRCS} + ${src_stm32l4xx_hal_drivers_SRCS} + ${src_user_SRCS} + ${src_startup_SRCS}) # # Add linked libraries for linker @@ -179,7 +179,7 @@ target_compile_options(${EXECUTABLE} PRIVATE # Setup linker parameters target_link_options(${EXECUTABLE} PRIVATE - -T${MCU_LINKER_SCRIPT}${linker_script_SRC} + -T${linker_script_SRC} ${CPU_PARAMETERS} -Wl,-Map=${CMAKE_PROJECT_NAME}.map -u _printf_float # STDIO float formatting support (remove if not used) From 4849aa0c235543fb3e0e6e2e117a2fd540d45055 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Wed, 18 May 2022 20:37:13 +0200 Subject: [PATCH 47/73] Update vscode & CMake related points --- .vscode/launch.json | 5 ++--- .vscode/settings.json | 10 ++++++++++ .vscode/tasks.json | 8 ++++---- cmake/i686-w64-mingw32-gcc.cmake | 7 +++++++ cmake/x86_64-w64-mingw32-gcc.cmake | 7 +++++++ 5 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 cmake/i686-w64-mingw32-gcc.cmake create mode 100644 cmake/x86_64-w64-mingw32-gcc.cmake diff --git a/.vscode/launch.json b/.vscode/launch.json index 8b95413..bf1450f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,13 +8,12 @@ "name": "(Windows) Launch", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}\\build\\LwLibPROJECT.exe", + "program": "${command:cmake.buildDirectory}\\LwLibPROJECT.exe", "miDebuggerPath": "c:\\msys64\\mingw64\\bin\\gdb.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", - "environment": [], - "console": "integratedTerminal" + "environment": [] } ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3b59a00 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,10 @@ +{ + "files.associations": { + "lwevt_types.h": "c", + "lwevt_type.h": "c", + "lwevt.h": "c", + "string.h": "c", + "lwevt_opt.h": "c" + }, + "esbonio.sphinx.confDir": "" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 4a5e5eb..103e43a 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -5,7 +5,7 @@ "type": "cppbuild", "label": "Build project", "command": "cmake", - "args": ["--build", "\"build\"", "-j", "8"], + "args": ["--build", "${command:cmake.buildDirectory}", "-j", "8"], "options": { "cwd": "${workspaceFolder}" }, @@ -19,7 +19,7 @@ "type": "shell", "label": "Re-build project", "command": "cmake", - "args": ["--build", "\"build\"", "--clean-first", "-v", "-j", "8"], + "args": ["--build", "${command:cmake.buildDirectory}", "--clean-first", "-v", "-j", "8"], "options": { "cwd": "${workspaceFolder}" }, @@ -29,7 +29,7 @@ "type": "shell", "label": "Clean project", "command": "cmake", - "args": ["--build", "\"build\"", "--target", "clean"], + "args": ["--build", "${command:cmake.buildDirectory}", "--target", "clean"], "options": { "cwd": "${workspaceFolder}" }, @@ -38,7 +38,7 @@ { "type": "shell", "label": "Run application", - "command": "${workspaceFolder}\\build\\LwLibPROJECT.exe", + "command": "${command:cmake.buildDirectory}\\LwLibPROJECT.exe", "args": [], "problemMatcher": [], }, diff --git a/cmake/i686-w64-mingw32-gcc.cmake b/cmake/i686-w64-mingw32-gcc.cmake new file mode 100644 index 0000000..334d580 --- /dev/null +++ b/cmake/i686-w64-mingw32-gcc.cmake @@ -0,0 +1,7 @@ +set(CMAKE_SYSTEM_NAME Windows) + +# Some default GCC settings +set(CMAKE_C_COMPILER i686-w64-mingw32-gcc) +set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) diff --git a/cmake/x86_64-w64-mingw32-gcc.cmake b/cmake/x86_64-w64-mingw32-gcc.cmake new file mode 100644 index 0000000..1d82433 --- /dev/null +++ b/cmake/x86_64-w64-mingw32-gcc.cmake @@ -0,0 +1,7 @@ +set(CMAKE_SYSTEM_NAME Windows) + +# Some default GCC settings +set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) +set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) From d0847bd6fa24e330b5ab5000d2e14c2023344d5e Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Wed, 18 May 2022 23:54:43 +0200 Subject: [PATCH 48/73] Update vscode & CMake related points --- .vscode/launch.json | 2 +- .vscode/tasks.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index bf1450f..a53089a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "name": "(Windows) Launch", "type": "cppdbg", "request": "launch", - "program": "${command:cmake.buildDirectory}\\LwLibPROJECT.exe", + "program": "${command:cmake.launchTargetPath}", "miDebuggerPath": "c:\\msys64\\mingw64\\bin\\gdb.exe", "args": [], "stopAtEntry": false, diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 103e43a..b15064b 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -38,7 +38,7 @@ { "type": "shell", "label": "Run application", - "command": "${command:cmake.buildDirectory}\\LwLibPROJECT.exe", + "command": "${command:cmake.launchTargetPath}", "args": [], "problemMatcher": [], }, From de9bae60ce0a56e79d997ae9a7025d5d11420fd0 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Tue, 24 May 2022 10:10:15 +0200 Subject: [PATCH 49/73] Add CMake Presets --- CMakePresets.json | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 CMakePresets.json diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..7d277c4 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,30 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "default", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + }, + { + "name": "Win32-Debug", + "inherits": "default", + "toolchainFile": "${sourceDir}/cmake/i686-w64-mingw32-gcc.cmake", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "Win64-Debug", + "inherits": "default", + "toolchainFile": "${sourceDir}/cmake/x86_64-w64-mingw32-gcc.cmake", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + } + ] +} \ No newline at end of file From c718f4001e1a400ba10000c84f1e805693b2ec82 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sat, 18 Jun 2022 14:55:06 +0200 Subject: [PATCH 50/73] Fix wrong naming --- lwmem/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lwmem/CMakeLists.txt b/lwmem/CMakeLists.txt index 66cb97c..7e2d523 100644 --- a/lwmem/CMakeLists.txt +++ b/lwmem/CMakeLists.txt @@ -10,8 +10,8 @@ target_include_directories(lwmem INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/include # Register core library with C++ extensions add_library(lwmem_cpp INTERFACE) -target_sources(lwmem PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.c ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.cpp) -target_include_directories(lwmem INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/include) +target_sources(lwmem_cpp PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.c ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.cpp) +target_include_directories(lwmem_cpp INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/include) # Register other modules From 7a379b0c7f65d5aa1c09b05f5b18d5ca51d30ff1 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Wed, 13 Jul 2022 14:34:02 +0200 Subject: [PATCH 51/73] Improve CMake for system port --- lwmem/CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lwmem/CMakeLists.txt b/lwmem/CMakeLists.txt index 66cb97c..ed6ca1e 100644 --- a/lwmem/CMakeLists.txt +++ b/lwmem/CMakeLists.txt @@ -8,10 +8,14 @@ add_library(lwmem INTERFACE) target_sources(lwmem PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.c) target_include_directories(lwmem INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/include) +if (DEFINED LWMEM_SYS_PORT) +target_sources(lwmem PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/system/lwmem_sys_${LWMEM_SYS_PORT}.c) +endif() + # Register core library with C++ extensions add_library(lwmem_cpp INTERFACE) -target_sources(lwmem PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.c ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.cpp) -target_include_directories(lwmem INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/include) +target_sources(lwmem_cpp PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.cpp) +target_include_directories(lwmem_cpp INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/include) # Register other modules From 8f38789a625db6e907675abcbf7f051096be0586 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sun, 17 Jul 2022 09:04:52 +0200 Subject: [PATCH 52/73] Compile only if enabled --- lwmem/src/include/system/lwmem_sys.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lwmem/src/include/system/lwmem_sys.h b/lwmem/src/include/system/lwmem_sys.h index d5301e2..d07b662 100644 --- a/lwmem/src/include/system/lwmem_sys.h +++ b/lwmem/src/include/system/lwmem_sys.h @@ -42,6 +42,8 @@ extern "C" { #endif /* __cplusplus */ +#if LWMEM_CFG_OS || __DOXYGEN__ + /** * \defgroup LWMEM_SYS System functions * \brief System functions when used with operating system @@ -80,6 +82,8 @@ uint8_t lwmem_sys_mutex_release(LWMEM_CFG_OS_MUTEX_HANDLE* m); * \} */ +#endif /* LWMEM_CFG_OS || __DOXYGEN__ */ + #ifdef __cplusplus } #endif /* __cplusplus */ From 9b1a7abe073f4bf8119905c12fa0aff572db5d5f Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Wed, 27 Jul 2022 11:56:22 +0200 Subject: [PATCH 53/73] Reduce compiler warnings for -Wall -Wpedantic -Wextra --- CMakeLists.txt | 12 +++++------- lwmem/src/lwmem/lwmem.c | 10 +++++++++- tests/lwmem_test.c | 4 ++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dbd12b2..5effcf7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,13 +23,13 @@ target_sources(${PROJECT_NAME} PUBLIC # win32 port ${CMAKE_CURRENT_LIST_DIR}/lwmem/src/system/lwmem_sys_win32.c - ) +) # Add key include paths target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/dev - ) +) # Compilation definition information target_compile_definitions(${PROJECT_NAME} PUBLIC @@ -37,16 +37,14 @@ target_compile_definitions(${PROJECT_NAME} PUBLIC _DEBUG CONSOLE LWMEM_DEV - ) +) -# Compiler and linker options +# Compiler options target_compile_options(${PROJECT_NAME} PRIVATE - ${CPU_PARAMETERS} -Wall -Wextra -Wpedantic - -Wno-unused-parameter - ) +) # Add subdir with lwmem and link to the project add_subdirectory("lwmem") diff --git a/lwmem/src/lwmem/lwmem.c b/lwmem/src/lwmem/lwmem.c index 2577c87..728c777 100644 --- a/lwmem/src/lwmem/lwmem.c +++ b/lwmem/src/lwmem/lwmem.c @@ -245,7 +245,12 @@ prv_insert_free_block(lwmem_t* const lw, lwmem_block_t* nb) { * By doing this, we protect data left by app * and we make sure new allocations cannot see old information */ - LWMEM_MEMSET(LWMEM_GET_PTR_FROM_BLOCK(nb), 0x00, nb->size - LWMEM_BLOCK_META_SIZE); + if (nb != NULL) { + void* p = LWMEM_GET_PTR_FROM_BLOCK(nb); + if (p != NULL) { + LWMEM_MEMSET(p, 0x00, nb->size - LWMEM_BLOCK_META_SIZE); + } + } #endif /* LWMEM_CFG_RESET_MEMORY */ /* @@ -1102,6 +1107,9 @@ lwmem_debug_print(uint8_t print_alloc, uint8_t print_free) { size_t block_size; lwmem_block_t* block; + (void)print_alloc; + (void)print_free; + printf("|-------|------------------|--------|------|------------------|-----------------|\r\n"); printf("| Block | Address | IsFree | Size | MaxUserAllocSize | Meta |\r\n"); printf("|-------|------------------|--------|------|------------------|-----------------|\r\n"); diff --git a/tests/lwmem_test.c b/tests/lwmem_test.c index e3b33d6..3737c2b 100644 --- a/tests/lwmem_test.c +++ b/tests/lwmem_test.c @@ -54,8 +54,8 @@ lw_c_regions[] = { void lwmem_test_run(void) { - void* ptr_1, * ptr_2, * ptr_3, * ptr_4; - void* ptr_c_1, * ptr_c_2, * ptr_c_3, * ptr_c_4; + void* ptr_1, * ptr_2, * ptr_3; + void* ptr_c_1, * ptr_c_2, * ptr_c_3; /* Initialize default lwmem instance */ /* Use one of 2 possible function calls: */ From 5f399d999382380157b9f3645b4ace2c4ab2a592 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sun, 31 Jul 2022 15:21:58 +0200 Subject: [PATCH 54/73] Move projects to vscode - remove vs --- .../win32/lwmem/.vscode/c_cpp_properties.json | 13 ++ examples/win32/lwmem/.vscode/extensions.json | 7 + examples/win32/lwmem/.vscode/launch.json | 19 ++ examples/win32/lwmem/.vscode/settings.json | 13 ++ examples/win32/lwmem/.vscode/tasks.json | 46 +++++ examples/win32/lwmem/CMakeLists.txt | 37 ++++ examples/win32/lwmem/CMakePresets.json | 40 +++++ examples/win32/lwmem/lwmem.vcxproj | 162 ------------------ examples/win32/lwmem/lwmem.vcxproj.filters | 17 -- examples/win32/lwmem_examples.sln | 61 ------- .../.vscode/c_cpp_properties.json | 13 ++ .../.vscode/extensions.json | 7 + .../.vscode/launch.json | 19 ++ .../.vscode/settings.json | 13 ++ .../.vscode/tasks.json | 46 +++++ .../CMakeLists.txt | 37 ++++ .../CMakePresets.json | 40 +++++ .../lwmem_multi_ins_multi_region.vcxproj | 162 ------------------ ...mem_multi_ins_multi_region.vcxproj.filters | 17 -- .../win32/lwmem_multi_ins_multi_region/main.c | 3 + .../.vscode/c_cpp_properties.json | 13 ++ .../.vscode/extensions.json | 7 + .../lwmem_multi_region/.vscode/launch.json | 19 ++ .../lwmem_multi_region/.vscode/settings.json | 13 ++ .../lwmem_multi_region/.vscode/tasks.json | 46 +++++ .../win32/lwmem_multi_region/CMakeLists.txt | 37 ++++ .../lwmem_multi_region/CMakePresets.json | 40 +++++ .../lwmem_multi_region.vcxproj | 162 ------------------ .../lwmem_multi_region.vcxproj.filters | 17 -- .../lwmem_os/.vscode/c_cpp_properties.json | 13 ++ .../win32/lwmem_os/.vscode/extensions.json | 7 + examples/win32/lwmem_os/.vscode/launch.json | 19 ++ examples/win32/lwmem_os/.vscode/settings.json | 13 ++ examples/win32/lwmem_os/.vscode/tasks.json | 46 +++++ examples/win32/lwmem_os/CMakeLists.txt | 37 ++++ examples/win32/lwmem_os/CMakePresets.json | 40 +++++ .../win32/lwmem_os/lwmem_os.vcxproj.filters | 17 -- examples/win32/lwmem_os/main.c | 8 +- 38 files changed, 707 insertions(+), 619 deletions(-) create mode 100644 examples/win32/lwmem/.vscode/c_cpp_properties.json create mode 100644 examples/win32/lwmem/.vscode/extensions.json create mode 100644 examples/win32/lwmem/.vscode/launch.json create mode 100644 examples/win32/lwmem/.vscode/settings.json create mode 100644 examples/win32/lwmem/.vscode/tasks.json create mode 100644 examples/win32/lwmem/CMakeLists.txt create mode 100644 examples/win32/lwmem/CMakePresets.json delete mode 100644 examples/win32/lwmem/lwmem.vcxproj delete mode 100644 examples/win32/lwmem/lwmem.vcxproj.filters delete mode 100644 examples/win32/lwmem_examples.sln create mode 100644 examples/win32/lwmem_multi_ins_multi_region/.vscode/c_cpp_properties.json create mode 100644 examples/win32/lwmem_multi_ins_multi_region/.vscode/extensions.json create mode 100644 examples/win32/lwmem_multi_ins_multi_region/.vscode/launch.json create mode 100644 examples/win32/lwmem_multi_ins_multi_region/.vscode/settings.json create mode 100644 examples/win32/lwmem_multi_ins_multi_region/.vscode/tasks.json create mode 100644 examples/win32/lwmem_multi_ins_multi_region/CMakeLists.txt create mode 100644 examples/win32/lwmem_multi_ins_multi_region/CMakePresets.json delete mode 100644 examples/win32/lwmem_multi_ins_multi_region/lwmem_multi_ins_multi_region.vcxproj delete mode 100644 examples/win32/lwmem_multi_ins_multi_region/lwmem_multi_ins_multi_region.vcxproj.filters create mode 100644 examples/win32/lwmem_multi_region/.vscode/c_cpp_properties.json create mode 100644 examples/win32/lwmem_multi_region/.vscode/extensions.json create mode 100644 examples/win32/lwmem_multi_region/.vscode/launch.json create mode 100644 examples/win32/lwmem_multi_region/.vscode/settings.json create mode 100644 examples/win32/lwmem_multi_region/.vscode/tasks.json create mode 100644 examples/win32/lwmem_multi_region/CMakeLists.txt create mode 100644 examples/win32/lwmem_multi_region/CMakePresets.json delete mode 100644 examples/win32/lwmem_multi_region/lwmem_multi_region.vcxproj delete mode 100644 examples/win32/lwmem_multi_region/lwmem_multi_region.vcxproj.filters create mode 100644 examples/win32/lwmem_os/.vscode/c_cpp_properties.json create mode 100644 examples/win32/lwmem_os/.vscode/extensions.json create mode 100644 examples/win32/lwmem_os/.vscode/launch.json create mode 100644 examples/win32/lwmem_os/.vscode/settings.json create mode 100644 examples/win32/lwmem_os/.vscode/tasks.json create mode 100644 examples/win32/lwmem_os/CMakeLists.txt create mode 100644 examples/win32/lwmem_os/CMakePresets.json delete mode 100644 examples/win32/lwmem_os/lwmem_os.vcxproj.filters diff --git a/examples/win32/lwmem/.vscode/c_cpp_properties.json b/examples/win32/lwmem/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..9768bc2 --- /dev/null +++ b/examples/win32/lwmem/.vscode/c_cpp_properties.json @@ -0,0 +1,13 @@ +{ + "version": 4, + "configurations": [ + { + "name": "Win32", + "compilerPath": "c:\\msys64\\mingw64\\bin\\gcc.exe", + "cStandard": "gnu17", + "cppStandard": "gnu++14", + "intelliSenseMode": "windows-gcc-x86", + "configurationProvider": "ms-vscode.cmake-tools" + } + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem/.vscode/extensions.json b/examples/win32/lwmem/.vscode/extensions.json new file mode 100644 index 0000000..6a07920 --- /dev/null +++ b/examples/win32/lwmem/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "ms-vscode.cpptools", + "ms-vscode.cmake-tools", + "twxs.cmake", + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem/.vscode/launch.json b/examples/win32/lwmem/.vscode/launch.json new file mode 100644 index 0000000..a53089a --- /dev/null +++ b/examples/win32/lwmem/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(Windows) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${command:cmake.launchTargetPath}", + "miDebuggerPath": "c:\\msys64\\mingw64\\bin\\gdb.exe", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [] + } + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem/.vscode/settings.json b/examples/win32/lwmem/.vscode/settings.json new file mode 100644 index 0000000..c7da4d9 --- /dev/null +++ b/examples/win32/lwmem/.vscode/settings.json @@ -0,0 +1,13 @@ +{ + "files.associations": { + "lwevt_types.h": "c", + "lwevt_type.h": "c", + "lwevt.h": "c", + "string.h": "c", + "lwevt_opt.h": "c", + "cli.h": "c", + "windows.h": "c", + "lwesp_private.h": "c" + }, + "esbonio.sphinx.confDir": "" +} \ No newline at end of file diff --git a/examples/win32/lwmem/.vscode/tasks.json b/examples/win32/lwmem/.vscode/tasks.json new file mode 100644 index 0000000..e526563 --- /dev/null +++ b/examples/win32/lwmem/.vscode/tasks.json @@ -0,0 +1,46 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "cppbuild", + "label": "Build project", + "command": "cmake", + "args": ["--build", "${command:cmake.buildDirectory}", "-j", "8"], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": ["$gcc"], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "type": "shell", + "label": "Re-build project", + "command": "cmake", + "args": ["--build", "${command:cmake.buildDirectory}", "--clean-first", "-v", "-j", "8"], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": ["$gcc"], + }, + { + "type": "shell", + "label": "Clean project", + "command": "cmake", + "args": ["--build", "${command:cmake.buildDirectory}", "--target", "clean"], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + }, + { + "type": "shell", + "label": "Run application", + "command": "${command:cmake.launchTargetPath}", + "args": [], + "problemMatcher": [], + } + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem/CMakeLists.txt b/examples/win32/lwmem/CMakeLists.txt new file mode 100644 index 0000000..9fcf0a6 --- /dev/null +++ b/examples/win32/lwmem/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.22) + +# Setup project +project(lwmem_proj) +add_executable(${PROJECT_NAME}) + +# Add key executable block +target_sources(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/main.c +) + +# Add key include paths +target_include_directories(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/ + + # Snippets + ${CMAKE_CURRENT_LIST_DIR}/../../../snippets/include +) + +# Compilation definition information +target_compile_definitions(${PROJECT_NAME} PUBLIC + WIN32 + _DEBUG + CONSOLE +) + +# Compiler options +target_compile_options(${PROJECT_NAME} PRIVATE + -Wall + -Wextra + -Wpedantic +) + +# Add subdir with lwmem and link to the project +set(LWMEM_SYS_PORT "win32") +add_subdirectory("../../../lwmem" lwmem) +target_link_libraries(${PROJECT_NAME} lwmem) diff --git a/examples/win32/lwmem/CMakePresets.json b/examples/win32/lwmem/CMakePresets.json new file mode 100644 index 0000000..b2c1112 --- /dev/null +++ b/examples/win32/lwmem/CMakePresets.json @@ -0,0 +1,40 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "default", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + }, + { + "name": "Win32-Debug", + "inherits": "default", + "toolchainFile": "${sourceDir}/../../../cmake/i686-w64-mingw32-gcc.cmake", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "Win64-Debug", + "inherits": "default", + "toolchainFile": "${sourceDir}/../../../cmake/x86_64-w64-mingw32-gcc.cmake", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + } + ], + "buildPresets": [ + { + "name": "Win32-Debug", + "configurePreset": "Win32-Debug" + }, + { + "name": "Win64-Debug", + "configurePreset": "Win64-Debug" + } + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem/lwmem.vcxproj b/examples/win32/lwmem/lwmem.vcxproj deleted file mode 100644 index 12b0fe0..0000000 --- a/examples/win32/lwmem/lwmem.vcxproj +++ /dev/null @@ -1,162 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - - - - - - 16.0 - {85F83F03-72F0-4F31-B7D3-294DA7D64D4E} - Win32Proj - LwMEMexamples - 10.0 - - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - .;..\..\..\lwmem\src\include;$(IncludePath) - - - true - - - false - - - false - - - - - - Level3 - Disabled - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - Level3 - Disabled - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - Level3 - MaxSpeed - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - Level3 - MaxSpeed - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - \ No newline at end of file diff --git a/examples/win32/lwmem/lwmem.vcxproj.filters b/examples/win32/lwmem/lwmem.vcxproj.filters deleted file mode 100644 index e7e5e08..0000000 --- a/examples/win32/lwmem/lwmem.vcxproj.filters +++ /dev/null @@ -1,17 +0,0 @@ - - - - - {9e597c89-5586-4692-864f-7152981cc7cf} - - - - - - LwMEM - - - LwMEM - - - \ No newline at end of file diff --git a/examples/win32/lwmem_examples.sln b/examples/win32/lwmem_examples.sln deleted file mode 100644 index 189f567..0000000 --- a/examples/win32/lwmem_examples.sln +++ /dev/null @@ -1,61 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29418.71 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lwmem", "lwmem\lwmem.vcxproj", "{85F83F03-72F0-4F31-B7D3-294DA7D64D4E}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lwmem_multi_ins_multi_region", "lwmem_multi_ins_multi_region\lwmem_multi_ins_multi_region.vcxproj", "{435D03A4-B3C0-4BC2-B739-542366BFBFAE}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lwmem_multi_region", "lwmem_multi_region\lwmem_multi_region.vcxproj", "{145E0F0F-D703-44A2-9375-7AD2E4EAB363}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lwmem_os", "lwmem_os\lwmem_os.vcxproj", "{34D02135-7971-49BD-8933-88A9B27D0A86}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {85F83F03-72F0-4F31-B7D3-294DA7D64D4E}.Debug|x64.ActiveCfg = Debug|x64 - {85F83F03-72F0-4F31-B7D3-294DA7D64D4E}.Debug|x64.Build.0 = Debug|x64 - {85F83F03-72F0-4F31-B7D3-294DA7D64D4E}.Debug|x86.ActiveCfg = Debug|Win32 - {85F83F03-72F0-4F31-B7D3-294DA7D64D4E}.Debug|x86.Build.0 = Debug|Win32 - {85F83F03-72F0-4F31-B7D3-294DA7D64D4E}.Release|x64.ActiveCfg = Release|x64 - {85F83F03-72F0-4F31-B7D3-294DA7D64D4E}.Release|x64.Build.0 = Release|x64 - {85F83F03-72F0-4F31-B7D3-294DA7D64D4E}.Release|x86.ActiveCfg = Release|Win32 - {85F83F03-72F0-4F31-B7D3-294DA7D64D4E}.Release|x86.Build.0 = Release|Win32 - {435D03A4-B3C0-4BC2-B739-542366BFBFAE}.Debug|x64.ActiveCfg = Debug|x64 - {435D03A4-B3C0-4BC2-B739-542366BFBFAE}.Debug|x64.Build.0 = Debug|x64 - {435D03A4-B3C0-4BC2-B739-542366BFBFAE}.Debug|x86.ActiveCfg = Debug|Win32 - {435D03A4-B3C0-4BC2-B739-542366BFBFAE}.Debug|x86.Build.0 = Debug|Win32 - {435D03A4-B3C0-4BC2-B739-542366BFBFAE}.Release|x64.ActiveCfg = Release|x64 - {435D03A4-B3C0-4BC2-B739-542366BFBFAE}.Release|x64.Build.0 = Release|x64 - {435D03A4-B3C0-4BC2-B739-542366BFBFAE}.Release|x86.ActiveCfg = Release|Win32 - {435D03A4-B3C0-4BC2-B739-542366BFBFAE}.Release|x86.Build.0 = Release|Win32 - {145E0F0F-D703-44A2-9375-7AD2E4EAB363}.Debug|x64.ActiveCfg = Debug|x64 - {145E0F0F-D703-44A2-9375-7AD2E4EAB363}.Debug|x64.Build.0 = Debug|x64 - {145E0F0F-D703-44A2-9375-7AD2E4EAB363}.Debug|x86.ActiveCfg = Debug|Win32 - {145E0F0F-D703-44A2-9375-7AD2E4EAB363}.Debug|x86.Build.0 = Debug|Win32 - {145E0F0F-D703-44A2-9375-7AD2E4EAB363}.Release|x64.ActiveCfg = Release|x64 - {145E0F0F-D703-44A2-9375-7AD2E4EAB363}.Release|x64.Build.0 = Release|x64 - {145E0F0F-D703-44A2-9375-7AD2E4EAB363}.Release|x86.ActiveCfg = Release|Win32 - {145E0F0F-D703-44A2-9375-7AD2E4EAB363}.Release|x86.Build.0 = Release|Win32 - {34D02135-7971-49BD-8933-88A9B27D0A86}.Debug|x64.ActiveCfg = Debug|x64 - {34D02135-7971-49BD-8933-88A9B27D0A86}.Debug|x64.Build.0 = Debug|x64 - {34D02135-7971-49BD-8933-88A9B27D0A86}.Debug|x86.ActiveCfg = Debug|Win32 - {34D02135-7971-49BD-8933-88A9B27D0A86}.Debug|x86.Build.0 = Debug|Win32 - {34D02135-7971-49BD-8933-88A9B27D0A86}.Release|x64.ActiveCfg = Release|x64 - {34D02135-7971-49BD-8933-88A9B27D0A86}.Release|x64.Build.0 = Release|x64 - {34D02135-7971-49BD-8933-88A9B27D0A86}.Release|x86.ActiveCfg = Release|Win32 - {34D02135-7971-49BD-8933-88A9B27D0A86}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {301D859A-02BB-4B30-867F-ED2E18E3305B} - EndGlobalSection -EndGlobal diff --git a/examples/win32/lwmem_multi_ins_multi_region/.vscode/c_cpp_properties.json b/examples/win32/lwmem_multi_ins_multi_region/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..9768bc2 --- /dev/null +++ b/examples/win32/lwmem_multi_ins_multi_region/.vscode/c_cpp_properties.json @@ -0,0 +1,13 @@ +{ + "version": 4, + "configurations": [ + { + "name": "Win32", + "compilerPath": "c:\\msys64\\mingw64\\bin\\gcc.exe", + "cStandard": "gnu17", + "cppStandard": "gnu++14", + "intelliSenseMode": "windows-gcc-x86", + "configurationProvider": "ms-vscode.cmake-tools" + } + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_ins_multi_region/.vscode/extensions.json b/examples/win32/lwmem_multi_ins_multi_region/.vscode/extensions.json new file mode 100644 index 0000000..6a07920 --- /dev/null +++ b/examples/win32/lwmem_multi_ins_multi_region/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "ms-vscode.cpptools", + "ms-vscode.cmake-tools", + "twxs.cmake", + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_ins_multi_region/.vscode/launch.json b/examples/win32/lwmem_multi_ins_multi_region/.vscode/launch.json new file mode 100644 index 0000000..a53089a --- /dev/null +++ b/examples/win32/lwmem_multi_ins_multi_region/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(Windows) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${command:cmake.launchTargetPath}", + "miDebuggerPath": "c:\\msys64\\mingw64\\bin\\gdb.exe", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [] + } + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_ins_multi_region/.vscode/settings.json b/examples/win32/lwmem_multi_ins_multi_region/.vscode/settings.json new file mode 100644 index 0000000..c7da4d9 --- /dev/null +++ b/examples/win32/lwmem_multi_ins_multi_region/.vscode/settings.json @@ -0,0 +1,13 @@ +{ + "files.associations": { + "lwevt_types.h": "c", + "lwevt_type.h": "c", + "lwevt.h": "c", + "string.h": "c", + "lwevt_opt.h": "c", + "cli.h": "c", + "windows.h": "c", + "lwesp_private.h": "c" + }, + "esbonio.sphinx.confDir": "" +} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_ins_multi_region/.vscode/tasks.json b/examples/win32/lwmem_multi_ins_multi_region/.vscode/tasks.json new file mode 100644 index 0000000..e526563 --- /dev/null +++ b/examples/win32/lwmem_multi_ins_multi_region/.vscode/tasks.json @@ -0,0 +1,46 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "cppbuild", + "label": "Build project", + "command": "cmake", + "args": ["--build", "${command:cmake.buildDirectory}", "-j", "8"], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": ["$gcc"], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "type": "shell", + "label": "Re-build project", + "command": "cmake", + "args": ["--build", "${command:cmake.buildDirectory}", "--clean-first", "-v", "-j", "8"], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": ["$gcc"], + }, + { + "type": "shell", + "label": "Clean project", + "command": "cmake", + "args": ["--build", "${command:cmake.buildDirectory}", "--target", "clean"], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + }, + { + "type": "shell", + "label": "Run application", + "command": "${command:cmake.launchTargetPath}", + "args": [], + "problemMatcher": [], + } + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_ins_multi_region/CMakeLists.txt b/examples/win32/lwmem_multi_ins_multi_region/CMakeLists.txt new file mode 100644 index 0000000..4b03dc6 --- /dev/null +++ b/examples/win32/lwmem_multi_ins_multi_region/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.22) + +# Setup project +project(lwmem_multi_ins_multi_region) +add_executable(${PROJECT_NAME}) + +# Add key executable block +target_sources(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/main.c +) + +# Add key include paths +target_include_directories(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/ + + # Snippets + ${CMAKE_CURRENT_LIST_DIR}/../../../snippets/include +) + +# Compilation definition information +target_compile_definitions(${PROJECT_NAME} PUBLIC + WIN32 + _DEBUG + CONSOLE +) + +# Compiler options +target_compile_options(${PROJECT_NAME} PRIVATE + -Wall + -Wextra + -Wpedantic +) + +# Add subdir with lwmem and link to the project +set(LWMEM_SYS_PORT "win32") +add_subdirectory("../../../lwmem" lwmem) +target_link_libraries(${PROJECT_NAME} lwmem) diff --git a/examples/win32/lwmem_multi_ins_multi_region/CMakePresets.json b/examples/win32/lwmem_multi_ins_multi_region/CMakePresets.json new file mode 100644 index 0000000..b2c1112 --- /dev/null +++ b/examples/win32/lwmem_multi_ins_multi_region/CMakePresets.json @@ -0,0 +1,40 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "default", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + }, + { + "name": "Win32-Debug", + "inherits": "default", + "toolchainFile": "${sourceDir}/../../../cmake/i686-w64-mingw32-gcc.cmake", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "Win64-Debug", + "inherits": "default", + "toolchainFile": "${sourceDir}/../../../cmake/x86_64-w64-mingw32-gcc.cmake", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + } + ], + "buildPresets": [ + { + "name": "Win32-Debug", + "configurePreset": "Win32-Debug" + }, + { + "name": "Win64-Debug", + "configurePreset": "Win64-Debug" + } + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_ins_multi_region/lwmem_multi_ins_multi_region.vcxproj b/examples/win32/lwmem_multi_ins_multi_region/lwmem_multi_ins_multi_region.vcxproj deleted file mode 100644 index 9e6e480..0000000 --- a/examples/win32/lwmem_multi_ins_multi_region/lwmem_multi_ins_multi_region.vcxproj +++ /dev/null @@ -1,162 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - - - - - - 16.0 - {435D03A4-B3C0-4BC2-B739-542366BFBFAE} - Win32Proj - LwMEMexamples - 10.0 - - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - .;..\..\..\lwmem\src\include;$(IncludePath) - - - true - - - false - - - false - - - - - - Level3 - Disabled - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - Level3 - Disabled - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - Level3 - MaxSpeed - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - Level3 - MaxSpeed - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - \ No newline at end of file diff --git a/examples/win32/lwmem_multi_ins_multi_region/lwmem_multi_ins_multi_region.vcxproj.filters b/examples/win32/lwmem_multi_ins_multi_region/lwmem_multi_ins_multi_region.vcxproj.filters deleted file mode 100644 index e7e5e08..0000000 --- a/examples/win32/lwmem_multi_ins_multi_region/lwmem_multi_ins_multi_region.vcxproj.filters +++ /dev/null @@ -1,17 +0,0 @@ - - - - - {9e597c89-5586-4692-864f-7152981cc7cf} - - - - - - LwMEM - - - LwMEM - - - \ No newline at end of file diff --git a/examples/win32/lwmem_multi_ins_multi_region/main.c b/examples/win32/lwmem_multi_ins_multi_region/main.c index bc14e9a..ebbb7a8 100644 --- a/examples/win32/lwmem_multi_ins_multi_region/main.c +++ b/examples/win32/lwmem_multi_ins_multi_region/main.c @@ -75,6 +75,9 @@ main(void) { lw1_ptr1 = lwmem_malloc_ex(&lw1, NULL, 24); /* Allocate memory from custom LwMEM instance, any region */ lw1_ptr2 = lwmem_malloc_ex(&lw1, &lw1_regions[1], 24); /* Allocate memory from default LwMEM instance, force second region */ + (void)lw1_ptr1; + (void)lw1_ptr2; + /* Free memory after use */ lwmem_free_ex(&lw1, lw0_ptr1); lwmem_free_ex(&lw1, lw0_ptr2); diff --git a/examples/win32/lwmem_multi_region/.vscode/c_cpp_properties.json b/examples/win32/lwmem_multi_region/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..9768bc2 --- /dev/null +++ b/examples/win32/lwmem_multi_region/.vscode/c_cpp_properties.json @@ -0,0 +1,13 @@ +{ + "version": 4, + "configurations": [ + { + "name": "Win32", + "compilerPath": "c:\\msys64\\mingw64\\bin\\gcc.exe", + "cStandard": "gnu17", + "cppStandard": "gnu++14", + "intelliSenseMode": "windows-gcc-x86", + "configurationProvider": "ms-vscode.cmake-tools" + } + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_region/.vscode/extensions.json b/examples/win32/lwmem_multi_region/.vscode/extensions.json new file mode 100644 index 0000000..6a07920 --- /dev/null +++ b/examples/win32/lwmem_multi_region/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "ms-vscode.cpptools", + "ms-vscode.cmake-tools", + "twxs.cmake", + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_region/.vscode/launch.json b/examples/win32/lwmem_multi_region/.vscode/launch.json new file mode 100644 index 0000000..a53089a --- /dev/null +++ b/examples/win32/lwmem_multi_region/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(Windows) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${command:cmake.launchTargetPath}", + "miDebuggerPath": "c:\\msys64\\mingw64\\bin\\gdb.exe", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [] + } + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_region/.vscode/settings.json b/examples/win32/lwmem_multi_region/.vscode/settings.json new file mode 100644 index 0000000..c7da4d9 --- /dev/null +++ b/examples/win32/lwmem_multi_region/.vscode/settings.json @@ -0,0 +1,13 @@ +{ + "files.associations": { + "lwevt_types.h": "c", + "lwevt_type.h": "c", + "lwevt.h": "c", + "string.h": "c", + "lwevt_opt.h": "c", + "cli.h": "c", + "windows.h": "c", + "lwesp_private.h": "c" + }, + "esbonio.sphinx.confDir": "" +} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_region/.vscode/tasks.json b/examples/win32/lwmem_multi_region/.vscode/tasks.json new file mode 100644 index 0000000..e526563 --- /dev/null +++ b/examples/win32/lwmem_multi_region/.vscode/tasks.json @@ -0,0 +1,46 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "cppbuild", + "label": "Build project", + "command": "cmake", + "args": ["--build", "${command:cmake.buildDirectory}", "-j", "8"], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": ["$gcc"], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "type": "shell", + "label": "Re-build project", + "command": "cmake", + "args": ["--build", "${command:cmake.buildDirectory}", "--clean-first", "-v", "-j", "8"], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": ["$gcc"], + }, + { + "type": "shell", + "label": "Clean project", + "command": "cmake", + "args": ["--build", "${command:cmake.buildDirectory}", "--target", "clean"], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + }, + { + "type": "shell", + "label": "Run application", + "command": "${command:cmake.launchTargetPath}", + "args": [], + "problemMatcher": [], + } + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_region/CMakeLists.txt b/examples/win32/lwmem_multi_region/CMakeLists.txt new file mode 100644 index 0000000..3940412 --- /dev/null +++ b/examples/win32/lwmem_multi_region/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.22) + +# Setup project +project(lwmem_multi_region) +add_executable(${PROJECT_NAME}) + +# Add key executable block +target_sources(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/main.c +) + +# Add key include paths +target_include_directories(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/ + + # Snippets + ${CMAKE_CURRENT_LIST_DIR}/../../../snippets/include +) + +# Compilation definition information +target_compile_definitions(${PROJECT_NAME} PUBLIC + WIN32 + _DEBUG + CONSOLE +) + +# Compiler options +target_compile_options(${PROJECT_NAME} PRIVATE + -Wall + -Wextra + -Wpedantic +) + +# Add subdir with lwmem and link to the project +set(LWMEM_SYS_PORT "win32") +add_subdirectory("../../../lwmem" lwmem) +target_link_libraries(${PROJECT_NAME} lwmem) diff --git a/examples/win32/lwmem_multi_region/CMakePresets.json b/examples/win32/lwmem_multi_region/CMakePresets.json new file mode 100644 index 0000000..b2c1112 --- /dev/null +++ b/examples/win32/lwmem_multi_region/CMakePresets.json @@ -0,0 +1,40 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "default", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + }, + { + "name": "Win32-Debug", + "inherits": "default", + "toolchainFile": "${sourceDir}/../../../cmake/i686-w64-mingw32-gcc.cmake", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "Win64-Debug", + "inherits": "default", + "toolchainFile": "${sourceDir}/../../../cmake/x86_64-w64-mingw32-gcc.cmake", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + } + ], + "buildPresets": [ + { + "name": "Win32-Debug", + "configurePreset": "Win32-Debug" + }, + { + "name": "Win64-Debug", + "configurePreset": "Win64-Debug" + } + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_region/lwmem_multi_region.vcxproj b/examples/win32/lwmem_multi_region/lwmem_multi_region.vcxproj deleted file mode 100644 index 21abf6e..0000000 --- a/examples/win32/lwmem_multi_region/lwmem_multi_region.vcxproj +++ /dev/null @@ -1,162 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - - - - - - 16.0 - {145E0F0F-D703-44A2-9375-7AD2E4EAB363} - Win32Proj - LwMEMexamples - 10.0 - - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - .;..\..\..\lwmem\src\include;$(IncludePath) - - - true - - - false - - - false - - - - - - Level3 - Disabled - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - Level3 - Disabled - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - Level3 - MaxSpeed - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - Level3 - MaxSpeed - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - \ No newline at end of file diff --git a/examples/win32/lwmem_multi_region/lwmem_multi_region.vcxproj.filters b/examples/win32/lwmem_multi_region/lwmem_multi_region.vcxproj.filters deleted file mode 100644 index e7e5e08..0000000 --- a/examples/win32/lwmem_multi_region/lwmem_multi_region.vcxproj.filters +++ /dev/null @@ -1,17 +0,0 @@ - - - - - {9e597c89-5586-4692-864f-7152981cc7cf} - - - - - - LwMEM - - - LwMEM - - - \ No newline at end of file diff --git a/examples/win32/lwmem_os/.vscode/c_cpp_properties.json b/examples/win32/lwmem_os/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..9768bc2 --- /dev/null +++ b/examples/win32/lwmem_os/.vscode/c_cpp_properties.json @@ -0,0 +1,13 @@ +{ + "version": 4, + "configurations": [ + { + "name": "Win32", + "compilerPath": "c:\\msys64\\mingw64\\bin\\gcc.exe", + "cStandard": "gnu17", + "cppStandard": "gnu++14", + "intelliSenseMode": "windows-gcc-x86", + "configurationProvider": "ms-vscode.cmake-tools" + } + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem_os/.vscode/extensions.json b/examples/win32/lwmem_os/.vscode/extensions.json new file mode 100644 index 0000000..6a07920 --- /dev/null +++ b/examples/win32/lwmem_os/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "ms-vscode.cpptools", + "ms-vscode.cmake-tools", + "twxs.cmake", + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem_os/.vscode/launch.json b/examples/win32/lwmem_os/.vscode/launch.json new file mode 100644 index 0000000..a53089a --- /dev/null +++ b/examples/win32/lwmem_os/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(Windows) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${command:cmake.launchTargetPath}", + "miDebuggerPath": "c:\\msys64\\mingw64\\bin\\gdb.exe", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [] + } + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem_os/.vscode/settings.json b/examples/win32/lwmem_os/.vscode/settings.json new file mode 100644 index 0000000..c7da4d9 --- /dev/null +++ b/examples/win32/lwmem_os/.vscode/settings.json @@ -0,0 +1,13 @@ +{ + "files.associations": { + "lwevt_types.h": "c", + "lwevt_type.h": "c", + "lwevt.h": "c", + "string.h": "c", + "lwevt_opt.h": "c", + "cli.h": "c", + "windows.h": "c", + "lwesp_private.h": "c" + }, + "esbonio.sphinx.confDir": "" +} \ No newline at end of file diff --git a/examples/win32/lwmem_os/.vscode/tasks.json b/examples/win32/lwmem_os/.vscode/tasks.json new file mode 100644 index 0000000..e526563 --- /dev/null +++ b/examples/win32/lwmem_os/.vscode/tasks.json @@ -0,0 +1,46 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "cppbuild", + "label": "Build project", + "command": "cmake", + "args": ["--build", "${command:cmake.buildDirectory}", "-j", "8"], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": ["$gcc"], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "type": "shell", + "label": "Re-build project", + "command": "cmake", + "args": ["--build", "${command:cmake.buildDirectory}", "--clean-first", "-v", "-j", "8"], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": ["$gcc"], + }, + { + "type": "shell", + "label": "Clean project", + "command": "cmake", + "args": ["--build", "${command:cmake.buildDirectory}", "--target", "clean"], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + }, + { + "type": "shell", + "label": "Run application", + "command": "${command:cmake.launchTargetPath}", + "args": [], + "problemMatcher": [], + } + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem_os/CMakeLists.txt b/examples/win32/lwmem_os/CMakeLists.txt new file mode 100644 index 0000000..4b03dc6 --- /dev/null +++ b/examples/win32/lwmem_os/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.22) + +# Setup project +project(lwmem_multi_ins_multi_region) +add_executable(${PROJECT_NAME}) + +# Add key executable block +target_sources(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/main.c +) + +# Add key include paths +target_include_directories(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/ + + # Snippets + ${CMAKE_CURRENT_LIST_DIR}/../../../snippets/include +) + +# Compilation definition information +target_compile_definitions(${PROJECT_NAME} PUBLIC + WIN32 + _DEBUG + CONSOLE +) + +# Compiler options +target_compile_options(${PROJECT_NAME} PRIVATE + -Wall + -Wextra + -Wpedantic +) + +# Add subdir with lwmem and link to the project +set(LWMEM_SYS_PORT "win32") +add_subdirectory("../../../lwmem" lwmem) +target_link_libraries(${PROJECT_NAME} lwmem) diff --git a/examples/win32/lwmem_os/CMakePresets.json b/examples/win32/lwmem_os/CMakePresets.json new file mode 100644 index 0000000..b2c1112 --- /dev/null +++ b/examples/win32/lwmem_os/CMakePresets.json @@ -0,0 +1,40 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "default", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + }, + { + "name": "Win32-Debug", + "inherits": "default", + "toolchainFile": "${sourceDir}/../../../cmake/i686-w64-mingw32-gcc.cmake", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "Win64-Debug", + "inherits": "default", + "toolchainFile": "${sourceDir}/../../../cmake/x86_64-w64-mingw32-gcc.cmake", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + } + ], + "buildPresets": [ + { + "name": "Win32-Debug", + "configurePreset": "Win32-Debug" + }, + { + "name": "Win64-Debug", + "configurePreset": "Win64-Debug" + } + ] +} \ No newline at end of file diff --git a/examples/win32/lwmem_os/lwmem_os.vcxproj.filters b/examples/win32/lwmem_os/lwmem_os.vcxproj.filters deleted file mode 100644 index e7e5e08..0000000 --- a/examples/win32/lwmem_os/lwmem_os.vcxproj.filters +++ /dev/null @@ -1,17 +0,0 @@ - - - - - {9e597c89-5586-4692-864f-7152981cc7cf} - - - - - - LwMEM - - - LwMEM - - - \ No newline at end of file diff --git a/examples/win32/lwmem_os/main.c b/examples/win32/lwmem_os/main.c index a1a4733..3e82098 100644 --- a/examples/win32/lwmem_os/main.c +++ b/examples/win32/lwmem_os/main.c @@ -45,17 +45,17 @@ static int thread_func(void* arg) { void* ptr, * ptr2; + (void)arg; + /* Allocate memory */ - ptr = lwmem_malloc(24); - if (ptr == NULL) { + if ((ptr = lwmem_malloc(24)) == NULL) { printf("Could not allocate memory!\r\n"); return -1; } printf("Memory allocated at address 0x%p!\r\n", ptr); /* Increase its size */ - ptr2 = lwmem_realloc(ptr, 48); - if (ptr2 == NULL) { + if ((ptr2 = lwmem_realloc(ptr, 48)) == NULL) { printf("Could not reallocate existing ptr\r\n"); } else { printf("Memory reallocated at address 0x%p!\r\n", ptr2); From 441b6618597575c272d3bc4d8102dc1ce8a792f7 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sun, 31 Jul 2022 16:43:05 +0200 Subject: [PATCH 55/73] Use one vscode & cmakelists file for all projects --- .../{lwmem => }/.vscode/c_cpp_properties.json | 0 .../win32/{lwmem => }/.vscode/extensions.json | 0 .../win32/{lwmem => }/.vscode/launch.json | 0 .../win32/{lwmem => }/.vscode/settings.json | 0 examples/win32/{lwmem => }/.vscode/tasks.json | 0 examples/win32/{lwmem => }/CMakeLists.txt | 14 +- examples/win32/CMakePresets.json | 44 +++++ examples/win32/README.md | 9 + examples/win32/lwmem/CMakePresets.json | 40 ----- .../win32/{lwmem => lwmem_basic}/lwmem_opts.h | 0 examples/win32/{lwmem => lwmem_basic}/main.c | 0 .../.vscode/c_cpp_properties.json | 13 -- .../.vscode/extensions.json | 7 - .../.vscode/launch.json | 19 -- .../.vscode/settings.json | 13 -- .../.vscode/tasks.json | 46 ----- .../CMakeLists.txt | 37 ---- .../CMakePresets.json | 40 ----- .../.vscode/c_cpp_properties.json | 13 -- .../.vscode/extensions.json | 7 - .../lwmem_multi_region/.vscode/launch.json | 19 -- .../lwmem_multi_region/.vscode/settings.json | 13 -- .../lwmem_multi_region/.vscode/tasks.json | 46 ----- .../win32/lwmem_multi_region/CMakeLists.txt | 37 ---- .../lwmem_multi_region/CMakePresets.json | 40 ----- .../lwmem_os/.vscode/c_cpp_properties.json | 13 -- .../win32/lwmem_os/.vscode/extensions.json | 7 - examples/win32/lwmem_os/.vscode/launch.json | 19 -- examples/win32/lwmem_os/.vscode/settings.json | 13 -- examples/win32/lwmem_os/.vscode/tasks.json | 46 ----- examples/win32/lwmem_os/CMakeLists.txt | 37 ---- examples/win32/lwmem_os/CMakePresets.json | 40 ----- examples/win32/lwmem_os/lwmem_os.vcxproj | 162 ------------------ 33 files changed, 60 insertions(+), 734 deletions(-) rename examples/win32/{lwmem => }/.vscode/c_cpp_properties.json (100%) rename examples/win32/{lwmem => }/.vscode/extensions.json (100%) rename examples/win32/{lwmem => }/.vscode/launch.json (100%) rename examples/win32/{lwmem => }/.vscode/settings.json (100%) rename examples/win32/{lwmem => }/.vscode/tasks.json (100%) rename examples/win32/{lwmem => }/CMakeLists.txt (68%) create mode 100644 examples/win32/CMakePresets.json create mode 100644 examples/win32/README.md delete mode 100644 examples/win32/lwmem/CMakePresets.json rename examples/win32/{lwmem => lwmem_basic}/lwmem_opts.h (100%) rename examples/win32/{lwmem => lwmem_basic}/main.c (100%) delete mode 100644 examples/win32/lwmem_multi_ins_multi_region/.vscode/c_cpp_properties.json delete mode 100644 examples/win32/lwmem_multi_ins_multi_region/.vscode/extensions.json delete mode 100644 examples/win32/lwmem_multi_ins_multi_region/.vscode/launch.json delete mode 100644 examples/win32/lwmem_multi_ins_multi_region/.vscode/settings.json delete mode 100644 examples/win32/lwmem_multi_ins_multi_region/.vscode/tasks.json delete mode 100644 examples/win32/lwmem_multi_ins_multi_region/CMakeLists.txt delete mode 100644 examples/win32/lwmem_multi_ins_multi_region/CMakePresets.json delete mode 100644 examples/win32/lwmem_multi_region/.vscode/c_cpp_properties.json delete mode 100644 examples/win32/lwmem_multi_region/.vscode/extensions.json delete mode 100644 examples/win32/lwmem_multi_region/.vscode/launch.json delete mode 100644 examples/win32/lwmem_multi_region/.vscode/settings.json delete mode 100644 examples/win32/lwmem_multi_region/.vscode/tasks.json delete mode 100644 examples/win32/lwmem_multi_region/CMakeLists.txt delete mode 100644 examples/win32/lwmem_multi_region/CMakePresets.json delete mode 100644 examples/win32/lwmem_os/.vscode/c_cpp_properties.json delete mode 100644 examples/win32/lwmem_os/.vscode/extensions.json delete mode 100644 examples/win32/lwmem_os/.vscode/launch.json delete mode 100644 examples/win32/lwmem_os/.vscode/settings.json delete mode 100644 examples/win32/lwmem_os/.vscode/tasks.json delete mode 100644 examples/win32/lwmem_os/CMakeLists.txt delete mode 100644 examples/win32/lwmem_os/CMakePresets.json delete mode 100644 examples/win32/lwmem_os/lwmem_os.vcxproj diff --git a/examples/win32/lwmem/.vscode/c_cpp_properties.json b/examples/win32/.vscode/c_cpp_properties.json similarity index 100% rename from examples/win32/lwmem/.vscode/c_cpp_properties.json rename to examples/win32/.vscode/c_cpp_properties.json diff --git a/examples/win32/lwmem/.vscode/extensions.json b/examples/win32/.vscode/extensions.json similarity index 100% rename from examples/win32/lwmem/.vscode/extensions.json rename to examples/win32/.vscode/extensions.json diff --git a/examples/win32/lwmem/.vscode/launch.json b/examples/win32/.vscode/launch.json similarity index 100% rename from examples/win32/lwmem/.vscode/launch.json rename to examples/win32/.vscode/launch.json diff --git a/examples/win32/lwmem/.vscode/settings.json b/examples/win32/.vscode/settings.json similarity index 100% rename from examples/win32/lwmem/.vscode/settings.json rename to examples/win32/.vscode/settings.json diff --git a/examples/win32/lwmem/.vscode/tasks.json b/examples/win32/.vscode/tasks.json similarity index 100% rename from examples/win32/lwmem/.vscode/tasks.json rename to examples/win32/.vscode/tasks.json diff --git a/examples/win32/lwmem/CMakeLists.txt b/examples/win32/CMakeLists.txt similarity index 68% rename from examples/win32/lwmem/CMakeLists.txt rename to examples/win32/CMakeLists.txt index 9fcf0a6..3407919 100644 --- a/examples/win32/lwmem/CMakeLists.txt +++ b/examples/win32/CMakeLists.txt @@ -1,20 +1,20 @@ cmake_minimum_required(VERSION 3.22) # Setup project -project(lwmem_proj) +project(${PROJECT_NAME}) add_executable(${PROJECT_NAME}) -# Add key executable block +# Add source files target_sources(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/main.c + ${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}/main.c ) -# Add key include paths +# Add include paths target_include_directories(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/ + ${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}/ # Snippets - ${CMAKE_CURRENT_LIST_DIR}/../../../snippets/include + ${CMAKE_CURRENT_LIST_DIR}/../../snippets/include ) # Compilation definition information @@ -33,5 +33,5 @@ target_compile_options(${PROJECT_NAME} PRIVATE # Add subdir with lwmem and link to the project set(LWMEM_SYS_PORT "win32") -add_subdirectory("../../../lwmem" lwmem) +add_subdirectory("../../lwmem" lwmem) target_link_libraries(${PROJECT_NAME} lwmem) diff --git a/examples/win32/CMakePresets.json b/examples/win32/CMakePresets.json new file mode 100644 index 0000000..9e6d591 --- /dev/null +++ b/examples/win32/CMakePresets.json @@ -0,0 +1,44 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "default", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", + "toolchainFile": "${sourceDir}/../../cmake/i686-w64-mingw32-gcc.cmake", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + }, + { + "name": "lwmem_basic", + "inherits": "default", + "cacheVariables": { + "PROJECT_NAME": "lwmem_basic" + } + }, + { + "name": "lwmem_multi_region", + "inherits": "default", + "cacheVariables": { + "PROJECT_NAME": "lwmem_multi_region" + } + }, + { + "name": "lwmem_multi_ins_multi_region", + "inherits": "default", + "cacheVariables": { + "PROJECT_NAME": "lwmem_multi_ins_multi_region" + } + }, + { + "name": "lwmem_os", + "inherits": "default", + "cacheVariables": { + "PROJECT_NAME": "lwmem_os" + } + } + ] +} \ No newline at end of file diff --git a/examples/win32/README.md b/examples/win32/README.md new file mode 100644 index 0000000..eba756c --- /dev/null +++ b/examples/win32/README.md @@ -0,0 +1,9 @@ +# WIN32 examples + +Examples are provided as CMake sources. +To run then, you can use VSCode or CMake directly. + +``` +cmake --preset +cmake --build --preset +``` diff --git a/examples/win32/lwmem/CMakePresets.json b/examples/win32/lwmem/CMakePresets.json deleted file mode 100644 index b2c1112..0000000 --- a/examples/win32/lwmem/CMakePresets.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "version": 3, - "configurePresets": [ - { - "name": "default", - "hidden": true, - "generator": "Ninja", - "binaryDir": "${sourceDir}/build/${presetName}", - "cacheVariables": { - "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" - } - }, - { - "name": "Win32-Debug", - "inherits": "default", - "toolchainFile": "${sourceDir}/../../../cmake/i686-w64-mingw32-gcc.cmake", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } - }, - { - "name": "Win64-Debug", - "inherits": "default", - "toolchainFile": "${sourceDir}/../../../cmake/x86_64-w64-mingw32-gcc.cmake", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } - } - ], - "buildPresets": [ - { - "name": "Win32-Debug", - "configurePreset": "Win32-Debug" - }, - { - "name": "Win64-Debug", - "configurePreset": "Win64-Debug" - } - ] -} \ No newline at end of file diff --git a/examples/win32/lwmem/lwmem_opts.h b/examples/win32/lwmem_basic/lwmem_opts.h similarity index 100% rename from examples/win32/lwmem/lwmem_opts.h rename to examples/win32/lwmem_basic/lwmem_opts.h diff --git a/examples/win32/lwmem/main.c b/examples/win32/lwmem_basic/main.c similarity index 100% rename from examples/win32/lwmem/main.c rename to examples/win32/lwmem_basic/main.c diff --git a/examples/win32/lwmem_multi_ins_multi_region/.vscode/c_cpp_properties.json b/examples/win32/lwmem_multi_ins_multi_region/.vscode/c_cpp_properties.json deleted file mode 100644 index 9768bc2..0000000 --- a/examples/win32/lwmem_multi_ins_multi_region/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "version": 4, - "configurations": [ - { - "name": "Win32", - "compilerPath": "c:\\msys64\\mingw64\\bin\\gcc.exe", - "cStandard": "gnu17", - "cppStandard": "gnu++14", - "intelliSenseMode": "windows-gcc-x86", - "configurationProvider": "ms-vscode.cmake-tools" - } - ] -} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_ins_multi_region/.vscode/extensions.json b/examples/win32/lwmem_multi_ins_multi_region/.vscode/extensions.json deleted file mode 100644 index 6a07920..0000000 --- a/examples/win32/lwmem_multi_ins_multi_region/.vscode/extensions.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "recommendations": [ - "ms-vscode.cpptools", - "ms-vscode.cmake-tools", - "twxs.cmake", - ] -} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_ins_multi_region/.vscode/launch.json b/examples/win32/lwmem_multi_ins_multi_region/.vscode/launch.json deleted file mode 100644 index a53089a..0000000 --- a/examples/win32/lwmem_multi_ins_multi_region/.vscode/launch.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "(Windows) Launch", - "type": "cppdbg", - "request": "launch", - "program": "${command:cmake.launchTargetPath}", - "miDebuggerPath": "c:\\msys64\\mingw64\\bin\\gdb.exe", - "args": [], - "stopAtEntry": false, - "cwd": "${fileDirname}", - "environment": [] - } - ] -} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_ins_multi_region/.vscode/settings.json b/examples/win32/lwmem_multi_ins_multi_region/.vscode/settings.json deleted file mode 100644 index c7da4d9..0000000 --- a/examples/win32/lwmem_multi_ins_multi_region/.vscode/settings.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "files.associations": { - "lwevt_types.h": "c", - "lwevt_type.h": "c", - "lwevt.h": "c", - "string.h": "c", - "lwevt_opt.h": "c", - "cli.h": "c", - "windows.h": "c", - "lwesp_private.h": "c" - }, - "esbonio.sphinx.confDir": "" -} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_ins_multi_region/.vscode/tasks.json b/examples/win32/lwmem_multi_ins_multi_region/.vscode/tasks.json deleted file mode 100644 index e526563..0000000 --- a/examples/win32/lwmem_multi_ins_multi_region/.vscode/tasks.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "type": "cppbuild", - "label": "Build project", - "command": "cmake", - "args": ["--build", "${command:cmake.buildDirectory}", "-j", "8"], - "options": { - "cwd": "${workspaceFolder}" - }, - "problemMatcher": ["$gcc"], - "group": { - "kind": "build", - "isDefault": true - } - }, - { - "type": "shell", - "label": "Re-build project", - "command": "cmake", - "args": ["--build", "${command:cmake.buildDirectory}", "--clean-first", "-v", "-j", "8"], - "options": { - "cwd": "${workspaceFolder}" - }, - "problemMatcher": ["$gcc"], - }, - { - "type": "shell", - "label": "Clean project", - "command": "cmake", - "args": ["--build", "${command:cmake.buildDirectory}", "--target", "clean"], - "options": { - "cwd": "${workspaceFolder}" - }, - "problemMatcher": [] - }, - { - "type": "shell", - "label": "Run application", - "command": "${command:cmake.launchTargetPath}", - "args": [], - "problemMatcher": [], - } - ] -} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_ins_multi_region/CMakeLists.txt b/examples/win32/lwmem_multi_ins_multi_region/CMakeLists.txt deleted file mode 100644 index 4b03dc6..0000000 --- a/examples/win32/lwmem_multi_ins_multi_region/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -cmake_minimum_required(VERSION 3.22) - -# Setup project -project(lwmem_multi_ins_multi_region) -add_executable(${PROJECT_NAME}) - -# Add key executable block -target_sources(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/main.c -) - -# Add key include paths -target_include_directories(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/ - - # Snippets - ${CMAKE_CURRENT_LIST_DIR}/../../../snippets/include -) - -# Compilation definition information -target_compile_definitions(${PROJECT_NAME} PUBLIC - WIN32 - _DEBUG - CONSOLE -) - -# Compiler options -target_compile_options(${PROJECT_NAME} PRIVATE - -Wall - -Wextra - -Wpedantic -) - -# Add subdir with lwmem and link to the project -set(LWMEM_SYS_PORT "win32") -add_subdirectory("../../../lwmem" lwmem) -target_link_libraries(${PROJECT_NAME} lwmem) diff --git a/examples/win32/lwmem_multi_ins_multi_region/CMakePresets.json b/examples/win32/lwmem_multi_ins_multi_region/CMakePresets.json deleted file mode 100644 index b2c1112..0000000 --- a/examples/win32/lwmem_multi_ins_multi_region/CMakePresets.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "version": 3, - "configurePresets": [ - { - "name": "default", - "hidden": true, - "generator": "Ninja", - "binaryDir": "${sourceDir}/build/${presetName}", - "cacheVariables": { - "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" - } - }, - { - "name": "Win32-Debug", - "inherits": "default", - "toolchainFile": "${sourceDir}/../../../cmake/i686-w64-mingw32-gcc.cmake", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } - }, - { - "name": "Win64-Debug", - "inherits": "default", - "toolchainFile": "${sourceDir}/../../../cmake/x86_64-w64-mingw32-gcc.cmake", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } - } - ], - "buildPresets": [ - { - "name": "Win32-Debug", - "configurePreset": "Win32-Debug" - }, - { - "name": "Win64-Debug", - "configurePreset": "Win64-Debug" - } - ] -} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_region/.vscode/c_cpp_properties.json b/examples/win32/lwmem_multi_region/.vscode/c_cpp_properties.json deleted file mode 100644 index 9768bc2..0000000 --- a/examples/win32/lwmem_multi_region/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "version": 4, - "configurations": [ - { - "name": "Win32", - "compilerPath": "c:\\msys64\\mingw64\\bin\\gcc.exe", - "cStandard": "gnu17", - "cppStandard": "gnu++14", - "intelliSenseMode": "windows-gcc-x86", - "configurationProvider": "ms-vscode.cmake-tools" - } - ] -} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_region/.vscode/extensions.json b/examples/win32/lwmem_multi_region/.vscode/extensions.json deleted file mode 100644 index 6a07920..0000000 --- a/examples/win32/lwmem_multi_region/.vscode/extensions.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "recommendations": [ - "ms-vscode.cpptools", - "ms-vscode.cmake-tools", - "twxs.cmake", - ] -} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_region/.vscode/launch.json b/examples/win32/lwmem_multi_region/.vscode/launch.json deleted file mode 100644 index a53089a..0000000 --- a/examples/win32/lwmem_multi_region/.vscode/launch.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "(Windows) Launch", - "type": "cppdbg", - "request": "launch", - "program": "${command:cmake.launchTargetPath}", - "miDebuggerPath": "c:\\msys64\\mingw64\\bin\\gdb.exe", - "args": [], - "stopAtEntry": false, - "cwd": "${fileDirname}", - "environment": [] - } - ] -} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_region/.vscode/settings.json b/examples/win32/lwmem_multi_region/.vscode/settings.json deleted file mode 100644 index c7da4d9..0000000 --- a/examples/win32/lwmem_multi_region/.vscode/settings.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "files.associations": { - "lwevt_types.h": "c", - "lwevt_type.h": "c", - "lwevt.h": "c", - "string.h": "c", - "lwevt_opt.h": "c", - "cli.h": "c", - "windows.h": "c", - "lwesp_private.h": "c" - }, - "esbonio.sphinx.confDir": "" -} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_region/.vscode/tasks.json b/examples/win32/lwmem_multi_region/.vscode/tasks.json deleted file mode 100644 index e526563..0000000 --- a/examples/win32/lwmem_multi_region/.vscode/tasks.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "type": "cppbuild", - "label": "Build project", - "command": "cmake", - "args": ["--build", "${command:cmake.buildDirectory}", "-j", "8"], - "options": { - "cwd": "${workspaceFolder}" - }, - "problemMatcher": ["$gcc"], - "group": { - "kind": "build", - "isDefault": true - } - }, - { - "type": "shell", - "label": "Re-build project", - "command": "cmake", - "args": ["--build", "${command:cmake.buildDirectory}", "--clean-first", "-v", "-j", "8"], - "options": { - "cwd": "${workspaceFolder}" - }, - "problemMatcher": ["$gcc"], - }, - { - "type": "shell", - "label": "Clean project", - "command": "cmake", - "args": ["--build", "${command:cmake.buildDirectory}", "--target", "clean"], - "options": { - "cwd": "${workspaceFolder}" - }, - "problemMatcher": [] - }, - { - "type": "shell", - "label": "Run application", - "command": "${command:cmake.launchTargetPath}", - "args": [], - "problemMatcher": [], - } - ] -} \ No newline at end of file diff --git a/examples/win32/lwmem_multi_region/CMakeLists.txt b/examples/win32/lwmem_multi_region/CMakeLists.txt deleted file mode 100644 index 3940412..0000000 --- a/examples/win32/lwmem_multi_region/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -cmake_minimum_required(VERSION 3.22) - -# Setup project -project(lwmem_multi_region) -add_executable(${PROJECT_NAME}) - -# Add key executable block -target_sources(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/main.c -) - -# Add key include paths -target_include_directories(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/ - - # Snippets - ${CMAKE_CURRENT_LIST_DIR}/../../../snippets/include -) - -# Compilation definition information -target_compile_definitions(${PROJECT_NAME} PUBLIC - WIN32 - _DEBUG - CONSOLE -) - -# Compiler options -target_compile_options(${PROJECT_NAME} PRIVATE - -Wall - -Wextra - -Wpedantic -) - -# Add subdir with lwmem and link to the project -set(LWMEM_SYS_PORT "win32") -add_subdirectory("../../../lwmem" lwmem) -target_link_libraries(${PROJECT_NAME} lwmem) diff --git a/examples/win32/lwmem_multi_region/CMakePresets.json b/examples/win32/lwmem_multi_region/CMakePresets.json deleted file mode 100644 index b2c1112..0000000 --- a/examples/win32/lwmem_multi_region/CMakePresets.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "version": 3, - "configurePresets": [ - { - "name": "default", - "hidden": true, - "generator": "Ninja", - "binaryDir": "${sourceDir}/build/${presetName}", - "cacheVariables": { - "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" - } - }, - { - "name": "Win32-Debug", - "inherits": "default", - "toolchainFile": "${sourceDir}/../../../cmake/i686-w64-mingw32-gcc.cmake", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } - }, - { - "name": "Win64-Debug", - "inherits": "default", - "toolchainFile": "${sourceDir}/../../../cmake/x86_64-w64-mingw32-gcc.cmake", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } - } - ], - "buildPresets": [ - { - "name": "Win32-Debug", - "configurePreset": "Win32-Debug" - }, - { - "name": "Win64-Debug", - "configurePreset": "Win64-Debug" - } - ] -} \ No newline at end of file diff --git a/examples/win32/lwmem_os/.vscode/c_cpp_properties.json b/examples/win32/lwmem_os/.vscode/c_cpp_properties.json deleted file mode 100644 index 9768bc2..0000000 --- a/examples/win32/lwmem_os/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "version": 4, - "configurations": [ - { - "name": "Win32", - "compilerPath": "c:\\msys64\\mingw64\\bin\\gcc.exe", - "cStandard": "gnu17", - "cppStandard": "gnu++14", - "intelliSenseMode": "windows-gcc-x86", - "configurationProvider": "ms-vscode.cmake-tools" - } - ] -} \ No newline at end of file diff --git a/examples/win32/lwmem_os/.vscode/extensions.json b/examples/win32/lwmem_os/.vscode/extensions.json deleted file mode 100644 index 6a07920..0000000 --- a/examples/win32/lwmem_os/.vscode/extensions.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "recommendations": [ - "ms-vscode.cpptools", - "ms-vscode.cmake-tools", - "twxs.cmake", - ] -} \ No newline at end of file diff --git a/examples/win32/lwmem_os/.vscode/launch.json b/examples/win32/lwmem_os/.vscode/launch.json deleted file mode 100644 index a53089a..0000000 --- a/examples/win32/lwmem_os/.vscode/launch.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "(Windows) Launch", - "type": "cppdbg", - "request": "launch", - "program": "${command:cmake.launchTargetPath}", - "miDebuggerPath": "c:\\msys64\\mingw64\\bin\\gdb.exe", - "args": [], - "stopAtEntry": false, - "cwd": "${fileDirname}", - "environment": [] - } - ] -} \ No newline at end of file diff --git a/examples/win32/lwmem_os/.vscode/settings.json b/examples/win32/lwmem_os/.vscode/settings.json deleted file mode 100644 index c7da4d9..0000000 --- a/examples/win32/lwmem_os/.vscode/settings.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "files.associations": { - "lwevt_types.h": "c", - "lwevt_type.h": "c", - "lwevt.h": "c", - "string.h": "c", - "lwevt_opt.h": "c", - "cli.h": "c", - "windows.h": "c", - "lwesp_private.h": "c" - }, - "esbonio.sphinx.confDir": "" -} \ No newline at end of file diff --git a/examples/win32/lwmem_os/.vscode/tasks.json b/examples/win32/lwmem_os/.vscode/tasks.json deleted file mode 100644 index e526563..0000000 --- a/examples/win32/lwmem_os/.vscode/tasks.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "type": "cppbuild", - "label": "Build project", - "command": "cmake", - "args": ["--build", "${command:cmake.buildDirectory}", "-j", "8"], - "options": { - "cwd": "${workspaceFolder}" - }, - "problemMatcher": ["$gcc"], - "group": { - "kind": "build", - "isDefault": true - } - }, - { - "type": "shell", - "label": "Re-build project", - "command": "cmake", - "args": ["--build", "${command:cmake.buildDirectory}", "--clean-first", "-v", "-j", "8"], - "options": { - "cwd": "${workspaceFolder}" - }, - "problemMatcher": ["$gcc"], - }, - { - "type": "shell", - "label": "Clean project", - "command": "cmake", - "args": ["--build", "${command:cmake.buildDirectory}", "--target", "clean"], - "options": { - "cwd": "${workspaceFolder}" - }, - "problemMatcher": [] - }, - { - "type": "shell", - "label": "Run application", - "command": "${command:cmake.launchTargetPath}", - "args": [], - "problemMatcher": [], - } - ] -} \ No newline at end of file diff --git a/examples/win32/lwmem_os/CMakeLists.txt b/examples/win32/lwmem_os/CMakeLists.txt deleted file mode 100644 index 4b03dc6..0000000 --- a/examples/win32/lwmem_os/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -cmake_minimum_required(VERSION 3.22) - -# Setup project -project(lwmem_multi_ins_multi_region) -add_executable(${PROJECT_NAME}) - -# Add key executable block -target_sources(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/main.c -) - -# Add key include paths -target_include_directories(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/ - - # Snippets - ${CMAKE_CURRENT_LIST_DIR}/../../../snippets/include -) - -# Compilation definition information -target_compile_definitions(${PROJECT_NAME} PUBLIC - WIN32 - _DEBUG - CONSOLE -) - -# Compiler options -target_compile_options(${PROJECT_NAME} PRIVATE - -Wall - -Wextra - -Wpedantic -) - -# Add subdir with lwmem and link to the project -set(LWMEM_SYS_PORT "win32") -add_subdirectory("../../../lwmem" lwmem) -target_link_libraries(${PROJECT_NAME} lwmem) diff --git a/examples/win32/lwmem_os/CMakePresets.json b/examples/win32/lwmem_os/CMakePresets.json deleted file mode 100644 index b2c1112..0000000 --- a/examples/win32/lwmem_os/CMakePresets.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "version": 3, - "configurePresets": [ - { - "name": "default", - "hidden": true, - "generator": "Ninja", - "binaryDir": "${sourceDir}/build/${presetName}", - "cacheVariables": { - "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" - } - }, - { - "name": "Win32-Debug", - "inherits": "default", - "toolchainFile": "${sourceDir}/../../../cmake/i686-w64-mingw32-gcc.cmake", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } - }, - { - "name": "Win64-Debug", - "inherits": "default", - "toolchainFile": "${sourceDir}/../../../cmake/x86_64-w64-mingw32-gcc.cmake", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } - } - ], - "buildPresets": [ - { - "name": "Win32-Debug", - "configurePreset": "Win32-Debug" - }, - { - "name": "Win64-Debug", - "configurePreset": "Win64-Debug" - } - ] -} \ No newline at end of file diff --git a/examples/win32/lwmem_os/lwmem_os.vcxproj b/examples/win32/lwmem_os/lwmem_os.vcxproj deleted file mode 100644 index d8064ff..0000000 --- a/examples/win32/lwmem_os/lwmem_os.vcxproj +++ /dev/null @@ -1,162 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - - - - - - 16.0 - {34D02135-7971-49BD-8933-88A9B27D0A86} - Win32Proj - LwMEMexamples - 10.0 - - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - .;..\..\..\lwmem\src\include;$(IncludePath) - - - true - - - false - - - false - - - - - - Level3 - Disabled - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - Level3 - Disabled - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - Level3 - MaxSpeed - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - Level3 - MaxSpeed - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - \ No newline at end of file From 6e5c080bcd14f22ca2f4f92253e94311a542fd5e Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sun, 31 Jul 2022 16:44:05 +0200 Subject: [PATCH 56/73] Add build presets --- examples/win32/CMakePresets.json | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/examples/win32/CMakePresets.json b/examples/win32/CMakePresets.json index 9e6d591..0f15284 100644 --- a/examples/win32/CMakePresets.json +++ b/examples/win32/CMakePresets.json @@ -40,5 +40,23 @@ "PROJECT_NAME": "lwmem_os" } } + ], + "buildPresets": [ + { + "name": "lwmem_basic", + "configurePreset": "lwmem_basic" + }, + { + "name": "lwmem_multi_region", + "configurePreset": "lwmem_multi_region" + }, + { + "name": "lwmem_multi_ins_multi_region", + "configurePreset": "lwmem_multi_ins_multi_region" + }, + { + "name": "lwmem_os", + "configurePreset": "lwmem_os" + } ] } \ No newline at end of file From 3cfa0c6b43f27c6e029522b6984ad7046bba5460 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sun, 31 Jul 2022 20:44:38 +0200 Subject: [PATCH 57/73] Update docs for exmaples --- docs/examples/index.rst | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/examples/index.rst b/docs/examples/index.rst index 6ef4a24..905872f 100644 --- a/docs/examples/index.rst +++ b/docs/examples/index.rst @@ -5,8 +5,8 @@ Examples and demos Various examples are provided for fast library evaluation on embedded systems. These are prepared and maintained for ``2`` platforms, but could be easily extended to more platforms: -* WIN32 examples, prepared as `Visual Studio Community `_ projects -* ARM Cortex-M examples for STM32, prepared as `STM32CubeIDE `_ GCC projects +* WIN32 examples, prepared as `CMake` projects, ready for `MSYS2 GCC compiler` +* ARM Cortex-M examples for STM32, prepared as `STM32CubeIDE `_ GCC projects. These are also supported in *Visual Studio Code* through *CMake* and *ninja* build system. `Dedicated tutorial `_ is available to get started in *VSCode*. .. warning:: Library is platform independent and can be used on any platform. @@ -20,8 +20,12 @@ Therefore it has been decided to support (for purpose of examples) ``2`` platfor WIN32 ***** -Examples for *WIN32* are prepared as `Visual Studio Community `_ projects. -You can directly open project in the IDE, compile & debug. +Examples for *WIN32* are CMake-ready and *VSCode*-ready. +It utilizes CMake-presets feature to let you select the example and compile it directly. + +* Make sure you have installed GCC compiler and is in env path (you can get it through MSYS2 packet manager) +* Install ninja and cmake and make them available in the path (you can get all through MSYS2 packet manager) +* Go to *examples win32* folder, open vscode there or run cmd: ``cmake --preset `` to configure cmake and later ``cmake --build --preset `` to compile the project STM32 ***** From 01cef12325af36e6d53cf1203f19774aa9e6555f Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sun, 31 Jul 2022 21:11:10 +0200 Subject: [PATCH 58/73] Add quick build-all script --- examples/win32/build_all_examples.py | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 examples/win32/build_all_examples.py diff --git a/examples/win32/build_all_examples.py b/examples/win32/build_all_examples.py new file mode 100644 index 0000000..9bc1747 --- /dev/null +++ b/examples/win32/build_all_examples.py @@ -0,0 +1,42 @@ +import os +import re + +# Get presets from the path +# Use cmake command line to list actual presets visible to cmake +def get_presets(): + presets = [] + resp = os.popen("cmake --list-presets").read().strip() + for line in resp.split("\n"): + l = line.strip() + r = re.findall("\"(.*)\"", l) + if r: + presets.append(r[0]) + return presets + +# Main execution +if __name__ == '__main__': + # Get all presets + failed = [] + presets = get_presets() + for preset in presets: + print("-------------------------------") + print("Configuring preset " + preset) + print("-------------------------------") + ret = os.system("cmake --preset " + preset) + if ret != 0: + print("!!!! Command failed !!!! with result code: " + str(ret)) + failed.append(preset) + print("Return: " + str(ret)) + print("-------------------------------") + print("Building preset " + preset) + print("-------------------------------") + ret = os.system("cmake --build --preset " + preset) + if ret != 0: + print("!!!! Command failed !!!! with result code: " + str(ret)) + failed.append(preset) + print("Return: " + str(ret)) + print("-------------------------------") + print("Failed presets:") + for p in failed: + print(p) + print("-------------------------------") \ No newline at end of file From 3b5345983b1662e3840abe597eb0d693ae601622 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sun, 31 Jul 2022 21:15:56 +0200 Subject: [PATCH 59/73] Add build-all-win32-examples task to dev env --- .vscode/tasks.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index b15064b..09422ee 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -69,5 +69,17 @@ }, "problemMatcher": [] }, + { + "label": "Build all WIN32 examples", + "type": "shell", + "command": "python", + "args": [ + "build_all_examples.py" + ], + "options": { + "cwd": "${workspaceFolder}/examples/win32" + }, + "problemMatcher": [] + } ] } \ No newline at end of file From 4bfb1c1c7dd8f54863ae3efa8483d1fc994f0044 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Tue, 16 Aug 2022 08:54:27 +0200 Subject: [PATCH 60/73] Improve C/C++ configuration for vscode --- .../.vscode/c_cpp_properties.json | 20 +++++++++---------- .../.vscode/c_cpp_properties.json | 20 +++++++++---------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json index 0bd1ee9..dd16d4c 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/c_cpp_properties.json @@ -2,17 +2,15 @@ "version": 4, "configurations": [ { - /* ms-vscode.cmake-tools plugin should be installed; it provides include paths and defines through CMake file */ + /* + * ms-vscode.cmake-tools plugin should be installed. + * + * It provides data for C/C++ plugin, + * such as include paths, browse paths, defines, etc. + */ "name": "STM32", - "includePath": [], - "defines": [], - "compilerPath": "", - "cStandard": "gnu17", - "cppStandard": "gnu++14", - "intelliSenseMode": "${default}", - - /* Use this and all the include paths will come from CMake configuration instead */ - "configurationProvider": "ms-vscode.cmake-tools" + "configurationProvider": "ms-vscode.cmake-tools", + "intelliSenseMode": "${default}" } ] -} \ No newline at end of file +} diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json index 0bd1ee9..dd16d4c 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/c_cpp_properties.json @@ -2,17 +2,15 @@ "version": 4, "configurations": [ { - /* ms-vscode.cmake-tools plugin should be installed; it provides include paths and defines through CMake file */ + /* + * ms-vscode.cmake-tools plugin should be installed. + * + * It provides data for C/C++ plugin, + * such as include paths, browse paths, defines, etc. + */ "name": "STM32", - "includePath": [], - "defines": [], - "compilerPath": "", - "cStandard": "gnu17", - "cppStandard": "gnu++14", - "intelliSenseMode": "${default}", - - /* Use this and all the include paths will come from CMake configuration instead */ - "configurationProvider": "ms-vscode.cmake-tools" + "configurationProvider": "ms-vscode.cmake-tools", + "intelliSenseMode": "${default}" } ] -} \ No newline at end of file +} From 112cd6598dfcac3044673fdff2840ed3f1343762 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Wed, 17 Aug 2022 21:24:58 +0200 Subject: [PATCH 61/73] Update C/C++ properties --- .vscode/c_cpp_properties.json | 9 +++++---- examples/win32/.vscode/c_cpp_properties.json | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 9768bc2..4f457d1 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -2,11 +2,12 @@ "version": 4, "configurations": [ { + /* + * Full configuration is provided by CMake plugin for vscode, + * that shall be installed by user + */ "name": "Win32", - "compilerPath": "c:\\msys64\\mingw64\\bin\\gcc.exe", - "cStandard": "gnu17", - "cppStandard": "gnu++14", - "intelliSenseMode": "windows-gcc-x86", + "intelliSenseMode": "${default}", "configurationProvider": "ms-vscode.cmake-tools" } ] diff --git a/examples/win32/.vscode/c_cpp_properties.json b/examples/win32/.vscode/c_cpp_properties.json index 9768bc2..4f457d1 100644 --- a/examples/win32/.vscode/c_cpp_properties.json +++ b/examples/win32/.vscode/c_cpp_properties.json @@ -2,11 +2,12 @@ "version": 4, "configurations": [ { + /* + * Full configuration is provided by CMake plugin for vscode, + * that shall be installed by user + */ "name": "Win32", - "compilerPath": "c:\\msys64\\mingw64\\bin\\gcc.exe", - "cStandard": "gnu17", - "cppStandard": "gnu++14", - "intelliSenseMode": "windows-gcc-x86", + "intelliSenseMode": "${default}", "configurationProvider": "ms-vscode.cmake-tools" } ] From 779e18d83a00946a70acbc3a76ab4e812a250521 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sun, 21 Aug 2022 16:50:08 +0200 Subject: [PATCH 62/73] Update docs --- docs/changelog/index.rst | 6 ++++++ docs/index.rst | 1 + 2 files changed, 7 insertions(+) create mode 100644 docs/changelog/index.rst diff --git a/docs/changelog/index.rst b/docs/changelog/index.rst new file mode 100644 index 0000000..51b89b4 --- /dev/null +++ b/docs/changelog/index.rst @@ -0,0 +1,6 @@ +.. _changelof: + +Changelog +========= + +.. literalinclude:: ../../CHANGELOG.md diff --git a/docs/index.rst b/docs/index.rst index 0337389..8129e18 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -66,6 +66,7 @@ Table of contents user-manual/index api-reference/index examples/index + changelog/index .. toctree:: :maxdepth: 2 From 90e4218226c8bd8a3be789b539e9f6f2df4953c0 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Tue, 30 Aug 2022 22:19:39 +0200 Subject: [PATCH 63/73] Add .clang-format first file --- .clang-format | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++ CHANGELOG.md | 1 + 2 files changed, 200 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..7f92b4a --- /dev/null +++ b/.clang-format @@ -0,0 +1,199 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveMacros: + Enabled: true + AcrossEmptyLines: true + AcrossComments: true +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: + Enabled: true + AcrossEmptyLines: true + AcrossComments: true +AlignConsecutiveDeclarations: None +AlignEscapedNewlines: Right +AlignOperands: Align +InsertBraces: true # Control statements must have curly brackets +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: AllDefinitions +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: 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 +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeConceptDeclarations: true +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +QualifierAlignment: Leave +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +PackConstructorInitializers: BinPack +BasedOnStyle: '' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +AllowAllConstructorInitializersOnNextLine: true +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseLabels: true +IndentCaseBlocks: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentExternBlock: AfterExternBlock +IndentRequires: true +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +LambdaBodyIndentation: Signature +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PenaltyIndentedWhitespace: 0 +PointerAlignment: Left +PPIndentWidth: -1 +ReferenceAlignment: Pointer +ReflowComments: false +RemoveBracesLLVM: false +SeparateDefinitionBlocks: Always +ShortNamespaceLines: 1 +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + BeforeNonEmptyParentheses: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +BitFieldColonSpacing: Both +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +... + diff --git a/CHANGELOG.md b/CHANGELOG.md index 876a5a3..aa56841 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Add C++ wrapper functions - Change license year to 2022 - Update code style with astyle +- Add `.clang-format` draft ## v2.0.0 From c16c2a3ef08f4e95de800eade409ce3107b68a05 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Thu, 1 Sep 2022 07:45:22 +0200 Subject: [PATCH 64/73] Update clang with regex and template break --- .clang-format | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/.clang-format b/.clang-format index 7f92b4a..490ba55 100644 --- a/.clang-format +++ b/.clang-format @@ -30,7 +30,7 @@ AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: AllDefinitions AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: MultiLine +AlwaysBreakTemplateDeclarations: Yes AttributeMacros: - __capability BinPackArguments: true @@ -90,18 +90,12 @@ IfMacros: - KJ_IF_MAYBE IncludeBlocks: Preserve IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - SortPriority: 0 - CaseSensitive: false - - Regex: '^(<|"(gtest|gmock|isl|json)/)' - Priority: 3 - SortPriority: 0 - CaseSensitive: false - - Regex: '.*' + - Regex: '^<(.*)>' + Priority: 0 + - Regex: '^"(.*)"' Priority: 1 - SortPriority: 0 - CaseSensitive: false + - Regex: '(.*)' + Priority: 2 IncludeIsMainRegex: '(Test)?$' IncludeIsMainSourceRegex: '' IndentAccessModifiers: false From b268fbbb868a72face3f987196f9b6174ada4ce2 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Thu, 1 Sep 2022 19:05:40 +0200 Subject: [PATCH 65/73] Apply clang-format --- dev/main.cpp | 4 +- lwmem/src/include/lwmem/lwmem.h | 87 ++++----- lwmem/src/include/lwmem/lwmem.hpp | 16 +- lwmem/src/include/lwmem/lwmem_opt.h | 10 +- lwmem/src/include/system/lwmem_sys.h | 10 +- lwmem/src/lwmem/lwmem.c | 255 ++++++++++++++------------- 6 files changed, 199 insertions(+), 183 deletions(-) diff --git a/dev/main.cpp b/dev/main.cpp index 5356162..62a4871 100644 --- a/dev/main.cpp +++ b/dev/main.cpp @@ -1,8 +1,8 @@ #include "lwmem/lwmem.h" #include "lwmem/lwmem.hpp" -#include -#include #include +#include +#include extern "C" void lwmem_test_run(void); extern "C" void lwmem_test_memory_structure(void); diff --git a/lwmem/src/include/lwmem/lwmem.h b/lwmem/src/include/lwmem/lwmem.h index 0c30969..fe996db 100644 --- a/lwmem/src/include/lwmem/lwmem.h +++ b/lwmem/src/include/lwmem/lwmem.h @@ -34,8 +34,8 @@ #ifndef LWMEM_HDR_H #define LWMEM_HDR_H -#include #include +#include #include "lwmem/lwmem_opt.h" #ifdef __cplusplus @@ -53,15 +53,15 @@ extern "C" { * \param[in] x: Object to get array size of * \return Number of elements in array */ -#define LWMEM_ARRAYSIZE(x) (sizeof(x) / sizeof((x)[0])) +#define LWMEM_ARRAYSIZE(x) (sizeof(x) / sizeof((x)[0])) /** * \brief Memory block structure */ typedef struct lwmem_block { - struct lwmem_block* next; /*!< Next free memory block on linked list. - Set to \ref LWMEM_BLOCK_ALLOC_MARK when block is allocated and in use */ - size_t size; /*!< Size of block, including metadata part. + struct lwmem_block* + next; /*!< Next free memory block on linked list. Set to \ref LWMEM_BLOCK_ALLOC_MARK when block is allocated and in use */ + size_t size; /*!< Size of block, including metadata part. MSB bit is set to `1` when block is allocated and in use, or `0` when block is considered free */ } lwmem_block_t; @@ -70,51 +70,52 @@ typedef struct lwmem_block { * \brief Statistics structure */ typedef struct { - uint32_t mem_size_bytes; /*!< Total memory size of all regions combined */ - uint32_t mem_available_bytes; /*!< Free memory available for allocation */ - uint32_t minimum_ever_mem_available_bytes; /*!< Minimum amount of total free memory there has been in the heap since the system booted. */ - uint32_t nr_alloc; /*!< Number of all allocated blocks in single instance */ - uint32_t nr_free; /*!< Number of frees in the LwMEM instance */ + uint32_t mem_size_bytes; /*!< Total memory size of all regions combined */ + uint32_t mem_available_bytes; /*!< Free memory available for allocation */ + uint32_t + minimum_ever_mem_available_bytes; /*!< Minimum amount of total free memory there has been in the heap since the system booted. */ + uint32_t nr_alloc; /*!< Number of all allocated blocks in single instance */ + uint32_t nr_free; /*!< Number of frees in the LwMEM instance */ } lwmem_stats_t; /** * \brief LwMEM main structure */ typedef struct lwmem { - lwmem_block_t start_block; /*!< Holds beginning of memory allocation regions */ - lwmem_block_t* end_block; /*!< Pointer to the last memory location in regions linked list */ - size_t mem_available_bytes; /*!< Memory size available for allocation */ - size_t mem_regions_count; /*!< Number of regions used for allocation */ + lwmem_block_t start_block; /*!< Holds beginning of memory allocation regions */ + lwmem_block_t* end_block; /*!< Pointer to the last memory location in regions linked list */ + size_t mem_available_bytes; /*!< Memory size available for allocation */ + size_t mem_regions_count; /*!< Number of regions used for allocation */ #if LWMEM_CFG_OS || __DOXYGEN__ - LWMEM_CFG_OS_MUTEX_HANDLE mutex; /*!< System mutex for OS */ -#endif /* LWMEM_CFG_OS || __DOXYGEN__ */ + LWMEM_CFG_OS_MUTEX_HANDLE mutex; /*!< System mutex for OS */ +#endif /* LWMEM_CFG_OS || __DOXYGEN__ */ #if LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ - lwmem_stats_t stats; /*!< Statistics */ -#endif /* LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ */ + lwmem_stats_t stats; /*!< Statistics */ +#endif /* LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ */ #if defined(LWMEM_DEV) && !__DOXYGEN__ - lwmem_block_t start_block_first_use; /*!< Value of start block for very first time. + lwmem_block_t start_block_first_use; /*!< Value of start block for very first time. This is used only during validation process and is removed in final use */ -#endif /* defined(LWMEM_DEV) && !__DOXYGEN__ */ +#endif /* defined(LWMEM_DEV) && !__DOXYGEN__ */ } lwmem_t; /** * \brief Memory region descriptor */ typedef struct { - void* start_addr; /*!< Region start address */ - size_t size; /*!< Size of region in units of bytes */ + void* start_addr; /*!< Region start address */ + size_t size; /*!< Size of region in units of bytes */ } lwmem_region_t; -size_t lwmem_assignmem_ex(lwmem_t* lw, const lwmem_region_t* regions); -void* lwmem_malloc_ex(lwmem_t* lw, const lwmem_region_t* region, const size_t size); -void* lwmem_calloc_ex(lwmem_t* lw, const lwmem_region_t* region, const size_t nitems, const size_t size); -void* lwmem_realloc_ex(lwmem_t* lw, const lwmem_region_t* region, void* const ptr, const size_t size); -uint8_t lwmem_realloc_s_ex(lwmem_t* lw, const lwmem_region_t* region, void** const ptr, const size_t size); -void lwmem_free_ex(lwmem_t* lw, void* const ptr); -void lwmem_free_s_ex(lwmem_t* lw, void** const ptr); -size_t lwmem_get_size_ex(lwmem_t* lw, void* ptr); +size_t lwmem_assignmem_ex(lwmem_t* lw, const lwmem_region_t* regions); +void* lwmem_malloc_ex(lwmem_t* lw, const lwmem_region_t* region, const size_t size); +void* lwmem_calloc_ex(lwmem_t* lw, const lwmem_region_t* region, const size_t nitems, const size_t size); +void* lwmem_realloc_ex(lwmem_t* lw, const lwmem_region_t* region, void* const ptr, const size_t size); +uint8_t lwmem_realloc_s_ex(lwmem_t* lw, const lwmem_region_t* region, void** const ptr, const size_t size); +void lwmem_free_ex(lwmem_t* lw, void* const ptr); +void lwmem_free_s_ex(lwmem_t* lw, void** const ptr); +size_t lwmem_get_size_ex(lwmem_t* lw, void* ptr); #if LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ -void lwmem_get_stats_ex(lwmem_t* lw, lwmem_stats_t* stats); +void lwmem_get_stats_ex(lwmem_t* lw, lwmem_stats_t* stats); #endif /* LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ */ /** @@ -134,7 +135,7 @@ lwmem_region_t regions[] = { \endcode * \return `0` on failure, number of final regions used for memory manager on success */ -#define lwmem_assignmem(regions) lwmem_assignmem_ex(NULL, (regions)) +#define lwmem_assignmem(regions) lwmem_assignmem_ex(NULL, (regions)) /** * \note This is a wrapper for \ref lwmem_malloc_ex function. @@ -143,7 +144,7 @@ lwmem_region_t regions[] = { * \return Pointer to allocated memory on success, `NULL` otherwise * \note This function is thread safe when \ref LWMEM_CFG_OS is enabled */ -#define lwmem_malloc(size) lwmem_malloc_ex(NULL, NULL, (size)) +#define lwmem_malloc(size) lwmem_malloc_ex(NULL, NULL, (size)) /** * \note This is a wrapper for \ref lwmem_calloc_ex function. @@ -153,7 +154,7 @@ lwmem_region_t regions[] = { * \return Pointer to allocated memory on success, `NULL` otherwise * \note This function is thread safe when \ref LWMEM_CFG_OS is enabled */ -#define lwmem_calloc(nitems, size) lwmem_calloc_ex(NULL, NULL, (nitems), (size)) +#define lwmem_calloc(nitems, size) lwmem_calloc_ex(NULL, NULL, (nitems), (size)) /** * \note This is a wrapper for \ref lwmem_realloc_ex function. @@ -164,7 +165,7 @@ lwmem_region_t regions[] = { * \return Pointer to allocated memory on success, `NULL` otherwise * \note This function is thread safe when \ref LWMEM_CFG_OS is enabled */ -#define lwmem_realloc(ptr, size) lwmem_realloc_ex(NULL, NULL, (ptr), (size)) +#define lwmem_realloc(ptr, size) lwmem_realloc_ex(NULL, NULL, (ptr), (size)) /** * \note This is a wrapper for \ref lwmem_realloc_s_ex function. @@ -176,7 +177,7 @@ lwmem_region_t regions[] = { * \return `1` if successfully reallocated, `0` otherwise * \note This function is thread safe when \ref LWMEM_CFG_OS is enabled */ -#define lwmem_realloc_s(ptrptr, size) lwmem_realloc_s_ex(NULL, NULL, (ptrptr), (size)) +#define lwmem_realloc_s(ptrptr, size) lwmem_realloc_s_ex(NULL, NULL, (ptrptr), (size)) /** * \note This is a wrapper for \ref lwmem_free_ex function. @@ -184,7 +185,7 @@ lwmem_region_t regions[] = { * \param[in] ptr: Memory to free. `NULL` pointer is valid input * \note This function is thread safe when \ref LWMEM_CFG_OS is enabled */ -#define lwmem_free(ptr) lwmem_free_ex(NULL, (ptr)) +#define lwmem_free(ptr) lwmem_free_ex(NULL, (ptr)) /** * \note This is a wrapper for \ref lwmem_free_s_ex function. @@ -193,7 +194,7 @@ lwmem_region_t regions[] = { * When set to non `NULL`, pointer is freed and set to `NULL` * \note This function is thread safe when \ref LWMEM_CFG_OS is enabled */ -#define lwmem_free_s(ptrptr) lwmem_free_s_ex(NULL, (ptrptr)) +#define lwmem_free_s(ptrptr) lwmem_free_s_ex(NULL, (ptrptr)) /** * \note This is a wrapper for \ref lwmem_get_size_ex function. @@ -201,21 +202,21 @@ lwmem_region_t regions[] = { * \param[in] ptr: Pointer to allocated memory * \return Block size for user in units of bytes */ -#define lwmem_get_size(ptr) lwmem_get_size_ex(NULL, (ptr)) +#define lwmem_get_size(ptr) lwmem_get_size_ex(NULL, (ptr)) /** * \note This is a wrapper for \ref lwmem_get_stats_ex function. * It operates in default LwMEM instance * \param[in] ptr: Pointer to lwmem_stats_t to store result */ -#define lwmem_get_stats(stats) lwmem_get_stats_ex(NULL, (stats)) +#define lwmem_get_stats(stats) lwmem_get_stats_ex(NULL, (stats)) #if defined(LWMEM_DEV) && !__DOXYGEN__ unsigned char lwmem_debug_create_regions(lwmem_region_t** regs_out, size_t count, size_t size); -void lwmem_debug_save_state(void); -void lwmem_debug_restore_to_saved(void); +void lwmem_debug_save_state(void); +void lwmem_debug_restore_to_saved(void); -void lwmem_debug_print(unsigned char print_alloc, unsigned char print_free); +void lwmem_debug_print(unsigned char print_alloc, unsigned char print_free); #endif /* defined(LWMEM_DEV) && !__DOXYGEN__ */ /** diff --git a/lwmem/src/include/lwmem/lwmem.hpp b/lwmem/src/include/lwmem/lwmem.hpp index 3ec2f2b..eaea617 100644 --- a/lwmem/src/include/lwmem/lwmem.hpp +++ b/lwmem/src/include/lwmem/lwmem.hpp @@ -43,7 +43,6 @@ * \{ */ - namespace Lwmem { /** @@ -62,15 +61,12 @@ void* ptr = mngr.malloc(...); mngr.free(ptr); \endcode */ -template +template class LwmemLight { -public: + public: LwmemLight() { /* Simple region descriptor with one region */ - const lwmem_region_t regions[] = { - {m_reg_data, sizeof(m_reg_data)}, - {NULL, 0} - }; + const lwmem_region_t regions[] = {{m_reg_data, sizeof(m_reg_data)}, {NULL, 0}}; lwmem_assignmem_ex(&m_lw, regions); } @@ -84,7 +80,7 @@ class LwmemLight { malloc(size_t size) { return lwmem_malloc_ex(&m_lw, nullptr, size); } - + /** * \brief Allocate block of memory with selected size and cleaned to all zeros * \param[in] nitems: Number of items to allocate @@ -119,7 +115,7 @@ class LwmemLight { lwmem_free_ex(&m_lw, ptr); } -private: + private: /* Delete unused constructors */ LwmemLight(const LwmemLight& other) = delete; /* Delete copy assignment operators */ @@ -130,7 +126,7 @@ class LwmemLight { uint8_t m_reg_data[LEN]; }; -}; +}; // namespace Lwmem /** * \} diff --git a/lwmem/src/include/lwmem/lwmem_opt.h b/lwmem/src/include/lwmem/lwmem_opt.h index ae7864b..4df0402 100644 --- a/lwmem/src/include/lwmem/lwmem_opt.h +++ b/lwmem/src/include/lwmem/lwmem_opt.h @@ -58,7 +58,7 @@ extern "C" { * \note When `LWMEM_CFG_OS` is enabled, user must implement functions in \ref LWMEM_SYS group. */ #ifndef LWMEM_CFG_OS -#define LWMEM_CFG_OS 0 +#define LWMEM_CFG_OS 0 #endif /** @@ -69,7 +69,7 @@ extern "C" { * definition before you define handle type */ #ifndef LWMEM_CFG_OS_MUTEX_HANDLE -#define LWMEM_CFG_OS_MUTEX_HANDLE void * +#define LWMEM_CFG_OS_MUTEX_HANDLE void* #endif /** @@ -82,7 +82,7 @@ extern "C" { * Usually alignment of `4` bytes fits to all processors. */ #ifndef LWMEM_CFG_ALIGN_NUM -#define LWMEM_CFG_ALIGN_NUM ((size_t)4) +#define LWMEM_CFG_ALIGN_NUM ((size_t)4) #endif /** @@ -92,7 +92,7 @@ extern "C" { * It is disabled by default since it has performance penalties. */ #ifndef LWMEM_CFG_CLEAN_MEMORY -#define LWMEM_CFG_CLEAN_MEMORY 0 +#define LWMEM_CFG_CLEAN_MEMORY 0 #endif /** @@ -100,7 +100,7 @@ extern "C" { * */ #ifndef LWMEM_CFG_ENABLE_STATS -#define LWMEM_CFG_ENABLE_STATS 0 +#define LWMEM_CFG_ENABLE_STATS 0 #endif /** diff --git a/lwmem/src/include/system/lwmem_sys.h b/lwmem/src/include/system/lwmem_sys.h index d07b662..0a84e3d 100644 --- a/lwmem/src/include/system/lwmem_sys.h +++ b/lwmem/src/include/system/lwmem_sys.h @@ -34,8 +34,8 @@ #ifndef LWMEM_HDR_SYS_H #define LWMEM_HDR_SYS_H -#include #include +#include #include "lwmem/lwmem.h" #ifdef __cplusplus @@ -55,28 +55,28 @@ extern "C" { * \param[out] m: Output variable to save mutex handle * \return `1` on success, `0` otherwise */ -uint8_t lwmem_sys_mutex_create(LWMEM_CFG_OS_MUTEX_HANDLE* m); +uint8_t lwmem_sys_mutex_create(LWMEM_CFG_OS_MUTEX_HANDLE* m); /** * \brief Check if mutex handle is valid * \param[in] m: Mutex handle to check if valid * \return `1` on success, `0` otherwise */ -uint8_t lwmem_sys_mutex_isvalid(LWMEM_CFG_OS_MUTEX_HANDLE* m); +uint8_t lwmem_sys_mutex_isvalid(LWMEM_CFG_OS_MUTEX_HANDLE* m); /** * \brief Wait for a mutex until ready (unlimited time) * \param[in] m: Mutex handle to wait for * \return `1` on success, `0` otherwise */ -uint8_t lwmem_sys_mutex_wait(LWMEM_CFG_OS_MUTEX_HANDLE* m); +uint8_t lwmem_sys_mutex_wait(LWMEM_CFG_OS_MUTEX_HANDLE* m); /** * \brief Release already locked mutex * \param[in] m: Mutex handle to release * \return `1` on success, `0` otherwise */ -uint8_t lwmem_sys_mutex_release(LWMEM_CFG_OS_MUTEX_HANDLE* m); +uint8_t lwmem_sys_mutex_release(LWMEM_CFG_OS_MUTEX_HANDLE* m); /** * \} diff --git a/lwmem/src/lwmem/lwmem.c b/lwmem/src/lwmem/lwmem.c index 728c777..69420dc 100644 --- a/lwmem/src/lwmem/lwmem.c +++ b/lwmem/src/lwmem/lwmem.c @@ -31,22 +31,22 @@ * Author: Tilen MAJERLE * Version: v2.0.0 */ +#include "lwmem/lwmem.h" #include #include -#include "lwmem/lwmem.h" #if LWMEM_CFG_OS #include "system/lwmem_sys.h" #endif /* LWMEM_CFG_OS */ -#define LWMEM_MEMSET memset -#define LWMEM_MEMCPY memcpy -#define LWMEM_MEMMOVE memmove +#define LWMEM_MEMSET memset +#define LWMEM_MEMCPY memcpy +#define LWMEM_MEMMOVE memmove /** * \brief Transform alignment number (power of `2`) to bits */ -#define LWMEM_ALIGN_BITS ((size_t)(((size_t)LWMEM_CFG_ALIGN_NUM) - 1)) +#define LWMEM_ALIGN_BITS ((size_t)(((size_t)LWMEM_CFG_ALIGN_NUM) - 1)) /** * \brief Aligns input value to next alignment bits @@ -63,65 +63,74 @@ * - Input: `7`; Output: `8` * - Input: `8`; Output: `8` */ -#define LWMEM_ALIGN(x) (((x) + (LWMEM_ALIGN_BITS)) & ~(LWMEM_ALIGN_BITS)) +#define LWMEM_ALIGN(x) (((x) + (LWMEM_ALIGN_BITS)) & ~(LWMEM_ALIGN_BITS)) /** * \brief Size of metadata header for block information */ -#define LWMEM_BLOCK_META_SIZE LWMEM_ALIGN(sizeof(lwmem_block_t)) +#define LWMEM_BLOCK_META_SIZE LWMEM_ALIGN(sizeof(lwmem_block_t)) /** * \brief Cast input pointer to byte * \param[in] p: Input pointer to cast to byte pointer */ -#define LWMEM_TO_BYTE_PTR(p) ((uint8_t *)(p)) +#define LWMEM_TO_BYTE_PTR(p) ((uint8_t*)(p)) /** * \brief Bit indicating memory block is allocated */ -#define LWMEM_ALLOC_BIT ((size_t)((size_t)1 << (sizeof(size_t) * CHAR_BIT - 1))) +#define LWMEM_ALLOC_BIT ((size_t)((size_t)1 << (sizeof(size_t) * CHAR_BIT - 1))) /** * \brief Mark written in `next` field when block is allocated */ -#define LWMEM_BLOCK_ALLOC_MARK (0xDEADBEEF) +#define LWMEM_BLOCK_ALLOC_MARK (0xDEADBEEF) /** * \brief Set block as allocated * \param[in] block: Block to set as allocated */ -#define LWMEM_BLOCK_SET_ALLOC(block) do { if ((block) != NULL) { (block)->size |= LWMEM_ALLOC_BIT; (block)->next = (void *)(LWMEM_TO_BYTE_PTR(0) + LWMEM_BLOCK_ALLOC_MARK); }} while (0) +#define LWMEM_BLOCK_SET_ALLOC(block) \ + do { \ + if ((block) != NULL) { \ + (block)->size |= LWMEM_ALLOC_BIT; \ + (block)->next = (void*)(LWMEM_TO_BYTE_PTR(0) + LWMEM_BLOCK_ALLOC_MARK); \ + } \ + } while (0) /** * \brief Check if input block is properly allocated and valid * \param[in] block: Block to check if properly set as allocated */ -#define LWMEM_BLOCK_IS_ALLOC(block) ((block) != NULL && ((block)->size & LWMEM_ALLOC_BIT) && (block)->next == (void *)(LWMEM_TO_BYTE_PTR(0) + LWMEM_BLOCK_ALLOC_MARK)) +#define LWMEM_BLOCK_IS_ALLOC(block) \ + ((block) != NULL && ((block)->size & LWMEM_ALLOC_BIT) \ + && (block)->next == (void*)(LWMEM_TO_BYTE_PTR(0) + LWMEM_BLOCK_ALLOC_MARK)) /** * \brief Get block handle from application pointer * \param[in] ptr: Input pointer to get block from */ -#define LWMEM_GET_BLOCK_FROM_PTR(ptr) (void *)((ptr) != NULL ? ((LWMEM_TO_BYTE_PTR(ptr)) - LWMEM_BLOCK_META_SIZE) : NULL) +#define LWMEM_GET_BLOCK_FROM_PTR(ptr) (void*)((ptr) != NULL ? ((LWMEM_TO_BYTE_PTR(ptr)) - LWMEM_BLOCK_META_SIZE) : NULL) /** * \brief Get block handle from application pointer * \param[in] block: Input pointer to get block from */ -#define LWMEM_GET_PTR_FROM_BLOCK(block) (void *)((block) != NULL ? ((LWMEM_TO_BYTE_PTR(block)) + LWMEM_BLOCK_META_SIZE) : NULL) +#define LWMEM_GET_PTR_FROM_BLOCK(block) \ + (void*)((block) != NULL ? ((LWMEM_TO_BYTE_PTR(block)) + LWMEM_BLOCK_META_SIZE) : NULL) /** * \brief Minimum amount of memory required to make new empty block * * Default size is size of meta block */ -#define LWMEM_BLOCK_MIN_SIZE (LWMEM_BLOCK_META_SIZE) +#define LWMEM_BLOCK_MIN_SIZE (LWMEM_BLOCK_META_SIZE) /** * \brief Get LwMEM instance based on user input * \param[in] in_lw: LwMEM instance. Set to `NULL` for default instance */ -#define LWMEM_GET_LW(in_lw) ((in_lw) != NULL ? (in_lw) : (&lwmem_default)) +#define LWMEM_GET_LW(in_lw) ((in_lw) != NULL ? (in_lw) : (&lwmem_default)) /** * \brief Gets block before input block (marked as prev) and its previous free block @@ -130,16 +139,15 @@ * \param[in] in_pp: Previous previous of input block * \param[in] in_p: Previous of input block */ -#define LWMEM_GET_PREV_CURR_OF_BLOCK(in_lw, in_b, in_pp, in_p) do { \ - for ((in_pp) = NULL, (in_p) = &((in_lw)->start_block); \ - (in_p) != NULL && (in_p)->next < (in_b); \ - (in_pp) = (in_p), (in_p) = (in_p)->next \ - ) {} \ +#define LWMEM_GET_PREV_CURR_OF_BLOCK(in_lw, in_b, in_pp, in_p) \ + do { \ + for ((in_pp) = NULL, (in_p) = &((in_lw)->start_block); (in_p) != NULL && (in_p)->next < (in_b); \ + (in_pp) = (in_p), (in_p) = (in_p)->next) {} \ } while (0) #if LWMEM_CFG_OS -#define LWMEM_PROTECT(lw) lwmem_sys_mutex_wait(&((lw)->mutex)) -#define LWMEM_UNPROTECT(lw) lwmem_sys_mutex_release(&((lw)->mutex)) +#define LWMEM_PROTECT(lw) lwmem_sys_mutex_wait(&((lw)->mutex)) +#define LWMEM_UNPROTECT(lw) lwmem_sys_mutex_release(&((lw)->mutex)) #else /* LWMEM_CFG_OS */ #define LWMEM_PROTECT(lw) #define LWMEM_UNPROTECT(lw) @@ -147,11 +155,12 @@ /* Statistics part */ #if LWMEM_CFG_ENABLE_STATS -#define LWMEM_INC_STATS(field) (++(field)) -#define LWMEM_UPDATE_MIN_FREE(lw) do { \ - if ((lw)->mem_available_bytes < (lw)->stats.minimum_ever_mem_available_bytes) { \ - (lw)->stats.minimum_ever_mem_available_bytes = (lw)->mem_available_bytes; \ - } \ +#define LWMEM_INC_STATS(field) (++(field)) +#define LWMEM_UPDATE_MIN_FREE(lw) \ + do { \ + if ((lw)->mem_available_bytes < (lw)->stats.minimum_ever_mem_available_bytes) { \ + (lw)->stats.minimum_ever_mem_available_bytes = (lw)->mem_available_bytes; \ + } \ } while (0) #else #define LWMEM_INC_STATS(field) @@ -171,7 +180,7 @@ static lwmem_t lwmem_default; * \return `1` if region valid, `0` otherwise */ static uint8_t -prv_get_region_addr_size(const lwmem_region_t* region, uint8_t** msa, size_t* ms) { +prv_get_region_addr_size(const lwmem_region_t* region, uint8_t** msa, size_t* ms) { size_t mem_size; uint8_t* mem_start_addr; @@ -182,7 +191,7 @@ prv_get_region_addr_size(const lwmem_region_t* region, uint8_t** msa, size_t* m *ms = 0; /* Check region size and align it to config bits */ - mem_size = region->size & ~LWMEM_ALIGN_BITS;/* Size does not include lower bits */ + mem_size = region->size & ~LWMEM_ALIGN_BITS; /* Size does not include lower bits */ if (mem_size < (2 * LWMEM_BLOCK_MIN_SIZE)) { return 0; } @@ -192,7 +201,7 @@ prv_get_region_addr_size(const lwmem_region_t* region, uint8_t** msa, size_t* m * Increase start address and decrease effective region size */ mem_start_addr = region->start_addr; - if (((size_t)mem_start_addr) & LWMEM_ALIGN_BITS) { /* Check alignment boundary */ + if (((size_t)mem_start_addr) & LWMEM_ALIGN_BITS) { /* Check alignment boundary */ mem_start_addr += ((size_t)LWMEM_CFG_ALIGN_NUM) - ((size_t)mem_start_addr & LWMEM_ALIGN_BITS); mem_size -= (size_t)(mem_start_addr - LWMEM_TO_BYTE_PTR(region->start_addr)); } @@ -258,9 +267,9 @@ prv_insert_free_block(lwmem_t* const lw, lwmem_block_t* nb) { * If this is the case, merge blocks together and increase previous block by input block size */ if ((LWMEM_TO_BYTE_PTR(prev) + prev->size) == LWMEM_TO_BYTE_PTR(nb)) { - prev->size += nb->size; /* Increase current block by size of new block */ - nb = prev; /* New block and current are now the same thing */ - /* + prev->size += nb->size; /* Increase current block by size of new block */ + nb = prev; /* New block and current are now the same thing */ + /* * It is important to set new block as current one * as this allows merging previous and next blocks together with new block * at the same time; follow next steps @@ -271,16 +280,18 @@ prv_insert_free_block(lwmem_t* const lw, lwmem_block_t* nb) { * Check if new block and next of previous create big contiguous block * Do not merge with "end of region" indication (commented part of if statement) */ - if (prev->next != NULL && prev->next->size > 0 /* Do not remove "end of region" indicator in each region */ + if (prev->next != NULL && prev->next->size > 0 /* Do not remove "end of region" indicator in each region */ && (LWMEM_TO_BYTE_PTR(nb) + nb->size) == LWMEM_TO_BYTE_PTR(prev->next)) { - if (prev->next == lw->end_block) {/* Does it points to the end? */ - nb->next = lw->end_block; /* Set end block pointer */ + if (prev->next == lw->end_block) { /* Does it points to the end? */ + nb->next = lw->end_block; /* Set end block pointer */ } else { - nb->size += prev->next->size; /* Expand of current block for size of next free block which is right behind new block */ - nb->next = prev->next->next; /* Next free is pointed to the next one of previous next */ + nb->size += + prev->next + ->size; /* Expand of current block for size of next free block which is right behind new block */ + nb->next = prev->next->next; /* Next free is pointed to the next one of previous next */ } } else { - nb->next = prev->next; /* Set next of input block as next of current one */ + nb->next = prev->next; /* Set next of input block as next of current one */ } /* @@ -305,8 +316,8 @@ prv_split_too_big_block(lwmem_t* const lw, lwmem_block_t* block, size_t new_bloc size_t block_size, is_alloc_bit; uint8_t success = 0; - is_alloc_bit = block->size & LWMEM_ALLOC_BIT; /* Check if allocation bit is set */ - block_size = block->size & ~LWMEM_ALLOC_BIT;/* Use size without allocated bit */ + is_alloc_bit = block->size & LWMEM_ALLOC_BIT; /* Check if allocation bit is set */ + block_size = block->size & ~LWMEM_ALLOC_BIT; /* Use size without allocated bit */ /* * If current block size is greater than requested size, @@ -314,12 +325,12 @@ prv_split_too_big_block(lwmem_t* const lw, lwmem_block_t* block, size_t new_bloc * and add it back to list of empty blocks */ if ((block_size - new_block_size) >= LWMEM_BLOCK_MIN_SIZE) { - next = (void*)(LWMEM_TO_BYTE_PTR(block) + new_block_size); /* Put next block after size of current allocation */ - next->size = block_size - new_block_size; /* Modify block data */ - block->size = new_block_size; /* Current size is now smaller */ + next = (void*)(LWMEM_TO_BYTE_PTR(block) + new_block_size); /* Put next block after size of current allocation */ + next->size = block_size - new_block_size; /* Modify block data */ + block->size = new_block_size; /* Current size is now smaller */ - lw->mem_available_bytes += next->size;/* Increase available bytes by new block size */ - prv_insert_free_block(lw, next); /* Add new block to the free list */ + lw->mem_available_bytes += next->size; /* Increase available bytes by new block size */ + prv_insert_free_block(lw, next); /* Add new block to the free list */ success = 1; } else { @@ -345,7 +356,7 @@ prv_split_too_big_block(lwmem_t* const lw, lwmem_block_t* block, size_t new_bloc */ static void* prv_alloc(lwmem_t* const lw, const lwmem_region_t* region, const size_t size) { - lwmem_block_t* prev, *curr; + lwmem_block_t *prev, *curr; void* retval = NULL; /* Calculate final size including meta data size */ @@ -357,8 +368,8 @@ prv_alloc(lwmem_t* const lw, const lwmem_region_t* region, const size_t size) { } /* Set default values */ - prev = &(lw->start_block); /* Use pointer from custom lwmem block */ - curr = prev->next; /* Curr represents first actual free block */ + prev = &(lw->start_block); /* Use pointer from custom lwmem block */ + curr = prev->next; /* Curr represents first actual free block */ /* * If region is not set to NULL, @@ -388,11 +399,11 @@ prv_alloc(lwmem_t* const lw, const lwmem_region_t* region, const size_t size) { if ((uint8_t*)curr < (uint8_t*)region_start_addr) { /* Check if we reached region */ continue; } - if ((uint8_t*)curr >= (uint8_t*)(region_start_addr + region_size)) {/* Check if we are out already */ + if ((uint8_t*)curr >= (uint8_t*)(region_start_addr + region_size)) { /* Check if we are out already */ return NULL; } if (curr->size >= final_size) { - break; /* Free block identified */ + break; /* Free block identified */ } } } else { @@ -401,8 +412,8 @@ prv_alloc(lwmem_t* const lw, const lwmem_region_t* region, const size_t size) { * Loop until size of current block is smaller than requested final size */ for (; curr != NULL && curr->size < final_size; prev = curr, curr = curr->next) { - if (curr->next == NULL || curr == lw->end_block) {/* If no more blocks available */ - return NULL; /* No sufficient memory available to allocate block of memory */ + if (curr->next == NULL || curr == lw->end_block) { /* If no more blocks available */ + return NULL; /* No sufficient memory available to allocate block of memory */ } } } @@ -413,14 +424,14 @@ prv_alloc(lwmem_t* const lw, const lwmem_region_t* region, const size_t size) { } /* There is a valid block available */ - retval = LWMEM_GET_PTR_FROM_BLOCK(curr); /* Return pointer does not include meta part */ - prev->next = curr->next; /* Remove this block from linked list by setting next of previous to next of current */ + retval = LWMEM_GET_PTR_FROM_BLOCK(curr); /* Return pointer does not include meta part */ + prev->next = curr->next; /* Remove this block from linked list by setting next of previous to next of current */ /* curr block is now removed from linked list */ - lw->mem_available_bytes -= curr->size;/* Decrease available bytes by allocated block size */ - prv_split_too_big_block(lw, curr, final_size); /* Split block if it is too big */ - LWMEM_BLOCK_SET_ALLOC(curr); /* Set block as allocated */ + lw->mem_available_bytes -= curr->size; /* Decrease available bytes by allocated block size */ + prv_split_too_big_block(lw, curr, final_size); /* Split block if it is too big */ + LWMEM_BLOCK_SET_ALLOC(curr); /* Set block as allocated */ LWMEM_UPDATE_MIN_FREE(lw); LWMEM_INC_STATS(lw->stats.nr_alloc); @@ -436,10 +447,10 @@ prv_alloc(lwmem_t* const lw, const lwmem_region_t* region, const size_t size) { static void prv_free(lwmem_t* const lw, void* const ptr) { lwmem_block_t* const block = LWMEM_GET_BLOCK_FROM_PTR(ptr); - if (LWMEM_BLOCK_IS_ALLOC(block)) { /* Check if block is valid */ - block->size &= ~LWMEM_ALLOC_BIT; /* Clear allocated bit indication */ + if (LWMEM_BLOCK_IS_ALLOC(block)) { /* Check if block is valid */ + block->size &= ~LWMEM_ALLOC_BIT; /* Clear allocated bit indication */ - lw->mem_available_bytes += block->size; /* Increase available bytes */ + lw->mem_available_bytes += block->size; /* Increase available bytes */ prv_insert_free_block(lw, block); /* Put block back to list of free block */ LWMEM_INC_STATS(lw->stats.nr_free); @@ -466,10 +477,11 @@ prv_free(lwmem_t* const lw, void* const ptr) { */ static void* prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, const size_t size) { - lwmem_block_t* block, *prevprev, *prev; - size_t block_size; /* Holds size of input block (ptr), including metadata size */ - const size_t final_size = LWMEM_ALIGN(size) + LWMEM_BLOCK_META_SIZE;/* Holds size of new requested block size, including metadata size */ - void* retval; /* Return pointer, used with LWMEM_RETURN macro */ + lwmem_block_t *block, *prevprev, *prev; + size_t block_size; /* Holds size of input block (ptr), including metadata size */ + const size_t final_size = + LWMEM_ALIGN(size) + LWMEM_BLOCK_META_SIZE; /* Holds size of new requested block size, including metadata size */ + void* retval; /* Return pointer, used with LWMEM_RETURN macro */ /* Check optional input parameters */ if (size == 0) { @@ -490,11 +502,11 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co /* Process existing block */ block = LWMEM_GET_BLOCK_FROM_PTR(ptr); if (LWMEM_BLOCK_IS_ALLOC(block)) { - block_size = block->size & ~LWMEM_ALLOC_BIT;/* Get actual block size, without memory allocation bit */ + block_size = block->size & ~LWMEM_ALLOC_BIT; /* Get actual block size, without memory allocation bit */ /* Check current block size is the same as new requested size */ if (block_size == final_size) { - return ptr; /* Just return pointer, nothing to do */ + return ptr; /* Just return pointer, nothing to do */ } /* @@ -531,7 +543,7 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co /* Check if current block and next free are connected */ if ((LWMEM_TO_BYTE_PTR(block) + block_size) == LWMEM_TO_BYTE_PTR(prev->next) - && prev->next->size > 0) { /* Must not be end of region indicator */ + && prev->next->size > 0) { /* Must not be end of region indicator */ /* Make temporary variables as prev->next will point to different location */ const size_t tmp_size = prev->next->size; void* const tmp_next = prev->next->next; @@ -540,13 +552,14 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co prev->next = (void*)(LWMEM_TO_BYTE_PTR(prev->next) - (block_size - final_size)); prev->next->size = tmp_size + (block_size - final_size); prev->next->next = tmp_next; - lw->mem_available_bytes += block_size - final_size; /* Increase available bytes by increase of free block */ + lw->mem_available_bytes += + block_size - final_size; /* Increase available bytes by increase of free block */ - block->size = final_size; /* Block size is requested size */ + block->size = final_size; /* Block size is requested size */ } } - LWMEM_BLOCK_SET_ALLOC(block); /* Set block as allocated */ - return ptr; /* Return existing pointer */ + LWMEM_BLOCK_SET_ALLOC(block); /* Set block as allocated */ + return ptr; /* Return existing pointer */ } /* New requested size is bigger than current block size is */ @@ -564,21 +577,23 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co /* Input block points to address somewhere between "prev" and "prev->next" pointers */ /* Check if "block" and next free "prev->next" create contiguous memory with size of at least new requested size */ - if ((LWMEM_TO_BYTE_PTR(block) + block_size) == LWMEM_TO_BYTE_PTR(prev->next)/* Blocks create contiguous block */ + if ((LWMEM_TO_BYTE_PTR(block) + block_size) + == LWMEM_TO_BYTE_PTR(prev->next) /* Blocks create contiguous block */ && (block_size + prev->next->size) >= final_size) { /* Size is greater or equal to requested */ /* * Merge blocks together by increasing current block with size of next free one * and remove next free from list of free blocks */ - lw->mem_available_bytes -= prev->next->size; /* For now decrease effective available bytes */ + lw->mem_available_bytes -= prev->next->size; /* For now decrease effective available bytes */ LWMEM_UPDATE_MIN_FREE(lw); - block->size = block_size + prev->next->size;/* Increase effective size of new block */ - prev->next = prev->next->next; /* Set next to next's next, effectively remove expanded block from free list */ + block->size = block_size + prev->next->size; /* Increase effective size of new block */ + prev->next = + prev->next->next; /* Set next to next's next, effectively remove expanded block from free list */ prv_split_too_big_block(lw, block, final_size); /* Split block if it is too big */ - LWMEM_BLOCK_SET_ALLOC(block); /* Set block as allocated */ - return ptr; /* Return existing pointer */ + LWMEM_BLOCK_SET_ALLOC(block); /* Set block as allocated */ + return ptr; /* Return existing pointer */ } /* @@ -586,8 +601,8 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co * * It is necessary to make a memory move and shift content up as new return pointer is now upper on address space */ - if ((LWMEM_TO_BYTE_PTR(prev) + prev->size) == LWMEM_TO_BYTE_PTR(block) /* Blocks create contiguous block */ - && (prev->size + block_size) >= final_size) { /* Size is greater or equal to requested */ + if ((LWMEM_TO_BYTE_PTR(prev) + prev->size) == LWMEM_TO_BYTE_PTR(block) /* Blocks create contiguous block */ + && (prev->size + block_size) >= final_size) { /* Size is greater or equal to requested */ /* Move memory from block to block previous to current */ void* const old_data_ptr = LWMEM_GET_PTR_FROM_BLOCK(block); void* const new_data_ptr = LWMEM_GET_PTR_FROM_BLOCK(prev); @@ -602,15 +617,16 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co */ LWMEM_MEMMOVE(new_data_ptr, old_data_ptr, block_size); - lw->mem_available_bytes -= prev->size;/* For now decrease effective available bytes */ + lw->mem_available_bytes -= prev->size; /* For now decrease effective available bytes */ LWMEM_UPDATE_MIN_FREE(lw); - prev->size += block_size; /* Increase size of input block size */ - prevprev->next = prev->next; /* Remove prev from free list as it is now being used for allocation together with existing block */ - block = prev; /* Move block pointer to previous one */ + prev->size += block_size; /* Increase size of input block size */ + prevprev->next = + prev->next; /* Remove prev from free list as it is now being used for allocation together with existing block */ + block = prev; /* Move block pointer to previous one */ prv_split_too_big_block(lw, block, final_size); /* Split block if it is too big */ - LWMEM_BLOCK_SET_ALLOC(block); /* Set block as allocated */ - return new_data_ptr; /* Return new data ptr */ + LWMEM_BLOCK_SET_ALLOC(block); /* Set block as allocated */ + return new_data_ptr; /* Return new data ptr */ } /* @@ -621,9 +637,11 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co * Last option is to check if previous free block "prev", input block "block" and next free block "prev->next" create contiguous block * and size of new block (from 3 contiguous blocks) together is big enough */ - if ((LWMEM_TO_BYTE_PTR(prev) + prev->size) == LWMEM_TO_BYTE_PTR(block) /* Input block and free block before create contiguous block */ - && (LWMEM_TO_BYTE_PTR(block) + block_size) == LWMEM_TO_BYTE_PTR(prev->next) /* Input block and free block after create contiguous block */ - && (prev->size + block_size + prev->next->size) >= final_size) {/* Size is greater or equal to requested */ + if ((LWMEM_TO_BYTE_PTR(prev) + prev->size) + == LWMEM_TO_BYTE_PTR(block) /* Input block and free block before create contiguous block */ + && (LWMEM_TO_BYTE_PTR(block) + block_size) + == LWMEM_TO_BYTE_PTR(prev->next) /* Input block and free block after create contiguous block */ + && (prev->size + block_size + prev->next->size) >= final_size) { /* Size is greater or equal to requested */ /* Move memory from block to block previous to current */ void* const old_data_ptr = LWMEM_GET_PTR_FROM_BLOCK(block); @@ -637,17 +655,22 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co * * Metadata of "prev" are not modified during memmove */ - LWMEM_MEMMOVE(new_data_ptr, old_data_ptr, block_size); /* Copy old buffer size to new location */ + LWMEM_MEMMOVE(new_data_ptr, old_data_ptr, block_size); /* Copy old buffer size to new location */ - lw->mem_available_bytes -= prev->size + prev->next->size; /* Decrease effective available bytes for free blocks before and after input block */ + lw->mem_available_bytes -= + prev->size + + prev->next + ->size; /* Decrease effective available bytes for free blocks before and after input block */ LWMEM_UPDATE_MIN_FREE(lw); - prev->size += block_size + prev->next->size;/* Increase size of new block by size of 2 free blocks */ - prevprev->next = prev->next->next; /* Remove free block before current one and block after current one from linked list (remove 2) */ - block = prev; /* Previous block is now current */ + prev->size += block_size + prev->next->size; /* Increase size of new block by size of 2 free blocks */ + prevprev->next = + prev->next + ->next; /* Remove free block before current one and block after current one from linked list (remove 2) */ + block = prev; /* Previous block is now current */ prv_split_too_big_block(lw, block, final_size); /* Split block if it is too big */ - LWMEM_BLOCK_SET_ALLOC(block); /* Set block as allocated */ - return new_data_ptr; /* Return new data ptr */ + LWMEM_BLOCK_SET_ALLOC(block); /* Set block as allocated */ + return new_data_ptr; /* Return new data ptr */ } } else { /* Hard error. Input pointer is not NULL and block is not considered allocated */ @@ -663,11 +686,12 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co * * Final solution is to find completely new empty block of sufficient size and copy content from old one to new one */ - retval = prv_alloc(lw, region, size); /* Try to allocate new block */ + retval = prv_alloc(lw, region, size); /* Try to allocate new block */ if (retval != NULL) { - block_size = (block->size & ~LWMEM_ALLOC_BIT) - LWMEM_BLOCK_META_SIZE; /* Get application size from input pointer */ - LWMEM_MEMCPY(retval, ptr, size > block_size ? block_size : size); /* Copy content to new allocated block */ - prv_free(lw, ptr); /* Free input pointer */ + block_size = + (block->size & ~LWMEM_ALLOC_BIT) - LWMEM_BLOCK_META_SIZE; /* Get application size from input pointer */ + LWMEM_MEMCPY(retval, ptr, size > block_size ? block_size : size); /* Copy content to new allocated block */ + prv_free(lw, ptr); /* Free input pointer */ } return retval; } @@ -695,12 +719,11 @@ size_t lwmem_assignmem_ex(lwmem_t* lw, const lwmem_region_t* regions) { uint8_t* mem_start_addr; size_t mem_size, len = 0; - lwmem_block_t* first_block, *prev_end_block; + lwmem_block_t *first_block, *prev_end_block; lw = LWMEM_GET_LW(lw); /* Check first things first */ - if (regions == NULL - || lw->end_block != NULL /* Init function may only be called once per lwmem instance */ + if (regions == NULL || lw->end_block != NULL /* Init function may only be called once per lwmem instance */ || (((size_t)LWMEM_CFG_ALIGN_NUM) & (((size_t)LWMEM_CFG_ALIGN_NUM) - 1)) > 0) { /* Must be power of 2 */ return 0; } @@ -735,10 +758,10 @@ lwmem_assignmem_ex(lwmem_t* lw, const lwmem_region_t* regions) { /* Process further checks of valid inputs */ if (regions == NULL || len == 0 #if LWMEM_CFG_OS - || lwmem_sys_mutex_isvalid(&(lw->mutex)) /* Check if mutex valid already = must not be */ - || !lwmem_sys_mutex_create(&(lw->mutex)) /* Final step = try to create mutex for new instance */ -#endif /* LWMEM_CFG_OS */ - ) { + || lwmem_sys_mutex_isvalid(&(lw->mutex)) /* Check if mutex valid already = must not be */ + || !lwmem_sys_mutex_create(&(lw->mutex)) /* Final step = try to create mutex for new instance */ +#endif /* LWMEM_CFG_OS */ + ) { return 0; } @@ -768,8 +791,8 @@ lwmem_assignmem_ex(lwmem_t* lw, const lwmem_region_t* regions) { /* Put end block to the end of the region with size = 0 */ lw->end_block = (void*)(mem_start_addr + mem_size - LWMEM_BLOCK_META_SIZE); - lw->end_block->next = NULL; /* End block in region does not have next entry */ - lw->end_block->size = 0; /* Size of end block is zero */ + lw->end_block->next = NULL; /* End block in region does not have next entry */ + lw->end_block->size = 0; /* Size of end block is zero */ /* * Create memory region first block. @@ -780,7 +803,7 @@ lwmem_assignmem_ex(lwmem_t* lw, const lwmem_region_t* regions) { * Actual maximal available size for application in the region is mem_size - 2 * MEM_BLOCK_META_SIZE */ first_block = (void*)mem_start_addr; - first_block->next = lw->end_block;/* Next block of first is last block */ + first_block->next = lw->end_block; /* Next block of first is last block */ first_block->size = mem_size - LWMEM_BLOCK_META_SIZE; /* Check if previous regions exist by checking previous end block state */ @@ -789,7 +812,7 @@ lwmem_assignmem_ex(lwmem_t* lw, const lwmem_region_t* regions) { } lw->mem_available_bytes += first_block->size; /* Increase number of available bytes */ - ++lw->mem_regions_count; /* Increase number of used regions */ + ++lw->mem_regions_count; /* Increase number of used regions */ } #if defined(LWMEM_DEV) @@ -929,7 +952,7 @@ lwmem_realloc_s_ex(lwmem_t* lw, const lwmem_region_t* region, void** const ptr, new_ptr = lwmem_realloc_ex(lw, region, *ptr, size); /* Try to reallocate existing pointer */ if (new_ptr != NULL) { *ptr = new_ptr; - } else if (size == 0) { /* size == 0 means free input memory */ + } else if (size == 0) { /* size == 0 means free input memory */ *ptr = NULL; return 1; } @@ -1082,11 +1105,7 @@ print_block(size_t i, lwmem_block_t* block) { is_free = (block->size & LWMEM_ALLOC_BIT) == 0 && block != &lwmem_default.start_block_first_use && block->size > 0; block_size = block->size & ~LWMEM_ALLOC_BIT; - printf("| %5d | %16p | %6d | %4d | %16d |", - (int)i, - (void*)block, - (int)is_free, - (int)block_size, + printf("| %5d | %16p | %6d | %4d | %16d |", (int)i, (void*)block, (int)is_free, (int)block_size, (int)(is_free ? (block_size - LWMEM_BLOCK_META_SIZE) : 0)); if (block == &lwmem_default.start_block_first_use) { printf(" Start block "); From 7c1b1104cfa1822ea60e8bb577cf3651e16ea79c Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Thu, 1 Sep 2022 23:08:51 +0200 Subject: [PATCH 66/73] Fix wrong clang formatting --- .clang-format | 84 +++++++++++++++++++++++------------------------ CMakePresets.json | 10 ++++++ 2 files changed, 52 insertions(+), 42 deletions(-) diff --git a/.clang-format b/.clang-format index 490ba55..1fad350 100644 --- a/.clang-format +++ b/.clang-format @@ -1,5 +1,5 @@ --- -Language: Cpp +Language: Cpp # BasedOnStyle: LLVM AccessModifierOffset: -2 AlignAfterOpenBracket: Align @@ -16,7 +16,8 @@ AlignConsecutiveBitFields: AlignConsecutiveDeclarations: None AlignEscapedNewlines: Right AlignOperands: Align -InsertBraces: true # Control statements must have curly brackets +SortIncludes: false +InsertBraces: true # Control statements must have curly brackets AlignTrailingComments: true AllowAllArgumentsOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true @@ -36,21 +37,21 @@ AttributeMacros: BinPackArguments: true BinPackParameters: true BraceWrapping: - AfterCaseLabel: false - AfterClass: false + AfterCaseLabel: false + AfterClass: false AfterControlStatement: Never - AfterEnum: false - AfterFunction: false - AfterNamespace: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false + AfterStruct: false + AfterUnion: false AfterExternBlock: false - BeforeCatch: false - BeforeElse: false + BeforeCatch: false + BeforeElse: false BeforeLambdaBody: false - BeforeWhile: false - IndentBraces: false + BeforeWhile: false + IndentBraces: false SplitEmptyFunction: true SplitEmptyRecord: true SplitEmptyNamespace: true @@ -64,8 +65,8 @@ BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: BeforeColon BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true -ColumnLimit: 120 -CommentPragmas: '^ IWYU pragma:' +ColumnLimit: 120 +CommentPragmas: "^ IWYU pragma:" QualifierAlignment: Leave CompactNamespaces: false ConstructorInitializerIndentWidth: 4 @@ -73,12 +74,12 @@ ContinuationIndentWidth: 4 Cpp11BracedListStyle: true DeriveLineEnding: true DerivePointerAlignment: false -DisableFormat: false +DisableFormat: false EmptyLineAfterAccessModifier: Never EmptyLineBeforeAccessModifier: LogicalBlock ExperimentalAutoDetectBinPacking: false PackConstructorInitializers: BinPack -BasedOnStyle: '' +BasedOnStyle: "" ConstructorInitializerAllOnOneLineOrOnePerLine: false AllowAllConstructorInitializersOnNextLine: true FixNamespaceComments: true @@ -88,32 +89,32 @@ ForEachMacros: - BOOST_FOREACH IfMacros: - KJ_IF_MAYBE -IncludeBlocks: Preserve +IncludeBlocks: Preserve IncludeCategories: - - Regex: '^<(.*)>' - Priority: 0 - - Regex: '^"(.*)"' - Priority: 1 - - Regex: '(.*)' - Priority: 2 -IncludeIsMainRegex: '(Test)?$' -IncludeIsMainSourceRegex: '' + - Regex: "^<(.*)>" + Priority: 0 + - Regex: '^"(.*)"' + Priority: 1 + - Regex: "(.*)" + Priority: 2 +IncludeIsMainRegex: "(Test)?$" +IncludeIsMainSourceRegex: "" IndentAccessModifiers: false IndentCaseLabels: true IndentCaseBlocks: false IndentGotoLabels: true IndentPPDirectives: None IndentExternBlock: AfterExternBlock -IndentRequires: true -IndentWidth: 4 +IndentRequires: true +IndentWidth: 4 IndentWrappedFunctionNames: false InsertTrailingCommas: None JavaScriptQuotes: Leave JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: true LambdaBodyIndentation: Signature -MacroBlockBegin: '' -MacroBlockEnd: '' +MacroBlockBegin: "" +MacroBlockEnd: "" MaxEmptyLinesToKeep: 1 NamespaceIndentation: None ObjCBinPackProtocolList: Auto @@ -132,13 +133,12 @@ PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 60 PenaltyIndentedWhitespace: 0 PointerAlignment: Left -PPIndentWidth: -1 +PPIndentWidth: -1 ReferenceAlignment: Pointer -ReflowComments: false +ReflowComments: false RemoveBracesLLVM: false SeparateDefinitionBlocks: Always ShortNamespaceLines: 1 -SortIncludes: CaseSensitive SortJavaStaticImport: Before SortUsingDeclarations: true SpaceAfterCStyleCast: false @@ -152,7 +152,7 @@ SpaceBeforeParensOptions: AfterForeachMacros: true AfterFunctionDefinitionName: false AfterFunctionDeclarationName: false - AfterIfMacros: true + AfterIfMacros: true AfterOverloadedOperator: false BeforeNonEmptyParentheses: false SpaceAroundPointerQualifiers: Default @@ -160,26 +160,26 @@ SpaceBeforeRangeBasedForLoopColon: true SpaceInEmptyBlock: false SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 1 -SpacesInAngles: Never +SpacesInAngles: Never SpacesInConditionalStatement: false SpacesInContainerLiterals: true SpacesInCStyleCastParentheses: false SpacesInLineCommentPrefix: - Minimum: 1 - Maximum: -1 + Minimum: 1 + Maximum: -1 SpacesInParentheses: false SpacesInSquareBrackets: false SpaceBeforeSquareBrackets: false BitFieldColonSpacing: Both -Standard: Latest +Standard: Latest StatementAttributeLikeMacros: - Q_EMIT StatementMacros: - Q_UNUSED - QT_REQUIRE_VERSION -TabWidth: 8 -UseCRLF: false -UseTab: Never +TabWidth: 8 +UseCRLF: false +UseTab: Never WhitespaceSensitiveMacros: - STRINGIZE - PP_STRINGIZE @@ -189,5 +189,5 @@ WhitespaceSensitiveMacros: SpaceBeforeCpp11BracedList: false SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true -... +--- diff --git a/CMakePresets.json b/CMakePresets.json index 7d277c4..f99154c 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -26,5 +26,15 @@ "CMAKE_BUILD_TYPE": "Debug" } } + ], + "buildPresets": [ + { + "name": "Win32-Debug", + "configurePreset": "Win32-Debug" + }, + { + "name": "Win64-Debug", + "configurePreset": "Win64-Debug" + } ] } \ No newline at end of file From dfa7b5773c8379dc6648b59b4606655589b47a1e Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 30 Sep 2022 08:13:14 +0200 Subject: [PATCH 67/73] Update CMakeLists.txt --- CMakeLists.txt | 86 +++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5effcf7..89ba41f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,50 +3,44 @@ cmake_minimum_required(VERSION 3.22) # Setup project project(LwLibPROJECT) -# ------------------------------------------------- -# This CMakeLists.txt is used only if it is a top-level file. -# Purpose of it is to be able to compile project in standalone way only -# -# When library sources are to be included in another project -# user shall use /lwmem/CMakeLists.txt instead -if (NOT PROJECT_IS_TOP_LEVEL) - message(FATAL_ERROR "This CMakeLists.txt can only be used as top-level. Use /lwmem/CMakeLists.txt for library include purpose") +if(NOT PROJECT_IS_TOP_LEVEL) + add_subdirectory(lwmem) +else() + # Set as executable + add_executable(${PROJECT_NAME}) + + # Add key executable block + target_sources(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/dev/main.cpp + ${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c + + # win32 port + ${CMAKE_CURRENT_LIST_DIR}/lwmem/src/system/lwmem_sys_win32.c + ) + + # Add key include paths + target_include_directories(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR} + ${CMAKE_CURRENT_LIST_DIR}/dev + ) + + # Compilation definition information + target_compile_definitions(${PROJECT_NAME} PUBLIC + WIN32 + _DEBUG + CONSOLE + LWMEM_DEV + ) + + # Compiler options + target_compile_options(${PROJECT_NAME} PRIVATE + -Wall + -Wextra + -Wpedantic + ) + + # Add subdir with lwmem and link to the project + add_subdirectory(lwmem) + target_link_libraries(${PROJECT_NAME} lwmem) + target_link_libraries(${PROJECT_NAME} lwmem_cpp) endif() - -# Set as executable -add_executable(${PROJECT_NAME}) - -# Add key executable block -target_sources(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/dev/main.cpp - ${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c - - # win32 port - ${CMAKE_CURRENT_LIST_DIR}/lwmem/src/system/lwmem_sys_win32.c -) - -# Add key include paths -target_include_directories(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR} - ${CMAKE_CURRENT_LIST_DIR}/dev -) - -# Compilation definition information -target_compile_definitions(${PROJECT_NAME} PUBLIC - WIN32 - _DEBUG - CONSOLE - LWMEM_DEV -) - -# Compiler options -target_compile_options(${PROJECT_NAME} PRIVATE - -Wall - -Wextra - -Wpedantic -) - -# Add subdir with lwmem and link to the project -add_subdirectory("lwmem") -target_link_libraries(${PROJECT_NAME} lwmem) -target_link_libraries(${PROJECT_NAME} lwmem_cpp) From 28a381e245212bbb7dd8bcbd6ed4536015213a5b Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sun, 30 Oct 2022 18:24:02 +0100 Subject: [PATCH 68/73] Update docs --- docs/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/index.rst b/docs/index.rst index 8129e18..3d67aae 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -73,6 +73,7 @@ Table of contents :caption: Other projects :hidden: + LwBTN - Button manager LwDTC - DateTimeCron LwESP - ESP-AT library LwEVT - Event manager From 42490d7cf9b664151fe2758d5da4d779912c80ae Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Mon, 31 Oct 2022 10:24:55 +0100 Subject: [PATCH 69/73] Update vscode --- .vscode/launch.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index a53089a..c76ad22 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,15 +1,12 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { + /* GDB must in be in the PATH environment */ "name": "(Windows) Launch", "type": "cppdbg", "request": "launch", "program": "${command:cmake.launchTargetPath}", - "miDebuggerPath": "c:\\msys64\\mingw64\\bin\\gdb.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", From de1cfde4fb89fa03467d079b9ef97e241f1dff0a Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sun, 18 Dec 2022 12:30:04 +0100 Subject: [PATCH 70/73] fix(hdr): Apply header guard syntax LWxxx_module_HDR_H --- lwmem/src/include/lwmem/lwmem_opt.h | 6 +++--- lwmem/src/include/lwmem/lwmem_opts_template.h | 6 +++--- lwmem/src/include/system/lwmem_sys.h | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lwmem/src/include/lwmem/lwmem_opt.h b/lwmem/src/include/lwmem/lwmem_opt.h index 4df0402..8e2bf4f 100644 --- a/lwmem/src/include/lwmem/lwmem_opt.h +++ b/lwmem/src/include/lwmem/lwmem_opt.h @@ -31,8 +31,8 @@ * Author: Tilen MAJERLE * Version: v2.0.0 */ -#ifndef LWMEM_HDR_OPT_H -#define LWMEM_HDR_OPT_H +#ifndef LWMEM_OPT_HDR_H +#define LWMEM_OPT_HDR_H /* Uncomment to ignore user options (or set macro in compiler flags) */ /* #define LWMEM_IGNORE_USER_OPTS */ @@ -111,4 +111,4 @@ extern "C" { } #endif /* __cplusplus */ -#endif /* LWMEM_HDR_OPT_H */ +#endif /* LWMEM_OPT_HDR_H */ diff --git a/lwmem/src/include/lwmem/lwmem_opts_template.h b/lwmem/src/include/lwmem/lwmem_opts_template.h index 1b54393..9036f0a 100644 --- a/lwmem/src/include/lwmem/lwmem_opts_template.h +++ b/lwmem/src/include/lwmem/lwmem_opts_template.h @@ -31,8 +31,8 @@ * Author: Tilen MAJERLE * Version: v2.0.0 */ -#ifndef LWMEM_HDR_OPTS_H -#define LWMEM_HDR_OPTS_H +#ifndef LWMEM_OPTS_HDR_H +#define LWMEM_OPTS_HDR_H /* Rename this file to "lwmem_opts.h" for your application */ @@ -41,4 +41,4 @@ * copy & replace here settings you want to change values */ -#endif /* LWMEM_HDR_OPTS_H */ +#endif /* LWMEM_OPTS_HDR_H */ diff --git a/lwmem/src/include/system/lwmem_sys.h b/lwmem/src/include/system/lwmem_sys.h index 0a84e3d..2e32fb4 100644 --- a/lwmem/src/include/system/lwmem_sys.h +++ b/lwmem/src/include/system/lwmem_sys.h @@ -31,8 +31,8 @@ * Author: Tilen MAJERLE * Version: v2.0.0 */ -#ifndef LWMEM_HDR_SYS_H -#define LWMEM_HDR_SYS_H +#ifndef LWMEM_SYS_HDR_H +#define LWMEM_SYS_HDR_H #include #include @@ -88,4 +88,4 @@ uint8_t lwmem_sys_mutex_release(LWMEM_CFG_OS_MUTEX_HANDLE* m); } #endif /* __cplusplus */ -#endif /* LWMEM_HDR_SYS_H */ +#endif /* LWMEM_SYS_HDR_H */ From e22c01f395f5b914a3e5e7fec0b382e9d28fee12 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Tue, 20 Dec 2022 17:45:17 +0100 Subject: [PATCH 71/73] Change lw to lwobj to better fit with clang-tidy --- lwmem/src/include/lwmem/lwmem.h | 18 +-- lwmem/src/lwmem/lwmem.c | 240 ++++++++++++++++---------------- 2 files changed, 129 insertions(+), 129 deletions(-) diff --git a/lwmem/src/include/lwmem/lwmem.h b/lwmem/src/include/lwmem/lwmem.h index fe996db..d878bf6 100644 --- a/lwmem/src/include/lwmem/lwmem.h +++ b/lwmem/src/include/lwmem/lwmem.h @@ -106,16 +106,16 @@ typedef struct { size_t size; /*!< Size of region in units of bytes */ } lwmem_region_t; -size_t lwmem_assignmem_ex(lwmem_t* lw, const lwmem_region_t* regions); -void* lwmem_malloc_ex(lwmem_t* lw, const lwmem_region_t* region, const size_t size); -void* lwmem_calloc_ex(lwmem_t* lw, const lwmem_region_t* region, const size_t nitems, const size_t size); -void* lwmem_realloc_ex(lwmem_t* lw, const lwmem_region_t* region, void* const ptr, const size_t size); -uint8_t lwmem_realloc_s_ex(lwmem_t* lw, const lwmem_region_t* region, void** const ptr, const size_t size); -void lwmem_free_ex(lwmem_t* lw, void* const ptr); -void lwmem_free_s_ex(lwmem_t* lw, void** const ptr); -size_t lwmem_get_size_ex(lwmem_t* lw, void* ptr); +size_t lwmem_assignmem_ex(lwmem_t* lwobj, const lwmem_region_t* regions); +void* lwmem_malloc_ex(lwmem_t* lwobj, const lwmem_region_t* region, const size_t size); +void* lwmem_calloc_ex(lwmem_t* lwobj, const lwmem_region_t* region, const size_t nitems, const size_t size); +void* lwmem_realloc_ex(lwmem_t* lwobj, const lwmem_region_t* region, void* const ptr, const size_t size); +uint8_t lwmem_realloc_s_ex(lwmem_t* lwobj, const lwmem_region_t* region, void** const ptr, const size_t size); +void lwmem_free_ex(lwmem_t* lwobj, void* const ptr); +void lwmem_free_s_ex(lwmem_t* lwobj, void** const ptr); +size_t lwmem_get_size_ex(lwmem_t* lwobj, void* ptr); #if LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ -void lwmem_get_stats_ex(lwmem_t* lw, lwmem_stats_t* stats); +void lwmem_get_stats_ex(lwmem_t* lwobj, lwmem_stats_t* stats); #endif /* LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ */ /** diff --git a/lwmem/src/lwmem/lwmem.c b/lwmem/src/lwmem/lwmem.c index 69420dc..6b27408 100644 --- a/lwmem/src/lwmem/lwmem.c +++ b/lwmem/src/lwmem/lwmem.c @@ -128,43 +128,43 @@ /** * \brief Get LwMEM instance based on user input - * \param[in] in_lw: LwMEM instance. Set to `NULL` for default instance + * \param[in] in_lwobj: LwMEM instance. Set to `NULL` for default instance */ -#define LWMEM_GET_LW(in_lw) ((in_lw) != NULL ? (in_lw) : (&lwmem_default)) +#define LWMEM_GET_LWOBJ(in_lwobj) ((in_lwobj) != NULL ? (in_lwobj) : (&lwmem_default)) /** * \brief Gets block before input block (marked as prev) and its previous free block - * \param[in] in_lw: LwMEM instance. Set to `NULL` to use default instance + * \param[in] in_lwobj: LwMEM instance. Set to `NULL` to use default instance * \param[in] in_b: Input block to find previous and its previous * \param[in] in_pp: Previous previous of input block * \param[in] in_p: Previous of input block */ -#define LWMEM_GET_PREV_CURR_OF_BLOCK(in_lw, in_b, in_pp, in_p) \ +#define LWMEM_GET_PREV_CURR_OF_BLOCK(in_lwobj, in_b, in_pp, in_p) \ do { \ - for ((in_pp) = NULL, (in_p) = &((in_lw)->start_block); (in_p) != NULL && (in_p)->next < (in_b); \ + for ((in_pp) = NULL, (in_p) = &((in_lwobj)->start_block); (in_p) != NULL && (in_p)->next < (in_b); \ (in_pp) = (in_p), (in_p) = (in_p)->next) {} \ } while (0) #if LWMEM_CFG_OS -#define LWMEM_PROTECT(lw) lwmem_sys_mutex_wait(&((lw)->mutex)) -#define LWMEM_UNPROTECT(lw) lwmem_sys_mutex_release(&((lw)->mutex)) +#define LWMEM_PROTECT(lwobj) lwmem_sys_mutex_wait(&((lwobj)->mutex)) +#define LWMEM_UNPROTECT(lwobj) lwmem_sys_mutex_release(&((lwobj)->mutex)) #else /* LWMEM_CFG_OS */ -#define LWMEM_PROTECT(lw) -#define LWMEM_UNPROTECT(lw) +#define LWMEM_PROTECT(lwobj) +#define LWMEM_UNPROTECT(lwobj) #endif /* !LWMEM_CFG_OS */ /* Statistics part */ #if LWMEM_CFG_ENABLE_STATS #define LWMEM_INC_STATS(field) (++(field)) -#define LWMEM_UPDATE_MIN_FREE(lw) \ +#define LWMEM_UPDATE_MIN_FREE(lwobj) \ do { \ - if ((lw)->mem_available_bytes < (lw)->stats.minimum_ever_mem_available_bytes) { \ - (lw)->stats.minimum_ever_mem_available_bytes = (lw)->mem_available_bytes; \ + if ((lwobj)->mem_available_bytes < (lwobj)->stats.minimum_ever_mem_available_bytes) { \ + (lwobj)->stats.minimum_ever_mem_available_bytes = (lwobj)->mem_available_bytes; \ } \ } while (0) #else #define LWMEM_INC_STATS(field) -#define LWMEM_UPDATE_MIN_FREE(lw) +#define LWMEM_UPDATE_MIN_FREE(lwobj) #endif /* LWMEM_CFG_ENABLE_STATS */ /** @@ -218,11 +218,11 @@ prv_get_region_addr_size(const lwmem_region_t* region, uint8_t** msa, size_t* ms /** * \brief Insert free block to linked list of free blocks - * \param[in] lw: LwMEM instance. Set to `NULL` to use default instance + * \param[in] lwobj: LwMEM instance. Set to `NULL` to use default instance * \param[in] nb: New free block to insert into linked list */ static void -prv_insert_free_block(lwmem_t* const lw, lwmem_block_t* nb) { +prv_insert_free_block(lwmem_t* const lwobj, lwmem_block_t* nb) { lwmem_block_t* prev; /* Check valid inputs */ @@ -234,7 +234,7 @@ prv_insert_free_block(lwmem_t* const lw, lwmem_block_t* nb) { * Try to find position to put new block in-between * Search until all free block addresses are lower than entry block */ - for (prev = &(lw->start_block); prev != NULL && prev->next < nb; prev = prev->next) {} + for (prev = &(lwobj->start_block); prev != NULL && prev->next < nb; prev = prev->next) {} /* This is hard error with wrong memory usage */ if (prev == NULL) { @@ -282,8 +282,8 @@ prv_insert_free_block(lwmem_t* const lw, lwmem_block_t* nb) { */ if (prev->next != NULL && prev->next->size > 0 /* Do not remove "end of region" indicator in each region */ && (LWMEM_TO_BYTE_PTR(nb) + nb->size) == LWMEM_TO_BYTE_PTR(prev->next)) { - if (prev->next == lw->end_block) { /* Does it points to the end? */ - nb->next = lw->end_block; /* Set end block pointer */ + if (prev->next == lwobj->end_block) { /* Does it points to the end? */ + nb->next = lwobj->end_block; /* Set end block pointer */ } else { nb->size += prev->next @@ -305,13 +305,13 @@ prv_insert_free_block(lwmem_t* const lw, lwmem_block_t* nb) { /** * \brief Split too big block and add it to list of free blocks - * \param[in] lw: LwMEM instance. Set to `NULL` to use default instance + * \param[in] lwobj: LwMEM instance. Set to `NULL` to use default instance * \param[in] block: Pointer to block with size already set * \param[in] new_block_size: New block size to be set * \return `1` if block splitted, `0` otherwise */ static uint8_t -prv_split_too_big_block(lwmem_t* const lw, lwmem_block_t* block, size_t new_block_size) { +prv_split_too_big_block(lwmem_t* const lwobj, lwmem_block_t* block, size_t new_block_size) { lwmem_block_t* next; size_t block_size, is_alloc_bit; uint8_t success = 0; @@ -329,8 +329,8 @@ prv_split_too_big_block(lwmem_t* const lw, lwmem_block_t* block, size_t new_bloc next->size = block_size - new_block_size; /* Modify block data */ block->size = new_block_size; /* Current size is now smaller */ - lw->mem_available_bytes += next->size; /* Increase available bytes by new block size */ - prv_insert_free_block(lw, next); /* Add new block to the free list */ + lwobj->mem_available_bytes += next->size; /* Increase available bytes by new block size */ + prv_insert_free_block(lwobj, next); /* Add new block to the free list */ success = 1; } else { @@ -348,14 +348,14 @@ prv_split_too_big_block(lwmem_t* const lw, lwmem_block_t* block, size_t new_bloc /** * \brief Private allocation function - * \param[in] lw: LwMEM instance. Set to `NULL` to use default instance + * \param[in] lwobj: LwMEM instance. Set to `NULL` to use default instance * \param[in] region: Pointer to region to allocate from. * Set to `NULL` for any region * \param[in] size: Application wanted size, excluding size of meta header * \return Pointer to allocated memory, `NULL` otherwise */ static void* -prv_alloc(lwmem_t* const lw, const lwmem_region_t* region, const size_t size) { +prv_alloc(lwmem_t* const lwobj, const lwmem_region_t* region, const size_t size) { lwmem_block_t *prev, *curr; void* retval = NULL; @@ -363,12 +363,12 @@ prv_alloc(lwmem_t* const lw, const lwmem_region_t* region, const size_t size) { const size_t final_size = LWMEM_ALIGN(size) + LWMEM_BLOCK_META_SIZE; /* Check if initialized and if size is in the limits */ - if (lw->end_block == NULL || final_size == LWMEM_BLOCK_META_SIZE || (final_size & LWMEM_ALLOC_BIT) > 0) { + if (lwobj->end_block == NULL || final_size == LWMEM_BLOCK_META_SIZE || (final_size & LWMEM_ALLOC_BIT) > 0) { return NULL; } /* Set default values */ - prev = &(lw->start_block); /* Use pointer from custom lwmem block */ + prev = &(lwobj->start_block); /* Use pointer from custom lwmem block */ curr = prev->next; /* Curr represents first actual free block */ /* @@ -393,7 +393,7 @@ prv_alloc(lwmem_t* const lw, const lwmem_region_t* region, const size_t size) { */ for (; curr != NULL; prev = curr, curr = curr->next) { /* Check bounds */ - if (curr->next == NULL || curr == lw->end_block) { + if (curr->next == NULL || curr == lwobj->end_block) { return NULL; } if ((uint8_t*)curr < (uint8_t*)region_start_addr) { /* Check if we reached region */ @@ -412,7 +412,7 @@ prv_alloc(lwmem_t* const lw, const lwmem_region_t* region, const size_t size) { * Loop until size of current block is smaller than requested final size */ for (; curr != NULL && curr->size < final_size; prev = curr, curr = curr->next) { - if (curr->next == NULL || curr == lw->end_block) { /* If no more blocks available */ + if (curr->next == NULL || curr == lwobj->end_block) { /* If no more blocks available */ return NULL; /* No sufficient memory available to allocate block of memory */ } } @@ -429,31 +429,31 @@ prv_alloc(lwmem_t* const lw, const lwmem_region_t* region, const size_t size) { /* curr block is now removed from linked list */ - lw->mem_available_bytes -= curr->size; /* Decrease available bytes by allocated block size */ - prv_split_too_big_block(lw, curr, final_size); /* Split block if it is too big */ + lwobj->mem_available_bytes -= curr->size; /* Decrease available bytes by allocated block size */ + prv_split_too_big_block(lwobj, curr, final_size); /* Split block if it is too big */ LWMEM_BLOCK_SET_ALLOC(curr); /* Set block as allocated */ - LWMEM_UPDATE_MIN_FREE(lw); - LWMEM_INC_STATS(lw->stats.nr_alloc); + LWMEM_UPDATE_MIN_FREE(lwobj); + LWMEM_INC_STATS(lwobj->stats.nr_alloc); return retval; } /** * \brief Free input pointer - * \param[in] lw: LwMEM instance. Set to `NULL` to use default instance + * \param[in] lwobj: LwMEM instance. Set to `NULL` to use default instance * \param[in] ptr: Input pointer to free */ static void -prv_free(lwmem_t* const lw, void* const ptr) { +prv_free(lwmem_t* const lwobj, void* const ptr) { lwmem_block_t* const block = LWMEM_GET_BLOCK_FROM_PTR(ptr); if (LWMEM_BLOCK_IS_ALLOC(block)) { /* Check if block is valid */ block->size &= ~LWMEM_ALLOC_BIT; /* Clear allocated bit indication */ - lw->mem_available_bytes += block->size; /* Increase available bytes */ - prv_insert_free_block(lw, block); /* Put block back to list of free block */ + lwobj->mem_available_bytes += block->size; /* Increase available bytes */ + prv_insert_free_block(lwobj, block); /* Put block back to list of free block */ - LWMEM_INC_STATS(lw->stats.nr_free); + LWMEM_INC_STATS(lwobj->stats.nr_free); } } @@ -467,7 +467,7 @@ prv_free(lwmem_t* const lw, void* const ptr) { * - `ptr != NULL; size == 0`: Function frees memory, equivalent to `free(ptr)` * - `ptr != NULL; size > 0`: Function tries to allocate new memory of copy content before returning pointer on success * - * \param[in] lw: LwMEM instance. Set to `NULL` to use default instance + * \param[in] lwobj: LwMEM instance. Set to `NULL` to use default instance * \param[in] region: Pointer to region to allocate from. * Set to `NULL` for any region * \param[in] ptr: Memory block previously allocated with one of allocation functions. @@ -476,7 +476,7 @@ prv_free(lwmem_t* const lw, void* const ptr) { * \return Pointer to allocated memory on success, `NULL` otherwise */ static void* -prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, const size_t size) { +prv_realloc(lwmem_t* const lwobj, const lwmem_region_t* region, void* const ptr, const size_t size) { lwmem_block_t *block, *prevprev, *prev; size_t block_size; /* Holds size of input block (ptr), including metadata size */ const size_t final_size = @@ -486,12 +486,12 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co /* Check optional input parameters */ if (size == 0) { if (ptr != NULL) { - prv_free(lw, ptr); + prv_free(lwobj, ptr); } return NULL; } if (ptr == NULL) { - return prv_alloc(lw, region, size); + return prv_alloc(lwobj, region, size); } /* Try to reallocate existing pointer */ @@ -529,7 +529,7 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co */ if (final_size < block_size) { if ((block_size - final_size) >= LWMEM_BLOCK_MIN_SIZE) { - prv_split_too_big_block(lw, block, final_size); /* Split block if it is too big */ + prv_split_too_big_block(lwobj, block, final_size); /* Split block if it is too big */ } else { /* * It is not possible to create new empty block at the end of input block @@ -539,7 +539,7 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co */ /* Find free blocks before input block */ - LWMEM_GET_PREV_CURR_OF_BLOCK(lw, block, prevprev, prev); + LWMEM_GET_PREV_CURR_OF_BLOCK(lwobj, block, prevprev, prev); /* Check if current block and next free are connected */ if ((LWMEM_TO_BYTE_PTR(block) + block_size) == LWMEM_TO_BYTE_PTR(prev->next) @@ -552,7 +552,7 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co prev->next = (void*)(LWMEM_TO_BYTE_PTR(prev->next) - (block_size - final_size)); prev->next->size = tmp_size + (block_size - final_size); prev->next->next = tmp_next; - lw->mem_available_bytes += + lwobj->mem_available_bytes += block_size - final_size; /* Increase available bytes by increase of free block */ block->size = final_size; /* Block size is requested size */ @@ -565,7 +565,7 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co /* New requested size is bigger than current block size is */ /* Find last free (and its previous) block, located just before input block */ - LWMEM_GET_PREV_CURR_OF_BLOCK(lw, block, prevprev, prev); + LWMEM_GET_PREV_CURR_OF_BLOCK(lwobj, block, prevprev, prev); /* If entry could not be found, there is a hard error */ if (prev == NULL) { @@ -585,13 +585,13 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co * Merge blocks together by increasing current block with size of next free one * and remove next free from list of free blocks */ - lw->mem_available_bytes -= prev->next->size; /* For now decrease effective available bytes */ - LWMEM_UPDATE_MIN_FREE(lw); + lwobj->mem_available_bytes -= prev->next->size; /* For now decrease effective available bytes */ + LWMEM_UPDATE_MIN_FREE(lwobj); block->size = block_size + prev->next->size; /* Increase effective size of new block */ prev->next = prev->next->next; /* Set next to next's next, effectively remove expanded block from free list */ - prv_split_too_big_block(lw, block, final_size); /* Split block if it is too big */ + prv_split_too_big_block(lwobj, block, final_size); /* Split block if it is too big */ LWMEM_BLOCK_SET_ALLOC(block); /* Set block as allocated */ return ptr; /* Return existing pointer */ } @@ -617,14 +617,14 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co */ LWMEM_MEMMOVE(new_data_ptr, old_data_ptr, block_size); - lw->mem_available_bytes -= prev->size; /* For now decrease effective available bytes */ - LWMEM_UPDATE_MIN_FREE(lw); + lwobj->mem_available_bytes -= prev->size; /* For now decrease effective available bytes */ + LWMEM_UPDATE_MIN_FREE(lwobj); prev->size += block_size; /* Increase size of input block size */ prevprev->next = prev->next; /* Remove prev from free list as it is now being used for allocation together with existing block */ block = prev; /* Move block pointer to previous one */ - prv_split_too_big_block(lw, block, final_size); /* Split block if it is too big */ + prv_split_too_big_block(lwobj, block, final_size); /* Split block if it is too big */ LWMEM_BLOCK_SET_ALLOC(block); /* Set block as allocated */ return new_data_ptr; /* Return new data ptr */ } @@ -657,18 +657,18 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co */ LWMEM_MEMMOVE(new_data_ptr, old_data_ptr, block_size); /* Copy old buffer size to new location */ - lw->mem_available_bytes -= + lwobj->mem_available_bytes -= prev->size + prev->next ->size; /* Decrease effective available bytes for free blocks before and after input block */ - LWMEM_UPDATE_MIN_FREE(lw); + LWMEM_UPDATE_MIN_FREE(lwobj); prev->size += block_size + prev->next->size; /* Increase size of new block by size of 2 free blocks */ prevprev->next = prev->next ->next; /* Remove free block before current one and block after current one from linked list (remove 2) */ block = prev; /* Previous block is now current */ - prv_split_too_big_block(lw, block, final_size); /* Split block if it is too big */ + prv_split_too_big_block(lwobj, block, final_size); /* Split block if it is too big */ LWMEM_BLOCK_SET_ALLOC(block); /* Set block as allocated */ return new_data_ptr; /* Return new data ptr */ } @@ -686,19 +686,19 @@ prv_realloc(lwmem_t* const lw, const lwmem_region_t* region, void* const ptr, co * * Final solution is to find completely new empty block of sufficient size and copy content from old one to new one */ - retval = prv_alloc(lw, region, size); /* Try to allocate new block */ + retval = prv_alloc(lwobj, region, size); /* Try to allocate new block */ if (retval != NULL) { block_size = (block->size & ~LWMEM_ALLOC_BIT) - LWMEM_BLOCK_META_SIZE; /* Get application size from input pointer */ LWMEM_MEMCPY(retval, ptr, size > block_size ? block_size : size); /* Copy content to new allocated block */ - prv_free(lw, ptr); /* Free input pointer */ + prv_free(lwobj, ptr); /* Free input pointer */ } return retval; } /** * \brief Initializes and assigns user regions for memory used by allocator algorithm - * \param[in] lw: LwMEM instance. Set to `NULL` to use default instance + * \param[in] lwobj: LwMEM instance. Set to `NULL` to use default instance * \param[in] regions: Pointer to array of regions with address and respective size. * Regions must be in increasing order (start address) and must not overlap in-between. * Last region entry must have address `NULL` and size set to `0` @@ -716,14 +716,14 @@ lwmem_region_t regions[] = { * It must be called only once to setup memory regions */ size_t -lwmem_assignmem_ex(lwmem_t* lw, const lwmem_region_t* regions) { +lwmem_assignmem_ex(lwmem_t* lwobj, const lwmem_region_t* regions) { uint8_t* mem_start_addr; size_t mem_size, len = 0; lwmem_block_t *first_block, *prev_end_block; - lw = LWMEM_GET_LW(lw); + lwobj = LWMEM_GET_LWOBJ(lwobj); /* Check first things first */ - if (regions == NULL || lw->end_block != NULL /* Init function may only be called once per lwmem instance */ + if (regions == NULL || lwobj->end_block != NULL /* Init function may only be called once per lwmem instance */ || (((size_t)LWMEM_CFG_ALIGN_NUM) & (((size_t)LWMEM_CFG_ALIGN_NUM) - 1)) > 0) { /* Must be power of 2 */ return 0; } @@ -758,8 +758,8 @@ lwmem_assignmem_ex(lwmem_t* lw, const lwmem_region_t* regions) { /* Process further checks of valid inputs */ if (regions == NULL || len == 0 #if LWMEM_CFG_OS - || lwmem_sys_mutex_isvalid(&(lw->mutex)) /* Check if mutex valid already = must not be */ - || !lwmem_sys_mutex_create(&(lw->mutex)) /* Final step = try to create mutex for new instance */ + || lwmem_sys_mutex_isvalid(&(lwobj->mutex)) /* Check if mutex valid already = must not be */ + || !lwmem_sys_mutex_create(&(lwobj->mutex)) /* Final step = try to create mutex for new instance */ #endif /* LWMEM_CFG_OS */ ) { return 0; @@ -776,23 +776,23 @@ lwmem_assignmem_ex(lwmem_t* lw, const lwmem_region_t* regions) { * In first indication application shall set start_block and never again * end_block value holds */ - if (lw->end_block == NULL) { + if (lwobj->end_block == NULL) { /* * Next entry of start block is first region * It points to beginning of region data * In the later step(s) first block is manually set on top of memory region */ - lw->start_block.next = (void*)mem_start_addr; - lw->start_block.size = 0; /* Size of dummy start block is zero */ + lwobj->start_block.next = (void*)mem_start_addr; + lwobj->start_block.size = 0; /* Size of dummy start block is zero */ } /* Save current end block status as it is used later for linked list insertion */ - prev_end_block = lw->end_block; + prev_end_block = lwobj->end_block; /* Put end block to the end of the region with size = 0 */ - lw->end_block = (void*)(mem_start_addr + mem_size - LWMEM_BLOCK_META_SIZE); - lw->end_block->next = NULL; /* End block in region does not have next entry */ - lw->end_block->size = 0; /* Size of end block is zero */ + lwobj->end_block = (void*)(mem_start_addr + mem_size - LWMEM_BLOCK_META_SIZE); + lwobj->end_block->next = NULL; /* End block in region does not have next entry */ + lwobj->end_block->size = 0; /* Size of end block is zero */ /* * Create memory region first block. @@ -803,7 +803,7 @@ lwmem_assignmem_ex(lwmem_t* lw, const lwmem_region_t* regions) { * Actual maximal available size for application in the region is mem_size - 2 * MEM_BLOCK_META_SIZE */ first_block = (void*)mem_start_addr; - first_block->next = lw->end_block; /* Next block of first is last block */ + first_block->next = lwobj->end_block; /* Next block of first is last block */ first_block->size = mem_size - LWMEM_BLOCK_META_SIZE; /* Check if previous regions exist by checking previous end block state */ @@ -811,8 +811,8 @@ lwmem_assignmem_ex(lwmem_t* lw, const lwmem_region_t* regions) { prev_end_block->next = first_block; /* End block of previous region now points to start of current region */ } - lw->mem_available_bytes += first_block->size; /* Increase number of available bytes */ - ++lw->mem_regions_count; /* Increase number of used regions */ + lwobj->mem_available_bytes += first_block->size; /* Increase number of available bytes */ + ++lwobj->mem_regions_count; /* Increase number of used regions */ } #if defined(LWMEM_DEV) @@ -820,17 +820,17 @@ lwmem_assignmem_ex(lwmem_t* lw, const lwmem_region_t* regions) { LWMEM_MEMCPY(&lwmem_default.start_block_first_use, &lwmem_default.start_block, sizeof(lwmem_default.start_block)); #endif /* defined(LWMEM_DEV) */ #if LWMEM_CFG_ENABLE_STATS - lw->stats.mem_size_bytes = lw->mem_available_bytes; - lw->stats.minimum_ever_mem_available_bytes = lw->mem_available_bytes; + lwobj->stats.mem_size_bytes = lwobj->mem_available_bytes; + lwobj->stats.minimum_ever_mem_available_bytes = lwobj->mem_available_bytes; #endif - return lw->mem_regions_count; /* Return number of regions used by manager */ + return lwobj->mem_regions_count; /* Return number of regions used by manager */ } /** * \brief Allocate memory of requested size in specific lwmem instance and optional region. * \note This is an extended malloc version function declaration to support advanced features - * \param[in] lw: LwMEM instance. Set to `NULL` to use default instance + * \param[in] lwobj: LwMEM instance. Set to `NULL` to use default instance * \param[in] region: Optional region instance within LwMEM instance to force allocation from. * Set to `NULL` to use any region within LwMEM instance * \param[in] size: Number of bytes to allocate @@ -838,12 +838,12 @@ lwmem_assignmem_ex(lwmem_t* lw, const lwmem_region_t* regions) { * \note This function is thread safe when \ref LWMEM_CFG_OS is enabled */ void* -lwmem_malloc_ex(lwmem_t* lw, const lwmem_region_t* region, const size_t size) { +lwmem_malloc_ex(lwmem_t* lwobj, const lwmem_region_t* region, const size_t size) { void* ptr; - lw = LWMEM_GET_LW(lw); - LWMEM_PROTECT(lw); - ptr = prv_alloc(lw, region, size); - LWMEM_UNPROTECT(lw); + lwobj = LWMEM_GET_LWOBJ(lwobj); + LWMEM_PROTECT(lwobj); + ptr = prv_alloc(lwobj, region, size); + LWMEM_UNPROTECT(lwobj); return ptr; } @@ -854,7 +854,7 @@ lwmem_malloc_ex(lwmem_t* lw, const lwmem_region_t* region, const size_t size) { * It resets allocated block of memory to zero if allocation is successful * \note This is an extended calloc version function declaration to support advanced features - * \param[in] lw: LwMEM instance. Set to `NULL` to use default instance + * \param[in] lwobj: LwMEM instance. Set to `NULL` to use default instance * \param[in] region: Optional region instance within LwMEM instance to force allocation from. * Set to `NULL` to use any region within LwMEM instance * \param[in] nitems: Number of elements to be allocated @@ -863,16 +863,16 @@ lwmem_malloc_ex(lwmem_t* lw, const lwmem_region_t* region, const size_t size) { * \note This function is thread safe when \ref LWMEM_CFG_OS is enabled */ void* -lwmem_calloc_ex(lwmem_t* lw, const lwmem_region_t* region, const size_t nitems, const size_t size) { +lwmem_calloc_ex(lwmem_t* lwobj, const lwmem_region_t* region, const size_t nitems, const size_t size) { void* ptr; const size_t s = size * nitems; - lw = LWMEM_GET_LW(lw); - LWMEM_PROTECT(lw); - if ((ptr = prv_alloc(lw, region, s)) != NULL) { + lwobj = LWMEM_GET_LWOBJ(lwobj); + LWMEM_PROTECT(lwobj); + if ((ptr = prv_alloc(lwobj, region, s)) != NULL) { LWMEM_MEMSET(ptr, 0x00, s); } - LWMEM_UNPROTECT(lw); + LWMEM_UNPROTECT(lwobj); return ptr; } @@ -888,7 +888,7 @@ lwmem_calloc_ex(lwmem_t* lw, const lwmem_region_t* region, const size_t nitems, * - `ptr != NULL; size == 0`: Function frees memory, equivalent to `free(ptr)` * - `ptr != NULL; size > 0`: Function tries to allocate new memory of copy content before returning pointer on success * - * \param[in] lw: LwMEM instance. Set to `NULL` to use default instance + * \param[in] lwobj: LwMEM instance. Set to `NULL` to use default instance * \param[in] region: Pointer to region to allocate from. * Set to `NULL` to use any region within LwMEM instance. * Instance must be the same as used during allocation procedure @@ -899,12 +899,12 @@ lwmem_calloc_ex(lwmem_t* lw, const lwmem_region_t* region, const size_t nitems, * \note This function is thread safe when \ref LWMEM_CFG_OS is enabled */ void* -lwmem_realloc_ex(lwmem_t* lw, const lwmem_region_t* region, void* const ptr, const size_t size) { +lwmem_realloc_ex(lwmem_t* lwobj, const lwmem_region_t* region, void* const ptr, const size_t size) { void* p; - lw = LWMEM_GET_LW(lw); - LWMEM_PROTECT(lw); - p = prv_realloc(lw, region, ptr, size); - LWMEM_UNPROTECT(lw); + lwobj = LWMEM_GET_LWOBJ(lwobj); + LWMEM_PROTECT(lwobj); + p = prv_realloc(lwobj, region, ptr, size); + LWMEM_UNPROTECT(lwobj); return p; } @@ -925,7 +925,7 @@ lwmem_realloc_ex(lwmem_t* lw, const lwmem_region_t* region, void* const ptr, con * - `*ptr != NULL; size == 0`: Function frees memory, equivalent to `free(ptr)`, sets input pointer pointing to `NULL` * - `*ptr != NULL; size > 0`: Function tries to reallocate existing pointer with new size and copy content to new block * - * \param[in] lw: LwMEM instance. Set to `NULL` to use default instance + * \param[in] lwobj: LwMEM instance. Set to `NULL` to use default instance * \param[in] region: Pointer to region to allocate from. * Set to `NULL` to use any region within LwMEM instance. * Instance must be the same as used during allocation procedure @@ -937,7 +937,7 @@ lwmem_realloc_ex(lwmem_t* lw, const lwmem_region_t* region, void* const ptr, con * \note This function is thread safe when \ref LWMEM_CFG_OS is enabled */ uint8_t -lwmem_realloc_s_ex(lwmem_t* lw, const lwmem_region_t* region, void** const ptr, const size_t size) { +lwmem_realloc_s_ex(lwmem_t* lwobj, const lwmem_region_t* region, void** const ptr, const size_t size) { void* new_ptr; /* @@ -949,7 +949,7 @@ lwmem_realloc_s_ex(lwmem_t* lw, const lwmem_region_t* region, void** const ptr, return 0; } - new_ptr = lwmem_realloc_ex(lw, region, *ptr, size); /* Try to reallocate existing pointer */ + new_ptr = lwmem_realloc_ex(lwobj, region, *ptr, size); /* Try to reallocate existing pointer */ if (new_ptr != NULL) { *ptr = new_ptr; } else if (size == 0) { /* size == 0 means free input memory */ @@ -962,18 +962,18 @@ lwmem_realloc_s_ex(lwmem_t* lw, const lwmem_region_t* region, void** const ptr, /** * \brief Free previously allocated memory using one of allocation functions * in specific lwmem instance. - * \param[in] lw: LwMEM instance. Set to `NULL` to use default instance. + * \param[in] lwobj: LwMEM instance. Set to `NULL` to use default instance. * Instance must be the same as used during allocation procedure * \note This is an extended free version function declaration to support advanced features * \param[in] ptr: Memory to free. `NULL` pointer is valid input * \note This function is thread safe when \ref LWMEM_CFG_OS is enabled */ void -lwmem_free_ex(lwmem_t* lw, void* const ptr) { - lw = LWMEM_GET_LW(lw); - LWMEM_PROTECT(lw); - prv_free(lw, ptr); - LWMEM_UNPROTECT(lw); +lwmem_free_ex(lwmem_t* lwobj, void* const ptr) { + lwobj = LWMEM_GET_LWOBJ(lwobj); + LWMEM_PROTECT(lwobj); + prv_free(lwobj, ptr); + LWMEM_UNPROTECT(lwobj); } /** @@ -984,43 +984,43 @@ lwmem_free_ex(lwmem_t* lw, void* const ptr) { * * It is advised to use this function when freeing memory. * - * \param[in] lw: LwMEM instance. Set to `NULL` to use default instance. + * \param[in] lwobj: LwMEM instance. Set to `NULL` to use default instance. * Instance must be the same as used during allocation procedure * \param[in] ptr: Pointer to pointer to allocated memory. * When set to non `NULL`, pointer is freed and set to `NULL` * \note This function is thread safe when \ref LWMEM_CFG_OS is enabled */ void -lwmem_free_s_ex(lwmem_t* lw, void** const ptr) { +lwmem_free_s_ex(lwmem_t* lwobj, void** const ptr) { if (ptr != NULL && *ptr != NULL) { - lw = LWMEM_GET_LW(lw); - LWMEM_PROTECT(lw); - prv_free(lw, *ptr); - LWMEM_UNPROTECT(lw); + lwobj = LWMEM_GET_LWOBJ(lwobj); + LWMEM_PROTECT(lwobj); + prv_free(lwobj, *ptr); + LWMEM_UNPROTECT(lwobj); *ptr = NULL; } } /** * \brief Get user size of allocated memory - * \param[in] lw: LwMEM instance. Set to `NULL` to use default instance. + * \param[in] lwobj: LwMEM instance. Set to `NULL` to use default instance. * Instance must be the same as used during allocation procedure * \param[in] ptr: Pointer to allocated memory * \return Block size for user in units of bytes */ size_t -lwmem_get_size_ex(lwmem_t* lw, void* ptr) { +lwmem_get_size_ex(lwmem_t* lwobj, void* ptr) { lwmem_block_t* block; uint32_t len = 0; if (ptr != NULL) { - lw = LWMEM_GET_LW(lw); - LWMEM_PROTECT(lw); + lwobj = LWMEM_GET_LWOBJ(lwobj); + LWMEM_PROTECT(lwobj); block = LWMEM_GET_BLOCK_FROM_PTR(ptr); if (LWMEM_BLOCK_IS_ALLOC(block)) { len = (block->size & ~LWMEM_ALLOC_BIT) - LWMEM_BLOCK_META_SIZE; } - LWMEM_UNPROTECT(lw); + LWMEM_UNPROTECT(lwobj); } return len; } @@ -1029,18 +1029,18 @@ lwmem_get_size_ex(lwmem_t* lw, void* ptr) { /** * \brief Get statistics of a LwMEM instance - * \param[in] lw: LwMEM instance. Set to `NULL` to use default instance. + * \param[in] lwobj: LwMEM instance. Set to `NULL` to use default instance. * Instance must be the same as used during allocation procedure * \param[in] stats: Pointer to \ref lwmem_stats_t to store result */ void -lwmem_get_stats_ex(lwmem_t* lw, lwmem_stats_t* stats) { +lwmem_get_stats_ex(lwmem_t* lwobj, lwmem_stats_t* stats) { if (stats != NULL) { - lw = LWMEM_GET_LW(lw); - LWMEM_PROTECT(lw); - *stats = lw->stats; - stats->mem_available_bytes = lw->mem_available_bytes; - LWMEM_UNPROTECT(lw); + lwobj = LWMEM_GET_LWOBJ(lwobj); + LWMEM_PROTECT(lwobj); + *stats = lwobj->stats; + stats->mem_available_bytes = lwobj->mem_available_bytes; + LWMEM_UNPROTECT(lwobj); } } From 4091da9d9dac16b5012b0a5422ee9c45d0484b5c Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Wed, 4 Jan 2023 21:14:09 +0100 Subject: [PATCH 72/73] Update license to 2023 --- LICENSE | 2 +- dev/lwmem_opts.h | 2 +- examples/stm32/lwmem_rtos_stm32l496_discovery/inc/lwmem_opts.h | 2 +- examples/stm32/lwmem_rtos_stm32l496_discovery/inc/main.h | 2 +- examples/stm32/lwmem_rtos_stm32l496_discovery/src/main.c | 2 +- examples/stm32/lwmem_stm32l496_discovery/inc/lwmem_opts.h | 2 +- examples/stm32/lwmem_stm32l496_discovery/inc/main.h | 2 +- examples/stm32/lwmem_stm32l496_discovery/src/main.c | 2 +- examples/win32/lwmem_basic/lwmem_opts.h | 2 +- examples/win32/lwmem_multi_ins_multi_region/lwmem_opts.h | 2 +- examples/win32/lwmem_multi_region/lwmem_opts.h | 2 +- examples/win32/lwmem_os/lwmem_opts.h | 2 +- lwmem/src/include/lwmem/lwmem.h | 2 +- lwmem/src/include/lwmem/lwmem_opt.h | 2 +- lwmem/src/include/lwmem/lwmem_opts_template.h | 2 +- lwmem/src/include/system/lwmem_sys.h | 2 +- lwmem/src/lwmem/lwmem.c | 2 +- lwmem/src/system/lwmem_sys_cmsis_os.c | 2 +- lwmem/src/system/lwmem_sys_threadx.c | 2 +- lwmem/src/system/lwmem_sys_win32.c | 2 +- 20 files changed, 20 insertions(+), 20 deletions(-) diff --git a/LICENSE b/LICENSE index 5625f63..3702ca4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Tilen MAJERLE +Copyright (c) 2023 Tilen MAJERLE Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/dev/lwmem_opts.h b/dev/lwmem_opts.h index 91db702..9c9bce8 100644 --- a/dev/lwmem_opts.h +++ b/dev/lwmem_opts.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2022 Tilen MAJERLE + * Copyright (c) 2023 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/inc/lwmem_opts.h b/examples/stm32/lwmem_rtos_stm32l496_discovery/inc/lwmem_opts.h index c3c6151..27f8119 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/inc/lwmem_opts.h +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/inc/lwmem_opts.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2022 Tilen MAJERLE + * Copyright (c) 2023 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/inc/main.h b/examples/stm32/lwmem_rtos_stm32l496_discovery/inc/main.h index a798edf..e3fd5d3 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/inc/main.h +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/inc/main.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2022 Tilen MAJERLE + * Copyright (c) 2023 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/src/main.c b/examples/stm32/lwmem_rtos_stm32l496_discovery/src/main.c index 45f1412..0a68844 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/src/main.c +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/src/main.c @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2022 Tilen MAJERLE + * Copyright (c) 2023 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/examples/stm32/lwmem_stm32l496_discovery/inc/lwmem_opts.h b/examples/stm32/lwmem_stm32l496_discovery/inc/lwmem_opts.h index 1c9c2d1..7762a8b 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/inc/lwmem_opts.h +++ b/examples/stm32/lwmem_stm32l496_discovery/inc/lwmem_opts.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2022 Tilen MAJERLE + * Copyright (c) 2023 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/examples/stm32/lwmem_stm32l496_discovery/inc/main.h b/examples/stm32/lwmem_stm32l496_discovery/inc/main.h index a798edf..e3fd5d3 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/inc/main.h +++ b/examples/stm32/lwmem_stm32l496_discovery/inc/main.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2022 Tilen MAJERLE + * Copyright (c) 2023 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/examples/stm32/lwmem_stm32l496_discovery/src/main.c b/examples/stm32/lwmem_stm32l496_discovery/src/main.c index 8592189..e11c079 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/src/main.c +++ b/examples/stm32/lwmem_stm32l496_discovery/src/main.c @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2022 Tilen MAJERLE + * Copyright (c) 2023 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/examples/win32/lwmem_basic/lwmem_opts.h b/examples/win32/lwmem_basic/lwmem_opts.h index 1c9c2d1..7762a8b 100644 --- a/examples/win32/lwmem_basic/lwmem_opts.h +++ b/examples/win32/lwmem_basic/lwmem_opts.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2022 Tilen MAJERLE + * Copyright (c) 2023 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/examples/win32/lwmem_multi_ins_multi_region/lwmem_opts.h b/examples/win32/lwmem_multi_ins_multi_region/lwmem_opts.h index 1c9c2d1..7762a8b 100644 --- a/examples/win32/lwmem_multi_ins_multi_region/lwmem_opts.h +++ b/examples/win32/lwmem_multi_ins_multi_region/lwmem_opts.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2022 Tilen MAJERLE + * Copyright (c) 2023 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/examples/win32/lwmem_multi_region/lwmem_opts.h b/examples/win32/lwmem_multi_region/lwmem_opts.h index 1c9c2d1..7762a8b 100644 --- a/examples/win32/lwmem_multi_region/lwmem_opts.h +++ b/examples/win32/lwmem_multi_region/lwmem_opts.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2022 Tilen MAJERLE + * Copyright (c) 2023 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/examples/win32/lwmem_os/lwmem_opts.h b/examples/win32/lwmem_os/lwmem_opts.h index a5dcb36..e86dbbe 100644 --- a/examples/win32/lwmem_os/lwmem_opts.h +++ b/examples/win32/lwmem_os/lwmem_opts.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2022 Tilen MAJERLE + * Copyright (c) 2023 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lwmem/src/include/lwmem/lwmem.h b/lwmem/src/include/lwmem/lwmem.h index d878bf6..e2833d6 100644 --- a/lwmem/src/include/lwmem/lwmem.h +++ b/lwmem/src/include/lwmem/lwmem.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2022 Tilen MAJERLE + * Copyright (c) 2023 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lwmem/src/include/lwmem/lwmem_opt.h b/lwmem/src/include/lwmem/lwmem_opt.h index 8e2bf4f..0b06771 100644 --- a/lwmem/src/include/lwmem/lwmem_opt.h +++ b/lwmem/src/include/lwmem/lwmem_opt.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2022 Tilen MAJERLE + * Copyright (c) 2023 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lwmem/src/include/lwmem/lwmem_opts_template.h b/lwmem/src/include/lwmem/lwmem_opts_template.h index 9036f0a..e22388e 100644 --- a/lwmem/src/include/lwmem/lwmem_opts_template.h +++ b/lwmem/src/include/lwmem/lwmem_opts_template.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2022 Tilen MAJERLE + * Copyright (c) 2023 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lwmem/src/include/system/lwmem_sys.h b/lwmem/src/include/system/lwmem_sys.h index 2e32fb4..eb516b5 100644 --- a/lwmem/src/include/system/lwmem_sys.h +++ b/lwmem/src/include/system/lwmem_sys.h @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2022 Tilen MAJERLE + * Copyright (c) 2023 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lwmem/src/lwmem/lwmem.c b/lwmem/src/lwmem/lwmem.c index 6b27408..c03e87e 100644 --- a/lwmem/src/lwmem/lwmem.c +++ b/lwmem/src/lwmem/lwmem.c @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2022 Tilen MAJERLE + * Copyright (c) 2023 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lwmem/src/system/lwmem_sys_cmsis_os.c b/lwmem/src/system/lwmem_sys_cmsis_os.c index c720cc2..c725ef8 100644 --- a/lwmem/src/system/lwmem_sys_cmsis_os.c +++ b/lwmem/src/system/lwmem_sys_cmsis_os.c @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2022 Tilen MAJERLE + * Copyright (c) 2023 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lwmem/src/system/lwmem_sys_threadx.c b/lwmem/src/system/lwmem_sys_threadx.c index db8fa51..c048e66 100644 --- a/lwmem/src/system/lwmem_sys_threadx.c +++ b/lwmem/src/system/lwmem_sys_threadx.c @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2022 Tilen MAJERLE + * Copyright (c) 2023 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lwmem/src/system/lwmem_sys_win32.c b/lwmem/src/system/lwmem_sys_win32.c index 449fecf..7496671 100644 --- a/lwmem/src/system/lwmem_sys_win32.c +++ b/lwmem/src/system/lwmem_sys_win32.c @@ -4,7 +4,7 @@ */ /* - * Copyright (c) 2022 Tilen MAJERLE + * Copyright (c) 2023 Tilen MAJERLE * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation From 2bf547109161645922f5dd4dda0ffeed2724ef8e Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Tue, 31 Jan 2023 07:55:11 +0100 Subject: [PATCH 73/73] Set version to 2.1.0 --- .vscode/tasks.json | 2 +- CHANGELOG.md | 3 + .../lib/FreeRTOS/CMSIS_RTOS_V2/cmsis_os.h | 4 +- .../.vscode/launch.json | 2 +- .../.vscode/tasks.json | 2 +- .../.vscode/launch.json | 2 +- .../.vscode/tasks.json | 2 +- examples/win32/.vscode/tasks.json | 2 +- library.json | 64 +++++++++---------- lwmem/src/include/lwmem/lwmem.h | 2 +- lwmem/src/include/lwmem/lwmem.hpp | 2 +- lwmem/src/include/lwmem/lwmem_opt.h | 2 +- lwmem/src/include/lwmem/lwmem_opts_template.h | 2 +- lwmem/src/include/system/lwmem_sys.h | 2 +- lwmem/src/lwmem/lwmem.c | 2 +- lwmem/src/lwmem/lwmem.cpp | 2 +- lwmem/src/system/lwmem_sys_cmsis_os.c | 2 +- lwmem/src/system/lwmem_sys_threadx.c | 2 +- lwmem/src/system/lwmem_sys_win32.c | 2 +- 19 files changed, 52 insertions(+), 51 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 09422ee..7a24c4a 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,5 +1,5 @@ { - "version": "2.0.0", + "version": "2.1.0", "tasks": [ { "type": "cppbuild", diff --git a/CHANGELOG.md b/CHANGELOG.md index aa56841..4133354 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,13 @@ ## Develop +## v2.1.0 + - Split CMakeLists.txt files between library and executable - Add C++ wrapper functions - Change license year to 2022 - Update code style with astyle +- Fix wrong length function usage - Add `.clang-format` draft ## v2.0.0 diff --git a/examples/lib/FreeRTOS/CMSIS_RTOS_V2/cmsis_os.h b/examples/lib/FreeRTOS/CMSIS_RTOS_V2/cmsis_os.h index 3b885bb..7eb8d8b 100644 --- a/examples/lib/FreeRTOS/CMSIS_RTOS_V2/cmsis_os.h +++ b/examples/lib/FreeRTOS/CMSIS_RTOS_V2/cmsis_os.h @@ -1,5 +1,5 @@ /* -------------------------------------------------------------------------- - * Portions Copyright © 2017 STMicroelectronics International N.V. All rights reserved. + * Portions Copyright � 2017 STMicroelectronics International N.V. All rights reserved. * Portions Copyright (c) 2013-2017 ARM Limited. All rights reserved. * -------------------------------------------------------------------------- * @@ -37,7 +37,7 @@ * Control functions for short timeouts in microsecond resolution: * Added: osKernelSysTick, osKernelSysTickFrequency, osKernelSysTickMicroSec * Removed: osSignalGet - * Version 2.0.0 + * Version 2.1.0 * OS objects creation without macros (dynamic creation and resource allocation): * - added: osXxxxNew functions which replace osXxxxCreate * - added: osXxxxAttr_t structures diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json index 9b3d92d..cfa57fa 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/launch.json @@ -22,7 +22,7 @@ /* Will get automatically detected if STM32CubeIDE is installed to default directory or it can be manually provided if necessary.. */ //"serverpath": "c:\\ST\\STM32CubeIDE_1.7.0\\STM32CubeIDE\\plugins\\com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.win32_2.0.100.202109301221\\tools\\bin\\ST-LINK_gdbserver.exe", - //"armToolchainPath": "c:\\ST\\STM32CubeIDE_1.7.0\\STM32CubeIDE\\plugins\\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\\tools\\bin", + //"armToolchainPath": "c:\\ST\\STM32CubeIDE_1.7.0\\STM32CubeIDE\\plugins\\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.1.0.202105311346\\tools\\bin", //"stm32cubeprogrammer": "c:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeProgrammer\\bin", /* If you use external loader, add additional arguments */ diff --git a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json index fe4c345..448dbf0 100644 --- a/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json +++ b/examples/stm32/lwmem_rtos_stm32l496_discovery/.vscode/tasks.json @@ -1,5 +1,5 @@ { - "version": "2.0.0", + "version": "2.1.0", "tasks": [ { "type": "cppbuild", diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json index 9b3d92d..cfa57fa 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/launch.json @@ -22,7 +22,7 @@ /* Will get automatically detected if STM32CubeIDE is installed to default directory or it can be manually provided if necessary.. */ //"serverpath": "c:\\ST\\STM32CubeIDE_1.7.0\\STM32CubeIDE\\plugins\\com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.win32_2.0.100.202109301221\\tools\\bin\\ST-LINK_gdbserver.exe", - //"armToolchainPath": "c:\\ST\\STM32CubeIDE_1.7.0\\STM32CubeIDE\\plugins\\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\\tools\\bin", + //"armToolchainPath": "c:\\ST\\STM32CubeIDE_1.7.0\\STM32CubeIDE\\plugins\\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.1.0.202105311346\\tools\\bin", //"stm32cubeprogrammer": "c:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeProgrammer\\bin", /* If you use external loader, add additional arguments */ diff --git a/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json b/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json index fe4c345..448dbf0 100644 --- a/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json +++ b/examples/stm32/lwmem_stm32l496_discovery/.vscode/tasks.json @@ -1,5 +1,5 @@ { - "version": "2.0.0", + "version": "2.1.0", "tasks": [ { "type": "cppbuild", diff --git a/examples/win32/.vscode/tasks.json b/examples/win32/.vscode/tasks.json index e526563..5bc8468 100644 --- a/examples/win32/.vscode/tasks.json +++ b/examples/win32/.vscode/tasks.json @@ -1,5 +1,5 @@ { - "version": "2.0.0", + "version": "2.1.0", "tasks": [ { "type": "cppbuild", diff --git a/library.json b/library.json index 4e8d30c..3e1f333 100644 --- a/library.json +++ b/library.json @@ -1,35 +1,33 @@ { - "name": "LwMEM", - "version": "2.0.0", - "description": "Lightweight dynamic memory manager optimized for embedded systems", - "keywords": "lwmem, memory, dynamic, heap, malloc, calloc, realloc, free, lightweight, manager, embedded, stm32, win32", - "repository": { - "type": "git", - "url": "https://github.com/MaJerle/lwmem.git" - }, - "authors": [ - { - "name": "Tilen Majerle", - "email": "tilen@majerle.eu", - "url": "https://majerle.eu" - } - ], - "license": "MIT", - "homepage": "https://github.com/MaJerle/lwmem", - "dependencies": { - - }, - "frameworks": "*", - "platforms": "*", - "export": { - "exclude": [ - ".github", - "dev", - "docs", - "**/.vs", - "**/Debug", - "build", - "**/build" - ] - } + "name": "LwMEM", + "version": "2.1.0", + "description": "Lightweight dynamic memory manager optimized for embedded systems", + "keywords": "lwmem, memory, dynamic, heap, malloc, calloc, realloc, free, lightweight, manager, embedded, stm32, win32", + "repository": { + "type": "git", + "url": "https://github.com/MaJerle/lwmem.git" + }, + "authors": [ + { + "name": "Tilen Majerle", + "email": "tilen@majerle.eu", + "url": "https://majerle.eu" + } + ], + "license": "MIT", + "homepage": "https://github.com/MaJerle/lwmem", + "dependencies": {}, + "frameworks": "*", + "platforms": "*", + "export": { + "exclude": [ + ".github", + "dev", + "docs", + "**/.vs", + "**/Debug", + "build", + "**/build" + ] + } } \ No newline at end of file diff --git a/lwmem/src/include/lwmem/lwmem.h b/lwmem/src/include/lwmem/lwmem.h index e2833d6..d854627 100644 --- a/lwmem/src/include/lwmem/lwmem.h +++ b/lwmem/src/include/lwmem/lwmem.h @@ -29,7 +29,7 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.0.0 + * Version: v2.1.0 */ #ifndef LWMEM_HDR_H #define LWMEM_HDR_H diff --git a/lwmem/src/include/lwmem/lwmem.hpp b/lwmem/src/include/lwmem/lwmem.hpp index eaea617..2240947 100644 --- a/lwmem/src/include/lwmem/lwmem.hpp +++ b/lwmem/src/include/lwmem/lwmem.hpp @@ -29,7 +29,7 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.0.0 + * Version: v2.1.0 */ #ifndef LWMEM_HDR_HPP #define LWMEM_HDR_HPP diff --git a/lwmem/src/include/lwmem/lwmem_opt.h b/lwmem/src/include/lwmem/lwmem_opt.h index 0b06771..b17b5ce 100644 --- a/lwmem/src/include/lwmem/lwmem_opt.h +++ b/lwmem/src/include/lwmem/lwmem_opt.h @@ -29,7 +29,7 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.0.0 + * Version: v2.1.0 */ #ifndef LWMEM_OPT_HDR_H #define LWMEM_OPT_HDR_H diff --git a/lwmem/src/include/lwmem/lwmem_opts_template.h b/lwmem/src/include/lwmem/lwmem_opts_template.h index e22388e..deb5e80 100644 --- a/lwmem/src/include/lwmem/lwmem_opts_template.h +++ b/lwmem/src/include/lwmem/lwmem_opts_template.h @@ -29,7 +29,7 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.0.0 + * Version: v2.1.0 */ #ifndef LWMEM_OPTS_HDR_H #define LWMEM_OPTS_HDR_H diff --git a/lwmem/src/include/system/lwmem_sys.h b/lwmem/src/include/system/lwmem_sys.h index eb516b5..a837d89 100644 --- a/lwmem/src/include/system/lwmem_sys.h +++ b/lwmem/src/include/system/lwmem_sys.h @@ -29,7 +29,7 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.0.0 + * Version: v2.1.0 */ #ifndef LWMEM_SYS_HDR_H #define LWMEM_SYS_HDR_H diff --git a/lwmem/src/lwmem/lwmem.c b/lwmem/src/lwmem/lwmem.c index c03e87e..02e755c 100644 --- a/lwmem/src/lwmem/lwmem.c +++ b/lwmem/src/lwmem/lwmem.c @@ -29,7 +29,7 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.0.0 + * Version: v2.1.0 */ #include "lwmem/lwmem.h" #include diff --git a/lwmem/src/lwmem/lwmem.cpp b/lwmem/src/lwmem/lwmem.cpp index 56ed731..4229285 100644 --- a/lwmem/src/lwmem/lwmem.cpp +++ b/lwmem/src/lwmem/lwmem.cpp @@ -29,5 +29,5 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.0.0 + * Version: v2.1.0 */ diff --git a/lwmem/src/system/lwmem_sys_cmsis_os.c b/lwmem/src/system/lwmem_sys_cmsis_os.c index c725ef8..a327f78 100644 --- a/lwmem/src/system/lwmem_sys_cmsis_os.c +++ b/lwmem/src/system/lwmem_sys_cmsis_os.c @@ -29,7 +29,7 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.0.0 + * Version: v2.1.0 */ #include "system/lwmem_sys.h" diff --git a/lwmem/src/system/lwmem_sys_threadx.c b/lwmem/src/system/lwmem_sys_threadx.c index c048e66..f6713ef 100644 --- a/lwmem/src/system/lwmem_sys_threadx.c +++ b/lwmem/src/system/lwmem_sys_threadx.c @@ -29,7 +29,7 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.0.0 + * Version: v2.1.0 */ #include "system/lwmem_sys.h" diff --git a/lwmem/src/system/lwmem_sys_win32.c b/lwmem/src/system/lwmem_sys_win32.c index 7496671..0a7bb8e 100644 --- a/lwmem/src/system/lwmem_sys_win32.c +++ b/lwmem/src/system/lwmem_sys_win32.c @@ -29,7 +29,7 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.0.0 + * Version: v2.1.0 */ #include "system/lwmem_sys.h"