#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
}
这里我已经发布了完整的代码 谁能解释一下 main 中的语句 1 是如何解决的。 我猜测他们正在尝试添加基地址和偏移量,并最终形成一个转储特定数据的地址
最佳答案
#define AVR32_EIC (*((volatile avr32_eic_t*)AVR32_EIC_ADDRESS))
是 AVR32_EIC_ADDRESS 的类型转换,之前定义为 0xFFFF0D80 - 该地址是一个 i/o 寄存器,其内容可以被改变。您可以从中读取数据并向其写入数据。
如果读取 0xFFFF0D80 的内容并将其保存到通用寄存器中,并且没有 volatile 关键字,程序将继续读取相同的值,即使 0xFFFF0D80 的值已更改(在嵌入式系统中,某些存储器值可能会在没有软件操作的情况下更改)。
网上有很多关于在嵌入式编程中使用 volatile 关键字的资源。
示例资源:
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/
关于c - 结构体指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24093718/