On 9/12/07, Stephen Queen <> wrote:
On 9/12/07, Yan Seiner <> wrote:
OK, great gurus of C programming....
I'm stumped, and I know it's something obvious.
I'm in the midst of some code cleanup. I had a pile of (unsigned int)
addressing 16 bit registers, so I changed everything over to uint16_t.
Here's the basic snippet of code from one of the aflicted registers:
#define QDDR (0x040c / sizeof(uint16_t))
#define TS733BASE 0x72000000
static uint16_t *qddr;
static uint16_t *ts733gpio;
ts733gpio = (uint16_t *)mmap(0, getpagesize(),
PROT_READ|PROT_WRITE, MAP_SHARED, fd, TS733BASE);
qddr = (ts733gpio + QDDR);
Now I print qddr:
printf("qddr: 0x%x 0x%x 0x%x 0x%x\n",*qddr,*((uint32_t
*)qddr),*(qddr+1), *((uint32_t *)(qddr+1)));
and I get:
qddr: 0x8cb3 0xff0009b3 0x8c00 0x9b3ff00
qddr: 0x8c6d 0xff000a6d 0x8c00 0xa6dff00
qddr: 0x8c92 0xff000b92 0x8c00 0xb92ff00
qddr: 0x8c3c 0xff000c3c 0x8c00 0xc3cff00
qddr: 0x8c59 0xff000d59 0x8c00 0xd59ff00
qddr: 0x8c4c 0xff000e4c 0x8c00 0xe4cff00
qddr: 0x8c22 0xff000f22 0x8c00 0xf22ff00
qddr: 0x8c7d 0xff000e7d 0x8c00 0xe7dff00
qddr: 0x8c3e 0xff000f3e 0x8c00 0xf3eff00
qddr: 0x8ce9 0xff000fe9 0x8c00 0xfe9ff00
qddr: 0x8c80 0xff001080 0x8c00 0x1080ff00
I get the values I would expect when I cast everything to uint32_t but
uint16_t types *always* start with 0x8c. What's even more bizarre is
that *all* (uint16_t *) pointers return 0x8c.. The real register
values are the 4 changing hex digits above....
Can anyone shed any light on this?
What is going on? Can anyone explain this? My snippet contains *all*
of the code dealing with qddr....
Scratching my head....
--Yan
Maybe I'm missing something here.
It looks like to me, the way you have things cast, that *qddr will give you the 16 bit contents of the object pointed to by qaddr, while *((uint32_t *)(qddr))
will cast qadd to 32 bits and then give you the 16 bit contents of the object pointed to by the 32 bit pointer. Do you mean (uint32_t)(*qddr) ????
Stephen Queen
Never mind, a little bit slow today. Stephen Queen
__._,_.___
__,_._,___
|