volatile in struct

Angelo Fraietta afraiett at bigpond.net.au
Wed Feb 18 18:36:47 UTC 2004


The problem, I believe, is in your implementation. See below. Am I
correct in assuming that only one thread is transmitting and another is
receiving?  Use a queue. Don't use a tx byte counter. Calculate if empty
or full by comparing the tx ptr with the rx ptr.

It might be that volatile is not generating errors, but rather showing
them to you.

I had a similar problem with my project using a 386sx and overcame the
requirement to use semaphores or disabling interrupts for data that was
entering ia the ISR.  I can provide a document showing some of the tests
that I did with different queue types if you are interested.

I did, however, use events to indicate to the thread that was waiting
for the data that data was ready.

I hope this helps.

Juergen Zeller wrote:

> 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
>
>
>

-- 
Angelo Fraietta

PO Box 859
Hamilton NSW 2303

Home Page


http://www.users.bigpond.com/angelo_f/

There are those who seek knowledge for the sake of knowledge - that is 
CURIOSITY
There are those who seek knowledge to be known by others - that is VANITY
There are those who seek knowledge in order to serve - that is LOVE
     Bernard of Clairvaux (1090 - 1153)





More information about the users mailing list