Page 1 of 1

Using volatile and the framebuffer setup

Posted: Mon Nov 05, 2012 7:46 am
by richcole
I tried using the framebuffer this weekend and seemed to get into some trouble using volatile. Here is my code: ... 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. ... armful.txt

While I'm linking. I got going with framebuffer by copying this

Re: Using volatile and the framebuffer setup

Posted: Mon Nov 05, 2012 8:05 am
by richcole
I found the answer in this forum: ... 43#p189643

There is a cache in the vidcore. Yikes, but at least the answer is simple. Add 0x40000000 to addresses that you give the vidcore and then it will skip its cache when writing to them. ... 63803a15ab