Shared memory locations

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
user_1570836
Level 4
Level 4
50 replies posted 25 replies posted 25 sign-ins

Hello,

I have a few questions about two-processor PSoCs.

If I declare a global variable in a header file inside shared-code folder, how will this be compiled?

Will this get compiled as two variables, one for each core? Or will this be compiled as a shared memory location?

If the first, how should I declare shared memory?

And the last question, how will volatile keyword behave in two-processor environment? I used to declare variable as volatile, when it may be accessed from multiple ISRs and/or non-interrupt code. Does this mean that all shared memory should be volatile?

Stanislav

1 Solution

Hello Stanislav,

The draft application note in another thread addresses the shared memory issue. There is an associated code example which I will also publish. Please let me know if these address your needs.

Regards,

Mark Ainsworth

View solution in original post

3 Replies
srnu_276571
Level 5
Level 5
25 replies posted 10 replies posted 5 replies posted

Hello,

A global variable defined in shared-code folder will be compiled as two variables, one for each core. One way you could declare shared memory between two cores is to use pointers and point to a known fixed memory location or region. However it is recommended that you use IPC to implement semaphores/mutexes when sharing resources (including memory) between CPU cores. Please see section 4.1 of this document to get more insight:AN_PSoC6_Dual-Core_Draft.pdf

It is always advisable to use the volatile keyword if you expect the variable content to change outside of the current code context. This will ensure that compiler optimizations are not applied on the said variable. To answer your question about all shared memory being volatile, the answer is a partial yes. It all depends on how you define and use the shared memory: say with the use of pointers, you need not use the volatile keyword.

Cheers.

Well, I can allocate a few bytes of memory dynamically. However I'll still need to pass the pointer to the other core...how would you do this?

And for semaphores/mutexes, I understand that I need to synchronize access to shared variables. However I have no idea how. Could you tell more about this, and how it is implemented in PSoC6 ?

0 Likes

Hello Stanislav,

The draft application note in another thread addresses the shared memory issue. There is an associated code example which I will also publish. Please let me know if these address your needs.

Regards,

Mark Ainsworth