3 Replies Latest reply on Mar 27, 2017 5:24 PM by mkea

    Shared memory locations

    maskrtnik01_1570836

      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. Re: Shared memory locations
          snvn

          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:PSoC® 6 Dual-Core CPU System Design

           

          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.

          2 of 2 people found this helpful
          • 2. Re: Shared memory locations
            maskrtnik01_1570836

            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 ?

            • 3. Re: Shared memory locations
              mkea

              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

              1 of 1 people found this helpful