gpt4 book ai didi

c++ - 在 C++ 中检查地址的可变值

转载 作者:行者123 更新时间:2023-11-30 01:17:51 24 4
gpt4 key购买 nike

我正在尝试为 Raspberry Pi 实现邮箱写入。根据我找到的信息,当邮箱为空时,我可以写入地址0x2000B8A0,这意味着0x2000B898没有设置最后一位。我是这样写的:

uint32_t *mailbox = reinterpret_cast<uint32_t*>(0x2000B880);

while((mailbox[6] & 0x80000000) != 0);

mailbox[8] = value + channel;

但是反汇编显示 mailbox[6] 的值只加载一次,在循环之前,然后它只是用那个值重复检查。

我找不到解决方案,因为我什至不知道这个问题的正确词语。我敢肯定这很简单,但谷歌搜索对这种特殊情况没有任何帮助。

最佳答案

答案就在你的问题标题中。您应该使用以下内容:

volatile uint32_t *mailbox = const_cast<volatile uint32_t *>(reinterpret_cast<uint32_t*>(0x2000B880));

这将确保每次在循环中加载该值。如果您看到任何应用程序没有响应,请考虑在 while 中添加一些sleepdelayyield

关于c++ - 在 C++ 中检查地址的可变值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23491306/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com