1

I'm working on an embedded processor and having trouble getting interrupts to work in real life. They work fine in simulation but that's another story.

Anyway on this ARC processor you set the interrupt handler with this function _setvect1 that looks like this

extern void _setvect1(int vector, _Interrupt1 void (*target)());

I don't understand what the second part means and what it's looking for. Is that a pointer to a function, I'm not used to seeing something like (*target) I vaguely remember that () is a function?

This is my isr

int volatile flag_sp3 = 0;
_Interrupt1 _Save_all_regs void sp3_isr(void)
{
    unsigned volatile long result;
    result = _lr(0x0A);//status maybe
    display_value(result);
    flag_sp3++;
}

They call Interrupt1 and _Save_all_regs calling conventions, another thing I've not really run into before. I am talking to their support but still trying to understand and work it out for myself.

confused
  • 713
  • 1
  • 5
  • 16
  • 1
    It is a pointer to Function, take a look of my code to see how it is used =>> http://stackoverflow.com/questions/32614150/clarification-on-function-pointers-in-c/32615240#32615240 – Michi Sep 17 '15 at 16:49
  • bad idea call display_value() inside a interrupt. Strongly suggest saving value to global variable, then some main line function looks for change in the flag_sp3 variable and when changed, call display_value() – user3629249 Sep 17 '15 at 17:19

2 Answers2

2

Yes it is asking you to pass a function pointer. void (*target)() represents a pointer to function which doesn't receive any argument or return anything.

In your case, you can just pass sp3_isr as the second argument to _setvec1 function (remember, function name represents function pointer). Also make sure that you have to declare/define sp3_isr before it's use.

1

The rototype:

extern void _setvect1(int vector, _Interrupt1 void (*target)());

declared two arguments named vector and target. The argument target has type _Interrupt1 void (*)() which means a pointer to a function returning void, and having an undefined number of arguments. Undefined because in C (but not C++) a function void fn() is not equivalent to void fn(void), which is a function taking no parameters. However this is somewhat pedantic as there are in fact no arguments passed in this case.

So in this case you would assign sp3_isr() as an interrupt handler thus:

_setvect1( SP3_VECT, sp3_isr ) ;

Where SP3_VECT is the interrupt vector number for the desired IRQ.

On many architectures interrupt handlers may have special requirements with respect to code generation by the compiler, and such architecture specific details are not supported in the standard definition of the C language, hence the compiler specific qualifiers _Interrupt1 and _Save_all_regs. Exactly how these directives affect code generation will be detailed in the compiler documentation - if not, they may be macros, in which case their definitions will be in an included header file.

Clifford
  • 88,407
  • 13
  • 85
  • 165