diff --git a/examples/platforms/utils/Makefile.am b/examples/platforms/utils/Makefile.am index a073d185d..aa29b83e2 100644 --- a/examples/platforms/utils/Makefile.am +++ b/examples/platforms/utils/Makefile.am @@ -45,6 +45,7 @@ libopenthread_platform_utils_a_SOURCES = \ logging_rtt.h \ mac_frame.cpp \ mac_frame.h \ + settings.h \ settings_ram.c \ settings_flash.c \ soft_source_match_table.c \ diff --git a/examples/platforms/utils/settings.h b/examples/platforms/utils/settings.h new file mode 100644 index 000000000..6cae2bec7 --- /dev/null +++ b/examples/platforms/utils/settings.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2016-2020, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * This file defines the configuration options for platform abstraction of non-volatile storage of settings. + * + */ + +#ifndef UTILS_SETTINGS_H_ +#define UTILS_SETTINGS_H_ + +#include + +/** + * @def SETTINGS_CONFIG_BASE_ADDRESS + * + * The base address of settings. + * + */ +#ifndef SETTINGS_CONFIG_BASE_ADDRESS +#define SETTINGS_CONFIG_BASE_ADDRESS 0x39000 +#endif + +/** + * @def SETTINGS_CONFIG_PAGE_SIZE + * + * The page size of settings. + * + */ +#ifndef SETTINGS_CONFIG_PAGE_SIZE +#define SETTINGS_CONFIG_PAGE_SIZE 0x800 +#endif + +/** + * @def SETTINGS_CONFIG_PAGE_NUM + * + * The page number of settings. + * + */ +#ifndef SETTINGS_CONFIG_PAGE_NUM +#define SETTINGS_CONFIG_PAGE_NUM 2 +#endif + +/** + * @def OPENTHREAD_SETTINGS_RAM + * + * Define as 1 to enable saving the settings in RAM instead of flash. + * + */ +#ifndef OPENTHREAD_SETTINGS_RAM +#define OPENTHREAD_SETTINGS_RAM 0 +#endif + +#endif // UTILS_SETTINGS_H_ diff --git a/examples/platforms/utils/settings_flash.c b/examples/platforms/utils/settings_flash.c index 47c06e5e8..b3a41a8f0 100644 --- a/examples/platforms/utils/settings_flash.c +++ b/examples/platforms/utils/settings_flash.c @@ -32,12 +32,12 @@ * */ +#include "settings.h" + #include #include #include -#include - #include #include @@ -67,36 +67,6 @@ struct settingsBlock uint16_t reserved; } OT_TOOL_PACKED_END; -/** - * @def SETTINGS_CONFIG_BASE_ADDRESS - * - * The base address of settings. - * - */ -#ifndef SETTINGS_CONFIG_BASE_ADDRESS -#define SETTINGS_CONFIG_BASE_ADDRESS 0x39000 -#endif // SETTINGS_CONFIG_BASE_ADDRESS - -/** - * @def SETTINGS_CONFIG_PAGE_SIZE - * - * The page size of settings. - * - */ -#ifndef SETTINGS_CONFIG_PAGE_SIZE -#define SETTINGS_CONFIG_PAGE_SIZE 0x800 -#endif // SETTINGS_CONFIG_PAGE_SIZE - -/** - * @def SETTINGS_CONFIG_PAGE_NUM - * - * The page number of settings. - * - */ -#ifndef SETTINGS_CONFIG_PAGE_NUM -#define SETTINGS_CONFIG_PAGE_NUM 2 -#endif // SETTINGS_CONFIG_PAGE_NUM - #if (SETTINGS_CONFIG_PAGE_NUM <= 1) #error "Invalid value for `SETTINGS_CONFIG_PAGE_NUM` (should be >= 2)" #endif diff --git a/examples/platforms/utils/settings_ram.c b/examples/platforms/utils/settings_ram.c index e474414e8..4ac9e2cd3 100644 --- a/examples/platforms/utils/settings_ram.c +++ b/examples/platforms/utils/settings_ram.c @@ -32,7 +32,7 @@ * */ -#include +#include "settings.h" #include #include