1

I am developing a simple OS, which needs a small interrupt vectors. I have been reading about the interrupt vectors in order to understand the concepts.

Many of the resources refer to like this: enter image description here

[1 ]http://www.embedded.com/electronics-blogs/programming-pointers/4025714/Modeling-interrupt-vectors#references

What confuses me is that how do I know the address of the interrupt handler? I know that I need to create different functions for the different types of interrupts but how can I know the address of the function?

I am developing my code in C.

2
  • Everything is done by linker. You write interrupt handlers, you fill a vector table with your handlers and mark it as the vector table, and linker do the rest. Have you yet developped on embedded device ? Commented Nov 18, 2016 at 14:13
  • 1
    The address of a function is expressed by the name of the function. E.g: the address of this function: void Foo() {bar();}; is simply foo. And to print that address: printf("%p\n", (void*)foo);. Commented Nov 18, 2016 at 14:13

1 Answer 1

2

Interrupt handler is, at the end, a function.

A function starts at "an address" and you can simply use its name to retrieve it.

The following code will warn about %p parameter type passed, but is explicative:

#include <stdio.h>

void dummy_ISR ( void )
{

}

int main ( void )
{
    printf("Address of function: %p\n", dummy_ISR);

}

You can use function pointer to create a table

#include<stdio.h>

int dummy_isr1 ( void )
{
    return 0;
}

int dummy_isr2 ( void )
{
    return 0;
}

typedef int (*functionPtr)(void);

functionPtr table[] =
{
        dummy_isr1,
        dummy_isr2
};


int main(void)
{
    for (size_t i=0; i<sizeof(table)/sizeof(table[0]); i++)
    {
        printf("Address %zu: %p\n", i, table[i]);
    }

   return 0;
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, but if I am pointing to a function, what would the type of the vector? if I have 32-bit machine
You can use function pointers to do so. Another way is to simply use void *, but Standard Lawyers can kill me if I officially support that solution ;)
@Salma: Note that on ARM, GCC (and some other compilers) support the interrupt function attribute (or isr), which tells the compiler to generate the necessary code around the function that makes the function work safely as an interrupt service routine. For the table, you can use the section("name")variable attribute, and use a linker script to tell the linker where to place that section.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.