[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CPU - PCI cycles




> Dose some one have an idea how can I access the locations I want, in the
> sequence I want, or what limitations do I have one such operations?

Ah, the magic of caching and/or optimizing compilers :-)

I would guess optimization is happening with your compiler.  Mark your
PCI memory as "volatile" and/or look at the optimization options for
your compiler.

Here's how optimization works: let's look at this bit of code here

  {
    int i;

    for (i=0;i<100;i++)
	;

    printf("i = %d\n",i);
  }

Your compiler will take one look at this code fragment and optimize it
to:

  {
    printf("i = %d\n",100);
  }

It saw that nothing happened with the variable i in the loop, so it
elimates the loop altogether.  In my example, it would also eliminate
the stack space used up by the variable and just inserted a constant.


Let's look at an example that might reflect the situation in a device
driver a bit more:

  /** 
     update_led() reads the read-only foo1 register on the F008638
     auto-LED updater.  Reading the read-only foo1 register 100 times
     and writing that value to the foo2 register will cause the LED to
     be updated to reflect the latest status and writing the value to

     foo1_register contains the address of the foo1 register on the F008638.
     foo2_register contains the address of the foo2 register on the F008638.
  **/
  int update_led(int *foo1_register, int *foo2_register)
  {
      int i;
      int junk;

      for (i=0;i<100;i++) {
          junk = *foo1_register;
	  *foo2_register = junk;
      }
  }

What will an optimizer do to this?

  int update_led(int *foo1_register, int *foo2_register)
  {
      *foo2_register = *foo1_register;
  }

You'll only see two accesses on the bus -- one read and one write.  So
your registers have to declared something like this:

  int update_led(volatile int *foo1_register, volatile int *foo2_register)


Richard "been doin drivers for 8 years" Masoner
^p"`"