MPC5775k Core 2 (z7 core2) can not get semaphore

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

MPC5775k Core 2 (z7 core2) can not get semaphore

跳至解决方案
2,443 次查看
zhangsan123
Contributor I

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!

标签 (1)
0 项奖励
回复
1 解答
2,058 次查看
martin_kovar
NXP Employee
NXP Employee

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:

  • Core0 has master ID 0, so the value 1 should be used to lock from core0. This agrees with (processor_number + 1)
  • Core1 has master ID 1, so the value 2 is used. This also agrees with (processor_number + 1)
  • Core2 has master ID 7, so the value 8 must be used to lock the gate. This does not agree with (processor_number + 1)

So you have to do some modifications in your code:

 

  1. #define CORE2_LOCK needs to be changed to 8
  2. GetCoreID() will return 2 when executed on core2/z7b so it can't be used directly. Code has to check return value of GetCoreID() in Lock_Gate() and if it is equal to 2, the SEMA42 register should be written with 8. The register cannot be written with anything apart from 8 from software executed on core2.

I have tested the case and now it works correct.

Regards,

Martin

在原帖中查看解决方案

0 项奖励
回复
8 回复数
2,058 次查看
zhangsan123
Contributor I

It work well now. thanks. Martin!

0 项奖励
回复
2,058 次查看
zhangsan123
Contributor I

thanks, Martin!

0 项奖励
回复
2,059 次查看
martin_kovar
NXP Employee
NXP Employee

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:

  • Core0 has master ID 0, so the value 1 should be used to lock from core0. This agrees with (processor_number + 1)
  • Core1 has master ID 1, so the value 2 is used. This also agrees with (processor_number + 1)
  • Core2 has master ID 7, so the value 8 must be used to lock the gate. This does not agree with (processor_number + 1)

So you have to do some modifications in your code:

 

  1. #define CORE2_LOCK needs to be changed to 8
  2. GetCoreID() will return 2 when executed on core2/z7b so it can't be used directly. Code has to check return value of GetCoreID() in Lock_Gate() and if it is equal to 2, the SEMA42 register should be written with 8. The register cannot be written with anything apart from 8 from software executed on core2.

I have tested the case and now it works correct.

Regards,

Martin

0 项奖励
回复
2,058 次查看
zhangsan123
Contributor I

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.

semaphore_core2.PNG

0 项奖励
回复
2,058 次查看
martin_kovar
NXP Employee
NXP Employee

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

0 项奖励
回复
2,058 次查看
zhangsan123
Contributor I

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.

0 项奖励
回复
2,058 次查看
martin_kovar
NXP Employee
NXP Employee

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

0 项奖励
回复
2,058 次查看
martin_kovar
NXP Employee
NXP Employee

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

0 项奖励
回复