This is the mail archive of the crossgcc@sourceware.cygnus.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more infromation.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: problem assigning value to global variables


Nicole Cook wrote:
> So, in some file there's a global variable declared:
> 
> unsigned short buffer[];
> 
> The program calls a function that sends an IDDrive command to the drive
> and zeros the buffer.  Then it calls a function to read the information
> in from the drive:
> 
> int readBuffer(unsigned short *buffer) {
>         unsigned short *temp;
>         int i;
> 
>         temp = buffer;
>         for (i=0;i<256;i++) {
>              *temp = *((unsigned long *)DATA_PORT;
>              temp++;
>         }
> }
> 
> This is almost identical to the code that correctly dumps the buffer
> read from DATA_PORT to stdout.  However, instead of reading the real
> data, temp is always set to some value (sometimes its 0x70, or 0x070070,
> or 0x90... it's not always the same value).
> 
> The code worked before, and I haven't made any changes to it, nor can I
> see anything wrong with the way it's reading from memory (the drive is
> memory mapped on an aeb-1c).  Is there some difference in the way the
> two versions of arm-elf-gcc work that would break this? Which is doing
> the correct thing? Is this a compiler bug?

You didn't include the call to readBuffer.  I hope you are not expecting
the "buffer" variable in the readBuffer() function to be the same as the
global "buffer" array.  One is a global variable, the other is a formal
parameter to the function with a scope local to that function.

Second, (I don't know how IDE drives behave) if successive reads to
DATA_PORT return different values, you want to make sure that DATA_PORT
is declared as a pointer to volatile.  Otherwise the compiler can
optimize the read out of the loop and only read once.  This could change
between compiler versions.

Art

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]