Introduction to RTOS Part 9 - Hardware Interrupts | Digi-Key Electronics
DigiKey DigiKey
151K subscribers
62,984 views
0

 Published On Mar 15, 2021

Hardware interrupts are important in many embedded systems. They allow us to respond to external events (such as a button being pressed) or internal events (such as a timer expiring) in an asynchronous manner, which means that the processor can stop whatever it was doing to run an interrupt service routine (ISR).

The solution to the challenge in the video can be found here: https://www.digikey.com/en/maker/proj...

Code for this video series (including demonstrations, challenges, and solutions) can be found here: https://github.com/ShawnHymel/introdu...

In most RTOSes, such as FreeRTOS, hardware interrupts occur at a higher priority than all other tasks. This means, unless specifically disabled, hardware interrupts will halt the execution of any currently running task. The CPU will be forced to handle the interrupt before returning to the task.

A few tips when working with interrupts:
ISRs should never block, which means you should only use FreeRTOS kernel function calls that end in “FromISR”
You should keep ISRs as short as possible to avoid delaying tasks longer than necessary
Any global variables that get updated in an ISR should be declared with the “volatile” qualifier

Rather than perform processing inside an ISR, you can “defer processing” by collecting data into a buffer and letting a task do the processinging. In the video, we look at how to accomplish deferred processing using semaphores (note that you can also use queues and task notifications).

When an ISR is done, it can set a lock (e.g. “give” a semaphore), which will unblock a task. This task can then use any data collected by the ISR (e.g. a new ADC value, a buffer filled with data from the serial port, etc.). With this method, you can keep ISRs short while relying on a task to perform any necessary processing.

Product Links:
https://www.digikey.com/en/products/d...

Related Videos:
Introduction to RTOS Part 1 - What is a Real-Time Operating System (RTOS)? -    • Introduction to RTOS Part 1 - What is...  ​

Introduction to RTOS Part 2 - Getting Started with FreeRTOS -    • Introduction to RTOS Part 2 - Getting...  ​

Introduction to RTOS Part 3 - Task Scheduling -    • Introduction to RTOS Part 3 - Task Sc...  ​

Introduction to RTOS Part 4 - Memory Management -    • Introduction to RTOS Part 4 - Memory ...  ​

Introduction to RTOS Part 5 - Queue -    • Introduction to RTOS Part 5 - Queue |...  ​

Introduction to RTOS Part 6 - Mutex -    • Introduction to RTOS Part 6 - Mutex |...  ​

Introduction to RTOS Part 7 -    • Introduction to RTOS Part 7 - Semapho...  ​

Introduction to RTOS Part 8 -    • Introduction to RTOS Part 8 - Softwar...  

Introduction to RTOS Part 9 -    • Introduction to RTOS Part 9 - Hardwar...  

Introduction to RTOS Part 10 -    • Introduction to RTOS Part 10 - Deadlo...  

Introduction to RTOS Part 11 -    • Introduction to RTOS Part 11 - Priori...  

Introduction to RTOS Part 12 -    • Introduction to RTOS Part 12 - Multic...  

Related Project Links:
https://www.digikey.com/en/maker/proj...

Related Articles:
https://www.digikey.com/en/maker/vide...

Learn more:
Maker.io - https://www.digikey.com/en/maker

Digi-Key’s Blog – TheCircuit https://www.digikey.com/en/blog

Connect with Digi-Key on Facebook   / digikey.electronics  

And follow us on Twitter   / digikey  

show more

Share/Embed