Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (c) 2025 Dmitry Ponomarev <ponomarevda96@gmail.com>
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

cmake_minimum_required(VERSION 3.22)
project(libparams VERSION 1.0 LANGUAGES CXX C)

if(LIBPARAMS_PLATFORM STREQUAL "stm32f103")
elseif(LIBPARAMS_PLATFORM STREQUAL "stm32g0b1")
elseif(LIBPARAMS_PLATFORM STREQUAL "ubuntu")
else()
message(SEND_ERROR "LIBPARAMS_PLATFORM is not specified! Options: stm32f103, stm32g0b1, ubuntu.")
endif()

execute_process(
COMMAND ${ROOT_DIR}/scripts/generate_default_params.py
--out-dir ${CMAKE_CURRENT_BINARY_DIR}/params
-f ${TESTS_DIR}/params/params.c
--out-file-name "init_params"
RESULT_VARIABLE ret
)
if(NOT ret EQUAL 0)
message( FATAL_ERROR "Default Params Generator has been failed. Abort.")
endif()
set(LIBPARAMS_PARAMS_DIR="${CMAKE_CURRENT_BINARY_DIR}/params")
add_definitions(-DLIBPARAMS_PARAMS_DIR="${CMAKE_CURRENT_BINARY_DIR}/params")

FILE(GLOB libparamsPlatformSpecificSrc
${CMAKE_CURRENT_LIST_DIR}/platform_specific/${LIBPARAMS_PLATFORM}/*.c*
)

FILE(GLOB libparamsGeneratedParams
${LIBPARAMS_GENERATED_PARAMS_DIR}/*.c*
${LIBPARAMS_GENERATED_PARAMS_DIR}/*.cpp*
)

add_library(${PROJECT_NAME} STATIC
src/rom.c
src/storage.c
${libparamsPlatformSpecificSrc}
${libparamsGeneratedParams}
)

add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<BUILD_INTERFACE:${LIBPARAMS_GENERATED_PARAMS_DIR}>
$<INSTALL_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<INSTALL_INTERFACE:${LIBPARAMS_GENERATED_PARAMS_DIR}>
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ You can create params.c and params.h files with the following content:
```c++
// params.h
#pragma once
#include "storage.h"
#include "libparams/storage.h"

enum IntParamsIndexes : ParamIndex_t {
PARAM_NODE_ID,
Expand Down
6 changes: 3 additions & 3 deletions include/libparams/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>
#include "rom.h"
#include "libparams_error_codes.h"
#include "_legacy_functions.h"
#include "libparams/rom.h"
#include "libparams/libparams_error_codes.h"
#include "libparams/_legacy_functions.h"

#ifdef __cplusplus
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion libparams.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ set(libparamsSrc
)

set(libparamsHeaders
${CMAKE_CURRENT_LIST_DIR}/include/libparams/
${CMAKE_CURRENT_LIST_DIR}/include/
${CMAKE_CURRENT_LIST_DIR}/platform_specific/${LIBPARAMS_PLATFORM}/
${libparamsPlatformSpecificHeaders}
)
4 changes: 2 additions & 2 deletions platform_specific/stm32f103/flash_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include "flash_driver.h"
#include "libparams/flash_driver.h"
#include <string.h>
#include "libparams_error_codes.h"
#include "libparams/libparams_error_codes.h"
#include "flash_registers.h"


Expand Down
4 changes: 2 additions & 2 deletions platform_specific/stm32g0b1/flash_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include "flash_driver.h"
#include "libparams/flash_driver.h"
#include <string.h>
#include "main.h"
#include "libparams_error_codes.h"
#include "libparams/libparams_error_codes.h"


static uint8_t* flashGetPointer();
Expand Down
2 changes: 1 addition & 1 deletion platform_specific/ubuntu/FlashMemoryLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef LIBPARAM_FLASH_MEMORY_LAYOUT_HPP_
#define LIBPARAM_FLASH_MEMORY_LAYOUT_HPP_

#include "storage.h"
#include "libparams/storage.h"

typedef struct {
IntegerDesc_t* integer_desc_pool;
Expand Down
2 changes: 1 addition & 1 deletion platform_specific/ubuntu/YamlParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <iostream>
#include <iomanip>

#include "storage.h"
#include "libparams/storage.h"
#include "YamlParameters.hpp"

YamlParameters::YamlParameters(FlashMemoryLayout_t flash_desc,
Expand Down
10 changes: 7 additions & 3 deletions platform_specific/ubuntu/flash_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/

#include <string.h>
#include "storage.h"
#include "flash_driver.h"
#include "libparams_error_codes.h"
#include "libparams/storage.h"
#include "libparams/flash_driver.h"
#include "libparams/libparams_error_codes.h"
#include "params.hpp"
#include "YamlParameters.hpp"

Expand Down Expand Up @@ -115,3 +115,7 @@ int32_t __save_to_files() {
int8_t __read_from_files() {
return yaml_params.read_from_dir(LIBPARAMS_PARAMS_DIR);
}

const char* get_libparams_params_dir() {
return LIBPARAMS_PARAMS_DIR;
}
8 changes: 4 additions & 4 deletions scripts/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class CppHeader:
INTEGER_HEAD = """#pragma once
#include "storage.h"
#include "libparams/storage.h"
#include "string_params.hpp"
enum IntParamsIndexes : ParamIndex_t {
"""
Expand Down Expand Up @@ -39,7 +39,7 @@ class CHeader:

class CSource:
INTEGER_HEAD="""#include "params.h"
#include "storage.h"
#include "libparams/storage.h"
IntegerDesc_t integer_desc_pool[] = {
"""

Expand All @@ -49,7 +49,7 @@ class CSource:
"""

STRING_HEAD="""#include "string_params.h"
#include "storage.h"
#include "libparams/storage.h"
StringDesc_t __attribute__((weak)) string_desc_pool[NUM_OF_STR_PARAMS] = {
"""
STRING_TAIL="""
Expand All @@ -68,7 +68,7 @@ class CppSource:
"""

STRING_HEAD="""#include "string_params.hpp"
#include "storage.h"
#include "libparams/storage.h"
StringDesc_t __attribute__((weak)) string_desc_pool[NUM_OF_STR_PARAMS] = {
"""
STRING_TAIL="""
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def generate(self):
hpp_content = (
f"{LICENSE_HEADER}\n"
"#pragma once\n"
"#include \"storage.h\"\n\n"
"#include \"libparams/storage.h\"\n\n"
"enum IntParamsIndexes {\n"
f"{self.integers_enums}\n"
" INTEGER_PARAMS_AMOUNT\n"
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_random_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def generate(self):
hpp_content = (
f"{LICENSE_HEADER}\n"
"#pragma once\n"
"#include \"storage.h\"\n\n"
"#include \"libparams/storage.h\"\n\n"
"enum IntParamsIndexes {\n"
f"{self.integers_enums}\n"
" INTEGER_PARAMS_AMOUNT\n"
Expand Down
6 changes: 3 additions & 3 deletions src/rom.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include "rom.h"
#include "libparams/rom.h"
#include <stddef.h>
#include <string.h>
#include "flash_driver.h"
#include "libparams_error_codes.h"
#include "libparams/flash_driver.h"
#include "libparams/libparams_error_codes.h"

int32_t libparams_rom_error_code = 0;

Expand Down
8 changes: 4 additions & 4 deletions src/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include "storage.h"
#include "libparams/storage.h"
#include <string.h>
#include "flash_driver.h"
#include "rom.h"
#include "libparams_error_codes.h"
#include "libparams/flash_driver.h"
#include "libparams/rom.h"
#include "libparams/libparams_error_codes.h"

extern IntegerDesc_t integer_desc_pool[];
extern IntegerParamValue_t integer_values_pool[];
Expand Down
4 changes: 2 additions & 2 deletions tests/params/params.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/

#include <assert.h>
#include "storage.h"
#include "flash_driver.h"
#include "libparams/storage.h"
#include "libparams/flash_driver.h"

IntegerDesc_t integer_desc_pool[512] = {
{"uavcan.node.id", 0, 127, 50, MUTABLE},
Expand Down
2 changes: 1 addition & 1 deletion tests/params/params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include "storage.h"
#include "libparams/storage.h"
#ifndef LIBPARAM_PARAMETERS_HPP_
#define LIBPARAM_PARAMETERS_HPP_

Expand Down
2 changes: 1 addition & 1 deletion tests/params_generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set(PARAMS_PATH ${LIBPARAMS_ROOT_DIR}/build/tests/params_generator)

add_definitions(-DLIBPARAMS_PARAMS_DIR="${CMAKE_CURRENT_BINARY_DIR}")
include_directories(
${LIBPARAMS_ROOT_DIR}/include/libparams
${LIBPARAMS_ROOT_DIR}/include
${PLATFORM_SPECIFIC_PATH}
${PARAMS_PATH}
)
Expand Down
2 changes: 1 addition & 1 deletion tests/params_generator/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <iostream>
#include <vector>
#include <gtest/gtest.h>
#include "storage.h"
#include "libparams/storage.h"
#include "params.hpp"

bool strCompareSafe(const char* first, const char* second, size_t len) {
Expand Down
2 changes: 1 addition & 1 deletion tests/platform_specific/stm32f103/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ application.c

# C includes
C_INCLUDES = \
-I${ROOT_DIR}/include/libparams/ \
-I${ROOT_DIR}/include/ \
-I${ROOT_DIR}/platform_specific/stm32f103/ \
-I./ \
-I../../
Expand Down
4 changes: 2 additions & 2 deletions tests/platform_specific/stm32f103/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include "rom.h"
#include "flash_driver.h"
#include "libparams/rom.h"
#include "libparams/flash_driver.h"

void test_flash_wr() {
RomDriverInstance rom = romInit(127, 1);
Expand Down
2 changes: 1 addition & 1 deletion tests/platform_specific/stm32g0b1/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ application.c

# C includes
C_INCLUDES = \
-I${ROOT_DIR}/include/libparams/ \
-I${ROOT_DIR}/include/ \
-I${ROOT_DIR}/platform_specific/stm32g0b1/ \
-I./ \
-I../../
Expand Down
4 changes: 2 additions & 2 deletions tests/platform_specific/stm32g0b1/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include "rom.h"
#include "flash_driver.h"
#include "libparams/rom.h"
#include "libparams/flash_driver.h"

void test_flash_wr() {
RomDriverInstance rom = romInit(255, 1);
Expand Down
4 changes: 2 additions & 2 deletions tests/platform_specific/ubuntu/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/

#include <iostream>
#include "flash_driver.h"
#include "libparams_error_codes.h"
#include "libparams/flash_driver.h"
#include "libparams/libparams_error_codes.h"
#include "params.hpp"

extern StringParamValue_t string_values_pool[];
Expand Down
29 changes: 6 additions & 23 deletions tests/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,17 @@ include_directories(${GTEST_INCLUDE_DIR})

# include_directories(.)
set(LIBPARAMS_PLATFORM ubuntu)
include(${ROOT_DIR}/libparams.cmake)

set(LIBPARAMS_PARAMS_DIR="${CMAKE_CURRENT_BINARY_DIR}/params")
add_definitions(-DLIBPARAMS_PARAMS_DIR="${CMAKE_CURRENT_BINARY_DIR}/params")
set(LIBPARAMS_GENERATED_PARAMS_DIR ${TESTS_DIR}/params/)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. ${CMAKE_BINARY_DIR}/libparams)

function(gen_test app_name test_file)
execute_process(
COMMAND ${ROOT_DIR}/scripts/generate_default_params.py --out-dir ${CMAKE_CURRENT_BINARY_DIR}/params -f ${TESTS_DIR}/params/params.c
--out-file-name "init_params"
RESULT_VARIABLE ret
)
if(NOT ret EQUAL 0)
message( FATAL_ERROR "Default Params Generator has been failed. Abort.")
endif()
# Create the executable target
add_executable(${app_name}
${test_file}
${libparamsSrc})

target_include_directories(${app_name} PUBLIC ${libparamsHeaders})
${test_file}
${libparamsSrc}
)

# Conditional source file based on app_name
message(STATUS "${app_name} params dir ${UNIT_TESTS_DIR}")
target_sources(${app_name} PRIVATE ${TESTS_DIR}/params/params.c)
target_include_directories(${app_name} PRIVATE ${TESTS_DIR}/params/)

# Link libraries to the target
target_link_libraries(${app_name} gtest)
target_link_libraries(${app_name} gtest libparams::libparams)
endfunction()

gen_test(flash_driver ${UNIT_TESTS_DIR}/test_flash_driver.cpp)
Expand Down
8 changes: 4 additions & 4 deletions tests/unit_tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ coverage: create_build_dir
cd ${BUILD_DIR} && ./yaml_parameters

echo "\n1. Storage:"
cd ${BUILD_DIR} && gcov ${BUILD_DIR}/CMakeFiles/storage.dir${REPO_DIR}/src/storage.c.gcda
cd ${BUILD_DIR} && gcov ${BUILD_DIR}/libparams/CMakeFiles/libparams.dir/src/storage.c.gcda

echo "\n2. ROM:"
cd ${BUILD_DIR} && gcov ${BUILD_DIR}/CMakeFiles/rom.dir${REPO_DIR}/src/rom.c.gcda
cd ${BUILD_DIR} && gcov ${BUILD_DIR}/libparams/CMakeFiles/libparams.dir/src/rom.c.gcda

echo "\n3. Ubuntu flash driver:"
cd ${BUILD_DIR} && gcov ${BUILD_DIR}/CMakeFiles/flash_driver.dir${REPO_DIR}/platform_specific/ubuntu/flash_driver.cpp.gcda
cd ${BUILD_DIR} && gcov ${BUILD_DIR}/libparams/CMakeFiles/libparams.dir/platform_specific/ubuntu/flash_driver.cpp.gcda

echo "\n4. Yaml Parameters:"
cd ${BUILD_DIR} && gcov ${BUILD_DIR}/CMakeFiles/yaml_parameters.dir${REPO_DIR}/platform_specific/ubuntu/YamlParameters.cpp.gcda
cd ${BUILD_DIR} && gcov ${BUILD_DIR}/libparams/CMakeFiles/libparams.dir/platform_specific/ubuntu/YamlParameters.cpp.gcda

flash_driver: create_build_dir
cd ${BUILD_DIR} && cmake ${CRNT_DIR} && make && ./flash_driver
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_flash_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include <gtest/gtest.h>
#include <iostream>
#include "flash_driver.h"
#include "libparams_error_codes.h"
#include "libparams/flash_driver.h"
#include "libparams/libparams_error_codes.h"
#include "common/algorithms.hpp"

// Test Case 1. Initialize flash driver
Expand Down
Loading