avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] How to pass a struct in Interrupt


From: David Brown
Subject: Re: [avr-gcc-list] How to pass a struct in Interrupt
Date: Fri, 16 Jan 2004 11:56:08 +0100

It looks like you have got your header files mixed up, so when compiling
isr.c there is no definition of the UART structure.  Since UART is an
unknown type, the compiler guesses (with an error message) that it is an
"int", and everything goes downhill from there.


The most common way to arrange something like this is:

/* uart.h */
typedef struct { ...} UART;
extern UART uart0;

/* uart.c */
#include "uart.h"
UART uart0;

/* isr.c */
#include "uart.h"
SIGNAL(SIG_UART_RECV) ...


Any "extern" in a ".c" file is almost always a sign of confused .h/.c module
interface definition (except for occasional quick-and-dirty test code added
to existing code).







----- Original Message -----
From: "Eric Fu" <address@hidden>
To: <address@hidden>
Sent: Friday, January 16, 2004 11:22 AM
Subject: [avr-gcc-list] How to pass a struct in Interrupt


Hi,

I'm trying to write a simple Interrupt driven UART.

I defined a struct  in UART.c like:
typedef struct UART
{
 byte RxBuf[RX_BUFFER_SIZE];
 volatile byte RxHead;
 volatile byte RxTail;
    .
    .

 }UART;

UART uart0;

And in isr.c, I declare and define:
extern UART uart0;
SIGNAL(SIG_UART_RECV) //USART RX complete INT
{
 byte data;
 byte tmphead;

 /* Read the received data */
 data = UDR;
 /* Calculate buffer index */
 tmphead = ( uart0.RxHead + 1 ) & RX_BUFFER_MASK;
 uart0.RxHead = tmphead;      /* Store new index */
    .
    .
}

I have the following compile error:
Compiling: isr.c
avr-gcc -c -mmcu=atmega16 -I. -g -Os -funsigned-char -funsigned-bitfields -f
pack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=isr.lst -Ic:
/pjt2/avr/PJT_inc -std=gnu99 isr.c -o isr.o
isr.c:17: error: parse error before "uart0"
isr.c:17: warning: type defaults to `int' in declaration of `uart0'
isr.c:17: warning: data definition has no type or storage class
isr.c: In function `__vector_11':
isr.c:84: error: request for member `RxHead' in something not a structure or
union
isr.c:85: error: request for member `RxHead' in something not a structure or
union
isr.c:87: error: request for member `RxTail' in something not a structure or
union
isr.c:92: error: request for member `RxBuf' in something not a structure or
union
isr.c: In function `__vector_12':
isr.c:104: error: request for member `TxHead' in something not a structure
or union
isr.c:104: error: request for member `TxTail' in something not a structure
or union
isr.c:107: error: request for member `TxTail' in something not a structure
or union
isr.c:108: error: request for member `TxTail' in something not a structure
or union
isr.c:110: error: request for member `TxBuf' in something not a structure or
union
make: *** [isr.o] Error 1

It seems the compiler doesn't recognise an external struct definition. Could
anyone give me a hint to get around this?
Thanks.

Eric Fu
_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list





reply via email to

[Prev in Thread] Current Thread [Next in Thread]