Reputation: 127
I have following code :
/* Window size in bytes. */
static uint32_t size = 0;
/* Window address. */
static uint32_t address = 0;
/* Memory Base Address */
static uint8_t *sharedMemory=NULL;
sharedMemory = memalign(size, size);
void rioShardMemoryWindowGet (uint8_t *baseAddr,uint32_t *memorySize,uint32_t *windowAddress )
{
*baseAddr=(int)sharedMemory;
printf("sharedMemory: #%x",sharedMemory);
*memorySize=size;
*windowAddress=address;
}
rioShardMemoryWindowGet(&baseAddr0, &baseSize, &(Addrs.virtualBaseAddr));
printf("baseAddr0 : #%x",baseAddr0);
I have no clue why baseAddr0 is 0 in the second printf, while in the first sharedMemory is 0x500000.
Upvotes: 1
Views: 2526
Reputation: 2770
Ok I think I understand your problem.
You're trying to store the address number in baseAddr0, am I right? (not sure the reasons but this is the only thing I came up with).
The reason that a 0x500000 is showing as a 0 is because a uint8_t has not enough bits to represent an address and so it's "culling it down" to only 1 byte (therefore showing a 0).
Change the baseAddr to a uint32_t and voila, everything works.
Anyways, the reason the other posters are telling you to use a pointer to pointer is because what you seem to be doing is weird, unless you're planning on using the address for something special such as displaying it or using as an offset, perhaps?
p.s.: you're also going to need to change this line
*baseAddr=(uint32_t)sharedMemory;
edit: your code should look like this to get what you want:
/* Window size in bytes. */
static uint32_t size = 0;
/* Window address. */
static uint32_t address = 0;
/* Memory Base Address */
static uint8_t *sharedMemory=NULL;
sharedMemory = memalign(size, size);
void rioShardMemoryWindowGet (uint32_t *baseAddr,uint32_t *memorySize,uint32_t *windowAddress )
{
*baseAddr=(uint32_t)sharedMemory;
printf("sharedMemory: #%x",sharedMemory);
*memorySize=size;
*windowAddress=address;
}
rioShardMemoryWindowGet(&baseAddr0, &baseSize, &(Addrs.virtualBaseAddr));
printf("baseAddr0 : #%x",baseAddr0);
The reason why you NEED an uint32 to store the numeric address is because addresses are 32 bits, and that's the reason why you see a 0 using an 8 bit value, because 0x500000 maps to 0x00 to a byte
Upvotes: 1
Reputation: 3462
You must pass a pointer to pointer as a function argument.
Only then you will be able to store the value in it. In your case, you tried to store the address of sharedMemory
in baseAddr[0]
location.
/* Window size in bytes. */
static uint32_t size = 0;
/* Window address. */
static uint32_t address = 0;
/* Memory Base Address */
static uint8_t *sharedMemory=NULL;
sharedMemory = memalign(size, size);
void rioShardMemoryWindowGet (uint8_t **baseAddr,uint32_t *memorySize,uint32_t *windowAddress )
{
*baseAddr=sharedMemory;
printf("sharedMemory: #%x",sharedMemory);
*memorySize=size;
*windowAddress=address;
}
uint8_t *baseAddr0;
rioShardMemoryWindowGet(&baseAddr0, &baseSize, &(Addrs.virtualBaseAddr));
printf("baseAddr0 : #%x",baseAddr0);
Upvotes: 1
Reputation: 21517
rioShardMemoryWindowGet
should accept uint8_t **baseAddrPtr
if you want it to modify baseAddr0
. Then you'll have *baseAddr = sharedMemory
without a cast.
Upvotes: 1