Es Unit-5
Es Unit-5
Course code:16CS402
How to pronounce?
“Are toss”
vButtonTask
vLevelsTask
Time
Fig: Semaphore.
Semaphores and Shared Data Cont.
RTOS Semaphores:
• No RTOS uses the terms raise and lower;
they use give, take and release, pend and
post, p and v, wait and any other
combinations.
• We use take for lower and release for raise.
• Most commonly used semaphore is binary
semaphore, which is most similar to the
railroad semaphore.
Semaphores and Shared Data Cont.
• RTOS function call TakeSemaphore is used
to take semaphore.
• RTOS function call ReleaseSemaphore is
used to release semaphore.
• Any other task that calls TakeSemaphore
will block until the first task calls
ReleaseSemaphore.
• Only one task can have the semaphore at a
time.
Fig: Semaphore Protect Data.
Semaphore Problems
Task A gets a message Task A tries to take
Task C takes a
In its queue and the semaphore that
semaphore that it
unblockes; RTOS Task C already has
shares with Task A
switches to Task A taken
Task B
Task C
Time
vTaskDelay (3) Task delay ends at vTaskDelay (3) Task delay ends at
Starts task delay. Timer interrupt. Starts task delay. Timer interrupt.
1 System tick
Timer interrupts
Timer functions cont.
What is the normal length of system tick?
• Short length gives accurate timings, but microprocessor has to
execute the instructions frequently.
• Designer has to consider this trade-off
Take semaphoreA
SemaphoreA is
shared with a
with TaskH and
TaskHigh.
not released.
ISR
RTOS
Task
Time
Interrupt routines in an RTOS
environment
Rule 2: No RTOS calls without fair warning
ISR
RTOS
Send Message
TaskHigh
to mailbox.
TaskLow
Time
Fig: How interrupt routines should work
Rule 2: No RTOS calls without fair warning
ISR
RTOS
Send
TaskHigh Message to
mailbox.
TaskLo
w
Time
TaskHigh Send
Message to
TaskLo mailbox.
w
Time
Fig: How interrupt routines do work
Solution 2: RTOS provides a function that the interrupt
routines call to let the RTOS know that an interrupt
routine is running.
This procedure disables scheduler for entire duration of
the interrupt routine.
ISR
Jump or call
RTOS
Enter Send
TaskHigh
Interrupt Message to
routine mailbox.
TaskLow
Time
Fig: How interrupt routines do work
Solution 3: Some RTOSs provides separate set of
funcitons especially for interrupt service routines.
Example: In addition to OSSemPost, there might be
OSISRSemPost.
Rule 2 and Nested Interrupts
Low-priority
ISR
RTOS
High Priority Send Message
TaskHigh
Interrupt to mailbox.
Occurs.
TaskLow
Time
Thank you