EFOS
Example
This is an example from the EFOS x86-Real mode examples list.
You can download the EFOS examples document from here
Complete set of EFOS examples comes along with the trial version.
You can get the trial version from here
Source code
/************************************************************************
* sema2.c: *
* We will have two tasks in this code. One High Priority Task(HPT) *
* and a Low Priority Task(LPT). The HPT gets blocked and the LPT *
* removes the block *
***********************************************************************/
#include "task.h"
#include "sema.h"
UInt16 task1Stack[1000], task2Stack[1000];
TASK_Handle task1Handle, task2Handle;
TASK_Obj task1Obj, task2Obj;
SEMA_Obj semaObj;
SEMA_Handle semaHandle;
/* Copy the string */
void CLIB_strcpy(char *dst, char *src)
{
while ( *src )
{
*dst++ = *src++;
}
*dst = 0;
}
/************************************************************************
* This function is the entry point for the High Priority Task. *
* It uses the library function printf to display Message From HPT *
* onto the screen. It also creates a semaphore and gets blocked on the *
* same. This becomes runnable as the Low Priority Task makes this *
* Runnable. Priority for this task is 3 *
***********************************************************************/
void hpt()
{
SEMA_Attrs semaAttrs;
semaAttrs.count = 0;
semaAttrs.objPtr = &semaObj;
#if ( ( EFOS_FEATURES_MASK & EFOS_DEBUG_LIST_MASK ) == EFOS_DEBUG_LIST_ON
)
semaAttrs.name = "SEMA1";
#endif
semaHandle = SEMA_create(&semaAttrs);
if ( semaHandle == NULL )
{
printf("Unable to create Semaphore\n");
while(1);
}
while ( 1 )
{
printf("Message from HPT\n",1);
SEMA_take(semaHandle,-1);
}
}
/************************************************************************
* This function is the entry point for the Low Priority Task. *
* It uses the library function printf to display Message from LPT *
* onto the screen. After printing the message it makes the HPT task *
* Runnable and gets prempted. Priority for this task is 2 *
***********************************************************************/
void lpt()
{
while(1)
{
printf("Message from LPT\n");
SEMA_give(semaHandle);
}
}
void main()
{
TASK_Attrs taskAttrs;
void **ptr;
OS_init();
taskAttrs.entryPt = hpt;
taskAttrs.stackPtr = &(task1Stack[999]);
taskAttrs.priority = 3;
taskAttrs.objPtr = &task1Obj;
#if ( ( EFOS_FEATURES_MASK & EFOS_DEBUG_LIST_MASK ) == EFOS_DEBUG_LIST_ON
)
taskAttrs.name = "HPT";
#endif
task1Handle = TASK_create(&taskAttrs);
if ( task1Handle == NULL )
{
printf("FROM MAIN:: Failed in Task Creation\n");
while(1);
}
taskAttrs.entryPt = lpt;
taskAttrs.stackPtr = &(task2Stack[999]);
taskAttrs.priority = 2;
taskAttrs.objPtr = &task2Obj;
task2Handle = TASK_create(&taskAttrs);
if ( task2Handle == NULL )
{
printf("FROM MAIN:: Failed in Task Creation\n");
while(1);
}
OS_start();
}
Explaination
This example is used to illustrate how SEMA_take can block a task and how SEMA_give
can make a blocked task runnable again. In this example we create two tasks
hpt and lpt with priority values 3 and 2 respectively. hpt after gaining control
displays message "Message from HPT" and gets blocked after that.
So lpt gets a chance to run. lpt prints a message "Message from LPT" and
invokes SEMA_give. SEMA_give increments the value of count if there is no blocked
that exists on the semaphore. If blocked tasks exist on the semaphore it makes
the task with highest priority among them runnable. In our example since hpt
is blocked on semaphore it becomes runnable again.
This example is taken from EFOS x86 Real Mode-Host Trial
version. For more examples get the trial version from here.
Output
Message from HPT
Message from LPT
Message from HPT
Message from LPT
...
...
|