LPC5410x Shared Variables

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC5410x Shared Variables

1,070 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ans.gomez on Sun Nov 22 13:05:22 MST 2015
I am looking at the sample multicore blinky project. There is a sharedLEDStates variable declared in both the M0 and M0 main files. The mailbox IPC is used to send the content of the M4 variable and copy it to the M0 variable. This is not what I have in mind when I think of shared variables.

Is there any way to actually have just one variable. For the M0 projects, can I declare the sharedLEDstates in a separate .c file, have an extern declaration in a .h, and be access those variable in the M4 project?

I want to declare global variables which can be accessed by both cores. Clearly, I need to be careful with semaphores and all that, but how can I get this to work?

Thanks

Andres
Labels (1)
0 Kudos
Reply
3 Replies

1,016 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by starblue on Mon Nov 23 05:55:44 MST 2015
Yes, it is a bit hackish, but it is simple and easy to understand, and guaranteed to work. The places where these variables are used stick out in the code, which is good.

I don't use it for all global variables, only a few variables that need to be shared among cores. And there are substructures for the different modules, so each variable is local to a module.

Convincing the linker to do the same is somewhat harder and more dangerous IMHO. Write a .c file with the definitions for the shared variables and put it in a separate section that is linked at a fixed address. Best would be to compile it only once, and link the .o file twice, but that might not be so easy to set up.
0 Kudos
Reply

1,016 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ans.gomez on Mon Nov 23 05:24:29 MST 2015
Thanks for your reply startblue.

I did in fact consider that. The only issue is that I am porting some legacy code, and I have many variables split among different .c files. I want to avoid re-writing this code at all costs. It seems to me like there should be some way. Maybe with external references to other projects. Fixing manual memory locations seems rather hackish.

Thanks!
0 Kudos
Reply

1,016 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by starblue on Mon Nov 23 04:36:22 MST 2015
I use a fixed pointer (specified by address) to a structure that contains global variables, on an LPC4357.
0 Kudos
Reply