4. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
In order to allow OSEK-OS to be used in a variety of systems with
different capacities and demands (for example memory, processing
capacity, etc.) is that OSEK-OS defines 4 classes of compliance (CC).
Conformance classes are determined according to the following
attributes:
Multiple activation of basic tasks
Types of tasks accepted: basic and extended
Number of tasks by priority
4
6. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Hook Routines
The hookroutines are functions implemented by the user that the
operating system will call in specific situations.
They are optional and can be used to add some specific management desired
by the user in the following situations:
StartupHook: it is called during the initialization of the operating system,
before being completed.
ShutdownHook: it is called at the end of the shutdown of the operating system.
PreTaskHook: is called before proceeding to execute a task. •
PostTaskHook: is called when the execution of a task ends.
ErrorHook: it is called in case any of the interfaces of the operating system
returns a value other than E_OK.
6
9. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
StartupHook example
1.After completing the initialization of C, the main
function is called, the same in this case proceeds to
start the execution of the operating system in 2.
3 Once the initialization of the operating system,
the same calls StartupHook.
4 Just when you start StartupHook starts the
Scheduler and it proceeds to run Tasks
9
1.For the operating system to call
the StartupHook, the same should be
indicate by setting STARTUPHOOK to
TRUE
2 Just after calling Startup-
Hook the operating system will proceed
to start the Scheduler, so the task
InitTask will be executed after
StartupHook
17. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
levels of error
OSEK-OS offers two levels of error checking that can be
configured in the .oil file
extended: it is the mode used during development. Some
extra checks are made and returned in case of error.
standard: this is the mode used in production. Only very
critical errors are detected and reported.
In this Example, "Error handling" is used the ActivateTask
interface that can return E_OK, E_OS_LIMIT or E_OS_ID
when the level of the error check is set to extended
but only E_OK and E_OS_LIMIT when the level of error
checks It is established to standard.
17
19. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Shared Data between Tasks
19
how does the consumer know that (new) data is available?
Data is shared between several tasks and, in
order to keep the data in a consistent state,
we need to protect it from concurrent
access. In other words: access to the data
must be serialized.
This use case is mainly about task synchronization:
the interplay between producer and consumer must work
smoothly. How does a consumer know that new data is
available?
how to serialize access to shared data?
20. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Two shared Resource Control
20
the mutex = MUTual EXclusion.
the semaphore
Resource
A resource is any entity used by a task. A resource can thus be
an I/O device such as a printer, a keyboard, a display, etc. or a
variable, a structure, an array, etc.
Shared Resource
A shared resource is a resource that can be used by more than one task. Each task should
gain exclusive access to the shared resource to prevent data corruption. This is called
Mutual Exclusion.
21. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
the mutex
A critical section is a piece of code (part of a
function) from which the access to the shared
resource must be atomic. At a certain moment in
time, one and only one critical section is allowed to
access the shared data
The mutex implements two operations:
acquire: enter the critical section, or sleep if another
task has already acquired the mutex, and
release: leave the critical section. Other tasks now
have the possibility to acquire the mutex.
21
23. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Mutual Exclusion
Disable interrupts Mechanism
Demand: exclusive use of a resource
Disable interrupts
Used on critical sections of code
disabling/enabling interrupts
used to access a few variables or small data
structures
used when the process time is minimal
affects interrupt latency
you should not disable interrupts for any longer
than the kernel does
in C/OS-II:
OS_ENTER_CRITICAL( );
… // you can access shared data here
OS_EXIT_CRITICAL( ):
23
26. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
performing test-and-set operations (indivisibly)
perform test-and-set operations (indivisibly)
two tasks may agree that to use a common
resource, they must first check a global
variable
while it is being checked, and before it is set,
by one task, it must be made inaccessible by
the other
this can be achieved by:
disabling interrupts (above) or
some processors now support a single TAS
instruction
Make the following
test test-and-set variable
Set test-and-set variable to 1
Access resource
Set test-and-set variable to 0
26
Kindly Note: DPRAM test-and-set instructions can
work in many ways
When CPU 1 issues a test-and-set instruction, the
DPRAM first makes an "internal note" of this by
storing the address of the memory location in a special
place. If at this point, CPU 2 happens to issue a test-
and-set instruction for the same memory location, the
DPRAM first checks its "internal note", recognizes the
situation, and issues a BUSY interrupt, which tells CPU
2 that it must wait and retry.
28. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Mutual Exclusion - semaphores
a protocol mechanism to control
access to shared resources, signal
the occurrence of an event or allow
two tasks to synchronize
one analogy is that in order for a
task to use a resource it must first
draw a key for it
if the key(s) is in use, the task
suspends
wait on (pend) & signal (post)
semaphore
two types of semaphores:
binary and counting (general)
28
task 2
task 1 1. pend
4. post
Printer
2. pend
6. post
5. “my name is task 2”
3. “my name is task 1”
34. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Resources
If two applications simultaneously use a resource such as being a data bus
or a port but they do not synchronize with each other, the result can be
indeterminate.
For this reason, in order to access resources, conventional traffic lights
are used or mutex to be able to access them from several tasks without
generating interference or collisions between them. However, the use of
traffic lights and mutex have two problems:
inversion of priorities: occurs when a relatively high priority task must be
blocked by requiring the use of a resource that is being used by a priority task
minor that was interrupted to execute the highest priority task.
deadlocks: occurs when two tasks use two resources (or semaphores) in
reverse order blocking each other. OSEK-OS offers a solution for accessing
resources that avoids both these problems.
34
35. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Priority inversion on occupying
semaphores
This means that a lower-priority task delays the execution of higher-priority task.
sequencing of the common access of two tasks to a semaphore (in a full preemptive system, task T1
has the highest priority) Task T4 which has a low priority, occupies the semaphore S1. T1 preempts
T4 and requests the same semaphore. As the semaphore S1 is already occupied, T1 enters the waiting
state. Now the low-priority T4 is interrupted and preempted by tasks with a priority between those
of T1 and T4. T1 can only be executed after all lower-priority tasks have been terminated, and the
semaphore S1 has been released again. Although T2 and T3 do not use semaphore S1, they delay T1
with their runtime.
35
36. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_systemDeadlock situation using
semaphores
In this case deadlock means the impossibility of task execution due to infinite waiting
for mutually locked resources
The following scenario results in a deadlock: Task T1 occupies the semaphore S1 and
subsequently cannot continue running, e.g. because it is waiting for an event. Thus, the
lower-priority task T2 is transferred into the running state. It occupies the semaphore
S2. If T1 gets ready again and tries to occupy semaphore S2, it enters the waiting state
again. If now T2 tries to occupy semaphore S1, this results in a deadlock
36
37. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
OSEK Priority Ceiling Protocol
To avoid the problems of priority inversion and deadlocks the OSEK
operating system requires following behavior:
At the system generation, to each resource its own ceiling priority is
statically assigned. The ceiling priority shall be set at least to the highest
priority of all tasks that access a resource or any of the resources linked
to this resource
If a task requires a resource, and its current priority is lower than the
ceiling priority of the resource, the priority of the task is raised to the
ceiling priority of the resource.
If the task releases the resource, the priority of this task is reset to the
priority which was dynamically assigned before requiring that resource.
37
45. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Tasks group
This feature allow to mix non-preemptable tasks and preemptable
tasks.
In the same group all the tasks are seen as non-preemptable by the other
tasks of the group.
A task having a higher priority of all the tasks of the group (and not part
of the group) may preempt any task of the group.
This feature uses an internal resource for each group:
The internal resource is got automatically when the task start to run;
The internal resource is released automatically when the task terminates;
An internal resource may not be reference with GetResource() or
ReleaseResource().
45
63. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Internal Resources
OSEK-OS offers the possibility of defining internal resources.
These resources are not handled and released by using GetResource and
ReleaseResource but they are automatically reserved and released by
the system at Begin and finish a task.
By using internal resources the user is allowed to create task groups
cooperatives which use the same internal resource. In this way all the tasks that
use the same internal resource behave each other as NON PREEMPTIVE.
63
64. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Internal Resources
Example
As you can see "Using internal resources" the
task DemoTask1 during its processing will never be
interrupted by DemoTask3, despite of this having a
priority of 5 and this is greater than the priority of
DemoTask1 which is 1.
Both DemoTask1 and DemoTask3 will have a priority of
5.5 when running "OSEK Priority Ceiling Protocol").
However, DemoTask1 may be interrupted by DemoTask2
that has a priority of 3, since it does not use the internal
resource.
DemoTask3 will be able to interrupt DemoTask1 if it
calls Schedule when DemoTask3 is in the ready
state. In this way it is possible to arm groups of tasks
that do not interrupt each other, or interrupt only
explicitly when the user calls Schedule.
64
68. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
References
Embedded Microcomputer Systems Real Time Interfacing Third
Edition Jonathan W. Valvano University of Texas at Austin.
MicroC/OS-II the real-time kernel second edition jean j.labrosse.
RTOS Concepts http://www.embeddedcraft.org.
OSEK/VDX Operating System Specification 2.2.3
AUTOSAR Layered Software Architecture
The Trampoline Handbook release 2.0
Trampoline (OSEK/VDX OS) Test Implementation -Version 1.0,
Florent PAVIN ; Jean-Luc BECHENNEC
68
70. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
References
Real Time Systems (RETSY)
Jean-Luc Béchennec - Jean-Luc.Bechennec@irccyn.ec-nantes.fr
Sébastien Faucou - Sebastien.Faucou@univ-nantes.fr
jeudi 12 novembre 15
AUTOSAR Specification of Operating System V5.0.0 R4.0 Rev 3
OSEK - Basics http://taisnotes.blogspot.com.eg/2016/07/osek-basic-
task-vs-extended-task.html
OSEK OS Session Speaker Deepak V.
M.S Ramaiah School of Advanced Studies - Bangalore 1
Introducción a OSEK-OS - El Sistema Operativo del CIAA-Firmware
Programación de Sistemas Embebidos
MSc. Ing. Mariano Cerdeiro
70