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

ef_env.c中“set_status”这个接口内部的status_table有问题? #124

Open
zhoujie-jay opened this issue Jul 26, 2021 · 3 comments

Comments

@zhoujie-jay
Copy link

对于
...
#if (EF_WRITE_GRAN == 1)
byte_index = (status_index - 1) / 8;
status_table[byte_index] &= ~(0x80 >> ((status_index - 1) % 8));
#else
...
中的0x80,如果编译器把0x80当成unsiged char 类型的移位结果和 当成char类型的移位结果是截然不同。
所以说你想表达的结果应该是status_table[byte_index] &= ~((char)0x80 >> ((status_index - 1) % 8)); @armink

@armink
Copy link
Owner

armink commented Jul 26, 2021

或者改为 0x80UL ?

@zhoujie-jay
Copy link
Author

不能改成0x80UL的。假如使用你说的,我要将ENV_PRE_DELETE状态变成ENV_DELETED,此时代码如下: result = write_status(old_env->addr.start, status_table, ENV_STATUS_NUM, ENV_PRE_DELETE);
result = write_status(old_env->addr.start, status_table, ENV_STATUS_NUM, ENV_DELETED);
此时将ENV_PRE_DELETE写到flash中(地址:0x460d4),写入的内容是0xDF(1101 1111)。接着状态变成ENV_DELETED,此时将ENV_DELETED写入到flash中(地址:0x460d4),写入的内容是0xEF(1110 1111)。所以如果要将0x460d4地址(0xDF)的内容改写成0xEF,有可能写入不成功,即0xEF的值写入到更新到flash失败。如果是(char)0x80 就不会存在该问题。
get_status 接口中的
#if (EF_WRITE_GRAN == 1)
if ((status_table[status_num / 8] & ((char)0x80 >> (status_num % 8))) == 0x00) {
break;
}
#else /* (EF_WRITE_GRAN == 8) || (EF_WRITE_GRAN == 32) || (EF_WRITE_GRAN == 64) */
0x80,是否也要做调整?

@armink
Copy link
Owner

armink commented Jul 26, 2021

没看太懂你的解释呢

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

No branches or pull requests

2 participants