Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Tutorial: User Interrupts with Processor Expert

DZone's Guide to

Tutorial: User Interrupts with Processor Expert

· Performance Zone ·
Free Resource

Sensu is an open source monitoring event pipeline. Try it today.

I have been asked this question several times:

“How can I define my own interrupt vector with Processor Expert?”

So I think it deserves a short tutorial, if more than one person is asking this.

My user interrupt in the vector table

My user interrupt in the vector table

Interrupts in Processor Expert: Vectors.c

If you are using an interrupt device (SPI, I2C, USB, etc), then Processor Expert cares about it. Processor Expert maintains the vector table But if I want to hook into an interrupt vector myself, I need to tell Processor Expert that. The interrupt vector table is generated as ‘vectors.c’ in the Generated_Code folder.

I’m using in this post screenshots from the newly released Processor Expert V10.4 version, but things apply to earlier versions too. I’m using here an ARM project (Kinetis KL02Z), but things are pretty the same for any other architecture supported by Processor Expert. Additionally, I’m *not* using the Kinetis SDK here, as the way how the SDK deals with interrupts is a different thing, and only would apply to Kinetis.

Vectors.c in Generated_Code Folder

Vectors.c in Generated_Code Folder

InterruptVector Component

There is a component in the Components Library where I can hook my interrupt into the vector table:

InterruptVector Component in Components Library

InterruptVector Component in Components Library

That component does nothing else than let me overwrite the interrupt vector in the vector table. So if I add that component, I can configure it to use my interrupt routine. For example if I want to map the Interrupts on port B to my handler, I only need to specify the interrupt and my function name:

InterruptVector Component Properties

InterruptVector Component Properties

Then I only need to add that interrupt handler (MyIRQ() in my example) and that’s it.

Oh, wait: how to define other properties for that interrupt? I mean I usually can configure to create an interrupt on PortB pin 7 on a falling edge, etc?

The answer is: either I configure all these settings in my code (setting the ‘trigger on’ flags, …), or I use a different component: the Init_GPIO one.

Init_GPIO Component

If I want to configure a pin to create an interrupt on a specific event, I can use the Init_GPIO component found in the Components Library:

Init_GPIO Component in Components Library

Init_GPIO Component in Components Library

Once I have added this component to my project, I specify the port and pin to be enabled and initialized:

PTB7 Interrupt on Falling Edge

PTB7 Interrupt on Falling Edge

:idea: Here I can configure other properties like direction and pull resistor of the pin.

To enable the interrupt and to give my user interrupt function name, I do this in the ‘Interrupts’ section:

Port Interrupt Settings

Port Interrupt Settings

Interrupt Code

What is missing is now my interrupt function in my application. An (empty) example would be like this:

void MyIRQ(void) {
  /* my interrupt code here */
}


Summary

Processor Expert takes care about the interrupt vectors and vector table. To define my own interrupts, I can use the InterruptVector component which allows me to add my function name to the vector table. If I want to use interrupts with general purpose I/O pins and want to configure properties like pull-resistors, then the preferred way is to use the Init_GPIO component.

Happy Vectoring!

Sensu: workflow automation for monitoring. Learn more—download the whitepaper.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}