In article <13*************@corp.supernews.com>,
CptDondo <ya*@NsOeSiPnAeMr.comwrote:
>I'm trying to write what should be a simple program, and it keeps
hanging if I use volatile....
>The program, stripped of its error checking, is this:
unsigned short * start;
unsigned short * ctl;
> int fd = open("/dev/mem", O_RDWR);
open() is not part of the C language; it is an OS extension.
> start = mmap(0, getpagesize()*2, PROT_READ|PROT_WRITE, MAP_SHARED, fd,
0x72000000);
mmap() is not part of the C language; it is an OS extension.
> ctl = (volatile unsigned short *)(start + 0x0410);
Note that start + 0x0410 means the address of the 0x0410'th
unsigned short past start, not the address of the unsigned
short 0x0410 bytes after short. If you intend a byte offset
rather than a short offset, then you will need to cast start
to be a character pointer before doing the pointer arithmetic.
> printf("got my pointer %p\n",ctl);
sleep(1);
printf("got ctl reg: 0x%02x\n",*ctl);
>The program hangs as soon as it hits the last printf - it prints the
"got my pointer" message but hard-locks before printing the "got ctl
reg" message.
>Before I start digging into various other issues, is this a proper use
of volatile?
In itself, it looks okay, but the pointer arithmetic is questionable.
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton