Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

7 Interrupt Managament Counting Semaphore

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Real Time Operating System

“FreeRTOS”
Interrupt Management
Counting Semaphores

1
Agenda
• Binary semaphore pitfall

• Counting semaphore handling of fast interrupts

• Sending/Receiving to Queues from ISR


Binary Semaphore Pitfall
Counting Semaphore
Counting Semaphore
 Counting events
– An event handler will 'give' a semaphore each time an event occurs—
causing the semaphore’s count value to be incremented on each ‘give’.
– A handler task will 'take' a semaphore each time it processes an event—
causing the semaphore’s count value to be decremented on each take.
– The count value is the difference between the number of events that
have occurred and the number that have been processed.
– Counting semaphores that are used to count events are created with an
initial count value of zero.

 Resource management.
– The count value indicates the number of resources available.
– To obtain control of a resource a task must first obtain a semaphore—
decrementing the semaphore’s count value.
– When the count value reaches zero, there are no free resources.
– When a task finishes with the resource, it 'gives' the semaphore
back—incrementing the semaphore’s count value.
– Counting semaphores that are used to manage resources are created so
that their initial count value equals the number of resources that are
available.
Counting Semaphore

 uxMaxCount: The maximum value the semaphore will count to.


– uxMaxCount value is effectively the length of the “queue”.
– When the semaphore is to be used to count or latch events,
uxMaxCount is the maximum number of events that can be latched.
– When the semaphore is to be used to manage access to a collection of
resources, uxMaxCount should be set to the total number of resources
that are available.

 uxInitialCount: The initial count value of the semaphore after it has


been created.
– When the semaphore is to be used to count or latch events,
uxInitialCount should be set to zero—as, presumably, when the
semaphore is created, no events have yet occurred.
– When the semaphore is to be used to manage access to a collection of
resources, uxInitialCount should be set to equal uxMaxCount—as,
presumably, when the semaphore is created, all the resources are
available.
Counting Semaphore; Example 13
Using Queues within an Interrupt Service Routine

 pxHigherPriorityTaskWoken It is possible that a single


queue will have one or more tasks blocked on it waiting for
data to become available.
 Calling xQueueSendToFrontFromISR() or
xQueueSendToBackFromISR() can make data available,
and so cause such a task to leave the Blocked state.
 If calling the API function causes a task to leave the
Blocked state, and the unblocked task has a priority equal to or
higher than the currently executing task (the task that was
interrupted), then, internally, the API function will set
*pxHigherPriorityTaskWoken to pdTRUE.
Using Queues within an Interrupt Service Routine; Example 14
Using Queues within an Interrupt Service Routine; Example 14
Using Queues within an Interrupt Service Routine; Example 14
Using Queues within an Interrupt Service Routine; Example 14
Using Queues within an Interrupt Service Routine; Example 14

You might also like