Available Languages?:

This is an old revision of the document!


OSA : System services

Common services

Service Description Properties
OS_Init() Init system variables.

Clears all task descriptors, all binary semaphores and static timers. This service must be called before OS_Run().

Service Description Properties
OS_Timer() Work with all timers

This service must be used if:

  • some tasks use OS_Delay();
  • some tasks wait events with timeout;
  • static or dinamic timers are used in program.

Calling this service is placed into periodical place in program (e.i. TMR0 inttertupt routine).

In this documentation we use a term system tick - period of OS_Timer calling. All delays and timeouts parameters in services are given in system ticks.

Every execution OS_Timer() all active timers are increased by 1 (except 24-bit old style static timers wich are increased 1 type per 256 ticks).

Example of using:

void interrupt isr()
{
 
    if (T0IE && T0IF) {
        TMR0 -= 250;
        T0IF = 0;
        OS_Timer();
    }
}
Service Description Properties
OS_Yield () Switch context

This service unconditionaly switchs cintext (returns to schoduler) to allow other task to be executed.

Wait services

Service Description Properties
OS_Delay (delaytime) Delay current task by delaytime system ticks

Puts task in waiting state for time given in parameter delaytime.

For example task indicates temperature to the LCD one ime per second. Let OS_Timer period = 10 ms. Task will looks like:

void Task_Indicate (void)
{
    for (;;) {
        OS_Delay(100);	            // Delay = 100 * 10 ms = 1 sec
        IndicateTemerature();	      // Out data to LCD
    }
}

Using this service you must remember that OS_Timer is discrete. So accuracy of all delay is one system tick. If OS_Timer calling interval is 10 ms, then OS_Delay(1) may wait 10 ms, and may wait 0 ms (it depends of at what stage of OS_Timer period OS_Delay was called). Therefore you should either to be sure that length of delay is not important or to decrease system ticks and increase delay value. For example reduce the value of system tick to 1 ms and call OS_Delay(10). Here we can be sure that delay will last for 9-10 ms.

Service Description Properties
OS_Wait (condition) Wait for condition became true

Puts task in waiting state while condition will not became true. Condition is any expression of boolean type. When conditin becames true task becames ready to execute.

    ...
    OS_Wait(m_nInPulseCounter >= 10 || m_bButtonPressed);
    ...

In thi example m_nInPulseCounter and m_bButtonPressed are some external variables that can be set anywhere in program. Task will be in waiting mode while m_nInPulseCounter less than 10 and button not pressed.


Service Description Properties
OS_Wait_TO (condition, timeout) Same as OS_Wait() with exit if timeout expired

Puts task in waiting state while condition will not became true or while timeout will not expired. Timeout value is given in system ticks.

    ...
    OS_Wait_TO(m_bButtonPressed, 100);
    if (OS_IsTimeout()) ...;
    ...

Here we wait button event within 100 system ticks. After exit waiting we check was there timeout or not by service OS_IsTimeout.

System state

All services that check system state return 0 or 1 deending of system state flags.

Service Description Properties
bool OS_IsTimeout () Check for exit waiting with timeout

This service can be used after waitng some event with timeout to check the reason of exit waiting. If returns 1 then timeout expired and event was not occured. If returns 0 then event occured and there was not timeout.

Service Description Properties
bool OS_IsError () Check for system error

System errors are:

  • Task creation error (there is no free descriptor)
Service Description Properties
bool OS_IsEventError () Check for event error

Event errors are:

  • Increasing counting semaphore when it already has maximum value
  • Sending message when it allready exists
  • Sending message via queue that allready full
Service Description Properties
bool OS_IsInCriticalSection () Returns 1 if one of tasks is in critical section

Interrupt control services

Service Description Properties
OS_EnterInt () For PICC16 and PICC18: sould be called in the begin of intterupt routine (saves FSR value)
OS_LeaveInt () For PICC16 and PICC18: sould be called in the end of intterupt routine (restores FSR value)

OS_EnterInt calling inserted in the begin of interrupt routine just after definition of local variables. OS_LeaveInt() calling inserted in the end of interrupt just before closing '}'.

void interrupt int_routine (void)
{
    char  var1, var2;
    int   var3;
    OS_EnterInt();
    ...                //
    ...                //
    OS_LeaveInt();
}
Service Description Properties
char OS_DI () Disable interrupts. Returns current GIEx value
OS_EI () Enable all interrupts
OS_RI (char) Restore GIEx value saved in OS_DI()

Service OS_RI restores only "1" but not "0". If before OS_DI() flag GIE == 0, and after OS_DI() GIE was set by OS_EI(), then OS_RI() will not restore zero value of GIE.

here is example of using these service to generate pulse in 5 cycles:

{
    char gie_temp;
    ...
    gie_temp = OS_DI();
    RB0 = 1;
    NOP();
    NOP();
    NOP();
    NOP();
    RB0 = 0;
    OS_RI(gie_temp);
    ...
}

All system services

Service Arguments Description Properties
System
OS_Sched List all tasks, select ready task with highest priority and run it.
OS_Run Run operating system's kernel. Calls OS_Sched() in infinite loop.
OS_Init Init system vars Not allowed in interrupt
OS_Timer Insrease all active timers.
Waiting
OS_Yield Return to scheduler Allowed only in taskSwitches contexts
OS_Delay (delaytime) Delay current task for delaytime system ticks Allowed only in taskSwitches contextsService uses system timer
OS_Wait (condition) Wait for condition is true Allowed only in taskSwitches contexts
OS_Wait_TO (condition, timeout) Wait for condition is true. Exit if timeout expired. Allowed only in taskSwitches contextsService uses system timer
Checking
bool
OS_IsTimeout
Return true if timeout occured in previos wait service. Service uses system timer
bool
OS_IsError
Check for error after task creating
bool
OS_IsEventError
Check for error after work with events
bool
OS_IsInCriticalSection
Return true if one of task is in critical section
Interrupts
OS_EnterInt For PICC16 and PICC18: save FSR in the begin of ISR function Only insize interrupt
OS_LeaveInt For PICC16 and PICC18: restore saved FSR in the end of ISR function Only insize interrupt
char
OS_DI
Disable all interrupts and save previos state of GIEx flags Not allowed in interrupt
OS_EI Enable all interrupts Not allowed in interrupt
OS_RI (char) Restore previosly saved by OS_DI service GIEx flags Not allowed in interrupt
OS_EnterCriticalSection Enter critical section Allowed only in task
OS_LeaveCriticalSection Leave critical section Allowed only in task
 
en/osa/ref/services/system_services.1260572268.txt.gz · Last modified: 12.12.2009 01:57 by osa_chief
 
Creative Commons License Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki