10

What is the preferred method of declaring an interrupt handler in mspgcc?

LittleBobbyTables - Au Revoir
  • 32,008
  • 25
  • 109
  • 114
Wayne Uroda
  • 5,025
  • 4
  • 30
  • 35

2 Answers2

7

Note that this information applies to MSPGCC v4.6.3 which pre-dates the Ti/Redhat/SOMNIUM port of MSPGCC which is now distributed with code composer studio.

Thanks go to Peter Bigot of the Mspgcc-users mailing list for this answer.

There are two possibilities:

A. Use Code composer studio style syntax (has the added benefit of being portable to CCS):

#pragma vector=TIMER0_A0_VECTOR    
__interrupt void
ta0cc0_isr (void)

(Note that this was introduced somewhere around version 20120406 of Mspgcc).

B. Use native gcc syntax:

static void
__attribute__((__interrupt__(TIMER0_A0_VECTOR)))
isr_cc0_TA0 (void)

C. Name the function correctly so that it is included into the vector table (useful for ASM functions).

The interrupt attribute causes the function to be named __isr_X where X is the word offset of the interrupt from the vector table start (equal to the value of the interrupt attribute's parameter divided by 2).

These __isr_X symbols are used to initialize the vector table in crt0ivtbl.o.

Wayne Uroda
  • 5,025
  • 4
  • 30
  • 35
  • This didn't work for me in CCS 6.2.0 when using GNU v5.3.0.219 (SOMNIUM Technologies Limited), which is installed as an add-on to CCS. Error: `internal compiler error: in msp430_attr, at`. Might start a new question if I don't find an answer. – coder.in.me Oct 17 '16 at 13:30
  • 1
    Manual says this: "To define an interrupt using MSP430 GCC, use the following syntax: `void __attribute__ ((interrupt(INTERRUPT_VECTOR))) INTERRUPT_ISR (void)` The static keyword should not be used on ISR definition." PDF: http://www.ti.com/lit/pdf/slau646 – coder.in.me Oct 17 '16 at 13:37
  • This original information was applicable to the MSPGCC port before it was re-implemented by Ti/Redhat, which did not exist in 2013 :) – Wayne Uroda Oct 18 '16 at 07:08
  • It's important to capture the current state of things. I prefer to download the latest version than the 2013 one. This question and answers are still useful for historic purposes. – coder.in.me Oct 18 '16 at 14:10
  • I don't disagree, by all means please add another answer to this question and add your findings! – Wayne Uroda Oct 19 '16 at 00:41
5

Just to clarify, because this is an early Google result.

__attribute__((__interrupt__(TIMER0_A0_VECTOR)))
void __isr_5(void)
{
        ...
}

Current GCC still (I believe this is what arvindpdmn commented about) raises an error, when using above syntax.

internal compiler error: in msp430_attr, at config/msp430/msp430.c:1835
 {
 ^

An issue was raised for this after a report of this in the TI E2E community, but said issue is still in its "Planned" state and it is unclear who the tracker even belongs to. (You can access the issue via the thread in above link.)

Looking at the code, the error is apparently raised, because the only attribute that may have arguments, is the interrupt attribute.

In fact, compilation works fine, if the leading and following underscores are omitted.

This right here is the correct syntax!

__attribute__((interrupt(TIMER0_A0_VECTOR)))
void name_does_not_matter(void)
{
        ...
}

And in fact, this attribute is documented in the official GNU GCC documentation. In retrospect, it is rather unclear where the underscores came from in the first place. So, basically, the only problem here is that the error message is so uninformative.

kllmnn
  • 111
  • 1
  • 3