semaphore

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

semaphore

跳至解决方案
1,096 次查看
steph
Contributor I

hello,

i'm using HCS12X with Xgate .

first, i use hc12 core for my main program and xgate core for have SCI communication.

for the semaphore, in my main program :

do{XGSEM=0x0101;}while(!XGSEM);

....

XGSEM=0x0100;

and in the Xgate program i use :

while(!_ssem(0)){}

...

_csem(0);

this program work fine

now, i want to add an I2C function in Xgate core, so in my main program i try to use a 2nd semaphore :

do{XGSEM=0x0202;}while(!XGSEM);

....

XGSEM=0x0200;

and in the Xgate program i use :

while(!_ssem(1)){}

...

_csem(1);

this program work fine

i must have a problem, the 2 communication work fine while 5 or 10 minut but stop after this time.

someone can say me if this declaration of semaphore is correct ?

thanks

Stéphane

标签 (1)
0 项奖励
回复
1 解答
837 次查看
kef2
Senior Contributor V
  • do{XGSEM=0x0101;}while(!XGSEM);

Waiting for any bit set in XGSEM is OK while one semaphore is used in your app. Using more semaphores, you need wait for specific bit in XGSEM. Like this

  • do{XGSEM=0x0101;}while( !(XGSEM & 0x0001));

or better something like this

#define SCISEMAPHORENO 0

#define I2CSEMAPHORENO 1

do{XGSEM=(0x0101 << SCISEMAPHORENO) ;}while( !(XGSEM & (0x0001 << SCISEMAPHORENO)));

..

XGSEM= 0x0100 << SCISEMAPHORENO;

do{XGSEM=(0x0101 << I2CSEMAPHORENO) ;}while( !(XGSEM & (0x0001 << I2CSCISEMAPHORENO)));

..

XGSEM= 0x0100 << I2CSEMAPHORENO;

(This is S12X specific question. I think you would be better asking here https://community.freescale.com/community/16bit)

Regards

Edward

在原帖中查看解决方案

0 项奖励
回复
3 回复数
838 次查看
kef2
Senior Contributor V
  • do{XGSEM=0x0101;}while(!XGSEM);

Waiting for any bit set in XGSEM is OK while one semaphore is used in your app. Using more semaphores, you need wait for specific bit in XGSEM. Like this

  • do{XGSEM=0x0101;}while( !(XGSEM & 0x0001));

or better something like this

#define SCISEMAPHORENO 0

#define I2CSEMAPHORENO 1

do{XGSEM=(0x0101 << SCISEMAPHORENO) ;}while( !(XGSEM & (0x0001 << SCISEMAPHORENO)));

..

XGSEM= 0x0100 << SCISEMAPHORENO;

do{XGSEM=(0x0101 << I2CSEMAPHORENO) ;}while( !(XGSEM & (0x0001 << I2CSCISEMAPHORENO)));

..

XGSEM= 0x0100 << I2CSEMAPHORENO;

(This is S12X specific question. I think you would be better asking here https://community.freescale.com/community/16bit)

Regards

Edward

0 项奖励
回复
837 次查看
steph
Contributor I

OK, thank you for the information and the maniere of proceder by renaming(reappointing) semaphores. Now I have find my error, I had forgotten a variable which had no semaphore. The question that I settled was is that I used well the good syntax:
XGSEM = 0x0101 for SSEM ( 0 ) and XGSM = 0x0202 for SSEM ( 1 )

0 项奖励
回复
837 次查看
trytohelp
NXP Employee
NXP Employee

Hi Stéphane,

Just to have more info regarding the tool used.

Do you use CodeWarrior for HC12 V5.1 ?

    or an older version ? which one ?

To do that you must:

  Under CodeWarrior IDE (classic)

                Start the IDE and click on Help | About Freescale CodeWarrior.

                Click on Installed Products

                Provide us all info displayed.

                Or you can save them in a txt file.

Do you use Osek or Autosar ?


Have a great day,
Pascal
Freescale Technical Support
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复