We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi,
I would like to prevent structure members optimization. I used volatile keyword:
typedef volatile struct { volatile ... volatile uint32_t discard; volatile ... } regs_t;
I declared a member in another non-volatile struct:
typedef struct { ... volatile regs_t *regs; ... } peripheral_t;
I used an "empty" expression to just clear flags in register (the memory read access must be performed):
peripheral_t p; p.regs = 0x12345678; /* init to register block starting address */ p.regs->discard; /* gets optimized out when opt. is on */
The "empty" expression gets optimized out although I thought (hoped) I prevented it via the volatile keywords. - What is the right place to put the volatile? - Does the whole struct have to be volatile? - Does it make sense to define volatile type? (typedef volatile struct...)
Thanks for tips/explanations.
Regards Pavel
Christoph: wrote > You may have discovered a compiler bug here.
As I wrote earlier, the behavior seems to be valid according to the C standard. The volatile structure is a member of a non-volatile structure, a pointer to which is used to access a register. Following my advice in previous post may solve the issue.
-- Marcus http://www.doulos.com/arm/
I don't know much about this. I don't have any experience on ATMEL MCU.
But, maybe you can take a look at some ATMEL Example Code.
In AT91SAM7S32.h
#ifndef AT91SAM7S32_H #define AT91SAM7S32_H #ifndef __ASSEMBLY__ typedef volatile unsigned int AT91_REG;// Hardware register definition #define AT91_CAST(a) (a) #else #define AT91_CAST(a) #endif // ***************************************************************************** // SOFTWARE API DEFINITION FOR System Peripherals // ***************************************************************************** #ifndef __ASSEMBLY__ typedef struct _AT91S_SYS { AT91_REG AIC_SMR[32]; // Source Mode Register AT91_REG AIC_SVR[32]; // Source Vector Register AT91_REG AIC_IVR; // IRQ Vector Register AT91_REG AIC_FVR; // FIQ Vector Register AT91_REG AIC_ISR; // Interrupt Status Register AT91_REG AIC_IPR; // Interrupt Pending Register