volatile in struct
Juergen Zeller
juergen.zeller at argovision.de
Mon Feb 16 16:32:50 UTC 2004
Hello all,
I'm confused, I need help from the specialists!
I'm using rtems4.6.0 with an i386ex board. I was looking for an error
for a while and now I figured out that it depends on a volatile
definition in the following manner:
#if 0
#define VOLATILE /*THIS WORKS for millions of packets without the
printk-msg 'lost bytes...' */
#else
#define VOLATILE volatile /*here I get the printk-msg 'lost bytes...'
sometimes (about once per 2000 packets)*/
#endif
typedef struct {
...
unsigned char txbuf[256];
VOLATILE unsigned char txwr; // tx write pointer
VOLATILE unsigned char txrd; // tx read pointer
VOLATILE unsigned char txcount; // tx byte counter
VOLATILE unsigned char txmsgcount; // tx packet counter
...
} MS3_COMDATA;
static rtems_task tx_task (rtems_task_argument arg)
{
...
while (1) {
...
rtems_interrupt_disable (l);
com->txcount -= count;
com->txmsgcount--;
rtems_interrupt_enable (l);
...
}
}
int send (MS3_COMDATA *com, something else )
{
...
rtems_semaphore_obtain (com->sema, RTEMS_NO_TIMEOUT, 0);
/* if the last message was sent there shouldn't remain any bytes in the
buffer*/
if (!com->txmsgcount && com->txcount) {
printk ("%d lost bytes in txbuffer[%d](%d)\n", com->txcount, port,
counter[port]);
com->txcount = 0;
}
... /*Code for putting it into txbuf*/
com->txmsgcount++;
rtems_semaphore_release (com->sema);
}
Can anyone out there explain whats going on here? I never thought that
volatile could be responsible for errors. Is it because it's inside a
struct?
regards
juergen
More information about the users
mailing list