This is an old revision of the document!
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:
Calling this service is placed into periodical place in program (e.i. TMR0 inttertupt routine).
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.
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.
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:
Service | Description | Properties |
---|---|---|
bool OS_IsEventError () | Check for event error |
Event errors are:
Service | Description | Properties |
---|---|---|
bool OS_IsInCriticalSection () | Returns 1 if one of tasks is in critical section |
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() |
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); ... }
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 | |
OS_Timer | | Insrease all active timers. | |
Waiting | |||
OS_Yield | | Return to scheduler | |
OS_Delay | (delaytime) | Delay current task for delaytime system ticks | |
OS_Wait | (condition) | Wait for condition is true | |
OS_Wait_TO | (condition, timeout) | Wait for condition is true. Exit if timeout expired. | |
Checking | |||
bool OS_IsTimeout | | Return true if timeout occured in previos wait service. | |
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 | |
OS_LeaveInt | | For PICC16 and PICC18: restore saved FSR in the end of ISR function | |
char OS_DI | | Disable all interrupts and save previos state of GIEx flags | |
OS_EI | | Enable all interrupts | |
OS_RI | (char) | Restore previosly saved by OS_DI service GIEx flags | |
OS_EnterCriticalSection | | Enter critical section | |
OS_LeaveCriticalSection | | Leave critical section |