Hello,
Base on the example "Example_MPC5775K-Semaphores-S32DS.zip", I create a project for all three cores. When I test the semaphore, I find core 2(z7 core2) can not lock the semaphore, as the following:
#define UNLOCK 0
#define CORE2_LOCK 3
#define GATE_0 0
/*when the Gate is not lock*/
while(status != CORE2_LOCK)
{
/*Lock the gate*/
status = Lock_Gate(GATE_0); //always in this loop, can not go through! Already make sure other cores/tasks will not take any semaphores.
}
/*Execute critical section*/
px1->myint = 20;
while(status == CORE2_LOCK)
{
/*Unlock the gate*/
status = Unlock_Gate(GATE_0);
}
/*End of the critical section*/
The value of GetCoreID() is 2, as expected. And core0 and core1 can get and release semaphore as expected. thanks!
Solved! Go to Solution.
Hi,
this is the answer from our application engineer.
The SEMA42 module uses the logical bus master ID and not the core ID, so attempts to lock a gate from a particular core must use the correct bus master ID. The SEMA42 chapter confuses by stating that the lock value is (processor_number + 1), but this is not strictly true:
So you have to do some modifications in your code:
I have tested the case and now it works correct.
Regards,
Martin
It work well now. thanks. Martin!
thanks, Martin!
Hi,
this is the answer from our application engineer.
The SEMA42 module uses the logical bus master ID and not the core ID, so attempts to lock a gate from a particular core must use the correct bus master ID. The SEMA42 chapter confuses by stating that the lock value is (processor_number + 1), but this is not strictly true:
So you have to do some modifications in your code:
I have tested the case and now it works correct.
Regards,
Martin
Hi Martin,
Attached is the project and the debug snapshot. I set breakpoints and stop after HW_Init for core0, and stop at main for core1; I only step over for core2. From the debug window, it can see that the status of Get_Gate_status(GATE0) is 0 and Process ID is 2. But the following while loop which try to get the semaphore can not go through. Could you please give me the project which use semaphore for core2? so that I can try at my side. thanks.
Hi,
I tested your code and I also tested the use case just using Lauterbach debugger and I am not able to lock any gate with z7b core. So I contacted our application team to investigate the issue.
I will try to keep you inform as soon as I have some new information.
Regards,
Martin
Hi Martin,
Thanks for your response. The return value of GetCoreID() is 2 and function Lock_Gate is exactly what you wrote above. The return value of Lock_Gate is always 0. I verify this on NXP evaluation board.
Hi,
at first, please check the gate status in debugger. Gate has to be unlock. After you lock the gate, check, which core locked the gate. Function Get_Gate_status always returns ID of the core, which locked the gate. So it is not possible to get stuck in endless loop, if for example core 2 locks unlocked gate.
It is little bit complicated to clear explanation and understanding, so if it is possible, please share your project and I will check the problem.
Regards,
Martin
Hi,
in your case, function Lock_Gate(GATE_0) has to return number 3. Check what number this function returns. Function Lock_Gate should looks like this:
static uint8_t Lock_Gate(uint8_t gate_no)
{
SEMA42.GATE[gate_no].R = GetCoreID()+1;
return Get_Gate_status(gate_no);
}
Do not forget to add number 1 to GetCoreID() result. On the first sight it looks like you do not add 1 to the result.
Regards,
Martin