Pumpkin, Inc.

Pumpkin User Forums

Semaphores

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

Semaphores

Postby aek » Thu Mar 04, 2004 8:31 am

Hi Raj.

Lite or LE/Pro?

When you aren't limited by the number of tasks you can have, then instead of having a task decide which routines to run (which amounts to polling, a no-no in event-driven systems), you move each routine into a Salvo task, and have each task wait a particular binSem. Then, most of the time, the tasks are dormant / waiting for the event to occur, and they "awaken" when the event happens / the binSem is signaled.

In general, the idea behind an RTOS with Salvo's features is to split up the things that the application needs to do into individual tasks, which is what you'd acheive as per the above.

In your second example, mySingleTask() won't work, because it's waiting on a sequence of events to happen, so if the binSem RUN_ADCROUTINE never happens, then the task doesn't even have a chance to wait on the binSem RUN_LEDROUTINE.

If for some strange reason you wanted to "dispatch" those eight routines from mySingleTask() based on an event, then you ought to use a message (which points to a variable with 8 bitfields) or an event flag, and then do a switch() on the message / event flag and run one of the routines accordingly.

The big difference between the independent task/routines and the routines called by a single task is that the latter has no real, flexible concept of priority, and no concurrency. But the former will likely require more RAM (though not more ROM).

------------------

[This message has been edited by aek (edited March 04, 2004).]

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

Re: Semaphores

Postby Raj » Thu Mar 04, 2004 12:46 pm

Hi,

I have a lot of events which can take place in my embedded application and I am setting various flags to let each task know that a particular event has occured. I understand that the proper approach to do this is by creating binary semaphores and have my tasks wait for them, but I am not sure which of the two methods is optimal and which one requires less memory.

For example I create 8 flags to check for various routines I have...

code:
struct FLAG1
{
unsigned RUN_ADCROUTINE:1;
unsigned DON_ADCROUTINE:1;
unsigned RUN_LEDROUTINE:1;
unsigned DON_LEDROUTINE:1;
unsigned RUN_COMROUTINE:1;
unsigned DON_COMROUTINE:1;
unsigned RUN_XXXROUTINE:1;
unsigned DON_XXXROUTINE:1;
}Routines;

...and have a single task take care of checking whether a particular routine needs to run.
code:
void mySingleTask(void)
{
for(;;)
{
if(Routines.RUN_ADCROUTINE==1)
{
Routines.RUN_ADCROUTINE=0;
RunADCRoutine();
}

if(Routines.RUN_LEDROUTINE==1)
{
Routines.RUN_LEDROUTINE=0;
RunLEDRoutine();
}

OS_Yield(CS1_mySingleTask);

}
}


If I have to acheive the same functionality using Binary Semaphores, isnt' it necessary to allocate 8 ECB pointers?
code:
#define RUN_ADCROUTINE	OSECBP(1)
#define DON_ADCROUTINE OSECBP(2)
#define RUN_LEDROUTINE OSECBP(3)
#define DON_LEDROUTINE OSECBP(4)
#define RUN_COMROUTINE OSECBP(5)
#define DON_COMROUTINE OSECBP(6)
#define RUN_XXXROUTINE OSECBP(7)
#define DON_XXXROUTINE OSECBP(8)

and 8 context switching labels...

and the code is like....
code:
void mySingleTask(void)
{
for(;;)
{
OS_WaitBinSem(RUN_ADCROUTINE, OSNO_TIMEOUT, CS1_mySingleTask)
RunADCRoutine();

OS_WaitBinSem(RUN_LEDROUTINE, OSNO_TIMEOUT, CS2_mySingleTask)
RunLEDRoutine();

}
}


So does the same functionality require atleast additional 8 bytes for the ECB pointers if I use Semaphores.

Kindly explain.

Thanks a million for your earlier replies!

Regards,
Raj.

[This message has been edited by aek (edited March 04, 2004).]

Raj
 
Posts: 7
Joined: Wed Nov 19, 2003 12:00 am
Location: Erie, PA, USA


Return to Coding

Who is online

Users browsing this forum: No registered users and 2 guests

cron