Search code examples
cgccavr

How to disable avr-gcc's "appears to be a misspelled interrupt handler" warning?


I'm currently creating firmware for an USB device on AVR microcontroller. Since USB timing is really strict, I cannot allow for non-USB interrupts to block for more than a few instruction cycles. Therefore, my USART RXC (character received) interrupt looks like this:

void usart_rxc_wrapped() __attribute__ ((interrupt));
void usart_rxc_wrapped(){
    uint8_t c=UDR;
    if(!ringBufferFull(&rx)){
        ringBufferWrite(&rx, c);
    }
    // Reenable nterrupt
    UCSRB|=1<<RXCIE;
}

// This cannot be ISR_NOBLOCK, since the interrupt would go
// into infinite loop, since we wouldn't get up to reading
// UDR register. Instead, we use assembly to do the job
// manually and then jump to the real handler.
ISR(USART_RXC_vect, ISR_NAKED){
    // Disable this interrupt by clearing its Interrupt Enable flag.
    __asm__ volatile("cbi %0, %1"::
            "I"(_SFR_IO_ADDR(UCSRB)),"I"(RXCIE));
    __asm__ volatile("sei"::);
    __asm__ volatile("rjmp usart_rxc_wrapped"::);
}

Note that I couldn't just put the main interrupt code in ISR routine, since avr-gcc generates a pretty long prologue for this function (after all, I call other functions from there, so many registers need to be pushed). Even if first instruction in C code were clearing interrupt flag, it would be still delayed by uncomfortably many cycles.

This solution works fine, but I'm worried by avr-gcc's warning:

uart.c:128:6: warning: ‘usart_rxc_wrapped’ appears to be a misspelled interrupt handler

This is because I use __attribute__((interrupt)) in its definition in order to notify compiler to save registers as though it was an ISR. I can't find any option in the compiler to disable this warning. Is there a workaround to make compilation less noisy? Or maybe there is a better way of dealing with this situation?


Solution

  • I found this patch from 8 years ago: http://savannah.nongnu.org/bugs/download.php?file_id=15656. Apparently the warning is generated unconditionally (there is no -WnoXXX flag for compilation). However, avr-gcc generates this warning only when the name of the function doesn't start with __vector. To fix my problem, I simply renamed the wrapped function to __vector_usart_rxc_wrapped.