D
Dirk Zabel
Hi,
I have a function to put out a byte to the i2c-bus. We are on an
embedded system here, the code is generated by a tool.
static int i2c_write_byte(unsigned char by)
{
card Data9th;
int rval;
/* [...] lot of stuff omitted here for brevity */
/*--- Dummy read to reset RI flag ---*/
by = U0RB;
return rval;
}
U0RB is some processor-specific control register and is defined as:
#define MA_UNSIGNED_SHORT *(volatile unsigned short *)
#define U0RB (MA_UNSIGNED_SHORT ( 0x03A6 ))
The read access changes the state of the U0RB register.
When I compile this function with space optimazation turned on, the
dummy read gets optimized out. Question: what is wrong, the code or the
compiler? Should the volatile attribute have prevented the compiler from
discarding the read access?
Thanks for answers
-- Dirk
I have a function to put out a byte to the i2c-bus. We are on an
embedded system here, the code is generated by a tool.
static int i2c_write_byte(unsigned char by)
{
card Data9th;
int rval;
/* [...] lot of stuff omitted here for brevity */
/*--- Dummy read to reset RI flag ---*/
by = U0RB;
return rval;
}
U0RB is some processor-specific control register and is defined as:
#define MA_UNSIGNED_SHORT *(volatile unsigned short *)
#define U0RB (MA_UNSIGNED_SHORT ( 0x03A6 ))
The read access changes the state of the U0RB register.
When I compile this function with space optimazation turned on, the
dummy read gets optimized out. Question: what is wrong, the code or the
compiler? Should the volatile attribute have prevented the compiler from
discarding the read access?
Thanks for answers
-- Dirk