How to use it?

R

rsk

Hi Friends,

I have defined a variable in file1.h as

#define BASE (0x00800000) // address of BASE

and i defined a pointer to the same variable in file2.h as

#define ibuf_base_ptr ((volatile uint *)IBUF_BASE)

Now my requirement is to change the following statements by using the
ibuf_base_ptr which i defined in file2.h

*((volatile uint *) 0x00850000) = 0x000a0041;
*((volatile uint *) 0x00850004) = 0x00870000;

can i do like this

*((volatile uint *)(*ibuf_base_ptr+0x50000)) = 0x000a0041;

*((volatile uint *)(*ibuf_base_ptr+0x50004)) = (*ibuf_base_ptr+70000);


Please help me .


With Regards,
ss
 
R

Richard Tobin

rsk said:
#define ibuf_base_ptr ((volatile uint *)IBUF_BASE)

Now my requirement is to change the following statements by using the
ibuf_base_ptr which i defined in file2.h

*((volatile uint *) 0x00850000) = 0x000a0041;
*((volatile uint *) 0x00850004) = 0x00870000;

can i do like this

*((volatile uint *)(*ibuf_base_ptr+0x50000)) = 0x000a0041;

*((volatile uint *)(*ibuf_base_ptr+0x50004)) = (*ibuf_base_ptr+70000);

There are a couple of problems here. First, you don't want the stars
before ibuf_base_ptr - that would take the value pointed to by
ibuf_base_ptr and add 0x50000 to it, and you just want to add 0x50000
to ibuf_base_ptr itself.

Second, because you have defined ibuf_base_ptr to be of type volatile uint *,
the addition will be done in units of sizeof(uint), not bytes. So you are
adding 0x50000 * sizeof(uint) instead of 0x50000. To declare a generic
byte pointer, use unsigned char:

#define ibuf_base_ptr ((volatile unsigned char *)IBUF_BASE)
or
volatile unsigned char *ibuf_base_ptr = IBUF_BASE;

Or if you're always going to cast it before using it, there's no need
to make it a pointer at all - just define it to be 0x00800000.

-- Richard
 
R

r6144

Now my requirement is to change the following statements by using the
ibuf_base_ptr which i defined in file2.h

*((volatile uint *) 0x00850000) = 0x000a0041;
*((volatile uint *) 0x00850004) = 0x00870000;

can i do like this

*((volatile uint *)(*ibuf_base_ptr+0x50000)) = 0x000a0041;

*((volatile uint *)(*ibuf_base_ptr+0x50004)) = (*ibuf_base_ptr+70000);

That depends on your intent. How should the numbers 0x00850000,
0x000a0041, etc. (conceivably) change if BASE (IBUF_BASE) were some
other address?
 
F

Francois Grieu

"rsk said:
I have defined a variable in file1.h as

#define BASE (0x00800000) // address of BASE

and i defined a pointer to the same variable in file2.h as

#define ibuf_base_ptr ((volatile uint *)IBUF_BASE)

Now my requirement is to change the following statements by using the
ibuf_base_ptr which i defined in file2.h

*((volatile uint *) 0x00850000) = 0x000a0041;
*((volatile uint *) 0x00850004) = 0x00870000;

can i do like this

*((volatile uint *)(*ibuf_base_ptr+0x50000)) = 0x000a0041;
*((volatile uint *)(*ibuf_base_ptr+0x50004)) = (*ibuf_base_ptr+70000);

You can do SOMETHING LIKE this, but not THIS terrible mess.
Find out what the above two instructions perform.
After this, this (homework?) will be easy.

Hint 1: think of *((volatile uint *)IBUF_BASE) as
"value returned by reading one uint from address IBUF_BASE",
for some signification of "reading one uint from address",
which on a simple 32-bit system might be just "applying
the value IBUF_BASE on the address bus, making a pulse on
the read signal, sampling the value on the data bus at
the end of the read signal".

Hint 2: after you get * in the right places, check
the C rules regarding addition involving a pointer.


Francois Grieu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,294
Messages
2,571,511
Members
48,201
Latest member
JefferyBur

Latest Threads

Top