I tried using the framebuffer this weekend and seemed to get into some trouble using volatile. Here is my code:
https://github.com/richcole/RaspberryPi ... framebuf.c
I thought I could get away with declaring structures volatile and that gcc would do the right thing ensuring that full reads from memory were taking place rather than from registers. I also presumed things would work with respect to any caches between the processor and main memory.
My program works with optimizations turned off. But if I compile with -O or -O2 then my program doesn't work. The framebuf_info->ptr never gets initialized whether I loop waiting for it. It also doesn't work if I loop sending messages to the vidcore to setup the frame buffer.
Is there a canonical way to deal with this message box thing and memory shared with the vidcore? Is volatile not to be trusted? I noted a linux article that says you can't trust volatile on all architectures and so it shouldn't be used the linux kernel.
http://www.mjmwired.net/kernel/Document ... armful.txt
While I'm linking. I got going with framebuffer by copying this