5. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
event
An event is like a flag that is raised to signal something just happened.
An event is private: It is a property of an Extended Task. Only the owning task may
wait for the event.
It is a N producers / 1 consumer model
Any task (extended or basic) or Interrupt Service Routines Category 2 may invoke the
service which set an event.
One task (an only one) may get the event (ie invoke the service which wait for an event.
An Extended Task may wait for many events simultaneously
The first to come wakes up the task.
an event corresponds to a binary mask: 0x01, 0x02, 0x04, ...
5
7. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Events’ services
StatusType SetEvent(TaskType <TaskID>, EventMaskType <Mask>);
Events of task <TaskID> are set according to the <Mask> passed as 2nd argument.
StatusType is an error code:
E_OK: no error;
E_OS_ID: invalid TaskId;
E_OS_ACCESS: TaskID is not an extended task (not able to manage events);
E_OS_STATE: Events cannot be set because the target task is in the SUSPENDED state.
This service is not blocking and may be called from a task or an ISR2
7
9. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Events’ services
StatusType GetEvent(TaskType <TaskId>, EventMaskRefType event);
The event mask of the task <TaskId> is copied to the variable event (A pointer to
an EventMaskType is passed to the service);
StatusType is an error code:
E_OK: no error;
E_OS_ID: invalid TaskID;
E_OS_ACCESS: TaskID is nor an extended task;
E_OS_STATE: Events may not be copied because the target task is in the
SUSPENDED state.
Non-blocking service, my be called from a task or an ISR2
9
10. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Events’ services
StatusType WaitEvent(EventMaskType <EventID>);
Put the calling task in the WAITING state until one of the events is set.
May be called by the event owning (extended) task only;
StatusType is an error code:
E_OK: no error;
E_OS_ACCESS: The calling task is not an extended one;
E_OS_RESOURCE: The task has not released all the resources (will be
explained later);
E_OS_CALLEVEL: The caller is not a task
Blocking service.
10
27. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Interrupts
2 kinds of interrupts (Interrupt Service Routine or ISR) are defined
in OSEK.
Level 1 interrupts
are very fast;
depends on the hardware capabilities of the micro-controller;
are not allowed to do a system call;
usually difficult to port to another micro-controller;
Level 2 interrupts
are not as fast as level 1 interrupts
are allowed to do some system calls (activate a task, get a resource, ...)
27
29. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Interrupt
29
ISR category 1 The ISR
does not use an operating
system service8. After the
ISR is finished,
processing continues
exactly at the instruction
where the interrupt has
occurred, i.e. the interrupt
has no influence on task
management. ISRs of this
category have the least
overhead.
ISR category 2 The OSEK
operating system provides
an ISR-frameto
prepare a run-time
environment for a
dedicated user routine.
During system generation
the user routine is
assigned to the
interrupt.
31. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Priority
31
ISR2
May (must?) do system calls (activate a task, get a
resource, …)
• Roughly the same behavior as a task
• they have a priority (greater than the higher priority
of tasks).
ISR2 priority is a logical one and not be related to the
hardware priority level.
• they have a context (registers, stack, …)
• In addition an ISR2
• is associated to a hardware interrupt (triggered by an
event)
To use an ISR2, it is necessary to
• declare it in the OIL file with the interrupt
source identifier (depends on the
target platform) to indicate where the interrupt handler
is installed;
• initialize the related interrupt registers of the
peripheral which will trigger
the interrupt.
36. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
The counters
The counter is an abstraction of the hardware “tick”
source (timer, interrupt source, ...)
The “tick” source is heavily dependent of the target
platform;
The counter is a standard component;
At least one counter is available:
SystemCounter
No system call to modify the counters.
Their behavior are masked by the alarms.
A hardware interrupt must be associated to
a counter
36
CPU
Interrupt
controller
PIT
Periodic
interrupt
timer
Other
Modules
SOC
37. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
The counters Cont.
A counter defines 3 values
37
The maximum
value of the
counter
(MaxAllowedValue)
The counter restart
to 0 after reaching
MaxAllowedValue
A division factor
(TicksPerBase):
for instance with a
TicksPerBase equal
to5, 5 ticks are
needed to have the
counter increased by 1;
(MINCYCLE)The
minimum number
of cycles before
the alarm is
triggered
Count = 0
Count = MaxAllowedValue
@count =
MINCYCLE alarm is happened
38. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
OIL description of a counter
COUNTER generalCounter {
TICKSPERBASE = 10;
MAXALLOWEDVALUE = 65535;
MINCYCLE = 128;
};
38
number of “ticks” (from the interrupt
source) needed to have the counter
increased by one.
Count = 0
Count = 1
Count = 2
TICKSPERBASE = 10 ticks
Maximum value of the counter. This value is used by
the OIL compiler to generate the size of the variable
used to store the value of the counter
Count = MAXALLOWEDVALUE = 65535;
minimum interval between 2 triggering
of the alarm.
39. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
The Alarms
An alarm is connected to a counter
an performs an action.
An alarm is associated to 1 counter
A counter may be used for several
alarms
When the counter reach a value of
the alarm (CycleTime, AlarmTime),
the alarm expires and an action is
performed:
Activation of a task;
Signalization of an event;
alarm-callback routine
39
Activate a task
Set an event
alarm-callback routine
43. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
SetAbsAlarm
StatusType SetAbsAlarm ( AlarmType <AlarmID>, TickType <start>,TickType
<cycle>)
AlarmID is the id of the alarm to start.
start is the absolute date at which the alarm expire
cycle is the relative date (counted from the start date) at which the alarm expire
again• If 0, it is a one shot alarm
StatusType is an error code:
E_OK: no error;
E_OS_STATE: The alarm is already started;
E_OS_ID: The AlarmID is invalid.
E_OS_VALUE: start is < 0 or > MaxAllowedValue and/or cycle is <MinCycle or >
MaxAllowedValue.
43
44. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
SetRelAlarm
StatusType SetRelAlarm ( AlarmType <AlarmID>, TickType
<increment>,TickType <cycle>)
AlarmID is the id of the alarm to start.
increment is the relative date at which the alarm expire
cycle is the relative date (counted from the start date) at which the alarm expire
again. If 0, it is a one shot alarm
StatusType is an error code:
E_OK: no error;
E_OS_STATE: The alarm is already started;
E_OS_ID: The AlarmID is invalid.
E_OS_VALUE: increment is < MinCycle or > MaxAllowedValue and/or cycle is < MinCycle
or > MaxAllowedValue.
44
50. https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
lab5
Led 0 >>PORTA pin 4
Led 1 >> PORTA pin 5
Buzzer >> PORTD pin 7
Write a periodic task (extended task) depends on Alram take action
(activate the periodic task ) with CYCLETIME = 512 counter cycles.
The counter here is SystemCounter.
The periodic task responsible on increment seven seg and toggle led 1
For each alarm.
Also once the Count value reached to (x == 10|| x==30||x ==50||x==70||
x==90)
Then will enable led 0 and the buzzer for only 1 count.
The last thing change CYCLETIME and expect what happens ?
50
68. 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.
68
69. 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
69
70. 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.
70
78. 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().
78
93. 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
93