Pumpkin, Inc.

Pumpkin User Forums

How to ensure that BinSem is reset before OS_WaitBinSem

If you can't make Salvo do what you want it to do, post it here.

How to ensure that BinSem is reset before OS_WaitBinSem

Postby aek » Tue Dec 26, 2000 2:56 am

use OSCreateBinSem()
-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: How to ensure that BinSem is reset before OS_WaitBinSem

Postby luben » Tue Dec 26, 2000 9:45 am

Hello,

Do you mean that I can use OSCreateBinSem() several times for ane and the same event? If yes, it's equal to OSResetBinSem() or OSSetBinSem(), when used after the first time and this can solve many potential problems.

Regards
Luben

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria

Re: How to ensure that BinSem is reset before OS_WaitBinSem

Postby aek » Tue Dec 26, 2000 11:07 am

yes, just use
code:
OSCreateBinSem(SEM_ID, 0);

to reset the binsem, and
code:
OSCreateBinSem(SEM_ID, 1);

to set the binsem.

In each case, the call to OSCreateBinSem() will create a semaphore without any tasks waiting for it -- therefore you must be sure that no task is waiting the semaphore when you so this.

Note that OSCreateXyz(), OSSignalXyz(), OS_WaitXyz() (and OSRtnXyz(), coming soon) are the user services we supply for each event type. If you need something else with different functionality, you can always create it by looking at the source code for these functions.

[This message has been edited by aek (edited December 26, 2000).]

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: How to ensure that BinSem is reset before OS_WaitBinSem

Postby luben » Tue Dec 26, 2000 12:00 pm

Hello,

After I played some time with one project with 2 tasks and 2 binsemaphores I got the following things that are not very good made in Salvo (or I don't know how to make them with the current set of Salvo's commands ellegantly):

In my project I used a flag that is set in the main loop (before scheduler) and is checked in one of tasks. Before checking the flag I had to ensure that there is no events, flagged before. It's something like "reset" semaphore. Because in Salvo is no OSResetBinSem() I had to make this with OS_WaitBinSem(flag, minimal timeout, label)
(in fact, my demo can't compile the final project, because don't support timeouts).

Do you have other suggestion to clear the semaphore or to ensure that it's cleared? I think that OSResetBinSem() is absolutely needed to complete the set of the Salvos's commands.

With two words - OSResetBinSem() is needed.
The same should be done for semaphores and messages - OSResetSem(), OSResetMsg().

This will be not difficult to implement in Salvo.

Regards
Luben

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria

Re: How to ensure that BinSem is reset before OS_WaitBinSem

Postby luben » Wed Dec 27, 2000 11:07 am

Hello,

I think that using of OSCreateXYZ to set/reset events is not good manner. It's potential way to include problems in the software (as you menshened I have to use such operations if I'm sure that no tasks are waiting for the events).

Maybe is better to be more patient and to wait the comming of OSResetXYZ and OSSetXYZ.... :-)

Regards
Luben

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria

Re: How to ensure that BinSem is reset before OS_WaitBinSem

Postby aek » Wed Dec 27, 2000 12:02 pm

In case I wasn't clear before ... we will not provide any OSResetXyz() and OSSetXyz() services. That's because the standard, agreed-upon services for using semaphores are only to create, to signal and to wait a semaphore.

You can create these services on your own, but we don't recommend it, and we won't support it.

Setting and resetting events is not a good idea. Instead, use the semaphore as intended through the services provided. Labrosse's uC/OS book has a good explanation on semaphores -- other books do too, of course.


Using OSCreateBinSem() on-the-fly is perfectly OK as long as you can guarantee that no tasks are waiting the binsem.

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm


Return to Coding

Who is online

Users browsing this forum: No registered users and 1 guest

cron