[Top][All Lists]
[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: |
Anton Erasmus |
Subject: |
Re: [avr-gcc-list] How to control the optimizer from the C source? |
Date: |
Sun, 15 Aug 2004 22:51:30 +0200 |
On 13 Aug 2004 at 10:50, Bernard Fouché wrote:
> I met an optimization problem: while porting code from icc to gcc, I had the
> following routine:
[routine etc snipped]
Hi,
Try the following - It produces to concecutive writes to the CLKPR register.
It also allows you to keep your critical section much shorter.
void set_clkdiv(int mode)
{
unsigned char tmp1,tmp2;
switch(mode)
{
case 0:
case 1:
tmp1=0x80;
tmp2=0x00;
break;
case 2:
tmp1=0x80;
tmp2=0x01;
break;
case 4:
tmp1=0x80;
tmp2=0x02;
break;
case 8:
tmp1=0x80;
tmp2=0x03;
break;
case 16:
tmp1=0x80;
tmp2=0x04;
break;
case 32:
tmp1=0x80;
tmp2=0x05;
break;
case 64:
tmp1=0x80;
tmp2=0x06;
break;
case 128:
tmp1=0x80;
tmp2=0x07;
break;
case 256:
tmp1=0x80;
tmp2=0x08;
break;
}
cli();
CLKPR=tmp1;
CLKPR=tmp2;
sei(); //re-enable interrupts
}
Regards
Anton Erasmus
--
A J Erasmus