semaphore

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

semaphore

Jump to solution
764 Views
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

Labels (1)
0 Kudos
1 Solution
505 Views
kef2
Senior Contributor IV
  • 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

View solution in original post

0 Kudos
3 Replies
506 Views
kef2
Senior Contributor IV
  • 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 Kudos
505 Views
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 Kudos
505 Views
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 Kudos