This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem with a macro


GCC does not use @... at least not like this.

Generally to access a specific memory location in a certain way I use
something like this:

struct foo  __attribute__ ((packed)) {
	uint8_t a        : 1;
	uint8_t b        : 1;
	uint8_t c        : 1;
	uint8_t d        : 1;
	uint8_t reserved : 4;
};

#define FOO (*((volatile struct foo *) 0x40005C00))

FOO.a = 1;

regards,
m.s.

On Sun, 2013-10-20 at 00:13 -0300, Peter Gregson wrote:
> Hello,
> 
> Perhaps you can help me.  I have a piece of code that I am porting to GCC and one of the macros has been giving me problems for over a week.  Could you please look at it and tell me what is wrong?  Note that this is extracted from the actual code, and is, I think, the smallest amount that shows the problem.
> 
> 
> First the code:
> 
> /*	Test macro defs		*/
> 
> #define __REG16 unsigned short 
> 
> #define __READ_WRITE	const
> 
> typedef struct {
>  __REG16  EA             : 4;
>  __REG16  STATTX         : 2;
>  __REG16  DTOGTX         : 1;
>  __REG16  CTRTX          : 1;
>  __REG16  EPKIND         : 1;
>  __REG16  EPTYPE         : 2;
>  __REG16  SETUP          : 1;
>  __REG16  STATRX         : 2;
>  __REG16  DTOGRX         : 1;
>  __REG16  CTRRX          : 1;
>  } __usb_epr_bits;
> 
> #define __IO_REG16(NAME, ADDRESS, ATTRIBUTE)             \
>      volatile __no_init ATTRIBUTE unsigned short NAME @ ADDRESS 
> 
> 
> 
> #define __IO_REG16_BIT(NAME, ADDRESS, ATTRIBUTE,BIT_STRUCT)\
> 		volatile __no_init  ATTRIBUTE union\
>      {unsigned short NAME;				\
>       BIT_STRUCT NAME ## _bit;      		\
>       } @ ADDRESS
> 
> 
> 
> int	main (void) {
> 
> 	unsigned short USB_EP0R;
> 	
>  __IO_REG16_BIT (USB_EP0R, 0x40005C00,__READ_WRITE,__usb_epr_bits);
>  return (0);
>  }
> 
> 
> 
> 
> Now the error message when I compile it.  Note that I have "--save-temps" in the compiler invocation so that I can see the output of the preprocessor.  I also used -O0 to keep things simple.
> 
> Peters-MacBook-Air:STM32F103-STK peter$ gcc -O0 --save-temps -I USB tt.c
> tt.c: In function âmainâ:
> tt.c:39: error: nested functions are disabled, use -fnested-functions to re-enable
> tt.c:39: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before âconstâ
> tt.c:39: error: stray â@â in program
> tt.c:39: error: expected identifier or â(â before numeric constant
> Peters-MacBook-Air:STM32F103-STK peter$ 
> 
> 
> 
> When I add -fnested-functions to the command line, I get :
> 
> Peters-MacBook-Air:STM32F103-STK peter$ gcc -O0 --save-temps -I USB -fnested-functions tt.c
> tt.c: In function âmainâ:
> tt.c:39: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before âconstâ
> tt.c:39: error: stray â@â in program
> tt.c:39: error: expected identifier or â(â before numeric constant
> Peters-MacBook-Air:STM32F103-STK peter$ 
> 
> 
> The output of the preprocessor is as follows.  You can see that the macro substitution has been carried out, and it appears to my eye, correctly. 
> 
> # 1 "tt.c"
> # 1 "<built-in>"
> # 1 "<command-line>"
> # 1 "tt.c"
> # 9 "tt.c"
> typedef struct {
>  unsigned short EA : 4;
>  unsigned short STATTX : 2;
>  unsigned short DTOGTX : 1;
>  unsigned short CTRTX : 1;
>  unsigned short EPKIND : 1;
>  unsigned short EPTYPE : 2;
>  unsigned short SETUP : 1;
>  unsigned short STATRX : 2;
>  unsigned short DTOGRX : 1;
>  unsigned short CTRRX : 1;
>  } __usb_epr_bits;
> # 35 "tt.c"
> int main (void) {
> 
> unsigned short USB_EP0R;
> 
>  volatile __no_init const union {unsigned short USB_EP0R; __usb_epr_bits USB_EP0R_bit; } @ 0x40005C00;
> 
>  return (0);
>  }
> 
> 
> I have the following questions:
> 
> 1.What are my errors?
> 2. What is the "@" syntax about?  I think that it means that he union is saved at absolute address 0x40005C00, but when I search on GCC "@" I get nothing.
> 
> Can you help me, please?
> 
> Thank you, and 
> 
> Best regards,
> 
> Peter
> 
> 



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]