Skip to content
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

[inc/fdb_low_lvl] fix An error occurred in FDB_ALIGN(size, align) #233

Merged
merged 1 commit into from
Aug 17, 2023

Conversation

DarryZh
Copy link
Contributor

@DarryZh DarryZh commented Aug 17, 2023

An error occurred in FDB_ALIGN(size, align) when align is not 2 to the nth power.

The following is the minimal unit test code for the new implementation:

#include <stdio.h>
#define FDB_ALIGN(size, align)                      ((size + align -1) - ((size + align -1) % align))
void main(void)
{
    printf("FDB_ALIGN(0, 8) : %d\n", FDB_ALIGN(0, 8));
    printf("FDB_ALIGN(0, 10) : %d\n", FDB_ALIGN(0, 10));
    printf("FDB_ALIGN(10, 10) : %d\n", FDB_ALIGN(10, 10));
    printf("FDB_ALIGN(10, 20) : %d\n", FDB_ALIGN(10, 20));
    printf("FDB_ALIGN(20, 20) : %d\n", FDB_ALIGN(20, 20));
    printf("FDB_ALIGN(20, 10) : %d\n", FDB_ALIGN(20, 10));
    printf("FDB_ALIGN(10, 8) : %d\n", FDB_ALIGN(10, 8));
    printf("FDB_ALIGN(10, 7) : %d\n", FDB_ALIGN(10, 7));
    printf("FDB_ALIGN(7, 10) : %d\n", FDB_ALIGN(7, 10));
    printf("FDB_ALIGN(7, 20) : %d\n", FDB_ALIGN(7, 20));
    printf("FDB_ALIGN(32, 16) : %d\n", FDB_ALIGN(32, 16));
    printf("FDB_ALIGN(100, 16) : %d\n", FDB_ALIGN(100, 16));
    printf("FDB_ALIGN(100, 17) : %d\n", FDB_ALIGN(100, 17));
}

The following is the test results:

FDB_ALIGN(0, 8) : 0
FDB_ALIGN(0, 10) : 0
FDB_ALIGN(10, 10) : 10
FDB_ALIGN(10, 20) : 20
FDB_ALIGN(20, 20) : 20
FDB_ALIGN(20, 10) : 20
FDB_ALIGN(10, 8) : 16
FDB_ALIGN(10, 7) : 14
FDB_ALIGN(7, 10) : 10
FDB_ALIGN(7, 20) : 20
FDB_ALIGN(32, 16) : 32
FDB_ALIGN(100, 16) : 112
FDB_ALIGN(100, 17) : 102

@armink
Copy link
Owner

armink commented Aug 17, 2023

非常感谢的你的贡献,很不错的一个算法,666666

@armink
Copy link
Owner

armink commented Aug 17, 2023

也欢迎去给 RT-Thread 提交一个 PR 哈,我是从这里 copy 的 :>

https://github.com/RT-Thread/rt-thread/blob/master/include/rtdef.h#L425

image

@armink armink merged commit 3e441f6 into armink:master Aug 17, 2023
1 check passed
@DarryZh
Copy link
Contributor Author

DarryZh commented Aug 17, 2023

有看到的,本来想参考一下rtthread,结果发现了FDB def的出处(狗头)

@hsSam
Copy link

hsSam commented Sep 18, 2023

这个更新后我原来正常使用的程序初始化后,读取数据报错了。

�[32;22m[I/FAL] Flash Abstraction Layer (V0.5.99) initialize success.�[0m
[FlashDB] FlashDB V2.0.0 is initialize success.
[FlashDB] You can get the latest version on https://github.com/armink/FlashDB .
fdb_kvdb_init: 0
[FlashDB][kv][env][kvdb] Error: The KV (@0x00000014) CRC32 check failed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants