user2988694
user2988694

Reputation: 89

Pointers to Strucures

#define AVR32_EIC_ADDRESS                  0xFFFF0D80 
#define AVR32_EIC  (*((volatile avr32_eic_t*)AVR32_EIC_ADDRESS))
typedef struct avr32_eic_t {
union {
      unsigned long                  ier       ;//0x0000
      avr32_eic_ier_t                IER       ;
      };
union {
      unsigned long                  idr       ;//0x0004
      avr32_eic_idr_t                IDR       ;
      };
union {
const unsigned long                  imr       ;//0x0008
const avr32_eic_imr_t                IMR       ;
};
union {
const unsigned long                  isr       ;//0x000c
const avr32_eic_isr_t                ISR       ;
};
union {
      unsigned long                  icr       ;//0x0010
      avr32_eic_icr_t                ICR       ;
 };
union {
      unsigned long                  mode      ;//0x0014
      avr32_eic_mode_t               MODE      ;
};
union {
      unsigned long                  edge      ;//0x0018
      avr32_eic_edge_t               EDGE      ;
};
union {
      unsigned long                  level     ;//0x001c
      avr32_eic_level_t              LEVEL     ;
 };
union {
      unsigned long                  filter    ;//0x0020
      avr32_eic_filter_t             FILTER    ;
 };
 union {
      unsigned long                  test      ;//0x0024
      avr32_eic_test_t               TEST      ;
 };
  union {
      unsigned long                  async     ;//0x0028
      avr32_eic_async_t              ASYNC     ;
 };
 union {
      unsigned long                  scan      ;//0x002c
      avr32_eic_scan_t               SCAN      ;
  };
   union {
      unsigned long                  en        ;//0x0030
      avr32_eic_en_t                 EN        ;
  };
 union {
      unsigned long                  dis       ;//0x0034
      avr32_eic_dis_t                DIS       ;
 };
 union {
      unsigned long                  ctrl      ;//0x0038
      avr32_eic_ctrl_t               CTRL      ;
 };
  } avr32_eic_t;

  typedef struct avr32_eic_ier_t {
   unsigned int                 :23;
   unsigned int nmi             : 1;
   unsigned int int7            : 1;
   unsigned int int6            : 1;
   unsigned int int5            : 1;
   unsigned int int4            : 1;
   unsigned int int3            : 1;
   unsigned int int2            : 1;
   unsigned int int1            : 1;
   unsigned int int0            : 1;
  } avr32_eic_ier_t;

  main()
  { 
      AVR32_EIC.IER.nmi = 1; // statment 1
   }

here i have posted the entire code can anyone explain how does the statment 1 gets resolved in main here. i am guessing here they are trying to add based address and offset and finally forming one address where particular data is is dumped

Upvotes: 0

Views: 83

Answers (1)

macfij
macfij

Reputation: 3209

#define AVR32_EIC (*((volatile avr32_eic_t*)AVR32_EIC_ADDRESS)) is a type casting on AVR32_EIC_ADDRESS, which was defined earlier as 0xFFFF0D80 - this address is an i/o register and its content can be changed. you can read from it and write data onto it.

if content of 0xFFFF0D80 was read and saved into general purpose register and there was no volatile keyword, program will keep reading the same value, even if the value of 0xFFFF0D80 has changed (in embedded system some memory values may change without software action).

there are many resources on net about using volatile keyword in embedded programming.
example resources:
http://www.embedded.com/electronics-blogs/barr-code/4236917/Combining-C-s-volatile-and-const-keywords
http://embeddedgurus.com/barr-code/2009/03/coding-standard-rule-4-use-volatile-whenever-possible/

Upvotes: 1

Related Questions