avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] How to control the optimizer from the C source?


From: Joerg Wunsch
Subject: Re: [avr-gcc-list] How to control the optimizer from the C source?
Date: Fri, 13 Aug 2004 11:19:56 +0200 (MET DST)

Bernard Fouché <address@hidden> wrote:

> the fun thing is that the optimizer does not spare many 'ldi r24,0x80' but
> change the code to have at the end of the function 'sts 0x0061,r24' once: it
> delayed the second setting of 0x0061 to the end of the function. The problem
> is that the clock prescaler register must be touched twice within 4 clock
> ticks. If we look at line 237a (for instance), There is:

How about that?
#include <avr/io.h>
#include <inttypes.h>

void set_clkdiv(int mode)
{
    uint8_t clkpr;

    switch(mode)
    {
       case 0:
       case 1:
          clkpr=0x00;
          break;
       case 2:
          clkpr=0x01;
          break;
       case 4:
          clkpr=0x02;
          break;
       case 8:
          clkpr=0x03;
          break;
       case 16:
          clkpr=0x04;
          break;
       case 32:
          clkpr=0x05;
          break;
       case 64:
          clkpr=0x06;
          break;
       case 128:
          clkpr=0x07;
          break;
       case 256:
          clkpr=0x08;
          break;
    }
    cli();
    CLKPR = 0x80;
    CLKPR = clkpr;
    sei(); //re-enable interrupts
}


-- 
J"org Wunsch                                           Unix support engineer
address@hidden        http://www.interface-systems.de/~j/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]