Hi Ron,
the general (simplified) principle of using semaphores is following:
You have two cores, one shared resource (for example memory) and one gate, which protects the shared resource. If any core wants to access to the shared resource, it has to check, of the gate is unlocked. If yes, core locks the gate and uses the shared resource (this is called critical section). After core leaves critical section (does not want to work shared resource anymore), core has to unlock the gate (because of deadlock) and any other core can use it now.
If the gate is locked, core has to wait, until other core unlock it. Gate can be unlock only by the the core which locked it.
And lets look at the example.
1)what do you mean about status? which core?
Status variable determines the status of the GATE (only gate 0 is used for both cores). If gate is unlock, core can lock it and execute it's critical section (access to shared resource).
2) status = Get_Gate_Status(GATE0 or GATE1)?
In this example only one gate is used, because there is only one shared resource. So the answer is GATE0. This is also answer for your next question.
3) Read shared memory here?
Yes, after you lock the gate, you are in the critical section and you can use (read/write) shared resource. Just realize, which operations are mutual.
read/read - not mutual...more cores can access shared resource
write/read - mutual exclusion
write/write - mutual exclusion
About the use case you describe I do not understand much, but I suppose you have some array called CanCMD[8]. If you want to write to this array, core0 should lock the gate0 and write to the array, then unlock the gate. Core1 has to wait, until gate0 is unlocked. Then core1 locks the gate, reads data from array and unlocks the gate.
Check in the debugger, if memcpy function copies correct data to the correct address and also if pcmd points to correct address.
Regards,
Martin