-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pkg/flashdb: enhance FAL config #20221
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6e1e78d
pkg/flashdb: have FAL MTD and defaults for partition 0 defined
fabian18 bd75060
pkg/flashdb: fix FAL partition offsets
fabian18 3167d58
pkg/flashdb: add configurable sector size
fabian18 057695b
tests/pkg/flashdb: add test for FAL config initialization
fabian18 b671dd4
tests/pkg/flashdb_mtd: add Makefile.ci
fabian18 bf4bfdf
tests/pkg/flashdb_fal_cfg: add Makefile.ci
fabian18 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
include ../Makefile.pkg_common | ||
|
||
# select the MTD backend | ||
USEMODULE += flashdb_mtd | ||
# enable key-value database | ||
USEMODULE += flashdb_kvdb | ||
# enable time series database | ||
USEMODULE += flashdb_tsdb | ||
# rtc_localtime() | ||
USEMODULE += rtc_utils | ||
|
||
# prefer periph_rtc over periph_rtt | ||
FEATURES_OPTIONAL += periph_rtc | ||
FEATURES_REQUIRED_ANY += periph_rtc|periph_rtt | ||
|
||
CFLAGS += -DFAL_PART1_LABEL=\"part1\" | ||
CFLAGS += -DFAL_PART1_LENGTH=FAL_PART0_LENGTH | ||
CFLAGS += -DFAL_PART2_LABEL=\"part2\" | ||
CFLAGS += -DFAL_PART2_LENGTH=FAL_PART0_LENGTH | ||
CFLAGS += -DFAL_PART3_LABEL=\"part3\" | ||
CFLAGS += -DFAL_PART3_LENGTH=FAL_PART0_LENGTH | ||
|
||
include $(RIOTBASE)/Makefile.include | ||
|
||
# handle RTC backend after inclusion of $(RIOTBASE)/Makefile.include | ||
ifeq (,$(filter periph_rtc,$(FEATURES_USED))) | ||
USEMODULE += rtt_rtc | ||
USEMODULE += ztimer_no_periph_rtt | ||
endif | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
BOARD_INSUFFICIENT_MEMORY := \ | ||
nucleo-f031k6 \ | ||
nucleo-l011k4 \ | ||
samd10-xmini \ | ||
stk3200 \ | ||
stm32f030f4-demo \ | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
* Copyright (C) 2023 ML!PA Consulting Gmbh | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser General | ||
* Public License v2.1. See the file LICENSE in the top level directory for more | ||
* details. | ||
*/ | ||
|
||
/** | ||
* @ingroup tests | ||
* @{ | ||
* | ||
* @file | ||
* @brief Short test for the FlashDB FAL configuration initialization | ||
* | ||
* @author Fabian Hüßler <fabian.huessler@ml-pa.com> | ||
* | ||
* @} | ||
*/ | ||
|
||
#include <stdio.h> | ||
|
||
#include "container.h" | ||
#include "fal.h" | ||
#include "macros/math.h" | ||
#include "mutex.h" | ||
#include "periph/rtc.h" | ||
|
||
#include <flashdb.h> | ||
|
||
/** | ||
* @brief FlashDB Magic Word | ||
* | ||
* The value here is not relevant but it must be defined. | ||
*/ | ||
#define FAL_PART_MAGIC_WORD 0x45503130 | ||
|
||
/** | ||
* @brief Number of FAL partitions | ||
*/ | ||
#define FAL_PART_TABLE_NUMOF ARRAY_SIZE(((const struct fal_partition[])FAL_PART_TABLE)) | ||
|
||
#if !defined(FAL_TSDB_MAX) || defined(DOXYGEN) | ||
/** | ||
* @brief Maximum length of a TSDB entry | ||
*/ | ||
#define FAL_TSDB_MAX 128 | ||
#endif | ||
|
||
#if !defined(FAL_PART_TABLE_KVDB) || defined(DOXYGEN) | ||
/** | ||
* @brief Indices of partitions in @ref FAL_PART_TABLE that can be initialized as a Key-Value-DB | ||
*/ | ||
#define FAL_PART_TABLE_KVDB \ | ||
{ \ | ||
0, \ | ||
1, \ | ||
} | ||
#endif | ||
|
||
#if !defined(FAL_PART_TABLE_TSDB) || defined(DOXYGEN) | ||
/** | ||
* @brief Indices of partitions in @ref FAL_PART_TABLE that can be initialized as a Time-Series-DB | ||
*/ | ||
#define FAL_PART_TABLE_TSDB \ | ||
{ \ | ||
2, \ | ||
3, \ | ||
} | ||
#endif | ||
|
||
extern void fdb_mtd_init(mtd_dev_t *mtd); | ||
|
||
static mutex_t _locker = MUTEX_INIT; | ||
static const unsigned _fdb_part_kvdb[] = FAL_PART_TABLE_KVDB; | ||
static const unsigned _fdb_part_tsdb[] = FAL_PART_TABLE_TSDB; | ||
static struct fdb_kvdb _kvdb[ARRAY_SIZE(_fdb_part_kvdb)]; | ||
static struct fdb_tsdb _tsdb[ARRAY_SIZE(_fdb_part_tsdb)]; | ||
|
||
/** | ||
* @brief Select MTD device to use for FlashDB | ||
*/ | ||
#if !defined(FDB_MTD) | ||
#define FDB_MTD FAL_MTD | ||
#endif | ||
|
||
static void _lock(fdb_db_t db) | ||
{ | ||
mutex_lock(db->user_data); | ||
} | ||
|
||
static void _unlock(fdb_db_t db) | ||
{ | ||
mutex_unlock(db->user_data); | ||
} | ||
|
||
static fdb_time_t _get_time(void) | ||
{ | ||
struct tm now; | ||
rtc_get_time(&now); | ||
return mktime(&now); | ||
} | ||
|
||
int main(void) | ||
{ | ||
int init_failed; | ||
fdb_mtd_init(FDB_MTD); | ||
size_t size = FDB_MTD->pages_per_sector * FDB_MTD->page_size; | ||
/* scale hardware sector size to minimum required virtual sector size */ | ||
size = DIV_ROUND_UP((CONFIG_FLASHDB_MIN_SECTOR_SIZE_DEFAULT_KiB * KiB(1)), size) * size; | ||
printf("Informational: Make sure the following requirements are fulfilled for a successful initialization:\n"); | ||
printf("The virtual sector size is a multiple of the physical sector size: %lu %% %lu == 0\n", | ||
(unsigned long)size, (unsigned long)FDB_MTD->pages_per_sector * FDB_MTD->page_size); | ||
printf("The maximum partition size is a multiple of the virtual sector size: %lu %% %lu == 0\n", | ||
(unsigned long)FAL_PART0_LENGTH, (unsigned long)size); | ||
|
||
for (unsigned i = 0; i < ARRAY_SIZE(_fdb_part_kvdb); i++) { | ||
unsigned part = _fdb_part_kvdb[i]; | ||
if (part >= FAL_PART_TABLE_NUMOF) { | ||
continue; | ||
} | ||
fdb_kvdb_control(&_kvdb[i], FDB_KVDB_CTRL_SET_SEC_SIZE, &size); | ||
fdb_kvdb_control(&_kvdb[i], FDB_KVDB_CTRL_SET_LOCK, (void *)(uintptr_t)_lock); | ||
fdb_kvdb_control(&_kvdb[i], FDB_KVDB_CTRL_SET_UNLOCK, (void *)(uintptr_t)_unlock); | ||
const char *spart = ((const struct fal_partition[])FAL_PART_TABLE)[part].name; | ||
printf("Initializing FlashDB KVDB partition %s\n", spart); | ||
if ((init_failed = fdb_kvdb_init(&_kvdb[i], "kvdb", spart, NULL, &_locker)) != FDB_NO_ERR) { | ||
printf("Failed to initialize FlashDB KVDB partition %s (%d)\n", spart, init_failed); | ||
return 1; | ||
} | ||
} | ||
for (unsigned i = 0; i < ARRAY_SIZE(_fdb_part_tsdb); i++) { | ||
unsigned part = _fdb_part_tsdb[i]; | ||
if (part >= FAL_PART_TABLE_NUMOF) { | ||
continue; | ||
} | ||
fdb_tsdb_control(&_tsdb[i], FDB_TSDB_CTRL_SET_LOCK, (void *)(uintptr_t)_lock); | ||
fdb_tsdb_control(&_tsdb[i], FDB_TSDB_CTRL_SET_UNLOCK, (void *)(uintptr_t)_unlock); | ||
fdb_tsdb_control(&_tsdb[i], FDB_TSDB_CTRL_SET_SEC_SIZE, &size); | ||
const char *spart = ((const struct fal_partition[])FAL_PART_TABLE)[part].name; | ||
printf("Initializing FlashDB TSDB partition %s\n", spart); | ||
if ((init_failed = fdb_tsdb_init(&_tsdb[i], "tsdb", spart, _get_time, FAL_TSDB_MAX, &_locker)) != FDB_NO_ERR) { | ||
printf("Failed to initialize FlashDB TSDB partition %s (%d)\n", spart, init_failed); | ||
return 1; | ||
} | ||
} | ||
puts("SUCCESS"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
BOARD_INSUFFICIENT_MEMORY := \ | ||
nucleo-f031k6 \ | ||
nucleo-l011k4 \ | ||
samd10-xmini \ | ||
stk3200 \ | ||
stm32f030f4-demo \ | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work? I would expect that doing this after the dependency resolution won't have any effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don´t know the magic behind it but I assume it works. When I remove
FEATURES_PROVIDED += periph_rtc
fromboards/same54-xpro/Makefile.features
and do aninfo-modules
I see thatrtt_rtc
andztimer_no_periph_rtt
are in. When I try to build after I removeUSEMODULE += rtt_rtc
linking fails, as expected.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/pkg/flashdb_fal_cfg/main.c:99: undefined reference to 'rtc_get_time'