Question

I'm trying to implement a mailbox write for the Raspberry Pi. According to the info I found, I can write to address 0x2000B8A0 when mailbox is empty, meaning 0x2000B898 has not the last bit set. I wrote it like this:

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

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

mailbox[8] = value + channel;

But the disassembly shows that the value at mailbox[6] is only loaded once, before the loop, then it just repeats the check with that one value.

I could not find a solution because I don't even know the proper words for this problem. I'm sure it's simple but googling brought nothing for this special case.

Was it helpful?

Solution

Answer lies in title of your question. You should use the following:

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

This will make sure the value is loaded each time in your loop. If you see any application not responding, consider adding some sleep or delay or yield in while.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top