Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating a data structure at specific memory location in c

Tags:

arrays

c

memory

I'm working on an embedded mcu that has two cores which can both see an area of memory beginning at 0x80000000.

The ADC is connected to one core and a radio is connected to another. I want to write the data value received by the ADC to this memory address so that the other core can read it.

Would somebody be able to help me figure out how to do this? The is no micro OS, it is bare metal.

Would I create a pointer to struct at a specific address?

I have two values in an array, how would I get them into the struct?

#define NUM_SAMPLES_POLLED (2)
uint16_t samples_polled[NUM_SAMPLES_POLLED]
like image 760
riverrock Avatar asked Mar 24 '26 05:03

riverrock


2 Answers

In this case you'd assign the address directly to a pointer:

char *memdata = (char *)0x80000000;

Keep in mind that this behavior is implementation defined.

like image 111
dbush Avatar answered Mar 25 '26 19:03

dbush


How can I create an array at this exact address with some values?

The C language does not define any mechanism for assigning variables to specific addresses. Indeed, no such mechanism would likely be viable in a hosted C implementation, for substantially all modern hosted implementations rely on an underlying OS with virtual memory.

Inasmuch as you are presumably writing for a freestanding implementation (given that the target is an embedded MCU), it is likely that there is a mechanism for what you ask. The one suggested by @dbush would then be a good candidate, but only by checking your documentation can you be sure.

like image 22
John Bollinger Avatar answered Mar 25 '26 20:03

John Bollinger