简体   繁体   中英

Assigning specific starting address to 2D array in C

I'm writing a program for a microcontroller system which has an external source writing a 2D array of samples to a configurable region in the data cache. For larger batches this naturally uses a higher percentage of the memory, and I've noticed that the program overwrites addresses already written to by the peripheral source for loop variables, interrupt context saving etc.

The starting address is externally configurable, as well as the dimensions of the array. I'm looking to block the program from using the portion used in the memory.

So far I have:

volatile float* samples_ptr = (float *)(base_address);

Is there any way of assigning this volatile variable as an array while keeping the starting address?

I don't know if C can do this, but if you want reserve an area of the memory for the peripheral to write in, and if the address and the size are known before compiling, you might consider edit your linker script and set this memory location to something like .rodata (ie read only data).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM