Simplifying Interrupts with the External IRQ Framework

Let’s be completely honest, no matter how many years a developer may have developing embedded software, setting up and configuring interrupts is still the most error prone and rarely works on the first try. There is just something about these interrupt controllers, probably the complexity and how they tie into every peripheral and processor core, that makes them a nightmare. Any developer who has Googled setting up interrupts will find numerous articles outlining the fifteen step process that hasn’t changed since the microcontroller was invented! The Renesas Synergy™ Platform has once again come through with their External IRQ Framework that makes setting up and configuring external interrupts simple.

 

 

The External Interrupt Framework provides developers with an easy way to setup and configure external interrupts using a high-level interface. Developers can use the External Interrupt Framework to monitor external hardware that want the microcontroller’s attention such as button presses, or requests from Wi-Fi or Bluetooth modules. The IRQ can be configured to perform a Semaphore Put operation that will allow a thread to be unblocked when the IRQ occurs. The framework contains some key features that are critical to understand include:

  • Supports unique pending IRQ request for multiple threads

  • Supports up to 16 hardware channels (dependent upon the microcontroller)

  • Thread can be suspended while waiting for external IRQ request

  • Can specify timeouts

 

These key features are just a few highlights and I highly recommend readers take a few moments to read the Synergy Software Package (SSP) User’s Manual to gain additional insights. In the meantime, let’s briefly dive into the External IRQ Framework and see how easy it is to add, configure and use within the e2 studio ISDE or the Synergy Standalone Configurator of IAR EW for Synergy.

 

From within the Synergy Configuration file view, open the threads tab and click the thread that the External IRQ Framework will be added to. From within the “Thread Stacks”, add the External IRQ Framework by selecting the Framework > Input > External Framework on sf_external_irq. After doing so, developers will find that their view looks something like the following:

 

 

Clicking on the g_sf_external0 block and looking at the Properties tab provides some insight into the behavior we can expect from the interrupt. As the reader can see below, we have the option to rename our interrupt but more importantly by default, the framework is configured to raise a Semaphore Put event. The only other option is to set the Event to None but that really doesn’t help us much as developers if we want to be notified that the interrupt has occurred. One might want to change the name g_sf_external_irq0 to represent something more system obvious like g_sf_Wifi_IRQ3 to let developers know that it is the Wi-Fi modules IRQ line and it is connected to the hardware IRQ3 line.

 

  

 

Clicking on the g_external_irq0 block and viewing the Properties tab again allows us to configure the low level details for the external interrupt. The first step a developer should take is to specify the Channel. The channel literally corresponds to the IRQn hardware pin and ICU line. So for example, if a developer wanted to setup an interrupt for a switch on the SK-S7G2 board, S4 and S5 are connected to IRQ10 and IRQ11. A developer would set the channel to 10 or 11 depending on the switch they want to use.

 

 

After setting the channel, configuring the interrupt is easy. Simply set the desired priority, name and trigger level. A developer can even set a callback function that will be called when the interrupt fires. Don’t forget that the callback is called from within an ISR and should be short and quick so that it doesn’t accidentally block other interrupts or threads.

 

 

There you have it! Setting up an external interrupt is easy and takes only minutes. Next time we will dig into the Thread Monitor Framework and learn how we can visualize what is happening within our embedded system.

 

Live long and profit!

 

Professor_IoT

 

 

Hot Tip of the Week

 

You may have noticed a new left side guide bar tab on Renesas Synergy web pages called Resource Library. Clicking this tab brings up a convent list (seen in the screen shot below) showing all Synergy App Notes, Datasheets, User’s Manuals and Quick Start Guides. Just click the document type you want and you will get a filterable list for all related documents. Cool!