embedded - Different ways of addressing pointers C/C++ -



embedded - Different ways of addressing pointers C/C++ -

i'm little confused accessing specific addresses using c style pointers.

i have 32 bit chip i'm tryin program. need flip bits or whatever in ram. next solution works fine.

uint32 strbase = 0x00168380; volatile uint32 *ram = (uint32*)0x03000000; ram[(strbase+0x48)/4] = 0x10000000; ram[(strbase+0x4c)/4] = 0x10000000; ram[(strbase+0x50)/4] = 0x10000000; ram[(strbase+0x54)/4] = 0x10000000; ram[(strbase+0x58)/4] = 0x10000000; ram[(strbase+0x5c)/4] = 0x10000000; ram += (strbase+0x60)/4;

however, i'm bit confused. tried writing few different subroutines thought equivalent didn't work. next method kinda works.

uint32 strbase = 0x00168380; volatile uint32 *ram = (uint32*)0x03000000; *(uint32*)(0x03000000 + 0x001683c8) = 0x10000000; *(uint32*)(0x03000000 + 0x001683cc) = 0x10000000; *(uint32*)(0x03000000 + 0x001683d0) = 0x10000000; *(uint32*)(0x03000000 + 0x001683d4) = 0x10000000; *(uint32*)(0x03000000 + 0x001683d8) = 0x10000000; *(uint32*)(0x03000000 + 0x001683dc) = 0x10000000; ram += (strbase+0x60)/4;

this next method doesn't work @ all.

uint32 strbase = 0x00168380; volatile uint32 *ram = (uint32*)0x03000000; ram += strbase+0x48; *ram++ = 0x10000000; *ram++ = 0x10000000; *ram++ = 0x10000000; *ram++ = 0x10000000; *ram++ = 0x10000000; *ram++ = 0x10000000;

i've been stewing on while. think might compiler doing kinda optimization. 1 of guys can explain me what's wrong or point me resources figure 1 out.

in sec solution, typedefing to

class="lang-c prettyprint-override">(uint32*)

instead of

class="lang-c prettyprint-override">(volatile uint32*)

that allows compiler optimize memory access , reorder writes. if code part of bigger routine , hardware expects write sequentially, problem.

in 3rd solution, doc brownish stated, have split 4 get:

class="lang-c prettyprint-override">ram += (strbase+0x48)/4;

note speaking, should utilize use sizeof(uint32) instead of literal constant. helps readability , c standard not provide exact sizes of integral types.

c embedded pointers

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -