0% found this document useful (0 votes)
47 views13 pages

7 Interrupt Managament Counting Semaphore

This document discusses interrupt handling and counting semaphores in FreeRTOS. It provides details on: - The differences between binary and counting semaphores, with counting semaphores being useful for counting events and managing shared resources. - How counting semaphores work, including initializing the maximum count and initial count values based on intended usage. - An example of using a counting semaphore to count events from an interrupt service routine and have a task process the events. - How queues can be used to send data from an interrupt service routine to tasks, and how this may cause higher priority tasks to unblock.

Uploaded by

Hegazy Hegazy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views13 pages

7 Interrupt Managament Counting Semaphore

This document discusses interrupt handling and counting semaphores in FreeRTOS. It provides details on: - The differences between binary and counting semaphores, with counting semaphores being useful for counting events and managing shared resources. - How counting semaphores work, including initializing the maximum count and initial count values based on intended usage. - An example of using a counting semaphore to count events from an interrupt service routine and have a task process the events. - How queues can be used to send data from an interrupt service routine to tasks, and how this may cause higher priority tasks to unblock.

Uploaded by

Hegazy Hegazy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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